Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / comctl32 / propsheet.c
blob7f46becfecac4f90fb60033ca3c6da83593ed5a5
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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_GETRESULT
36 * o PSM_IDTOINDEX
37 * o PSM_INSERTPAGE
38 * o PSM_RECALCPAGESIZES
39 * o PSM_SETHEADERSUBTITLE
40 * o PSM_SETHEADERTITLE
41 * o WM_HELP
42 * o WM_CONTEXTMENU
43 * - Notifications:
44 * o PSN_GETOBJECT
45 * o PSN_QUERYINITIALFOCUS
46 * o PSN_TRANSLATEACCELERATOR
47 * - Styles:
48 * o PSH_WIZARDHASFINISH
49 * o PSH_RTLREADING
50 * o PSH_STRETCHWATERMARK
51 * o PSH_USEPAGELANG
52 * o PSH_USEPSTARTPAGE
53 * - Page styles:
54 * o PSP_USEFUSIONCONTEXT
55 * o PSP_USEREFPARENT
58 #include <stdarg.h>
59 #include <string.h>
61 #define NONAMELESSUNION
62 #define NONAMELESSSTRUCT
63 #include "windef.h"
64 #include "winbase.h"
65 #include "wingdi.h"
66 #include "winuser.h"
67 #include "winnls.h"
68 #include "commctrl.h"
69 #include "prsht.h"
70 #include "comctl32.h"
72 #include "wine/debug.h"
73 #include "wine/unicode.h"
75 /******************************************************************************
76 * Data structures
78 #include "pshpack2.h"
80 typedef struct
82 WORD dlgVer;
83 WORD signature;
84 DWORD helpID;
85 DWORD exStyle;
86 DWORD style;
87 } MyDLGTEMPLATEEX;
89 typedef struct
91 DWORD helpid;
92 DWORD exStyle;
93 DWORD style;
94 short x;
95 short y;
96 short cx;
97 short cy;
98 DWORD id;
99 } MyDLGITEMTEMPLATEEX;
100 #include "poppack.h"
102 typedef struct tagPropPageInfo
104 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
105 HWND hwndPage;
106 BOOL isDirty;
107 LPCWSTR pszText;
108 BOOL hasHelp;
109 BOOL useCallback;
110 BOOL hasIcon;
111 } PropPageInfo;
113 typedef struct tagPropSheetInfo
115 HWND hwnd;
116 PROPSHEETHEADERW ppshheader;
117 BOOL unicode;
118 LPWSTR strPropertiesFor;
119 int nPages;
120 int active_page;
121 BOOL isModeless;
122 BOOL hasHelp;
123 BOOL hasApply;
124 BOOL useCallback;
125 BOOL restartWindows;
126 BOOL rebootSystem;
127 BOOL activeValid;
128 PropPageInfo* proppage;
129 HFONT hFont;
130 HFONT hFontBold;
131 int width;
132 int height;
133 HIMAGELIST hImageList;
134 } PropSheetInfo;
136 typedef struct
138 int x;
139 int y;
140 } PADDING_INFO;
142 /******************************************************************************
143 * Defines and global variables
146 const WCHAR PropSheetInfoStr[] =
147 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
149 #define PSP_INTERNAL_UNICODE 0x80000000
151 #define MAX_CAPTION_LENGTH 255
152 #define MAX_TABTEXT_LENGTH 255
153 #define MAX_BUTTONTEXT_LENGTH 64
155 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
157 /* Wizard metrics specified in DLUs */
158 #define WIZARD_PADDING 7
159 #define WIZARD_HEADER_HEIGHT 36
161 /******************************************************************************
162 * Prototypes
164 static int PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
165 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
166 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
167 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
169 PropSheetInfo * psInfo);
170 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
171 PropSheetInfo * psInfo);
172 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
173 PropSheetInfo * psInfo,
174 int index);
175 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
176 PropSheetInfo * psInfo);
177 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
178 const PropSheetInfo * psInfo,
179 LPCPROPSHEETPAGEW ppshpage);
180 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
181 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
182 static BOOL PROPSHEET_Back(HWND hwndDlg);
183 static BOOL PROPSHEET_Next(HWND hwndDlg);
184 static BOOL PROPSHEET_Finish(HWND hwndDlg);
185 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
186 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
187 static void PROPSHEET_Help(HWND hwndDlg);
188 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
189 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
190 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
191 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
192 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
193 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
194 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
195 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
196 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
197 int index,
198 int skipdir,
199 HPROPSHEETPAGE hpage);
200 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
201 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
202 WPARAM wParam, LPARAM lParam);
203 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
204 HPROPSHEETPAGE hpage);
206 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
207 int index,
208 HPROPSHEETPAGE hpage);
209 static void PROPSHEET_CleanUp(HWND hwndDlg);
210 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
211 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
212 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
213 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
214 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
216 INT_PTR CALLBACK
217 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
219 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
221 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
222 /******************************************************************************
223 * PROPSHEET_UnImplementedFlags
225 * Document use of flags we don't implement yet.
227 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
229 CHAR string[256];
231 string[0] = '\0';
234 * unhandled header flags:
235 * PSH_WIZARDHASFINISH 0x00000010
236 * PSH_RTLREADING 0x00000800
237 * PSH_STRETCHWATERMARK 0x00040000
238 * PSH_USEPAGELANG 0x00200000
241 add_flag(PSH_WIZARDHASFINISH);
242 add_flag(PSH_RTLREADING);
243 add_flag(PSH_STRETCHWATERMARK);
244 add_flag(PSH_USEPAGELANG);
245 if (string[0] != '\0')
246 FIXME("%s\n", string);
248 #undef add_flag
250 /******************************************************************************
251 * PROPSHEET_GetPageRect
253 * Retrieve rect from tab control and map into the dialog for SetWindowPos
255 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
256 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
258 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
259 HWND hwndChild;
260 RECT r;
262 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
263 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
264 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
265 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
267 rc->left = rc->top = WIZARD_PADDING;
269 else
271 rc->left = rc->top = 0;
273 rc->right = psInfo->width - rc->left;
274 rc->bottom = psInfo->height - rc->top;
275 MapDialogRect(hwndDlg, rc);
277 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
278 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
279 !(ppshpage->dwFlags & PSP_HIDEHEADER))
281 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
282 GetClientRect(hwndChild, &r);
283 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
284 rc->top += r.bottom + 1;
286 } else {
287 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
288 GetClientRect(hwndTabCtrl, rc);
289 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
290 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
294 /******************************************************************************
295 * PROPSHEET_FindPageByResId
297 * Find page index corresponding to page resource id.
299 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
301 INT i;
303 for (i = 0; i < psInfo->nPages; i++)
305 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
307 /* Fixme: if resource ID is a string shall we use strcmp ??? */
308 if (lppsp->u.pszTemplate == (LPVOID)resId)
309 break;
312 return i;
315 /******************************************************************************
316 * PROPSHEET_AtoW
318 * Convert ASCII to Unicode since all data is saved as Unicode.
320 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
322 INT len;
324 TRACE("<%s>\n", frstr);
325 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
326 *tostr = Alloc(len * sizeof(WCHAR));
327 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
330 /******************************************************************************
331 * PROPSHEET_CollectSheetInfoA
333 * Collect relevant data.
335 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
336 PropSheetInfo * psInfo)
338 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
339 DWORD dwFlags = lppsh->dwFlags;
341 psInfo->hasHelp = dwFlags & PSH_HASHELP;
342 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
343 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
344 psInfo->isModeless = dwFlags & PSH_MODELESS;
346 memcpy(&psInfo->ppshheader,lppsh,dwSize);
347 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
348 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
349 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
351 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
353 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
354 psInfo->ppshheader.pszCaption = NULL;
355 else
357 if (HIWORD(lppsh->pszCaption))
359 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
360 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
361 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
364 psInfo->nPages = lppsh->nPages;
366 if (dwFlags & PSH_USEPSTARTPAGE)
368 TRACE("PSH_USEPSTARTPAGE is on\n");
369 psInfo->active_page = 0;
371 else
372 psInfo->active_page = lppsh->u2.nStartPage;
374 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
375 psInfo->active_page = 0;
377 psInfo->restartWindows = FALSE;
378 psInfo->rebootSystem = FALSE;
379 psInfo->hImageList = 0;
380 psInfo->activeValid = FALSE;
382 return TRUE;
385 /******************************************************************************
386 * PROPSHEET_CollectSheetInfoW
388 * Collect relevant data.
390 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
391 PropSheetInfo * psInfo)
393 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
394 DWORD dwFlags = lppsh->dwFlags;
396 psInfo->hasHelp = dwFlags & PSH_HASHELP;
397 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
398 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
399 psInfo->isModeless = dwFlags & PSH_MODELESS;
401 memcpy(&psInfo->ppshheader,lppsh,dwSize);
402 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
403 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
405 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
407 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
408 psInfo->ppshheader.pszCaption = NULL;
409 else
411 if (HIWORD(lppsh->pszCaption))
413 int len = strlenW(lppsh->pszCaption);
414 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
415 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
418 psInfo->nPages = lppsh->nPages;
420 if (dwFlags & PSH_USEPSTARTPAGE)
422 TRACE("PSH_USEPSTARTPAGE is on\n");
423 psInfo->active_page = 0;
425 else
426 psInfo->active_page = lppsh->u2.nStartPage;
428 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
429 psInfo->active_page = 0;
431 psInfo->restartWindows = FALSE;
432 psInfo->rebootSystem = FALSE;
433 psInfo->hImageList = 0;
434 psInfo->activeValid = FALSE;
436 return TRUE;
439 /******************************************************************************
440 * PROPSHEET_CollectPageInfo
442 * Collect property sheet data.
443 * With code taken from DIALOG_ParseTemplate32.
445 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
446 PropSheetInfo * psInfo,
447 int index)
449 DLGTEMPLATE* pTemplate;
450 const WORD* p;
451 DWORD dwFlags;
452 int width, height;
454 TRACE("\n");
455 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
456 psInfo->proppage[index].hwndPage = 0;
457 psInfo->proppage[index].isDirty = FALSE;
460 * Process property page flags.
462 dwFlags = lppsp->dwFlags;
463 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
464 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
465 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
467 /* as soon as we have a page with the help flag, set the sheet flag on */
468 if (psInfo->proppage[index].hasHelp)
469 psInfo->hasHelp = TRUE;
472 * Process page template.
474 if (dwFlags & PSP_DLGINDIRECT)
475 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
476 else if(dwFlags & PSP_INTERNAL_UNICODE )
478 HRSRC hResource = FindResourceW(lppsp->hInstance,
479 lppsp->u.pszTemplate,
480 (LPWSTR)RT_DIALOG);
481 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
482 hResource);
483 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
485 else
487 HRSRC hResource = FindResourceA(lppsp->hInstance,
488 (LPSTR)lppsp->u.pszTemplate,
489 (LPSTR)RT_DIALOG);
490 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
491 hResource);
492 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
496 * Extract the size of the page and the caption.
498 if (!pTemplate)
499 return FALSE;
501 p = (const WORD *)pTemplate;
503 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
505 /* DLGTEMPLATEEX (not defined in any std. header file) */
507 p++; /* dlgVer */
508 p++; /* signature */
509 p += 2; /* help ID */
510 p += 2; /* ext style */
511 p += 2; /* style */
513 else
515 /* DLGTEMPLATE */
517 p += 2; /* style */
518 p += 2; /* ext style */
521 p++; /* nb items */
522 p++; /* x */
523 p++; /* y */
524 width = (WORD)*p; p++;
525 height = (WORD)*p; p++;
527 /* Special calculation for interior wizard pages so the largest page is
528 * calculated correctly. We need to add all the padding and space occupied
529 * by the header so the width and height sums up to the whole wizard client
530 * area. */
531 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
532 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
533 !(dwFlags & PSP_HIDEHEADER))
535 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
536 width += 2 * WIZARD_PADDING;
538 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
540 height += 2 * WIZARD_PADDING;
541 width += 2 * WIZARD_PADDING;
544 /* remember the largest width and height */
545 if (width > psInfo->width)
546 psInfo->width = width;
548 if (height > psInfo->height)
549 psInfo->height = height;
551 /* menu */
552 switch ((WORD)*p)
554 case 0x0000:
555 p++;
556 break;
557 case 0xffff:
558 p += 2;
559 break;
560 default:
561 p += lstrlenW( (LPCWSTR)p ) + 1;
562 break;
565 /* class */
566 switch ((WORD)*p)
568 case 0x0000:
569 p++;
570 break;
571 case 0xffff:
572 p += 2;
573 break;
574 default:
575 p += lstrlenW( (LPCWSTR)p ) + 1;
576 break;
579 /* Extract the caption */
580 psInfo->proppage[index].pszText = (LPCWSTR)p;
581 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
582 p += lstrlenW((LPCWSTR)p) + 1;
584 if (dwFlags & PSP_USETITLE)
586 WCHAR szTitle[256];
587 const WCHAR *pTitle;
588 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
589 int len;
591 if ( !HIWORD( lppsp->pszTitle ) )
593 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
595 pTitle = pszNull;
596 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
598 else
599 pTitle = szTitle;
601 else
602 pTitle = lppsp->pszTitle;
604 len = strlenW(pTitle);
605 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
606 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
610 * Build the image list for icons
612 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
614 HICON hIcon;
615 int icon_cx = GetSystemMetrics(SM_CXSMICON);
616 int icon_cy = GetSystemMetrics(SM_CYSMICON);
618 if (dwFlags & PSP_USEICONID)
619 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
620 icon_cx, icon_cy, LR_DEFAULTCOLOR);
621 else
622 hIcon = lppsp->u2.hIcon;
624 if ( hIcon )
626 if (psInfo->hImageList == 0 )
627 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
629 ImageList_AddIcon(psInfo->hImageList, hIcon);
634 return TRUE;
637 /******************************************************************************
638 * PROPSHEET_CreateDialog
640 * Creates the actual property sheet.
642 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
644 LRESULT ret;
645 LPCVOID template;
646 LPVOID temp = 0;
647 HRSRC hRes;
648 DWORD resSize;
649 WORD resID = IDD_PROPSHEET;
651 TRACE("\n");
652 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
653 resID = IDD_WIZARD;
655 if( psInfo->unicode )
657 if(!(hRes = FindResourceW(COMCTL32_hModule,
658 MAKEINTRESOURCEW(resID),
659 (LPWSTR)RT_DIALOG)))
660 return -1;
662 else
664 if(!(hRes = FindResourceA(COMCTL32_hModule,
665 MAKEINTRESOURCEA(resID),
666 (LPSTR)RT_DIALOG)))
667 return -1;
670 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
671 return -1;
674 * Make a copy of the dialog template.
676 resSize = SizeofResource(COMCTL32_hModule, hRes);
678 temp = Alloc(resSize);
680 if (!temp)
681 return -1;
683 memcpy(temp, template, resSize);
685 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
687 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
688 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
689 else
690 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
692 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
693 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
695 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
696 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
697 else
698 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
701 if (psInfo->useCallback)
702 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
704 /* NOTE: MSDN states "Returns a positive value if successful, or -1
705 * otherwise for modal property sheets.", but this is wrong. The
706 * actual return value is either TRUE (success), FALSE (cancel) or
707 * -1 (error). */
708 if( psInfo->unicode )
710 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
711 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
712 (LPDLGTEMPLATEW) temp,
713 psInfo->ppshheader.hwndParent,
714 PROPSHEET_DialogProc,
715 (LPARAM)psInfo);
716 else
718 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
719 (LPDLGTEMPLATEW) temp,
720 psInfo->ppshheader.hwndParent,
721 PROPSHEET_DialogProc,
722 (LPARAM)psInfo);
723 if ( !ret ) ret = -1;
726 else
728 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
729 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
730 (LPDLGTEMPLATEA) temp,
731 psInfo->ppshheader.hwndParent,
732 PROPSHEET_DialogProc,
733 (LPARAM)psInfo);
734 else
736 ret = (int)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
737 (LPDLGTEMPLATEA) temp,
738 psInfo->ppshheader.hwndParent,
739 PROPSHEET_DialogProc,
740 (LPARAM)psInfo);
741 if ( !ret ) ret = -1;
745 Free(temp);
747 return ret;
750 /******************************************************************************
751 * PROPSHEET_SizeMismatch
753 * Verify that the tab control and the "largest" property sheet page dlg. template
754 * match in size.
756 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
758 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
759 RECT rcOrigTab, rcPage;
762 * Original tab size.
764 GetClientRect(hwndTabCtrl, &rcOrigTab);
765 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
766 rcOrigTab.right, rcOrigTab.bottom);
769 * Biggest page size.
771 rcPage.left = 0;
772 rcPage.top = 0;
773 rcPage.right = psInfo->width;
774 rcPage.bottom = psInfo->height;
776 MapDialogRect(hwndDlg, &rcPage);
777 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
778 rcPage.right, rcPage.bottom);
780 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
781 return TRUE;
782 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
783 return TRUE;
785 return FALSE;
788 /******************************************************************************
789 * PROPSHEET_AdjustSize
791 * Resizes the property sheet and the tab control to fit the largest page.
793 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
795 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
796 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
797 RECT rc,tabRect;
798 int tabOffsetX, tabOffsetY, buttonHeight;
799 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
800 RECT units;
802 /* Get the height of buttons */
803 GetClientRect(hwndButton, &rc);
804 buttonHeight = rc.bottom;
807 * Biggest page size.
809 rc.left = 0;
810 rc.top = 0;
811 rc.right = psInfo->width;
812 rc.bottom = psInfo->height;
814 MapDialogRect(hwndDlg, &rc);
816 /* retrieve the dialog units */
817 units.left = units.right = 4;
818 units.top = units.bottom = 8;
819 MapDialogRect(hwndDlg, &units);
822 * Resize the tab control.
824 GetClientRect(hwndTabCtrl,&tabRect);
826 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
828 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
830 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
831 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
834 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
836 rc.right = rc.left + tabRect.right - tabRect.left;
837 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
840 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
842 tabOffsetX = -(rc.left);
843 tabOffsetY = -(rc.top);
845 rc.right -= rc.left;
846 rc.bottom -= rc.top;
847 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
848 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
849 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
850 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
852 GetClientRect(hwndTabCtrl, &rc);
854 TRACE("tab client rc %ld %ld %ld %ld\n",
855 rc.left, rc.top, rc.right, rc.bottom);
857 rc.right += ((padding.x * 2) + tabOffsetX);
858 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
861 * Resize the property sheet.
863 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
864 (DWORD)hwndDlg, rc.right, rc.bottom);
865 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
866 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
867 return TRUE;
870 /******************************************************************************
871 * PROPSHEET_AdjustSizeWizard
873 * Resizes the property sheet to fit the largest page.
875 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
877 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
878 RECT rc, lineRect, dialogRect;
880 /* Biggest page size */
881 rc.left = 0;
882 rc.top = 0;
883 rc.right = psInfo->width;
884 rc.bottom = psInfo->height;
885 MapDialogRect(hwndDlg, &rc);
887 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
889 /* Add space for the buttons row */
890 GetWindowRect(hwndLine, &lineRect);
891 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
892 GetClientRect(hwndDlg, &dialogRect);
893 rc.bottom += dialogRect.bottom - lineRect.top - 1;
895 /* Convert the client coordinates to window coordinates */
896 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
898 /* Resize the property sheet */
899 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
900 (DWORD)hwndDlg, rc.right, rc.bottom);
901 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
902 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
904 return TRUE;
907 /******************************************************************************
908 * PROPSHEET_AdjustButtons
910 * Adjusts the buttons' positions.
912 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
914 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
915 RECT rcSheet;
916 int x, y;
917 int num_buttons = 2;
918 int buttonWidth, buttonHeight;
919 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
921 if (psInfo->hasApply)
922 num_buttons++;
924 if (psInfo->hasHelp)
925 num_buttons++;
928 * Obtain the size of the buttons.
930 GetClientRect(hwndButton, &rcSheet);
931 buttonWidth = rcSheet.right;
932 buttonHeight = rcSheet.bottom;
935 * Get the size of the property sheet.
937 GetClientRect(hwndParent, &rcSheet);
940 * All buttons will be at this y coordinate.
942 y = rcSheet.bottom - (padding.y + buttonHeight);
945 * Position OK button and make it default.
947 hwndButton = GetDlgItem(hwndParent, IDOK);
949 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
951 SetWindowPos(hwndButton, 0, x, y, 0, 0,
952 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
954 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
958 * Position Cancel button.
960 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
962 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
964 SetWindowPos(hwndButton, 0, x, y, 0, 0,
965 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968 * Position Apply button.
970 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
972 if (psInfo->hasApply)
974 if (psInfo->hasHelp)
975 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
976 else
977 x = rcSheet.right - (padding.x + buttonWidth);
979 SetWindowPos(hwndButton, 0, x, y, 0, 0,
980 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
982 EnableWindow(hwndButton, FALSE);
984 else
985 ShowWindow(hwndButton, SW_HIDE);
988 * Position Help button.
990 hwndButton = GetDlgItem(hwndParent, IDHELP);
992 if (psInfo->hasHelp)
994 x = rcSheet.right - (padding.x + buttonWidth);
996 SetWindowPos(hwndButton, 0, x, y, 0, 0,
997 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
999 else
1000 ShowWindow(hwndButton, SW_HIDE);
1002 return TRUE;
1005 /******************************************************************************
1006 * PROPSHEET_AdjustButtonsWizard
1008 * Adjusts the buttons' positions.
1010 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1011 PropSheetInfo* psInfo)
1013 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1014 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1015 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1016 RECT rcSheet;
1017 int x, y;
1018 int num_buttons = 3;
1019 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1020 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1022 if (psInfo->hasHelp)
1023 num_buttons++;
1026 * Obtain the size of the buttons.
1028 GetClientRect(hwndButton, &rcSheet);
1029 buttonWidth = rcSheet.right;
1030 buttonHeight = rcSheet.bottom;
1032 GetClientRect(hwndLine, &rcSheet);
1033 lineHeight = rcSheet.bottom;
1036 * Get the size of the property sheet.
1038 GetClientRect(hwndParent, &rcSheet);
1041 * All buttons will be at this y coordinate.
1043 y = rcSheet.bottom - (padding.y + buttonHeight);
1046 * Position the Next and the Finish buttons.
1048 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1050 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1052 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1053 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1055 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1057 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1058 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1060 ShowWindow(hwndButton, SW_HIDE);
1063 * Position the Back button.
1065 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1067 x -= buttonWidth;
1069 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1070 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1073 * Position the Cancel button.
1075 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1077 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1079 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1080 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1083 * Position Help button.
1085 hwndButton = GetDlgItem(hwndParent, IDHELP);
1087 if (psInfo->hasHelp)
1089 x = rcSheet.right - (padding.x + buttonWidth);
1091 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1092 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1094 else
1095 ShowWindow(hwndButton, SW_HIDE);
1097 if (psInfo->ppshheader.dwFlags &
1098 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1099 padding.x = 0;
1102 * Position and resize the sunken line.
1104 x = padding.x;
1105 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1107 lineWidth = rcSheet.right - (padding.x * 2);
1108 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1109 SWP_NOZORDER | SWP_NOACTIVATE);
1112 * Position and resize the header sunken line.
1115 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1116 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1117 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1118 ShowWindow(hwndLineHeader, SW_HIDE);
1120 return TRUE;
1123 /******************************************************************************
1124 * PROPSHEET_GetPaddingInfo
1126 * Returns the layout information.
1128 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1130 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1131 RECT rcTab;
1132 POINT tl;
1133 PADDING_INFO padding;
1135 GetWindowRect(hwndTab, &rcTab);
1137 tl.x = rcTab.left;
1138 tl.y = rcTab.top;
1140 ScreenToClient(hwndDlg, &tl);
1142 padding.x = tl.x;
1143 padding.y = tl.y;
1145 return padding;
1148 /******************************************************************************
1149 * PROPSHEET_GetPaddingInfoWizard
1151 * Returns the layout information.
1152 * Vertical spacing is the distance between the line and the buttons.
1153 * Do NOT use the Help button to gather padding information when it isn't mapped
1154 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1155 * for it in this case !
1156 * FIXME: I'm not sure about any other coordinate problems with these evil
1157 * buttons. Fix it in case additional problems appear or maybe calculate
1158 * a padding in a completely different way, as this is somewhat messy.
1160 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1161 psInfo)
1163 PADDING_INFO padding;
1164 RECT rc;
1165 HWND hwndControl;
1166 INT idButton;
1167 POINT ptButton, ptLine;
1169 TRACE("\n");
1170 if (psInfo->hasHelp)
1172 idButton = IDHELP;
1174 else
1176 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1178 idButton = IDC_NEXT_BUTTON;
1180 else
1182 /* hopefully this is ok */
1183 idButton = IDCANCEL;
1187 hwndControl = GetDlgItem(hwndDlg, idButton);
1188 GetWindowRect(hwndControl, &rc);
1190 ptButton.x = rc.left;
1191 ptButton.y = rc.top;
1193 ScreenToClient(hwndDlg, &ptButton);
1195 /* Line */
1196 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1197 GetWindowRect(hwndControl, &rc);
1199 ptLine.x = rc.left;
1200 ptLine.y = rc.bottom;
1202 ScreenToClient(hwndDlg, &ptLine);
1204 padding.y = ptButton.y - ptLine.y;
1206 if (padding.y < 0)
1207 ERR("padding negative ! Please report this !\n");
1209 /* this is most probably not correct, but the best we have now */
1210 padding.x = padding.y;
1211 return padding;
1214 /******************************************************************************
1215 * PROPSHEET_CreateTabControl
1217 * Insert the tabs in the tab control.
1219 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1220 PropSheetInfo * psInfo)
1222 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1223 TCITEMW item;
1224 int i, nTabs;
1225 int iImage = 0;
1227 TRACE("\n");
1228 item.mask = TCIF_TEXT;
1229 item.cchTextMax = MAX_TABTEXT_LENGTH;
1231 nTabs = psInfo->nPages;
1234 * Set the image list for icons.
1236 if (psInfo->hImageList)
1238 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1241 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1242 for (i = 0; i < nTabs; i++)
1244 if ( psInfo->proppage[i].hasIcon )
1246 item.mask |= TCIF_IMAGE;
1247 item.iImage = iImage++;
1249 else
1251 item.mask &= ~TCIF_IMAGE;
1254 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1255 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1257 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1259 return TRUE;
1262 /******************************************************************************
1263 * PROPSHEET_WizardSubclassProc
1265 * Subclassing window procedure for wizard extrior pages to prevent drawing
1266 * background and so drawing above the watermark.
1268 LRESULT CALLBACK
1269 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1271 switch (uMsg)
1273 case WM_ERASEBKGND:
1274 return TRUE;
1276 case WM_CTLCOLORSTATIC:
1277 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1278 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1281 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1285 * Get the size of an in-memory Template
1287 *( Based on the code of PROPSHEET_CollectPageInfo)
1288 * See also dialog.c/DIALOG_ParseTemplate32().
1291 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1294 const WORD* p = (const WORD *)pTemplate;
1295 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1296 WORD nrofitems;
1298 if (istemplateex)
1300 /* DLGTEMPLATEEX (not defined in any std. header file) */
1302 TRACE("is DLGTEMPLATEEX\n");
1303 p++; /* dlgVer */
1304 p++; /* signature */
1305 p += 2; /* help ID */
1306 p += 2; /* ext style */
1307 p += 2; /* style */
1309 else
1311 /* DLGTEMPLATE */
1313 TRACE("is DLGTEMPLATE\n");
1314 p += 2; /* style */
1315 p += 2; /* ext style */
1318 nrofitems = (WORD)*p; p++; /* nb items */
1319 p++; /* x */
1320 p++; /* y */
1321 p++; /* width */
1322 p++; /* height */
1324 /* menu */
1325 switch ((WORD)*p)
1327 case 0x0000:
1328 p++;
1329 break;
1330 case 0xffff:
1331 p += 2;
1332 break;
1333 default:
1334 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1335 p += lstrlenW( (LPCWSTR)p ) + 1;
1336 break;
1339 /* class */
1340 switch ((WORD)*p)
1342 case 0x0000:
1343 p++;
1344 break;
1345 case 0xffff:
1346 p += 2; /* 0xffff plus predefined window class ordinal value */
1347 break;
1348 default:
1349 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1350 p += lstrlenW( (LPCWSTR)p ) + 1;
1351 break;
1354 /* title */
1355 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1356 p += lstrlenW((LPCWSTR)p) + 1;
1358 /* font, if DS_SETFONT set */
1359 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1360 pTemplate->style)))
1362 p+=(istemplateex)?3:1;
1363 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1364 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1367 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1368 * that are following the DLGTEMPLATE(EX) data */
1369 TRACE("%d items\n",nrofitems);
1370 while (nrofitems > 0)
1372 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1374 /* skip header */
1375 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1377 /* check class */
1378 switch ((WORD)*p)
1380 case 0x0000:
1381 p++;
1382 break;
1383 case 0xffff:
1384 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1385 p += 2;
1386 break;
1387 default:
1388 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1389 p += lstrlenW( (LPCWSTR)p ) + 1;
1390 break;
1393 /* check title text */
1394 switch ((WORD)*p)
1396 case 0x0000:
1397 p++;
1398 break;
1399 case 0xffff:
1400 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1401 p += 2;
1402 break;
1403 default:
1404 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1405 p += lstrlenW( (LPCWSTR)p ) + 1;
1406 break;
1408 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1409 --nrofitems;
1412 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1413 return (p - (WORD*)pTemplate)*sizeof(WORD);
1417 /******************************************************************************
1418 * PROPSHEET_CreatePage
1420 * Creates a page.
1422 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1423 int index,
1424 const PropSheetInfo * psInfo,
1425 LPCPROPSHEETPAGEW ppshpage)
1427 DLGTEMPLATE* pTemplate;
1428 HWND hwndPage;
1429 DWORD resSize;
1430 LPVOID temp = NULL;
1432 TRACE("index %d\n", index);
1434 if (ppshpage == NULL)
1436 return FALSE;
1439 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1441 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1442 resSize = GetTemplateSize(pTemplate);
1444 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1446 HRSRC hResource;
1447 HANDLE hTemplate;
1449 hResource = FindResourceW(ppshpage->hInstance,
1450 ppshpage->u.pszTemplate,
1451 (LPWSTR)RT_DIALOG);
1452 if(!hResource)
1453 return FALSE;
1455 resSize = SizeofResource(ppshpage->hInstance, hResource);
1457 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1458 if(!hTemplate)
1459 return FALSE;
1461 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1463 * Make a copy of the dialog template to make it writable
1466 else
1468 HRSRC hResource;
1469 HANDLE hTemplate;
1471 hResource = FindResourceA(ppshpage->hInstance,
1472 (LPSTR)ppshpage->u.pszTemplate,
1473 (LPSTR)RT_DIALOG);
1474 if(!hResource)
1475 return FALSE;
1477 resSize = SizeofResource(ppshpage->hInstance, hResource);
1479 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1480 if(!hTemplate)
1481 return FALSE;
1483 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1485 * Make a copy of the dialog template to make it writable
1488 temp = Alloc(resSize);
1489 if (!temp)
1490 return FALSE;
1492 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1493 memcpy(temp, pTemplate, resSize);
1494 pTemplate = temp;
1496 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1498 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1500 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1501 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1502 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1503 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1504 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1505 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1507 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1509 else
1511 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1512 pTemplate->style &= ~DS_MODALFRAME;
1513 pTemplate->style &= ~WS_CAPTION;
1514 pTemplate->style &= ~WS_SYSMENU;
1515 pTemplate->style &= ~WS_POPUP;
1516 pTemplate->style &= ~WS_DISABLED;
1517 pTemplate->style &= ~WS_VISIBLE;
1518 pTemplate->style &= ~WS_THICKFRAME;
1520 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1523 if (psInfo->proppage[index].useCallback)
1524 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1525 (LPPROPSHEETPAGEW)ppshpage);
1527 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1528 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1529 pTemplate,
1530 hwndParent,
1531 ppshpage->pfnDlgProc,
1532 (LPARAM)ppshpage);
1533 else
1534 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1535 pTemplate,
1536 hwndParent,
1537 ppshpage->pfnDlgProc,
1538 (LPARAM)ppshpage);
1539 /* Free a no more needed copy */
1540 if(temp)
1541 Free(temp);
1543 psInfo->proppage[index].hwndPage = hwndPage;
1545 /* Subclass exterior wizard pages */
1546 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1547 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1548 (ppshpage->dwFlags & PSP_HIDEHEADER))
1550 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1551 (DWORD_PTR)ppshpage);
1554 return TRUE;
1557 /******************************************************************************
1558 * PROPSHEET_LoadWizardBitmaps
1560 * Loads the watermark and header bitmaps for a wizard.
1562 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1564 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1566 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1567 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1568 considers hbmWatermark as valid. */
1569 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1570 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1572 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1573 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1576 /* Same behavior as for watermarks */
1577 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1578 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1580 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1581 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1587 /******************************************************************************
1588 * PROPSHEET_ShowPage
1590 * Displays or creates the specified page.
1592 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1594 HWND hwndTabCtrl;
1595 HWND hwndLineHeader;
1596 LPCPROPSHEETPAGEW ppshpage;
1598 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1599 if (index == psInfo->active_page)
1601 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1602 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1603 return TRUE;
1606 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1607 if (psInfo->proppage[index].hwndPage == 0)
1609 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1612 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1613 (ppshpage->dwFlags & PSP_USETITLE))
1615 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1616 psInfo->proppage[index].pszText);
1619 if (psInfo->active_page != -1)
1620 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1622 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1624 /* Synchronize current selection with tab control
1625 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1626 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1627 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1629 psInfo->active_page = index;
1630 psInfo->activeValid = TRUE;
1632 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1634 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1635 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1637 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1638 ShowWindow(hwndLineHeader, SW_HIDE);
1639 else
1640 ShowWindow(hwndLineHeader, SW_SHOW);
1643 InvalidateRgn(hwndDlg, NULL, TRUE);
1644 UpdateWindow(hwndDlg);
1646 return TRUE;
1649 /******************************************************************************
1650 * PROPSHEET_Back
1652 static BOOL PROPSHEET_Back(HWND hwndDlg)
1654 PSHNOTIFY psn;
1655 HWND hwndPage;
1656 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1657 PropSheetInfoStr);
1658 LRESULT result;
1659 int idx;
1661 TRACE("active_page %d\n", psInfo->active_page);
1662 if (psInfo->active_page < 0)
1663 return FALSE;
1665 psn.hdr.code = PSN_WIZBACK;
1666 psn.hdr.hwndFrom = hwndDlg;
1667 psn.hdr.idFrom = 0;
1668 psn.lParam = 0;
1670 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1672 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1673 if (result == -1)
1674 return FALSE;
1675 else if (result == 0)
1676 idx = psInfo->active_page - 1;
1677 else
1678 idx = PROPSHEET_FindPageByResId(psInfo, result);
1680 if (idx >= 0 && idx < psInfo->nPages)
1682 if (PROPSHEET_CanSetCurSel(hwndDlg))
1683 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1685 return TRUE;
1688 /******************************************************************************
1689 * PROPSHEET_Next
1691 static BOOL PROPSHEET_Next(HWND hwndDlg)
1693 PSHNOTIFY psn;
1694 HWND hwndPage;
1695 LRESULT msgResult = 0;
1696 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1697 PropSheetInfoStr);
1698 int idx;
1700 TRACE("active_page %d\n", psInfo->active_page);
1701 if (psInfo->active_page < 0)
1702 return FALSE;
1704 psn.hdr.code = PSN_WIZNEXT;
1705 psn.hdr.hwndFrom = hwndDlg;
1706 psn.hdr.idFrom = 0;
1707 psn.lParam = 0;
1709 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1711 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1712 if (msgResult == -1)
1713 return FALSE;
1714 else if (msgResult == 0)
1715 idx = psInfo->active_page + 1;
1716 else
1717 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1719 if (idx < psInfo->nPages )
1721 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1722 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1725 return TRUE;
1728 /******************************************************************************
1729 * PROPSHEET_Finish
1731 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1733 PSHNOTIFY psn;
1734 HWND hwndPage;
1735 LRESULT msgResult = 0;
1736 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1737 PropSheetInfoStr);
1739 TRACE("active_page %d\n", psInfo->active_page);
1740 if (psInfo->active_page < 0)
1741 return FALSE;
1743 psn.hdr.code = PSN_WIZFINISH;
1744 psn.hdr.hwndFrom = hwndDlg;
1745 psn.hdr.idFrom = 0;
1746 psn.lParam = 0;
1748 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1750 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1752 TRACE("msg result %ld\n", msgResult);
1754 if (msgResult != 0)
1755 return FALSE;
1757 if (psInfo->isModeless)
1758 psInfo->activeValid = FALSE;
1759 else
1760 EndDialog(hwndDlg, TRUE);
1762 return TRUE;
1765 /******************************************************************************
1766 * PROPSHEET_Apply
1768 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1770 int i;
1771 HWND hwndPage;
1772 PSHNOTIFY psn;
1773 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1774 PropSheetInfoStr);
1776 TRACE("active_page %d\n", psInfo->active_page);
1777 if (psInfo->active_page < 0)
1778 return FALSE;
1780 psn.hdr.hwndFrom = hwndDlg;
1781 psn.hdr.idFrom = 0;
1782 psn.lParam = 0;
1786 * Send PSN_KILLACTIVE to the current page.
1788 psn.hdr.code = PSN_KILLACTIVE;
1790 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1792 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1793 return FALSE;
1796 * Send PSN_APPLY to all pages.
1798 psn.hdr.code = PSN_APPLY;
1799 psn.lParam = lParam;
1801 for (i = 0; i < psInfo->nPages; i++)
1803 hwndPage = psInfo->proppage[i].hwndPage;
1804 if (hwndPage)
1806 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1808 case PSNRET_INVALID:
1809 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1810 /* fall through */
1811 case PSNRET_INVALID_NOCHANGEPAGE:
1812 return FALSE;
1817 if(lParam)
1819 psInfo->activeValid = FALSE;
1821 else if(psInfo->active_page >= 0)
1823 psn.hdr.code = PSN_SETACTIVE;
1824 psn.lParam = 0;
1825 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1826 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1829 return TRUE;
1832 /******************************************************************************
1833 * PROPSHEET_Cancel
1835 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1837 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1838 PropSheetInfoStr);
1839 HWND hwndPage;
1840 PSHNOTIFY psn;
1841 int i;
1843 TRACE("active_page %d\n", psInfo->active_page);
1844 if (psInfo->active_page < 0)
1845 return;
1847 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1848 psn.hdr.code = PSN_QUERYCANCEL;
1849 psn.hdr.hwndFrom = hwndDlg;
1850 psn.hdr.idFrom = 0;
1851 psn.lParam = 0;
1853 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1854 return;
1856 psn.hdr.code = PSN_RESET;
1857 psn.lParam = lParam;
1859 for (i = 0; i < psInfo->nPages; i++)
1861 hwndPage = psInfo->proppage[i].hwndPage;
1863 if (hwndPage)
1864 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1867 if (psInfo->isModeless)
1869 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1870 psInfo->activeValid = FALSE;
1872 else
1873 EndDialog(hwndDlg, FALSE);
1876 /******************************************************************************
1877 * PROPSHEET_Help
1879 static void PROPSHEET_Help(HWND hwndDlg)
1881 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1882 PropSheetInfoStr);
1883 HWND hwndPage;
1884 PSHNOTIFY psn;
1886 TRACE("active_page %d\n", psInfo->active_page);
1887 if (psInfo->active_page < 0)
1888 return;
1890 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1891 psn.hdr.code = PSN_HELP;
1892 psn.hdr.hwndFrom = hwndDlg;
1893 psn.hdr.idFrom = 0;
1894 psn.lParam = 0;
1896 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1899 /******************************************************************************
1900 * PROPSHEET_Changed
1902 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1904 int i;
1905 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1906 PropSheetInfoStr);
1908 TRACE("\n");
1909 if (!psInfo) return;
1911 * Set the dirty flag of this page.
1913 for (i = 0; i < psInfo->nPages; i++)
1915 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1916 psInfo->proppage[i].isDirty = TRUE;
1920 * Enable the Apply button.
1922 if (psInfo->hasApply)
1924 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1926 EnableWindow(hwndApplyBtn, TRUE);
1930 /******************************************************************************
1931 * PROPSHEET_UnChanged
1933 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1935 int i;
1936 BOOL noPageDirty = TRUE;
1937 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1938 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1939 PropSheetInfoStr);
1941 TRACE("\n");
1942 if ( !psInfo ) return;
1943 for (i = 0; i < psInfo->nPages; i++)
1945 /* set the specified page as clean */
1946 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1947 psInfo->proppage[i].isDirty = FALSE;
1949 /* look to see if there's any dirty pages */
1950 if (psInfo->proppage[i].isDirty)
1951 noPageDirty = FALSE;
1955 * Disable Apply button.
1957 if (noPageDirty)
1958 EnableWindow(hwndApplyBtn, FALSE);
1961 /******************************************************************************
1962 * PROPSHEET_PressButton
1964 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1966 TRACE("buttonID %d\n", buttonID);
1967 switch (buttonID)
1969 case PSBTN_APPLYNOW:
1970 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1971 break;
1972 case PSBTN_BACK:
1973 PROPSHEET_Back(hwndDlg);
1974 break;
1975 case PSBTN_CANCEL:
1976 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1977 break;
1978 case PSBTN_FINISH:
1979 PROPSHEET_Finish(hwndDlg);
1980 break;
1981 case PSBTN_HELP:
1982 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1983 break;
1984 case PSBTN_NEXT:
1985 PROPSHEET_Next(hwndDlg);
1986 break;
1987 case PSBTN_OK:
1988 PROPSHEET_DoCommand(hwndDlg, IDOK);
1989 break;
1990 default:
1991 FIXME("Invalid button index %d\n", buttonID);
1996 /*************************************************************************
1997 * BOOL PROPSHEET_CanSetCurSel [Internal]
1999 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2001 * PARAMS
2002 * hwndDlg [I] handle to a Dialog hWnd
2004 * RETURNS
2005 * TRUE if Current Selection can change
2007 * NOTES
2009 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2011 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2012 PropSheetInfoStr);
2013 HWND hwndPage;
2014 PSHNOTIFY psn;
2015 BOOL res = FALSE;
2017 TRACE("active_page %d\n", psInfo->active_page);
2018 if (!psInfo)
2020 res = FALSE;
2021 goto end;
2024 if (psInfo->active_page < 0)
2026 res = TRUE;
2027 goto end;
2031 * Notify the current page.
2033 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2034 psn.hdr.code = PSN_KILLACTIVE;
2035 psn.hdr.hwndFrom = hwndDlg;
2036 psn.hdr.idFrom = 0;
2037 psn.lParam = 0;
2039 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2041 end:
2042 TRACE("<-- %d\n", res);
2043 return res;
2046 /******************************************************************************
2047 * PROPSHEET_SetCurSel
2049 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2050 int index,
2051 int skipdir,
2052 HPROPSHEETPAGE hpage
2055 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2056 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2057 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2059 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2060 /* hpage takes precedence over index */
2061 if (hpage != NULL)
2062 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2064 if (index < 0 || index >= psInfo->nPages)
2066 TRACE("Could not find page to select!\n");
2067 return FALSE;
2070 while (1) {
2071 int result;
2072 PSHNOTIFY psn;
2073 RECT rc;
2074 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2076 if (hwndTabControl)
2077 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2079 psn.hdr.code = PSN_SETACTIVE;
2080 psn.hdr.hwndFrom = hwndDlg;
2081 psn.hdr.idFrom = 0;
2082 psn.lParam = 0;
2084 if (!psInfo->proppage[index].hwndPage) {
2085 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2088 /* Resize the property sheet page to the fit in the Tab control
2089 * (for regular property sheets) or to fit in the client area (for
2090 * wizards).
2091 * NOTE: The resizing happens every time the page is selected and
2092 * not only when it's created (some applications depend on it). */
2093 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2094 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2095 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2096 rc.right - rc.left, rc.bottom - rc.top);
2097 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2098 rc.left, rc.top,
2099 rc.right - rc.left, rc.bottom - rc.top, 0);
2101 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2102 if (!result)
2103 break;
2104 if (result == -1) {
2105 index+=skipdir;
2106 if (index < 0) {
2107 index = 0;
2108 WARN("Tried to skip before first property sheet page!\n");
2109 break;
2111 if (index >= psInfo->nPages) {
2112 WARN("Tried to skip after last property sheet page!\n");
2113 index = psInfo->nPages-1;
2114 break;
2117 else if (result != 0)
2119 int old_index = index;
2120 index = PROPSHEET_FindPageByResId(psInfo, result);
2121 if(index >= psInfo->nPages) {
2122 index = old_index;
2123 WARN("Tried to skip to nonexistant page by res id\n");
2124 break;
2126 continue;
2130 * Display the new page.
2132 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2134 if (psInfo->proppage[index].hasHelp)
2135 EnableWindow(hwndHelp, TRUE);
2136 else
2137 EnableWindow(hwndHelp, FALSE);
2139 return TRUE;
2142 /******************************************************************************
2143 * PROPSHEET_SetCurSelId
2145 * Selects the page, specified by resource id.
2147 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2149 int idx;
2150 PropSheetInfo* psInfo =
2151 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2153 idx = PROPSHEET_FindPageByResId(psInfo, id);
2154 if (idx < psInfo->nPages )
2156 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2157 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2161 /******************************************************************************
2162 * PROPSHEET_SetTitleA
2164 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2166 if(HIWORD(lpszText))
2168 WCHAR szTitle[256];
2169 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2170 szTitle, sizeof(szTitle));
2171 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2173 else
2175 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2179 /******************************************************************************
2180 * PROPSHEET_SetTitleW
2182 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2184 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2185 WCHAR szTitle[256];
2187 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2188 if (HIWORD(lpszText) == 0) {
2189 if (!LoadStringW(psInfo->ppshheader.hInstance,
2190 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2191 return;
2192 lpszText = szTitle;
2194 if (dwStyle & PSH_PROPTITLE)
2196 WCHAR* dest;
2197 int lentitle = strlenW(lpszText);
2198 int lenprop = strlenW(psInfo->strPropertiesFor);
2200 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2201 strcpyW(dest, psInfo->strPropertiesFor);
2202 strcatW(dest, lpszText);
2204 SetWindowTextW(hwndDlg, dest);
2205 Free(dest);
2207 else
2208 SetWindowTextW(hwndDlg, lpszText);
2211 /******************************************************************************
2212 * PROPSHEET_SetFinishTextA
2214 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2216 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2218 TRACE("'%s'\n", lpszText);
2219 /* Set text, show and enable the Finish button */
2220 SetWindowTextA(hwndButton, lpszText);
2221 ShowWindow(hwndButton, SW_SHOW);
2222 EnableWindow(hwndButton, TRUE);
2224 /* Make it default pushbutton */
2225 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2227 /* Hide Back button */
2228 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2229 ShowWindow(hwndButton, SW_HIDE);
2231 /* Hide Next button */
2232 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2233 ShowWindow(hwndButton, SW_HIDE);
2236 /******************************************************************************
2237 * PROPSHEET_SetFinishTextW
2239 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2241 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2243 TRACE("'%s'\n", debugstr_w(lpszText));
2244 /* Set text, show and enable the Finish button */
2245 SetWindowTextW(hwndButton, lpszText);
2246 ShowWindow(hwndButton, SW_SHOW);
2247 EnableWindow(hwndButton, TRUE);
2249 /* Make it default pushbutton */
2250 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2252 /* Hide Back button */
2253 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2254 ShowWindow(hwndButton, SW_HIDE);
2256 /* Hide Next button */
2257 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2258 ShowWindow(hwndButton, SW_HIDE);
2261 /******************************************************************************
2262 * PROPSHEET_QuerySiblings
2264 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2265 WPARAM wParam, LPARAM lParam)
2267 int i = 0;
2268 HWND hwndPage;
2269 LRESULT msgResult = 0;
2270 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2272 while ((i < psInfo->nPages) && (msgResult == 0))
2274 hwndPage = psInfo->proppage[i].hwndPage;
2275 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2276 i++;
2279 return msgResult;
2283 /******************************************************************************
2284 * PROPSHEET_AddPage
2286 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2287 HPROPSHEETPAGE hpage)
2289 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2290 PropSheetInfoStr);
2291 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2292 TCITEMW item;
2293 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2295 TRACE("hpage %p\n", hpage);
2297 * Allocate and fill in a new PropPageInfo entry.
2299 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2300 sizeof(PropPageInfo) *
2301 (psInfo->nPages + 1));
2302 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2303 return FALSE;
2305 psInfo->proppage[psInfo->nPages].hpage = hpage;
2307 if (ppsp->dwFlags & PSP_PREMATURE)
2309 /* Create the page but don't show it */
2310 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2314 * Add a new tab to the tab control.
2316 item.mask = TCIF_TEXT;
2317 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2318 item.cchTextMax = MAX_TABTEXT_LENGTH;
2320 if (psInfo->hImageList)
2322 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2325 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2327 item.mask |= TCIF_IMAGE;
2328 item.iImage = psInfo->nPages;
2331 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2332 (LPARAM)&item);
2334 psInfo->nPages++;
2336 /* If it is the only page - show it */
2337 if(psInfo->nPages == 1)
2338 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2339 return TRUE;
2342 /******************************************************************************
2343 * PROPSHEET_RemovePage
2345 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2346 int index,
2347 HPROPSHEETPAGE hpage)
2349 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2350 PropSheetInfoStr);
2351 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2352 PropPageInfo* oldPages;
2354 TRACE("index %d, hpage %p\n", index, hpage);
2355 if (!psInfo) {
2356 return FALSE;
2359 * hpage takes precedence over index.
2361 if (hpage != 0)
2363 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2366 /* Make sure that index is within range */
2367 if (index < 0 || index >= psInfo->nPages)
2369 TRACE("Could not find page to remove!\n");
2370 return FALSE;
2373 TRACE("total pages %d removing page %d active page %d\n",
2374 psInfo->nPages, index, psInfo->active_page);
2376 * Check if we're removing the active page.
2378 if (index == psInfo->active_page)
2380 if (psInfo->nPages > 1)
2382 if (index > 0)
2384 /* activate previous page */
2385 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2387 else
2389 /* activate the next page */
2390 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2391 psInfo->active_page = index;
2394 else
2396 psInfo->active_page = -1;
2397 if (!psInfo->isModeless)
2399 EndDialog(hwndDlg, FALSE);
2400 return TRUE;
2404 else if (index < psInfo->active_page)
2405 psInfo->active_page--;
2407 /* Unsubclass the page dialog window */
2408 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2409 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2410 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2412 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2413 PROPSHEET_WizardSubclassProc, 1);
2416 /* Destroy page dialog window */
2417 DestroyWindow(psInfo->proppage[index].hwndPage);
2419 /* Free page resources */
2420 if(psInfo->proppage[index].hpage)
2422 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2424 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2425 Free ((LPVOID)psInfo->proppage[index].pszText);
2427 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2430 /* Remove the tab */
2431 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2433 oldPages = psInfo->proppage;
2434 psInfo->nPages--;
2435 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2437 if (index > 0)
2438 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2440 if (index < psInfo->nPages)
2441 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2442 (psInfo->nPages - index) * sizeof(PropPageInfo));
2444 Free(oldPages);
2446 return FALSE;
2449 /******************************************************************************
2450 * PROPSHEET_SetWizButtons
2452 * This code will work if (and assumes that) the Next button is on top of the
2453 * Finish button. ie. Finish comes after Next in the Z order.
2454 * This means make sure the dialog template reflects this.
2457 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2459 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2460 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2461 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2463 TRACE("%ld\n", dwFlags);
2465 EnableWindow(hwndBack, FALSE);
2466 EnableWindow(hwndNext, FALSE);
2467 EnableWindow(hwndFinish, FALSE);
2469 if (dwFlags & PSWIZB_BACK)
2470 EnableWindow(hwndBack, TRUE);
2472 if (dwFlags & PSWIZB_NEXT)
2474 /* Hide the Finish button */
2475 ShowWindow(hwndFinish, SW_HIDE);
2477 /* Show and enable the Next button */
2478 ShowWindow(hwndNext, SW_SHOW);
2479 EnableWindow(hwndNext, TRUE);
2481 /* Set the Next button as the default pushbutton */
2482 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2485 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2487 /* Hide the Next button */
2488 ShowWindow(hwndNext, SW_HIDE);
2490 /* Show the Finish button */
2491 ShowWindow(hwndFinish, SW_SHOW);
2493 if (dwFlags & PSWIZB_FINISH)
2494 EnableWindow(hwndFinish, TRUE);
2496 /* Set the Finish button as the default pushbutton */
2497 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2501 /******************************************************************************
2502 * PROPSHEET_InsertPage
2504 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2506 if (!HIWORD(hpageInsertAfter))
2507 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2508 else
2509 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2510 return FALSE;
2513 /******************************************************************************
2514 * PROPSHEET_SetHeaderTitleW
2516 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2518 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2521 /******************************************************************************
2522 * PROPSHEET_SetHeaderTitleA
2524 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2526 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2529 /******************************************************************************
2530 * PROPSHEET_SetHeaderSubTitleW
2532 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2534 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2537 /******************************************************************************
2538 * PROPSHEET_SetHeaderSubTitleA
2540 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2542 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2545 /******************************************************************************
2546 * PROPSHEET_HwndToIndex
2548 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2550 int index;
2551 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2552 PropSheetInfoStr);
2554 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2556 for (index = 0; index < psInfo->nPages; index++)
2557 if (psInfo->proppage[index].hwndPage == hPageDlg)
2558 return index;
2559 WARN("%p not found\n", hPageDlg);
2560 return -1;
2563 /******************************************************************************
2564 * PROPSHEET_IndexToHwnd
2566 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2568 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2569 PropSheetInfoStr);
2570 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2571 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2572 WARN("%d out of range.\n", iPageIndex);
2573 return 0;
2575 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2578 /******************************************************************************
2579 * PROPSHEET_PageToIndex
2581 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2583 int index;
2584 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2585 PropSheetInfoStr);
2587 TRACE("(%p, %p)\n", hwndDlg, hPage);
2589 for (index = 0; index < psInfo->nPages; index++)
2590 if (psInfo->proppage[index].hpage == hPage)
2591 return index;
2592 WARN("%p not found\n", hPage);
2593 return -1;
2596 /******************************************************************************
2597 * PROPSHEET_IndexToPage
2599 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2601 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2602 PropSheetInfoStr);
2603 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2604 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2605 WARN("%d out of range.\n", iPageIndex);
2606 return 0;
2608 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2611 /******************************************************************************
2612 * PROPSHEET_IdToIndex
2614 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2616 FIXME("(%p, %d): stub\n", hwndDlg, iPageId);
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 FIXME("(%p): stub\n", hwndDlg);
2646 return -1;
2649 /******************************************************************************
2650 * PROPSHEET_RecalcPageSizes
2652 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2654 FIXME("(%p): stub\n", hwndDlg);
2655 return FALSE;
2658 /******************************************************************************
2659 * PROPSHEET_GetPageIndex
2661 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2662 * the array of PropPageInfo.
2664 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2666 BOOL found = FALSE;
2667 int index = 0;
2669 TRACE("hpage %p\n", hpage);
2670 while ((index < psInfo->nPages) && (found == FALSE))
2672 if (psInfo->proppage[index].hpage == hpage)
2673 found = TRUE;
2674 else
2675 index++;
2678 if (found == FALSE)
2679 index = -1;
2681 return index;
2684 /******************************************************************************
2685 * PROPSHEET_CleanUp
2687 static void PROPSHEET_CleanUp(HWND hwndDlg)
2689 int i;
2690 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2691 PropSheetInfoStr);
2693 TRACE("\n");
2694 if (!psInfo) return;
2695 if (HIWORD(psInfo->ppshheader.pszCaption))
2696 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2698 for (i = 0; i < psInfo->nPages; i++)
2700 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2702 /* Unsubclass the page dialog window */
2703 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2704 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2705 (psp->dwFlags & PSP_HIDEHEADER))
2707 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2708 PROPSHEET_WizardSubclassProc, 1);
2711 if(psInfo->proppage[i].hwndPage)
2712 DestroyWindow(psInfo->proppage[i].hwndPage);
2714 if(psp)
2716 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2717 Free ((LPVOID)psInfo->proppage[i].pszText);
2719 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2723 DeleteObject(psInfo->hFont);
2724 DeleteObject(psInfo->hFontBold);
2725 /* If we created the bitmaps, destroy them */
2726 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2727 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2728 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2729 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2730 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2731 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2733 Free(psInfo->proppage);
2734 Free(psInfo->strPropertiesFor);
2735 ImageList_Destroy(psInfo->hImageList);
2737 GlobalFree((HGLOBAL)psInfo);
2740 /******************************************************************************
2741 * PropertySheet (COMCTL32.@)
2742 * PropertySheetA (COMCTL32.@)
2744 * Creates a property sheet in the specified property sheet header.
2746 * RETURNS
2747 * Modal property sheets: Positive if successful or -1 otherwise.
2748 * Modeless property sheets: Property sheet handle.
2749 * Or:
2750 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2751 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2753 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2755 int bRet = 0;
2756 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2757 sizeof(PropSheetInfo));
2758 UINT i, n;
2759 BYTE* pByte;
2761 TRACE("(%p)\n", lppsh);
2763 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2765 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2766 lppsh->nPages);
2767 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2769 for (n = i = 0; i < lppsh->nPages; i++, n++)
2771 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2772 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2773 else
2775 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2776 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2779 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2780 psInfo, n))
2782 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2783 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2784 n--;
2785 psInfo->nPages--;
2789 psInfo->unicode = FALSE;
2790 bRet = PROPSHEET_CreateDialog(psInfo);
2792 return bRet;
2795 /******************************************************************************
2796 * PropertySheetW (COMCTL32.@)
2798 * See PropertySheetA.
2800 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2802 int bRet = 0;
2803 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2804 sizeof(PropSheetInfo));
2805 UINT i, n;
2806 BYTE* pByte;
2808 TRACE("(%p)\n", lppsh);
2810 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2812 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2813 lppsh->nPages);
2814 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2816 for (n = i = 0; i < lppsh->nPages; i++, n++)
2818 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2819 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2820 else
2822 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2823 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2826 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2827 psInfo, n))
2829 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2830 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2831 n--;
2832 psInfo->nPages--;
2836 psInfo->unicode = TRUE;
2837 bRet = PROPSHEET_CreateDialog(psInfo);
2839 return bRet;
2842 /******************************************************************************
2843 * CreatePropertySheetPage (COMCTL32.@)
2844 * CreatePropertySheetPageA (COMCTL32.@)
2846 * Creates a new property sheet page.
2848 * RETURNS
2849 * Success: Handle to new property sheet page.
2850 * Failure: NULL.
2852 * NOTES
2853 * An application must use the PSM_ADDPAGE message to add the new page to
2854 * an existing property sheet.
2856 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2857 LPCPROPSHEETPAGEA lpPropSheetPage)
2859 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2861 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2863 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2864 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2866 int len = strlen(lpPropSheetPage->u.pszTemplate);
2868 ppsp->u.pszTemplate = Alloc( len+1 );
2869 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2871 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2873 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2876 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2878 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2880 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2881 ppsp->pszTitle = NULL;
2883 return (HPROPSHEETPAGE)ppsp;
2886 /******************************************************************************
2887 * CreatePropertySheetPageW (COMCTL32.@)
2889 * See CreatePropertySheetA.
2891 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2893 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2895 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2897 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2899 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2901 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2903 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2904 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2906 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2908 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2909 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2910 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2913 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2915 int len = strlenW(lpPropSheetPage->pszTitle);
2916 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2917 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2919 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2920 ppsp->pszTitle = NULL;
2922 return (HPROPSHEETPAGE)ppsp;
2925 /******************************************************************************
2926 * DestroyPropertySheetPage (COMCTL32.@)
2928 * Destroys a property sheet page previously created with
2929 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2930 * memory.
2932 * RETURNS
2933 * Success: TRUE
2934 * Failure: FALSE
2936 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2938 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2940 if (!psp)
2941 return FALSE;
2943 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2944 Free ((LPVOID)psp->u.pszTemplate);
2946 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2947 Free ((LPVOID)psp->u2.pszIcon);
2949 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2950 Free ((LPVOID)psp->pszTitle);
2952 Free(hPropPage);
2954 return TRUE;
2957 /******************************************************************************
2958 * PROPSHEET_IsDialogMessage
2960 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2962 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2964 TRACE("\n");
2965 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2966 return FALSE;
2968 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2970 int new_page = 0;
2971 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2973 if (!(dlgCode & DLGC_WANTMESSAGE))
2975 switch (lpMsg->wParam)
2977 case VK_TAB:
2978 if (GetKeyState(VK_SHIFT) & 0x8000)
2979 new_page = -1;
2980 else
2981 new_page = 1;
2982 break;
2984 case VK_NEXT: new_page = 1; break;
2985 case VK_PRIOR: new_page = -1; break;
2989 if (new_page)
2991 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2993 new_page += psInfo->active_page;
2995 if (new_page < 0)
2996 new_page = psInfo->nPages - 1;
2997 else if (new_page >= psInfo->nPages)
2998 new_page = 0;
3000 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3003 return TRUE;
3007 return IsDialogMessageW(hwnd, lpMsg);
3010 /******************************************************************************
3011 * PROPSHEET_DoCommand
3013 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3016 switch (wID) {
3018 case IDOK:
3019 case IDC_APPLY_BUTTON:
3021 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3023 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3024 break;
3026 if (wID == IDOK)
3028 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3029 PropSheetInfoStr);
3030 int result = TRUE;
3032 if (psInfo->restartWindows)
3033 result = ID_PSRESTARTWINDOWS;
3035 /* reboot system takes precedence over restart windows */
3036 if (psInfo->rebootSystem)
3037 result = ID_PSREBOOTSYSTEM;
3039 if (psInfo->isModeless)
3040 psInfo->activeValid = FALSE;
3041 else
3042 EndDialog(hwnd, result);
3044 else
3045 EnableWindow(hwndApplyBtn, FALSE);
3047 break;
3050 case IDC_BACK_BUTTON:
3051 PROPSHEET_Back(hwnd);
3052 break;
3054 case IDC_NEXT_BUTTON:
3055 PROPSHEET_Next(hwnd);
3056 break;
3058 case IDC_FINISH_BUTTON:
3059 PROPSHEET_Finish(hwnd);
3060 break;
3062 case IDCANCEL:
3063 PROPSHEET_Cancel(hwnd, 0);
3064 break;
3066 case IDHELP:
3067 PROPSHEET_Help(hwnd);
3068 break;
3070 default:
3071 return FALSE;
3074 return TRUE;
3077 /******************************************************************************
3078 * PROPSHEET_Paint
3080 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3082 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3083 PAINTSTRUCT ps;
3084 HDC hdc, hdcSrc;
3085 BITMAP bm;
3086 HBITMAP hbmp;
3087 HPALETTE hOldPal = 0;
3088 int offsety = 0;
3089 HBRUSH hbr;
3090 RECT r, rzone;
3091 LPCPROPSHEETPAGEW ppshpage;
3092 WCHAR szBuffer[256];
3093 int nLength;
3095 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3096 if (!hdc) return 1;
3098 hdcSrc = CreateCompatibleDC(0);
3099 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3101 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3102 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3104 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3105 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3106 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3108 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3109 HFONT hOldFont;
3110 COLORREF clrOld = 0;
3111 int oldBkMode = 0;
3113 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3114 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3116 GetClientRect(hwndLineHeader, &r);
3117 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3118 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3120 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3122 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3124 /* Fill the unoccupied part of the header with color of the
3125 * left-top pixel, but do it only when needed.
3127 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3129 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3130 CopyRect(&r, &rzone);
3131 if (bm.bmWidth < r.right)
3133 r.left = bm.bmWidth;
3134 FillRect(hdc, &r, hbr);
3136 if (bm.bmHeight < r.bottom)
3138 r.left = 0;
3139 r.top = bm.bmHeight;
3140 FillRect(hdc, &r, hbr);
3142 DeleteObject(hbr);
3145 /* Draw the header itself. */
3146 BitBlt(hdc, 0, 0,
3147 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3148 hdcSrc, 0, 0, SRCCOPY);
3150 else
3152 hbr = GetSysColorBrush(COLOR_WINDOW);
3153 FillRect(hdc, &rzone, hbr);
3155 /* Draw the header bitmap. It's always centered like a
3156 * common 49 x 49 bitmap. */
3157 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3158 (rzone.bottom - 49) / 2,
3159 bm.bmWidth, bm.bmHeight,
3160 hdcSrc, 0, 0, SRCCOPY);
3162 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3163 * if its height is smaller than 49 pixels. Because the reason
3164 * for this bug is unknown the current code doesn't try to
3165 * replicate it. */
3168 clrOld = SetTextColor (hdc, 0x00000000);
3169 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3171 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3172 SetRect(&r, 20, 10, 0, 0);
3173 if (HIWORD(ppshpage->pszHeaderTitle))
3175 if (psInfo->unicode)
3176 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3177 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3178 else
3179 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3180 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3182 else
3184 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderTitle,
3185 szBuffer, 256);
3186 if (nLength != 0)
3188 DrawTextW(hdc, szBuffer, nLength,
3189 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3194 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3195 SelectObject(hdc, psInfo->hFont);
3196 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3197 if (HIWORD(ppshpage->pszHeaderTitle))
3199 if (psInfo->unicode)
3200 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3201 -1, &r, DT_LEFT | DT_SINGLELINE);
3202 else
3203 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3204 -1, &r, DT_LEFT | DT_SINGLELINE);
3206 else
3208 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderSubTitle,
3209 szBuffer, 256);
3210 if (nLength != 0)
3212 DrawTextW(hdc, szBuffer, nLength,
3213 &r, DT_LEFT | DT_SINGLELINE);
3218 offsety = rzone.bottom + 2;
3220 SetTextColor(hdc, clrOld);
3221 SetBkMode(hdc, oldBkMode);
3222 SelectObject(hdc, hOldFont);
3223 SelectObject(hdcSrc, hbmp);
3226 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3227 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3228 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3230 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3232 GetClientRect(hwndLine, &r);
3233 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3235 rzone.left = 0;
3236 rzone.top = 0;
3237 rzone.right = r.right;
3238 rzone.bottom = r.top - 1;
3240 hbr = GetSysColorBrush(COLOR_WINDOW);
3241 FillRect(hdc, &rzone, hbr);
3243 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3244 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3246 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3247 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3249 /* If the bitmap is not big enough, fill the remaining area
3250 with the color of pixel (0,0) of bitmap - see MSDN */
3251 if (r.top > bm.bmHeight) {
3252 r.bottom = r.top - 1;
3253 r.top = bm.bmHeight;
3254 r.left = 0;
3255 r.right = bm.bmWidth;
3256 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3257 FillRect(hdc, &r, hbr);
3258 DeleteObject(hbr);
3261 SelectObject(hdcSrc, hbmp);
3264 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3265 SelectPalette(hdc, hOldPal, FALSE);
3267 DeleteDC(hdcSrc);
3269 if (!hdcParam) EndPaint(hwnd, &ps);
3271 return 0;
3274 /******************************************************************************
3275 * PROPSHEET_DialogProc
3277 INT_PTR CALLBACK
3278 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3280 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3281 hwnd, uMsg, wParam, lParam);
3283 switch (uMsg)
3285 case WM_INITDIALOG:
3287 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3288 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3289 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3290 LPCPROPSHEETPAGEW ppshpage;
3291 int idx;
3292 LOGFONTW logFont;
3294 /* Using PropSheetInfoStr to store extra data doesn't match the native
3295 * common control: native uses TCM_[GS]ETITEM
3297 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3300 * psInfo->hwnd is not being used by WINE code - it exists
3301 * for compatibility with "real" Windoze. The same about
3302 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3303 * property.
3305 psInfo->hwnd = hwnd;
3306 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3308 /* set up the Next and Back buttons by default */
3309 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3311 /* Set up fonts */
3312 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3313 psInfo->hFont = CreateFontIndirectW (&logFont);
3314 logFont.lfWeight = FW_BOLD;
3315 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3318 * Small icon in the title bar.
3320 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3321 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3323 HICON hIcon;
3324 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3325 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3327 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3328 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3329 psInfo->ppshheader.u.pszIcon,
3330 IMAGE_ICON,
3331 icon_cx, icon_cy,
3332 LR_DEFAULTCOLOR);
3333 else
3334 hIcon = psInfo->ppshheader.u.hIcon;
3336 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3339 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3340 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3342 psInfo->strPropertiesFor = strCaption;
3344 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3346 PROPSHEET_CreateTabControl(hwnd, psInfo);
3348 PROPSHEET_LoadWizardBitmaps(psInfo);
3350 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3352 ShowWindow(hwndTabCtrl, SW_HIDE);
3353 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3354 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3356 else
3358 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3360 PROPSHEET_AdjustSize(hwnd, psInfo);
3361 PROPSHEET_AdjustButtons(hwnd, psInfo);
3365 if (psInfo->useCallback)
3366 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3367 PSCB_INITIALIZED, (LPARAM)0);
3369 idx = psInfo->active_page;
3370 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3371 psInfo->active_page = -1;
3373 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3375 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3376 * as some programs call TCM_GETCURSEL to get the current selection
3377 * from which to switch to the next page */
3378 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3380 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3381 psInfo->ppshheader.hInstance)
3383 WCHAR szText[256];
3385 if (LoadStringW(psInfo->ppshheader.hInstance,
3386 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3387 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3389 else
3391 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3392 psInfo->ppshheader.pszCaption);
3395 return TRUE;
3398 case WM_PAINT:
3399 PROPSHEET_Paint(hwnd, (HDC)wParam);
3400 return TRUE;
3402 case WM_DESTROY:
3403 PROPSHEET_CleanUp(hwnd);
3404 return TRUE;
3406 case WM_CLOSE:
3407 PROPSHEET_Cancel(hwnd, 1);
3408 return TRUE;
3410 case WM_COMMAND:
3411 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3413 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3415 if (!psInfo)
3416 return FALSE;
3418 /* No default handler, forward notification to active page */
3419 if (psInfo->activeValid && psInfo->active_page != -1)
3421 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3422 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3425 return TRUE;
3427 case WM_NOTIFY:
3429 NMHDR* pnmh = (LPNMHDR) lParam;
3431 if (pnmh->code == TCN_SELCHANGE)
3433 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3434 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3437 if(pnmh->code == TCN_SELCHANGING)
3439 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3440 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3441 return TRUE;
3444 return FALSE;
3447 case PSM_GETCURRENTPAGEHWND:
3449 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3450 PropSheetInfoStr);
3451 HWND hwndPage = 0;
3453 if (!psInfo)
3454 return FALSE;
3456 if (psInfo->activeValid && psInfo->active_page != -1)
3457 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3459 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3461 return TRUE;
3464 case PSM_CHANGED:
3465 PROPSHEET_Changed(hwnd, (HWND)wParam);
3466 return TRUE;
3468 case PSM_UNCHANGED:
3469 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3470 return TRUE;
3472 case PSM_GETTABCONTROL:
3474 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3476 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3478 return TRUE;
3481 case PSM_SETCURSEL:
3483 BOOL msgResult;
3485 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3486 if(msgResult != FALSE)
3488 msgResult = PROPSHEET_SetCurSel(hwnd,
3489 (int)wParam,
3491 (HPROPSHEETPAGE)lParam);
3494 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3496 return TRUE;
3499 case PSM_CANCELTOCLOSE:
3501 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3502 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3503 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3505 EnableWindow(hwndCancel, FALSE);
3506 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3507 SetWindowTextW(hwndOK, buf);
3509 return FALSE;
3512 case PSM_RESTARTWINDOWS:
3514 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3515 PropSheetInfoStr);
3517 if (!psInfo)
3518 return FALSE;
3520 psInfo->restartWindows = TRUE;
3521 return TRUE;
3524 case PSM_REBOOTSYSTEM:
3526 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3527 PropSheetInfoStr);
3529 if (!psInfo)
3530 return FALSE;
3532 psInfo->rebootSystem = TRUE;
3533 return TRUE;
3536 case PSM_SETTITLEA:
3537 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3538 return TRUE;
3540 case PSM_SETTITLEW:
3541 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3542 return TRUE;
3544 case PSM_APPLY:
3546 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3548 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3550 return TRUE;
3553 case PSM_QUERYSIBLINGS:
3555 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3557 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3559 return TRUE;
3562 case PSM_ADDPAGE:
3565 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3566 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3567 * on success or FALSE otherwise, as specified on MSDN Online.
3568 * Also see the MFC code for
3569 * CPropertySheet::AddPage(CPropertyPage* pPage).
3572 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3574 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3576 return TRUE;
3579 case PSM_REMOVEPAGE:
3580 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3581 return TRUE;
3583 case PSM_ISDIALOGMESSAGE:
3585 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3586 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3587 return TRUE;
3590 case PSM_PRESSBUTTON:
3591 PROPSHEET_PressButton(hwnd, (int)wParam);
3592 return TRUE;
3594 case PSM_SETFINISHTEXTA:
3595 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3596 return TRUE;
3598 case PSM_SETWIZBUTTONS:
3599 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3600 return TRUE;
3602 case PSM_SETCURSELID:
3603 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3604 return TRUE;
3606 case PSM_SETFINISHTEXTW:
3607 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3608 return FALSE;
3610 case PSM_INSERTPAGE:
3612 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3613 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3614 return TRUE;
3617 case PSM_SETHEADERTITLEW:
3618 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3619 return TRUE;
3621 case PSM_SETHEADERTITLEA:
3622 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3623 return TRUE;
3625 case PSM_SETHEADERSUBTITLEW:
3626 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3627 return TRUE;
3629 case PSM_SETHEADERSUBTITLEA:
3630 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3631 return TRUE;
3633 case PSM_HWNDTOINDEX:
3635 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3636 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3637 return TRUE;
3640 case PSM_INDEXTOHWND:
3642 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3643 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3644 return TRUE;
3647 case PSM_PAGETOINDEX:
3649 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3650 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3651 return TRUE;
3654 case PSM_INDEXTOPAGE:
3656 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3657 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3658 return TRUE;
3661 case PSM_IDTOINDEX:
3663 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3664 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3665 return TRUE;
3668 case PSM_INDEXTOID:
3670 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3671 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3672 return TRUE;
3675 case PSM_GETRESULT:
3677 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3678 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3679 return TRUE;
3682 case PSM_RECALCPAGESIZES:
3684 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3685 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3686 return TRUE;
3689 default:
3690 return FALSE;