[SHELL32] CDrivesFolder: Implement the eject and disconnect menu items. CORE-13841
[reactos.git] / 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 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1180 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1181 }
1182
1183 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1184 }
1185
1186 /*
1187 * Get the size of an in-memory Template
1188 *
1189 *( Based on the code of PROPSHEET_CollectPageInfo)
1190 * See also dialog.c/DIALOG_ParseTemplate32().
1191 */
1192
1193 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1194
1195 {
1196 const WORD* p = (const WORD *)pTemplate;
1197 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1198 WORD nrofitems;
1199 UINT ret;
1200
1201 if (istemplateex)
1202 {
1203 /* DLGTEMPLATEEX (not defined in any std. header file) */
1204
1205 TRACE("is DLGTEMPLATEEX\n");
1206 p++; /* dlgVer */
1207 p++; /* signature */
1208 p += 2; /* help ID */
1209 p += 2; /* ext style */
1210 p += 2; /* style */
1211 }
1212 else
1213 {
1214 /* DLGTEMPLATE */
1215
1216 TRACE("is DLGTEMPLATE\n");
1217 p += 2; /* style */
1218 p += 2; /* ext style */
1219 }
1220
1221 nrofitems = (WORD)*p; p++; /* nb items */
1222 p++; /* x */
1223 p++; /* y */
1224 p++; /* width */
1225 p++; /* height */
1226
1227 /* menu */
1228 switch ((WORD)*p)
1229 {
1230 case 0x0000:
1231 p++;
1232 break;
1233 case 0xffff:
1234 p += 2;
1235 break;
1236 default:
1237 TRACE("menu %s\n",debugstr_w( p ));
1238 p += lstrlenW( p ) + 1;
1239 break;
1240 }
1241
1242 /* class */
1243 switch ((WORD)*p)
1244 {
1245 case 0x0000:
1246 p++;
1247 break;
1248 case 0xffff:
1249 p += 2; /* 0xffff plus predefined window class ordinal value */
1250 break;
1251 default:
1252 TRACE("class %s\n",debugstr_w( p ));
1253 p += lstrlenW( p ) + 1;
1254 break;
1255 }
1256
1257 /* title */
1258 TRACE("title %s\n",debugstr_w( p ));
1259 p += lstrlenW( p ) + 1;
1260
1261 /* font, if DS_SETFONT set */
1262 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1263 pTemplate->style)))
1264 {
1265 p+=(istemplateex)?3:1;
1266 TRACE("font %s\n",debugstr_w( p ));
1267 p += lstrlenW( p ) + 1; /* the font name */
1268 }
1269
1270 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1271 * that are following the DLGTEMPLATE(EX) data */
1272 TRACE("%d items\n",nrofitems);
1273 while (nrofitems > 0)
1274 {
1275 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1276
1277 /* skip header */
1278 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1279
1280 /* check class */
1281 switch ((WORD)*p)
1282 {
1283 case 0x0000:
1284 p++;
1285 break;
1286 case 0xffff:
1287 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1288 p += 2;
1289 break;
1290 default:
1291 TRACE("class %s\n",debugstr_w( p ));
1292 p += lstrlenW( p ) + 1;
1293 break;
1294 }
1295
1296 /* check title text */
1297 switch ((WORD)*p)
1298 {
1299 case 0x0000:
1300 p++;
1301 break;
1302 case 0xffff:
1303 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1304 p += 2;
1305 break;
1306 default:
1307 TRACE("text %s\n",debugstr_w( p ));
1308 p += lstrlenW( p ) + 1;
1309 break;
1310 }
1311 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1312 --nrofitems;
1313 }
1314
1315 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1316 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1317 return ret;
1318 }
1319
1320 /******************************************************************************
1321 * PROPSHEET_CreatePage
1322 *
1323 * Creates a page.
1324 */
1325 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1326 int index,
1327 const PropSheetInfo * psInfo,
1328 LPCPROPSHEETPAGEW ppshpage)
1329 {
1330 const DLGTEMPLATE* pTemplate;
1331 HWND hwndPage;
1332 DWORD resSize;
1333 DLGTEMPLATE* pTemplateCopy = NULL;
1334
1335 TRACE("index %d\n", index);
1336
1337 if (ppshpage == NULL)
1338 {
1339 return FALSE;
1340 }
1341
1342 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1343 {
1344 pTemplate = ppshpage->u.pResource;
1345 resSize = GetTemplateSize(pTemplate);
1346 }
1347 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1348 {
1349 HRSRC hResource;
1350 HANDLE hTemplate;
1351
1352 hResource = FindResourceW(ppshpage->hInstance,
1353 ppshpage->u.pszTemplate,
1354 (LPWSTR)RT_DIALOG);
1355 if(!hResource)
1356 return FALSE;
1357
1358 resSize = SizeofResource(ppshpage->hInstance, hResource);
1359
1360 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1361 if(!hTemplate)
1362 return FALSE;
1363
1364 pTemplate = LockResource(hTemplate);
1365 /*
1366 * Make a copy of the dialog template to make it writable
1367 */
1368 }
1369 else
1370 {
1371 HRSRC hResource;
1372 HANDLE hTemplate;
1373
1374 hResource = FindResourceA(ppshpage->hInstance,
1375 (LPCSTR)ppshpage->u.pszTemplate,
1376 (LPSTR)RT_DIALOG);
1377 if(!hResource)
1378 return FALSE;
1379
1380 resSize = SizeofResource(ppshpage->hInstance, hResource);
1381
1382 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1383 if(!hTemplate)
1384 return FALSE;
1385
1386 pTemplate = LockResource(hTemplate);
1387 /*
1388 * Make a copy of the dialog template to make it writable
1389 */
1390 }
1391 pTemplateCopy = Alloc(resSize);
1392 if (!pTemplateCopy)
1393 return FALSE;
1394
1395 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1396 memcpy(pTemplateCopy, pTemplate, resSize);
1397
1398 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1399 {
1400 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1401 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1402 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1403 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1404 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1405 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1406 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1407 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1408
1409 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1410 }
1411 else
1412 {
1413 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1414 pTemplateCopy->style &= ~DS_MODALFRAME;
1415 pTemplateCopy->style &= ~WS_CAPTION;
1416 pTemplateCopy->style &= ~WS_SYSMENU;
1417 pTemplateCopy->style &= ~WS_POPUP;
1418 pTemplateCopy->style &= ~WS_DISABLED;
1419 pTemplateCopy->style &= ~WS_VISIBLE;
1420 pTemplateCopy->style &= ~WS_THICKFRAME;
1421
1422 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1423 }
1424
1425 if (psInfo->proppage[index].useCallback)
1426 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1427 (LPPROPSHEETPAGEW)ppshpage);
1428
1429 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1430 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1431 pTemplateCopy,
1432 hwndParent,
1433 ppshpage->pfnDlgProc,
1434 (LPARAM)ppshpage);
1435 else
1436 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1437 pTemplateCopy,
1438 hwndParent,
1439 ppshpage->pfnDlgProc,
1440 (LPARAM)ppshpage);
1441 /* Free a no more needed copy */
1442 Free(pTemplateCopy);
1443
1444 if(!hwndPage)
1445 return FALSE;
1446
1447 psInfo->proppage[index].hwndPage = hwndPage;
1448
1449 /* Subclass exterior wizard pages */
1450 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1451 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1452 (ppshpage->dwFlags & PSP_HIDEHEADER))
1453 {
1454 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1455 (DWORD_PTR)ppshpage);
1456 }
1457 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1458 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1459
1460 return TRUE;
1461 }
1462
1463 /******************************************************************************
1464 * PROPSHEET_LoadWizardBitmaps
1465 *
1466 * Loads the watermark and header bitmaps for a wizard.
1467 */
1468 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1469 {
1470 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1471 {
1472 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1473 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1474 considers hbmWatermark as valid. */
1475 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1476 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1477 {
1478 psInfo->ppshheader.u4.hbmWatermark =
1479 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1480 }
1481
1482 /* Same behavior as for watermarks */
1483 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1484 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1485 {
1486 psInfo->ppshheader.u5.hbmHeader =
1487 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1488 }
1489 }
1490 }
1491
1492
1493 /******************************************************************************
1494 * PROPSHEET_ShowPage
1495 *
1496 * Displays or creates the specified page.
1497 */
1498 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1499 {
1500 HWND hwndTabCtrl;
1501 HWND hwndLineHeader;
1502 HWND control;
1503 LPCPROPSHEETPAGEW ppshpage;
1504
1505 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1506 if (index == psInfo->active_page)
1507 {
1508 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1509 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1510 return TRUE;
1511 }
1512
1513 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1514 if (psInfo->proppage[index].hwndPage == 0)
1515 {
1516 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1517 }
1518
1519 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1520 {
1521 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1522 psInfo->proppage[index].pszText);
1523
1524 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1525 if(control != NULL)
1526 SetFocus(control);
1527 }
1528
1529 if (psInfo->active_page != -1)
1530 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1531
1532 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1533
1534 /* Synchronize current selection with tab control
1535 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1536 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1537 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1538
1539 psInfo->active_page = index;
1540 psInfo->activeValid = TRUE;
1541
1542 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1543 {
1544 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1545 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1546
1547 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1548 ShowWindow(hwndLineHeader, SW_HIDE);
1549 else
1550 ShowWindow(hwndLineHeader, SW_SHOW);
1551 }
1552
1553 return TRUE;
1554 }
1555
1556 /******************************************************************************
1557 * PROPSHEET_Back
1558 */
1559 static BOOL PROPSHEET_Back(HWND hwndDlg)
1560 {
1561 PSHNOTIFY psn;
1562 HWND hwndPage;
1563 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1564 LRESULT result;
1565 int idx;
1566
1567 TRACE("active_page %d\n", psInfo->active_page);
1568 if (psInfo->active_page < 0)
1569 return FALSE;
1570
1571 psn.hdr.code = PSN_WIZBACK;
1572 psn.hdr.hwndFrom = hwndDlg;
1573 psn.hdr.idFrom = 0;
1574 psn.lParam = 0;
1575
1576 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1577
1578 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1579 if (result == -1)
1580 return FALSE;
1581 else if (result == 0)
1582 idx = psInfo->active_page - 1;
1583 else
1584 idx = PROPSHEET_FindPageByResId(psInfo, result);
1585
1586 if (idx >= 0 && idx < psInfo->nPages)
1587 {
1588 if (PROPSHEET_CanSetCurSel(hwndDlg))
1589 {
1590 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1591 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1592 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1593 }
1594 }
1595 return TRUE;
1596 }
1597
1598 /******************************************************************************
1599 * PROPSHEET_Next
1600 */
1601 static BOOL PROPSHEET_Next(HWND hwndDlg)
1602 {
1603 PSHNOTIFY psn;
1604 HWND hwndPage;
1605 LRESULT msgResult = 0;
1606 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1607 int idx;
1608
1609 TRACE("active_page %d\n", psInfo->active_page);
1610 if (psInfo->active_page < 0)
1611 return FALSE;
1612
1613 psn.hdr.code = PSN_WIZNEXT;
1614 psn.hdr.hwndFrom = hwndDlg;
1615 psn.hdr.idFrom = 0;
1616 psn.lParam = 0;
1617
1618 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1619
1620 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1621 if (msgResult == -1)
1622 return FALSE;
1623 else if (msgResult == 0)
1624 idx = psInfo->active_page + 1;
1625 else
1626 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1627
1628 if (idx < psInfo->nPages )
1629 {
1630 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1631 {
1632 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1633 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1634 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1635 }
1636 }
1637
1638 return TRUE;
1639 }
1640
1641 /******************************************************************************
1642 * PROPSHEET_Finish
1643 */
1644 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1645 {
1646 PSHNOTIFY psn;
1647 HWND hwndPage;
1648 LRESULT msgResult = 0;
1649 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1650
1651 TRACE("active_page %d\n", psInfo->active_page);
1652 if (psInfo->active_page < 0)
1653 return FALSE;
1654
1655 psn.hdr.code = PSN_WIZFINISH;
1656 psn.hdr.hwndFrom = hwndDlg;
1657 psn.hdr.idFrom = 0;
1658 psn.lParam = 0;
1659
1660 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1661
1662 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1663
1664 TRACE("msg result %ld\n", msgResult);
1665
1666 if (msgResult != 0)
1667 return FALSE;
1668
1669 if (psInfo->result == 0)
1670 psInfo->result = IDOK;
1671 if (psInfo->isModeless)
1672 psInfo->activeValid = FALSE;
1673 else
1674 psInfo->ended = TRUE;
1675
1676 return TRUE;
1677 }
1678
1679 /******************************************************************************
1680 * PROPSHEET_Apply
1681 */
1682 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1683 {
1684 int i;
1685 HWND hwndPage;
1686 PSHNOTIFY psn;
1687 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1688
1689 TRACE("active_page %d\n", psInfo->active_page);
1690 if (psInfo->active_page < 0)
1691 return FALSE;
1692
1693 psn.hdr.hwndFrom = hwndDlg;
1694 psn.hdr.idFrom = 0;
1695 psn.lParam = 0;
1696
1697
1698 /*
1699 * Send PSN_KILLACTIVE to the current page.
1700 */
1701 psn.hdr.code = PSN_KILLACTIVE;
1702
1703 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1704
1705 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1706 return FALSE;
1707
1708 /*
1709 * Send PSN_APPLY to all pages.
1710 */
1711 psn.hdr.code = PSN_APPLY;
1712 psn.lParam = lParam;
1713
1714 for (i = 0; i < psInfo->nPages; i++)
1715 {
1716 hwndPage = psInfo->proppage[i].hwndPage;
1717 if (hwndPage)
1718 {
1719 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1720 {
1721 case PSNRET_INVALID:
1722 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1723 /* fall through */
1724 case PSNRET_INVALID_NOCHANGEPAGE:
1725 return FALSE;
1726 }
1727 }
1728 }
1729
1730 if(lParam)
1731 {
1732 psInfo->activeValid = FALSE;
1733 }
1734 else if(psInfo->active_page >= 0)
1735 {
1736 psn.hdr.code = PSN_SETACTIVE;
1737 psn.lParam = 0;
1738 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1739 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1740 }
1741
1742 return TRUE;
1743 }
1744
1745 /******************************************************************************
1746 * PROPSHEET_Cancel
1747 */
1748 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1749 {
1750 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1751 HWND hwndPage;
1752 PSHNOTIFY psn;
1753 int i;
1754
1755 TRACE("active_page %d\n", psInfo->active_page);
1756 if (psInfo->active_page < 0)
1757 return;
1758
1759 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1760 psn.hdr.code = PSN_QUERYCANCEL;
1761 psn.hdr.hwndFrom = hwndDlg;
1762 psn.hdr.idFrom = 0;
1763 psn.lParam = 0;
1764
1765 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1766 return;
1767
1768 psn.hdr.code = PSN_RESET;
1769 psn.lParam = lParam;
1770
1771 for (i = 0; i < psInfo->nPages; i++)
1772 {
1773 hwndPage = psInfo->proppage[i].hwndPage;
1774
1775 if (hwndPage)
1776 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1777 }
1778
1779 if (psInfo->isModeless)
1780 {
1781 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1782 psInfo->activeValid = FALSE;
1783 }
1784 else
1785 psInfo->ended = TRUE;
1786 }
1787
1788 /******************************************************************************
1789 * PROPSHEET_Help
1790 */
1791 static void PROPSHEET_Help(HWND hwndDlg)
1792 {
1793 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1794 HWND hwndPage;
1795 PSHNOTIFY psn;
1796
1797 TRACE("active_page %d\n", psInfo->active_page);
1798 if (psInfo->active_page < 0)
1799 return;
1800
1801 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1802 psn.hdr.code = PSN_HELP;
1803 psn.hdr.hwndFrom = hwndDlg;
1804 psn.hdr.idFrom = 0;
1805 psn.lParam = 0;
1806
1807 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1808 }
1809
1810 /******************************************************************************
1811 * PROPSHEET_Changed
1812 */
1813 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1814 {
1815 int i;
1816 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1817
1818 TRACE("\n");
1819 if (!psInfo) return;
1820 /*
1821 * Set the dirty flag of this page.
1822 */
1823 for (i = 0; i < psInfo->nPages; i++)
1824 {
1825 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1826 psInfo->proppage[i].isDirty = TRUE;
1827 }
1828
1829 /*
1830 * Enable the Apply button.
1831 */
1832 if (psInfo->hasApply)
1833 {
1834 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1835
1836 EnableWindow(hwndApplyBtn, TRUE);
1837 }
1838 }
1839
1840 /******************************************************************************
1841 * PROPSHEET_UnChanged
1842 */
1843 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1844 {
1845 int i;
1846 BOOL noPageDirty = TRUE;
1847 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1848 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1849
1850 TRACE("\n");
1851 if ( !psInfo ) return;
1852 for (i = 0; i < psInfo->nPages; i++)
1853 {
1854 /* set the specified page as clean */
1855 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1856 psInfo->proppage[i].isDirty = FALSE;
1857
1858 /* look to see if there are any dirty pages */
1859 if (psInfo->proppage[i].isDirty)
1860 noPageDirty = FALSE;
1861 }
1862
1863 /*
1864 * Disable Apply button.
1865 */
1866 if (noPageDirty)
1867 EnableWindow(hwndApplyBtn, FALSE);
1868 }
1869
1870 /******************************************************************************
1871 * PROPSHEET_PressButton
1872 */
1873 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1874 {
1875 TRACE("buttonID %d\n", buttonID);
1876 switch (buttonID)
1877 {
1878 case PSBTN_APPLYNOW:
1879 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1880 break;
1881 case PSBTN_BACK:
1882 PROPSHEET_Back(hwndDlg);
1883 break;
1884 case PSBTN_CANCEL:
1885 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1886 break;
1887 case PSBTN_FINISH:
1888 PROPSHEET_Finish(hwndDlg);
1889 break;
1890 case PSBTN_HELP:
1891 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1892 break;
1893 case PSBTN_NEXT:
1894 PROPSHEET_Next(hwndDlg);
1895 break;
1896 case PSBTN_OK:
1897 PROPSHEET_DoCommand(hwndDlg, IDOK);
1898 break;
1899 default:
1900 FIXME("Invalid button index %d\n", buttonID);
1901 }
1902 }
1903
1904
1905 /*************************************************************************
1906 * BOOL PROPSHEET_CanSetCurSel [Internal]
1907 *
1908 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1909 *
1910 * PARAMS
1911 * hwndDlg [I] handle to a Dialog hWnd
1912 *
1913 * RETURNS
1914 * TRUE if Current Selection can change
1915 *
1916 * NOTES
1917 */
1918 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1919 {
1920 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1921 HWND hwndPage;
1922 PSHNOTIFY psn;
1923 BOOL res = FALSE;
1924
1925 if (!psInfo)
1926 {
1927 res = FALSE;
1928 goto end;
1929 }
1930
1931 TRACE("active_page %d\n", psInfo->active_page);
1932 if (psInfo->active_page < 0)
1933 {
1934 res = TRUE;
1935 goto end;
1936 }
1937
1938 /*
1939 * Notify the current page.
1940 */
1941 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1942 psn.hdr.code = PSN_KILLACTIVE;
1943 psn.hdr.hwndFrom = hwndDlg;
1944 psn.hdr.idFrom = 0;
1945 psn.lParam = 0;
1946
1947 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1948
1949 end:
1950 TRACE("<-- %d\n", res);
1951 return res;
1952 }
1953
1954 /******************************************************************************
1955 * PROPSHEET_SetCurSel
1956 */
1957 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1958 int index,
1959 int skipdir,
1960 HPROPSHEETPAGE hpage
1961 )
1962 {
1963 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1964 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1965 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1966
1967 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1968
1969 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1970
1971 if (index < 0 || index >= psInfo->nPages)
1972 {
1973 TRACE("Could not find page to select!\n");
1974 return FALSE;
1975 }
1976
1977 /* unset active page while doing this transition. */
1978 if (psInfo->active_page != -1)
1979 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1980 psInfo->active_page = -1;
1981
1982 while (1) {
1983 int result;
1984 PSHNOTIFY psn;
1985 RECT rc;
1986 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1987
1988 if (hwndTabControl)
1989 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
1990
1991 psn.hdr.code = PSN_SETACTIVE;
1992 psn.hdr.hwndFrom = hwndDlg;
1993 psn.hdr.idFrom = 0;
1994 psn.lParam = 0;
1995
1996 if (!psInfo->proppage[index].hwndPage) {
1997 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
1998 PROPSHEET_RemovePage(hwndDlg, index, NULL);
1999 if(index >= psInfo->nPages)
2000 index--;
2001 if(index < 0)
2002 return FALSE;
2003 continue;
2004 }
2005 }
2006
2007 /* Resize the property sheet page to the fit in the Tab control
2008 * (for regular property sheets) or to fit in the client area (for
2009 * wizards).
2010 * NOTE: The resizing happens every time the page is selected and
2011 * not only when it's created (some applications depend on it). */
2012 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2013 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2014 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2015 rc.right - rc.left, rc.bottom - rc.top);
2016 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2017 rc.left, rc.top,
2018 rc.right - rc.left, rc.bottom - rc.top, 0);
2019
2020 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2021 if (!result)
2022 break;
2023 if (result == -1) {
2024 index+=skipdir;
2025 if (index < 0) {
2026 index = 0;
2027 WARN("Tried to skip before first property sheet page!\n");
2028 break;
2029 }
2030 if (index >= psInfo->nPages) {
2031 WARN("Tried to skip after last property sheet page!\n");
2032 index = psInfo->nPages-1;
2033 break;
2034 }
2035 }
2036 else if (result != 0)
2037 {
2038 int old_index = index;
2039 index = PROPSHEET_FindPageByResId(psInfo, result);
2040 if(index >= psInfo->nPages) {
2041 index = old_index;
2042 WARN("Tried to skip to nonexistent page by res id\n");
2043 break;
2044 }
2045 continue;
2046 }
2047 }
2048
2049 /* Invalidate the header area */
2050 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2051 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2052 {
2053 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2054 RECT r;
2055
2056 GetClientRect(hwndLineHeader, &r);
2057 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2058 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2059
2060 InvalidateRect(hwndDlg, &r, TRUE);
2061 }
2062
2063 /*
2064 * Display the new page.
2065 */
2066 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2067
2068 if (psInfo->proppage[index].hasHelp)
2069 EnableWindow(hwndHelp, TRUE);
2070 else
2071 EnableWindow(hwndHelp, FALSE);
2072
2073 return TRUE;
2074 }
2075
2076 /******************************************************************************
2077 * PROPSHEET_SetCurSelId
2078 *
2079 * Selects the page, specified by resource id.
2080 */
2081 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2082 {
2083 int idx;
2084 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2085
2086 idx = PROPSHEET_FindPageByResId(psInfo, id);
2087 if (idx < psInfo->nPages )
2088 {
2089 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2090 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2091 }
2092 }
2093
2094 /******************************************************************************
2095 * PROPSHEET_SetTitleA
2096 */
2097 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2098 {
2099 if(!IS_INTRESOURCE(lpszText))
2100 {
2101 WCHAR szTitle[256];
2102 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2103 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2104 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2105 }
2106 else
2107 {
2108 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2109 }
2110 }
2111
2112 /******************************************************************************
2113 * PROPSHEET_SetTitleW
2114 */
2115 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2116 {
2117 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2118 WCHAR szTitle[256];
2119
2120 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2121 if (IS_INTRESOURCE(lpszText)) {
2122 if (!LoadStringW(psInfo->ppshheader.hInstance,
2123 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2124 return;
2125 lpszText = szTitle;
2126 }
2127 if (dwStyle & PSH_PROPTITLE)
2128 {
2129 WCHAR* dest;
2130 int lentitle = strlenW(lpszText);
2131 int lenprop = strlenW(psInfo->strPropertiesFor);
2132
2133 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2134 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2135
2136 SetWindowTextW(hwndDlg, dest);
2137 Free(dest);
2138 }
2139 else
2140 SetWindowTextW(hwndDlg, lpszText);
2141 }
2142
2143 /******************************************************************************
2144 * PROPSHEET_SetFinishTextA
2145 */
2146 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2147 {
2148 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2149 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2150
2151 TRACE("'%s'\n", lpszText);
2152 /* Set text, show and enable the Finish button */
2153 SetWindowTextA(hwndButton, lpszText);
2154 ShowWindow(hwndButton, SW_SHOW);
2155 EnableWindow(hwndButton, TRUE);
2156
2157 /* Make it default pushbutton */
2158 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2159
2160 /* Hide Back button */
2161 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2162 ShowWindow(hwndButton, SW_HIDE);
2163
2164 if (!psInfo->hasFinish)
2165 {
2166 /* Hide Next button */
2167 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2168 ShowWindow(hwndButton, SW_HIDE);
2169 }
2170 }
2171
2172 /******************************************************************************
2173 * PROPSHEET_SetFinishTextW
2174 */
2175 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2176 {
2177 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2178 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2179
2180 TRACE("%s\n", debugstr_w(lpszText));
2181 /* Set text, show and enable the Finish button */
2182 SetWindowTextW(hwndButton, lpszText);
2183 ShowWindow(hwndButton, SW_SHOW);
2184 EnableWindow(hwndButton, TRUE);
2185
2186 /* Make it default pushbutton */
2187 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2188
2189 /* Hide Back button */
2190 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2191 ShowWindow(hwndButton, SW_HIDE);
2192
2193 if (!psInfo->hasFinish)
2194 {
2195 /* Hide Next button */
2196 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2197 ShowWindow(hwndButton, SW_HIDE);
2198 }
2199 }
2200
2201 /******************************************************************************
2202 * PROPSHEET_QuerySiblings
2203 */
2204 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2205 WPARAM wParam, LPARAM lParam)
2206 {
2207 int i = 0;
2208 HWND hwndPage;
2209 LRESULT msgResult = 0;
2210 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2211
2212 while ((i < psInfo->nPages) && (msgResult == 0))
2213 {
2214 hwndPage = psInfo->proppage[i].hwndPage;
2215 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2216 i++;
2217 }
2218
2219 return msgResult;
2220 }
2221
2222 /******************************************************************************
2223 * PROPSHEET_InsertPage
2224 */
2225 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2226 {
2227 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2228 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2229 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2230 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2231 TCITEMW item;
2232 int index;
2233
2234 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2235
2236 if (IS_INTRESOURCE(hpageInsertAfter))
2237 index = LOWORD(hpageInsertAfter);
2238 else
2239 {
2240 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2241 if (index < 0)
2242 {
2243 TRACE("Could not find page to insert after!\n");
2244 return FALSE;
2245 }
2246 index++;
2247 }
2248
2249 if (index > psInfo->nPages)
2250 index = psInfo->nPages;
2251
2252 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2253 if (!ppi)
2254 return FALSE;
2255
2256 /*
2257 * Fill in a new PropPageInfo entry.
2258 */
2259 if (index > 0)
2260 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2261 memset(&ppi[index], 0, sizeof(PropPageInfo));
2262 if (index < psInfo->nPages)
2263 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2264 psInfo->proppage = ppi;
2265
2266 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
2267 {
2268 psInfo->proppage = prev_ppi;
2269 Free(ppi);
2270 return FALSE;
2271 }
2272
2273 psInfo->proppage[index].hpage = hpage;
2274
2275 if (ppsp->dwFlags & PSP_PREMATURE)
2276 {
2277 /* Create the page but don't show it */
2278 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
2279 {
2280 psInfo->proppage = prev_ppi;
2281 Free(ppi);
2282 return FALSE;
2283 }
2284 }
2285
2286 Free(prev_ppi);
2287 psInfo->nPages++;
2288 if (index <= psInfo->active_page)
2289 psInfo->active_page++;
2290
2291 /*
2292 * Add a new tab to the tab control.
2293 */
2294 item.mask = TCIF_TEXT;
2295 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2296 item.cchTextMax = MAX_TABTEXT_LENGTH;
2297
2298 if (psInfo->hImageList)
2299 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2300
2301 if (psInfo->proppage[index].hasIcon)
2302 {
2303 item.mask |= TCIF_IMAGE;
2304 item.iImage = index;
2305 }
2306
2307 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2308
2309 /* If it is the only page - show it */
2310 if (psInfo->nPages == 1)
2311 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2312
2313 return TRUE;
2314 }
2315
2316 /******************************************************************************
2317 * PROPSHEET_AddPage
2318 */
2319 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2320 {
2321 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2322 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2323 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2324 }
2325
2326 /******************************************************************************
2327 * PROPSHEET_RemovePage
2328 */
2329 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2330 int index,
2331 HPROPSHEETPAGE hpage)
2332 {
2333 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2334 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2335 PropPageInfo* oldPages;
2336
2337 TRACE("index %d, hpage %p\n", index, hpage);
2338 if (!psInfo) {
2339 return FALSE;
2340 }
2341
2342 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2343
2344 /* Make sure that index is within range */
2345 if (index < 0 || index >= psInfo->nPages)
2346 {
2347 TRACE("Could not find page to remove!\n");
2348 return FALSE;
2349 }
2350
2351 TRACE("total pages %d removing page %d active page %d\n",
2352 psInfo->nPages, index, psInfo->active_page);
2353 /*
2354 * Check if we're removing the active page.
2355 */
2356 if (index == psInfo->active_page)
2357 {
2358 if (psInfo->nPages > 1)
2359 {
2360 if (index > 0)
2361 {
2362 /* activate previous page */
2363 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2364 }
2365 else
2366 {
2367 /* activate the next page */
2368 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2369 psInfo->active_page = index;
2370 }
2371 }
2372 else
2373 {
2374 psInfo->active_page = -1;
2375 if (!psInfo->isModeless)
2376 {
2377 psInfo->ended = TRUE;
2378 return TRUE;
2379 }
2380 }
2381 }
2382 else if (index < psInfo->active_page)
2383 psInfo->active_page--;
2384
2385 /* Unsubclass the page dialog window */
2386 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2387 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2388 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2389 {
2390 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2391 PROPSHEET_WizardSubclassProc, 1);
2392 }
2393
2394 /* Destroy page dialog window */
2395 DestroyWindow(psInfo->proppage[index].hwndPage);
2396
2397 /* Free page resources */
2398 if(psInfo->proppage[index].hpage)
2399 {
2400 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2401
2402 if (psp->dwFlags & PSP_USETITLE)
2403 Free ((LPVOID)psInfo->proppage[index].pszText);
2404
2405 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2406 }
2407
2408 /* Remove the tab */
2409 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2410
2411 oldPages = psInfo->proppage;
2412 psInfo->nPages--;
2413 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2414
2415 if (index > 0)
2416 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2417
2418 if (index < psInfo->nPages)
2419 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2420 (psInfo->nPages - index) * sizeof(PropPageInfo));
2421
2422 Free(oldPages);
2423
2424 return FALSE;
2425 }
2426
2427 /******************************************************************************
2428 * PROPSHEET_SetWizButtons
2429 *
2430 * This code will work if (and assumes that) the Next button is on top of the
2431 * Finish button. ie. Finish comes after Next in the Z order.
2432 * This means make sure the dialog template reflects this.
2433 *
2434 */
2435 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2436 {
2437 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2438 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2439 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2440 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2441 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2442
2443 #ifdef __REACTOS__
2444 HWND hwndCancel = GetDlgItem(hwndDlg, IDCANCEL);
2445 INT iDefItem = 0;
2446 HWND hwndFocus;
2447 #endif
2448
2449 TRACE("%d\n", dwFlags);
2450
2451 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2452 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2453 EnableWindow(hwndFinish, enable_finish);
2454
2455 #ifndef __REACTOS__
2456 /* set the default pushbutton to an enabled button */
2457 if (enable_finish)
2458 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2459 else if (dwFlags & PSWIZB_NEXT)
2460 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2461 else if (dwFlags & PSWIZB_BACK)
2462 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2463 else
2464 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2465 #endif
2466
2467 if (!psInfo->hasFinish)
2468 {
2469 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2470 {
2471 /* Hide the Next button */
2472 ShowWindow(hwndNext, SW_HIDE);
2473
2474 /* Show the Finish button */
2475 ShowWindow(hwndFinish, SW_SHOW);
2476 }
2477 else
2478 {
2479 /* Hide the Finish button */
2480 ShowWindow(hwndFinish, SW_HIDE);
2481 /* Show the Next button */
2482 ShowWindow(hwndNext, SW_SHOW);
2483 }
2484 }
2485
2486 #ifdef __REACTOS__
2487 /* set the default pushbutton to an enabled button */
2488 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2489 iDefItem = IDC_FINISH_BUTTON;
2490 else if (dwFlags & PSWIZB_NEXT)
2491 iDefItem = IDC_NEXT_BUTTON;
2492 else if (dwFlags & PSWIZB_BACK)
2493 iDefItem = IDC_BACK_BUTTON;
2494 else
2495 iDefItem = IDCANCEL;
2496 SendMessageW(hwndDlg, DM_SETDEFID, iDefItem, 0);
2497
2498 /* Set focus if no control has it */
2499 hwndFocus = GetFocus();
2500 if (!hwndFocus || hwndFocus == hwndCancel)
2501 SetFocus(GetDlgItem(hwndDlg, iDefItem));
2502 #endif
2503
2504 }
2505
2506 /******************************************************************************
2507 * PROPSHEET_SetHeaderTitleW
2508 */
2509 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2510 {
2511 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2512 PROPSHEETPAGEW *page;
2513
2514 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2515
2516 if (page_index >= psInfo->nPages)
2517 return;
2518
2519 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2520
2521 if (!IS_INTRESOURCE(page->pszHeaderTitle))
2522 Free((void *)page->pszHeaderTitle);
2523
2524 page->pszHeaderTitle = heap_strdupW(title);
2525 page->dwFlags |= PSP_USEHEADERTITLE;
2526 }
2527
2528 /******************************************************************************
2529 * PROPSHEET_SetHeaderTitleA
2530 */
2531 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2532 {
2533 WCHAR *titleW;
2534
2535 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2536
2537 titleW = heap_strdupAtoW(title);
2538 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2539 Free(titleW);
2540 }
2541
2542 /******************************************************************************
2543 * PROPSHEET_SetHeaderSubTitleW
2544 */
2545 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2546 {
2547 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2548 PROPSHEETPAGEW *page;
2549
2550 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2551
2552 if (page_index >= psInfo->nPages)
2553 return;
2554
2555 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2556
2557 if (!IS_INTRESOURCE(page->pszHeaderSubTitle))
2558 Free((void *)page->pszHeaderSubTitle);
2559
2560 page->pszHeaderSubTitle = heap_strdupW(subtitle);
2561 page->dwFlags |= PSP_USEHEADERSUBTITLE;
2562 }
2563
2564 /******************************************************************************
2565 * PROPSHEET_SetHeaderSubTitleA
2566 */
2567 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2568 {
2569 WCHAR *subtitleW;
2570
2571 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2572
2573 subtitleW = heap_strdupAtoW(subtitle);
2574 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2575 Free(subtitleW);
2576 }
2577
2578 /******************************************************************************
2579 * PROPSHEET_HwndToIndex
2580 */
2581 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2582 {
2583 int index;
2584 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2585
2586 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2587
2588 for (index = 0; index < psInfo->nPages; index++)
2589 if (psInfo->proppage[index].hwndPage == hPageDlg)
2590 return index;
2591 WARN("%p not found\n", hPageDlg);
2592 return -1;
2593 }
2594
2595 /******************************************************************************
2596 * PROPSHEET_IndexToHwnd
2597 */
2598 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2599 {
2600 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2601 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2602 if (!psInfo)
2603 return 0;
2604 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2605 WARN("%d out of range.\n", iPageIndex);
2606 return 0;
2607 }
2608 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2609 }
2610
2611 /******************************************************************************
2612 * PROPSHEET_PageToIndex
2613 */
2614 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2615 {
2616 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2617
2618 TRACE("(%p, %p)\n", hwndDlg, hPage);
2619
2620 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2621 }
2622
2623 /******************************************************************************
2624 * PROPSHEET_IndexToPage
2625 */
2626 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2627 {
2628 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2629 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2630 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2631 WARN("%d out of range.\n", iPageIndex);
2632 return 0;
2633 }
2634 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2635 }
2636
2637 /******************************************************************************
2638 * PROPSHEET_IdToIndex
2639 */
2640 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2641 {
2642 int index;
2643 LPCPROPSHEETPAGEW psp;
2644 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2645 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2646 for (index = 0; index < psInfo->nPages; index++) {
2647 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2648 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2649 return index;
2650 }
2651
2652 return -1;
2653 }
2654
2655 /******************************************************************************
2656 * PROPSHEET_IndexToId
2657 */
2658 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2659 {
2660 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2661 LPCPROPSHEETPAGEW psp;
2662 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2663 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2664 WARN("%d out of range.\n", iPageIndex);
2665 return 0;
2666 }
2667 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2668 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2669 return 0;
2670 }
2671 return (LRESULT)psp->u.pszTemplate;
2672 }
2673
2674 /******************************************************************************
2675 * PROPSHEET_GetResult
2676 */
2677 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2678 {
2679 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2680 return psInfo->result;
2681 }
2682
2683 /******************************************************************************
2684 * PROPSHEET_RecalcPageSizes
2685 */
2686 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2687 {
2688 FIXME("(%p): stub\n", hwndDlg);
2689 return FALSE;
2690 }
2691
2692 /******************************************************************************
2693 * PROPSHEET_GetPageIndex
2694 *
2695 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2696 * the array of PropPageInfo. If page is not found original index is used
2697 * (page takes precedence over index).
2698 */
2699 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2700 {
2701 int index;
2702
2703 TRACE("page %p index %d\n", page, original_index);
2704
2705 for (index = 0; index < psInfo->nPages; index++)
2706 if (psInfo->proppage[index].hpage == page)
2707 return index;
2708
2709 return original_index;
2710 }
2711
2712 /******************************************************************************
2713 * PROPSHEET_CleanUp
2714 */
2715 static void PROPSHEET_CleanUp(HWND hwndDlg)
2716 {
2717 int i;
2718 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2719
2720 TRACE("\n");
2721 if (!psInfo) return;
2722 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2723 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2724
2725 for (i = 0; i < psInfo->nPages; i++)
2726 {
2727 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2728
2729 /* Unsubclass the page dialog window */
2730 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2731 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2732 (psp->dwFlags & PSP_HIDEHEADER))
2733 {
2734 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2735 PROPSHEET_WizardSubclassProc, 1);
2736 }
2737
2738 if(psInfo->proppage[i].hwndPage)
2739 DestroyWindow(psInfo->proppage[i].hwndPage);
2740
2741 if(psp)
2742 {
2743 if (psp->dwFlags & PSP_USETITLE)
2744 Free ((LPVOID)psInfo->proppage[i].pszText);
2745
2746 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2747 }
2748 }
2749
2750 DeleteObject(psInfo->hFont);
2751 DeleteObject(psInfo->hFontBold);
2752 /* If we created the bitmaps, destroy them */
2753 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2754 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2755 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2756 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2757 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2758 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2759
2760 Free(psInfo->proppage);
2761 Free(psInfo->strPropertiesFor);
2762 ImageList_Destroy(psInfo->hImageList);
2763
2764 GlobalFree(psInfo);
2765 }
2766
2767 static INT do_loop(const PropSheetInfo *psInfo)
2768 {
2769 MSG msg;
2770 INT ret = -1;
2771 HWND hwnd = psInfo->hwnd;
2772 HWND parent = psInfo->ppshheader.hwndParent;
2773
2774 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2775 {
2776 if(ret == -1)
2777 break;
2778
2779 if(!IsDialogMessageW(hwnd, &msg))
2780 {
2781 TranslateMessage(&msg);
2782 DispatchMessageW(&msg);
2783 }
2784 }
2785
2786 if(ret == 0)
2787 {
2788 PostQuitMessage(msg.wParam);
2789 ret = -1;
2790 }
2791
2792 if(ret != -1)
2793 ret = psInfo->result;
2794
2795 if(parent)
2796 EnableWindow(parent, TRUE);
2797
2798 DestroyWindow(hwnd);
2799 return ret;
2800 }
2801
2802 /******************************************************************************
2803 * PROPSHEET_PropertySheet
2804 *
2805 * Common code between PropertySheetA/W
2806 */
2807 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2808 {
2809 INT_PTR bRet = 0;
2810 HWND parent = NULL;
2811 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2812 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2813
2814 psInfo->unicode = unicode;
2815 psInfo->ended = FALSE;
2816
2817 if(!psInfo->isModeless)
2818 {
2819 parent = psInfo->ppshheader.hwndParent;
2820 if (parent) EnableWindow(parent, FALSE);
2821 }
2822 bRet = PROPSHEET_CreateDialog(psInfo);
2823 if(!psInfo->isModeless)
2824 bRet = do_loop(psInfo);
2825 return bRet;
2826 }
2827
2828 /******************************************************************************
2829 * PropertySheet (COMCTL32.@)
2830 * PropertySheetA (COMCTL32.@)
2831 *
2832 * Creates a property sheet in the specified property sheet header.
2833 *
2834 * RETURNS
2835 * Modal property sheets: Positive if successful or -1 otherwise.
2836 * Modeless property sheets: Property sheet handle.
2837 * Or:
2838 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2839 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2840 */
2841 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2842 {
2843 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2844 UINT i, n;
2845 const BYTE* pByte;
2846
2847 TRACE("(%p)\n", lppsh);
2848
2849 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2850
2851 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2852 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2853
2854 for (n = i = 0; i < lppsh->nPages; i++, n++)
2855 {
2856 if (!psInfo->usePropPage)
2857 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2858 else
2859 {
2860 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2861 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2862 }
2863
2864 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2865 psInfo, n, TRUE))
2866 {
2867 if (psInfo->usePropPage)
2868 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2869 n--;
2870 psInfo->nPages--;
2871 }
2872 }
2873
2874 return PROPSHEET_PropertySheet(psInfo, FALSE);
2875 }
2876
2877 /******************************************************************************
2878 * PropertySheetW (COMCTL32.@)
2879 *
2880 * See PropertySheetA.
2881 */
2882 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2883 {
2884 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2885 UINT i, n;
2886 const BYTE* pByte;
2887
2888 TRACE("(%p)\n", lppsh);
2889
2890 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2891
2892 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2893 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2894
2895 for (n = i = 0; i < lppsh->nPages; i++, n++)
2896 {
2897 if (!psInfo->usePropPage)
2898 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2899 else
2900 {
2901 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2902 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2903 }
2904
2905 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2906 psInfo, n, TRUE))
2907 {
2908 if (psInfo->usePropPage)
2909 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2910 n--;
2911 psInfo->nPages--;
2912 }
2913 }
2914
2915 return PROPSHEET_PropertySheet(psInfo, TRUE);
2916 }
2917
2918 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2919 {
2920 LPWSTR ret;
2921
2922 if (IS_INTRESOURCE(str))
2923 {
2924 HRSRC hrsrc;
2925 HGLOBAL hmem;
2926 WCHAR *ptr;
2927 WORD i, id = LOWORD(str);
2928 UINT len;
2929
2930 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2931 return NULL;
2932 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2933 if (!(ptr = LockResource( hmem ))) return NULL;
2934 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2935 len = *ptr;
2936 if (!len) return NULL;
2937 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2938 if (ret)
2939 {
2940 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2941 ret[len] = 0;
2942 }
2943 }
2944 else
2945 {
2946 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2947 ret = Alloc( len );
2948 if (ret) memcpy( ret, str, len );
2949 }
2950 return ret;
2951 }
2952
2953
2954 /******************************************************************************
2955 * CreatePropertySheetPage (COMCTL32.@)
2956 * CreatePropertySheetPageA (COMCTL32.@)
2957 *
2958 * Creates a new property sheet page.
2959 *
2960 * RETURNS
2961 * Success: Handle to new property sheet page.
2962 * Failure: NULL.
2963 *
2964 * NOTES
2965 * An application must use the PSM_ADDPAGE message to add the new page to
2966 * an existing property sheet.
2967 */
2968 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2969 LPCPROPSHEETPAGEA lpPropSheetPage)
2970 {
2971 PROPSHEETPAGEW *ppsp;
2972
2973 if (lpPropSheetPage->dwSize < PROPSHEETPAGEA_V1_SIZE)
2974 return NULL;
2975
2976 /* original data is used for callback notifications */
2977 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
2978 {
2979 ppsp = Alloc(2 * sizeof(*ppsp));
2980 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2981 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2982 }
2983 else
2984 {
2985 ppsp = Alloc(sizeof(*ppsp));
2986 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2987 }
2988
2989 ppsp->dwFlags &= ~PSP_INTERNAL_UNICODE;
2990
2991 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2992 {
2993 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2994 {
2995 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2996 char *template = Alloc( len );
2997
2998 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2999 }
3000 }
3001
3002 if (ppsp->dwFlags & PSP_USEICONID)
3003 {
3004 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3005 ppsp->u2.pszIcon = heap_strdupAtoW( lpPropSheetPage->u2.pszIcon );
3006 }
3007
3008 if (ppsp->dwFlags & PSP_USETITLE)
3009 {
3010 if (IS_INTRESOURCE( ppsp->pszTitle ))
3011 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3012 else
3013 ppsp->pszTitle = heap_strdupAtoW( lpPropSheetPage->pszTitle );
3014 }
3015 else
3016 ppsp->pszTitle = NULL;
3017
3018 if (ppsp->dwFlags & PSP_HIDEHEADER)
3019 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3020
3021 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3022 {
3023 if (IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3024 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3025 else
3026 ppsp->pszHeaderTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderTitle );
3027 }
3028 else
3029 ppsp->pszHeaderTitle = NULL;
3030
3031 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3032 {
3033 if (IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3034 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3035 else
3036 ppsp->pszHeaderSubTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderSubTitle );
3037 }
3038 else
3039 ppsp->pszHeaderSubTitle = NULL;
3040
3041 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEA_V1_SIZE && ppsp->pfnCallback)
3042 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3043
3044 return (HPROPSHEETPAGE)ppsp;
3045 }
3046
3047 /******************************************************************************
3048 * CreatePropertySheetPageW (COMCTL32.@)
3049 *
3050 * See CreatePropertySheetA.
3051 */
3052 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3053 {
3054 PROPSHEETPAGEW *ppsp;
3055
3056 if (lpPropSheetPage->dwSize < PROPSHEETPAGEW_V1_SIZE)
3057 return NULL;
3058
3059 /* original data is used for callback notifications */
3060 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
3061 {
3062 ppsp = Alloc(2 * sizeof(*ppsp));
3063 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3064 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3065 }
3066 else
3067 {
3068 ppsp = Alloc(sizeof(*ppsp));
3069 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3070 }
3071
3072 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3073
3074 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3075 {
3076 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3077 ppsp->u.pszTemplate = heap_strdupW( lpPropSheetPage->u.pszTemplate );
3078 }
3079
3080 if ( ppsp->dwFlags & PSP_USEICONID )
3081 {
3082 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3083 ppsp->u2.pszIcon = heap_strdupW( lpPropSheetPage->u2.pszIcon );
3084 }
3085
3086 if (ppsp->dwFlags & PSP_USETITLE)
3087 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3088 else
3089 ppsp->pszTitle = NULL;
3090
3091 if (ppsp->dwFlags & PSP_HIDEHEADER)
3092 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3093
3094 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3095 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3096 else
3097 ppsp->pszHeaderTitle = NULL;
3098
3099 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3100 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3101 else
3102 ppsp->pszHeaderSubTitle = NULL;
3103
3104 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEW_V1_SIZE && ppsp->pfnCallback)
3105 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3106
3107 return (HPROPSHEETPAGE)ppsp;
3108 }
3109
3110 /******************************************************************************
3111 * DestroyPropertySheetPage (COMCTL32.@)
3112 *
3113 * Destroys a property sheet page previously created with
3114 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3115 * memory.
3116 *
3117 * RETURNS
3118 * Success: TRUE
3119 * Failure: FALSE
3120 */
3121 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3122 {
3123 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3124
3125 if (!psp)
3126 return FALSE;
3127
3128 if ((psp->dwFlags & PSP_USECALLBACK) && psp->pfnCallback)
3129 psp->pfnCallback(0, PSPCB_RELEASE, psp + 1);
3130
3131 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3132 Free ((LPVOID)psp->u.pszTemplate);
3133
3134 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3135 Free ((LPVOID)psp->u2.pszIcon);
3136
3137 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3138 Free ((LPVOID)psp->pszTitle);
3139
3140 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3141 Free ((LPVOID)psp->pszHeaderTitle);
3142
3143 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3144 Free ((LPVOID)psp->pszHeaderSubTitle);
3145
3146 Free(hPropPage);
3147
3148 return TRUE;
3149 }
3150
3151 /******************************************************************************
3152 * PROPSHEET_IsDialogMessage
3153 */
3154 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3155 {
3156 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3157
3158 TRACE("\n");
3159 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3160 return FALSE;
3161
3162 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3163 {
3164 int new_page = 0;
3165 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3166
3167 if (!(dlgCode & DLGC_WANTMESSAGE))
3168 {
3169 switch (lpMsg->wParam)
3170 {
3171 case VK_TAB:
3172 if (GetKeyState(VK_SHIFT) & 0x8000)
3173 new_page = -1;
3174 else
3175 new_page = 1;
3176 break;
3177
3178 case VK_NEXT: new_page = 1; break;
3179 case VK_PRIOR: new_page = -1; break;
3180 }
3181 }
3182
3183 if (new_page)
3184 {
3185 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3186 {
3187 new_page += psInfo->active_page;
3188
3189 if (new_page < 0)
3190 new_page = psInfo->nPages - 1;
3191 else if (new_page >= psInfo->nPages)
3192 new_page = 0;
3193
3194 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3195 }
3196
3197 return TRUE;
3198 }
3199 }
3200
3201 return IsDialogMessageW(hwnd, lpMsg);
3202 }
3203
3204 /******************************************************************************
3205 * PROPSHEET_DoCommand
3206 */
3207 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3208 {
3209
3210 switch (wID) {
3211
3212 case IDOK:
3213 case IDC_APPLY_BUTTON:
3214 {
3215 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3216
3217 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3218 break;
3219
3220 if (wID == IDOK)
3221 {
3222 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3223
3224 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3225 if (psInfo->result == 0)
3226 psInfo->result = IDOK;
3227
3228 if (psInfo->isModeless)
3229 psInfo->activeValid = FALSE;
3230 else
3231 psInfo->ended = TRUE;
3232 }
3233 else
3234 EnableWindow(hwndApplyBtn, FALSE);
3235
3236 break;
3237 }
3238
3239 case IDC_BACK_BUTTON:
3240 PROPSHEET_Back(hwnd);
3241 break;
3242
3243 case IDC_NEXT_BUTTON:
3244 PROPSHEET_Next(hwnd);
3245 break;
3246
3247 case IDC_FINISH_BUTTON:
3248 PROPSHEET_Finish(hwnd);
3249 break;
3250
3251 case IDCANCEL:
3252 PROPSHEET_Cancel(hwnd, 0);
3253 break;
3254
3255 case IDHELP:
3256 PROPSHEET_Help(hwnd);
3257 break;
3258
3259 default:
3260 return FALSE;
3261 }
3262
3263 return TRUE;
3264 }
3265
3266 /******************************************************************************
3267 * PROPSHEET_Paint
3268 */
3269 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3270 {
3271 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3272 PAINTSTRUCT ps;
3273 HDC hdc, hdcSrc;
3274 BITMAP bm;
3275 HBITMAP hbmp;
3276 HPALETTE hOldPal = 0;
3277 int offsety = 0;
3278 HBRUSH hbr;
3279 RECT r, rzone;
3280 LPCPROPSHEETPAGEW ppshpage;
3281 WCHAR szBuffer[256];
3282 int nLength;
3283
3284 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3285 if (!hdc) return 1;
3286
3287 hdcSrc = CreateCompatibleDC(0);
3288
3289 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3290 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3291
3292 if (psInfo->active_page < 0)
3293 ppshpage = NULL;
3294 else
3295 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3296
3297 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3298 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3299 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3300 {
3301 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3302 HFONT hOldFont;
3303 COLORREF clrOld = 0;
3304 int oldBkMode = 0;
3305
3306 GetClientRect(hwndLineHeader, &r);
3307 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3308 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3309
3310 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3311
3312 #ifdef __REACTOS__
3313 if (psInfo->ppshheader.u5.hbmHeader)
3314 #else
3315 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3316 #endif
3317 {
3318 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3319
3320 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3321 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3322 {
3323 /* Fill the unoccupied part of the header with color of the
3324 * left-top pixel, but do it only when needed.
3325 */
3326 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3327 {
3328 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3329 r = rzone;
3330 if (bm.bmWidth < r.right)
3331 {
3332 r.left = bm.bmWidth;
3333 FillRect(hdc, &r, hbr);
3334 }
3335 if (bm.bmHeight < r.bottom)
3336 {
3337 r.left = 0;
3338 r.top = bm.bmHeight;
3339 FillRect(hdc, &r, hbr);
3340 }
3341 DeleteObject(hbr);
3342 }
3343
3344 /* Draw the header itself. */
3345 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3346 hdcSrc, 0, 0, SRCCOPY);
3347 }
3348 else
3349 {
3350 int margin;
3351 hbr = GetSysColorBrush(COLOR_WINDOW);
3352 FillRect(hdc, &rzone, hbr);
3353
3354 /* Draw the header bitmap. It's always centered like a
3355 * common 49 x 49 bitmap. */
3356 margin = (rzone.bottom - 49) / 2;
3357 BitBlt(hdc, rzone.right - 49 - margin, margin,
3358 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3359 hdcSrc, 0, 0, SRCCOPY);
3360
3361 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3362 * if its height is smaller than 49 pixels. Because the reason
3363 * for this bug is unknown the current code doesn't try to
3364 * replicate it. */
3365 }
3366
3367 SelectObject(hdcSrc, hbmp);
3368 }
3369
3370 clrOld = SetTextColor (hdc, 0x00000000);
3371 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3372
3373 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3374 SetRect(&r, 20, 10, 0, 0);
3375 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3376 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3377 else
3378 {
3379 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3380 szBuffer, 256);
3381 if (nLength != 0)
3382 {
3383 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3384 }
3385 }
3386 }
3387
3388 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3389 SelectObject(hdc, psInfo->hFont);
3390 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3391 #ifdef __REACTOS__
3392 if (!IS_INTRESOURCE(ppshpage->pszHeaderSubTitle))
3393 #else
3394 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3395 #endif
3396 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3397 else
3398 {
3399 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3400 szBuffer, 256);
3401 if (nLength != 0)
3402 {
3403 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3404 }
3405 }
3406 }
3407
3408 offsety = rzone.bottom + 2;
3409
3410 SetTextColor(hdc, clrOld);
3411 SetBkMode(hdc, oldBkMode);
3412 SelectObject(hdc, hOldFont);
3413 }
3414
3415 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3416 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3417 #ifdef __REACTOS__
3418 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
3419 (psInfo->ppshheader.u4.hbmWatermark) )
3420 #else
3421 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3422 #endif
3423 {
3424 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3425
3426 GetClientRect(hwndLine, &r);
3427 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3428 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3429
3430 hbr = GetSysColorBrush(COLOR_WINDOW);
3431 FillRect(hdc, &rzone, hbr);
3432
3433 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3434 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3435
3436 /* The watermark is truncated to a width of 164 pixels */
3437 r.right = min(r.right, 164);
3438 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3439 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3440
3441 /* If the bitmap is not big enough, fill the remaining area
3442 with the color of pixel (0,0) of bitmap - see MSDN */
3443 if (r.top > bm.bmHeight) {
3444 r.bottom = r.top - 1;
3445 r.top = bm.bmHeight;
3446 r.left = 0;
3447 r.right = bm.bmWidth;
3448 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3449 FillRect(hdc, &r, hbr);
3450 DeleteObject(hbr);
3451 }
3452
3453 SelectObject(hdcSrc, hbmp);
3454 }
3455
3456 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3457 SelectPalette(hdc, hOldPal, FALSE);
3458
3459 DeleteDC(hdcSrc);
3460
3461 if (!hdcParam) EndPaint(hwnd, &ps);
3462
3463 return 0;
3464 }
3465
3466 /******************************************************************************
3467 * PROPSHEET_DialogProc
3468 */
3469 static INT_PTR CALLBACK
3470 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3471 {
3472 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3473 hwnd, uMsg, wParam, lParam);
3474
3475 switch (uMsg)
3476 {
3477 case WM_INITDIALOG:
3478 {
3479 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3480 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3481 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3482 int idx;
3483 LOGFONTW logFont;
3484
3485 /* Using PropSheetInfoStr to store extra data doesn't match the native
3486 * common control: native uses TCM_[GS]ETITEM
3487 */
3488 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3489
3490 /*
3491 * psInfo->hwnd is not being used by WINE code - it exists
3492 * for compatibility with "real" Windoze. The same about
3493 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3494 * property.
3495 */
3496 psInfo->hwnd = hwnd;
3497 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3498
3499 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3500 {
3501 /* set up the Next and Back buttons by default */
3502 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3503 }
3504
3505 /* Set up fonts */
3506 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3507 psInfo->hFont = CreateFontIndirectW (&logFont);
3508 logFont.lfWeight = FW_BOLD;
3509 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3510
3511 /*
3512 * Small icon in the title bar.
3513 */
3514 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3515 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3516 {
3517 HICON hIcon;
3518 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3519 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3520
3521 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3522 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3523 psInfo->ppshheader.u.pszIcon,
3524 IMAGE_ICON,
3525 icon_cx, icon_cy,
3526 LR_DEFAULTCOLOR);
3527 else
3528 hIcon = psInfo->ppshheader.u.hIcon;
3529
3530 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3531 }
3532
3533 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3534 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3535
3536 psInfo->strPropertiesFor = strCaption;
3537
3538 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3539
3540 PROPSHEET_CreateTabControl(hwnd, psInfo);
3541
3542 PROPSHEET_LoadWizardBitmaps(psInfo);
3543
3544 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3545 {
3546 ShowWindow(hwndTabCtrl, SW_HIDE);
3547 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3548 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3549 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3550 }
3551 else
3552 {
3553 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3554 {
3555 PROPSHEET_AdjustSize(hwnd, psInfo);
3556 PROPSHEET_AdjustButtons(hwnd, psInfo);
3557 }
3558 SetFocus(GetDlgItem(hwnd, IDOK));
3559 }
3560
3561 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3562 psInfo->ppshheader.hInstance)
3563 {
3564 WCHAR szText[256];
3565
3566 if (LoadStringW(psInfo->ppshheader.hInstance,
3567 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3568 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3569 }
3570 else
3571 {
3572 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3573 psInfo->ppshheader.pszCaption);
3574 }
3575
3576
3577 if (psInfo->useCallback)
3578 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3579
3580 idx = psInfo->active_page;
3581 psInfo->active_page = -1;
3582
3583 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3584
3585 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3586 * as some programs call TCM_GETCURSEL to get the current selection
3587 * from which to switch to the next page */
3588 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3589
3590 PROPSHEET_UnChanged(hwnd, NULL);
3591
3592 /* wizards set their focus during init */
3593 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3594 return FALSE;
3595
3596 return TRUE;
3597 }
3598
3599 case WM_PRINTCLIENT:
3600 case WM_PAINT:
3601 PROPSHEET_Paint(hwnd, (HDC)wParam);
3602 return TRUE;
3603
3604 case WM_DESTROY:
3605 PROPSHEET_CleanUp(hwnd);
3606 return TRUE;
3607
3608 case WM_CLOSE:
3609 PROPSHEET_Cancel(hwnd, 1);
3610 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3611
3612 case WM_COMMAND:
3613 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3614 {
3615 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3616
3617 if (!psInfo)
3618 return FALSE;
3619
3620 /* No default handler, forward notification to active page */
3621 if (psInfo->activeValid && psInfo->active_page != -1)
3622 {
3623 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3624 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3625 }
3626 }
3627 return TRUE;
3628
3629 case WM_NOTIFY:
3630 {
3631 NMHDR* pnmh = (LPNMHDR) lParam;
3632
3633 if (pnmh->code == TCN_SELCHANGE)
3634 {
3635 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3636 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3637 }
3638
3639 if(pnmh->code == TCN_SELCHANGING)
3640 {
3641 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3642 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3643 return TRUE;
3644 }
3645
3646 return FALSE;
3647 }
3648
3649 case WM_SYSCOLORCHANGE:
3650 COMCTL32_RefreshSysColors();
3651 return FALSE;
3652
3653 case PSM_GETCURRENTPAGEHWND:
3654 {
3655 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3656 HWND hwndPage = 0;
3657
3658 if (!psInfo)
3659 return FALSE;
3660
3661 if (psInfo->activeValid && psInfo->active_page != -1)
3662 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3663
3664 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3665
3666 return TRUE;
3667 }
3668
3669 case PSM_CHANGED:
3670 PROPSHEET_Changed(hwnd, (HWND)wParam);
3671 return TRUE;
3672
3673 case PSM_UNCHANGED:
3674 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3675 return TRUE;
3676
3677 case PSM_GETTABCONTROL:
3678 {
3679 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3680
3681 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3682
3683 return TRUE;
3684 }
3685
3686 case PSM_SETCURSEL:
3687 {
3688 BOOL msgResult;
3689
3690 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3691 if(msgResult != FALSE)
3692 {
3693 msgResult = PROPSHEET_SetCurSel(hwnd,
3694 (int)wParam,
3695 1,
3696 (HPROPSHEETPAGE)lParam);
3697 }
3698
3699 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3700
3701 return TRUE;
3702 }
3703
3704 case PSM_CANCELTOCLOSE:
3705 {
3706 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3707 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3708 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3709
3710 EnableWindow(hwndCancel, FALSE);
3711 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3712 SetWindowTextW(hwndOK, buf);
3713
3714 return FALSE;
3715 }
3716
3717 case PSM_RESTARTWINDOWS:
3718 {
3719 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3720
3721 if (!psInfo)
3722 return FALSE;
3723
3724 /* reboot system takes precedence over restart windows */
3725 if (psInfo->result != ID_PSREBOOTSYSTEM)
3726 psInfo->result = ID_PSRESTARTWINDOWS;
3727
3728 return TRUE;
3729 }
3730
3731 case PSM_REBOOTSYSTEM:
3732 {
3733 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3734
3735 if (!psInfo)
3736 return FALSE;
3737
3738 psInfo->result = ID_PSREBOOTSYSTEM;
3739
3740 return TRUE;
3741 }
3742
3743 case PSM_SETTITLEA:
3744 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3745 return TRUE;
3746
3747 case PSM_SETTITLEW:
3748 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3749 return TRUE;
3750
3751 case PSM_APPLY:
3752 {
3753 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3754
3755 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3756
3757 return TRUE;
3758 }
3759
3760 case PSM_QUERYSIBLINGS:
3761 {
3762 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3763
3764 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3765
3766 return TRUE;
3767 }
3768
3769 case PSM_ADDPAGE:
3770 {
3771 /*
3772 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3773 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3774 * on success or FALSE otherwise, as specified on MSDN Online.
3775 * Also see the MFC code for
3776 * CPropertySheet::AddPage(CPropertyPage* pPage).
3777 */
3778
3779 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3780
3781 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3782
3783 return TRUE;
3784 }
3785
3786 case PSM_REMOVEPAGE:
3787 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3788 return TRUE;
3789
3790 case PSM_ISDIALOGMESSAGE:
3791 {
3792 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3793 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3794 return TRUE;
3795 }
3796
3797 case PSM_PRESSBUTTON:
3798 PROPSHEET_PressButton(hwnd, (int)wParam);
3799 return TRUE;
3800
3801 case PSM_SETFINISHTEXTA:
3802 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3803 return TRUE;
3804
3805 case PSM_SETWIZBUTTONS:
3806 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3807 return TRUE;
3808
3809 case PSM_SETCURSELID:
3810 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3811 return TRUE;
3812
3813 case PSM_SETFINISHTEXTW:
3814 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3815 return FALSE;
3816
3817 case PSM_INSERTPAGE:
3818 {
3819 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3820 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3821 return TRUE;
3822 }
3823
3824 case PSM_SETHEADERTITLEW:
3825 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3826 return TRUE;
3827
3828 case PSM_SETHEADERTITLEA:
3829 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3830 return TRUE;
3831
3832 case PSM_SETHEADERSUBTITLEW:
3833 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3834 return TRUE;
3835
3836 case PSM_SETHEADERSUBTITLEA:
3837 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3838 return TRUE;
3839
3840 case PSM_HWNDTOINDEX:
3841 {
3842 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3843 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3844 return TRUE;
3845 }
3846
3847 case PSM_INDEXTOHWND:
3848 {
3849 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3850 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3851 return TRUE;
3852 }
3853
3854 case PSM_PAGETOINDEX:
3855 {
3856 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3857 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3858 return TRUE;
3859 }
3860
3861 case PSM_INDEXTOPAGE:
3862 {
3863 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3864 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3865 return TRUE;
3866 }
3867
3868 case PSM_IDTOINDEX:
3869 {
3870 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3871 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3872 return TRUE;
3873 }
3874
3875 case PSM_INDEXTOID:
3876 {
3877 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3878 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3879 return TRUE;
3880 }
3881
3882 case PSM_GETRESULT:
3883 {
3884 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3885 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3886 return TRUE;
3887 }
3888
3889 case PSM_RECALCPAGESIZES:
3890 {
3891 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3892 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3893 return TRUE;
3894 }
3895
3896 default:
3897 return FALSE;
3898 }
3899 }