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