Added descriptions for a few more machine types.
[wine/multimedia.git] / dlls / comctl32 / propsheet.c
blob5e539123f913e53766dde81604a896443f93c437
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));
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 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2292 PropSheetInfoStr);
2293 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2294 TCITEMW item;
2295 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2297 TRACE("hpage %p\n", hpage);
2299 * Allocate and fill in a new PropPageInfo entry.
2301 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2302 sizeof(PropPageInfo) *
2303 (psInfo->nPages + 1));
2304 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2305 return FALSE;
2307 psInfo->proppage[psInfo->nPages].hpage = hpage;
2309 if (ppsp->dwFlags & PSP_PREMATURE)
2311 /* Create the page but don't show it */
2312 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2316 * Add a new tab to the tab control.
2318 item.mask = TCIF_TEXT;
2319 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2320 item.cchTextMax = MAX_TABTEXT_LENGTH;
2322 if (psInfo->hImageList)
2324 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2327 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2329 item.mask |= TCIF_IMAGE;
2330 item.iImage = psInfo->nPages;
2333 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2334 (LPARAM)&item);
2336 psInfo->nPages++;
2338 /* If it is the only page - show it */
2339 if(psInfo->nPages == 1)
2340 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2341 return TRUE;
2344 /******************************************************************************
2345 * PROPSHEET_RemovePage
2347 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2348 int index,
2349 HPROPSHEETPAGE hpage)
2351 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2352 PropSheetInfoStr);
2353 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2354 PropPageInfo* oldPages;
2356 TRACE("index %d, hpage %p\n", index, hpage);
2357 if (!psInfo) {
2358 return FALSE;
2361 * hpage takes precedence over index.
2363 if (hpage != 0)
2365 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2368 /* Make sure that index is within range */
2369 if (index < 0 || index >= psInfo->nPages)
2371 TRACE("Could not find page to remove!\n");
2372 return FALSE;
2375 TRACE("total pages %d removing page %d active page %d\n",
2376 psInfo->nPages, index, psInfo->active_page);
2378 * Check if we're removing the active page.
2380 if (index == psInfo->active_page)
2382 if (psInfo->nPages > 1)
2384 if (index > 0)
2386 /* activate previous page */
2387 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2389 else
2391 /* activate the next page */
2392 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2393 psInfo->active_page = index;
2396 else
2398 psInfo->active_page = -1;
2399 if (!psInfo->isModeless)
2401 psInfo->ended = TRUE;
2402 return TRUE;
2406 else if (index < psInfo->active_page)
2407 psInfo->active_page--;
2409 /* Unsubclass the page dialog window */
2410 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2411 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2412 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2414 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2415 PROPSHEET_WizardSubclassProc, 1);
2418 /* Destroy page dialog window */
2419 DestroyWindow(psInfo->proppage[index].hwndPage);
2421 /* Free page resources */
2422 if(psInfo->proppage[index].hpage)
2424 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2426 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2427 Free ((LPVOID)psInfo->proppage[index].pszText);
2429 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2432 /* Remove the tab */
2433 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2435 oldPages = psInfo->proppage;
2436 psInfo->nPages--;
2437 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2439 if (index > 0)
2440 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2442 if (index < psInfo->nPages)
2443 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2444 (psInfo->nPages - index) * sizeof(PropPageInfo));
2446 Free(oldPages);
2448 return FALSE;
2451 /******************************************************************************
2452 * PROPSHEET_SetWizButtons
2454 * This code will work if (and assumes that) the Next button is on top of the
2455 * Finish button. ie. Finish comes after Next in the Z order.
2456 * This means make sure the dialog template reflects this.
2459 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2461 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2462 PropSheetInfoStr);
2463 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2464 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2465 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2467 TRACE("%ld\n", dwFlags);
2469 EnableWindow(hwndBack, FALSE);
2470 EnableWindow(hwndNext, FALSE);
2471 EnableWindow(hwndFinish, FALSE);
2473 if (dwFlags & PSWIZB_BACK)
2474 EnableWindow(hwndBack, TRUE);
2476 if (dwFlags & PSWIZB_NEXT)
2478 if (!psInfo->hasFinish)
2480 /* Hide the Finish button */
2481 ShowWindow(hwndFinish, SW_HIDE);
2484 /* Show and enable the Next button */
2485 ShowWindow(hwndNext, SW_SHOW);
2486 EnableWindow(hwndNext, TRUE);
2488 /* Set the Next button as the default pushbutton */
2489 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2492 if (!psInfo->hasFinish)
2494 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2496 /* Hide the Next button */
2497 ShowWindow(hwndNext, SW_HIDE);
2499 /* Show the Finish button */
2500 ShowWindow(hwndFinish, SW_SHOW);
2502 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2504 EnableWindow(hwndFinish, TRUE);
2506 /* Set the Finish button as the default pushbutton */
2507 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2511 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2512 EnableWindow(hwndFinish, TRUE);
2515 /******************************************************************************
2516 * PROPSHEET_InsertPage
2518 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2520 if (!HIWORD(hpageInsertAfter))
2521 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2522 else
2523 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2524 return FALSE;
2527 /******************************************************************************
2528 * PROPSHEET_SetHeaderTitleW
2530 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2532 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2535 /******************************************************************************
2536 * PROPSHEET_SetHeaderTitleA
2538 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2540 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2543 /******************************************************************************
2544 * PROPSHEET_SetHeaderSubTitleW
2546 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2548 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2551 /******************************************************************************
2552 * PROPSHEET_SetHeaderSubTitleA
2554 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2556 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2559 /******************************************************************************
2560 * PROPSHEET_HwndToIndex
2562 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2564 int index;
2565 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2566 PropSheetInfoStr);
2568 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2570 for (index = 0; index < psInfo->nPages; index++)
2571 if (psInfo->proppage[index].hwndPage == hPageDlg)
2572 return index;
2573 WARN("%p not found\n", hPageDlg);
2574 return -1;
2577 /******************************************************************************
2578 * PROPSHEET_IndexToHwnd
2580 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2582 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2583 PropSheetInfoStr);
2584 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2585 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2586 WARN("%d out of range.\n", iPageIndex);
2587 return 0;
2589 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2592 /******************************************************************************
2593 * PROPSHEET_PageToIndex
2595 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2597 int index;
2598 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2599 PropSheetInfoStr);
2601 TRACE("(%p, %p)\n", hwndDlg, hPage);
2603 for (index = 0; index < psInfo->nPages; index++)
2604 if (psInfo->proppage[index].hpage == hPage)
2605 return index;
2606 WARN("%p not found\n", hPage);
2607 return -1;
2610 /******************************************************************************
2611 * PROPSHEET_IndexToPage
2613 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2615 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2616 PropSheetInfoStr);
2617 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2618 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2619 WARN("%d out of range.\n", iPageIndex);
2620 return 0;
2622 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2625 /******************************************************************************
2626 * PROPSHEET_IdToIndex
2628 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2630 int index;
2631 LPCPROPSHEETPAGEW psp;
2632 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2633 PropSheetInfoStr);
2634 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2635 for (index = 0; index < psInfo->nPages; index++) {
2636 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2637 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2638 return index;
2641 return -1;
2644 /******************************************************************************
2645 * PROPSHEET_IndexToId
2647 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2649 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2650 PropSheetInfoStr);
2651 LPCPROPSHEETPAGEW psp;
2652 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2653 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2654 WARN("%d out of range.\n", iPageIndex);
2655 return 0;
2657 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2658 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2659 return 0;
2661 return (LRESULT)psp->u.pszTemplate;
2664 /******************************************************************************
2665 * PROPSHEET_GetResult
2667 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2669 FIXME("(%p): stub\n", hwndDlg);
2670 return -1;
2673 /******************************************************************************
2674 * PROPSHEET_RecalcPageSizes
2676 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2678 FIXME("(%p): stub\n", hwndDlg);
2679 return FALSE;
2682 /******************************************************************************
2683 * PROPSHEET_GetPageIndex
2685 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2686 * the array of PropPageInfo.
2688 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2690 BOOL found = FALSE;
2691 int index = 0;
2693 TRACE("hpage %p\n", hpage);
2694 while ((index < psInfo->nPages) && (found == FALSE))
2696 if (psInfo->proppage[index].hpage == hpage)
2697 found = TRUE;
2698 else
2699 index++;
2702 if (found == FALSE)
2703 index = -1;
2705 return index;
2708 /******************************************************************************
2709 * PROPSHEET_CleanUp
2711 static void PROPSHEET_CleanUp(HWND hwndDlg)
2713 int i;
2714 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2715 PropSheetInfoStr);
2717 TRACE("\n");
2718 if (!psInfo) return;
2719 if (HIWORD(psInfo->ppshheader.pszCaption))
2720 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2722 for (i = 0; i < psInfo->nPages; i++)
2724 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2726 /* Unsubclass the page dialog window */
2727 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2728 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2729 (psp->dwFlags & PSP_HIDEHEADER))
2731 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2732 PROPSHEET_WizardSubclassProc, 1);
2735 if(psInfo->proppage[i].hwndPage)
2736 DestroyWindow(psInfo->proppage[i].hwndPage);
2738 if(psp)
2740 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2741 Free ((LPVOID)psInfo->proppage[i].pszText);
2743 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2747 DeleteObject(psInfo->hFont);
2748 DeleteObject(psInfo->hFontBold);
2749 /* If we created the bitmaps, destroy them */
2750 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2751 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2752 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2753 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2754 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2755 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2757 Free(psInfo->proppage);
2758 Free(psInfo->strPropertiesFor);
2759 ImageList_Destroy(psInfo->hImageList);
2761 GlobalFree((HGLOBAL)psInfo);
2764 static INT do_loop(PropSheetInfo *psInfo)
2766 MSG msg;
2767 INT ret = -1;
2768 HWND hwnd = psInfo->hwnd;
2770 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2772 if(ret == -1)
2773 break;
2775 if(!IsDialogMessageW(hwnd, &msg))
2777 TranslateMessage(&msg);
2778 DispatchMessageW(&msg);
2782 if(ret == 0)
2784 PostQuitMessage(msg.wParam);
2785 ret = -1;
2788 DestroyWindow(hwnd);
2789 return ret;
2792 /******************************************************************************
2793 * PropertySheet (COMCTL32.@)
2794 * PropertySheetA (COMCTL32.@)
2796 * Creates a property sheet in the specified property sheet header.
2798 * RETURNS
2799 * Modal property sheets: Positive if successful or -1 otherwise.
2800 * Modeless property sheets: Property sheet handle.
2801 * Or:
2802 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2803 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2805 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2807 INT_PTR bRet = 0;
2808 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2809 sizeof(PropSheetInfo));
2810 UINT i, n;
2811 BYTE* pByte;
2813 TRACE("(%p)\n", lppsh);
2815 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2817 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2818 lppsh->nPages);
2819 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2821 for (n = i = 0; i < lppsh->nPages; i++, n++)
2823 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2824 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2825 else
2827 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2828 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2831 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2832 psInfo, n))
2834 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2835 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2836 n--;
2837 psInfo->nPages--;
2841 psInfo->unicode = FALSE;
2842 psInfo->ended = FALSE;
2844 bRet = PROPSHEET_CreateDialog(psInfo);
2845 if(!psInfo->isModeless)
2846 bRet = do_loop(psInfo);
2848 return bRet;
2851 /******************************************************************************
2852 * PropertySheetW (COMCTL32.@)
2854 * See PropertySheetA.
2856 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2858 INT_PTR bRet = 0;
2859 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2860 sizeof(PropSheetInfo));
2861 UINT i, n;
2862 BYTE* pByte;
2864 TRACE("(%p)\n", lppsh);
2866 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2868 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2869 lppsh->nPages);
2870 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2872 for (n = i = 0; i < lppsh->nPages; i++, n++)
2874 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2875 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2876 else
2878 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2879 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2882 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2883 psInfo, n))
2885 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2886 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2887 n--;
2888 psInfo->nPages--;
2892 psInfo->unicode = TRUE;
2893 psInfo->ended = FALSE;
2895 bRet = PROPSHEET_CreateDialog(psInfo);
2896 if(!psInfo->isModeless)
2897 bRet = do_loop(psInfo);
2899 return bRet;
2902 /******************************************************************************
2903 * CreatePropertySheetPage (COMCTL32.@)
2904 * CreatePropertySheetPageA (COMCTL32.@)
2906 * Creates a new property sheet page.
2908 * RETURNS
2909 * Success: Handle to new property sheet page.
2910 * Failure: NULL.
2912 * NOTES
2913 * An application must use the PSM_ADDPAGE message to add the new page to
2914 * an existing property sheet.
2916 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2917 LPCPROPSHEETPAGEA lpPropSheetPage)
2919 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2921 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2923 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2924 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2926 int len = strlen(lpPropSheetPage->u.pszTemplate);
2928 ppsp->u.pszTemplate = Alloc( len+1 );
2929 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2931 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2933 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2936 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2938 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2940 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2941 ppsp->pszTitle = NULL;
2943 return (HPROPSHEETPAGE)ppsp;
2946 /******************************************************************************
2947 * CreatePropertySheetPageW (COMCTL32.@)
2949 * See CreatePropertySheetA.
2951 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2953 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2955 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2957 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2959 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2961 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2963 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2964 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2966 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2968 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2969 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2970 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2973 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2975 int len = strlenW(lpPropSheetPage->pszTitle);
2976 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2977 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2979 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2980 ppsp->pszTitle = NULL;
2982 return (HPROPSHEETPAGE)ppsp;
2985 /******************************************************************************
2986 * DestroyPropertySheetPage (COMCTL32.@)
2988 * Destroys a property sheet page previously created with
2989 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2990 * memory.
2992 * RETURNS
2993 * Success: TRUE
2994 * Failure: FALSE
2996 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2998 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3000 if (!psp)
3001 return FALSE;
3003 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3004 Free ((LPVOID)psp->u.pszTemplate);
3006 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3007 Free ((LPVOID)psp->u2.pszIcon);
3009 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3010 Free ((LPVOID)psp->pszTitle);
3012 Free(hPropPage);
3014 return TRUE;
3017 /******************************************************************************
3018 * PROPSHEET_IsDialogMessage
3020 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3022 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3024 TRACE("\n");
3025 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3026 return FALSE;
3028 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3030 int new_page = 0;
3031 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3033 if (!(dlgCode & DLGC_WANTMESSAGE))
3035 switch (lpMsg->wParam)
3037 case VK_TAB:
3038 if (GetKeyState(VK_SHIFT) & 0x8000)
3039 new_page = -1;
3040 else
3041 new_page = 1;
3042 break;
3044 case VK_NEXT: new_page = 1; break;
3045 case VK_PRIOR: new_page = -1; break;
3049 if (new_page)
3051 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3053 new_page += psInfo->active_page;
3055 if (new_page < 0)
3056 new_page = psInfo->nPages - 1;
3057 else if (new_page >= psInfo->nPages)
3058 new_page = 0;
3060 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3063 return TRUE;
3067 return IsDialogMessageW(hwnd, lpMsg);
3070 /******************************************************************************
3071 * PROPSHEET_DoCommand
3073 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3076 switch (wID) {
3078 case IDOK:
3079 case IDC_APPLY_BUTTON:
3081 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3083 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3084 break;
3086 if (wID == IDOK)
3088 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3089 PropSheetInfoStr);
3090 int result = TRUE;
3092 if (psInfo->restartWindows)
3093 result = ID_PSRESTARTWINDOWS;
3095 /* reboot system takes precedence over restart windows */
3096 if (psInfo->rebootSystem)
3097 result = ID_PSREBOOTSYSTEM;
3099 if (psInfo->isModeless)
3100 psInfo->activeValid = FALSE;
3101 else
3102 psInfo->ended = TRUE;
3104 else
3105 EnableWindow(hwndApplyBtn, FALSE);
3107 break;
3110 case IDC_BACK_BUTTON:
3111 PROPSHEET_Back(hwnd);
3112 break;
3114 case IDC_NEXT_BUTTON:
3115 PROPSHEET_Next(hwnd);
3116 break;
3118 case IDC_FINISH_BUTTON:
3119 PROPSHEET_Finish(hwnd);
3120 break;
3122 case IDCANCEL:
3123 PROPSHEET_Cancel(hwnd, 0);
3124 break;
3126 case IDHELP:
3127 PROPSHEET_Help(hwnd);
3128 break;
3130 default:
3131 return FALSE;
3134 return TRUE;
3137 /******************************************************************************
3138 * PROPSHEET_Paint
3140 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3142 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3143 PAINTSTRUCT ps;
3144 HDC hdc, hdcSrc;
3145 BITMAP bm;
3146 HBITMAP hbmp;
3147 HPALETTE hOldPal = 0;
3148 int offsety = 0;
3149 HBRUSH hbr;
3150 RECT r, rzone;
3151 LPCPROPSHEETPAGEW ppshpage;
3152 WCHAR szBuffer[256];
3153 int nLength;
3155 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3156 if (!hdc) return 1;
3158 hdcSrc = CreateCompatibleDC(0);
3159 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3161 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3162 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3164 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3165 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3166 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3168 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3169 HFONT hOldFont;
3170 COLORREF clrOld = 0;
3171 int oldBkMode = 0;
3173 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3174 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3176 GetClientRect(hwndLineHeader, &r);
3177 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3178 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3180 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3182 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3184 /* Fill the unoccupied part of the header with color of the
3185 * left-top pixel, but do it only when needed.
3187 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3189 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3190 CopyRect(&r, &rzone);
3191 if (bm.bmWidth < r.right)
3193 r.left = bm.bmWidth;
3194 FillRect(hdc, &r, hbr);
3196 if (bm.bmHeight < r.bottom)
3198 r.left = 0;
3199 r.top = bm.bmHeight;
3200 FillRect(hdc, &r, hbr);
3202 DeleteObject(hbr);
3205 /* Draw the header itself. */
3206 BitBlt(hdc, 0, 0,
3207 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3208 hdcSrc, 0, 0, SRCCOPY);
3210 else
3212 hbr = GetSysColorBrush(COLOR_WINDOW);
3213 FillRect(hdc, &rzone, hbr);
3215 /* Draw the header bitmap. It's always centered like a
3216 * common 49 x 49 bitmap. */
3217 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3218 (rzone.bottom - 49) / 2,
3219 bm.bmWidth, bm.bmHeight,
3220 hdcSrc, 0, 0, SRCCOPY);
3222 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3223 * if its height is smaller than 49 pixels. Because the reason
3224 * for this bug is unknown the current code doesn't try to
3225 * replicate it. */
3228 clrOld = SetTextColor (hdc, 0x00000000);
3229 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3231 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3232 SetRect(&r, 20, 10, 0, 0);
3233 if (HIWORD(ppshpage->pszHeaderTitle))
3235 if (psInfo->unicode)
3236 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3237 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3238 else
3239 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3240 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3242 else
3244 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3245 szBuffer, 256);
3246 if (nLength != 0)
3248 DrawTextW(hdc, szBuffer, nLength,
3249 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3254 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3255 SelectObject(hdc, psInfo->hFont);
3256 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3257 if (HIWORD(ppshpage->pszHeaderTitle))
3259 if (psInfo->unicode)
3260 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3261 -1, &r, DT_LEFT | DT_SINGLELINE);
3262 else
3263 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3264 -1, &r, DT_LEFT | DT_SINGLELINE);
3266 else
3268 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3269 szBuffer, 256);
3270 if (nLength != 0)
3272 DrawTextW(hdc, szBuffer, nLength,
3273 &r, DT_LEFT | DT_SINGLELINE);
3278 offsety = rzone.bottom + 2;
3280 SetTextColor(hdc, clrOld);
3281 SetBkMode(hdc, oldBkMode);
3282 SelectObject(hdc, hOldFont);
3283 SelectObject(hdcSrc, hbmp);
3286 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3287 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3288 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3290 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3292 GetClientRect(hwndLine, &r);
3293 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3295 rzone.left = 0;
3296 rzone.top = 0;
3297 rzone.right = r.right;
3298 rzone.bottom = r.top - 1;
3300 hbr = GetSysColorBrush(COLOR_WINDOW);
3301 FillRect(hdc, &rzone, hbr);
3303 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3304 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3306 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3307 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3309 /* If the bitmap is not big enough, fill the remaining area
3310 with the color of pixel (0,0) of bitmap - see MSDN */
3311 if (r.top > bm.bmHeight) {
3312 r.bottom = r.top - 1;
3313 r.top = bm.bmHeight;
3314 r.left = 0;
3315 r.right = bm.bmWidth;
3316 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3317 FillRect(hdc, &r, hbr);
3318 DeleteObject(hbr);
3321 SelectObject(hdcSrc, hbmp);
3324 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3325 SelectPalette(hdc, hOldPal, FALSE);
3327 DeleteDC(hdcSrc);
3329 if (!hdcParam) EndPaint(hwnd, &ps);
3331 return 0;
3334 /******************************************************************************
3335 * PROPSHEET_DialogProc
3337 INT_PTR CALLBACK
3338 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3340 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3341 hwnd, uMsg, wParam, lParam);
3343 switch (uMsg)
3345 case WM_INITDIALOG:
3347 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3348 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3349 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3350 LPCPROPSHEETPAGEW ppshpage;
3351 int idx;
3352 LOGFONTW logFont;
3354 /* Using PropSheetInfoStr to store extra data doesn't match the native
3355 * common control: native uses TCM_[GS]ETITEM
3357 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3360 * psInfo->hwnd is not being used by WINE code - it exists
3361 * for compatibility with "real" Windoze. The same about
3362 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3363 * property.
3365 psInfo->hwnd = hwnd;
3366 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3368 /* set up the Next and Back buttons by default */
3369 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3371 /* Set up fonts */
3372 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3373 psInfo->hFont = CreateFontIndirectW (&logFont);
3374 logFont.lfWeight = FW_BOLD;
3375 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3378 * Small icon in the title bar.
3380 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3381 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3383 HICON hIcon;
3384 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3385 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3387 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3388 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3389 psInfo->ppshheader.u.pszIcon,
3390 IMAGE_ICON,
3391 icon_cx, icon_cy,
3392 LR_DEFAULTCOLOR);
3393 else
3394 hIcon = psInfo->ppshheader.u.hIcon;
3396 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3399 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3400 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3402 psInfo->strPropertiesFor = strCaption;
3404 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3406 PROPSHEET_CreateTabControl(hwnd, psInfo);
3408 PROPSHEET_LoadWizardBitmaps(psInfo);
3410 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3412 ShowWindow(hwndTabCtrl, SW_HIDE);
3413 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3414 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3416 else
3418 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3420 PROPSHEET_AdjustSize(hwnd, psInfo);
3421 PROPSHEET_AdjustButtons(hwnd, psInfo);
3425 if (psInfo->useCallback)
3426 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3427 PSCB_INITIALIZED, (LPARAM)0);
3429 idx = psInfo->active_page;
3430 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3431 psInfo->active_page = -1;
3433 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3435 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3436 * as some programs call TCM_GETCURSEL to get the current selection
3437 * from which to switch to the next page */
3438 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3440 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3441 psInfo->ppshheader.hInstance)
3443 WCHAR szText[256];
3445 if (LoadStringW(psInfo->ppshheader.hInstance,
3446 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3447 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3449 else
3451 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3452 psInfo->ppshheader.pszCaption);
3455 return TRUE;
3458 case WM_PAINT:
3459 PROPSHEET_Paint(hwnd, (HDC)wParam);
3460 return TRUE;
3462 case WM_DESTROY:
3463 PROPSHEET_CleanUp(hwnd);
3464 return TRUE;
3466 case WM_CLOSE:
3467 PROPSHEET_Cancel(hwnd, 1);
3468 return TRUE;
3470 case WM_COMMAND:
3471 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3473 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3475 if (!psInfo)
3476 return FALSE;
3478 /* No default handler, forward notification to active page */
3479 if (psInfo->activeValid && psInfo->active_page != -1)
3481 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3482 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3485 return TRUE;
3487 case WM_SYSCOMMAND:
3488 switch(wParam & 0xfff0)
3490 case SC_CLOSE:
3491 PROPSHEET_Cancel(hwnd, 1);
3492 return TRUE;
3494 default:
3495 return FALSE;
3498 case WM_NOTIFY:
3500 NMHDR* pnmh = (LPNMHDR) lParam;
3502 if (pnmh->code == TCN_SELCHANGE)
3504 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3505 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3508 if(pnmh->code == TCN_SELCHANGING)
3510 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3511 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3512 return TRUE;
3515 return FALSE;
3518 case WM_SYSCOLORCHANGE:
3519 COMCTL32_RefreshSysColors();
3520 return FALSE;
3522 case PSM_GETCURRENTPAGEHWND:
3524 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3525 PropSheetInfoStr);
3526 HWND hwndPage = 0;
3528 if (!psInfo)
3529 return FALSE;
3531 if (psInfo->activeValid && psInfo->active_page != -1)
3532 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3534 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3536 return TRUE;
3539 case PSM_CHANGED:
3540 PROPSHEET_Changed(hwnd, (HWND)wParam);
3541 return TRUE;
3543 case PSM_UNCHANGED:
3544 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3545 return TRUE;
3547 case PSM_GETTABCONTROL:
3549 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3551 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3553 return TRUE;
3556 case PSM_SETCURSEL:
3558 BOOL msgResult;
3560 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3561 if(msgResult != FALSE)
3563 msgResult = PROPSHEET_SetCurSel(hwnd,
3564 (int)wParam,
3566 (HPROPSHEETPAGE)lParam);
3569 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3571 return TRUE;
3574 case PSM_CANCELTOCLOSE:
3576 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3577 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3578 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3580 EnableWindow(hwndCancel, FALSE);
3581 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3582 SetWindowTextW(hwndOK, buf);
3584 return FALSE;
3587 case PSM_RESTARTWINDOWS:
3589 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3590 PropSheetInfoStr);
3592 if (!psInfo)
3593 return FALSE;
3595 psInfo->restartWindows = TRUE;
3596 return TRUE;
3599 case PSM_REBOOTSYSTEM:
3601 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3602 PropSheetInfoStr);
3604 if (!psInfo)
3605 return FALSE;
3607 psInfo->rebootSystem = TRUE;
3608 return TRUE;
3611 case PSM_SETTITLEA:
3612 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3613 return TRUE;
3615 case PSM_SETTITLEW:
3616 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3617 return TRUE;
3619 case PSM_APPLY:
3621 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3623 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3625 return TRUE;
3628 case PSM_QUERYSIBLINGS:
3630 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3632 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3634 return TRUE;
3637 case PSM_ADDPAGE:
3640 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3641 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3642 * on success or FALSE otherwise, as specified on MSDN Online.
3643 * Also see the MFC code for
3644 * CPropertySheet::AddPage(CPropertyPage* pPage).
3647 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3649 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3651 return TRUE;
3654 case PSM_REMOVEPAGE:
3655 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3656 return TRUE;
3658 case PSM_ISDIALOGMESSAGE:
3660 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3661 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3662 return TRUE;
3665 case PSM_PRESSBUTTON:
3666 PROPSHEET_PressButton(hwnd, (int)wParam);
3667 return TRUE;
3669 case PSM_SETFINISHTEXTA:
3670 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3671 return TRUE;
3673 case PSM_SETWIZBUTTONS:
3674 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3675 return TRUE;
3677 case PSM_SETCURSELID:
3678 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3679 return TRUE;
3681 case PSM_SETFINISHTEXTW:
3682 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3683 return FALSE;
3685 case PSM_INSERTPAGE:
3687 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3688 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3689 return TRUE;
3692 case PSM_SETHEADERTITLEW:
3693 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3694 return TRUE;
3696 case PSM_SETHEADERTITLEA:
3697 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3698 return TRUE;
3700 case PSM_SETHEADERSUBTITLEW:
3701 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3702 return TRUE;
3704 case PSM_SETHEADERSUBTITLEA:
3705 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3706 return TRUE;
3708 case PSM_HWNDTOINDEX:
3710 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3711 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3712 return TRUE;
3715 case PSM_INDEXTOHWND:
3717 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3718 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3719 return TRUE;
3722 case PSM_PAGETOINDEX:
3724 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3725 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3726 return TRUE;
3729 case PSM_INDEXTOPAGE:
3731 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3732 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3733 return TRUE;
3736 case PSM_IDTOINDEX:
3738 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3739 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3740 return TRUE;
3743 case PSM_INDEXTOID:
3745 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3746 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3747 return TRUE;
3750 case PSM_GETRESULT:
3752 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3753 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3754 return TRUE;
3757 case PSM_RECALCPAGESIZES:
3759 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3760 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3761 return TRUE;
3764 default:
3765 return FALSE;