comctl32: Set the result to IDOK on 'Finish'.
[wine/multimedia.git] / dlls / comctl32 / propsheet.c
bloba865f513460ae6de078774721c9ad123aa7c5ca7
1 /*
2 * Property Sheets
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
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.
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.
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
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.
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.
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
55 #include <stdarg.h>
56 #include <string.h>
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winuser.h"
64 #include "winnls.h"
65 #include "commctrl.h"
66 #include "prsht.h"
67 #include "comctl32.h"
68 #include "uxtheme.h"
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
73 /******************************************************************************
74 * Data structures
76 #include "pshpack2.h"
78 typedef struct
80 WORD dlgVer;
81 WORD signature;
82 DWORD helpID;
83 DWORD exStyle;
84 DWORD style;
85 } MyDLGTEMPLATEEX;
87 typedef struct
89 DWORD helpid;
90 DWORD exStyle;
91 DWORD style;
92 short x;
93 short y;
94 short cx;
95 short cy;
96 DWORD id;
97 } MyDLGITEMTEMPLATEEX;
98 #include "poppack.h"
100 typedef struct tagPropPageInfo
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 HWND hwndPage;
104 BOOL isDirty;
105 LPCWSTR pszText;
106 BOOL hasHelp;
107 BOOL useCallback;
108 BOOL hasIcon;
109 } PropPageInfo;
111 typedef struct tagPropSheetInfo
113 HWND hwnd;
114 PROPSHEETHEADERW ppshheader;
115 BOOL unicode;
116 LPWSTR strPropertiesFor;
117 int nPages;
118 int active_page;
119 BOOL isModeless;
120 BOOL hasHelp;
121 BOOL hasApply;
122 BOOL hasFinish;
123 BOOL useCallback;
124 BOOL activeValid;
125 PropPageInfo* proppage;
126 HFONT hFont;
127 HFONT hFontBold;
128 int width;
129 int height;
130 HIMAGELIST hImageList;
131 BOOL ended;
132 INT result;
133 } PropSheetInfo;
135 typedef struct
137 int x;
138 int y;
139 } PADDING_INFO;
141 /******************************************************************************
142 * Defines and global variables
145 static const WCHAR PropSheetInfoStr[] =
146 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
148 #define PSP_INTERNAL_UNICODE 0x80000000
150 #define MAX_CAPTION_LENGTH 255
151 #define MAX_TABTEXT_LENGTH 255
152 #define MAX_BUTTONTEXT_LENGTH 64
154 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
156 /* Wizard metrics specified in DLUs */
157 #define WIZARD_PADDING 7
158 #define WIZARD_HEADER_HEIGHT 36
160 /******************************************************************************
161 * Prototypes
163 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
164 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
165 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
166 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
167 int index,
168 int skipdir,
169 HPROPSHEETPAGE hpage);
170 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
171 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
172 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 static INT_PTR CALLBACK
175 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
179 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
180 /******************************************************************************
181 * PROPSHEET_UnImplementedFlags
183 * Document use of flags we don't implement yet.
185 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
187 CHAR string[256];
189 string[0] = '\0';
192 * unhandled header flags:
193 * PSH_RTLREADING 0x00000800
194 * PSH_STRETCHWATERMARK 0x00040000
195 * PSH_USEPAGELANG 0x00200000
198 add_flag(PSH_RTLREADING);
199 add_flag(PSH_STRETCHWATERMARK);
200 add_flag(PSH_USEPAGELANG);
201 if (string[0] != '\0')
202 FIXME("%s\n", string);
204 #undef add_flag
206 /******************************************************************************
207 * PROPSHEET_GetPageRect
209 * Retrieve rect from tab control and map into the dialog for SetWindowPos
211 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
212 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
214 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
215 HWND hwndChild;
216 RECT r;
218 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
219 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
220 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
221 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
223 rc->left = rc->top = WIZARD_PADDING;
225 else
227 rc->left = rc->top = 0;
229 rc->right = psInfo->width - rc->left;
230 rc->bottom = psInfo->height - rc->top;
231 MapDialogRect(hwndDlg, rc);
233 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
234 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
235 !(ppshpage->dwFlags & PSP_HIDEHEADER))
237 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
238 GetClientRect(hwndChild, &r);
239 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
240 rc->top += r.bottom + 1;
242 } else {
243 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
244 GetClientRect(hwndTabCtrl, rc);
245 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
246 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
250 /******************************************************************************
251 * PROPSHEET_FindPageByResId
253 * Find page index corresponding to page resource id.
255 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
257 INT i;
259 for (i = 0; i < psInfo->nPages; i++)
261 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
263 /* Fixme: if resource ID is a string shall we use strcmp ??? */
264 if (lppsp->u.pszTemplate == (LPVOID)resId)
265 break;
268 return i;
271 /******************************************************************************
272 * PROPSHEET_AtoW
274 * Convert ASCII to Unicode since all data is saved as Unicode.
276 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
278 INT len;
280 TRACE("<%s>\n", frstr);
281 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
282 *tostr = Alloc(len * sizeof(WCHAR));
283 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
286 /******************************************************************************
287 * PROPSHEET_CollectSheetInfoA
289 * Collect relevant data.
291 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
292 PropSheetInfo * psInfo)
294 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
295 DWORD dwFlags = lppsh->dwFlags;
297 psInfo->hasHelp = dwFlags & PSH_HASHELP;
298 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
299 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
300 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
303 memcpy(&psInfo->ppshheader,lppsh,dwSize);
304 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",
305 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
306 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
308 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
310 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
311 psInfo->ppshheader.pszCaption = NULL;
312 else
314 if (HIWORD(lppsh->pszCaption))
316 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
317 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
318 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
321 psInfo->nPages = lppsh->nPages;
323 if (dwFlags & PSH_USEPSTARTPAGE)
325 TRACE("PSH_USEPSTARTPAGE is on\n");
326 psInfo->active_page = 0;
328 else
329 psInfo->active_page = lppsh->u2.nStartPage;
331 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
332 psInfo->active_page = 0;
334 psInfo->result = 0;
335 psInfo->hImageList = 0;
336 psInfo->activeValid = FALSE;
338 return TRUE;
341 /******************************************************************************
342 * PROPSHEET_CollectSheetInfoW
344 * Collect relevant data.
346 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
347 PropSheetInfo * psInfo)
349 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
350 DWORD dwFlags = lppsh->dwFlags;
352 psInfo->hasHelp = dwFlags & PSH_HASHELP;
353 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
354 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
355 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
356 psInfo->isModeless = dwFlags & PSH_MODELESS;
358 memcpy(&psInfo->ppshheader,lppsh,dwSize);
359 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",
360 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
362 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
364 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
365 psInfo->ppshheader.pszCaption = NULL;
366 else
368 if (HIWORD(lppsh->pszCaption))
370 int len = strlenW(lppsh->pszCaption);
371 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
372 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
375 psInfo->nPages = lppsh->nPages;
377 if (dwFlags & PSH_USEPSTARTPAGE)
379 TRACE("PSH_USEPSTARTPAGE is on\n");
380 psInfo->active_page = 0;
382 else
383 psInfo->active_page = lppsh->u2.nStartPage;
385 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
386 psInfo->active_page = 0;
388 psInfo->result = 0;
389 psInfo->hImageList = 0;
390 psInfo->activeValid = FALSE;
392 return TRUE;
395 /******************************************************************************
396 * PROPSHEET_CollectPageInfo
398 * Collect property sheet data.
399 * With code taken from DIALOG_ParseTemplate32.
401 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
402 PropSheetInfo * psInfo,
403 int index)
405 DLGTEMPLATE* pTemplate;
406 const WORD* p;
407 DWORD dwFlags;
408 int width, height;
410 if (!lppsp)
411 return FALSE;
413 TRACE("\n");
414 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
415 psInfo->proppage[index].hwndPage = 0;
416 psInfo->proppage[index].isDirty = FALSE;
419 * Process property page flags.
421 dwFlags = lppsp->dwFlags;
422 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
423 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
424 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
426 /* as soon as we have a page with the help flag, set the sheet flag on */
427 if (psInfo->proppage[index].hasHelp)
428 psInfo->hasHelp = TRUE;
431 * Process page template.
433 if (dwFlags & PSP_DLGINDIRECT)
434 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
435 else if(dwFlags & PSP_INTERNAL_UNICODE )
437 HRSRC hResource = FindResourceW(lppsp->hInstance,
438 lppsp->u.pszTemplate,
439 (LPWSTR)RT_DIALOG);
440 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
441 hResource);
442 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
444 else
446 HRSRC hResource = FindResourceA(lppsp->hInstance,
447 (LPCSTR)lppsp->u.pszTemplate,
448 (LPSTR)RT_DIALOG);
449 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
450 hResource);
451 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
455 * Extract the size of the page and the caption.
457 if (!pTemplate)
458 return FALSE;
460 p = (const WORD *)pTemplate;
462 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
464 /* DLGTEMPLATEEX (not defined in any std. header file) */
466 p++; /* dlgVer */
467 p++; /* signature */
468 p += 2; /* help ID */
469 p += 2; /* ext style */
470 p += 2; /* style */
472 else
474 /* DLGTEMPLATE */
476 p += 2; /* style */
477 p += 2; /* ext style */
480 p++; /* nb items */
481 p++; /* x */
482 p++; /* y */
483 width = (WORD)*p; p++;
484 height = (WORD)*p; p++;
486 /* Special calculation for interior wizard pages so the largest page is
487 * calculated correctly. We need to add all the padding and space occupied
488 * by the header so the width and height sums up to the whole wizard client
489 * area. */
490 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
491 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
492 !(dwFlags & PSP_HIDEHEADER))
494 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
495 width += 2 * WIZARD_PADDING;
497 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
499 height += 2 * WIZARD_PADDING;
500 width += 2 * WIZARD_PADDING;
503 /* remember the largest width and height */
504 if (width > psInfo->width)
505 psInfo->width = width;
507 if (height > psInfo->height)
508 psInfo->height = height;
510 /* menu */
511 switch ((WORD)*p)
513 case 0x0000:
514 p++;
515 break;
516 case 0xffff:
517 p += 2;
518 break;
519 default:
520 p += lstrlenW( (LPCWSTR)p ) + 1;
521 break;
524 /* class */
525 switch ((WORD)*p)
527 case 0x0000:
528 p++;
529 break;
530 case 0xffff:
531 p += 2;
532 break;
533 default:
534 p += lstrlenW( (LPCWSTR)p ) + 1;
535 break;
538 /* Extract the caption */
539 psInfo->proppage[index].pszText = (LPCWSTR)p;
540 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
541 p += lstrlenW((LPCWSTR)p) + 1;
543 if (dwFlags & PSP_USETITLE)
545 WCHAR szTitle[256];
546 const WCHAR *pTitle;
547 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
548 int len;
550 if ( !HIWORD( lppsp->pszTitle ) )
552 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
554 pTitle = pszNull;
555 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
557 else
558 pTitle = szTitle;
560 else
561 pTitle = lppsp->pszTitle;
563 len = strlenW(pTitle);
564 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
565 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
569 * Build the image list for icons
571 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
573 HICON hIcon;
574 int icon_cx = GetSystemMetrics(SM_CXSMICON);
575 int icon_cy = GetSystemMetrics(SM_CYSMICON);
577 if (dwFlags & PSP_USEICONID)
578 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
579 icon_cx, icon_cy, LR_DEFAULTCOLOR);
580 else
581 hIcon = lppsp->u2.hIcon;
583 if ( hIcon )
585 if (psInfo->hImageList == 0 )
586 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
588 ImageList_AddIcon(psInfo->hImageList, hIcon);
593 return TRUE;
596 /******************************************************************************
597 * PROPSHEET_CreateDialog
599 * Creates the actual property sheet.
601 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
603 LRESULT ret;
604 LPCVOID template;
605 LPVOID temp = 0;
606 HRSRC hRes;
607 DWORD resSize;
608 WORD resID = IDD_PROPSHEET;
610 TRACE("\n");
611 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
612 resID = IDD_WIZARD;
614 if( psInfo->unicode )
616 if(!(hRes = FindResourceW(COMCTL32_hModule,
617 MAKEINTRESOURCEW(resID),
618 (LPWSTR)RT_DIALOG)))
619 return -1;
621 else
623 if(!(hRes = FindResourceA(COMCTL32_hModule,
624 MAKEINTRESOURCEA(resID),
625 (LPSTR)RT_DIALOG)))
626 return -1;
629 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
630 return -1;
633 * Make a copy of the dialog template.
635 resSize = SizeofResource(COMCTL32_hModule, hRes);
637 temp = Alloc(resSize);
639 if (!temp)
640 return -1;
642 memcpy(temp, template, resSize);
644 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
646 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
647 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
648 else
649 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
651 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
652 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
654 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
655 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
656 else
657 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
660 if (psInfo->useCallback)
661 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
663 /* NOTE: MSDN states "Returns a positive value if successful, or -1
664 * otherwise for modal property sheets.", but this is wrong. The
665 * actual return value is either TRUE (success), FALSE (cancel) or
666 * -1 (error). */
667 if( psInfo->unicode )
669 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
670 (LPDLGTEMPLATEW) temp,
671 psInfo->ppshheader.hwndParent,
672 PROPSHEET_DialogProc,
673 (LPARAM)psInfo);
674 if ( !ret ) ret = -1;
676 else
678 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
679 (LPDLGTEMPLATEA) temp,
680 psInfo->ppshheader.hwndParent,
681 PROPSHEET_DialogProc,
682 (LPARAM)psInfo);
683 if ( !ret ) ret = -1;
686 Free(temp);
688 return ret;
691 /******************************************************************************
692 * PROPSHEET_SizeMismatch
694 * Verify that the tab control and the "largest" property sheet page dlg. template
695 * match in size.
697 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
699 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
700 RECT rcOrigTab, rcPage;
703 * Original tab size.
705 GetClientRect(hwndTabCtrl, &rcOrigTab);
706 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
707 rcOrigTab.right, rcOrigTab.bottom);
710 * Biggest page size.
712 rcPage.left = 0;
713 rcPage.top = 0;
714 rcPage.right = psInfo->width;
715 rcPage.bottom = psInfo->height;
717 MapDialogRect(hwndDlg, &rcPage);
718 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
719 rcPage.right, rcPage.bottom);
721 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
722 return TRUE;
723 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
724 return TRUE;
726 return FALSE;
729 /******************************************************************************
730 * PROPSHEET_AdjustSize
732 * Resizes the property sheet and the tab control to fit the largest page.
734 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
736 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
737 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
738 RECT rc,tabRect;
739 int tabOffsetX, tabOffsetY, buttonHeight;
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
741 RECT units;
743 /* Get the height of buttons */
744 GetClientRect(hwndButton, &rc);
745 buttonHeight = rc.bottom;
748 * Biggest page size.
750 rc.left = 0;
751 rc.top = 0;
752 rc.right = psInfo->width;
753 rc.bottom = psInfo->height;
755 MapDialogRect(hwndDlg, &rc);
757 /* retrieve the dialog units */
758 units.left = units.right = 4;
759 units.top = units.bottom = 8;
760 MapDialogRect(hwndDlg, &units);
763 * Resize the tab control.
765 GetClientRect(hwndTabCtrl,&tabRect);
767 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
769 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
771 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
772 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
775 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
777 rc.right = rc.left + tabRect.right - tabRect.left;
778 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
781 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
783 tabOffsetX = -(rc.left);
784 tabOffsetY = -(rc.top);
786 rc.right -= rc.left;
787 rc.bottom -= rc.top;
788 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
789 hwndTabCtrl, rc.right, rc.bottom);
790 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
791 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
793 GetClientRect(hwndTabCtrl, &rc);
795 TRACE("tab client rc %d %d %d %d\n",
796 rc.left, rc.top, rc.right, rc.bottom);
798 rc.right += ((padding.x * 2) + tabOffsetX);
799 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
802 * Resize the property sheet.
804 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
805 hwndDlg, rc.right, rc.bottom);
806 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
807 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
808 return TRUE;
811 /******************************************************************************
812 * PROPSHEET_AdjustSizeWizard
814 * Resizes the property sheet to fit the largest page.
816 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
818 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
819 RECT rc, lineRect, dialogRect;
821 /* Biggest page size */
822 rc.left = 0;
823 rc.top = 0;
824 rc.right = psInfo->width;
825 rc.bottom = psInfo->height;
826 MapDialogRect(hwndDlg, &rc);
828 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
830 /* Add space for the buttons row */
831 GetWindowRect(hwndLine, &lineRect);
832 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
833 GetClientRect(hwndDlg, &dialogRect);
834 rc.bottom += dialogRect.bottom - lineRect.top - 1;
836 /* Convert the client coordinates to window coordinates */
837 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
839 /* Resize the property sheet */
840 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
841 hwndDlg, rc.right, rc.bottom);
842 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
843 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
845 return TRUE;
848 /******************************************************************************
849 * PROPSHEET_AdjustButtons
851 * Adjusts the buttons' positions.
853 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
855 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
856 RECT rcSheet;
857 int x, y;
858 int num_buttons = 2;
859 int buttonWidth, buttonHeight;
860 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
862 if (psInfo->hasApply)
863 num_buttons++;
865 if (psInfo->hasHelp)
866 num_buttons++;
869 * Obtain the size of the buttons.
871 GetClientRect(hwndButton, &rcSheet);
872 buttonWidth = rcSheet.right;
873 buttonHeight = rcSheet.bottom;
876 * Get the size of the property sheet.
878 GetClientRect(hwndParent, &rcSheet);
881 * All buttons will be at this y coordinate.
883 y = rcSheet.bottom - (padding.y + buttonHeight);
886 * Position OK button and make it default.
888 hwndButton = GetDlgItem(hwndParent, IDOK);
890 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
892 SetWindowPos(hwndButton, 0, x, y, 0, 0,
893 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
895 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
899 * Position Cancel button.
901 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
903 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
905 SetWindowPos(hwndButton, 0, x, y, 0, 0,
906 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
909 * Position Apply button.
911 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
913 if (psInfo->hasApply)
915 if (psInfo->hasHelp)
916 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
917 else
918 x = rcSheet.right - (padding.x + buttonWidth);
920 SetWindowPos(hwndButton, 0, x, y, 0, 0,
921 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
923 EnableWindow(hwndButton, FALSE);
925 else
926 ShowWindow(hwndButton, SW_HIDE);
929 * Position Help button.
931 hwndButton = GetDlgItem(hwndParent, IDHELP);
933 if (psInfo->hasHelp)
935 x = rcSheet.right - (padding.x + buttonWidth);
937 SetWindowPos(hwndButton, 0, x, y, 0, 0,
938 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
940 else
941 ShowWindow(hwndButton, SW_HIDE);
943 return TRUE;
946 /******************************************************************************
947 * PROPSHEET_AdjustButtonsWizard
949 * Adjusts the buttons' positions.
951 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
952 PropSheetInfo* psInfo)
954 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
955 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
956 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
957 RECT rcSheet;
958 int x, y;
959 int num_buttons = 3;
960 int buttonWidth, buttonHeight, lineHeight, lineWidth;
961 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
963 if (psInfo->hasHelp)
964 num_buttons++;
965 if (psInfo->hasFinish)
966 num_buttons++;
969 * Obtain the size of the buttons.
971 GetClientRect(hwndButton, &rcSheet);
972 buttonWidth = rcSheet.right;
973 buttonHeight = rcSheet.bottom;
975 GetClientRect(hwndLine, &rcSheet);
976 lineHeight = rcSheet.bottom;
979 * Get the size of the property sheet.
981 GetClientRect(hwndParent, &rcSheet);
984 * All buttons will be at this y coordinate.
986 y = rcSheet.bottom - (padding.y + buttonHeight);
989 * Position the Back button.
991 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
993 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
995 SetWindowPos(hwndButton, 0, x, y, 0, 0,
996 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
999 * Position the Next button.
1001 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1003 x += buttonWidth;
1005 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1006 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1009 * Position the Finish button.
1011 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1013 if (psInfo->hasFinish)
1014 x += padding.x + buttonWidth;
1016 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1017 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1019 if (!psInfo->hasFinish)
1020 ShowWindow(hwndButton, SW_HIDE);
1023 * Position the Cancel button.
1025 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1027 x += padding.x + buttonWidth;
1029 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1030 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1033 * Position Help button.
1035 hwndButton = GetDlgItem(hwndParent, IDHELP);
1037 if (psInfo->hasHelp)
1039 x += padding.x + buttonWidth;
1041 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1042 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1044 else
1045 ShowWindow(hwndButton, SW_HIDE);
1047 if (psInfo->ppshheader.dwFlags &
1048 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1049 padding.x = 0;
1052 * Position and resize the sunken line.
1054 x = padding.x;
1055 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1057 lineWidth = rcSheet.right - (padding.x * 2);
1058 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1059 SWP_NOZORDER | SWP_NOACTIVATE);
1062 * Position and resize the header sunken line.
1065 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1066 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1067 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1068 ShowWindow(hwndLineHeader, SW_HIDE);
1070 return TRUE;
1073 /******************************************************************************
1074 * PROPSHEET_GetPaddingInfo
1076 * Returns the layout information.
1078 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1080 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1081 RECT rcTab;
1082 POINT tl;
1083 PADDING_INFO padding;
1085 GetWindowRect(hwndTab, &rcTab);
1087 tl.x = rcTab.left;
1088 tl.y = rcTab.top;
1090 ScreenToClient(hwndDlg, &tl);
1092 padding.x = tl.x;
1093 padding.y = tl.y;
1095 return padding;
1098 /******************************************************************************
1099 * PROPSHEET_GetPaddingInfoWizard
1101 * Returns the layout information.
1102 * Vertical spacing is the distance between the line and the buttons.
1103 * Do NOT use the Help button to gather padding information when it isn't mapped
1104 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1105 * for it in this case !
1106 * FIXME: I'm not sure about any other coordinate problems with these evil
1107 * buttons. Fix it in case additional problems appear or maybe calculate
1108 * a padding in a completely different way, as this is somewhat messy.
1110 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1111 psInfo)
1113 PADDING_INFO padding;
1114 RECT rc;
1115 HWND hwndControl;
1116 INT idButton;
1117 POINT ptButton, ptLine;
1119 TRACE("\n");
1120 if (psInfo->hasHelp)
1122 idButton = IDHELP;
1124 else
1126 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1128 idButton = IDC_NEXT_BUTTON;
1130 else
1132 /* hopefully this is ok */
1133 idButton = IDCANCEL;
1137 hwndControl = GetDlgItem(hwndDlg, idButton);
1138 GetWindowRect(hwndControl, &rc);
1140 ptButton.x = rc.left;
1141 ptButton.y = rc.top;
1143 ScreenToClient(hwndDlg, &ptButton);
1145 /* Line */
1146 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1147 GetWindowRect(hwndControl, &rc);
1149 ptLine.x = rc.left;
1150 ptLine.y = rc.bottom;
1152 ScreenToClient(hwndDlg, &ptLine);
1154 padding.y = ptButton.y - ptLine.y;
1156 if (padding.y < 0)
1157 ERR("padding negative ! Please report this !\n");
1159 /* this is most probably not correct, but the best we have now */
1160 padding.x = padding.y;
1161 return padding;
1164 /******************************************************************************
1165 * PROPSHEET_CreateTabControl
1167 * Insert the tabs in the tab control.
1169 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1170 PropSheetInfo * psInfo)
1172 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1173 TCITEMW item;
1174 int i, nTabs;
1175 int iImage = 0;
1177 TRACE("\n");
1178 item.mask = TCIF_TEXT;
1179 item.cchTextMax = MAX_TABTEXT_LENGTH;
1181 nTabs = psInfo->nPages;
1184 * Set the image list for icons.
1186 if (psInfo->hImageList)
1188 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1191 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1192 for (i = 0; i < nTabs; i++)
1194 if ( psInfo->proppage[i].hasIcon )
1196 item.mask |= TCIF_IMAGE;
1197 item.iImage = iImage++;
1199 else
1201 item.mask &= ~TCIF_IMAGE;
1204 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1205 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1207 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1209 return TRUE;
1212 /******************************************************************************
1213 * PROPSHEET_WizardSubclassProc
1215 * Subclassing window procedure for wizard extrior pages to prevent drawing
1216 * background and so drawing above the watermark.
1218 static LRESULT CALLBACK
1219 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1221 switch (uMsg)
1223 case WM_ERASEBKGND:
1224 return TRUE;
1226 case WM_CTLCOLORSTATIC:
1227 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1228 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1231 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1235 * Get the size of an in-memory Template
1237 *( Based on the code of PROPSHEET_CollectPageInfo)
1238 * See also dialog.c/DIALOG_ParseTemplate32().
1241 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1244 const WORD* p = (const WORD *)pTemplate;
1245 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1246 WORD nrofitems;
1247 UINT ret;
1249 if (istemplateex)
1251 /* DLGTEMPLATEEX (not defined in any std. header file) */
1253 TRACE("is DLGTEMPLATEEX\n");
1254 p++; /* dlgVer */
1255 p++; /* signature */
1256 p += 2; /* help ID */
1257 p += 2; /* ext style */
1258 p += 2; /* style */
1260 else
1262 /* DLGTEMPLATE */
1264 TRACE("is DLGTEMPLATE\n");
1265 p += 2; /* style */
1266 p += 2; /* ext style */
1269 nrofitems = (WORD)*p; p++; /* nb items */
1270 p++; /* x */
1271 p++; /* y */
1272 p++; /* width */
1273 p++; /* height */
1275 /* menu */
1276 switch ((WORD)*p)
1278 case 0x0000:
1279 p++;
1280 break;
1281 case 0xffff:
1282 p += 2;
1283 break;
1284 default:
1285 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1286 p += lstrlenW( (LPCWSTR)p ) + 1;
1287 break;
1290 /* class */
1291 switch ((WORD)*p)
1293 case 0x0000:
1294 p++;
1295 break;
1296 case 0xffff:
1297 p += 2; /* 0xffff plus predefined window class ordinal value */
1298 break;
1299 default:
1300 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1301 p += lstrlenW( (LPCWSTR)p ) + 1;
1302 break;
1305 /* title */
1306 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1307 p += lstrlenW((LPCWSTR)p) + 1;
1309 /* font, if DS_SETFONT set */
1310 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1311 pTemplate->style)))
1313 p+=(istemplateex)?3:1;
1314 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1315 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1318 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1319 * that are following the DLGTEMPLATE(EX) data */
1320 TRACE("%d items\n",nrofitems);
1321 while (nrofitems > 0)
1323 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1325 /* skip header */
1326 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1328 /* check class */
1329 switch ((WORD)*p)
1331 case 0x0000:
1332 p++;
1333 break;
1334 case 0xffff:
1335 TRACE("class ordinal 0x%08x\n",*(DWORD*)p);
1336 p += 2;
1337 break;
1338 default:
1339 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1340 p += lstrlenW( (LPCWSTR)p ) + 1;
1341 break;
1344 /* check title text */
1345 switch ((WORD)*p)
1347 case 0x0000:
1348 p++;
1349 break;
1350 case 0xffff:
1351 TRACE("text ordinal 0x%08x\n",*(DWORD*)p);
1352 p += 2;
1353 break;
1354 default:
1355 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1356 p += lstrlenW( (LPCWSTR)p ) + 1;
1357 break;
1359 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1360 --nrofitems;
1363 ret = (p - (WORD*)pTemplate) * sizeof(WORD);
1364 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1365 return ret;
1368 /******************************************************************************
1369 * PROPSHEET_CreatePage
1371 * Creates a page.
1373 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1374 int index,
1375 const PropSheetInfo * psInfo,
1376 LPCPROPSHEETPAGEW ppshpage)
1378 DLGTEMPLATE* pTemplate;
1379 HWND hwndPage;
1380 DWORD resSize;
1381 LPVOID temp = NULL;
1383 TRACE("index %d\n", index);
1385 if (ppshpage == NULL)
1387 return FALSE;
1390 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1392 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1393 resSize = GetTemplateSize(pTemplate);
1395 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1397 HRSRC hResource;
1398 HANDLE hTemplate;
1400 hResource = FindResourceW(ppshpage->hInstance,
1401 ppshpage->u.pszTemplate,
1402 (LPWSTR)RT_DIALOG);
1403 if(!hResource)
1404 return FALSE;
1406 resSize = SizeofResource(ppshpage->hInstance, hResource);
1408 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1409 if(!hTemplate)
1410 return FALSE;
1412 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1414 * Make a copy of the dialog template to make it writable
1417 else
1419 HRSRC hResource;
1420 HANDLE hTemplate;
1422 hResource = FindResourceA(ppshpage->hInstance,
1423 (LPCSTR)ppshpage->u.pszTemplate,
1424 (LPSTR)RT_DIALOG);
1425 if(!hResource)
1426 return FALSE;
1428 resSize = SizeofResource(ppshpage->hInstance, hResource);
1430 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1431 if(!hTemplate)
1432 return FALSE;
1434 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1436 * Make a copy of the dialog template to make it writable
1439 temp = Alloc(resSize);
1440 if (!temp)
1441 return FALSE;
1443 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1444 memcpy(temp, pTemplate, resSize);
1445 pTemplate = temp;
1447 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1449 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1450 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1451 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1452 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1453 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1454 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1460 else
1462 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1463 pTemplate->style &= ~DS_MODALFRAME;
1464 pTemplate->style &= ~WS_CAPTION;
1465 pTemplate->style &= ~WS_SYSMENU;
1466 pTemplate->style &= ~WS_POPUP;
1467 pTemplate->style &= ~WS_DISABLED;
1468 pTemplate->style &= ~WS_VISIBLE;
1469 pTemplate->style &= ~WS_THICKFRAME;
1471 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1474 if (psInfo->proppage[index].useCallback)
1475 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1476 (LPPROPSHEETPAGEW)ppshpage);
1478 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1479 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1480 pTemplate,
1481 hwndParent,
1482 ppshpage->pfnDlgProc,
1483 (LPARAM)ppshpage);
1484 else
1485 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1486 pTemplate,
1487 hwndParent,
1488 ppshpage->pfnDlgProc,
1489 (LPARAM)ppshpage);
1490 /* Free a no more needed copy */
1491 if(temp)
1492 Free(temp);
1494 psInfo->proppage[index].hwndPage = hwndPage;
1496 /* Subclass exterior wizard pages */
1497 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1498 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1499 (ppshpage->dwFlags & PSP_HIDEHEADER))
1501 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1502 (DWORD_PTR)ppshpage);
1504 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1505 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1507 return TRUE;
1510 /******************************************************************************
1511 * PROPSHEET_LoadWizardBitmaps
1513 * Loads the watermark and header bitmaps for a wizard.
1515 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1517 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1519 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1520 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1521 considers hbmWatermark as valid. */
1522 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1523 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1525 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1526 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1529 /* Same behavior as for watermarks */
1530 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1531 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1533 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1534 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1540 /******************************************************************************
1541 * PROPSHEET_ShowPage
1543 * Displays or creates the specified page.
1545 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1547 HWND hwndTabCtrl;
1548 HWND hwndLineHeader;
1549 LPCPROPSHEETPAGEW ppshpage;
1551 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1552 if (index == psInfo->active_page)
1554 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1555 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1556 return TRUE;
1559 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1560 if (psInfo->proppage[index].hwndPage == 0)
1562 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1565 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1567 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1568 psInfo->proppage[index].pszText);
1571 if (psInfo->active_page != -1)
1572 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1574 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1576 /* Synchronize current selection with tab control
1577 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1578 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1579 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1581 psInfo->active_page = index;
1582 psInfo->activeValid = TRUE;
1584 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1586 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1587 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1589 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1590 ShowWindow(hwndLineHeader, SW_HIDE);
1591 else
1592 ShowWindow(hwndLineHeader, SW_SHOW);
1595 return TRUE;
1598 /******************************************************************************
1599 * PROPSHEET_Back
1601 static BOOL PROPSHEET_Back(HWND hwndDlg)
1603 PSHNOTIFY psn;
1604 HWND hwndPage;
1605 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1606 PropSheetInfoStr);
1607 LRESULT result;
1608 int idx;
1610 TRACE("active_page %d\n", psInfo->active_page);
1611 if (psInfo->active_page < 0)
1612 return FALSE;
1614 psn.hdr.code = PSN_WIZBACK;
1615 psn.hdr.hwndFrom = hwndDlg;
1616 psn.hdr.idFrom = 0;
1617 psn.lParam = 0;
1619 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1621 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1622 if (result == -1)
1623 return FALSE;
1624 else if (result == 0)
1625 idx = psInfo->active_page - 1;
1626 else
1627 idx = PROPSHEET_FindPageByResId(psInfo, result);
1629 if (idx >= 0 && idx < psInfo->nPages)
1631 if (PROPSHEET_CanSetCurSel(hwndDlg))
1632 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1634 return TRUE;
1637 /******************************************************************************
1638 * PROPSHEET_Next
1640 static BOOL PROPSHEET_Next(HWND hwndDlg)
1642 PSHNOTIFY psn;
1643 HWND hwndPage;
1644 LRESULT msgResult = 0;
1645 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1646 PropSheetInfoStr);
1647 int idx;
1649 TRACE("active_page %d\n", psInfo->active_page);
1650 if (psInfo->active_page < 0)
1651 return FALSE;
1653 psn.hdr.code = PSN_WIZNEXT;
1654 psn.hdr.hwndFrom = hwndDlg;
1655 psn.hdr.idFrom = 0;
1656 psn.lParam = 0;
1658 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1660 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1661 if (msgResult == -1)
1662 return FALSE;
1663 else if (msgResult == 0)
1664 idx = psInfo->active_page + 1;
1665 else
1666 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1668 if (idx < psInfo->nPages )
1670 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1671 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1674 return TRUE;
1677 /******************************************************************************
1678 * PROPSHEET_Finish
1680 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1682 PSHNOTIFY psn;
1683 HWND hwndPage;
1684 LRESULT msgResult = 0;
1685 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1686 PropSheetInfoStr);
1688 TRACE("active_page %d\n", psInfo->active_page);
1689 if (psInfo->active_page < 0)
1690 return FALSE;
1692 psn.hdr.code = PSN_WIZFINISH;
1693 psn.hdr.hwndFrom = hwndDlg;
1694 psn.hdr.idFrom = 0;
1695 psn.lParam = 0;
1697 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1699 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1701 TRACE("msg result %ld\n", msgResult);
1703 if (msgResult != 0)
1704 return FALSE;
1706 if (psInfo->result == 0)
1707 psInfo->result = IDOK;
1708 if (psInfo->isModeless)
1709 psInfo->activeValid = FALSE;
1710 else
1711 psInfo->ended = TRUE;
1713 return TRUE;
1716 /******************************************************************************
1717 * PROPSHEET_Apply
1719 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1721 int i;
1722 HWND hwndPage;
1723 PSHNOTIFY psn;
1724 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1725 PropSheetInfoStr);
1727 TRACE("active_page %d\n", psInfo->active_page);
1728 if (psInfo->active_page < 0)
1729 return FALSE;
1731 psn.hdr.hwndFrom = hwndDlg;
1732 psn.hdr.idFrom = 0;
1733 psn.lParam = 0;
1737 * Send PSN_KILLACTIVE to the current page.
1739 psn.hdr.code = PSN_KILLACTIVE;
1741 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1743 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1744 return FALSE;
1747 * Send PSN_APPLY to all pages.
1749 psn.hdr.code = PSN_APPLY;
1750 psn.lParam = lParam;
1752 for (i = 0; i < psInfo->nPages; i++)
1754 hwndPage = psInfo->proppage[i].hwndPage;
1755 if (hwndPage)
1757 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1759 case PSNRET_INVALID:
1760 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1761 /* fall through */
1762 case PSNRET_INVALID_NOCHANGEPAGE:
1763 return FALSE;
1768 if(lParam)
1770 psInfo->activeValid = FALSE;
1772 else if(psInfo->active_page >= 0)
1774 psn.hdr.code = PSN_SETACTIVE;
1775 psn.lParam = 0;
1776 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1777 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1780 return TRUE;
1783 /******************************************************************************
1784 * PROPSHEET_Cancel
1786 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1788 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1789 PropSheetInfoStr);
1790 HWND hwndPage;
1791 PSHNOTIFY psn;
1792 int i;
1794 TRACE("active_page %d\n", psInfo->active_page);
1795 if (psInfo->active_page < 0)
1796 return;
1798 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1799 psn.hdr.code = PSN_QUERYCANCEL;
1800 psn.hdr.hwndFrom = hwndDlg;
1801 psn.hdr.idFrom = 0;
1802 psn.lParam = 0;
1804 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1805 return;
1807 psn.hdr.code = PSN_RESET;
1808 psn.lParam = lParam;
1810 for (i = 0; i < psInfo->nPages; i++)
1812 hwndPage = psInfo->proppage[i].hwndPage;
1814 if (hwndPage)
1815 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1818 if (psInfo->isModeless)
1820 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1821 psInfo->activeValid = FALSE;
1823 else
1824 psInfo->ended = TRUE;
1827 /******************************************************************************
1828 * PROPSHEET_Help
1830 static void PROPSHEET_Help(HWND hwndDlg)
1832 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1833 PropSheetInfoStr);
1834 HWND hwndPage;
1835 PSHNOTIFY psn;
1837 TRACE("active_page %d\n", psInfo->active_page);
1838 if (psInfo->active_page < 0)
1839 return;
1841 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1842 psn.hdr.code = PSN_HELP;
1843 psn.hdr.hwndFrom = hwndDlg;
1844 psn.hdr.idFrom = 0;
1845 psn.lParam = 0;
1847 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1850 /******************************************************************************
1851 * PROPSHEET_Changed
1853 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1855 int i;
1856 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1857 PropSheetInfoStr);
1859 TRACE("\n");
1860 if (!psInfo) return;
1862 * Set the dirty flag of this page.
1864 for (i = 0; i < psInfo->nPages; i++)
1866 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1867 psInfo->proppage[i].isDirty = TRUE;
1871 * Enable the Apply button.
1873 if (psInfo->hasApply)
1875 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1877 EnableWindow(hwndApplyBtn, TRUE);
1881 /******************************************************************************
1882 * PROPSHEET_UnChanged
1884 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1886 int i;
1887 BOOL noPageDirty = TRUE;
1888 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1889 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1890 PropSheetInfoStr);
1892 TRACE("\n");
1893 if ( !psInfo ) return;
1894 for (i = 0; i < psInfo->nPages; i++)
1896 /* set the specified page as clean */
1897 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1898 psInfo->proppage[i].isDirty = FALSE;
1900 /* look to see if there's any dirty pages */
1901 if (psInfo->proppage[i].isDirty)
1902 noPageDirty = FALSE;
1906 * Disable Apply button.
1908 if (noPageDirty)
1909 EnableWindow(hwndApplyBtn, FALSE);
1912 /******************************************************************************
1913 * PROPSHEET_PressButton
1915 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1917 TRACE("buttonID %d\n", buttonID);
1918 switch (buttonID)
1920 case PSBTN_APPLYNOW:
1921 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1922 break;
1923 case PSBTN_BACK:
1924 PROPSHEET_Back(hwndDlg);
1925 break;
1926 case PSBTN_CANCEL:
1927 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1928 break;
1929 case PSBTN_FINISH:
1930 PROPSHEET_Finish(hwndDlg);
1931 break;
1932 case PSBTN_HELP:
1933 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1934 break;
1935 case PSBTN_NEXT:
1936 PROPSHEET_Next(hwndDlg);
1937 break;
1938 case PSBTN_OK:
1939 PROPSHEET_DoCommand(hwndDlg, IDOK);
1940 break;
1941 default:
1942 FIXME("Invalid button index %d\n", buttonID);
1947 /*************************************************************************
1948 * BOOL PROPSHEET_CanSetCurSel [Internal]
1950 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1952 * PARAMS
1953 * hwndDlg [I] handle to a Dialog hWnd
1955 * RETURNS
1956 * TRUE if Current Selection can change
1958 * NOTES
1960 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1962 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1963 PropSheetInfoStr);
1964 HWND hwndPage;
1965 PSHNOTIFY psn;
1966 BOOL res = FALSE;
1968 TRACE("active_page %d\n", psInfo->active_page);
1969 if (!psInfo)
1971 res = FALSE;
1972 goto end;
1975 if (psInfo->active_page < 0)
1977 res = TRUE;
1978 goto end;
1982 * Notify the current page.
1984 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1985 psn.hdr.code = PSN_KILLACTIVE;
1986 psn.hdr.hwndFrom = hwndDlg;
1987 psn.hdr.idFrom = 0;
1988 psn.lParam = 0;
1990 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1992 end:
1993 TRACE("<-- %d\n", res);
1994 return res;
1997 /******************************************************************************
1998 * PROPSHEET_SetCurSel
2000 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2001 int index,
2002 int skipdir,
2003 HPROPSHEETPAGE hpage
2006 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2007 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2008 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2010 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2011 /* hpage takes precedence over index */
2012 if (hpage != NULL)
2013 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2015 if (index < 0 || index >= psInfo->nPages)
2017 TRACE("Could not find page to select!\n");
2018 return FALSE;
2021 while (1) {
2022 int result;
2023 PSHNOTIFY psn;
2024 RECT rc;
2025 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2027 if (hwndTabControl)
2028 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2030 psn.hdr.code = PSN_SETACTIVE;
2031 psn.hdr.hwndFrom = hwndDlg;
2032 psn.hdr.idFrom = 0;
2033 psn.lParam = 0;
2035 if (!psInfo->proppage[index].hwndPage) {
2036 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2039 /* Resize the property sheet page to the fit in the Tab control
2040 * (for regular property sheets) or to fit in the client area (for
2041 * wizards).
2042 * NOTE: The resizing happens every time the page is selected and
2043 * not only when it's created (some applications depend on it). */
2044 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2045 TRACE("setting page %p, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
2046 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2047 rc.right - rc.left, rc.bottom - rc.top);
2048 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2049 rc.left, rc.top,
2050 rc.right - rc.left, rc.bottom - rc.top, 0);
2052 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2053 if (!result)
2054 break;
2055 if (result == -1) {
2056 index+=skipdir;
2057 if (index < 0) {
2058 index = 0;
2059 WARN("Tried to skip before first property sheet page!\n");
2060 break;
2062 if (index >= psInfo->nPages) {
2063 WARN("Tried to skip after last property sheet page!\n");
2064 index = psInfo->nPages-1;
2065 break;
2068 else if (result != 0)
2070 int old_index = index;
2071 index = PROPSHEET_FindPageByResId(psInfo, result);
2072 if(index >= psInfo->nPages) {
2073 index = old_index;
2074 WARN("Tried to skip to nonexistant page by res id\n");
2075 break;
2077 continue;
2081 /* Invalidate the header area */
2082 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2083 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2085 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2086 RECT r;
2088 GetClientRect(hwndLineHeader, &r);
2089 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2090 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2092 InvalidateRect(hwndDlg, &r, TRUE);
2096 * Display the new page.
2098 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2100 if (psInfo->proppage[index].hasHelp)
2101 EnableWindow(hwndHelp, TRUE);
2102 else
2103 EnableWindow(hwndHelp, FALSE);
2105 return TRUE;
2108 /******************************************************************************
2109 * PROPSHEET_SetCurSelId
2111 * Selects the page, specified by resource id.
2113 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2115 int idx;
2116 PropSheetInfo* psInfo =
2117 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2119 idx = PROPSHEET_FindPageByResId(psInfo, id);
2120 if (idx < psInfo->nPages )
2122 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2123 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2127 /******************************************************************************
2128 * PROPSHEET_SetTitleA
2130 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2132 if(HIWORD(lpszText))
2134 WCHAR szTitle[256];
2135 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2136 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2137 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2139 else
2141 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2145 /******************************************************************************
2146 * PROPSHEET_SetTitleW
2148 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2150 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2151 WCHAR szTitle[256];
2153 TRACE("'%s' (style %08x)\n", debugstr_w(lpszText), dwStyle);
2154 if (HIWORD(lpszText) == 0) {
2155 if (!LoadStringW(psInfo->ppshheader.hInstance,
2156 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2157 return;
2158 lpszText = szTitle;
2160 if (dwStyle & PSH_PROPTITLE)
2162 WCHAR* dest;
2163 int lentitle = strlenW(lpszText);
2164 int lenprop = strlenW(psInfo->strPropertiesFor);
2166 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2167 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2169 SetWindowTextW(hwndDlg, dest);
2170 Free(dest);
2172 else
2173 SetWindowTextW(hwndDlg, lpszText);
2176 /******************************************************************************
2177 * PROPSHEET_SetFinishTextA
2179 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2181 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2182 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2184 TRACE("'%s'\n", lpszText);
2185 /* Set text, show and enable the Finish button */
2186 SetWindowTextA(hwndButton, lpszText);
2187 ShowWindow(hwndButton, SW_SHOW);
2188 EnableWindow(hwndButton, TRUE);
2190 /* Make it default pushbutton */
2191 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2193 /* Hide Back button */
2194 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2195 ShowWindow(hwndButton, SW_HIDE);
2197 if (!psInfo->hasFinish)
2199 /* Hide Next button */
2200 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2201 ShowWindow(hwndButton, SW_HIDE);
2205 /******************************************************************************
2206 * PROPSHEET_SetFinishTextW
2208 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2210 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2211 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2213 TRACE("'%s'\n", debugstr_w(lpszText));
2214 /* Set text, show and enable the Finish button */
2215 SetWindowTextW(hwndButton, lpszText);
2216 ShowWindow(hwndButton, SW_SHOW);
2217 EnableWindow(hwndButton, TRUE);
2219 /* Make it default pushbutton */
2220 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2222 /* Hide Back button */
2223 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2224 ShowWindow(hwndButton, SW_HIDE);
2226 if (!psInfo->hasFinish)
2228 /* Hide Next button */
2229 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2230 ShowWindow(hwndButton, SW_HIDE);
2234 /******************************************************************************
2235 * PROPSHEET_QuerySiblings
2237 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2238 WPARAM wParam, LPARAM lParam)
2240 int i = 0;
2241 HWND hwndPage;
2242 LRESULT msgResult = 0;
2243 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2245 while ((i < psInfo->nPages) && (msgResult == 0))
2247 hwndPage = psInfo->proppage[i].hwndPage;
2248 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2249 i++;
2252 return msgResult;
2256 /******************************************************************************
2257 * PROPSHEET_AddPage
2259 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2260 HPROPSHEETPAGE hpage)
2262 PropPageInfo * ppi;
2263 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2264 PropSheetInfoStr);
2265 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2266 TCITEMW item;
2267 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2269 TRACE("hpage %p\n", hpage);
2271 * Allocate and fill in a new PropPageInfo entry.
2273 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2274 sizeof(PropPageInfo) *
2275 (psInfo->nPages + 1));
2276 if (!ppi)
2277 return FALSE;
2279 psInfo->proppage = ppi;
2280 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2281 return FALSE;
2283 psInfo->proppage[psInfo->nPages].hpage = hpage;
2285 if (ppsp->dwFlags & PSP_PREMATURE)
2287 /* Create the page but don't show it */
2288 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2292 * Add a new tab to the tab control.
2294 item.mask = TCIF_TEXT;
2295 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2296 item.cchTextMax = MAX_TABTEXT_LENGTH;
2298 if (psInfo->hImageList)
2300 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2303 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2305 item.mask |= TCIF_IMAGE;
2306 item.iImage = psInfo->nPages;
2309 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2310 (LPARAM)&item);
2312 psInfo->nPages++;
2314 /* If it is the only page - show it */
2315 if(psInfo->nPages == 1)
2316 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2317 return TRUE;
2320 /******************************************************************************
2321 * PROPSHEET_RemovePage
2323 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2324 int index,
2325 HPROPSHEETPAGE hpage)
2327 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2328 PropSheetInfoStr);
2329 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2330 PropPageInfo* oldPages;
2332 TRACE("index %d, hpage %p\n", index, hpage);
2333 if (!psInfo) {
2334 return FALSE;
2337 * hpage takes precedence over index.
2339 if (hpage != 0)
2341 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2344 /* Make sure that index is within range */
2345 if (index < 0 || index >= psInfo->nPages)
2347 TRACE("Could not find page to remove!\n");
2348 return FALSE;
2351 TRACE("total pages %d removing page %d active page %d\n",
2352 psInfo->nPages, index, psInfo->active_page);
2354 * Check if we're removing the active page.
2356 if (index == psInfo->active_page)
2358 if (psInfo->nPages > 1)
2360 if (index > 0)
2362 /* activate previous page */
2363 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2365 else
2367 /* activate the next page */
2368 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2369 psInfo->active_page = index;
2372 else
2374 psInfo->active_page = -1;
2375 if (!psInfo->isModeless)
2377 psInfo->ended = TRUE;
2378 return TRUE;
2382 else if (index < psInfo->active_page)
2383 psInfo->active_page--;
2385 /* Unsubclass the page dialog window */
2386 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2387 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2388 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2390 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2391 PROPSHEET_WizardSubclassProc, 1);
2394 /* Destroy page dialog window */
2395 DestroyWindow(psInfo->proppage[index].hwndPage);
2397 /* Free page resources */
2398 if(psInfo->proppage[index].hpage)
2400 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2402 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2403 Free ((LPVOID)psInfo->proppage[index].pszText);
2405 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2408 /* Remove the tab */
2409 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2411 oldPages = psInfo->proppage;
2412 psInfo->nPages--;
2413 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2415 if (index > 0)
2416 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2418 if (index < psInfo->nPages)
2419 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2420 (psInfo->nPages - index) * sizeof(PropPageInfo));
2422 Free(oldPages);
2424 return FALSE;
2427 /******************************************************************************
2428 * PROPSHEET_SetWizButtons
2430 * This code will work if (and assumes that) the Next button is on top of the
2431 * Finish button. ie. Finish comes after Next in the Z order.
2432 * This means make sure the dialog template reflects this.
2435 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2437 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2438 PropSheetInfoStr);
2439 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2440 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2441 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2443 TRACE("%d\n", dwFlags);
2445 EnableWindow(hwndBack, FALSE);
2446 EnableWindow(hwndNext, FALSE);
2447 EnableWindow(hwndFinish, FALSE);
2449 /* set the default pushbutton to an enabled button */
2450 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2451 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2452 else if (dwFlags & PSWIZB_NEXT)
2453 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2454 else if (dwFlags & PSWIZB_BACK)
2455 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2456 else
2457 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2460 if (dwFlags & PSWIZB_BACK)
2461 EnableWindow(hwndBack, TRUE);
2463 if (dwFlags & PSWIZB_NEXT)
2464 EnableWindow(hwndNext, TRUE);
2466 if (!psInfo->hasFinish)
2468 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2470 /* Hide the Next button */
2471 ShowWindow(hwndNext, SW_HIDE);
2473 /* Show the Finish button */
2474 ShowWindow(hwndFinish, SW_SHOW);
2476 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2477 EnableWindow(hwndFinish, TRUE);
2479 else
2481 /* Hide the Finish button */
2482 ShowWindow(hwndFinish, SW_HIDE);
2483 /* Show the Next button */
2484 ShowWindow(hwndNext, SW_SHOW);
2487 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2488 EnableWindow(hwndFinish, TRUE);
2491 /******************************************************************************
2492 * PROPSHEET_InsertPage
2494 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2496 if (!HIWORD(hpageInsertAfter))
2497 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2498 else
2499 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2500 return FALSE;
2503 /******************************************************************************
2504 * PROPSHEET_SetHeaderTitleW
2506 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2508 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2511 /******************************************************************************
2512 * PROPSHEET_SetHeaderTitleA
2514 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2516 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2519 /******************************************************************************
2520 * PROPSHEET_SetHeaderSubTitleW
2522 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2524 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2527 /******************************************************************************
2528 * PROPSHEET_SetHeaderSubTitleA
2530 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2532 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2535 /******************************************************************************
2536 * PROPSHEET_HwndToIndex
2538 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2540 int index;
2541 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2542 PropSheetInfoStr);
2544 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
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;
2553 /******************************************************************************
2554 * PROPSHEET_IndexToHwnd
2556 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2558 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2559 PropSheetInfoStr);
2560 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2561 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2562 WARN("%d out of range.\n", iPageIndex);
2563 return 0;
2565 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2568 /******************************************************************************
2569 * PROPSHEET_PageToIndex
2571 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2573 int index;
2574 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2575 PropSheetInfoStr);
2577 TRACE("(%p, %p)\n", hwndDlg, hPage);
2579 for (index = 0; index < psInfo->nPages; index++)
2580 if (psInfo->proppage[index].hpage == hPage)
2581 return index;
2582 WARN("%p not found\n", hPage);
2583 return -1;
2586 /******************************************************************************
2587 * PROPSHEET_IndexToPage
2589 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2591 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2592 PropSheetInfoStr);
2593 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2594 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2595 WARN("%d out of range.\n", iPageIndex);
2596 return 0;
2598 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2601 /******************************************************************************
2602 * PROPSHEET_IdToIndex
2604 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2606 int index;
2607 LPCPROPSHEETPAGEW psp;
2608 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2609 PropSheetInfoStr);
2610 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2611 for (index = 0; index < psInfo->nPages; index++) {
2612 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2613 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2614 return index;
2617 return -1;
2620 /******************************************************************************
2621 * PROPSHEET_IndexToId
2623 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2625 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2626 PropSheetInfoStr);
2627 LPCPROPSHEETPAGEW psp;
2628 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2629 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2630 WARN("%d out of range.\n", iPageIndex);
2631 return 0;
2633 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2634 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2635 return 0;
2637 return (LRESULT)psp->u.pszTemplate;
2640 /******************************************************************************
2641 * PROPSHEET_GetResult
2643 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2645 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2646 PropSheetInfoStr);
2647 return psInfo->result;
2650 /******************************************************************************
2651 * PROPSHEET_RecalcPageSizes
2653 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2655 FIXME("(%p): stub\n", hwndDlg);
2656 return FALSE;
2659 /******************************************************************************
2660 * PROPSHEET_GetPageIndex
2662 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2663 * the array of PropPageInfo.
2665 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2667 BOOL found = FALSE;
2668 int index = 0;
2670 TRACE("hpage %p\n", hpage);
2671 while ((index < psInfo->nPages) && (found == FALSE))
2673 if (psInfo->proppage[index].hpage == hpage)
2674 found = TRUE;
2675 else
2676 index++;
2679 if (found == FALSE)
2680 index = -1;
2682 return index;
2685 /******************************************************************************
2686 * PROPSHEET_CleanUp
2688 static void PROPSHEET_CleanUp(HWND hwndDlg)
2690 int i;
2691 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2692 PropSheetInfoStr);
2694 TRACE("\n");
2695 if (!psInfo) return;
2696 if (HIWORD(psInfo->ppshheader.pszCaption))
2697 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2699 for (i = 0; i < psInfo->nPages; i++)
2701 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2703 /* Unsubclass the page dialog window */
2704 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2705 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2706 (psp->dwFlags & PSP_HIDEHEADER))
2708 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2709 PROPSHEET_WizardSubclassProc, 1);
2712 if(psInfo->proppage[i].hwndPage)
2713 DestroyWindow(psInfo->proppage[i].hwndPage);
2715 if(psp)
2717 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2718 Free ((LPVOID)psInfo->proppage[i].pszText);
2720 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2724 DeleteObject(psInfo->hFont);
2725 DeleteObject(psInfo->hFontBold);
2726 /* If we created the bitmaps, destroy them */
2727 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2728 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2729 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2730 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2731 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2732 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2734 Free(psInfo->proppage);
2735 Free(psInfo->strPropertiesFor);
2736 ImageList_Destroy(psInfo->hImageList);
2738 GlobalFree((HGLOBAL)psInfo);
2741 static INT do_loop(PropSheetInfo *psInfo)
2743 MSG msg;
2744 INT ret = -1;
2745 HWND hwnd = psInfo->hwnd;
2747 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2749 if(ret == -1)
2750 break;
2752 if(!IsDialogMessageW(hwnd, &msg))
2754 TranslateMessage(&msg);
2755 DispatchMessageW(&msg);
2759 if(ret == 0)
2761 PostQuitMessage(msg.wParam);
2762 ret = -1;
2765 if(ret != -1)
2766 ret = psInfo->result;
2768 DestroyWindow(hwnd);
2769 return ret;
2772 /******************************************************************************
2773 * PropertySheet (COMCTL32.@)
2774 * PropertySheetA (COMCTL32.@)
2776 * Creates a property sheet in the specified property sheet header.
2778 * RETURNS
2779 * Modal property sheets: Positive if successful or -1 otherwise.
2780 * Modeless property sheets: Property sheet handle.
2781 * Or:
2782 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2783 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2785 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2787 INT_PTR bRet = 0;
2788 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2789 sizeof(PropSheetInfo));
2790 UINT i, n;
2791 BYTE* pByte;
2793 TRACE("(%p)\n", lppsh);
2795 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2797 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2798 lppsh->nPages);
2799 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2801 for (n = i = 0; i < lppsh->nPages; i++, n++)
2803 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2804 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2805 else
2807 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2808 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2811 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2812 psInfo, n))
2814 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2815 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2816 n--;
2817 psInfo->nPages--;
2821 psInfo->unicode = FALSE;
2822 psInfo->ended = FALSE;
2824 bRet = PROPSHEET_CreateDialog(psInfo);
2825 if(!psInfo->isModeless)
2826 bRet = do_loop(psInfo);
2828 return bRet;
2831 /******************************************************************************
2832 * PropertySheetW (COMCTL32.@)
2834 * See PropertySheetA.
2836 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2838 INT_PTR bRet = 0;
2839 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2840 sizeof(PropSheetInfo));
2841 UINT i, n;
2842 BYTE* pByte;
2844 TRACE("(%p)\n", lppsh);
2846 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2848 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2849 lppsh->nPages);
2850 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2852 for (n = i = 0; i < lppsh->nPages; i++, n++)
2854 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2855 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2856 else
2858 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2859 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2862 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2863 psInfo, n))
2865 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2866 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2867 n--;
2868 psInfo->nPages--;
2872 psInfo->unicode = TRUE;
2873 psInfo->ended = FALSE;
2875 bRet = PROPSHEET_CreateDialog(psInfo);
2876 if(!psInfo->isModeless)
2877 bRet = do_loop(psInfo);
2879 return bRet;
2882 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2884 LPWSTR ret;
2885 UINT len;
2887 if (IS_INTRESOURCE(str))
2889 HRSRC hrsrc;
2890 HGLOBAL hmem;
2891 WCHAR *ptr;
2892 WORD i, id = LOWORD(str);
2894 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2895 return NULL;
2896 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2897 if (!(ptr = LockResource( hmem ))) return NULL;
2898 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2899 len = *ptr;
2900 if (!len) return NULL;
2901 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2902 if (ret)
2904 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2905 ret[len] = 0;
2908 else
2910 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2911 ret = Alloc( len );
2912 if (ret) memcpy( ret, str, len );
2914 return ret;
2918 /******************************************************************************
2919 * CreatePropertySheetPage (COMCTL32.@)
2920 * CreatePropertySheetPageA (COMCTL32.@)
2922 * Creates a new property sheet page.
2924 * RETURNS
2925 * Success: Handle to new property sheet page.
2926 * Failure: NULL.
2928 * NOTES
2929 * An application must use the PSM_ADDPAGE message to add the new page to
2930 * an existing property sheet.
2932 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2933 LPCPROPSHEETPAGEA lpPropSheetPage)
2935 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2937 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2939 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2941 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2943 if (HIWORD( ppsp->u.pszTemplate ))
2945 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2946 ppsp->u.pszTemplate = Alloc( len );
2947 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2951 if (ppsp->dwFlags & PSP_USEICONID)
2953 if (HIWORD( ppsp->u2.pszIcon ))
2954 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2957 if (ppsp->dwFlags & PSP_USETITLE)
2959 if (HIWORD( ppsp->pszTitle ))
2960 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2961 else
2962 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2964 else
2965 ppsp->pszTitle = NULL;
2967 if (ppsp->dwFlags & PSP_HIDEHEADER)
2968 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2970 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2972 if (HIWORD( ppsp->pszHeaderTitle ))
2973 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2974 else
2975 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2977 else
2978 ppsp->pszHeaderTitle = NULL;
2980 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2982 if (HIWORD( ppsp->pszHeaderSubTitle ))
2983 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2984 else
2985 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2987 else
2988 ppsp->pszHeaderSubTitle = NULL;
2990 return (HPROPSHEETPAGE)ppsp;
2993 /******************************************************************************
2994 * CreatePropertySheetPageW (COMCTL32.@)
2996 * See CreatePropertySheetA.
2998 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3000 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3002 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3004 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3006 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3008 if (HIWORD( ppsp->u.pszTemplate ))
3010 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3011 ppsp->u.pszTemplate = Alloc( len * sizeof (WCHAR) );
3012 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
3016 if ( ppsp->dwFlags & PSP_USEICONID )
3018 if (HIWORD( ppsp->u2.pszIcon ))
3020 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3021 ppsp->u2.pszIcon = Alloc( len * sizeof (WCHAR) );
3022 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
3026 if (ppsp->dwFlags & PSP_USETITLE)
3027 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3028 else
3029 ppsp->pszTitle = NULL;
3031 if (ppsp->dwFlags & PSP_HIDEHEADER)
3032 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3034 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3035 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3036 else
3037 ppsp->pszHeaderTitle = NULL;
3039 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3040 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3041 else
3042 ppsp->pszHeaderSubTitle = NULL;
3044 return (HPROPSHEETPAGE)ppsp;
3047 /******************************************************************************
3048 * DestroyPropertySheetPage (COMCTL32.@)
3050 * Destroys a property sheet page previously created with
3051 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3052 * memory.
3054 * RETURNS
3055 * Success: TRUE
3056 * Failure: FALSE
3058 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3060 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3062 if (!psp)
3063 return FALSE;
3065 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3066 Free ((LPVOID)psp->u.pszTemplate);
3068 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3069 Free ((LPVOID)psp->u2.pszIcon);
3071 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3072 Free ((LPVOID)psp->pszTitle);
3074 Free(hPropPage);
3076 return TRUE;
3079 /******************************************************************************
3080 * PROPSHEET_IsDialogMessage
3082 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3084 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3086 TRACE("\n");
3087 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3088 return FALSE;
3090 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3092 int new_page = 0;
3093 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3095 if (!(dlgCode & DLGC_WANTMESSAGE))
3097 switch (lpMsg->wParam)
3099 case VK_TAB:
3100 if (GetKeyState(VK_SHIFT) & 0x8000)
3101 new_page = -1;
3102 else
3103 new_page = 1;
3104 break;
3106 case VK_NEXT: new_page = 1; break;
3107 case VK_PRIOR: new_page = -1; break;
3111 if (new_page)
3113 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3115 new_page += psInfo->active_page;
3117 if (new_page < 0)
3118 new_page = psInfo->nPages - 1;
3119 else if (new_page >= psInfo->nPages)
3120 new_page = 0;
3122 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3125 return TRUE;
3129 return IsDialogMessageW(hwnd, lpMsg);
3132 /******************************************************************************
3133 * PROPSHEET_DoCommand
3135 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3138 switch (wID) {
3140 case IDOK:
3141 case IDC_APPLY_BUTTON:
3143 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3145 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3146 break;
3148 if (wID == IDOK)
3150 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3151 PropSheetInfoStr);
3153 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3154 if (psInfo->result == 0)
3155 psInfo->result = IDOK;
3157 if (psInfo->isModeless)
3158 psInfo->activeValid = FALSE;
3159 else
3160 psInfo->ended = TRUE;
3162 else
3163 EnableWindow(hwndApplyBtn, FALSE);
3165 break;
3168 case IDC_BACK_BUTTON:
3169 PROPSHEET_Back(hwnd);
3170 break;
3172 case IDC_NEXT_BUTTON:
3173 PROPSHEET_Next(hwnd);
3174 break;
3176 case IDC_FINISH_BUTTON:
3177 PROPSHEET_Finish(hwnd);
3178 break;
3180 case IDCANCEL:
3181 PROPSHEET_Cancel(hwnd, 0);
3182 break;
3184 case IDHELP:
3185 PROPSHEET_Help(hwnd);
3186 break;
3188 default:
3189 return FALSE;
3192 return TRUE;
3195 /******************************************************************************
3196 * PROPSHEET_Paint
3198 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3200 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3201 PAINTSTRUCT ps;
3202 HDC hdc, hdcSrc;
3203 BITMAP bm;
3204 HBITMAP hbmp;
3205 HPALETTE hOldPal = 0;
3206 int offsety = 0;
3207 HBRUSH hbr;
3208 RECT r, rzone;
3209 LPCPROPSHEETPAGEW ppshpage;
3210 WCHAR szBuffer[256];
3211 int nLength;
3213 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3214 if (!hdc) return 1;
3216 hdcSrc = CreateCompatibleDC(0);
3217 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3219 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3220 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3222 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3223 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3224 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3226 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3227 HFONT hOldFont;
3228 COLORREF clrOld = 0;
3229 int oldBkMode = 0;
3231 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3232 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3234 GetClientRect(hwndLineHeader, &r);
3235 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3236 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3238 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3240 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3242 /* Fill the unoccupied part of the header with color of the
3243 * left-top pixel, but do it only when needed.
3245 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3247 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3248 CopyRect(&r, &rzone);
3249 if (bm.bmWidth < r.right)
3251 r.left = bm.bmWidth;
3252 FillRect(hdc, &r, hbr);
3254 if (bm.bmHeight < r.bottom)
3256 r.left = 0;
3257 r.top = bm.bmHeight;
3258 FillRect(hdc, &r, hbr);
3260 DeleteObject(hbr);
3263 /* Draw the header itself. */
3264 BitBlt(hdc, 0, 0,
3265 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3266 hdcSrc, 0, 0, SRCCOPY);
3268 else
3270 int margin;
3271 hbr = GetSysColorBrush(COLOR_WINDOW);
3272 FillRect(hdc, &rzone, hbr);
3274 /* Draw the header bitmap. It's always centered like a
3275 * common 49 x 49 bitmap. */
3276 margin = (rzone.bottom - 49) / 2;
3277 BitBlt(hdc, rzone.right - 49 - margin, margin,
3278 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3279 hdcSrc, 0, 0, SRCCOPY);
3281 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3282 * if its height is smaller than 49 pixels. Because the reason
3283 * for this bug is unknown the current code doesn't try to
3284 * replicate it. */
3287 clrOld = SetTextColor (hdc, 0x00000000);
3288 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3290 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3291 SetRect(&r, 20, 10, 0, 0);
3292 if (HIWORD(ppshpage->pszHeaderTitle))
3293 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3294 else
3296 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3297 szBuffer, 256);
3298 if (nLength != 0)
3300 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3305 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3306 SelectObject(hdc, psInfo->hFont);
3307 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3308 if (HIWORD(ppshpage->pszHeaderTitle))
3309 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3310 else
3312 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3313 szBuffer, 256);
3314 if (nLength != 0)
3316 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3321 offsety = rzone.bottom + 2;
3323 SetTextColor(hdc, clrOld);
3324 SetBkMode(hdc, oldBkMode);
3325 SelectObject(hdc, hOldFont);
3326 SelectObject(hdcSrc, hbmp);
3329 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3330 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3331 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3333 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3335 GetClientRect(hwndLine, &r);
3336 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3338 rzone.left = 0;
3339 rzone.top = 0;
3340 rzone.right = r.right;
3341 rzone.bottom = r.top - 1;
3343 hbr = GetSysColorBrush(COLOR_WINDOW);
3344 FillRect(hdc, &rzone, hbr);
3346 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3347 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3349 /* The watermark is truncated to a width of 164 pixels */
3350 r.right = min(r.right, 164);
3351 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3352 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3354 /* If the bitmap is not big enough, fill the remaining area
3355 with the color of pixel (0,0) of bitmap - see MSDN */
3356 if (r.top > bm.bmHeight) {
3357 r.bottom = r.top - 1;
3358 r.top = bm.bmHeight;
3359 r.left = 0;
3360 r.right = bm.bmWidth;
3361 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3362 FillRect(hdc, &r, hbr);
3363 DeleteObject(hbr);
3366 SelectObject(hdcSrc, hbmp);
3369 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3370 SelectPalette(hdc, hOldPal, FALSE);
3372 DeleteDC(hdcSrc);
3374 if (!hdcParam) EndPaint(hwnd, &ps);
3376 return 0;
3379 /******************************************************************************
3380 * PROPSHEET_DialogProc
3382 static INT_PTR CALLBACK
3383 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3385 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3386 hwnd, uMsg, wParam, lParam);
3388 switch (uMsg)
3390 case WM_INITDIALOG:
3392 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3393 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3394 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3395 LPCPROPSHEETPAGEW ppshpage;
3396 int idx;
3397 LOGFONTW logFont;
3399 /* Using PropSheetInfoStr to store extra data doesn't match the native
3400 * common control: native uses TCM_[GS]ETITEM
3402 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3405 * psInfo->hwnd is not being used by WINE code - it exists
3406 * for compatibility with "real" Windoze. The same about
3407 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3408 * property.
3410 psInfo->hwnd = hwnd;
3411 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3413 /* set up the Next and Back buttons by default */
3414 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3416 /* Set up fonts */
3417 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3418 psInfo->hFont = CreateFontIndirectW (&logFont);
3419 logFont.lfWeight = FW_BOLD;
3420 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3423 * Small icon in the title bar.
3425 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3426 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3428 HICON hIcon;
3429 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3430 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3432 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3433 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3434 psInfo->ppshheader.u.pszIcon,
3435 IMAGE_ICON,
3436 icon_cx, icon_cy,
3437 LR_DEFAULTCOLOR);
3438 else
3439 hIcon = psInfo->ppshheader.u.hIcon;
3441 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3444 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3445 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3447 psInfo->strPropertiesFor = strCaption;
3449 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3451 PROPSHEET_CreateTabControl(hwnd, psInfo);
3453 PROPSHEET_LoadWizardBitmaps(psInfo);
3455 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3457 ShowWindow(hwndTabCtrl, SW_HIDE);
3458 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3459 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3461 else
3463 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3465 PROPSHEET_AdjustSize(hwnd, psInfo);
3466 PROPSHEET_AdjustButtons(hwnd, psInfo);
3470 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3471 psInfo->ppshheader.hInstance)
3473 WCHAR szText[256];
3475 if (LoadStringW(psInfo->ppshheader.hInstance,
3476 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3477 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3479 else
3481 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3482 psInfo->ppshheader.pszCaption);
3486 if (psInfo->useCallback)
3487 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3488 PSCB_INITIALIZED, (LPARAM)0);
3490 idx = psInfo->active_page;
3491 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3492 psInfo->active_page = -1;
3494 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3496 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3497 * as some programs call TCM_GETCURSEL to get the current selection
3498 * from which to switch to the next page */
3499 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3501 return TRUE;
3504 case WM_PRINTCLIENT:
3505 case WM_PAINT:
3506 PROPSHEET_Paint(hwnd, (HDC)wParam);
3507 return TRUE;
3509 case WM_DESTROY:
3510 PROPSHEET_CleanUp(hwnd);
3511 return TRUE;
3513 case WM_CLOSE:
3514 PROPSHEET_Cancel(hwnd, 1);
3515 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3517 case WM_COMMAND:
3518 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3520 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3522 if (!psInfo)
3523 return FALSE;
3525 /* No default handler, forward notification to active page */
3526 if (psInfo->activeValid && psInfo->active_page != -1)
3528 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3529 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3532 return TRUE;
3534 case WM_NOTIFY:
3536 NMHDR* pnmh = (LPNMHDR) lParam;
3538 if (pnmh->code == TCN_SELCHANGE)
3540 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3541 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3544 if(pnmh->code == TCN_SELCHANGING)
3546 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3547 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3548 return TRUE;
3551 return FALSE;
3554 case WM_SYSCOLORCHANGE:
3555 COMCTL32_RefreshSysColors();
3556 return FALSE;
3558 case PSM_GETCURRENTPAGEHWND:
3560 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3561 PropSheetInfoStr);
3562 HWND hwndPage = 0;
3564 if (!psInfo)
3565 return FALSE;
3567 if (psInfo->activeValid && psInfo->active_page != -1)
3568 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3570 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3572 return TRUE;
3575 case PSM_CHANGED:
3576 PROPSHEET_Changed(hwnd, (HWND)wParam);
3577 return TRUE;
3579 case PSM_UNCHANGED:
3580 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3581 return TRUE;
3583 case PSM_GETTABCONTROL:
3585 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3587 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3589 return TRUE;
3592 case PSM_SETCURSEL:
3594 BOOL msgResult;
3596 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3597 if(msgResult != FALSE)
3599 msgResult = PROPSHEET_SetCurSel(hwnd,
3600 (int)wParam,
3602 (HPROPSHEETPAGE)lParam);
3605 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3607 return TRUE;
3610 case PSM_CANCELTOCLOSE:
3612 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3613 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3614 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3616 EnableWindow(hwndCancel, FALSE);
3617 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3618 SetWindowTextW(hwndOK, buf);
3620 return FALSE;
3623 case PSM_RESTARTWINDOWS:
3625 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3626 PropSheetInfoStr);
3628 if (!psInfo)
3629 return FALSE;
3631 /* reboot system takes precedence over restart windows */
3632 if (psInfo->result != ID_PSREBOOTSYSTEM)
3633 psInfo->result = ID_PSRESTARTWINDOWS;
3635 return TRUE;
3638 case PSM_REBOOTSYSTEM:
3640 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3641 PropSheetInfoStr);
3643 if (!psInfo)
3644 return FALSE;
3646 psInfo->result = ID_PSREBOOTSYSTEM;
3648 return TRUE;
3651 case PSM_SETTITLEA:
3652 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3653 return TRUE;
3655 case PSM_SETTITLEW:
3656 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3657 return TRUE;
3659 case PSM_APPLY:
3661 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3663 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3665 return TRUE;
3668 case PSM_QUERYSIBLINGS:
3670 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3672 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3674 return TRUE;
3677 case PSM_ADDPAGE:
3680 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3681 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3682 * on success or FALSE otherwise, as specified on MSDN Online.
3683 * Also see the MFC code for
3684 * CPropertySheet::AddPage(CPropertyPage* pPage).
3687 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3689 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3691 return TRUE;
3694 case PSM_REMOVEPAGE:
3695 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3696 return TRUE;
3698 case PSM_ISDIALOGMESSAGE:
3700 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3701 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3702 return TRUE;
3705 case PSM_PRESSBUTTON:
3706 PROPSHEET_PressButton(hwnd, (int)wParam);
3707 return TRUE;
3709 case PSM_SETFINISHTEXTA:
3710 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3711 return TRUE;
3713 case PSM_SETWIZBUTTONS:
3714 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3715 return TRUE;
3717 case PSM_SETCURSELID:
3718 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3719 return TRUE;
3721 case PSM_SETFINISHTEXTW:
3722 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3723 return FALSE;
3725 case PSM_INSERTPAGE:
3727 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3728 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3729 return TRUE;
3732 case PSM_SETHEADERTITLEW:
3733 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3734 return TRUE;
3736 case PSM_SETHEADERTITLEA:
3737 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3738 return TRUE;
3740 case PSM_SETHEADERSUBTITLEW:
3741 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3742 return TRUE;
3744 case PSM_SETHEADERSUBTITLEA:
3745 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3746 return TRUE;
3748 case PSM_HWNDTOINDEX:
3750 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3751 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3752 return TRUE;
3755 case PSM_INDEXTOHWND:
3757 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3758 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3759 return TRUE;
3762 case PSM_PAGETOINDEX:
3764 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3765 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3766 return TRUE;
3769 case PSM_INDEXTOPAGE:
3771 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3772 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3773 return TRUE;
3776 case PSM_IDTOINDEX:
3778 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3779 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3780 return TRUE;
3783 case PSM_INDEXTOID:
3785 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3786 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3787 return TRUE;
3790 case PSM_GETRESULT:
3792 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3793 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3794 return TRUE;
3797 case PSM_RECALCPAGESIZES:
3799 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3800 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3801 return TRUE;
3804 default:
3805 return FALSE;