shdocvw: Add class definition for InternetExplorer.
[wine/multimedia.git] / dlls / comctl32 / propsheet.c
blob78fdc430a1da52cd7af745e815e30d51a03b5a8e
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_INSERTPAGE
37 * o PSM_RECALCPAGESIZES
38 * o PSM_SETHEADERSUBTITLE
39 * o PSM_SETHEADERTITLE
40 * o WM_HELP
41 * o WM_CONTEXTMENU
42 * - Notifications:
43 * o PSN_GETOBJECT
44 * o PSN_QUERYINITIALFOCUS
45 * o PSN_TRANSLATEACCELERATOR
46 * - Styles:
47 * o PSH_RTLREADING
48 * o PSH_STRETCHWATERMARK
49 * o PSH_USEPAGELANG
50 * o PSH_USEPSTARTPAGE
51 * - Page styles:
52 * o PSP_USEFUSIONCONTEXT
53 * o PSP_USEREFPARENT
56 #include <stdarg.h>
57 #include <string.h>
59 #define NONAMELESSUNION
60 #define NONAMELESSSTRUCT
61 #include "windef.h"
62 #include "winbase.h"
63 #include "wingdi.h"
64 #include "winuser.h"
65 #include "winnls.h"
66 #include "commctrl.h"
67 #include "prsht.h"
68 #include "comctl32.h"
69 #include "uxtheme.h"
71 #include "wine/debug.h"
72 #include "wine/unicode.h"
74 /******************************************************************************
75 * Data structures
77 #include "pshpack2.h"
79 typedef struct
81 WORD dlgVer;
82 WORD signature;
83 DWORD helpID;
84 DWORD exStyle;
85 DWORD style;
86 } MyDLGTEMPLATEEX;
88 typedef struct
90 DWORD helpid;
91 DWORD exStyle;
92 DWORD style;
93 short x;
94 short y;
95 short cx;
96 short cy;
97 DWORD id;
98 } MyDLGITEMTEMPLATEEX;
99 #include "poppack.h"
101 typedef struct tagPropPageInfo
103 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
104 HWND hwndPage;
105 BOOL isDirty;
106 LPCWSTR pszText;
107 BOOL hasHelp;
108 BOOL useCallback;
109 BOOL hasIcon;
110 } PropPageInfo;
112 typedef struct tagPropSheetInfo
114 HWND hwnd;
115 PROPSHEETHEADERW ppshheader;
116 BOOL unicode;
117 LPWSTR strPropertiesFor;
118 int nPages;
119 int active_page;
120 BOOL isModeless;
121 BOOL hasHelp;
122 BOOL hasApply;
123 BOOL hasFinish;
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 BOOL ended;
135 } PropSheetInfo;
137 typedef struct
139 int x;
140 int y;
141 } PADDING_INFO;
143 /******************************************************************************
144 * Defines and global variables
147 const WCHAR PropSheetInfoStr[] =
148 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
150 #define PSP_INTERNAL_UNICODE 0x80000000
152 #define MAX_CAPTION_LENGTH 255
153 #define MAX_TABTEXT_LENGTH 255
154 #define MAX_BUTTONTEXT_LENGTH 64
156 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
158 /* Wizard metrics specified in DLUs */
159 #define WIZARD_PADDING 7
160 #define WIZARD_HEADER_HEIGHT 36
162 /******************************************************************************
163 * Prototypes
165 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
166 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
167 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
169 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
170 PropSheetInfo * psInfo);
171 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
172 PropSheetInfo * psInfo);
173 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
174 PropSheetInfo * psInfo,
175 int index);
176 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
177 PropSheetInfo * psInfo);
178 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
179 const PropSheetInfo * psInfo,
180 LPCPROPSHEETPAGEW ppshpage);
181 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
182 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
183 static BOOL PROPSHEET_Back(HWND hwndDlg);
184 static BOOL PROPSHEET_Next(HWND hwndDlg);
185 static BOOL PROPSHEET_Finish(HWND hwndDlg);
186 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
187 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
188 static void PROPSHEET_Help(HWND hwndDlg);
189 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
190 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
191 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
192 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
193 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
194 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
195 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
196 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
197 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
198 int index,
199 int skipdir,
200 HPROPSHEETPAGE hpage);
201 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
202 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
203 WPARAM wParam, LPARAM lParam);
204 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
205 HPROPSHEETPAGE hpage);
207 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
208 int index,
209 HPROPSHEETPAGE hpage);
210 static void PROPSHEET_CleanUp(HWND hwndDlg);
211 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
212 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
213 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
214 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
215 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
217 INT_PTR CALLBACK
218 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
220 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
222 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
223 /******************************************************************************
224 * PROPSHEET_UnImplementedFlags
226 * Document use of flags we don't implement yet.
228 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
230 CHAR string[256];
232 string[0] = '\0';
235 * unhandled header flags:
236 * PSH_RTLREADING 0x00000800
237 * PSH_STRETCHWATERMARK 0x00040000
238 * PSH_USEPAGELANG 0x00200000
241 add_flag(PSH_RTLREADING);
242 add_flag(PSH_STRETCHWATERMARK);
243 add_flag(PSH_USEPAGELANG);
244 if (string[0] != '\0')
245 FIXME("%s\n", string);
247 #undef add_flag
249 /******************************************************************************
250 * PROPSHEET_GetPageRect
252 * Retrieve rect from tab control and map into the dialog for SetWindowPos
254 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
255 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
257 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
258 HWND hwndChild;
259 RECT r;
261 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
262 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
263 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
264 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
266 rc->left = rc->top = WIZARD_PADDING;
268 else
270 rc->left = rc->top = 0;
272 rc->right = psInfo->width - rc->left;
273 rc->bottom = psInfo->height - rc->top;
274 MapDialogRect(hwndDlg, rc);
276 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
277 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
278 !(ppshpage->dwFlags & PSP_HIDEHEADER))
280 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
281 GetClientRect(hwndChild, &r);
282 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
283 rc->top += r.bottom + 1;
285 } else {
286 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
287 GetClientRect(hwndTabCtrl, rc);
288 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
289 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
293 /******************************************************************************
294 * PROPSHEET_FindPageByResId
296 * Find page index corresponding to page resource id.
298 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
300 INT i;
302 for (i = 0; i < psInfo->nPages; i++)
304 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
306 /* Fixme: if resource ID is a string shall we use strcmp ??? */
307 if (lppsp->u.pszTemplate == (LPVOID)resId)
308 break;
311 return i;
314 /******************************************************************************
315 * PROPSHEET_AtoW
317 * Convert ASCII to Unicode since all data is saved as Unicode.
319 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
321 INT len;
323 TRACE("<%s>\n", frstr);
324 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
325 *tostr = Alloc(len * sizeof(WCHAR));
326 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
329 /******************************************************************************
330 * PROPSHEET_CollectSheetInfoA
332 * Collect relevant data.
334 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
335 PropSheetInfo * psInfo)
337 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
338 DWORD dwFlags = lppsh->dwFlags;
340 psInfo->hasHelp = dwFlags & PSH_HASHELP;
341 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
342 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
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->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
399 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
400 psInfo->isModeless = dwFlags & PSH_MODELESS;
402 memcpy(&psInfo->ppshheader,lppsh,dwSize);
403 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",
404 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
406 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
408 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
409 psInfo->ppshheader.pszCaption = NULL;
410 else
412 if (HIWORD(lppsh->pszCaption))
414 int len = strlenW(lppsh->pszCaption);
415 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
416 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
419 psInfo->nPages = lppsh->nPages;
421 if (dwFlags & PSH_USEPSTARTPAGE)
423 TRACE("PSH_USEPSTARTPAGE is on\n");
424 psInfo->active_page = 0;
426 else
427 psInfo->active_page = lppsh->u2.nStartPage;
429 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
430 psInfo->active_page = 0;
432 psInfo->restartWindows = FALSE;
433 psInfo->rebootSystem = FALSE;
434 psInfo->hImageList = 0;
435 psInfo->activeValid = FALSE;
437 return TRUE;
440 /******************************************************************************
441 * PROPSHEET_CollectPageInfo
443 * Collect property sheet data.
444 * With code taken from DIALOG_ParseTemplate32.
446 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
447 PropSheetInfo * psInfo,
448 int index)
450 DLGTEMPLATE* pTemplate;
451 const WORD* p;
452 DWORD dwFlags;
453 int width, height;
455 if (!lppsp)
456 return FALSE;
458 TRACE("\n");
459 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
460 psInfo->proppage[index].hwndPage = 0;
461 psInfo->proppage[index].isDirty = FALSE;
464 * Process property page flags.
466 dwFlags = lppsp->dwFlags;
467 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
468 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
469 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
471 /* as soon as we have a page with the help flag, set the sheet flag on */
472 if (psInfo->proppage[index].hasHelp)
473 psInfo->hasHelp = TRUE;
476 * Process page template.
478 if (dwFlags & PSP_DLGINDIRECT)
479 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
480 else if(dwFlags & PSP_INTERNAL_UNICODE )
482 HRSRC hResource = FindResourceW(lppsp->hInstance,
483 lppsp->u.pszTemplate,
484 (LPWSTR)RT_DIALOG);
485 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
486 hResource);
487 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
489 else
491 HRSRC hResource = FindResourceA(lppsp->hInstance,
492 (LPSTR)lppsp->u.pszTemplate,
493 (LPSTR)RT_DIALOG);
494 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
495 hResource);
496 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
500 * Extract the size of the page and the caption.
502 if (!pTemplate)
503 return FALSE;
505 p = (const WORD *)pTemplate;
507 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
509 /* DLGTEMPLATEEX (not defined in any std. header file) */
511 p++; /* dlgVer */
512 p++; /* signature */
513 p += 2; /* help ID */
514 p += 2; /* ext style */
515 p += 2; /* style */
517 else
519 /* DLGTEMPLATE */
521 p += 2; /* style */
522 p += 2; /* ext style */
525 p++; /* nb items */
526 p++; /* x */
527 p++; /* y */
528 width = (WORD)*p; p++;
529 height = (WORD)*p; p++;
531 /* Special calculation for interior wizard pages so the largest page is
532 * calculated correctly. We need to add all the padding and space occupied
533 * by the header so the width and height sums up to the whole wizard client
534 * area. */
535 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
536 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
537 !(dwFlags & PSP_HIDEHEADER))
539 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
540 width += 2 * WIZARD_PADDING;
542 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
544 height += 2 * WIZARD_PADDING;
545 width += 2 * WIZARD_PADDING;
548 /* remember the largest width and height */
549 if (width > psInfo->width)
550 psInfo->width = width;
552 if (height > psInfo->height)
553 psInfo->height = height;
555 /* menu */
556 switch ((WORD)*p)
558 case 0x0000:
559 p++;
560 break;
561 case 0xffff:
562 p += 2;
563 break;
564 default:
565 p += lstrlenW( (LPCWSTR)p ) + 1;
566 break;
569 /* class */
570 switch ((WORD)*p)
572 case 0x0000:
573 p++;
574 break;
575 case 0xffff:
576 p += 2;
577 break;
578 default:
579 p += lstrlenW( (LPCWSTR)p ) + 1;
580 break;
583 /* Extract the caption */
584 psInfo->proppage[index].pszText = (LPCWSTR)p;
585 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
586 p += lstrlenW((LPCWSTR)p) + 1;
588 if (dwFlags & PSP_USETITLE)
590 WCHAR szTitle[256];
591 const WCHAR *pTitle;
592 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
593 int len;
595 if ( !HIWORD( lppsp->pszTitle ) )
597 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
599 pTitle = pszNull;
600 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
602 else
603 pTitle = szTitle;
605 else
606 pTitle = lppsp->pszTitle;
608 len = strlenW(pTitle);
609 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
610 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
614 * Build the image list for icons
616 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
618 HICON hIcon;
619 int icon_cx = GetSystemMetrics(SM_CXSMICON);
620 int icon_cy = GetSystemMetrics(SM_CYSMICON);
622 if (dwFlags & PSP_USEICONID)
623 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
624 icon_cx, icon_cy, LR_DEFAULTCOLOR);
625 else
626 hIcon = lppsp->u2.hIcon;
628 if ( hIcon )
630 if (psInfo->hImageList == 0 )
631 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
633 ImageList_AddIcon(psInfo->hImageList, hIcon);
638 return TRUE;
641 /******************************************************************************
642 * PROPSHEET_CreateDialog
644 * Creates the actual property sheet.
646 INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
648 LRESULT ret;
649 LPCVOID template;
650 LPVOID temp = 0;
651 HRSRC hRes;
652 DWORD resSize;
653 WORD resID = IDD_PROPSHEET;
655 TRACE("\n");
656 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
657 resID = IDD_WIZARD;
659 if( psInfo->unicode )
661 if(!(hRes = FindResourceW(COMCTL32_hModule,
662 MAKEINTRESOURCEW(resID),
663 (LPWSTR)RT_DIALOG)))
664 return -1;
666 else
668 if(!(hRes = FindResourceA(COMCTL32_hModule,
669 MAKEINTRESOURCEA(resID),
670 (LPSTR)RT_DIALOG)))
671 return -1;
674 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
675 return -1;
678 * Make a copy of the dialog template.
680 resSize = SizeofResource(COMCTL32_hModule, hRes);
682 temp = Alloc(resSize);
684 if (!temp)
685 return -1;
687 memcpy(temp, template, resSize);
689 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
691 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
692 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
693 else
694 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
696 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
697 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
699 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
700 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
701 else
702 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
705 if (psInfo->useCallback)
706 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
708 /* NOTE: MSDN states "Returns a positive value if successful, or -1
709 * otherwise for modal property sheets.", but this is wrong. The
710 * actual return value is either TRUE (success), FALSE (cancel) or
711 * -1 (error). */
712 if( psInfo->unicode )
714 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
715 (LPDLGTEMPLATEW) temp,
716 psInfo->ppshheader.hwndParent,
717 PROPSHEET_DialogProc,
718 (LPARAM)psInfo);
719 if ( !ret ) ret = -1;
721 else
723 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
724 (LPDLGTEMPLATEA) temp,
725 psInfo->ppshheader.hwndParent,
726 PROPSHEET_DialogProc,
727 (LPARAM)psInfo);
728 if ( !ret ) ret = -1;
731 Free(temp);
733 return ret;
736 /******************************************************************************
737 * PROPSHEET_SizeMismatch
739 * Verify that the tab control and the "largest" property sheet page dlg. template
740 * match in size.
742 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
744 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
745 RECT rcOrigTab, rcPage;
748 * Original tab size.
750 GetClientRect(hwndTabCtrl, &rcOrigTab);
751 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
752 rcOrigTab.right, rcOrigTab.bottom);
755 * Biggest page size.
757 rcPage.left = 0;
758 rcPage.top = 0;
759 rcPage.right = psInfo->width;
760 rcPage.bottom = psInfo->height;
762 MapDialogRect(hwndDlg, &rcPage);
763 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
764 rcPage.right, rcPage.bottom);
766 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
767 return TRUE;
768 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
769 return TRUE;
771 return FALSE;
774 /******************************************************************************
775 * PROPSHEET_AdjustSize
777 * Resizes the property sheet and the tab control to fit the largest page.
779 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
781 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
782 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
783 RECT rc,tabRect;
784 int tabOffsetX, tabOffsetY, buttonHeight;
785 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
786 RECT units;
788 /* Get the height of buttons */
789 GetClientRect(hwndButton, &rc);
790 buttonHeight = rc.bottom;
793 * Biggest page size.
795 rc.left = 0;
796 rc.top = 0;
797 rc.right = psInfo->width;
798 rc.bottom = psInfo->height;
800 MapDialogRect(hwndDlg, &rc);
802 /* retrieve the dialog units */
803 units.left = units.right = 4;
804 units.top = units.bottom = 8;
805 MapDialogRect(hwndDlg, &units);
808 * Resize the tab control.
810 GetClientRect(hwndTabCtrl,&tabRect);
812 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
814 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
816 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
817 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
820 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
822 rc.right = rc.left + tabRect.right - tabRect.left;
823 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
826 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
828 tabOffsetX = -(rc.left);
829 tabOffsetY = -(rc.top);
831 rc.right -= rc.left;
832 rc.bottom -= rc.top;
833 TRACE("setting tab %p, rc (0,0)-(%ld,%ld)\n",
834 hwndTabCtrl, rc.right, rc.bottom);
835 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
836 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
838 GetClientRect(hwndTabCtrl, &rc);
840 TRACE("tab client rc %ld %ld %ld %ld\n",
841 rc.left, rc.top, rc.right, rc.bottom);
843 rc.right += ((padding.x * 2) + tabOffsetX);
844 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
847 * Resize the property sheet.
849 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
850 hwndDlg, rc.right, rc.bottom);
851 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
852 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
853 return TRUE;
856 /******************************************************************************
857 * PROPSHEET_AdjustSizeWizard
859 * Resizes the property sheet to fit the largest page.
861 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
863 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
864 RECT rc, lineRect, dialogRect;
866 /* Biggest page size */
867 rc.left = 0;
868 rc.top = 0;
869 rc.right = psInfo->width;
870 rc.bottom = psInfo->height;
871 MapDialogRect(hwndDlg, &rc);
873 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
875 /* Add space for the buttons row */
876 GetWindowRect(hwndLine, &lineRect);
877 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
878 GetClientRect(hwndDlg, &dialogRect);
879 rc.bottom += dialogRect.bottom - lineRect.top - 1;
881 /* Convert the client coordinates to window coordinates */
882 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
884 /* Resize the property sheet */
885 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
886 hwndDlg, rc.right, rc.bottom);
887 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
888 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
890 return TRUE;
893 /******************************************************************************
894 * PROPSHEET_AdjustButtons
896 * Adjusts the buttons' positions.
898 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
900 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
901 RECT rcSheet;
902 int x, y;
903 int num_buttons = 2;
904 int buttonWidth, buttonHeight;
905 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
907 if (psInfo->hasApply)
908 num_buttons++;
910 if (psInfo->hasHelp)
911 num_buttons++;
914 * Obtain the size of the buttons.
916 GetClientRect(hwndButton, &rcSheet);
917 buttonWidth = rcSheet.right;
918 buttonHeight = rcSheet.bottom;
921 * Get the size of the property sheet.
923 GetClientRect(hwndParent, &rcSheet);
926 * All buttons will be at this y coordinate.
928 y = rcSheet.bottom - (padding.y + buttonHeight);
931 * Position OK button and make it default.
933 hwndButton = GetDlgItem(hwndParent, IDOK);
935 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
937 SetWindowPos(hwndButton, 0, x, y, 0, 0,
938 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
940 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
944 * Position Cancel button.
946 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
948 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
950 SetWindowPos(hwndButton, 0, x, y, 0, 0,
951 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
954 * Position Apply button.
956 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
958 if (psInfo->hasApply)
960 if (psInfo->hasHelp)
961 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
962 else
963 x = rcSheet.right - (padding.x + buttonWidth);
965 SetWindowPos(hwndButton, 0, x, y, 0, 0,
966 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968 EnableWindow(hwndButton, FALSE);
970 else
971 ShowWindow(hwndButton, SW_HIDE);
974 * Position Help button.
976 hwndButton = GetDlgItem(hwndParent, IDHELP);
978 if (psInfo->hasHelp)
980 x = rcSheet.right - (padding.x + buttonWidth);
982 SetWindowPos(hwndButton, 0, x, y, 0, 0,
983 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
985 else
986 ShowWindow(hwndButton, SW_HIDE);
988 return TRUE;
991 /******************************************************************************
992 * PROPSHEET_AdjustButtonsWizard
994 * Adjusts the buttons' positions.
996 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
997 PropSheetInfo* psInfo)
999 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1000 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1001 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1002 RECT rcSheet;
1003 int x, y;
1004 int num_buttons = 3;
1005 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1006 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1008 if (psInfo->hasHelp)
1009 num_buttons++;
1010 if (psInfo->hasFinish)
1011 num_buttons++;
1014 * Obtain the size of the buttons.
1016 GetClientRect(hwndButton, &rcSheet);
1017 buttonWidth = rcSheet.right;
1018 buttonHeight = rcSheet.bottom;
1020 GetClientRect(hwndLine, &rcSheet);
1021 lineHeight = rcSheet.bottom;
1024 * Get the size of the property sheet.
1026 GetClientRect(hwndParent, &rcSheet);
1029 * All buttons will be at this y coordinate.
1031 y = rcSheet.bottom - (padding.y + buttonHeight);
1034 * Position the Back button.
1036 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1038 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1040 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1041 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1044 * Position the Next button.
1046 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1048 x += buttonWidth;
1050 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1051 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1054 * Position the Finish button.
1056 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1058 if (psInfo->hasFinish)
1059 x += padding.x + buttonWidth;
1061 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1062 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1064 if (!psInfo->hasFinish)
1065 ShowWindow(hwndButton, SW_HIDE);
1068 * Position the Cancel button.
1070 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1072 x += padding.x + buttonWidth;
1074 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1075 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1078 * Position Help button.
1080 hwndButton = GetDlgItem(hwndParent, IDHELP);
1082 if (psInfo->hasHelp)
1084 x += padding.x + buttonWidth;
1086 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1087 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1089 else
1090 ShowWindow(hwndButton, SW_HIDE);
1092 if (psInfo->ppshheader.dwFlags &
1093 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1094 padding.x = 0;
1097 * Position and resize the sunken line.
1099 x = padding.x;
1100 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1102 lineWidth = rcSheet.right - (padding.x * 2);
1103 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1104 SWP_NOZORDER | SWP_NOACTIVATE);
1107 * Position and resize the header sunken line.
1110 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1111 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1112 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1113 ShowWindow(hwndLineHeader, SW_HIDE);
1115 return TRUE;
1118 /******************************************************************************
1119 * PROPSHEET_GetPaddingInfo
1121 * Returns the layout information.
1123 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1125 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1126 RECT rcTab;
1127 POINT tl;
1128 PADDING_INFO padding;
1130 GetWindowRect(hwndTab, &rcTab);
1132 tl.x = rcTab.left;
1133 tl.y = rcTab.top;
1135 ScreenToClient(hwndDlg, &tl);
1137 padding.x = tl.x;
1138 padding.y = tl.y;
1140 return padding;
1143 /******************************************************************************
1144 * PROPSHEET_GetPaddingInfoWizard
1146 * Returns the layout information.
1147 * Vertical spacing is the distance between the line and the buttons.
1148 * Do NOT use the Help button to gather padding information when it isn't mapped
1149 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1150 * for it in this case !
1151 * FIXME: I'm not sure about any other coordinate problems with these evil
1152 * buttons. Fix it in case additional problems appear or maybe calculate
1153 * a padding in a completely different way, as this is somewhat messy.
1155 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1156 psInfo)
1158 PADDING_INFO padding;
1159 RECT rc;
1160 HWND hwndControl;
1161 INT idButton;
1162 POINT ptButton, ptLine;
1164 TRACE("\n");
1165 if (psInfo->hasHelp)
1167 idButton = IDHELP;
1169 else
1171 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1173 idButton = IDC_NEXT_BUTTON;
1175 else
1177 /* hopefully this is ok */
1178 idButton = IDCANCEL;
1182 hwndControl = GetDlgItem(hwndDlg, idButton);
1183 GetWindowRect(hwndControl, &rc);
1185 ptButton.x = rc.left;
1186 ptButton.y = rc.top;
1188 ScreenToClient(hwndDlg, &ptButton);
1190 /* Line */
1191 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1192 GetWindowRect(hwndControl, &rc);
1194 ptLine.x = rc.left;
1195 ptLine.y = rc.bottom;
1197 ScreenToClient(hwndDlg, &ptLine);
1199 padding.y = ptButton.y - ptLine.y;
1201 if (padding.y < 0)
1202 ERR("padding negative ! Please report this !\n");
1204 /* this is most probably not correct, but the best we have now */
1205 padding.x = padding.y;
1206 return padding;
1209 /******************************************************************************
1210 * PROPSHEET_CreateTabControl
1212 * Insert the tabs in the tab control.
1214 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1215 PropSheetInfo * psInfo)
1217 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1218 TCITEMW item;
1219 int i, nTabs;
1220 int iImage = 0;
1222 TRACE("\n");
1223 item.mask = TCIF_TEXT;
1224 item.cchTextMax = MAX_TABTEXT_LENGTH;
1226 nTabs = psInfo->nPages;
1229 * Set the image list for icons.
1231 if (psInfo->hImageList)
1233 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1236 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1237 for (i = 0; i < nTabs; i++)
1239 if ( psInfo->proppage[i].hasIcon )
1241 item.mask |= TCIF_IMAGE;
1242 item.iImage = iImage++;
1244 else
1246 item.mask &= ~TCIF_IMAGE;
1249 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1250 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1252 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1254 return TRUE;
1257 /******************************************************************************
1258 * PROPSHEET_WizardSubclassProc
1260 * Subclassing window procedure for wizard extrior pages to prevent drawing
1261 * background and so drawing above the watermark.
1263 static LRESULT CALLBACK
1264 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1266 switch (uMsg)
1268 case WM_ERASEBKGND:
1269 return TRUE;
1271 case WM_CTLCOLORSTATIC:
1272 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1273 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1276 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1280 * Get the size of an in-memory Template
1282 *( Based on the code of PROPSHEET_CollectPageInfo)
1283 * See also dialog.c/DIALOG_ParseTemplate32().
1286 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1289 const WORD* p = (const WORD *)pTemplate;
1290 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1291 WORD nrofitems;
1293 if (istemplateex)
1295 /* DLGTEMPLATEEX (not defined in any std. header file) */
1297 TRACE("is DLGTEMPLATEEX\n");
1298 p++; /* dlgVer */
1299 p++; /* signature */
1300 p += 2; /* help ID */
1301 p += 2; /* ext style */
1302 p += 2; /* style */
1304 else
1306 /* DLGTEMPLATE */
1308 TRACE("is DLGTEMPLATE\n");
1309 p += 2; /* style */
1310 p += 2; /* ext style */
1313 nrofitems = (WORD)*p; p++; /* nb items */
1314 p++; /* x */
1315 p++; /* y */
1316 p++; /* width */
1317 p++; /* height */
1319 /* menu */
1320 switch ((WORD)*p)
1322 case 0x0000:
1323 p++;
1324 break;
1325 case 0xffff:
1326 p += 2;
1327 break;
1328 default:
1329 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1330 p += lstrlenW( (LPCWSTR)p ) + 1;
1331 break;
1334 /* class */
1335 switch ((WORD)*p)
1337 case 0x0000:
1338 p++;
1339 break;
1340 case 0xffff:
1341 p += 2; /* 0xffff plus predefined window class ordinal value */
1342 break;
1343 default:
1344 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1345 p += lstrlenW( (LPCWSTR)p ) + 1;
1346 break;
1349 /* title */
1350 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1351 p += lstrlenW((LPCWSTR)p) + 1;
1353 /* font, if DS_SETFONT set */
1354 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1355 pTemplate->style)))
1357 p+=(istemplateex)?3:1;
1358 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1359 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1362 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1363 * that are following the DLGTEMPLATE(EX) data */
1364 TRACE("%d items\n",nrofitems);
1365 while (nrofitems > 0)
1367 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1369 /* skip header */
1370 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1372 /* check class */
1373 switch ((WORD)*p)
1375 case 0x0000:
1376 p++;
1377 break;
1378 case 0xffff:
1379 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1380 p += 2;
1381 break;
1382 default:
1383 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1384 p += lstrlenW( (LPCWSTR)p ) + 1;
1385 break;
1388 /* check title text */
1389 switch ((WORD)*p)
1391 case 0x0000:
1392 p++;
1393 break;
1394 case 0xffff:
1395 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1396 p += 2;
1397 break;
1398 default:
1399 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1400 p += lstrlenW( (LPCWSTR)p ) + 1;
1401 break;
1403 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1404 --nrofitems;
1407 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1408 return (p - (WORD*)pTemplate)*sizeof(WORD);
1412 /******************************************************************************
1413 * PROPSHEET_CreatePage
1415 * Creates a page.
1417 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1418 int index,
1419 const PropSheetInfo * psInfo,
1420 LPCPROPSHEETPAGEW ppshpage)
1422 DLGTEMPLATE* pTemplate;
1423 HWND hwndPage;
1424 DWORD resSize;
1425 LPVOID temp = NULL;
1427 TRACE("index %d\n", index);
1429 if (ppshpage == NULL)
1431 return FALSE;
1434 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1436 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1437 resSize = GetTemplateSize(pTemplate);
1439 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1441 HRSRC hResource;
1442 HANDLE hTemplate;
1444 hResource = FindResourceW(ppshpage->hInstance,
1445 ppshpage->u.pszTemplate,
1446 (LPWSTR)RT_DIALOG);
1447 if(!hResource)
1448 return FALSE;
1450 resSize = SizeofResource(ppshpage->hInstance, hResource);
1452 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1453 if(!hTemplate)
1454 return FALSE;
1456 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1458 * Make a copy of the dialog template to make it writable
1461 else
1463 HRSRC hResource;
1464 HANDLE hTemplate;
1466 hResource = FindResourceA(ppshpage->hInstance,
1467 (LPSTR)ppshpage->u.pszTemplate,
1468 (LPSTR)RT_DIALOG);
1469 if(!hResource)
1470 return FALSE;
1472 resSize = SizeofResource(ppshpage->hInstance, hResource);
1474 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1475 if(!hTemplate)
1476 return FALSE;
1478 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1480 * Make a copy of the dialog template to make it writable
1483 temp = Alloc(resSize);
1484 if (!temp)
1485 return FALSE;
1487 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1488 memcpy(temp, pTemplate, resSize);
1489 pTemplate = temp;
1491 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1493 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1494 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1495 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1496 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1497 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1498 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1500 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1502 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1504 else
1506 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1507 pTemplate->style &= ~DS_MODALFRAME;
1508 pTemplate->style &= ~WS_CAPTION;
1509 pTemplate->style &= ~WS_SYSMENU;
1510 pTemplate->style &= ~WS_POPUP;
1511 pTemplate->style &= ~WS_DISABLED;
1512 pTemplate->style &= ~WS_VISIBLE;
1513 pTemplate->style &= ~WS_THICKFRAME;
1515 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1518 if (psInfo->proppage[index].useCallback)
1519 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1520 (LPPROPSHEETPAGEW)ppshpage);
1522 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1523 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1524 pTemplate,
1525 hwndParent,
1526 ppshpage->pfnDlgProc,
1527 (LPARAM)ppshpage);
1528 else
1529 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1530 pTemplate,
1531 hwndParent,
1532 ppshpage->pfnDlgProc,
1533 (LPARAM)ppshpage);
1534 /* Free a no more needed copy */
1535 if(temp)
1536 Free(temp);
1538 psInfo->proppage[index].hwndPage = hwndPage;
1540 /* Subclass exterior wizard pages */
1541 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1542 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1543 (ppshpage->dwFlags & PSP_HIDEHEADER))
1545 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1546 (DWORD_PTR)ppshpage);
1548 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1549 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1551 return TRUE;
1554 /******************************************************************************
1555 * PROPSHEET_LoadWizardBitmaps
1557 * Loads the watermark and header bitmaps for a wizard.
1559 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1561 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1563 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1564 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1565 considers hbmWatermark as valid. */
1566 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1567 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1569 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1570 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1573 /* Same behavior as for watermarks */
1574 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1575 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1577 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1578 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1584 /******************************************************************************
1585 * PROPSHEET_ShowPage
1587 * Displays or creates the specified page.
1589 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1591 HWND hwndTabCtrl;
1592 HWND hwndLineHeader;
1593 LPCPROPSHEETPAGEW ppshpage;
1595 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1596 if (index == psInfo->active_page)
1598 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1599 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1600 return TRUE;
1603 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1604 if (psInfo->proppage[index].hwndPage == 0)
1606 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1609 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1610 (ppshpage->dwFlags & PSP_USETITLE))
1612 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1613 psInfo->proppage[index].pszText);
1616 if (psInfo->active_page != -1)
1617 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1619 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1621 /* Synchronize current selection with tab control
1622 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1623 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1624 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1626 psInfo->active_page = index;
1627 psInfo->activeValid = TRUE;
1629 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1631 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1632 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1634 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1635 ShowWindow(hwndLineHeader, SW_HIDE);
1636 else
1637 ShowWindow(hwndLineHeader, SW_SHOW);
1640 return TRUE;
1643 /******************************************************************************
1644 * PROPSHEET_Back
1646 static BOOL PROPSHEET_Back(HWND hwndDlg)
1648 PSHNOTIFY psn;
1649 HWND hwndPage;
1650 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1651 PropSheetInfoStr);
1652 LRESULT result;
1653 int idx;
1655 TRACE("active_page %d\n", psInfo->active_page);
1656 if (psInfo->active_page < 0)
1657 return FALSE;
1659 psn.hdr.code = PSN_WIZBACK;
1660 psn.hdr.hwndFrom = hwndDlg;
1661 psn.hdr.idFrom = 0;
1662 psn.lParam = 0;
1664 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1666 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1667 if (result == -1)
1668 return FALSE;
1669 else if (result == 0)
1670 idx = psInfo->active_page - 1;
1671 else
1672 idx = PROPSHEET_FindPageByResId(psInfo, result);
1674 if (idx >= 0 && idx < psInfo->nPages)
1676 if (PROPSHEET_CanSetCurSel(hwndDlg))
1677 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1679 return TRUE;
1682 /******************************************************************************
1683 * PROPSHEET_Next
1685 static BOOL PROPSHEET_Next(HWND hwndDlg)
1687 PSHNOTIFY psn;
1688 HWND hwndPage;
1689 LRESULT msgResult = 0;
1690 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1691 PropSheetInfoStr);
1692 int idx;
1694 TRACE("active_page %d\n", psInfo->active_page);
1695 if (psInfo->active_page < 0)
1696 return FALSE;
1698 psn.hdr.code = PSN_WIZNEXT;
1699 psn.hdr.hwndFrom = hwndDlg;
1700 psn.hdr.idFrom = 0;
1701 psn.lParam = 0;
1703 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1705 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1706 if (msgResult == -1)
1707 return FALSE;
1708 else if (msgResult == 0)
1709 idx = psInfo->active_page + 1;
1710 else
1711 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1713 if (idx < psInfo->nPages )
1715 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1716 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1719 return TRUE;
1722 /******************************************************************************
1723 * PROPSHEET_Finish
1725 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1727 PSHNOTIFY psn;
1728 HWND hwndPage;
1729 LRESULT msgResult = 0;
1730 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1731 PropSheetInfoStr);
1733 TRACE("active_page %d\n", psInfo->active_page);
1734 if (psInfo->active_page < 0)
1735 return FALSE;
1737 psn.hdr.code = PSN_WIZFINISH;
1738 psn.hdr.hwndFrom = hwndDlg;
1739 psn.hdr.idFrom = 0;
1740 psn.lParam = 0;
1742 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1744 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1746 TRACE("msg result %ld\n", msgResult);
1748 if (msgResult != 0)
1749 return FALSE;
1751 if (psInfo->isModeless)
1752 psInfo->activeValid = FALSE;
1753 else
1754 psInfo->ended = TRUE;
1756 return TRUE;
1759 /******************************************************************************
1760 * PROPSHEET_Apply
1762 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1764 int i;
1765 HWND hwndPage;
1766 PSHNOTIFY psn;
1767 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1768 PropSheetInfoStr);
1770 TRACE("active_page %d\n", psInfo->active_page);
1771 if (psInfo->active_page < 0)
1772 return FALSE;
1774 psn.hdr.hwndFrom = hwndDlg;
1775 psn.hdr.idFrom = 0;
1776 psn.lParam = 0;
1780 * Send PSN_KILLACTIVE to the current page.
1782 psn.hdr.code = PSN_KILLACTIVE;
1784 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1786 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1787 return FALSE;
1790 * Send PSN_APPLY to all pages.
1792 psn.hdr.code = PSN_APPLY;
1793 psn.lParam = lParam;
1795 for (i = 0; i < psInfo->nPages; i++)
1797 hwndPage = psInfo->proppage[i].hwndPage;
1798 if (hwndPage)
1800 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1802 case PSNRET_INVALID:
1803 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1804 /* fall through */
1805 case PSNRET_INVALID_NOCHANGEPAGE:
1806 return FALSE;
1811 if(lParam)
1813 psInfo->activeValid = FALSE;
1815 else if(psInfo->active_page >= 0)
1817 psn.hdr.code = PSN_SETACTIVE;
1818 psn.lParam = 0;
1819 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1820 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1823 return TRUE;
1826 /******************************************************************************
1827 * PROPSHEET_Cancel
1829 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1831 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1832 PropSheetInfoStr);
1833 HWND hwndPage;
1834 PSHNOTIFY psn;
1835 int i;
1837 TRACE("active_page %d\n", psInfo->active_page);
1838 if (psInfo->active_page < 0)
1839 return;
1841 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1842 psn.hdr.code = PSN_QUERYCANCEL;
1843 psn.hdr.hwndFrom = hwndDlg;
1844 psn.hdr.idFrom = 0;
1845 psn.lParam = 0;
1847 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1848 return;
1850 psn.hdr.code = PSN_RESET;
1851 psn.lParam = lParam;
1853 for (i = 0; i < psInfo->nPages; i++)
1855 hwndPage = psInfo->proppage[i].hwndPage;
1857 if (hwndPage)
1858 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1861 if (psInfo->isModeless)
1863 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1864 psInfo->activeValid = FALSE;
1866 else
1867 psInfo->ended = TRUE;
1870 /******************************************************************************
1871 * PROPSHEET_Help
1873 static void PROPSHEET_Help(HWND hwndDlg)
1875 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1876 PropSheetInfoStr);
1877 HWND hwndPage;
1878 PSHNOTIFY psn;
1880 TRACE("active_page %d\n", psInfo->active_page);
1881 if (psInfo->active_page < 0)
1882 return;
1884 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1885 psn.hdr.code = PSN_HELP;
1886 psn.hdr.hwndFrom = hwndDlg;
1887 psn.hdr.idFrom = 0;
1888 psn.lParam = 0;
1890 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1893 /******************************************************************************
1894 * PROPSHEET_Changed
1896 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1898 int i;
1899 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1900 PropSheetInfoStr);
1902 TRACE("\n");
1903 if (!psInfo) return;
1905 * Set the dirty flag of this page.
1907 for (i = 0; i < psInfo->nPages; i++)
1909 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1910 psInfo->proppage[i].isDirty = TRUE;
1914 * Enable the Apply button.
1916 if (psInfo->hasApply)
1918 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1920 EnableWindow(hwndApplyBtn, TRUE);
1924 /******************************************************************************
1925 * PROPSHEET_UnChanged
1927 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1929 int i;
1930 BOOL noPageDirty = TRUE;
1931 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1932 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1933 PropSheetInfoStr);
1935 TRACE("\n");
1936 if ( !psInfo ) return;
1937 for (i = 0; i < psInfo->nPages; i++)
1939 /* set the specified page as clean */
1940 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1941 psInfo->proppage[i].isDirty = FALSE;
1943 /* look to see if there's any dirty pages */
1944 if (psInfo->proppage[i].isDirty)
1945 noPageDirty = FALSE;
1949 * Disable Apply button.
1951 if (noPageDirty)
1952 EnableWindow(hwndApplyBtn, FALSE);
1955 /******************************************************************************
1956 * PROPSHEET_PressButton
1958 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1960 TRACE("buttonID %d\n", buttonID);
1961 switch (buttonID)
1963 case PSBTN_APPLYNOW:
1964 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1965 break;
1966 case PSBTN_BACK:
1967 PROPSHEET_Back(hwndDlg);
1968 break;
1969 case PSBTN_CANCEL:
1970 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1971 break;
1972 case PSBTN_FINISH:
1973 PROPSHEET_Finish(hwndDlg);
1974 break;
1975 case PSBTN_HELP:
1976 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1977 break;
1978 case PSBTN_NEXT:
1979 PROPSHEET_Next(hwndDlg);
1980 break;
1981 case PSBTN_OK:
1982 PROPSHEET_DoCommand(hwndDlg, IDOK);
1983 break;
1984 default:
1985 FIXME("Invalid button index %d\n", buttonID);
1990 /*************************************************************************
1991 * BOOL PROPSHEET_CanSetCurSel [Internal]
1993 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1995 * PARAMS
1996 * hwndDlg [I] handle to a Dialog hWnd
1998 * RETURNS
1999 * TRUE if Current Selection can change
2001 * NOTES
2003 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2005 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2006 PropSheetInfoStr);
2007 HWND hwndPage;
2008 PSHNOTIFY psn;
2009 BOOL res = FALSE;
2011 TRACE("active_page %d\n", psInfo->active_page);
2012 if (!psInfo)
2014 res = FALSE;
2015 goto end;
2018 if (psInfo->active_page < 0)
2020 res = TRUE;
2021 goto end;
2025 * Notify the current page.
2027 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2028 psn.hdr.code = PSN_KILLACTIVE;
2029 psn.hdr.hwndFrom = hwndDlg;
2030 psn.hdr.idFrom = 0;
2031 psn.lParam = 0;
2033 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2035 end:
2036 TRACE("<-- %d\n", res);
2037 return res;
2040 /******************************************************************************
2041 * PROPSHEET_SetCurSel
2043 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2044 int index,
2045 int skipdir,
2046 HPROPSHEETPAGE hpage
2049 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2050 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2051 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2053 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2054 /* hpage takes precedence over index */
2055 if (hpage != NULL)
2056 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2058 if (index < 0 || index >= psInfo->nPages)
2060 TRACE("Could not find page to select!\n");
2061 return FALSE;
2064 while (1) {
2065 int result;
2066 PSHNOTIFY psn;
2067 RECT rc;
2068 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2070 if (hwndTabControl)
2071 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2073 psn.hdr.code = PSN_SETACTIVE;
2074 psn.hdr.hwndFrom = hwndDlg;
2075 psn.hdr.idFrom = 0;
2076 psn.lParam = 0;
2078 if (!psInfo->proppage[index].hwndPage) {
2079 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2082 /* Resize the property sheet page to the fit in the Tab control
2083 * (for regular property sheets) or to fit in the client area (for
2084 * wizards).
2085 * NOTE: The resizing happens every time the page is selected and
2086 * not only when it's created (some applications depend on it). */
2087 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2088 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2089 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2090 rc.right - rc.left, rc.bottom - rc.top);
2091 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2092 rc.left, rc.top,
2093 rc.right - rc.left, rc.bottom - rc.top, 0);
2095 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2096 if (!result)
2097 break;
2098 if (result == -1) {
2099 index+=skipdir;
2100 if (index < 0) {
2101 index = 0;
2102 WARN("Tried to skip before first property sheet page!\n");
2103 break;
2105 if (index >= psInfo->nPages) {
2106 WARN("Tried to skip after last property sheet page!\n");
2107 index = psInfo->nPages-1;
2108 break;
2111 else if (result != 0)
2113 int old_index = index;
2114 index = PROPSHEET_FindPageByResId(psInfo, result);
2115 if(index >= psInfo->nPages) {
2116 index = old_index;
2117 WARN("Tried to skip to nonexistant page by res id\n");
2118 break;
2120 continue;
2124 * Display the new page.
2126 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2128 if (psInfo->proppage[index].hasHelp)
2129 EnableWindow(hwndHelp, TRUE);
2130 else
2131 EnableWindow(hwndHelp, FALSE);
2133 return TRUE;
2136 /******************************************************************************
2137 * PROPSHEET_SetCurSelId
2139 * Selects the page, specified by resource id.
2141 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2143 int idx;
2144 PropSheetInfo* psInfo =
2145 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2147 idx = PROPSHEET_FindPageByResId(psInfo, id);
2148 if (idx < psInfo->nPages )
2150 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2151 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2155 /******************************************************************************
2156 * PROPSHEET_SetTitleA
2158 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2160 if(HIWORD(lpszText))
2162 WCHAR szTitle[256];
2163 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2164 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2165 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2167 else
2169 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2173 /******************************************************************************
2174 * PROPSHEET_SetTitleW
2176 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2178 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2179 WCHAR szTitle[256];
2181 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2182 if (HIWORD(lpszText) == 0) {
2183 if (!LoadStringW(psInfo->ppshheader.hInstance,
2184 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2185 return;
2186 lpszText = szTitle;
2188 if (dwStyle & PSH_PROPTITLE)
2190 WCHAR* dest;
2191 int lentitle = strlenW(lpszText);
2192 int lenprop = strlenW(psInfo->strPropertiesFor);
2194 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2195 strcpyW(dest, psInfo->strPropertiesFor);
2196 strcatW(dest, lpszText);
2198 SetWindowTextW(hwndDlg, dest);
2199 Free(dest);
2201 else
2202 SetWindowTextW(hwndDlg, lpszText);
2205 /******************************************************************************
2206 * PROPSHEET_SetFinishTextA
2208 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2210 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2211 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2213 TRACE("'%s'\n", lpszText);
2214 /* Set text, show and enable the Finish button */
2215 SetWindowTextA(hwndButton, lpszText);
2216 ShowWindow(hwndButton, SW_SHOW);
2217 EnableWindow(hwndButton, TRUE);
2219 /* Make it default pushbutton */
2220 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2222 /* Hide Back button */
2223 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2224 ShowWindow(hwndButton, SW_HIDE);
2226 if (!psInfo->hasFinish)
2228 /* Hide Next button */
2229 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2230 ShowWindow(hwndButton, SW_HIDE);
2234 /******************************************************************************
2235 * PROPSHEET_SetFinishTextW
2237 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2239 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2240 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2242 TRACE("'%s'\n", debugstr_w(lpszText));
2243 /* Set text, show and enable the Finish button */
2244 SetWindowTextW(hwndButton, lpszText);
2245 ShowWindow(hwndButton, SW_SHOW);
2246 EnableWindow(hwndButton, TRUE);
2248 /* Make it default pushbutton */
2249 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2251 /* Hide Back button */
2252 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2253 ShowWindow(hwndButton, SW_HIDE);
2255 if (!psInfo->hasFinish)
2257 /* Hide Next button */
2258 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2259 ShowWindow(hwndButton, SW_HIDE);
2263 /******************************************************************************
2264 * PROPSHEET_QuerySiblings
2266 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2267 WPARAM wParam, LPARAM lParam)
2269 int i = 0;
2270 HWND hwndPage;
2271 LRESULT msgResult = 0;
2272 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2274 while ((i < psInfo->nPages) && (msgResult == 0))
2276 hwndPage = psInfo->proppage[i].hwndPage;
2277 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2278 i++;
2281 return msgResult;
2285 /******************************************************************************
2286 * PROPSHEET_AddPage
2288 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2289 HPROPSHEETPAGE hpage)
2291 PropPageInfo * ppi;
2292 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2293 PropSheetInfoStr);
2294 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2295 TCITEMW item;
2296 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2298 TRACE("hpage %p\n", hpage);
2300 * Allocate and fill in a new PropPageInfo entry.
2302 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2303 sizeof(PropPageInfo) *
2304 (psInfo->nPages + 1));
2305 if (!ppi)
2306 return FALSE;
2308 psInfo->proppage = ppi;
2309 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2310 return FALSE;
2312 psInfo->proppage[psInfo->nPages].hpage = hpage;
2314 if (ppsp->dwFlags & PSP_PREMATURE)
2316 /* Create the page but don't show it */
2317 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2321 * Add a new tab to the tab control.
2323 item.mask = TCIF_TEXT;
2324 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2325 item.cchTextMax = MAX_TABTEXT_LENGTH;
2327 if (psInfo->hImageList)
2329 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2332 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2334 item.mask |= TCIF_IMAGE;
2335 item.iImage = psInfo->nPages;
2338 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2339 (LPARAM)&item);
2341 psInfo->nPages++;
2343 /* If it is the only page - show it */
2344 if(psInfo->nPages == 1)
2345 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2346 return TRUE;
2349 /******************************************************************************
2350 * PROPSHEET_RemovePage
2352 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2353 int index,
2354 HPROPSHEETPAGE hpage)
2356 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2357 PropSheetInfoStr);
2358 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2359 PropPageInfo* oldPages;
2361 TRACE("index %d, hpage %p\n", index, hpage);
2362 if (!psInfo) {
2363 return FALSE;
2366 * hpage takes precedence over index.
2368 if (hpage != 0)
2370 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2373 /* Make sure that index is within range */
2374 if (index < 0 || index >= psInfo->nPages)
2376 TRACE("Could not find page to remove!\n");
2377 return FALSE;
2380 TRACE("total pages %d removing page %d active page %d\n",
2381 psInfo->nPages, index, psInfo->active_page);
2383 * Check if we're removing the active page.
2385 if (index == psInfo->active_page)
2387 if (psInfo->nPages > 1)
2389 if (index > 0)
2391 /* activate previous page */
2392 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2394 else
2396 /* activate the next page */
2397 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2398 psInfo->active_page = index;
2401 else
2403 psInfo->active_page = -1;
2404 if (!psInfo->isModeless)
2406 psInfo->ended = TRUE;
2407 return TRUE;
2411 else if (index < psInfo->active_page)
2412 psInfo->active_page--;
2414 /* Unsubclass the page dialog window */
2415 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2416 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2417 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2419 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2420 PROPSHEET_WizardSubclassProc, 1);
2423 /* Destroy page dialog window */
2424 DestroyWindow(psInfo->proppage[index].hwndPage);
2426 /* Free page resources */
2427 if(psInfo->proppage[index].hpage)
2429 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2431 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2432 Free ((LPVOID)psInfo->proppage[index].pszText);
2434 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2437 /* Remove the tab */
2438 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2440 oldPages = psInfo->proppage;
2441 psInfo->nPages--;
2442 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2444 if (index > 0)
2445 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2447 if (index < psInfo->nPages)
2448 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2449 (psInfo->nPages - index) * sizeof(PropPageInfo));
2451 Free(oldPages);
2453 return FALSE;
2456 /******************************************************************************
2457 * PROPSHEET_SetWizButtons
2459 * This code will work if (and assumes that) the Next button is on top of the
2460 * Finish button. ie. Finish comes after Next in the Z order.
2461 * This means make sure the dialog template reflects this.
2464 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2466 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2467 PropSheetInfoStr);
2468 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2469 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2470 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2472 TRACE("%ld\n", dwFlags);
2474 EnableWindow(hwndBack, FALSE);
2475 EnableWindow(hwndNext, FALSE);
2476 EnableWindow(hwndFinish, FALSE);
2478 if (dwFlags & PSWIZB_BACK)
2479 EnableWindow(hwndBack, TRUE);
2481 if (dwFlags & PSWIZB_NEXT)
2483 if (!psInfo->hasFinish)
2485 /* Hide the Finish button */
2486 ShowWindow(hwndFinish, SW_HIDE);
2489 /* Show and enable the Next button */
2490 ShowWindow(hwndNext, SW_SHOW);
2491 EnableWindow(hwndNext, TRUE);
2493 /* Set the Next button as the default pushbutton */
2494 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2497 if (!psInfo->hasFinish)
2499 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2501 /* Hide the Next button */
2502 ShowWindow(hwndNext, SW_HIDE);
2504 /* Show the Finish button */
2505 ShowWindow(hwndFinish, SW_SHOW);
2507 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2509 EnableWindow(hwndFinish, TRUE);
2511 /* Set the Finish button as the default pushbutton */
2512 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2516 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2517 EnableWindow(hwndFinish, TRUE);
2520 /******************************************************************************
2521 * PROPSHEET_InsertPage
2523 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2525 if (!HIWORD(hpageInsertAfter))
2526 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2527 else
2528 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2529 return FALSE;
2532 /******************************************************************************
2533 * PROPSHEET_SetHeaderTitleW
2535 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2537 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2540 /******************************************************************************
2541 * PROPSHEET_SetHeaderTitleA
2543 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2545 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2548 /******************************************************************************
2549 * PROPSHEET_SetHeaderSubTitleW
2551 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2553 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2556 /******************************************************************************
2557 * PROPSHEET_SetHeaderSubTitleA
2559 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2561 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2564 /******************************************************************************
2565 * PROPSHEET_HwndToIndex
2567 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2569 int index;
2570 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2571 PropSheetInfoStr);
2573 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2575 for (index = 0; index < psInfo->nPages; index++)
2576 if (psInfo->proppage[index].hwndPage == hPageDlg)
2577 return index;
2578 WARN("%p not found\n", hPageDlg);
2579 return -1;
2582 /******************************************************************************
2583 * PROPSHEET_IndexToHwnd
2585 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2587 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2588 PropSheetInfoStr);
2589 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2590 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2591 WARN("%d out of range.\n", iPageIndex);
2592 return 0;
2594 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2597 /******************************************************************************
2598 * PROPSHEET_PageToIndex
2600 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2602 int index;
2603 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2604 PropSheetInfoStr);
2606 TRACE("(%p, %p)\n", hwndDlg, hPage);
2608 for (index = 0; index < psInfo->nPages; index++)
2609 if (psInfo->proppage[index].hpage == hPage)
2610 return index;
2611 WARN("%p not found\n", hPage);
2612 return -1;
2615 /******************************************************************************
2616 * PROPSHEET_IndexToPage
2618 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2620 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2621 PropSheetInfoStr);
2622 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2623 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2624 WARN("%d out of range.\n", iPageIndex);
2625 return 0;
2627 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2630 /******************************************************************************
2631 * PROPSHEET_IdToIndex
2633 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2635 int index;
2636 LPCPROPSHEETPAGEW psp;
2637 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2638 PropSheetInfoStr);
2639 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2640 for (index = 0; index < psInfo->nPages; index++) {
2641 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2642 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2643 return index;
2646 return -1;
2649 /******************************************************************************
2650 * PROPSHEET_IndexToId
2652 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2654 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2655 PropSheetInfoStr);
2656 LPCPROPSHEETPAGEW psp;
2657 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2658 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2659 WARN("%d out of range.\n", iPageIndex);
2660 return 0;
2662 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2663 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2664 return 0;
2666 return (LRESULT)psp->u.pszTemplate;
2669 /******************************************************************************
2670 * PROPSHEET_GetResult
2672 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2674 FIXME("(%p): stub\n", hwndDlg);
2675 return -1;
2678 /******************************************************************************
2679 * PROPSHEET_RecalcPageSizes
2681 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2683 FIXME("(%p): stub\n", hwndDlg);
2684 return FALSE;
2687 /******************************************************************************
2688 * PROPSHEET_GetPageIndex
2690 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2691 * the array of PropPageInfo.
2693 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2695 BOOL found = FALSE;
2696 int index = 0;
2698 TRACE("hpage %p\n", hpage);
2699 while ((index < psInfo->nPages) && (found == FALSE))
2701 if (psInfo->proppage[index].hpage == hpage)
2702 found = TRUE;
2703 else
2704 index++;
2707 if (found == FALSE)
2708 index = -1;
2710 return index;
2713 /******************************************************************************
2714 * PROPSHEET_CleanUp
2716 static void PROPSHEET_CleanUp(HWND hwndDlg)
2718 int i;
2719 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2720 PropSheetInfoStr);
2722 TRACE("\n");
2723 if (!psInfo) return;
2724 if (HIWORD(psInfo->ppshheader.pszCaption))
2725 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2727 for (i = 0; i < psInfo->nPages; i++)
2729 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2731 /* Unsubclass the page dialog window */
2732 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2733 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2734 (psp->dwFlags & PSP_HIDEHEADER))
2736 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2737 PROPSHEET_WizardSubclassProc, 1);
2740 if(psInfo->proppage[i].hwndPage)
2741 DestroyWindow(psInfo->proppage[i].hwndPage);
2743 if(psp)
2745 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2746 Free ((LPVOID)psInfo->proppage[i].pszText);
2748 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2752 DeleteObject(psInfo->hFont);
2753 DeleteObject(psInfo->hFontBold);
2754 /* If we created the bitmaps, destroy them */
2755 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2756 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2757 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2758 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2759 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2760 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2762 Free(psInfo->proppage);
2763 Free(psInfo->strPropertiesFor);
2764 ImageList_Destroy(psInfo->hImageList);
2766 GlobalFree((HGLOBAL)psInfo);
2769 static INT do_loop(PropSheetInfo *psInfo)
2771 MSG msg;
2772 INT ret = -1;
2773 HWND hwnd = psInfo->hwnd;
2775 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2777 if(ret == -1)
2778 break;
2780 if(!IsDialogMessageW(hwnd, &msg))
2782 TranslateMessage(&msg);
2783 DispatchMessageW(&msg);
2787 if(ret == 0)
2789 PostQuitMessage(msg.wParam);
2790 ret = -1;
2793 DestroyWindow(hwnd);
2794 return ret;
2797 /******************************************************************************
2798 * PropertySheet (COMCTL32.@)
2799 * PropertySheetA (COMCTL32.@)
2801 * Creates a property sheet in the specified property sheet header.
2803 * RETURNS
2804 * Modal property sheets: Positive if successful or -1 otherwise.
2805 * Modeless property sheets: Property sheet handle.
2806 * Or:
2807 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2808 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2810 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2812 INT_PTR bRet = 0;
2813 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2814 sizeof(PropSheetInfo));
2815 UINT i, n;
2816 BYTE* pByte;
2818 TRACE("(%p)\n", lppsh);
2820 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2822 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2823 lppsh->nPages);
2824 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2826 for (n = i = 0; i < lppsh->nPages; i++, n++)
2828 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2829 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2830 else
2832 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2833 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2836 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2837 psInfo, n))
2839 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2840 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2841 n--;
2842 psInfo->nPages--;
2846 psInfo->unicode = FALSE;
2847 psInfo->ended = FALSE;
2849 bRet = PROPSHEET_CreateDialog(psInfo);
2850 if(!psInfo->isModeless)
2851 bRet = do_loop(psInfo);
2853 return bRet;
2856 /******************************************************************************
2857 * PropertySheetW (COMCTL32.@)
2859 * See PropertySheetA.
2861 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2863 INT_PTR bRet = 0;
2864 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2865 sizeof(PropSheetInfo));
2866 UINT i, n;
2867 BYTE* pByte;
2869 TRACE("(%p)\n", lppsh);
2871 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2873 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2874 lppsh->nPages);
2875 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2877 for (n = i = 0; i < lppsh->nPages; i++, n++)
2879 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2880 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2881 else
2883 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2884 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2887 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2888 psInfo, n))
2890 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2891 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2892 n--;
2893 psInfo->nPages--;
2897 psInfo->unicode = TRUE;
2898 psInfo->ended = FALSE;
2900 bRet = PROPSHEET_CreateDialog(psInfo);
2901 if(!psInfo->isModeless)
2902 bRet = do_loop(psInfo);
2904 return bRet;
2907 /******************************************************************************
2908 * CreatePropertySheetPage (COMCTL32.@)
2909 * CreatePropertySheetPageA (COMCTL32.@)
2911 * Creates a new property sheet page.
2913 * RETURNS
2914 * Success: Handle to new property sheet page.
2915 * Failure: NULL.
2917 * NOTES
2918 * An application must use the PSM_ADDPAGE message to add the new page to
2919 * an existing property sheet.
2921 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2922 LPCPROPSHEETPAGEA lpPropSheetPage)
2924 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2926 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2928 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2929 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2931 int len = strlen(lpPropSheetPage->u.pszTemplate);
2933 ppsp->u.pszTemplate = Alloc( len+1 );
2934 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2936 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2938 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2941 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2943 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2945 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2946 ppsp->pszTitle = NULL;
2948 return (HPROPSHEETPAGE)ppsp;
2951 /******************************************************************************
2952 * CreatePropertySheetPageW (COMCTL32.@)
2954 * See CreatePropertySheetA.
2956 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2958 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2960 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2962 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2964 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2966 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2968 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2969 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2971 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2973 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2974 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2975 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2978 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2980 int len = strlenW(lpPropSheetPage->pszTitle);
2981 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2982 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2984 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2985 ppsp->pszTitle = NULL;
2987 return (HPROPSHEETPAGE)ppsp;
2990 /******************************************************************************
2991 * DestroyPropertySheetPage (COMCTL32.@)
2993 * Destroys a property sheet page previously created with
2994 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2995 * memory.
2997 * RETURNS
2998 * Success: TRUE
2999 * Failure: FALSE
3001 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3003 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3005 if (!psp)
3006 return FALSE;
3008 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3009 Free ((LPVOID)psp->u.pszTemplate);
3011 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3012 Free ((LPVOID)psp->u2.pszIcon);
3014 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3015 Free ((LPVOID)psp->pszTitle);
3017 Free(hPropPage);
3019 return TRUE;
3022 /******************************************************************************
3023 * PROPSHEET_IsDialogMessage
3025 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3027 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3029 TRACE("\n");
3030 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3031 return FALSE;
3033 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3035 int new_page = 0;
3036 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3038 if (!(dlgCode & DLGC_WANTMESSAGE))
3040 switch (lpMsg->wParam)
3042 case VK_TAB:
3043 if (GetKeyState(VK_SHIFT) & 0x8000)
3044 new_page = -1;
3045 else
3046 new_page = 1;
3047 break;
3049 case VK_NEXT: new_page = 1; break;
3050 case VK_PRIOR: new_page = -1; break;
3054 if (new_page)
3056 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3058 new_page += psInfo->active_page;
3060 if (new_page < 0)
3061 new_page = psInfo->nPages - 1;
3062 else if (new_page >= psInfo->nPages)
3063 new_page = 0;
3065 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3068 return TRUE;
3072 return IsDialogMessageW(hwnd, lpMsg);
3075 /******************************************************************************
3076 * PROPSHEET_DoCommand
3078 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3081 switch (wID) {
3083 case IDOK:
3084 case IDC_APPLY_BUTTON:
3086 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3088 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3089 break;
3091 if (wID == IDOK)
3093 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3094 PropSheetInfoStr);
3095 int result = TRUE;
3097 if (psInfo->restartWindows)
3098 result = ID_PSRESTARTWINDOWS;
3100 /* reboot system takes precedence over restart windows */
3101 if (psInfo->rebootSystem)
3102 result = ID_PSREBOOTSYSTEM;
3104 if (psInfo->isModeless)
3105 psInfo->activeValid = FALSE;
3106 else
3107 psInfo->ended = TRUE;
3109 else
3110 EnableWindow(hwndApplyBtn, FALSE);
3112 break;
3115 case IDC_BACK_BUTTON:
3116 PROPSHEET_Back(hwnd);
3117 break;
3119 case IDC_NEXT_BUTTON:
3120 PROPSHEET_Next(hwnd);
3121 break;
3123 case IDC_FINISH_BUTTON:
3124 PROPSHEET_Finish(hwnd);
3125 break;
3127 case IDCANCEL:
3128 PROPSHEET_Cancel(hwnd, 0);
3129 break;
3131 case IDHELP:
3132 PROPSHEET_Help(hwnd);
3133 break;
3135 default:
3136 return FALSE;
3139 return TRUE;
3142 /******************************************************************************
3143 * PROPSHEET_Paint
3145 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3147 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3148 PAINTSTRUCT ps;
3149 HDC hdc, hdcSrc;
3150 BITMAP bm;
3151 HBITMAP hbmp;
3152 HPALETTE hOldPal = 0;
3153 int offsety = 0;
3154 HBRUSH hbr;
3155 RECT r, rzone;
3156 LPCPROPSHEETPAGEW ppshpage;
3157 WCHAR szBuffer[256];
3158 int nLength;
3160 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3161 if (!hdc) return 1;
3163 hdcSrc = CreateCompatibleDC(0);
3164 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3166 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3167 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3169 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3170 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3171 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3173 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3174 HFONT hOldFont;
3175 COLORREF clrOld = 0;
3176 int oldBkMode = 0;
3178 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3179 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3181 GetClientRect(hwndLineHeader, &r);
3182 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3183 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3185 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3187 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3189 /* Fill the unoccupied part of the header with color of the
3190 * left-top pixel, but do it only when needed.
3192 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3194 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3195 CopyRect(&r, &rzone);
3196 if (bm.bmWidth < r.right)
3198 r.left = bm.bmWidth;
3199 FillRect(hdc, &r, hbr);
3201 if (bm.bmHeight < r.bottom)
3203 r.left = 0;
3204 r.top = bm.bmHeight;
3205 FillRect(hdc, &r, hbr);
3207 DeleteObject(hbr);
3210 /* Draw the header itself. */
3211 BitBlt(hdc, 0, 0,
3212 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3213 hdcSrc, 0, 0, SRCCOPY);
3215 else
3217 hbr = GetSysColorBrush(COLOR_WINDOW);
3218 FillRect(hdc, &rzone, hbr);
3220 /* Draw the header bitmap. It's always centered like a
3221 * common 49 x 49 bitmap. */
3222 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3223 (rzone.bottom - 49) / 2,
3224 bm.bmWidth, bm.bmHeight,
3225 hdcSrc, 0, 0, SRCCOPY);
3227 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3228 * if its height is smaller than 49 pixels. Because the reason
3229 * for this bug is unknown the current code doesn't try to
3230 * replicate it. */
3233 clrOld = SetTextColor (hdc, 0x00000000);
3234 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3236 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3237 SetRect(&r, 20, 10, 0, 0);
3238 if (HIWORD(ppshpage->pszHeaderTitle))
3240 if (psInfo->unicode)
3241 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3242 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3243 else
3244 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3245 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3247 else
3249 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3250 szBuffer, 256);
3251 if (nLength != 0)
3253 DrawTextW(hdc, szBuffer, nLength,
3254 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3259 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3260 SelectObject(hdc, psInfo->hFont);
3261 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3262 if (HIWORD(ppshpage->pszHeaderTitle))
3264 if (psInfo->unicode)
3265 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3266 -1, &r, DT_LEFT | DT_SINGLELINE);
3267 else
3268 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3269 -1, &r, DT_LEFT | DT_SINGLELINE);
3271 else
3273 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3274 szBuffer, 256);
3275 if (nLength != 0)
3277 DrawTextW(hdc, szBuffer, nLength,
3278 &r, DT_LEFT | DT_SINGLELINE);
3283 offsety = rzone.bottom + 2;
3285 SetTextColor(hdc, clrOld);
3286 SetBkMode(hdc, oldBkMode);
3287 SelectObject(hdc, hOldFont);
3288 SelectObject(hdcSrc, hbmp);
3291 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3292 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3293 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3295 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3297 GetClientRect(hwndLine, &r);
3298 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3300 rzone.left = 0;
3301 rzone.top = 0;
3302 rzone.right = r.right;
3303 rzone.bottom = r.top - 1;
3305 hbr = GetSysColorBrush(COLOR_WINDOW);
3306 FillRect(hdc, &rzone, hbr);
3308 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3309 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3311 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3312 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3314 /* If the bitmap is not big enough, fill the remaining area
3315 with the color of pixel (0,0) of bitmap - see MSDN */
3316 if (r.top > bm.bmHeight) {
3317 r.bottom = r.top - 1;
3318 r.top = bm.bmHeight;
3319 r.left = 0;
3320 r.right = bm.bmWidth;
3321 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3322 FillRect(hdc, &r, hbr);
3323 DeleteObject(hbr);
3326 SelectObject(hdcSrc, hbmp);
3329 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3330 SelectPalette(hdc, hOldPal, FALSE);
3332 DeleteDC(hdcSrc);
3334 if (!hdcParam) EndPaint(hwnd, &ps);
3336 return 0;
3339 /******************************************************************************
3340 * PROPSHEET_DialogProc
3342 INT_PTR CALLBACK
3343 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3345 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3346 hwnd, uMsg, wParam, lParam);
3348 switch (uMsg)
3350 case WM_INITDIALOG:
3352 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3353 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3354 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3355 LPCPROPSHEETPAGEW ppshpage;
3356 int idx;
3357 LOGFONTW logFont;
3359 /* Using PropSheetInfoStr to store extra data doesn't match the native
3360 * common control: native uses TCM_[GS]ETITEM
3362 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3365 * psInfo->hwnd is not being used by WINE code - it exists
3366 * for compatibility with "real" Windoze. The same about
3367 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3368 * property.
3370 psInfo->hwnd = hwnd;
3371 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3373 /* set up the Next and Back buttons by default */
3374 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3376 /* Set up fonts */
3377 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3378 psInfo->hFont = CreateFontIndirectW (&logFont);
3379 logFont.lfWeight = FW_BOLD;
3380 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3383 * Small icon in the title bar.
3385 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3386 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3388 HICON hIcon;
3389 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3390 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3392 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3393 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3394 psInfo->ppshheader.u.pszIcon,
3395 IMAGE_ICON,
3396 icon_cx, icon_cy,
3397 LR_DEFAULTCOLOR);
3398 else
3399 hIcon = psInfo->ppshheader.u.hIcon;
3401 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3404 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3405 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3407 psInfo->strPropertiesFor = strCaption;
3409 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3411 PROPSHEET_CreateTabControl(hwnd, psInfo);
3413 PROPSHEET_LoadWizardBitmaps(psInfo);
3415 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3417 ShowWindow(hwndTabCtrl, SW_HIDE);
3418 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3419 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3421 else
3423 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3425 PROPSHEET_AdjustSize(hwnd, psInfo);
3426 PROPSHEET_AdjustButtons(hwnd, psInfo);
3430 if (psInfo->useCallback)
3431 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3432 PSCB_INITIALIZED, (LPARAM)0);
3434 idx = psInfo->active_page;
3435 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3436 psInfo->active_page = -1;
3438 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3440 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3441 * as some programs call TCM_GETCURSEL to get the current selection
3442 * from which to switch to the next page */
3443 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3445 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3446 psInfo->ppshheader.hInstance)
3448 WCHAR szText[256];
3450 if (LoadStringW(psInfo->ppshheader.hInstance,
3451 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3452 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3454 else
3456 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3457 psInfo->ppshheader.pszCaption);
3460 return TRUE;
3463 case WM_PRINTCLIENT:
3464 case WM_PAINT:
3465 PROPSHEET_Paint(hwnd, (HDC)wParam);
3466 return TRUE;
3468 case WM_DESTROY:
3469 PROPSHEET_CleanUp(hwnd);
3470 return TRUE;
3472 case WM_CLOSE:
3473 PROPSHEET_Cancel(hwnd, 1);
3474 return TRUE;
3476 case WM_COMMAND:
3477 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3479 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3481 if (!psInfo)
3482 return FALSE;
3484 /* No default handler, forward notification to active page */
3485 if (psInfo->activeValid && psInfo->active_page != -1)
3487 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3488 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3491 return TRUE;
3493 case WM_SYSCOMMAND:
3494 switch(wParam & 0xfff0)
3496 case SC_CLOSE:
3497 PROPSHEET_Cancel(hwnd, 1);
3498 return TRUE;
3500 default:
3501 return FALSE;
3504 case WM_NOTIFY:
3506 NMHDR* pnmh = (LPNMHDR) lParam;
3508 if (pnmh->code == TCN_SELCHANGE)
3510 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3511 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3514 if(pnmh->code == TCN_SELCHANGING)
3516 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3517 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3518 return TRUE;
3521 return FALSE;
3524 case WM_SYSCOLORCHANGE:
3525 COMCTL32_RefreshSysColors();
3526 return FALSE;
3528 case PSM_GETCURRENTPAGEHWND:
3530 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3531 PropSheetInfoStr);
3532 HWND hwndPage = 0;
3534 if (!psInfo)
3535 return FALSE;
3537 if (psInfo->activeValid && psInfo->active_page != -1)
3538 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3540 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3542 return TRUE;
3545 case PSM_CHANGED:
3546 PROPSHEET_Changed(hwnd, (HWND)wParam);
3547 return TRUE;
3549 case PSM_UNCHANGED:
3550 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3551 return TRUE;
3553 case PSM_GETTABCONTROL:
3555 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3557 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3559 return TRUE;
3562 case PSM_SETCURSEL:
3564 BOOL msgResult;
3566 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3567 if(msgResult != FALSE)
3569 msgResult = PROPSHEET_SetCurSel(hwnd,
3570 (int)wParam,
3572 (HPROPSHEETPAGE)lParam);
3575 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3577 return TRUE;
3580 case PSM_CANCELTOCLOSE:
3582 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3583 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3584 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3586 EnableWindow(hwndCancel, FALSE);
3587 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3588 SetWindowTextW(hwndOK, buf);
3590 return FALSE;
3593 case PSM_RESTARTWINDOWS:
3595 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3596 PropSheetInfoStr);
3598 if (!psInfo)
3599 return FALSE;
3601 psInfo->restartWindows = TRUE;
3602 return TRUE;
3605 case PSM_REBOOTSYSTEM:
3607 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3608 PropSheetInfoStr);
3610 if (!psInfo)
3611 return FALSE;
3613 psInfo->rebootSystem = TRUE;
3614 return TRUE;
3617 case PSM_SETTITLEA:
3618 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3619 return TRUE;
3621 case PSM_SETTITLEW:
3622 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3623 return TRUE;
3625 case PSM_APPLY:
3627 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3629 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3631 return TRUE;
3634 case PSM_QUERYSIBLINGS:
3636 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3638 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3640 return TRUE;
3643 case PSM_ADDPAGE:
3646 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3647 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3648 * on success or FALSE otherwise, as specified on MSDN Online.
3649 * Also see the MFC code for
3650 * CPropertySheet::AddPage(CPropertyPage* pPage).
3653 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3655 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3657 return TRUE;
3660 case PSM_REMOVEPAGE:
3661 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3662 return TRUE;
3664 case PSM_ISDIALOGMESSAGE:
3666 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3667 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3668 return TRUE;
3671 case PSM_PRESSBUTTON:
3672 PROPSHEET_PressButton(hwnd, (int)wParam);
3673 return TRUE;
3675 case PSM_SETFINISHTEXTA:
3676 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3677 return TRUE;
3679 case PSM_SETWIZBUTTONS:
3680 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3681 return TRUE;
3683 case PSM_SETCURSELID:
3684 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3685 return TRUE;
3687 case PSM_SETFINISHTEXTW:
3688 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3689 return FALSE;
3691 case PSM_INSERTPAGE:
3693 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3694 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3695 return TRUE;
3698 case PSM_SETHEADERTITLEW:
3699 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3700 return TRUE;
3702 case PSM_SETHEADERTITLEA:
3703 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3704 return TRUE;
3706 case PSM_SETHEADERSUBTITLEW:
3707 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3708 return TRUE;
3710 case PSM_SETHEADERSUBTITLEA:
3711 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3712 return TRUE;
3714 case PSM_HWNDTOINDEX:
3716 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3717 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3718 return TRUE;
3721 case PSM_INDEXTOHWND:
3723 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3724 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3725 return TRUE;
3728 case PSM_PAGETOINDEX:
3730 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3731 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3732 return TRUE;
3735 case PSM_INDEXTOPAGE:
3737 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3738 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3739 return TRUE;
3742 case PSM_IDTOINDEX:
3744 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3745 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3746 return TRUE;
3749 case PSM_INDEXTOID:
3751 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3752 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3753 return TRUE;
3756 case PSM_GETRESULT:
3758 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3759 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3760 return TRUE;
3763 case PSM_RECALCPAGESIZES:
3765 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3766 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3767 return TRUE;
3770 default:
3771 return FALSE;