[COMCTL32]: comctl32/propsheet: Diverse UI fixes:
[reactos.git] / reactos / dll / win32 / comctl32 / propsheet.c
1 /*
2 * Property Sheets
3 *
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
29 *
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_RECALCPAGESIZES
36 * o WM_HELP
37 * o WM_CONTEXTMENU
38 * - Notifications:
39 * o PSN_GETOBJECT
40 * o PSN_QUERYINITIALFOCUS
41 * o PSN_TRANSLATEACCELERATOR
42 * - Styles:
43 * o PSH_RTLREADING
44 * o PSH_STRETCHWATERMARK
45 * o PSH_USEPAGELANG
46 * o PSH_USEPSTARTPAGE
47 * - Page styles:
48 * o PSP_USEFUSIONCONTEXT
49 * o PSP_USEREFPARENT
50 */
51
52 #include "comctl32.h"
53
54 /******************************************************************************
55 * Data structures
56 */
57 #include "pshpack2.h"
58
59 typedef struct
60 {
61 WORD dlgVer;
62 WORD signature;
63 DWORD helpID;
64 DWORD exStyle;
65 DWORD style;
66 } MyDLGTEMPLATEEX;
67
68 typedef struct
69 {
70 DWORD helpid;
71 DWORD exStyle;
72 DWORD style;
73 short x;
74 short y;
75 short cx;
76 short cy;
77 DWORD id;
78 } MyDLGITEMTEMPLATEEX;
79 #include "poppack.h"
80
81 typedef struct tagPropPageInfo
82 {
83 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
84 HWND hwndPage;
85 BOOL isDirty;
86 LPCWSTR pszText;
87 BOOL hasHelp;
88 BOOL useCallback;
89 BOOL hasIcon;
90 } PropPageInfo;
91
92 typedef struct tagPropSheetInfo
93 {
94 HWND hwnd;
95 PROPSHEETHEADERW ppshheader;
96 BOOL unicode;
97 LPWSTR strPropertiesFor;
98 int nPages;
99 int active_page;
100 BOOL isModeless;
101 BOOL hasHelp;
102 BOOL hasApply;
103 BOOL hasFinish;
104 BOOL usePropPage;
105 BOOL useCallback;
106 BOOL activeValid;
107 PropPageInfo* proppage;
108 HFONT hFont;
109 HFONT hFontBold;
110 int width;
111 int height;
112 HIMAGELIST hImageList;
113 BOOL ended;
114 INT result;
115 } PropSheetInfo;
116
117 typedef struct
118 {
119 int x;
120 int y;
121 } PADDING_INFO;
122
123 /******************************************************************************
124 * Defines and global variables
125 */
126
127 static const WCHAR PropSheetInfoStr[] =
128 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
129
130 #define PSP_INTERNAL_UNICODE 0x80000000
131
132 #define MAX_CAPTION_LENGTH 255
133 #define MAX_TABTEXT_LENGTH 255
134 #define MAX_BUTTONTEXT_LENGTH 64
135
136 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
137
138 /* Wizard metrics specified in DLUs */
139 #define WIZARD_PADDING 7
140 #define WIZARD_HEADER_HEIGHT 36
141
142 /******************************************************************************
143 * Prototypes
144 */
145 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
146 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
147 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
148 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
149 int index,
150 int skipdir,
151 HPROPSHEETPAGE hpage);
152 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo, int original_index);
153 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
154 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
155 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
156
157 static INT_PTR CALLBACK
158 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159
160 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
161
162 static WCHAR *heap_strdupW(const WCHAR *str)
163 {
164 int len = strlenW(str) + 1;
165 WCHAR *ret = Alloc(len * sizeof(WCHAR));
166 strcpyW(ret, str);
167 return ret;
168 }
169
170 static WCHAR *heap_strdupAtoW(const char *str)
171 {
172 WCHAR *ret;
173 INT len;
174
175 len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
176 ret = Alloc(len * sizeof(WCHAR));
177 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
178
179 return ret;
180 }
181
182 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
183 /******************************************************************************
184 * PROPSHEET_UnImplementedFlags
185 *
186 * Document use of flags we don't implement yet.
187 */
188 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
189 {
190 CHAR string[256];
191
192 string[0] = '\0';
193
194 /*
195 * unhandled header flags:
196 * PSH_RTLREADING 0x00000800
197 * PSH_STRETCHWATERMARK 0x00040000
198 * PSH_USEPAGELANG 0x00200000
199 */
200
201 add_flag(PSH_RTLREADING);
202 add_flag(PSH_STRETCHWATERMARK);
203 add_flag(PSH_USEPAGELANG);
204 if (string[0] != '\0')
205 FIXME("%s\n", string);
206 }
207 #undef add_flag
208
209 /******************************************************************************
210 * PROPSHEET_GetPageRect
211 *
212 * Retrieve rect from tab control and map into the dialog for SetWindowPos
213 */
214 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
215 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
216 {
217 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
218 HWND hwndChild;
219 RECT r;
220
221 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
222 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
223 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
224 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
225 {
226 rc->left = rc->top = WIZARD_PADDING;
227 }
228 else
229 {
230 rc->left = rc->top = 0;
231 }
232 rc->right = psInfo->width - rc->left;
233 rc->bottom = psInfo->height - rc->top;
234 MapDialogRect(hwndDlg, rc);
235
236 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
237 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
238 !(ppshpage->dwFlags & PSP_HIDEHEADER))
239 {
240 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
241 GetClientRect(hwndChild, &r);
242 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
243 rc->top += r.bottom + 1;
244 }
245 } else {
246 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
247 GetClientRect(hwndTabCtrl, rc);
248 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
249 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
250 }
251 }
252
253 /******************************************************************************
254 * PROPSHEET_FindPageByResId
255 *
256 * Find page index corresponding to page resource id.
257 */
258 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
259 {
260 INT i;
261
262 for (i = 0; i < psInfo->nPages; i++)
263 {
264 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
265
266 /* Fixme: if resource ID is a string shall we use strcmp ??? */
267 if (lppsp->u.pszTemplate == (LPVOID)resId)
268 break;
269 }
270
271 return i;
272 }
273
274 /******************************************************************************
275 * PROPSHEET_CollectSheetInfoCommon
276 *
277 * Common code for PROPSHEET_CollectSheetInfoA/W
278 */
279 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
280 {
281 PROPSHEET_UnImplementedFlags(dwFlags);
282
283 psInfo->hasHelp = dwFlags & PSH_HASHELP;
284 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
285 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
286 psInfo->isModeless = dwFlags & PSH_MODELESS;
287 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
288 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
289 psInfo->active_page = 0;
290
291 psInfo->result = 0;
292 psInfo->hImageList = 0;
293 psInfo->activeValid = FALSE;
294 }
295
296 /******************************************************************************
297 * PROPSHEET_CollectSheetInfoA
298 *
299 * Collect relevant data.
300 */
301 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
302 PropSheetInfo * psInfo)
303 {
304 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
305 DWORD dwFlags = lppsh->dwFlags;
306
307 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
308
309 memcpy(&psInfo->ppshheader,lppsh,dwSize);
310 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
311 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
312 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
313
314 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
315 psInfo->ppshheader.pszCaption = NULL;
316 else
317 {
318 if (!IS_INTRESOURCE(lppsh->pszCaption))
319 {
320 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
321 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
322
323 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
324 psInfo->ppshheader.pszCaption = caption;
325 }
326 }
327 psInfo->nPages = lppsh->nPages;
328
329 if (dwFlags & PSH_USEPSTARTPAGE)
330 {
331 TRACE("PSH_USEPSTARTPAGE is on\n");
332 psInfo->active_page = 0;
333 }
334 else
335 psInfo->active_page = lppsh->u2.nStartPage;
336
337 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
338 }
339
340 /******************************************************************************
341 * PROPSHEET_CollectSheetInfoW
342 *
343 * Collect relevant data.
344 */
345 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
346 PropSheetInfo * psInfo)
347 {
348 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
349 DWORD dwFlags = lppsh->dwFlags;
350
351 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
352
353 memcpy(&psInfo->ppshheader,lppsh,dwSize);
354 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
355 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
356
357 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
358 psInfo->ppshheader.pszCaption = NULL;
359 else
360 {
361 if (!IS_INTRESOURCE(lppsh->pszCaption))
362 psInfo->ppshheader.pszCaption = heap_strdupW( lppsh->pszCaption );
363 }
364 psInfo->nPages = lppsh->nPages;
365
366 if (dwFlags & PSH_USEPSTARTPAGE)
367 {
368 TRACE("PSH_USEPSTARTPAGE is on\n");
369 psInfo->active_page = 0;
370 }
371 else
372 psInfo->active_page = lppsh->u2.nStartPage;
373
374 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
375 }
376
377 /******************************************************************************
378 * PROPSHEET_CollectPageInfo
379 *
380 * Collect property sheet data.
381 * With code taken from DIALOG_ParseTemplate32.
382 */
383 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
384 PropSheetInfo * psInfo,
385 int index, BOOL resize)
386 {
387 const DLGTEMPLATE* pTemplate;
388 const WORD* p;
389 DWORD dwFlags;
390 int width, height;
391
392 if (!lppsp)
393 return FALSE;
394
395 TRACE("\n");
396 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
397 psInfo->proppage[index].hwndPage = 0;
398 psInfo->proppage[index].isDirty = FALSE;
399
400 /*
401 * Process property page flags.
402 */
403 dwFlags = lppsp->dwFlags;
404 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
405 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
406 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
407
408 /* as soon as we have a page with the help flag, set the sheet flag on */
409 if (psInfo->proppage[index].hasHelp)
410 psInfo->hasHelp = TRUE;
411
412 /*
413 * Process page template.
414 */
415 if (dwFlags & PSP_DLGINDIRECT)
416 pTemplate = lppsp->u.pResource;
417 else if(dwFlags & PSP_INTERNAL_UNICODE )
418 {
419 HRSRC hResource = FindResourceW(lppsp->hInstance,
420 lppsp->u.pszTemplate,
421 (LPWSTR)RT_DIALOG);
422 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
423 hResource);
424 pTemplate = LockResource(hTemplate);
425 }
426 else
427 {
428 HRSRC hResource = FindResourceA(lppsp->hInstance,
429 (LPCSTR)lppsp->u.pszTemplate,
430 (LPSTR)RT_DIALOG);
431 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
432 hResource);
433 pTemplate = LockResource(hTemplate);
434 }
435
436 /*
437 * Extract the size of the page and the caption.
438 */
439 if (!pTemplate)
440 return FALSE;
441
442 p = (const WORD *)pTemplate;
443
444 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
445 {
446 /* DLGTEMPLATEEX (not defined in any std. header file) */
447
448 p++; /* dlgVer */
449 p++; /* signature */
450 p += 2; /* help ID */
451 p += 2; /* ext style */
452 p += 2; /* style */
453 }
454 else
455 {
456 /* DLGTEMPLATE */
457
458 p += 2; /* style */
459 p += 2; /* ext style */
460 }
461
462 p++; /* nb items */
463 p++; /* x */
464 p++; /* y */
465 width = (WORD)*p; p++;
466 height = (WORD)*p; p++;
467
468 if (lppsp->dwFlags & (PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE))
469 psInfo->ppshheader.dwFlags |= PSH_HEADER;
470
471 /* Special calculation for interior wizard pages so the largest page is
472 * calculated correctly. We need to add all the padding and space occupied
473 * by the header so the width and height sums up to the whole wizard client
474 * area. */
475 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
476 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
477 !(dwFlags & PSP_HIDEHEADER))
478 {
479 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
480 width += 2 * WIZARD_PADDING;
481 }
482 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
483 {
484 height += 2 * WIZARD_PADDING;
485 width += 2 * WIZARD_PADDING;
486 }
487
488 /* remember the largest width and height */
489 if (resize)
490 {
491 if (width > psInfo->width)
492 psInfo->width = width;
493
494 if (height > psInfo->height)
495 psInfo->height = height;
496 }
497
498 /* menu */
499 switch ((WORD)*p)
500 {
501 case 0x0000:
502 p++;
503 break;
504 case 0xffff:
505 p += 2;
506 break;
507 default:
508 p += lstrlenW( p ) + 1;
509 break;
510 }
511
512 /* class */
513 switch ((WORD)*p)
514 {
515 case 0x0000:
516 p++;
517 break;
518 case 0xffff:
519 p += 2;
520 break;
521 default:
522 p += lstrlenW( p ) + 1;
523 break;
524 }
525
526 /* Extract the caption */
527 psInfo->proppage[index].pszText = p;
528 TRACE("Tab %d %s\n",index,debugstr_w( p ));
529
530 if (dwFlags & PSP_USETITLE)
531 {
532 WCHAR szTitle[256];
533 const WCHAR *pTitle;
534 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
535
536 if (IS_INTRESOURCE( lppsp->pszTitle ))
537 {
538 if (LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle, szTitle, sizeof(szTitle)/sizeof(szTitle[0]) ))
539 pTitle = szTitle;
540 else if (*p)
541 pTitle = p;
542 else
543 pTitle = pszNull;
544 }
545 else
546 pTitle = lppsp->pszTitle;
547
548 psInfo->proppage[index].pszText = heap_strdupW( pTitle );
549 }
550
551 /*
552 * Build the image list for icons
553 */
554 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
555 {
556 HICON hIcon;
557 int icon_cx = GetSystemMetrics(SM_CXSMICON);
558 int icon_cy = GetSystemMetrics(SM_CYSMICON);
559
560 if (dwFlags & PSP_USEICONID)
561 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
562 icon_cx, icon_cy, LR_DEFAULTCOLOR);
563 else
564 hIcon = lppsp->u2.hIcon;
565
566 if ( hIcon )
567 {
568 if (psInfo->hImageList == 0 )
569 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
570
571 ImageList_AddIcon(psInfo->hImageList, hIcon);
572 }
573
574 }
575
576 return TRUE;
577 }
578
579 /******************************************************************************
580 * PROPSHEET_CreateDialog
581 *
582 * Creates the actual property sheet.
583 */
584 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
585 {
586 LRESULT ret;
587 LPCVOID template;
588 LPVOID temp = 0;
589 HRSRC hRes;
590 DWORD resSize;
591 WORD resID = IDD_PROPSHEET;
592
593 TRACE("(%p)\n", psInfo);
594 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
595 resID = IDD_WIZARD;
596
597 if( psInfo->unicode )
598 {
599 if(!(hRes = FindResourceW(COMCTL32_hModule,
600 MAKEINTRESOURCEW(resID),
601 (LPWSTR)RT_DIALOG)))
602 return -1;
603 }
604 else
605 {
606 if(!(hRes = FindResourceA(COMCTL32_hModule,
607 MAKEINTRESOURCEA(resID),
608 (LPSTR)RT_DIALOG)))
609 return -1;
610 }
611
612 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
613 return -1;
614
615 /*
616 * Make a copy of the dialog template.
617 */
618 resSize = SizeofResource(COMCTL32_hModule, hRes);
619
620 temp = Alloc(2 * resSize);
621
622 if (!temp)
623 return -1;
624
625 memcpy(temp, template, resSize);
626
627 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
628 {
629 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
630 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
631 else
632 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
633 }
634 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
635 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
636 {
637 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
638 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
639 else
640 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
641 }
642
643 if (psInfo->useCallback)
644 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
645
646 /* NOTE: MSDN states "Returns a positive value if successful, or -1
647 * otherwise for modal property sheets.", but this is wrong. The
648 * actual return value is either TRUE (success), FALSE (cancel) or
649 * -1 (error). */
650 if( psInfo->unicode )
651 {
652 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
653 temp, psInfo->ppshheader.hwndParent,
654 PROPSHEET_DialogProc, (LPARAM)psInfo);
655 if ( !ret ) ret = -1;
656 }
657 else
658 {
659 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
660 temp, psInfo->ppshheader.hwndParent,
661 PROPSHEET_DialogProc, (LPARAM)psInfo);
662 if ( !ret ) ret = -1;
663 }
664
665 Free(temp);
666
667 return ret;
668 }
669
670 /******************************************************************************
671 * PROPSHEET_SizeMismatch
672 *
673 * Verify that the tab control and the "largest" property sheet page dlg. template
674 * match in size.
675 */
676 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
677 {
678 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
679 RECT rcOrigTab, rcPage;
680
681 /*
682 * Original tab size.
683 */
684 GetClientRect(hwndTabCtrl, &rcOrigTab);
685 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
686
687 /*
688 * Biggest page size.
689 */
690 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
691 MapDialogRect(hwndDlg, &rcPage);
692 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
693
694 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
695 return TRUE;
696 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
697 return TRUE;
698
699 return FALSE;
700 }
701
702 /******************************************************************************
703 * PROPSHEET_AdjustSize
704 *
705 * Resizes the property sheet and the tab control to fit the largest page.
706 */
707 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
708 {
709 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
710 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
711 RECT rc,tabRect;
712 int buttonHeight;
713 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
714 RECT units;
715 LONG style;
716
717 /* Get the height of buttons */
718 GetClientRect(hwndButton, &rc);
719 buttonHeight = rc.bottom;
720
721 /*
722 * Biggest page size.
723 */
724 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
725 MapDialogRect(hwndDlg, &rc);
726
727 /* retrieve the dialog units */
728 units.left = units.right = 4;
729 units.top = units.bottom = 8;
730 MapDialogRect(hwndDlg, &units);
731
732 /*
733 * Resize the tab control.
734 */
735 GetClientRect(hwndTabCtrl,&tabRect);
736
737 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
738
739 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
740 {
741 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
742 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
743 }
744
745 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
746 {
747 rc.right = rc.left + tabRect.right - tabRect.left;
748 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
749 }
750
751 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
752
753 rc.right -= rc.left;
754 rc.bottom -= rc.top;
755 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
756 hwndTabCtrl, rc.right, rc.bottom);
757 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
758 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
759
760 GetClientRect(hwndTabCtrl, &rc);
761
762 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
763
764 rc.right += (padding.x * 2);
765 rc.bottom += buttonHeight + (3 * padding.y);
766
767 style = GetWindowLongW(hwndDlg, GWL_STYLE);
768 if (!(style & WS_CHILD))
769 AdjustWindowRect(&rc, style, FALSE);
770
771 rc.right -= rc.left;
772 rc.bottom -= rc.top;
773
774 /*
775 * Resize the property sheet.
776 */
777 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
778 hwndDlg, rc.right, rc.bottom);
779 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
780 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
781 return TRUE;
782 }
783
784 /******************************************************************************
785 * PROPSHEET_AdjustSizeWizard
786 *
787 * Resizes the property sheet to fit the largest page.
788 */
789 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
790 {
791 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
792 RECT rc, lineRect, dialogRect;
793
794 /* Biggest page size */
795 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
796 MapDialogRect(hwndDlg, &rc);
797
798 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
799
800 /* Add space for the buttons row */
801 GetWindowRect(hwndLine, &lineRect);
802 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
803 GetClientRect(hwndDlg, &dialogRect);
804 rc.bottom += dialogRect.bottom - lineRect.top - 1;
805
806 /* Convert the client coordinates to window coordinates */
807 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
808
809 /* Resize the property sheet */
810 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
811 hwndDlg, rc.right, rc.bottom);
812 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
813 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
814
815 return TRUE;
816 }
817
818 /******************************************************************************
819 * PROPSHEET_AdjustButtons
820 *
821 * Adjusts the buttons' positions.
822 */
823 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
824 {
825 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
826 RECT rcSheet;
827 int x, y;
828 int num_buttons = 2;
829 int buttonWidth, buttonHeight;
830 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
831
832 if (psInfo->hasApply)
833 num_buttons++;
834
835 if (psInfo->hasHelp)
836 num_buttons++;
837
838 /*
839 * Obtain the size of the buttons.
840 */
841 GetClientRect(hwndButton, &rcSheet);
842 buttonWidth = rcSheet.right;
843 buttonHeight = rcSheet.bottom;
844
845 /*
846 * Get the size of the property sheet.
847 */
848 GetClientRect(hwndParent, &rcSheet);
849
850 /*
851 * All buttons will be at this y coordinate.
852 */
853 y = rcSheet.bottom - (padding.y + buttonHeight);
854
855 /*
856 * Position OK button and make it default.
857 */
858 hwndButton = GetDlgItem(hwndParent, IDOK);
859
860 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
861
862 SetWindowPos(hwndButton, 0, x, y, 0, 0,
863 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
864
865 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
866
867
868 /*
869 * Position Cancel button.
870 */
871 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
872
873 x += padding.x + buttonWidth;
874
875 SetWindowPos(hwndButton, 0, x, y, 0, 0,
876 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
877
878 /*
879 * Position Apply button.
880 */
881 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
882
883 if(psInfo->hasApply)
884 x += padding.x + buttonWidth;
885 else
886 ShowWindow(hwndButton, SW_HIDE);
887
888 SetWindowPos(hwndButton, 0, x, y, 0, 0,
889 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
890 EnableWindow(hwndButton, FALSE);
891
892 /*
893 * Position Help button.
894 */
895 hwndButton = GetDlgItem(hwndParent, IDHELP);
896
897 x += padding.x + buttonWidth;
898 SetWindowPos(hwndButton, 0, x, y, 0, 0,
899 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
900
901 if(!psInfo->hasHelp)
902 ShowWindow(hwndButton, SW_HIDE);
903
904 return TRUE;
905 }
906
907 /******************************************************************************
908 * PROPSHEET_AdjustButtonsWizard
909 *
910 * Adjusts the buttons' positions.
911 */
912 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
913 const PropSheetInfo* psInfo)
914 {
915 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
916 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
917 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
918 RECT rcSheet;
919 int x, y;
920 int num_buttons = 3;
921 int buttonWidth, buttonHeight, lineHeight, lineWidth;
922 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
923
924 if (psInfo->hasHelp)
925 num_buttons++;
926 if (psInfo->hasFinish)
927 num_buttons++;
928
929 /*
930 * Obtain the size of the buttons.
931 */
932 GetClientRect(hwndButton, &rcSheet);
933 buttonWidth = rcSheet.right;
934 buttonHeight = rcSheet.bottom;
935
936 GetClientRect(hwndLine, &rcSheet);
937 lineHeight = rcSheet.bottom;
938
939 /*
940 * Get the size of the property sheet.
941 */
942 GetClientRect(hwndParent, &rcSheet);
943
944 /*
945 * All buttons will be at this y coordinate.
946 */
947 y = rcSheet.bottom - (padding.y + buttonHeight);
948
949 /*
950 * Position the Back button.
951 */
952 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
953
954 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
955
956 SetWindowPos(hwndButton, 0, x, y, 0, 0,
957 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
958
959 /*
960 * Position the Next button.
961 */
962 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
963
964 x += buttonWidth;
965
966 SetWindowPos(hwndButton, 0, x, y, 0, 0,
967 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968
969 /*
970 * Position the Finish button.
971 */
972 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
973
974 if (psInfo->hasFinish)
975 x += padding.x + buttonWidth;
976
977 SetWindowPos(hwndButton, 0, x, y, 0, 0,
978 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
979
980 if (!psInfo->hasFinish)
981 ShowWindow(hwndButton, SW_HIDE);
982
983 /*
984 * Position the Cancel button.
985 */
986 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
987
988 x += padding.x + buttonWidth;
989
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
992
993 /*
994 * Position Help button.
995 */
996 hwndButton = GetDlgItem(hwndParent, IDHELP);
997
998 if (psInfo->hasHelp)
999 {
1000 x += padding.x + buttonWidth;
1001
1002 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1003 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1004 }
1005 else
1006 ShowWindow(hwndButton, SW_HIDE);
1007
1008 if (psInfo->ppshheader.dwFlags &
1009 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1010 padding.x = 0;
1011
1012 /*
1013 * Position and resize the sunken line.
1014 */
1015 x = padding.x;
1016 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1017
1018 lineWidth = rcSheet.right - (padding.x * 2);
1019 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1020 SWP_NOZORDER | SWP_NOACTIVATE);
1021
1022 /*
1023 * Position and resize the header sunken line.
1024 */
1025
1026 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1027 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1028 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1029 ShowWindow(hwndLineHeader, SW_HIDE);
1030
1031 return TRUE;
1032 }
1033
1034 /******************************************************************************
1035 * PROPSHEET_GetPaddingInfo
1036 *
1037 * Returns the layout information.
1038 */
1039 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1040 {
1041 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1042 RECT rcTab;
1043 PADDING_INFO padding;
1044
1045 GetWindowRect(hwndTab, &rcTab);
1046 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1047
1048 padding.x = rcTab.left;
1049 padding.y = rcTab.top;
1050
1051 return padding;
1052 }
1053
1054 /******************************************************************************
1055 * PROPSHEET_GetPaddingInfoWizard
1056 *
1057 * Returns the layout information.
1058 * Vertical spacing is the distance between the line and the buttons.
1059 * Do NOT use the Help button to gather padding information when it isn't mapped
1060 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1061 * for it in this case !
1062 * FIXME: I'm not sure about any other coordinate problems with these evil
1063 * buttons. Fix it in case additional problems appear or maybe calculate
1064 * a padding in a completely different way, as this is somewhat messy.
1065 */
1066 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1067 psInfo)
1068 {
1069 PADDING_INFO padding;
1070 RECT rc;
1071 HWND hwndControl;
1072 INT idButton;
1073 POINT ptButton, ptLine;
1074
1075 TRACE("\n");
1076 if (psInfo->hasHelp)
1077 {
1078 idButton = IDHELP;
1079 }
1080 else
1081 {
1082 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1083 {
1084 idButton = IDC_NEXT_BUTTON;
1085 }
1086 else
1087 {
1088 /* hopefully this is ok */
1089 idButton = IDCANCEL;
1090 }
1091 }
1092
1093 hwndControl = GetDlgItem(hwndDlg, idButton);
1094 GetWindowRect(hwndControl, &rc);
1095 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1096 ptButton.x = rc.left;
1097 ptButton.y = rc.top;
1098
1099 /* Line */
1100 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1101 GetWindowRect(hwndControl, &rc);
1102 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1103 ptLine.x = rc.left;
1104 ptLine.y = rc.bottom;
1105
1106 padding.y = ptButton.y - ptLine.y;
1107
1108 if (padding.y < 0)
1109 ERR("padding negative ! Please report this !\n");
1110
1111 /* this is most probably not correct, but the best we have now */
1112 padding.x = padding.y;
1113 return padding;
1114 }
1115
1116 /******************************************************************************
1117 * PROPSHEET_CreateTabControl
1118 *
1119 * Insert the tabs in the tab control.
1120 */
1121 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1122 const PropSheetInfo * psInfo)
1123 {
1124 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1125 TCITEMW item;
1126 int i, nTabs;
1127 int iImage = 0;
1128
1129 TRACE("\n");
1130 item.mask = TCIF_TEXT;
1131 item.cchTextMax = MAX_TABTEXT_LENGTH;
1132
1133 nTabs = psInfo->nPages;
1134
1135 /*
1136 * Set the image list for icons.
1137 */
1138 if (psInfo->hImageList)
1139 {
1140 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1141 }
1142
1143 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1144 for (i = 0; i < nTabs; i++)
1145 {
1146 if ( psInfo->proppage[i].hasIcon )
1147 {
1148 item.mask |= TCIF_IMAGE;
1149 item.iImage = iImage++;
1150 }
1151 else
1152 {
1153 item.mask &= ~TCIF_IMAGE;
1154 }
1155
1156 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1157 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1158 }
1159 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1160
1161 return TRUE;
1162 }
1163
1164 /******************************************************************************
1165 * PROPSHEET_WizardSubclassProc
1166 *
1167 * Subclassing window procedure for wizard exterior pages to prevent drawing
1168 * background and so drawing above the watermark.
1169 */
1170 static LRESULT CALLBACK
1171 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1172 {
1173 switch (uMsg)
1174 {
1175 case WM_ERASEBKGND:
1176 return TRUE;
1177
1178 case WM_CTLCOLORSTATIC:
1179 #ifdef __REACTOS__
1180 SetBkMode((HDC)wParam, TRANSPARENT);
1181 return (INT_PTR)GetStockObject(HOLLOW_BRUSH);
1182 #else
1183 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1184 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1185 #endif
1186 }
1187
1188 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1189 }
1190
1191 /*
1192 * Get the size of an in-memory Template
1193 *
1194 *( Based on the code of PROPSHEET_CollectPageInfo)
1195 * See also dialog.c/DIALOG_ParseTemplate32().
1196 */
1197
1198 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1199
1200 {
1201 const WORD* p = (const WORD *)pTemplate;
1202 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1203 WORD nrofitems;
1204 UINT ret;
1205
1206 if (istemplateex)
1207 {
1208 /* DLGTEMPLATEEX (not defined in any std. header file) */
1209
1210 TRACE("is DLGTEMPLATEEX\n");
1211 p++; /* dlgVer */
1212 p++; /* signature */
1213 p += 2; /* help ID */
1214 p += 2; /* ext style */
1215 p += 2; /* style */
1216 }
1217 else
1218 {
1219 /* DLGTEMPLATE */
1220
1221 TRACE("is DLGTEMPLATE\n");
1222 p += 2; /* style */
1223 p += 2; /* ext style */
1224 }
1225
1226 nrofitems = (WORD)*p; p++; /* nb items */
1227 p++; /* x */
1228 p++; /* y */
1229 p++; /* width */
1230 p++; /* height */
1231
1232 /* menu */
1233 switch ((WORD)*p)
1234 {
1235 case 0x0000:
1236 p++;
1237 break;
1238 case 0xffff:
1239 p += 2;
1240 break;
1241 default:
1242 TRACE("menu %s\n",debugstr_w( p ));
1243 p += lstrlenW( p ) + 1;
1244 break;
1245 }
1246
1247 /* class */
1248 switch ((WORD)*p)
1249 {
1250 case 0x0000:
1251 p++;
1252 break;
1253 case 0xffff:
1254 p += 2; /* 0xffff plus predefined window class ordinal value */
1255 break;
1256 default:
1257 TRACE("class %s\n",debugstr_w( p ));
1258 p += lstrlenW( p ) + 1;
1259 break;
1260 }
1261
1262 /* title */
1263 TRACE("title %s\n",debugstr_w( p ));
1264 p += lstrlenW( p ) + 1;
1265
1266 /* font, if DS_SETFONT set */
1267 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1268 pTemplate->style)))
1269 {
1270 p+=(istemplateex)?3:1;
1271 TRACE("font %s\n",debugstr_w( p ));
1272 p += lstrlenW( p ) + 1; /* the font name */
1273 }
1274
1275 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1276 * that are following the DLGTEMPLATE(EX) data */
1277 TRACE("%d items\n",nrofitems);
1278 while (nrofitems > 0)
1279 {
1280 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1281
1282 /* skip header */
1283 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1284
1285 /* check class */
1286 switch ((WORD)*p)
1287 {
1288 case 0x0000:
1289 p++;
1290 break;
1291 case 0xffff:
1292 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1293 p += 2;
1294 break;
1295 default:
1296 TRACE("class %s\n",debugstr_w( p ));
1297 p += lstrlenW( p ) + 1;
1298 break;
1299 }
1300
1301 /* check title text */
1302 switch ((WORD)*p)
1303 {
1304 case 0x0000:
1305 p++;
1306 break;
1307 case 0xffff:
1308 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1309 p += 2;
1310 break;
1311 default:
1312 TRACE("text %s\n",debugstr_w( p ));
1313 p += lstrlenW( p ) + 1;
1314 break;
1315 }
1316 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1317 --nrofitems;
1318 }
1319
1320 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1321 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1322 return ret;
1323 }
1324
1325 /******************************************************************************
1326 * PROPSHEET_CreatePage
1327 *
1328 * Creates a page.
1329 */
1330 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1331 int index,
1332 const PropSheetInfo * psInfo,
1333 LPCPROPSHEETPAGEW ppshpage)
1334 {
1335 const DLGTEMPLATE* pTemplate;
1336 HWND hwndPage;
1337 DWORD resSize;
1338 DLGTEMPLATE* pTemplateCopy = NULL;
1339
1340 TRACE("index %d\n", index);
1341
1342 if (ppshpage == NULL)
1343 {
1344 return FALSE;
1345 }
1346
1347 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1348 {
1349 pTemplate = ppshpage->u.pResource;
1350 resSize = GetTemplateSize(pTemplate);
1351 }
1352 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1353 {
1354 HRSRC hResource;
1355 HANDLE hTemplate;
1356
1357 hResource = FindResourceW(ppshpage->hInstance,
1358 ppshpage->u.pszTemplate,
1359 (LPWSTR)RT_DIALOG);
1360 if(!hResource)
1361 return FALSE;
1362
1363 resSize = SizeofResource(ppshpage->hInstance, hResource);
1364
1365 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1366 if(!hTemplate)
1367 return FALSE;
1368
1369 pTemplate = LockResource(hTemplate);
1370 /*
1371 * Make a copy of the dialog template to make it writable
1372 */
1373 }
1374 else
1375 {
1376 HRSRC hResource;
1377 HANDLE hTemplate;
1378
1379 hResource = FindResourceA(ppshpage->hInstance,
1380 (LPCSTR)ppshpage->u.pszTemplate,
1381 (LPSTR)RT_DIALOG);
1382 if(!hResource)
1383 return FALSE;
1384
1385 resSize = SizeofResource(ppshpage->hInstance, hResource);
1386
1387 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1388 if(!hTemplate)
1389 return FALSE;
1390
1391 pTemplate = LockResource(hTemplate);
1392 /*
1393 * Make a copy of the dialog template to make it writable
1394 */
1395 }
1396 pTemplateCopy = Alloc(resSize);
1397 if (!pTemplateCopy)
1398 return FALSE;
1399
1400 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1401 memcpy(pTemplateCopy, pTemplate, resSize);
1402
1403 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1404 {
1405 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1406 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1407 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1408 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1409 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1410 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1411 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1412 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1413
1414 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1415 }
1416 else
1417 {
1418 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1419 pTemplateCopy->style &= ~DS_MODALFRAME;
1420 pTemplateCopy->style &= ~WS_CAPTION;
1421 pTemplateCopy->style &= ~WS_SYSMENU;
1422 pTemplateCopy->style &= ~WS_POPUP;
1423 pTemplateCopy->style &= ~WS_DISABLED;
1424 pTemplateCopy->style &= ~WS_VISIBLE;
1425 pTemplateCopy->style &= ~WS_THICKFRAME;
1426
1427 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1428 }
1429
1430 if (psInfo->proppage[index].useCallback)
1431 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1432 (LPPROPSHEETPAGEW)ppshpage);
1433
1434 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1435 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1436 pTemplateCopy,
1437 hwndParent,
1438 ppshpage->pfnDlgProc,
1439 (LPARAM)ppshpage);
1440 else
1441 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1442 pTemplateCopy,
1443 hwndParent,
1444 ppshpage->pfnDlgProc,
1445 (LPARAM)ppshpage);
1446 /* Free a no more needed copy */
1447 Free(pTemplateCopy);
1448
1449 if(!hwndPage)
1450 return FALSE;
1451
1452 psInfo->proppage[index].hwndPage = hwndPage;
1453
1454 /* Subclass exterior wizard pages */
1455 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1456 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1457 (ppshpage->dwFlags & PSP_HIDEHEADER))
1458 {
1459 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1460 (DWORD_PTR)ppshpage);
1461 }
1462 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1463 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1464
1465 return TRUE;
1466 }
1467
1468 /******************************************************************************
1469 * PROPSHEET_LoadWizardBitmaps
1470 *
1471 * Loads the watermark and header bitmaps for a wizard.
1472 */
1473 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1474 {
1475 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1476 {
1477 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1478 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1479 considers hbmWatermark as valid. */
1480 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1481 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1482 {
1483 psInfo->ppshheader.u4.hbmWatermark =
1484 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1485 }
1486
1487 /* Same behavior as for watermarks */
1488 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1489 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1490 {
1491 psInfo->ppshheader.u5.hbmHeader =
1492 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1493 }
1494 }
1495 }
1496
1497
1498 /******************************************************************************
1499 * PROPSHEET_ShowPage
1500 *
1501 * Displays or creates the specified page.
1502 */
1503 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1504 {
1505 HWND hwndTabCtrl;
1506 HWND hwndLineHeader;
1507 HWND control;
1508 LPCPROPSHEETPAGEW ppshpage;
1509
1510 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1511 if (index == psInfo->active_page)
1512 {
1513 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1514 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1515 return TRUE;
1516 }
1517
1518 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1519 if (psInfo->proppage[index].hwndPage == 0)
1520 {
1521 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1522 }
1523
1524 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1525 {
1526 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1527 psInfo->proppage[index].pszText);
1528
1529 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1530 if(control != NULL)
1531 SetFocus(control);
1532 }
1533
1534 if (psInfo->active_page != -1)
1535 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1536
1537 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1538
1539 /* Synchronize current selection with tab control
1540 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1541 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1542 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1543
1544 psInfo->active_page = index;
1545 psInfo->activeValid = TRUE;
1546
1547 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1548 {
1549 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1550 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1551
1552 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1553 ShowWindow(hwndLineHeader, SW_HIDE);
1554 else
1555 ShowWindow(hwndLineHeader, SW_SHOW);
1556 }
1557
1558 return TRUE;
1559 }
1560
1561 /******************************************************************************
1562 * PROPSHEET_Back
1563 */
1564 static BOOL PROPSHEET_Back(HWND hwndDlg)
1565 {
1566 PSHNOTIFY psn;
1567 HWND hwndPage;
1568 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1569 LRESULT result;
1570 int idx;
1571
1572 TRACE("active_page %d\n", psInfo->active_page);
1573 if (psInfo->active_page < 0)
1574 return FALSE;
1575
1576 psn.hdr.code = PSN_WIZBACK;
1577 psn.hdr.hwndFrom = hwndDlg;
1578 psn.hdr.idFrom = 0;
1579 psn.lParam = 0;
1580
1581 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1582
1583 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1584 if (result == -1)
1585 return FALSE;
1586 else if (result == 0)
1587 idx = psInfo->active_page - 1;
1588 else
1589 idx = PROPSHEET_FindPageByResId(psInfo, result);
1590
1591 if (idx >= 0 && idx < psInfo->nPages)
1592 {
1593 if (PROPSHEET_CanSetCurSel(hwndDlg))
1594 {
1595 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1596 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1597 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1598 }
1599 }
1600 return TRUE;
1601 }
1602
1603 /******************************************************************************
1604 * PROPSHEET_Next
1605 */
1606 static BOOL PROPSHEET_Next(HWND hwndDlg)
1607 {
1608 PSHNOTIFY psn;
1609 HWND hwndPage;
1610 LRESULT msgResult = 0;
1611 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1612 int idx;
1613
1614 TRACE("active_page %d\n", psInfo->active_page);
1615 if (psInfo->active_page < 0)
1616 return FALSE;
1617
1618 psn.hdr.code = PSN_WIZNEXT;
1619 psn.hdr.hwndFrom = hwndDlg;
1620 psn.hdr.idFrom = 0;
1621 psn.lParam = 0;
1622
1623 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1624
1625 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1626 if (msgResult == -1)
1627 return FALSE;
1628 else if (msgResult == 0)
1629 idx = psInfo->active_page + 1;
1630 else
1631 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1632
1633 if (idx < psInfo->nPages )
1634 {
1635 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1636 {
1637 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1638 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1639 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1640 }
1641 }
1642
1643 return TRUE;
1644 }
1645
1646 /******************************************************************************
1647 * PROPSHEET_Finish
1648 */
1649 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1650 {
1651 PSHNOTIFY psn;
1652 HWND hwndPage;
1653 LRESULT msgResult = 0;
1654 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1655
1656 TRACE("active_page %d\n", psInfo->active_page);
1657 if (psInfo->active_page < 0)
1658 return FALSE;
1659
1660 psn.hdr.code = PSN_WIZFINISH;
1661 psn.hdr.hwndFrom = hwndDlg;
1662 psn.hdr.idFrom = 0;
1663 psn.lParam = 0;
1664
1665 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1666
1667 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1668
1669 TRACE("msg result %ld\n", msgResult);
1670
1671 if (msgResult != 0)
1672 return FALSE;
1673
1674 if (psInfo->result == 0)
1675 psInfo->result = IDOK;
1676 if (psInfo->isModeless)
1677 psInfo->activeValid = FALSE;
1678 else
1679 psInfo->ended = TRUE;
1680
1681 return TRUE;
1682 }
1683
1684 /******************************************************************************
1685 * PROPSHEET_Apply
1686 */
1687 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1688 {
1689 int i;
1690 HWND hwndPage;
1691 PSHNOTIFY psn;
1692 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1693
1694 TRACE("active_page %d\n", psInfo->active_page);
1695 if (psInfo->active_page < 0)
1696 return FALSE;
1697
1698 psn.hdr.hwndFrom = hwndDlg;
1699 psn.hdr.idFrom = 0;
1700 psn.lParam = 0;
1701
1702
1703 /*
1704 * Send PSN_KILLACTIVE to the current page.
1705 */
1706 psn.hdr.code = PSN_KILLACTIVE;
1707
1708 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1709
1710 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1711 return FALSE;
1712
1713 /*
1714 * Send PSN_APPLY to all pages.
1715 */
1716 psn.hdr.code = PSN_APPLY;
1717 psn.lParam = lParam;
1718
1719 for (i = 0; i < psInfo->nPages; i++)
1720 {
1721 hwndPage = psInfo->proppage[i].hwndPage;
1722 if (hwndPage)
1723 {
1724 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1725 {
1726 case PSNRET_INVALID:
1727 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1728 /* fall through */
1729 case PSNRET_INVALID_NOCHANGEPAGE:
1730 return FALSE;
1731 }
1732 }
1733 }
1734
1735 if(lParam)
1736 {
1737 psInfo->activeValid = FALSE;
1738 }
1739 else if(psInfo->active_page >= 0)
1740 {
1741 psn.hdr.code = PSN_SETACTIVE;
1742 psn.lParam = 0;
1743 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1744 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1745 }
1746
1747 return TRUE;
1748 }
1749
1750 /******************************************************************************
1751 * PROPSHEET_Cancel
1752 */
1753 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1754 {
1755 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1756 HWND hwndPage;
1757 PSHNOTIFY psn;
1758 int i;
1759
1760 TRACE("active_page %d\n", psInfo->active_page);
1761 if (psInfo->active_page < 0)
1762 return;
1763
1764 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1765 psn.hdr.code = PSN_QUERYCANCEL;
1766 psn.hdr.hwndFrom = hwndDlg;
1767 psn.hdr.idFrom = 0;
1768 psn.lParam = 0;
1769
1770 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1771 return;
1772
1773 psn.hdr.code = PSN_RESET;
1774 psn.lParam = lParam;
1775
1776 for (i = 0; i < psInfo->nPages; i++)
1777 {
1778 hwndPage = psInfo->proppage[i].hwndPage;
1779
1780 if (hwndPage)
1781 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1782 }
1783
1784 if (psInfo->isModeless)
1785 {
1786 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1787 psInfo->activeValid = FALSE;
1788 }
1789 else
1790 psInfo->ended = TRUE;
1791 }
1792
1793 /******************************************************************************
1794 * PROPSHEET_Help
1795 */
1796 static void PROPSHEET_Help(HWND hwndDlg)
1797 {
1798 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1799 HWND hwndPage;
1800 PSHNOTIFY psn;
1801
1802 TRACE("active_page %d\n", psInfo->active_page);
1803 if (psInfo->active_page < 0)
1804 return;
1805
1806 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1807 psn.hdr.code = PSN_HELP;
1808 psn.hdr.hwndFrom = hwndDlg;
1809 psn.hdr.idFrom = 0;
1810 psn.lParam = 0;
1811
1812 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1813 }
1814
1815 /******************************************************************************
1816 * PROPSHEET_Changed
1817 */
1818 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1819 {
1820 int i;
1821 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1822
1823 TRACE("\n");
1824 if (!psInfo) return;
1825 /*
1826 * Set the dirty flag of this page.
1827 */
1828 for (i = 0; i < psInfo->nPages; i++)
1829 {
1830 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1831 psInfo->proppage[i].isDirty = TRUE;
1832 }
1833
1834 /*
1835 * Enable the Apply button.
1836 */
1837 if (psInfo->hasApply)
1838 {
1839 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1840
1841 EnableWindow(hwndApplyBtn, TRUE);
1842 }
1843 }
1844
1845 /******************************************************************************
1846 * PROPSHEET_UnChanged
1847 */
1848 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1849 {
1850 int i;
1851 BOOL noPageDirty = TRUE;
1852 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1853 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1854
1855 TRACE("\n");
1856 if ( !psInfo ) return;
1857 for (i = 0; i < psInfo->nPages; i++)
1858 {
1859 /* set the specified page as clean */
1860 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1861 psInfo->proppage[i].isDirty = FALSE;
1862
1863 /* look to see if there are any dirty pages */
1864 if (psInfo->proppage[i].isDirty)
1865 noPageDirty = FALSE;
1866 }
1867
1868 /*
1869 * Disable Apply button.
1870 */
1871 if (noPageDirty)
1872 EnableWindow(hwndApplyBtn, FALSE);
1873 }
1874
1875 /******************************************************************************
1876 * PROPSHEET_PressButton
1877 */
1878 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1879 {
1880 TRACE("buttonID %d\n", buttonID);
1881 switch (buttonID)
1882 {
1883 case PSBTN_APPLYNOW:
1884 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1885 break;
1886 case PSBTN_BACK:
1887 PROPSHEET_Back(hwndDlg);
1888 break;
1889 case PSBTN_CANCEL:
1890 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1891 break;
1892 case PSBTN_FINISH:
1893 PROPSHEET_Finish(hwndDlg);
1894 break;
1895 case PSBTN_HELP:
1896 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1897 break;
1898 case PSBTN_NEXT:
1899 PROPSHEET_Next(hwndDlg);
1900 break;
1901 case PSBTN_OK:
1902 PROPSHEET_DoCommand(hwndDlg, IDOK);
1903 break;
1904 default:
1905 FIXME("Invalid button index %d\n", buttonID);
1906 }
1907 }
1908
1909
1910 /*************************************************************************
1911 * BOOL PROPSHEET_CanSetCurSel [Internal]
1912 *
1913 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1914 *
1915 * PARAMS
1916 * hwndDlg [I] handle to a Dialog hWnd
1917 *
1918 * RETURNS
1919 * TRUE if Current Selection can change
1920 *
1921 * NOTES
1922 */
1923 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1924 {
1925 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1926 HWND hwndPage;
1927 PSHNOTIFY psn;
1928 BOOL res = FALSE;
1929
1930 if (!psInfo)
1931 {
1932 res = FALSE;
1933 goto end;
1934 }
1935
1936 TRACE("active_page %d\n", psInfo->active_page);
1937 if (psInfo->active_page < 0)
1938 {
1939 res = TRUE;
1940 goto end;
1941 }
1942
1943 /*
1944 * Notify the current page.
1945 */
1946 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1947 psn.hdr.code = PSN_KILLACTIVE;
1948 psn.hdr.hwndFrom = hwndDlg;
1949 psn.hdr.idFrom = 0;
1950 psn.lParam = 0;
1951
1952 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1953
1954 end:
1955 TRACE("<-- %d\n", res);
1956 return res;
1957 }
1958
1959 /******************************************************************************
1960 * PROPSHEET_SetCurSel
1961 */
1962 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1963 int index,
1964 int skipdir,
1965 HPROPSHEETPAGE hpage
1966 )
1967 {
1968 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1969 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1970 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1971
1972 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1973
1974 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1975
1976 if (index < 0 || index >= psInfo->nPages)
1977 {
1978 TRACE("Could not find page to select!\n");
1979 return FALSE;
1980 }
1981
1982 /* unset active page while doing this transition. */
1983 if (psInfo->active_page != -1)
1984 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1985 psInfo->active_page = -1;
1986
1987 while (1) {
1988 int result;
1989 PSHNOTIFY psn;
1990 RECT rc;
1991 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1992
1993 if (hwndTabControl)
1994 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
1995
1996 psn.hdr.code = PSN_SETACTIVE;
1997 psn.hdr.hwndFrom = hwndDlg;
1998 psn.hdr.idFrom = 0;
1999 psn.lParam = 0;
2000
2001 if (!psInfo->proppage[index].hwndPage) {
2002 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2003 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2004 if(index >= psInfo->nPages)
2005 index--;
2006 if(index < 0)
2007 return FALSE;
2008 continue;
2009 }
2010 }
2011
2012 /* Resize the property sheet page to the fit in the Tab control
2013 * (for regular property sheets) or to fit in the client area (for
2014 * wizards).
2015 * NOTE: The resizing happens every time the page is selected and
2016 * not only when it's created (some applications depend on it). */
2017 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2018 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2019 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2020 rc.right - rc.left, rc.bottom - rc.top);
2021 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2022 rc.left, rc.top,
2023 rc.right - rc.left, rc.bottom - rc.top, 0);
2024
2025 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2026 if (!result)
2027 break;
2028 if (result == -1) {
2029 index+=skipdir;
2030 if (index < 0) {
2031 index = 0;
2032 WARN("Tried to skip before first property sheet page!\n");
2033 break;
2034 }
2035 if (index >= psInfo->nPages) {
2036 WARN("Tried to skip after last property sheet page!\n");
2037 index = psInfo->nPages-1;
2038 break;
2039 }
2040 }
2041 else if (result != 0)
2042 {
2043 int old_index = index;
2044 index = PROPSHEET_FindPageByResId(psInfo, result);
2045 if(index >= psInfo->nPages) {
2046 index = old_index;
2047 WARN("Tried to skip to nonexistent page by res id\n");
2048 break;
2049 }
2050 continue;
2051 }
2052 }
2053
2054 /* Invalidate the header area */
2055 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2056 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2057 {
2058 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2059 RECT r;
2060
2061 GetClientRect(hwndLineHeader, &r);
2062 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2063 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2064
2065 InvalidateRect(hwndDlg, &r, TRUE);
2066 }
2067
2068 /*
2069 * Display the new page.
2070 */
2071 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2072
2073 if (psInfo->proppage[index].hasHelp)
2074 EnableWindow(hwndHelp, TRUE);
2075 else
2076 EnableWindow(hwndHelp, FALSE);
2077
2078 return TRUE;
2079 }
2080
2081 /******************************************************************************
2082 * PROPSHEET_SetCurSelId
2083 *
2084 * Selects the page, specified by resource id.
2085 */
2086 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2087 {
2088 int idx;
2089 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2090
2091 idx = PROPSHEET_FindPageByResId(psInfo, id);
2092 if (idx < psInfo->nPages )
2093 {
2094 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2095 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2096 }
2097 }
2098
2099 /******************************************************************************
2100 * PROPSHEET_SetTitleA
2101 */
2102 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2103 {
2104 if(!IS_INTRESOURCE(lpszText))
2105 {
2106 WCHAR szTitle[256];
2107 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2108 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2109 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2110 }
2111 else
2112 {
2113 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2114 }
2115 }
2116
2117 /******************************************************************************
2118 * PROPSHEET_SetTitleW
2119 */
2120 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2121 {
2122 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2123 WCHAR szTitle[256];
2124
2125 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2126 if (IS_INTRESOURCE(lpszText)) {
2127 if (!LoadStringW(psInfo->ppshheader.hInstance,
2128 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2129 return;
2130 lpszText = szTitle;
2131 }
2132 if (dwStyle & PSH_PROPTITLE)
2133 {
2134 WCHAR* dest;
2135 int lentitle = strlenW(lpszText);
2136 int lenprop = strlenW(psInfo->strPropertiesFor);
2137
2138 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2139 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2140
2141 SetWindowTextW(hwndDlg, dest);
2142 Free(dest);
2143 }
2144 else
2145 SetWindowTextW(hwndDlg, lpszText);
2146 }
2147
2148 /******************************************************************************
2149 * PROPSHEET_SetFinishTextA
2150 */
2151 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2152 {
2153 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2154 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2155
2156 TRACE("'%s'\n", lpszText);
2157 /* Set text, show and enable the Finish button */
2158 SetWindowTextA(hwndButton, lpszText);
2159 ShowWindow(hwndButton, SW_SHOW);
2160 EnableWindow(hwndButton, TRUE);
2161
2162 /* Make it default pushbutton */
2163 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2164
2165 /* Hide Back button */
2166 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2167 ShowWindow(hwndButton, SW_HIDE);
2168
2169 if (!psInfo->hasFinish)
2170 {
2171 /* Hide Next button */
2172 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2173 ShowWindow(hwndButton, SW_HIDE);
2174 }
2175 }
2176
2177 /******************************************************************************
2178 * PROPSHEET_SetFinishTextW
2179 */
2180 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2181 {
2182 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2183 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2184
2185 TRACE("%s\n", debugstr_w(lpszText));
2186 /* Set text, show and enable the Finish button */
2187 SetWindowTextW(hwndButton, lpszText);
2188 ShowWindow(hwndButton, SW_SHOW);
2189 EnableWindow(hwndButton, TRUE);
2190
2191 /* Make it default pushbutton */
2192 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2193
2194 /* Hide Back button */
2195 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2196 ShowWindow(hwndButton, SW_HIDE);
2197
2198 if (!psInfo->hasFinish)
2199 {
2200 /* Hide Next button */
2201 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2202 ShowWindow(hwndButton, SW_HIDE);
2203 }
2204 }
2205
2206 /******************************************************************************
2207 * PROPSHEET_QuerySiblings
2208 */
2209 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2210 WPARAM wParam, LPARAM lParam)
2211 {
2212 int i = 0;
2213 HWND hwndPage;
2214 LRESULT msgResult = 0;
2215 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2216
2217 while ((i < psInfo->nPages) && (msgResult == 0))
2218 {
2219 hwndPage = psInfo->proppage[i].hwndPage;
2220 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2221 i++;
2222 }
2223
2224 return msgResult;
2225 }
2226
2227 /******************************************************************************
2228 * PROPSHEET_InsertPage
2229 */
2230 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2231 {
2232 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2233 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2234 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2235 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2236 TCITEMW item;
2237 int index;
2238
2239 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2240
2241 if (IS_INTRESOURCE(hpageInsertAfter))
2242 index = LOWORD(hpageInsertAfter);
2243 else
2244 {
2245 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2246 if (index < 0)
2247 {
2248 TRACE("Could not find page to insert after!\n");
2249 return FALSE;
2250 }
2251 index++;
2252 }
2253
2254 if (index > psInfo->nPages)
2255 index = psInfo->nPages;
2256
2257 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2258 if (!ppi)
2259 return FALSE;
2260
2261 /*
2262 * Fill in a new PropPageInfo entry.
2263 */
2264 if (index > 0)
2265 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2266 memset(&ppi[index], 0, sizeof(PropPageInfo));
2267 if (index < psInfo->nPages)
2268 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2269 psInfo->proppage = ppi;
2270
2271 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
2272 {
2273 psInfo->proppage = prev_ppi;
2274 Free(ppi);
2275 return FALSE;
2276 }
2277
2278 psInfo->proppage[index].hpage = hpage;
2279
2280 if (ppsp->dwFlags & PSP_PREMATURE)
2281 {
2282 /* Create the page but don't show it */
2283 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
2284 {
2285 psInfo->proppage = prev_ppi;
2286 Free(ppi);
2287 return FALSE;
2288 }
2289 }
2290
2291 Free(prev_ppi);
2292 psInfo->nPages++;
2293 if (index <= psInfo->active_page)
2294 psInfo->active_page++;
2295
2296 /*
2297 * Add a new tab to the tab control.
2298 */
2299 item.mask = TCIF_TEXT;
2300 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2301 item.cchTextMax = MAX_TABTEXT_LENGTH;
2302
2303 if (psInfo->hImageList)
2304 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2305
2306 if (psInfo->proppage[index].hasIcon)
2307 {
2308 item.mask |= TCIF_IMAGE;
2309 item.iImage = index;
2310 }
2311
2312 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2313
2314 /* If it is the only page - show it */
2315 if (psInfo->nPages == 1)
2316 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2317
2318 return TRUE;
2319 }
2320
2321 /******************************************************************************
2322 * PROPSHEET_AddPage
2323 */
2324 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2325 {
2326 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2327 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2328 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2329 }
2330
2331 /******************************************************************************
2332 * PROPSHEET_RemovePage
2333 */
2334 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2335 int index,
2336 HPROPSHEETPAGE hpage)
2337 {
2338 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2339 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2340 PropPageInfo* oldPages;
2341
2342 TRACE("index %d, hpage %p\n", index, hpage);
2343 if (!psInfo) {
2344 return FALSE;
2345 }
2346
2347 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2348
2349 /* Make sure that index is within range */
2350 if (index < 0 || index >= psInfo->nPages)
2351 {
2352 TRACE("Could not find page to remove!\n");
2353 return FALSE;
2354 }
2355
2356 TRACE("total pages %d removing page %d active page %d\n",
2357 psInfo->nPages, index, psInfo->active_page);
2358 /*
2359 * Check if we're removing the active page.
2360 */
2361 if (index == psInfo->active_page)
2362 {
2363 if (psInfo->nPages > 1)
2364 {
2365 if (index > 0)
2366 {
2367 /* activate previous page */
2368 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2369 }
2370 else
2371 {
2372 /* activate the next page */
2373 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2374 psInfo->active_page = index;
2375 }
2376 }
2377 else
2378 {
2379 psInfo->active_page = -1;
2380 if (!psInfo->isModeless)
2381 {
2382 psInfo->ended = TRUE;
2383 return TRUE;
2384 }
2385 }
2386 }
2387 else if (index < psInfo->active_page)
2388 psInfo->active_page--;
2389
2390 /* Unsubclass the page dialog window */
2391 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2392 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2393 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2394 {
2395 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2396 PROPSHEET_WizardSubclassProc, 1);
2397 }
2398
2399 /* Destroy page dialog window */
2400 DestroyWindow(psInfo->proppage[index].hwndPage);
2401
2402 /* Free page resources */
2403 if(psInfo->proppage[index].hpage)
2404 {
2405 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2406
2407 if (psp->dwFlags & PSP_USETITLE)
2408 Free ((LPVOID)psInfo->proppage[index].pszText);
2409
2410 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2411 }
2412
2413 /* Remove the tab */
2414 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2415
2416 oldPages = psInfo->proppage;
2417 psInfo->nPages--;
2418 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2419
2420 if (index > 0)
2421 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2422
2423 if (index < psInfo->nPages)
2424 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2425 (psInfo->nPages - index) * sizeof(PropPageInfo));
2426
2427 Free(oldPages);
2428
2429 return FALSE;
2430 }
2431
2432 /******************************************************************************
2433 * PROPSHEET_SetWizButtons
2434 *
2435 * This code will work if (and assumes that) the Next button is on top of the
2436 * Finish button. ie. Finish comes after Next in the Z order.
2437 * This means make sure the dialog template reflects this.
2438 *
2439 */
2440 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2441 {
2442 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2443 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2444 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2445 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2446 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2447
2448 #ifdef __REACTOS__
2449 HWND hwndCancel = GetDlgItem(hwndDlg, IDCANCEL);
2450 INT iDefItem = 0;
2451 HWND hwndFocus;
2452 #endif
2453
2454 TRACE("%d\n", dwFlags);
2455
2456 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2457 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2458 EnableWindow(hwndFinish, enable_finish);
2459
2460 #ifndef __REACTOS__
2461 /* set the default pushbutton to an enabled button */
2462 if (enable_finish)
2463 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2464 else if (dwFlags & PSWIZB_NEXT)
2465 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2466 else if (dwFlags & PSWIZB_BACK)
2467 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2468 else
2469 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2470 #endif
2471
2472 if (!psInfo->hasFinish)
2473 {
2474 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2475 {
2476 /* Hide the Next button */
2477 ShowWindow(hwndNext, SW_HIDE);
2478
2479 /* Show the Finish button */
2480 ShowWindow(hwndFinish, SW_SHOW);
2481 }
2482 else
2483 {
2484 /* Hide the Finish button */
2485 ShowWindow(hwndFinish, SW_HIDE);
2486 /* Show the Next button */
2487 ShowWindow(hwndNext, SW_SHOW);
2488 }
2489 }
2490
2491 #ifdef __REACTOS__
2492 /* set the default pushbutton to an enabled button */
2493 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2494 iDefItem = IDC_FINISH_BUTTON;
2495 else if (dwFlags & PSWIZB_NEXT)
2496 iDefItem = IDC_NEXT_BUTTON;
2497 else if (dwFlags & PSWIZB_BACK)
2498 iDefItem = IDC_BACK_BUTTON;
2499 else
2500 iDefItem = IDCANCEL;
2501 SendMessageW(hwndDlg, DM_SETDEFID, iDefItem, 0);
2502
2503 /* Set focus if no control has it */
2504 hwndFocus = GetFocus();
2505 if (!hwndFocus || hwndFocus == hwndCancel)
2506 SetFocus(GetDlgItem(hwndDlg, iDefItem));
2507 #endif
2508
2509 }
2510
2511 /******************************************************************************
2512 * PROPSHEET_SetHeaderTitleW
2513 */
2514 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2515 {
2516 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2517 PROPSHEETPAGEW *page;
2518
2519 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2520
2521 if (page_index >= psInfo->nPages)
2522 return;
2523
2524 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2525
2526 if (!IS_INTRESOURCE(page->pszHeaderTitle))
2527 Free((void *)page->pszHeaderTitle);
2528
2529 page->pszHeaderTitle = heap_strdupW(title);
2530 page->dwFlags |= PSP_USEHEADERTITLE;
2531 }
2532
2533 /******************************************************************************
2534 * PROPSHEET_SetHeaderTitleA
2535 */
2536 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2537 {
2538 WCHAR *titleW;
2539
2540 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2541
2542 titleW = heap_strdupAtoW(title);
2543 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2544 Free(titleW);
2545 }
2546
2547 /******************************************************************************
2548 * PROPSHEET_SetHeaderSubTitleW
2549 */
2550 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2551 {
2552 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2553 PROPSHEETPAGEW *page;
2554
2555 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2556
2557 if (page_index >= psInfo->nPages)
2558 return;
2559
2560 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2561
2562 if (!IS_INTRESOURCE(page->pszHeaderSubTitle))
2563 Free((void *)page->pszHeaderSubTitle);
2564
2565 page->pszHeaderSubTitle = heap_strdupW(subtitle);
2566 page->dwFlags |= PSP_USEHEADERSUBTITLE;
2567 }
2568
2569 /******************************************************************************
2570 * PROPSHEET_SetHeaderSubTitleA
2571 */
2572 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2573 {
2574 WCHAR *subtitleW;
2575
2576 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2577
2578 subtitleW = heap_strdupAtoW(subtitle);
2579 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2580 Free(subtitleW);
2581 }
2582
2583 /******************************************************************************
2584 * PROPSHEET_HwndToIndex
2585 */
2586 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2587 {
2588 int index;
2589 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2590
2591 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2592
2593 for (index = 0; index < psInfo->nPages; index++)
2594 if (psInfo->proppage[index].hwndPage == hPageDlg)
2595 return index;
2596 WARN("%p not found\n", hPageDlg);
2597 return -1;
2598 }
2599
2600 /******************************************************************************
2601 * PROPSHEET_IndexToHwnd
2602 */
2603 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2604 {
2605 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2606 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2607 if (!psInfo)
2608 return 0;
2609 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2610 WARN("%d out of range.\n", iPageIndex);
2611 return 0;
2612 }
2613 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2614 }
2615
2616 /******************************************************************************
2617 * PROPSHEET_PageToIndex
2618 */
2619 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2620 {
2621 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2622
2623 TRACE("(%p, %p)\n", hwndDlg, hPage);
2624
2625 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2626 }
2627
2628 /******************************************************************************
2629 * PROPSHEET_IndexToPage
2630 */
2631 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2632 {
2633 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2634 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2635 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2636 WARN("%d out of range.\n", iPageIndex);
2637 return 0;
2638 }
2639 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2640 }
2641
2642 /******************************************************************************
2643 * PROPSHEET_IdToIndex
2644 */
2645 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2646 {
2647 int index;
2648 LPCPROPSHEETPAGEW psp;
2649 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2650 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2651 for (index = 0; index < psInfo->nPages; index++) {
2652 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2653 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2654 return index;
2655 }
2656
2657 return -1;
2658 }
2659
2660 /******************************************************************************
2661 * PROPSHEET_IndexToId
2662 */
2663 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2664 {
2665 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2666 LPCPROPSHEETPAGEW psp;
2667 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2668 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2669 WARN("%d out of range.\n", iPageIndex);
2670 return 0;
2671 }
2672 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2673 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2674 return 0;
2675 }
2676 return (LRESULT)psp->u.pszTemplate;
2677 }
2678
2679 /******************************************************************************
2680 * PROPSHEET_GetResult
2681 */
2682 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2683 {
2684 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2685 return psInfo->result;
2686 }
2687
2688 /******************************************************************************
2689 * PROPSHEET_RecalcPageSizes
2690 */
2691 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2692 {
2693 FIXME("(%p): stub\n", hwndDlg);
2694 return FALSE;
2695 }
2696
2697 /******************************************************************************
2698 * PROPSHEET_GetPageIndex
2699 *
2700 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2701 * the array of PropPageInfo. If page is not found original index is used
2702 * (page takes precedence over index).
2703 */
2704 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2705 {
2706 int index;
2707
2708 TRACE("page %p index %d\n", page, original_index);
2709
2710 for (index = 0; index < psInfo->nPages; index++)
2711 if (psInfo->proppage[index].hpage == page)
2712 return index;
2713
2714 return original_index;
2715 }
2716
2717 /******************************************************************************
2718 * PROPSHEET_CleanUp
2719 */
2720 static void PROPSHEET_CleanUp(HWND hwndDlg)
2721 {
2722 int i;
2723 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2724
2725 TRACE("\n");
2726 if (!psInfo) return;
2727 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2728 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2729
2730 for (i = 0; i < psInfo->nPages; i++)
2731 {
2732 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2733
2734 /* Unsubclass the page dialog window */
2735 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2736 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2737 (psp->dwFlags & PSP_HIDEHEADER))
2738 {
2739 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2740 PROPSHEET_WizardSubclassProc, 1);
2741 }
2742
2743 if(psInfo->proppage[i].hwndPage)
2744 DestroyWindow(psInfo->proppage[i].hwndPage);
2745
2746 if(psp)
2747 {
2748 if (psp->dwFlags & PSP_USETITLE)
2749 Free ((LPVOID)psInfo->proppage[i].pszText);
2750
2751 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2752 }
2753 }
2754
2755 DeleteObject(psInfo->hFont);
2756 DeleteObject(psInfo->hFontBold);
2757 /* If we created the bitmaps, destroy them */
2758 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2759 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2760 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2761 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2762 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2763 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2764
2765 Free(psInfo->proppage);
2766 Free(psInfo->strPropertiesFor);
2767 ImageList_Destroy(psInfo->hImageList);
2768
2769 GlobalFree(psInfo);
2770 }
2771
2772 static INT do_loop(const PropSheetInfo *psInfo)
2773 {
2774 MSG msg;
2775 INT ret = -1;
2776 HWND hwnd = psInfo->hwnd;
2777 HWND parent = psInfo->ppshheader.hwndParent;
2778
2779 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2780 {
2781 if(ret == -1)
2782 break;
2783
2784 if(!IsDialogMessageW(hwnd, &msg))
2785 {
2786 TranslateMessage(&msg);
2787 DispatchMessageW(&msg);
2788 }
2789 }
2790
2791 if(ret == 0)
2792 {
2793 PostQuitMessage(msg.wParam);
2794 ret = -1;
2795 }
2796
2797 if(ret != -1)
2798 ret = psInfo->result;
2799
2800 if(parent)
2801 EnableWindow(parent, TRUE);
2802
2803 DestroyWindow(hwnd);
2804 return ret;
2805 }
2806
2807 /******************************************************************************
2808 * PROPSHEET_PropertySheet
2809 *
2810 * Common code between PropertySheetA/W
2811 */
2812 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2813 {
2814 INT_PTR bRet = 0;
2815 HWND parent = NULL;
2816 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2817 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2818
2819 psInfo->unicode = unicode;
2820 psInfo->ended = FALSE;
2821
2822 if(!psInfo->isModeless)
2823 {
2824 parent = psInfo->ppshheader.hwndParent;
2825 if (parent) EnableWindow(parent, FALSE);
2826 }
2827 bRet = PROPSHEET_CreateDialog(psInfo);
2828 if(!psInfo->isModeless)
2829 bRet = do_loop(psInfo);
2830 return bRet;
2831 }
2832
2833 /******************************************************************************
2834 * PropertySheet (COMCTL32.@)
2835 * PropertySheetA (COMCTL32.@)
2836 *
2837 * Creates a property sheet in the specified property sheet header.
2838 *
2839 * RETURNS
2840 * Modal property sheets: Positive if successful or -1 otherwise.
2841 * Modeless property sheets: Property sheet handle.
2842 * Or:
2843 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2844 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2845 */
2846 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2847 {
2848 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2849 UINT i, n;
2850 const BYTE* pByte;
2851
2852 TRACE("(%p)\n", lppsh);
2853
2854 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2855
2856 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2857 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2858
2859 for (n = i = 0; i < lppsh->nPages; i++, n++)
2860 {
2861 if (!psInfo->usePropPage)
2862 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2863 else
2864 {
2865 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2866 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2867 }
2868
2869 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2870 psInfo, n, TRUE))
2871 {
2872 if (psInfo->usePropPage)
2873 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2874 n--;
2875 psInfo->nPages--;
2876 }
2877 }
2878
2879 return PROPSHEET_PropertySheet(psInfo, FALSE);
2880 }
2881
2882 /******************************************************************************
2883 * PropertySheetW (COMCTL32.@)
2884 *
2885 * See PropertySheetA.
2886 */
2887 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2888 {
2889 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2890 UINT i, n;
2891 const BYTE* pByte;
2892
2893 TRACE("(%p)\n", lppsh);
2894
2895 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2896
2897 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2898 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2899
2900 for (n = i = 0; i < lppsh->nPages; i++, n++)
2901 {
2902 if (!psInfo->usePropPage)
2903 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2904 else
2905 {
2906 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2907 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2908 }
2909
2910 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2911 psInfo, n, TRUE))
2912 {
2913 if (psInfo->usePropPage)
2914 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2915 n--;
2916 psInfo->nPages--;
2917 }
2918 }
2919
2920 return PROPSHEET_PropertySheet(psInfo, TRUE);
2921 }
2922
2923 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2924 {
2925 LPWSTR ret;
2926
2927 if (IS_INTRESOURCE(str))
2928 {
2929 HRSRC hrsrc;
2930 HGLOBAL hmem;
2931 WCHAR *ptr;
2932 WORD i, id = LOWORD(str);
2933 UINT len;
2934
2935 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2936 return NULL;
2937 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2938 if (!(ptr = LockResource( hmem ))) return NULL;
2939 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2940 len = *ptr;
2941 if (!len) return NULL;
2942 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2943 if (ret)
2944 {
2945 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2946 ret[len] = 0;
2947 }
2948 }
2949 else
2950 {
2951 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2952 ret = Alloc( len );
2953 if (ret) memcpy( ret, str, len );
2954 }
2955 return ret;
2956 }
2957
2958
2959 /******************************************************************************
2960 * CreatePropertySheetPage (COMCTL32.@)
2961 * CreatePropertySheetPageA (COMCTL32.@)
2962 *
2963 * Creates a new property sheet page.
2964 *
2965 * RETURNS
2966 * Success: Handle to new property sheet page.
2967 * Failure: NULL.
2968 *
2969 * NOTES
2970 * An application must use the PSM_ADDPAGE message to add the new page to
2971 * an existing property sheet.
2972 */
2973 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2974 LPCPROPSHEETPAGEA lpPropSheetPage)
2975 {
2976 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2977
2978 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2979
2980 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2981
2982 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2983 {
2984 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2985 {
2986 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2987 char *template = Alloc( len );
2988
2989 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2990 }
2991 }
2992
2993 if (ppsp->dwFlags & PSP_USEICONID)
2994 {
2995 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2996 ppsp->u2.pszIcon = heap_strdupAtoW( lpPropSheetPage->u2.pszIcon );
2997 }
2998
2999 if (ppsp->dwFlags & PSP_USETITLE)
3000 {
3001 if (IS_INTRESOURCE( ppsp->pszTitle ))
3002 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3003 else
3004 ppsp->pszTitle = heap_strdupAtoW( lpPropSheetPage->pszTitle );
3005 }
3006 else
3007 ppsp->pszTitle = NULL;
3008
3009 if (ppsp->dwFlags & PSP_HIDEHEADER)
3010 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3011
3012 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3013 {
3014 if (IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3015 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3016 else
3017 ppsp->pszHeaderTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderTitle );
3018 }
3019 else
3020 ppsp->pszHeaderTitle = NULL;
3021
3022 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3023 {
3024 if (IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3025 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3026 else
3027 ppsp->pszHeaderSubTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderSubTitle );
3028 }
3029 else
3030 ppsp->pszHeaderSubTitle = NULL;
3031
3032 if ((ppsp->dwFlags & PSH_USECALLBACK) && ppsp->pfnCallback)
3033 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp);
3034
3035 return (HPROPSHEETPAGE)ppsp;
3036 }
3037
3038 /******************************************************************************
3039 * CreatePropertySheetPageW (COMCTL32.@)
3040 *
3041 * See CreatePropertySheetA.
3042 */
3043 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3044 {
3045 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3046
3047 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3048
3049 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3050
3051 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3052 {
3053 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3054 ppsp->u.pszTemplate = heap_strdupW( lpPropSheetPage->u.pszTemplate );
3055 }
3056
3057 if ( ppsp->dwFlags & PSP_USEICONID )
3058 {
3059 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3060 ppsp->u2.pszIcon = heap_strdupW( lpPropSheetPage->u2.pszIcon );
3061 }
3062
3063 if (ppsp->dwFlags & PSP_USETITLE)
3064 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3065 else
3066 ppsp->pszTitle = NULL;
3067
3068 if (ppsp->dwFlags & PSP_HIDEHEADER)
3069 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3070
3071 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3072 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3073 else
3074 ppsp->pszHeaderTitle = NULL;
3075
3076 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3077 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3078 else
3079 ppsp->pszHeaderSubTitle = NULL;
3080
3081 if ((ppsp->dwFlags & PSH_USECALLBACK) && ppsp->pfnCallback)
3082 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp);
3083
3084 return (HPROPSHEETPAGE)ppsp;
3085 }
3086
3087 /******************************************************************************
3088 * DestroyPropertySheetPage (COMCTL32.@)
3089 *
3090 * Destroys a property sheet page previously created with
3091 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3092 * memory.
3093 *
3094 * RETURNS
3095 * Success: TRUE
3096 * Failure: FALSE
3097 */
3098 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3099 {
3100 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3101
3102 if (!psp)
3103 return FALSE;
3104
3105 if ((psp->dwFlags & PSH_USECALLBACK) && psp->pfnCallback)
3106 psp->pfnCallback(0, PSPCB_RELEASE, psp);
3107
3108 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3109 Free ((LPVOID)psp->u.pszTemplate);
3110
3111 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3112 Free ((LPVOID)psp->u2.pszIcon);
3113
3114 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3115 Free ((LPVOID)psp->pszTitle);
3116
3117 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3118 Free ((LPVOID)psp->pszHeaderTitle);
3119
3120 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3121 Free ((LPVOID)psp->pszHeaderSubTitle);
3122
3123 Free(hPropPage);
3124
3125 return TRUE;
3126 }
3127
3128 /******************************************************************************
3129 * PROPSHEET_IsDialogMessage
3130 */
3131 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3132 {
3133 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3134
3135 TRACE("\n");
3136 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3137 return FALSE;
3138
3139 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3140 {
3141 int new_page = 0;
3142 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3143
3144 if (!(dlgCode & DLGC_WANTMESSAGE))
3145 {
3146 switch (lpMsg->wParam)
3147 {
3148 case VK_TAB:
3149 if (GetKeyState(VK_SHIFT) & 0x8000)
3150 new_page = -1;
3151 else
3152 new_page = 1;
3153 break;
3154
3155 case VK_NEXT: new_page = 1; break;
3156 case VK_PRIOR: new_page = -1; break;
3157 }
3158 }
3159
3160 if (new_page)
3161 {
3162 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3163 {
3164 new_page += psInfo->active_page;
3165
3166 if (new_page < 0)
3167 new_page = psInfo->nPages - 1;
3168 else if (new_page >= psInfo->nPages)
3169 new_page = 0;
3170
3171 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3172 }
3173
3174 return TRUE;
3175 }
3176 }
3177
3178 return IsDialogMessageW(hwnd, lpMsg);
3179 }
3180
3181 /******************************************************************************
3182 * PROPSHEET_DoCommand
3183 */
3184 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3185 {
3186
3187 switch (wID) {
3188
3189 case IDOK:
3190 case IDC_APPLY_BUTTON:
3191 {
3192 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3193
3194 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3195 break;
3196
3197 if (wID == IDOK)
3198 {
3199 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3200
3201 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3202 if (psInfo->result == 0)
3203 psInfo->result = IDOK;
3204
3205 if (psInfo->isModeless)
3206 psInfo->activeValid = FALSE;
3207 else
3208 psInfo->ended = TRUE;
3209 }
3210 else
3211 EnableWindow(hwndApplyBtn, FALSE);
3212
3213 break;
3214 }
3215
3216 case IDC_BACK_BUTTON:
3217 PROPSHEET_Back(hwnd);
3218 break;
3219
3220 case IDC_NEXT_BUTTON:
3221 PROPSHEET_Next(hwnd);
3222 break;
3223
3224 case IDC_FINISH_BUTTON:
3225 PROPSHEET_Finish(hwnd);
3226 break;
3227
3228 case IDCANCEL:
3229 PROPSHEET_Cancel(hwnd, 0);
3230 break;
3231
3232 case IDHELP:
3233 PROPSHEET_Help(hwnd);
3234 break;
3235
3236 default:
3237 return FALSE;
3238 }
3239
3240 return TRUE;
3241 }
3242
3243 /******************************************************************************
3244 * PROPSHEET_Paint
3245 */
3246 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3247 {
3248 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3249 PAINTSTRUCT ps;
3250 HDC hdc, hdcSrc;
3251 BITMAP bm;
3252 HBITMAP hbmp;
3253 HPALETTE hOldPal = 0;
3254 int offsety = 0;
3255 HBRUSH hbr;
3256 RECT r, rzone;
3257 LPCPROPSHEETPAGEW ppshpage;
3258 WCHAR szBuffer[256];
3259 int nLength;
3260
3261 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3262 if (!hdc) return 1;
3263
3264 hdcSrc = CreateCompatibleDC(0);
3265
3266 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3267 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3268
3269 if (psInfo->active_page < 0)
3270 ppshpage = NULL;
3271 else
3272 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3273
3274 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3275 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3276 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3277 {
3278 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3279 HFONT hOldFont;
3280 COLORREF clrOld = 0;
3281 int oldBkMode = 0;
3282
3283 GetClientRect(hwndLineHeader, &r);
3284 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3285 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3286
3287 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3288
3289 #ifdef __REACTOS__
3290 if (psInfo->ppshheader.u5.hbmHeader)
3291 #else
3292 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3293 #endif
3294 {
3295 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3296
3297 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3298 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3299 {
3300 /* Fill the unoccupied part of the header with color of the
3301 * left-top pixel, but do it only when needed.
3302 */
3303 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3304 {
3305 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3306 r = rzone;
3307 if (bm.bmWidth < r.right)
3308 {
3309 r.left = bm.bmWidth;
3310 FillRect(hdc, &r, hbr);
3311 }
3312 if (bm.bmHeight < r.bottom)
3313 {
3314 r.left = 0;
3315 r.top = bm.bmHeight;
3316 FillRect(hdc, &r, hbr);
3317 }
3318 DeleteObject(hbr);
3319 }
3320
3321 /* Draw the header itself. */
3322 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3323 hdcSrc, 0, 0, SRCCOPY);
3324 }
3325 else
3326 {
3327 int margin;
3328 hbr = GetSysColorBrush(COLOR_WINDOW);
3329 FillRect(hdc, &rzone, hbr);
3330
3331 /* Draw the header bitmap. It's always centered like a
3332 * common 49 x 49 bitmap. */
3333 margin = (rzone.bottom - 49) / 2;
3334 BitBlt(hdc, rzone.right - 49 - margin, margin,
3335 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3336 hdcSrc, 0, 0, SRCCOPY);
3337
3338 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3339 * if its height is smaller than 49 pixels. Because the reason
3340 * for this bug is unknown the current code doesn't try to
3341 * replicate it. */
3342 }
3343
3344 SelectObject(hdcSrc, hbmp);
3345 }
3346
3347 clrOld = SetTextColor (hdc, 0x00000000);
3348 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3349
3350 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3351 SetRect(&r, 20, 10, 0, 0);
3352 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3353 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3354 else
3355 {
3356 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3357 szBuffer, 256);
3358 if (nLength != 0)
3359 {
3360 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3361 }
3362 }
3363 }
3364
3365 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3366 SelectObject(hdc, psInfo->hFont);
3367 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3368 #ifdef __REACTOS__
3369 if (!IS_INTRESOURCE(ppshpage->pszHeaderSubTitle))
3370 #else
3371 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3372 #endif
3373 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3374 else
3375 {
3376 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3377 szBuffer, 256);
3378 if (nLength != 0)
3379 {
3380 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3381 }
3382 }
3383 }
3384
3385 offsety = rzone.bottom + 2;
3386
3387 SetTextColor(hdc, clrOld);
3388 SetBkMode(hdc, oldBkMode);
3389 SelectObject(hdc, hOldFont);
3390 }
3391
3392 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3393 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3394 #ifdef __REACTOS__
3395 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
3396 (psInfo->ppshheader.u4.hbmWatermark) )
3397 #else
3398 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3399 #endif
3400 {
3401 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3402
3403 GetClientRect(hwndLine, &r);
3404 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3405 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3406
3407 hbr = GetSysColorBrush(COLOR_WINDOW);
3408 FillRect(hdc, &rzone, hbr);
3409
3410 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3411 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3412
3413 /* The watermark is truncated to a width of 164 pixels */
3414 r.right = min(r.right, 164);
3415 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3416 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3417
3418 /* If the bitmap is not big enough, fill the remaining area
3419 with the color of pixel (0,0) of bitmap - see MSDN */
3420 if (r.top > bm.bmHeight) {
3421 r.bottom = r.top - 1;
3422 r.top = bm.bmHeight;
3423 r.left = 0;
3424 r.right = bm.bmWidth;
3425 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3426 FillRect(hdc, &r, hbr);
3427 DeleteObject(hbr);
3428 }
3429
3430 SelectObject(hdcSrc, hbmp);
3431 }
3432
3433 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3434 SelectPalette(hdc, hOldPal, FALSE);
3435
3436 DeleteDC(hdcSrc);
3437
3438 if (!hdcParam) EndPaint(hwnd, &ps);
3439
3440 return 0;
3441 }
3442
3443 /******************************************************************************
3444 * PROPSHEET_DialogProc
3445 */
3446 static INT_PTR CALLBACK
3447 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3448 {
3449 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3450 hwnd, uMsg, wParam, lParam);
3451
3452 switch (uMsg)
3453 {
3454 case WM_INITDIALOG:
3455 {
3456 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3457 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3458 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3459 int idx;
3460 LOGFONTW logFont;
3461
3462 /* Using PropSheetInfoStr to store extra data doesn't match the native
3463 * common control: native uses TCM_[GS]ETITEM
3464 */
3465 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3466
3467 /*
3468 * psInfo->hwnd is not being used by WINE code - it exists
3469 * for compatibility with "real" Windoze. The same about
3470 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3471 * property.
3472 */
3473 psInfo->hwnd = hwnd;
3474 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3475
3476 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3477 {
3478 /* set up the Next and Back buttons by default */
3479 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3480 }
3481
3482 /* Set up fonts */
3483 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3484 psInfo->hFont = CreateFontIndirectW (&logFont);
3485 logFont.lfWeight = FW_BOLD;
3486 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3487
3488 /*
3489 * Small icon in the title bar.
3490 */
3491 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3492 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3493 {
3494 HICON hIcon;
3495 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3496 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3497
3498 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3499 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3500 psInfo->ppshheader.u.pszIcon,
3501 IMAGE_ICON,
3502 icon_cx, icon_cy,
3503 LR_DEFAULTCOLOR);
3504 else
3505 hIcon = psInfo->ppshheader.u.hIcon;
3506
3507 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3508 }
3509
3510 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3511 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3512
3513 psInfo->strPropertiesFor = strCaption;
3514
3515 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3516
3517 PROPSHEET_CreateTabControl(hwnd, psInfo);
3518
3519 PROPSHEET_LoadWizardBitmaps(psInfo);
3520
3521 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3522 {
3523 ShowWindow(hwndTabCtrl, SW_HIDE);
3524 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3525 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3526 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3527 }
3528 else
3529 {
3530 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3531 {
3532 PROPSHEET_AdjustSize(hwnd, psInfo);
3533 PROPSHEET_AdjustButtons(hwnd, psInfo);
3534 }
3535 SetFocus(GetDlgItem(hwnd, IDOK));
3536 }
3537
3538 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3539 psInfo->ppshheader.hInstance)
3540 {
3541 WCHAR szText[256];
3542
3543 if (LoadStringW(psInfo->ppshheader.hInstance,
3544 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3545 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3546 }
3547 else
3548 {
3549 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3550 psInfo->ppshheader.pszCaption);
3551 }
3552
3553
3554 if (psInfo->useCallback)
3555 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3556
3557 idx = psInfo->active_page;
3558 psInfo->active_page = -1;
3559
3560 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3561
3562 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3563 * as some programs call TCM_GETCURSEL to get the current selection
3564 * from which to switch to the next page */
3565 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3566
3567 PROPSHEET_UnChanged(hwnd, NULL);
3568
3569 /* wizards set their focus during init */
3570 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3571 return FALSE;
3572
3573 return TRUE;
3574 }
3575
3576 case WM_PRINTCLIENT:
3577 case WM_PAINT:
3578 PROPSHEET_Paint(hwnd, (HDC)wParam);
3579 return TRUE;
3580
3581 case WM_DESTROY:
3582 PROPSHEET_CleanUp(hwnd);
3583 return TRUE;
3584
3585 case WM_CLOSE:
3586 PROPSHEET_Cancel(hwnd, 1);
3587 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3588
3589 case WM_COMMAND:
3590 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3591 {
3592 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3593
3594 if (!psInfo)
3595 return FALSE;
3596
3597 /* No default handler, forward notification to active page */
3598 if (psInfo->activeValid && psInfo->active_page != -1)
3599 {
3600 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3601 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3602 }
3603 }
3604 return TRUE;
3605
3606 case WM_NOTIFY:
3607 {
3608 NMHDR* pnmh = (LPNMHDR) lParam;
3609
3610 if (pnmh->code == TCN_SELCHANGE)
3611 {
3612 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3613 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3614 }
3615
3616 if(pnmh->code == TCN_SELCHANGING)
3617 {
3618 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3619 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3620 return TRUE;
3621 }
3622
3623 return FALSE;
3624 }
3625
3626 case WM_SYSCOLORCHANGE:
3627 COMCTL32_RefreshSysColors();
3628 return FALSE;
3629
3630 case PSM_GETCURRENTPAGEHWND:
3631 {
3632 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3633 HWND hwndPage = 0;
3634
3635 if (!psInfo)
3636 return FALSE;
3637
3638 if (psInfo->activeValid && psInfo->active_page != -1)
3639 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3640
3641 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3642
3643 return TRUE;
3644 }
3645
3646 case PSM_CHANGED:
3647 PROPSHEET_Changed(hwnd, (HWND)wParam);
3648 return TRUE;
3649
3650 case PSM_UNCHANGED:
3651 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3652 return TRUE;
3653
3654 case PSM_GETTABCONTROL:
3655 {
3656 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3657
3658 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3659
3660 return TRUE;
3661 }
3662
3663 case PSM_SETCURSEL:
3664 {
3665 BOOL msgResult;
3666
3667 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3668 if(msgResult != FALSE)
3669 {
3670 msgResult = PROPSHEET_SetCurSel(hwnd,
3671 (int)wParam,
3672 1,
3673 (HPROPSHEETPAGE)lParam);
3674 }
3675
3676 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3677
3678 return TRUE;
3679 }
3680
3681 case PSM_CANCELTOCLOSE:
3682 {
3683 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3684 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3685 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3686
3687 EnableWindow(hwndCancel, FALSE);
3688 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3689 SetWindowTextW(hwndOK, buf);
3690
3691 return FALSE;
3692 }
3693
3694 case PSM_RESTARTWINDOWS:
3695 {
3696 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3697
3698 if (!psInfo)
3699 return FALSE;
3700
3701 /* reboot system takes precedence over restart windows */
3702 if (psInfo->result != ID_PSREBOOTSYSTEM)
3703 psInfo->result = ID_PSRESTARTWINDOWS;
3704
3705 return TRUE;
3706 }
3707
3708 case PSM_REBOOTSYSTEM:
3709 {
3710 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3711
3712 if (!psInfo)
3713 return FALSE;
3714
3715 psInfo->result = ID_PSREBOOTSYSTEM;
3716
3717 return TRUE;
3718 }
3719
3720 case PSM_SETTITLEA:
3721 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3722 return TRUE;
3723
3724 case PSM_SETTITLEW:
3725 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3726 return TRUE;
3727
3728 case PSM_APPLY:
3729 {
3730 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3731
3732 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3733
3734 return TRUE;
3735 }
3736
3737 case PSM_QUERYSIBLINGS:
3738 {
3739 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3740
3741 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3742
3743 return TRUE;
3744 }
3745
3746 case PSM_ADDPAGE:
3747 {
3748 /*
3749 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3750 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3751 * on success or FALSE otherwise, as specified on MSDN Online.
3752 * Also see the MFC code for
3753 * CPropertySheet::AddPage(CPropertyPage* pPage).
3754 */
3755
3756 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3757
3758 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3759
3760 return TRUE;
3761 }
3762
3763 case PSM_REMOVEPAGE:
3764 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3765 return TRUE;
3766
3767 case PSM_ISDIALOGMESSAGE:
3768 {
3769 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3770 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3771 return TRUE;
3772 }
3773
3774 case PSM_PRESSBUTTON:
3775 PROPSHEET_PressButton(hwnd, (int)wParam);
3776 return TRUE;
3777
3778 case PSM_SETFINISHTEXTA:
3779 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3780 return TRUE;
3781
3782 case PSM_SETWIZBUTTONS:
3783 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3784 return TRUE;
3785
3786 case PSM_SETCURSELID:
3787 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3788 return TRUE;
3789
3790 case PSM_SETFINISHTEXTW:
3791 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3792 return FALSE;
3793
3794 case PSM_INSERTPAGE:
3795 {
3796 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3799 }
3800
3801 case PSM_SETHEADERTITLEW:
3802 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3803 return TRUE;
3804
3805 case PSM_SETHEADERTITLEA:
3806 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3807 return TRUE;
3808
3809 case PSM_SETHEADERSUBTITLEW:
3810 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3811 return TRUE;
3812
3813 case PSM_SETHEADERSUBTITLEA:
3814 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3815 return TRUE;
3816
3817 case PSM_HWNDTOINDEX:
3818 {
3819 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3820 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3821 return TRUE;
3822 }
3823
3824 case PSM_INDEXTOHWND:
3825 {
3826 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3827 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3828 return TRUE;
3829 }
3830
3831 case PSM_PAGETOINDEX:
3832 {
3833 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3834 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3835 return TRUE;
3836 }
3837
3838 case PSM_INDEXTOPAGE:
3839 {
3840 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3841 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3842 return TRUE;
3843 }
3844
3845 case PSM_IDTOINDEX:
3846 {
3847 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3848 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3849 return TRUE;
3850 }
3851
3852 case PSM_INDEXTOID:
3853 {
3854 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3855 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3856 return TRUE;
3857 }
3858
3859 case PSM_GETRESULT:
3860 {
3861 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3862 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3863 return TRUE;
3864 }
3865
3866 case PSM_RECALCPAGESIZES:
3867 {
3868 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3869 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3870 return TRUE;
3871 }
3872
3873 default:
3874 return FALSE;
3875 }
3876 }