Changes of picasa-wine-2.2.2820-5 except to configure
[wine/hacks.git] / dlls / comctl32 / propsheet.c
blobbba28de3b43132c5cb7b3921922cef7de215ce79
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 int returned;
136 } PropSheetInfo;
138 typedef struct
140 int x;
141 int y;
142 } PADDING_INFO;
144 /******************************************************************************
145 * Defines and global variables
148 const WCHAR PropSheetInfoStr[] =
149 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
151 #define PSP_INTERNAL_UNICODE 0x80000000
153 #define MAX_CAPTION_LENGTH 255
154 #define MAX_TABTEXT_LENGTH 255
155 #define MAX_BUTTONTEXT_LENGTH 64
157 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
159 /* Wizard metrics specified in DLUs */
160 #define WIZARD_PADDING 7
161 #define WIZARD_HEADER_HEIGHT 36
163 /******************************************************************************
164 * Prototypes
166 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
167 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
169 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
170 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
171 PropSheetInfo * psInfo);
172 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
173 PropSheetInfo * psInfo);
174 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
175 PropSheetInfo * psInfo,
176 int index);
177 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
178 PropSheetInfo * psInfo);
179 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
180 const PropSheetInfo * psInfo,
181 LPCPROPSHEETPAGEW ppshpage);
182 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
183 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
184 static BOOL PROPSHEET_Back(HWND hwndDlg);
185 static BOOL PROPSHEET_Next(HWND hwndDlg);
186 static BOOL PROPSHEET_Finish(HWND hwndDlg);
187 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
188 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
189 static void PROPSHEET_Help(HWND hwndDlg);
190 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
191 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
192 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
193 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
194 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
195 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
196 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
197 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
198 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
199 int index,
200 int skipdir,
201 HPROPSHEETPAGE hpage);
202 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
203 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
204 WPARAM wParam, LPARAM lParam);
205 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
206 HPROPSHEETPAGE hpage);
208 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
209 int index,
210 HPROPSHEETPAGE hpage);
211 static void PROPSHEET_CleanUp(HWND hwndDlg);
212 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
213 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
214 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
215 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
216 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
218 INT_PTR CALLBACK
219 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
221 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
223 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
224 /******************************************************************************
225 * PROPSHEET_UnImplementedFlags
227 * Document use of flags we don't implement yet.
229 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
231 CHAR string[256];
233 string[0] = '\0';
236 * unhandled header flags:
237 * PSH_RTLREADING 0x00000800
238 * PSH_STRETCHWATERMARK 0x00040000
239 * PSH_USEPAGELANG 0x00200000
242 add_flag(PSH_RTLREADING);
243 add_flag(PSH_STRETCHWATERMARK);
244 add_flag(PSH_USEPAGELANG);
245 if (string[0] != '\0')
246 FIXME("%s\n", string);
248 #undef add_flag
250 /******************************************************************************
251 * PROPSHEET_GetPageRect
253 * Retrieve rect from tab control and map into the dialog for SetWindowPos
255 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
256 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
258 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
259 HWND hwndChild;
260 RECT r;
262 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
263 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
264 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
265 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
267 rc->left = rc->top = WIZARD_PADDING;
269 else
271 rc->left = rc->top = 0;
273 rc->right = psInfo->width - rc->left;
274 rc->bottom = psInfo->height - rc->top;
275 MapDialogRect(hwndDlg, rc);
277 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
278 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
279 !(ppshpage->dwFlags & PSP_HIDEHEADER))
281 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
282 GetClientRect(hwndChild, &r);
283 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
284 rc->top += r.bottom + 1;
286 } else {
287 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
288 GetClientRect(hwndTabCtrl, rc);
289 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
290 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
294 /******************************************************************************
295 * PROPSHEET_FindPageByResId
297 * Find page index corresponding to page resource id.
299 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
301 INT i;
303 for (i = 0; i < psInfo->nPages; i++)
305 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
307 /* Fixme: if resource ID is a string shall we use strcmp ??? */
308 if (lppsp->u.pszTemplate == (LPVOID)resId)
309 break;
312 return i;
315 /******************************************************************************
316 * PROPSHEET_AtoW
318 * Convert ASCII to Unicode since all data is saved as Unicode.
320 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
322 INT len;
324 TRACE("<%s>\n", frstr);
325 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
326 *tostr = Alloc(len * sizeof(WCHAR));
327 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
330 /******************************************************************************
331 * PROPSHEET_CollectSheetInfoA
333 * Collect relevant data.
335 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
336 PropSheetInfo * psInfo)
338 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
339 DWORD dwFlags = lppsh->dwFlags;
341 psInfo->hasHelp = dwFlags & PSH_HASHELP;
342 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
343 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
344 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
345 psInfo->isModeless = dwFlags & PSH_MODELESS;
347 memcpy(&psInfo->ppshheader,lppsh,dwSize);
348 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",
349 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
350 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
352 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
354 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
355 psInfo->ppshheader.pszCaption = NULL;
356 else
358 if (HIWORD(lppsh->pszCaption))
360 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
361 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
362 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
365 psInfo->nPages = lppsh->nPages;
367 if (dwFlags & PSH_USEPSTARTPAGE)
369 TRACE("PSH_USEPSTARTPAGE is on\n");
370 psInfo->active_page = 0;
372 else
373 psInfo->active_page = lppsh->u2.nStartPage;
375 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
376 psInfo->active_page = 0;
378 psInfo->restartWindows = FALSE;
379 psInfo->rebootSystem = FALSE;
380 psInfo->hImageList = 0;
381 psInfo->activeValid = FALSE;
383 return TRUE;
386 /******************************************************************************
387 * PROPSHEET_CollectSheetInfoW
389 * Collect relevant data.
391 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
392 PropSheetInfo * psInfo)
394 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
395 DWORD dwFlags = lppsh->dwFlags;
397 psInfo->hasHelp = dwFlags & PSH_HASHELP;
398 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
399 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
400 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
401 psInfo->isModeless = dwFlags & PSH_MODELESS;
403 memcpy(&psInfo->ppshheader,lppsh,dwSize);
404 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",
405 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
407 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
409 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
410 psInfo->ppshheader.pszCaption = NULL;
411 else
413 if (HIWORD(lppsh->pszCaption))
415 int len = strlenW(lppsh->pszCaption);
416 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
417 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
420 psInfo->nPages = lppsh->nPages;
422 if (dwFlags & PSH_USEPSTARTPAGE)
424 TRACE("PSH_USEPSTARTPAGE is on\n");
425 psInfo->active_page = 0;
427 else
428 psInfo->active_page = lppsh->u2.nStartPage;
430 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
431 psInfo->active_page = 0;
433 psInfo->restartWindows = FALSE;
434 psInfo->rebootSystem = FALSE;
435 psInfo->hImageList = 0;
436 psInfo->activeValid = FALSE;
438 return TRUE;
441 /******************************************************************************
442 * PROPSHEET_CollectPageInfo
444 * Collect property sheet data.
445 * With code taken from DIALOG_ParseTemplate32.
447 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
448 PropSheetInfo * psInfo,
449 int index)
451 DLGTEMPLATE* pTemplate;
452 const WORD* p;
453 DWORD dwFlags;
454 int width, height;
456 if (!lppsp)
457 return FALSE;
459 TRACE("\n");
460 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
461 psInfo->proppage[index].hwndPage = 0;
462 psInfo->proppage[index].isDirty = FALSE;
465 * Process property page flags.
467 dwFlags = lppsp->dwFlags;
468 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
469 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
470 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
472 /* as soon as we have a page with the help flag, set the sheet flag on */
473 if (psInfo->proppage[index].hasHelp)
474 psInfo->hasHelp = TRUE;
477 * Process page template.
479 if (dwFlags & PSP_DLGINDIRECT)
480 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
481 else if(dwFlags & PSP_INTERNAL_UNICODE )
483 HRSRC hResource = FindResourceW(lppsp->hInstance,
484 lppsp->u.pszTemplate,
485 (LPWSTR)RT_DIALOG);
486 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
487 hResource);
488 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
490 else
492 HRSRC hResource = FindResourceA(lppsp->hInstance,
493 (LPSTR)lppsp->u.pszTemplate,
494 (LPSTR)RT_DIALOG);
495 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
496 hResource);
497 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
501 * Extract the size of the page and the caption.
503 if (!pTemplate)
504 return FALSE;
506 p = (const WORD *)pTemplate;
508 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
510 /* DLGTEMPLATEEX (not defined in any std. header file) */
512 p++; /* dlgVer */
513 p++; /* signature */
514 p += 2; /* help ID */
515 p += 2; /* ext style */
516 p += 2; /* style */
518 else
520 /* DLGTEMPLATE */
522 p += 2; /* style */
523 p += 2; /* ext style */
526 p++; /* nb items */
527 p++; /* x */
528 p++; /* y */
529 width = (WORD)*p; p++;
530 height = (WORD)*p; p++;
532 /* Special calculation for interior wizard pages so the largest page is
533 * calculated correctly. We need to add all the padding and space occupied
534 * by the header so the width and height sums up to the whole wizard client
535 * area. */
536 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
537 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
538 !(dwFlags & PSP_HIDEHEADER))
540 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
541 width += 2 * WIZARD_PADDING;
543 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
545 height += 2 * WIZARD_PADDING;
546 width += 2 * WIZARD_PADDING;
549 /* remember the largest width and height */
550 if (width > psInfo->width)
551 psInfo->width = width;
553 if (height > psInfo->height)
554 psInfo->height = height;
556 /* menu */
557 switch ((WORD)*p)
559 case 0x0000:
560 p++;
561 break;
562 case 0xffff:
563 p += 2;
564 break;
565 default:
566 p += lstrlenW( (LPCWSTR)p ) + 1;
567 break;
570 /* class */
571 switch ((WORD)*p)
573 case 0x0000:
574 p++;
575 break;
576 case 0xffff:
577 p += 2;
578 break;
579 default:
580 p += lstrlenW( (LPCWSTR)p ) + 1;
581 break;
584 /* Extract the caption */
585 psInfo->proppage[index].pszText = (LPCWSTR)p;
586 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
587 p += lstrlenW((LPCWSTR)p) + 1;
589 if (dwFlags & PSP_USETITLE)
591 WCHAR szTitle[256];
592 const WCHAR *pTitle;
593 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
594 int len;
596 if ( !HIWORD( lppsp->pszTitle ) )
598 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
600 pTitle = pszNull;
601 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
603 else
604 pTitle = szTitle;
606 else
607 pTitle = lppsp->pszTitle;
609 len = strlenW(pTitle);
610 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
611 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
615 * Build the image list for icons
617 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
619 HICON hIcon;
620 int icon_cx = GetSystemMetrics(SM_CXSMICON);
621 int icon_cy = GetSystemMetrics(SM_CYSMICON);
623 if (dwFlags & PSP_USEICONID)
624 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
625 icon_cx, icon_cy, LR_DEFAULTCOLOR);
626 else
627 hIcon = lppsp->u2.hIcon;
629 if ( hIcon )
631 if (psInfo->hImageList == 0 )
632 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
634 ImageList_AddIcon(psInfo->hImageList, hIcon);
639 return TRUE;
642 /******************************************************************************
643 * PROPSHEET_CreateDialog
645 * Creates the actual property sheet.
647 INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
649 LRESULT ret;
650 LPCVOID template;
651 LPVOID temp = 0;
652 HRSRC hRes;
653 DWORD resSize;
654 WORD resID = IDD_PROPSHEET;
656 TRACE("\n");
657 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
658 resID = IDD_WIZARD;
660 if( psInfo->unicode )
662 if(!(hRes = FindResourceW(COMCTL32_hModule,
663 MAKEINTRESOURCEW(resID),
664 (LPWSTR)RT_DIALOG)))
665 return -1;
667 else
669 if(!(hRes = FindResourceA(COMCTL32_hModule,
670 MAKEINTRESOURCEA(resID),
671 (LPSTR)RT_DIALOG)))
672 return -1;
675 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
676 return -1;
679 * Make a copy of the dialog template.
681 resSize = SizeofResource(COMCTL32_hModule, hRes);
683 temp = Alloc(resSize);
685 if (!temp)
686 return -1;
688 memcpy(temp, template, resSize);
690 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
692 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
693 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
694 else
695 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
697 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
698 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
700 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
701 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
702 else
703 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
706 if (psInfo->useCallback)
707 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
709 /* NOTE: MSDN states "Returns a positive value if successful, or -1
710 * otherwise for modal property sheets.", but this is wrong. The
711 * actual return value is either TRUE (success), FALSE (cancel) or
712 * -1 (error). */
713 if( psInfo->unicode )
715 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
716 (LPDLGTEMPLATEW) temp,
717 psInfo->ppshheader.hwndParent,
718 PROPSHEET_DialogProc,
719 (LPARAM)psInfo);
720 if ( !ret ) ret = -1;
722 else
724 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
725 (LPDLGTEMPLATEA) temp,
726 psInfo->ppshheader.hwndParent,
727 PROPSHEET_DialogProc,
728 (LPARAM)psInfo);
729 if ( !ret ) ret = -1;
732 Free(temp);
734 return ret;
737 /******************************************************************************
738 * PROPSHEET_SizeMismatch
740 * Verify that the tab control and the "largest" property sheet page dlg. template
741 * match in size.
743 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
745 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
746 RECT rcOrigTab, rcPage;
749 * Original tab size.
751 GetClientRect(hwndTabCtrl, &rcOrigTab);
752 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
753 rcOrigTab.right, rcOrigTab.bottom);
756 * Biggest page size.
758 rcPage.left = 0;
759 rcPage.top = 0;
760 rcPage.right = psInfo->width;
761 rcPage.bottom = psInfo->height;
763 MapDialogRect(hwndDlg, &rcPage);
764 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
765 rcPage.right, rcPage.bottom);
767 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
768 return TRUE;
769 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
770 return TRUE;
772 return FALSE;
775 /******************************************************************************
776 * PROPSHEET_AdjustSize
778 * Resizes the property sheet and the tab control to fit the largest page.
780 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
782 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
783 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
784 RECT rc,tabRect;
785 int tabOffsetX, tabOffsetY, buttonHeight;
786 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
787 RECT units;
789 /* Get the height of buttons */
790 GetClientRect(hwndButton, &rc);
791 buttonHeight = rc.bottom;
794 * Biggest page size.
796 rc.left = 0;
797 rc.top = 0;
798 rc.right = psInfo->width;
799 rc.bottom = psInfo->height;
801 MapDialogRect(hwndDlg, &rc);
803 /* retrieve the dialog units */
804 units.left = units.right = 4;
805 units.top = units.bottom = 8;
806 MapDialogRect(hwndDlg, &units);
809 * Resize the tab control.
811 GetClientRect(hwndTabCtrl,&tabRect);
813 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
815 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
817 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
818 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
821 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
823 rc.right = rc.left + tabRect.right - tabRect.left;
824 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
827 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
829 tabOffsetX = -(rc.left);
830 tabOffsetY = -(rc.top);
832 rc.right -= rc.left;
833 rc.bottom -= rc.top;
834 TRACE("setting tab %p, rc (0,0)-(%ld,%ld)\n",
835 hwndTabCtrl, rc.right, rc.bottom);
836 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
837 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
839 GetClientRect(hwndTabCtrl, &rc);
841 TRACE("tab client rc %ld %ld %ld %ld\n",
842 rc.left, rc.top, rc.right, rc.bottom);
844 rc.right += ((padding.x * 2) + tabOffsetX);
845 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
848 * Resize the property sheet.
850 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
851 hwndDlg, rc.right, rc.bottom);
852 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
853 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
854 return TRUE;
857 /******************************************************************************
858 * PROPSHEET_AdjustSizeWizard
860 * Resizes the property sheet to fit the largest page.
862 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
864 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
865 RECT rc, lineRect, dialogRect;
867 /* Biggest page size */
868 rc.left = 0;
869 rc.top = 0;
870 rc.right = psInfo->width;
871 rc.bottom = psInfo->height;
872 MapDialogRect(hwndDlg, &rc);
874 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
876 /* Add space for the buttons row */
877 GetWindowRect(hwndLine, &lineRect);
878 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
879 GetClientRect(hwndDlg, &dialogRect);
880 rc.bottom += dialogRect.bottom - lineRect.top - 1;
882 /* Convert the client coordinates to window coordinates */
883 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
885 /* Resize the property sheet */
886 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
887 hwndDlg, rc.right, rc.bottom);
888 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
889 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
891 return TRUE;
894 /******************************************************************************
895 * PROPSHEET_AdjustButtons
897 * Adjusts the buttons' positions.
899 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
901 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
902 RECT rcSheet;
903 int x, y;
904 int num_buttons = 2;
905 int buttonWidth, buttonHeight;
906 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
908 if (psInfo->hasApply)
909 num_buttons++;
911 if (psInfo->hasHelp)
912 num_buttons++;
915 * Obtain the size of the buttons.
917 GetClientRect(hwndButton, &rcSheet);
918 buttonWidth = rcSheet.right;
919 buttonHeight = rcSheet.bottom;
922 * Get the size of the property sheet.
924 GetClientRect(hwndParent, &rcSheet);
927 * All buttons will be at this y coordinate.
929 y = rcSheet.bottom - (padding.y + buttonHeight);
932 * Position OK button and make it default.
934 hwndButton = GetDlgItem(hwndParent, IDOK);
936 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
938 SetWindowPos(hwndButton, 0, x, y, 0, 0,
939 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
941 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
945 * Position Cancel button.
947 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
949 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
951 SetWindowPos(hwndButton, 0, x, y, 0, 0,
952 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
955 * Position Apply button.
957 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
959 if (psInfo->hasApply)
961 if (psInfo->hasHelp)
962 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
963 else
964 x = rcSheet.right - (padding.x + buttonWidth);
966 SetWindowPos(hwndButton, 0, x, y, 0, 0,
967 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
969 EnableWindow(hwndButton, FALSE);
971 else
972 ShowWindow(hwndButton, SW_HIDE);
975 * Position Help button.
977 hwndButton = GetDlgItem(hwndParent, IDHELP);
979 if (psInfo->hasHelp)
981 x = rcSheet.right - (padding.x + buttonWidth);
983 SetWindowPos(hwndButton, 0, x, y, 0, 0,
984 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
986 else
987 ShowWindow(hwndButton, SW_HIDE);
989 return TRUE;
992 /******************************************************************************
993 * PROPSHEET_AdjustButtonsWizard
995 * Adjusts the buttons' positions.
997 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
998 PropSheetInfo* psInfo)
1000 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1001 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1002 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1003 RECT rcSheet;
1004 int x, y;
1005 int num_buttons = 3;
1006 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1007 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1009 if (psInfo->hasHelp)
1010 num_buttons++;
1011 if (psInfo->hasFinish)
1012 num_buttons++;
1015 * Obtain the size of the buttons.
1017 GetClientRect(hwndButton, &rcSheet);
1018 buttonWidth = rcSheet.right;
1019 buttonHeight = rcSheet.bottom;
1021 GetClientRect(hwndLine, &rcSheet);
1022 lineHeight = rcSheet.bottom;
1025 * Get the size of the property sheet.
1027 GetClientRect(hwndParent, &rcSheet);
1030 * All buttons will be at this y coordinate.
1032 y = rcSheet.bottom - (padding.y + buttonHeight);
1035 * Position the Back button.
1037 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1039 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1041 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1042 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1045 * Position the Next button.
1047 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1049 x += buttonWidth;
1051 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1052 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1055 * Position the Finish button.
1057 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1059 if (psInfo->hasFinish)
1060 x += padding.x + buttonWidth;
1062 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1063 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1065 if (!psInfo->hasFinish)
1066 ShowWindow(hwndButton, SW_HIDE);
1069 * Position the Cancel button.
1071 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1073 x += padding.x + buttonWidth;
1075 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1076 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1079 * Position Help button.
1081 hwndButton = GetDlgItem(hwndParent, IDHELP);
1083 if (psInfo->hasHelp)
1085 x += padding.x + buttonWidth;
1087 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1088 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1090 else
1091 ShowWindow(hwndButton, SW_HIDE);
1093 if (psInfo->ppshheader.dwFlags &
1094 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1095 padding.x = 0;
1098 * Position and resize the sunken line.
1100 x = padding.x;
1101 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1103 lineWidth = rcSheet.right - (padding.x * 2);
1104 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1105 SWP_NOZORDER | SWP_NOACTIVATE);
1108 * Position and resize the header sunken line.
1111 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1112 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1113 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1114 ShowWindow(hwndLineHeader, SW_HIDE);
1116 return TRUE;
1119 /******************************************************************************
1120 * PROPSHEET_GetPaddingInfo
1122 * Returns the layout information.
1124 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1126 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1127 RECT rcTab;
1128 POINT tl;
1129 PADDING_INFO padding;
1131 GetWindowRect(hwndTab, &rcTab);
1133 tl.x = rcTab.left;
1134 tl.y = rcTab.top;
1136 ScreenToClient(hwndDlg, &tl);
1138 padding.x = tl.x;
1139 padding.y = tl.y;
1141 return padding;
1144 /******************************************************************************
1145 * PROPSHEET_GetPaddingInfoWizard
1147 * Returns the layout information.
1148 * Vertical spacing is the distance between the line and the buttons.
1149 * Do NOT use the Help button to gather padding information when it isn't mapped
1150 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1151 * for it in this case !
1152 * FIXME: I'm not sure about any other coordinate problems with these evil
1153 * buttons. Fix it in case additional problems appear or maybe calculate
1154 * a padding in a completely different way, as this is somewhat messy.
1156 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1157 psInfo)
1159 PADDING_INFO padding;
1160 RECT rc;
1161 HWND hwndControl;
1162 INT idButton;
1163 POINT ptButton, ptLine;
1165 TRACE("\n");
1166 if (psInfo->hasHelp)
1168 idButton = IDHELP;
1170 else
1172 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1174 idButton = IDC_NEXT_BUTTON;
1176 else
1178 /* hopefully this is ok */
1179 idButton = IDCANCEL;
1183 hwndControl = GetDlgItem(hwndDlg, idButton);
1184 GetWindowRect(hwndControl, &rc);
1186 ptButton.x = rc.left;
1187 ptButton.y = rc.top;
1189 ScreenToClient(hwndDlg, &ptButton);
1191 /* Line */
1192 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1193 GetWindowRect(hwndControl, &rc);
1195 ptLine.x = rc.left;
1196 ptLine.y = rc.bottom;
1198 ScreenToClient(hwndDlg, &ptLine);
1200 padding.y = ptButton.y - ptLine.y;
1202 if (padding.y < 0)
1203 ERR("padding negative ! Please report this !\n");
1205 /* this is most probably not correct, but the best we have now */
1206 padding.x = padding.y;
1207 return padding;
1210 /******************************************************************************
1211 * PROPSHEET_CreateTabControl
1213 * Insert the tabs in the tab control.
1215 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1216 PropSheetInfo * psInfo)
1218 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1219 TCITEMW item;
1220 int i, nTabs;
1221 int iImage = 0;
1223 TRACE("\n");
1224 item.mask = TCIF_TEXT;
1225 item.cchTextMax = MAX_TABTEXT_LENGTH;
1227 nTabs = psInfo->nPages;
1230 * Set the image list for icons.
1232 if (psInfo->hImageList)
1234 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1237 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1238 for (i = 0; i < nTabs; i++)
1240 if ( psInfo->proppage[i].hasIcon )
1242 item.mask |= TCIF_IMAGE;
1243 item.iImage = iImage++;
1245 else
1247 item.mask &= ~TCIF_IMAGE;
1250 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1251 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1253 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1255 return TRUE;
1258 /******************************************************************************
1259 * PROPSHEET_WizardSubclassProc
1261 * Subclassing window procedure for wizard extrior pages to prevent drawing
1262 * background and so drawing above the watermark.
1264 static LRESULT CALLBACK
1265 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1267 switch (uMsg)
1269 case WM_ERASEBKGND:
1270 return TRUE;
1272 case WM_CTLCOLORSTATIC:
1273 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1274 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1277 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1281 * Get the size of an in-memory Template
1283 *( Based on the code of PROPSHEET_CollectPageInfo)
1284 * See also dialog.c/DIALOG_ParseTemplate32().
1287 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1290 const WORD* p = (const WORD *)pTemplate;
1291 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1292 WORD nrofitems;
1294 if (istemplateex)
1296 /* DLGTEMPLATEEX (not defined in any std. header file) */
1298 TRACE("is DLGTEMPLATEEX\n");
1299 p++; /* dlgVer */
1300 p++; /* signature */
1301 p += 2; /* help ID */
1302 p += 2; /* ext style */
1303 p += 2; /* style */
1305 else
1307 /* DLGTEMPLATE */
1309 TRACE("is DLGTEMPLATE\n");
1310 p += 2; /* style */
1311 p += 2; /* ext style */
1314 nrofitems = (WORD)*p; p++; /* nb items */
1315 p++; /* x */
1316 p++; /* y */
1317 p++; /* width */
1318 p++; /* height */
1320 /* menu */
1321 switch ((WORD)*p)
1323 case 0x0000:
1324 p++;
1325 break;
1326 case 0xffff:
1327 p += 2;
1328 break;
1329 default:
1330 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1331 p += lstrlenW( (LPCWSTR)p ) + 1;
1332 break;
1335 /* class */
1336 switch ((WORD)*p)
1338 case 0x0000:
1339 p++;
1340 break;
1341 case 0xffff:
1342 p += 2; /* 0xffff plus predefined window class ordinal value */
1343 break;
1344 default:
1345 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1346 p += lstrlenW( (LPCWSTR)p ) + 1;
1347 break;
1350 /* title */
1351 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1352 p += lstrlenW((LPCWSTR)p) + 1;
1354 /* font, if DS_SETFONT set */
1355 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1356 pTemplate->style)))
1358 p+=(istemplateex)?3:1;
1359 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1360 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1363 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1364 * that are following the DLGTEMPLATE(EX) data */
1365 TRACE("%d items\n",nrofitems);
1366 while (nrofitems > 0)
1368 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1370 /* skip header */
1371 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1373 /* check class */
1374 switch ((WORD)*p)
1376 case 0x0000:
1377 p++;
1378 break;
1379 case 0xffff:
1380 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1381 p += 2;
1382 break;
1383 default:
1384 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1385 p += lstrlenW( (LPCWSTR)p ) + 1;
1386 break;
1389 /* check title text */
1390 switch ((WORD)*p)
1392 case 0x0000:
1393 p++;
1394 break;
1395 case 0xffff:
1396 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1397 p += 2;
1398 break;
1399 default:
1400 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1401 p += lstrlenW( (LPCWSTR)p ) + 1;
1402 break;
1404 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1405 --nrofitems;
1408 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1409 return (p - (WORD*)pTemplate)*sizeof(WORD);
1413 /******************************************************************************
1414 * PROPSHEET_CreatePage
1416 * Creates a page.
1418 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1419 int index,
1420 const PropSheetInfo * psInfo,
1421 LPCPROPSHEETPAGEW ppshpage)
1423 DLGTEMPLATE* pTemplate;
1424 HWND hwndPage;
1425 DWORD resSize;
1426 LPVOID temp = NULL;
1428 TRACE("index %d\n", index);
1430 if (ppshpage == NULL)
1432 return FALSE;
1435 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1437 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1438 resSize = GetTemplateSize(pTemplate);
1440 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1442 HRSRC hResource;
1443 HANDLE hTemplate;
1445 hResource = FindResourceW(ppshpage->hInstance,
1446 ppshpage->u.pszTemplate,
1447 (LPWSTR)RT_DIALOG);
1448 if(!hResource)
1449 return FALSE;
1451 resSize = SizeofResource(ppshpage->hInstance, hResource);
1453 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1454 if(!hTemplate)
1455 return FALSE;
1457 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1459 * Make a copy of the dialog template to make it writable
1462 else
1464 HRSRC hResource;
1465 HANDLE hTemplate;
1467 hResource = FindResourceA(ppshpage->hInstance,
1468 (LPSTR)ppshpage->u.pszTemplate,
1469 (LPSTR)RT_DIALOG);
1470 if(!hResource)
1471 return FALSE;
1473 resSize = SizeofResource(ppshpage->hInstance, hResource);
1475 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1476 if(!hTemplate)
1477 return FALSE;
1479 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1481 * Make a copy of the dialog template to make it writable
1484 temp = Alloc(resSize);
1485 if (!temp)
1486 return FALSE;
1488 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1489 memcpy(temp, pTemplate, resSize);
1490 pTemplate = temp;
1492 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1494 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1495 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1496 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1497 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1498 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1500 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1501 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1503 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1505 else
1507 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1508 pTemplate->style &= ~DS_MODALFRAME;
1509 pTemplate->style &= ~WS_CAPTION;
1510 pTemplate->style &= ~WS_SYSMENU;
1511 pTemplate->style &= ~WS_POPUP;
1512 pTemplate->style &= ~WS_DISABLED;
1513 pTemplate->style &= ~WS_VISIBLE;
1514 pTemplate->style &= ~WS_THICKFRAME;
1516 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1519 if (psInfo->proppage[index].useCallback)
1520 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1521 (LPPROPSHEETPAGEW)ppshpage);
1523 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1524 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1525 pTemplate,
1526 hwndParent,
1527 ppshpage->pfnDlgProc,
1528 (LPARAM)ppshpage);
1529 else
1530 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1531 pTemplate,
1532 hwndParent,
1533 ppshpage->pfnDlgProc,
1534 (LPARAM)ppshpage);
1535 /* Free a no more needed copy */
1536 if(temp)
1537 Free(temp);
1539 psInfo->proppage[index].hwndPage = hwndPage;
1541 /* Subclass exterior wizard pages */
1542 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1543 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1544 (ppshpage->dwFlags & PSP_HIDEHEADER))
1546 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1547 (DWORD_PTR)ppshpage);
1549 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1550 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1552 return TRUE;
1555 /******************************************************************************
1556 * PROPSHEET_LoadWizardBitmaps
1558 * Loads the watermark and header bitmaps for a wizard.
1560 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1562 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1564 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1565 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1566 considers hbmWatermark as valid. */
1567 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1568 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1570 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1571 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1574 /* Same behavior as for watermarks */
1575 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1576 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1578 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1579 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1585 /******************************************************************************
1586 * PROPSHEET_ShowPage
1588 * Displays or creates the specified page.
1590 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1592 HWND hwndTabCtrl;
1593 HWND hwndLineHeader;
1594 LPCPROPSHEETPAGEW ppshpage;
1596 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1597 if (index == psInfo->active_page)
1599 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1600 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1601 return TRUE;
1604 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1605 if (psInfo->proppage[index].hwndPage == 0)
1607 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1610 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1611 (ppshpage->dwFlags & PSP_USETITLE))
1613 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1614 psInfo->proppage[index].pszText);
1617 if (psInfo->active_page != -1)
1618 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1620 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1622 /* Synchronize current selection with tab control
1623 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1624 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1625 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1627 psInfo->active_page = index;
1628 psInfo->activeValid = TRUE;
1630 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1632 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1633 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1635 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1636 ShowWindow(hwndLineHeader, SW_HIDE);
1637 else
1638 ShowWindow(hwndLineHeader, SW_SHOW);
1641 return TRUE;
1644 /******************************************************************************
1645 * PROPSHEET_Back
1647 static BOOL PROPSHEET_Back(HWND hwndDlg)
1649 PSHNOTIFY psn;
1650 HWND hwndPage;
1651 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1652 PropSheetInfoStr);
1653 LRESULT result;
1654 int idx;
1656 TRACE("active_page %d\n", psInfo->active_page);
1657 if (psInfo->active_page < 0)
1658 return FALSE;
1660 psn.hdr.code = PSN_WIZBACK;
1661 psn.hdr.hwndFrom = hwndDlg;
1662 psn.hdr.idFrom = 0;
1663 psn.lParam = 0;
1665 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1667 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1668 if (result == -1)
1669 return FALSE;
1670 else if (result == 0)
1671 idx = psInfo->active_page - 1;
1672 else
1673 idx = PROPSHEET_FindPageByResId(psInfo, result);
1675 if (idx >= 0 && idx < psInfo->nPages)
1677 if (PROPSHEET_CanSetCurSel(hwndDlg))
1678 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1680 return TRUE;
1683 /******************************************************************************
1684 * PROPSHEET_Next
1686 static BOOL PROPSHEET_Next(HWND hwndDlg)
1688 PSHNOTIFY psn;
1689 HWND hwndPage;
1690 LRESULT msgResult = 0;
1691 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1692 PropSheetInfoStr);
1693 int idx;
1695 TRACE("active_page %d\n", psInfo->active_page);
1696 if (psInfo->active_page < 0)
1697 return FALSE;
1699 psn.hdr.code = PSN_WIZNEXT;
1700 psn.hdr.hwndFrom = hwndDlg;
1701 psn.hdr.idFrom = 0;
1702 psn.lParam = 0;
1704 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1706 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1707 if (msgResult == -1)
1708 return FALSE;
1709 else if (msgResult == 0)
1710 idx = psInfo->active_page + 1;
1711 else
1712 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1714 if (idx < psInfo->nPages )
1716 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1717 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1720 return TRUE;
1723 /******************************************************************************
1724 * PROPSHEET_Finish
1726 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1728 PSHNOTIFY psn;
1729 HWND hwndPage;
1730 LRESULT msgResult = 0;
1731 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1732 PropSheetInfoStr);
1734 TRACE("active_page %d\n", psInfo->active_page);
1735 if (psInfo->active_page < 0)
1736 return FALSE;
1738 psn.hdr.code = PSN_WIZFINISH;
1739 psn.hdr.hwndFrom = hwndDlg;
1740 psn.hdr.idFrom = 0;
1741 psn.lParam = 0;
1743 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1745 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1747 TRACE("msg result %ld\n", msgResult);
1749 if (msgResult != 0)
1750 return FALSE;
1752 if (psInfo->isModeless)
1753 psInfo->activeValid = FALSE;
1754 else
1756 psInfo->ended = TRUE;
1757 psInfo->returned = 1;
1760 return TRUE;
1763 /******************************************************************************
1764 * PROPSHEET_Apply
1766 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1768 int i;
1769 HWND hwndPage;
1770 PSHNOTIFY psn;
1771 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1772 PropSheetInfoStr);
1774 TRACE("active_page %d\n", psInfo->active_page);
1775 if (psInfo->active_page < 0)
1776 return FALSE;
1778 psn.hdr.hwndFrom = hwndDlg;
1779 psn.hdr.idFrom = 0;
1780 psn.lParam = 0;
1784 * Send PSN_KILLACTIVE to the current page.
1786 psn.hdr.code = PSN_KILLACTIVE;
1788 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1790 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1791 return FALSE;
1794 * Send PSN_APPLY to all pages.
1796 psn.hdr.code = PSN_APPLY;
1797 psn.lParam = lParam;
1799 for (i = 0; i < psInfo->nPages; i++)
1801 hwndPage = psInfo->proppage[i].hwndPage;
1802 if (hwndPage)
1804 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1806 case PSNRET_INVALID:
1807 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1808 /* fall through */
1809 case PSNRET_INVALID_NOCHANGEPAGE:
1810 return FALSE;
1815 if(lParam)
1817 psInfo->activeValid = FALSE;
1819 else if(psInfo->active_page >= 0)
1821 psn.hdr.code = PSN_SETACTIVE;
1822 psn.lParam = 0;
1823 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1824 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1827 return TRUE;
1830 /******************************************************************************
1831 * PROPSHEET_Cancel
1833 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1835 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1836 PropSheetInfoStr);
1837 HWND hwndPage;
1838 PSHNOTIFY psn;
1839 int i;
1841 TRACE("active_page %d\n", psInfo->active_page);
1842 if (psInfo->active_page < 0)
1843 return;
1845 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1846 psn.hdr.code = PSN_QUERYCANCEL;
1847 psn.hdr.hwndFrom = hwndDlg;
1848 psn.hdr.idFrom = 0;
1849 psn.lParam = 0;
1851 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1852 return;
1854 psn.hdr.code = PSN_RESET;
1855 psn.lParam = lParam;
1857 for (i = 0; i < psInfo->nPages; i++)
1859 hwndPage = psInfo->proppage[i].hwndPage;
1861 if (hwndPage)
1862 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1865 if (psInfo->isModeless)
1867 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1868 psInfo->activeValid = FALSE;
1870 else
1872 psInfo->ended = TRUE;
1873 psInfo->returned = 0;
1877 /******************************************************************************
1878 * PROPSHEET_Help
1880 static void PROPSHEET_Help(HWND hwndDlg)
1882 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1883 PropSheetInfoStr);
1884 HWND hwndPage;
1885 PSHNOTIFY psn;
1887 TRACE("active_page %d\n", psInfo->active_page);
1888 if (psInfo->active_page < 0)
1889 return;
1891 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1892 psn.hdr.code = PSN_HELP;
1893 psn.hdr.hwndFrom = hwndDlg;
1894 psn.hdr.idFrom = 0;
1895 psn.lParam = 0;
1897 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1900 /******************************************************************************
1901 * PROPSHEET_Changed
1903 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1905 int i;
1906 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1907 PropSheetInfoStr);
1909 TRACE("\n");
1910 if (!psInfo) return;
1912 * Set the dirty flag of this page.
1914 for (i = 0; i < psInfo->nPages; i++)
1916 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1917 psInfo->proppage[i].isDirty = TRUE;
1921 * Enable the Apply button.
1923 if (psInfo->hasApply)
1925 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1927 EnableWindow(hwndApplyBtn, TRUE);
1931 /******************************************************************************
1932 * PROPSHEET_UnChanged
1934 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1936 int i;
1937 BOOL noPageDirty = TRUE;
1938 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1939 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1940 PropSheetInfoStr);
1942 TRACE("\n");
1943 if ( !psInfo ) return;
1944 for (i = 0; i < psInfo->nPages; i++)
1946 /* set the specified page as clean */
1947 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1948 psInfo->proppage[i].isDirty = FALSE;
1950 /* look to see if there's any dirty pages */
1951 if (psInfo->proppage[i].isDirty)
1952 noPageDirty = FALSE;
1956 * Disable Apply button.
1958 if (noPageDirty)
1959 EnableWindow(hwndApplyBtn, FALSE);
1962 /******************************************************************************
1963 * PROPSHEET_PressButton
1965 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1967 TRACE("buttonID %d\n", buttonID);
1968 switch (buttonID)
1970 case PSBTN_APPLYNOW:
1971 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1972 break;
1973 case PSBTN_BACK:
1974 PROPSHEET_Back(hwndDlg);
1975 break;
1976 case PSBTN_CANCEL:
1977 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1978 break;
1979 case PSBTN_FINISH:
1980 PROPSHEET_Finish(hwndDlg);
1981 break;
1982 case PSBTN_HELP:
1983 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1984 break;
1985 case PSBTN_NEXT:
1986 PROPSHEET_Next(hwndDlg);
1987 break;
1988 case PSBTN_OK:
1989 PROPSHEET_DoCommand(hwndDlg, IDOK);
1990 break;
1991 default:
1992 FIXME("Invalid button index %d\n", buttonID);
1997 /*************************************************************************
1998 * BOOL PROPSHEET_CanSetCurSel [Internal]
2000 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2002 * PARAMS
2003 * hwndDlg [I] handle to a Dialog hWnd
2005 * RETURNS
2006 * TRUE if Current Selection can change
2008 * NOTES
2010 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2012 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2013 PropSheetInfoStr);
2014 HWND hwndPage;
2015 PSHNOTIFY psn;
2016 BOOL res = FALSE;
2018 TRACE("active_page %d\n", psInfo->active_page);
2019 if (!psInfo)
2021 res = FALSE;
2022 goto end;
2025 if (psInfo->active_page < 0)
2027 res = TRUE;
2028 goto end;
2032 * Notify the current page.
2034 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2035 psn.hdr.code = PSN_KILLACTIVE;
2036 psn.hdr.hwndFrom = hwndDlg;
2037 psn.hdr.idFrom = 0;
2038 psn.lParam = 0;
2040 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2042 end:
2043 TRACE("<-- %d\n", res);
2044 return res;
2047 /******************************************************************************
2048 * PROPSHEET_SetCurSel
2050 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2051 int index,
2052 int skipdir,
2053 HPROPSHEETPAGE hpage
2056 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2057 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2058 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2060 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2061 /* hpage takes precedence over index */
2062 if (hpage != NULL)
2063 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2065 if (index < 0 || index >= psInfo->nPages)
2067 TRACE("Could not find page to select!\n");
2068 return FALSE;
2071 while (1) {
2072 int result;
2073 PSHNOTIFY psn;
2074 RECT rc;
2075 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2077 if (hwndTabControl)
2078 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2080 psn.hdr.code = PSN_SETACTIVE;
2081 psn.hdr.hwndFrom = hwndDlg;
2082 psn.hdr.idFrom = 0;
2083 psn.lParam = 0;
2085 if (!psInfo->proppage[index].hwndPage) {
2086 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2089 /* Resize the property sheet page to the fit in the Tab control
2090 * (for regular property sheets) or to fit in the client area (for
2091 * wizards).
2092 * NOTE: The resizing happens every time the page is selected and
2093 * not only when it's created (some applications depend on it). */
2094 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2095 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2096 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2097 rc.right - rc.left, rc.bottom - rc.top);
2098 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2099 rc.left, rc.top,
2100 rc.right - rc.left, rc.bottom - rc.top, 0);
2102 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2103 if (!result)
2104 break;
2105 if (result == -1) {
2106 index+=skipdir;
2107 if (index < 0) {
2108 index = 0;
2109 WARN("Tried to skip before first property sheet page!\n");
2110 break;
2112 if (index >= psInfo->nPages) {
2113 WARN("Tried to skip after last property sheet page!\n");
2114 index = psInfo->nPages-1;
2115 break;
2118 else if (result != 0)
2120 int old_index = index;
2121 index = PROPSHEET_FindPageByResId(psInfo, result);
2122 if(index >= psInfo->nPages) {
2123 index = old_index;
2124 WARN("Tried to skip to nonexistant page by res id\n");
2125 break;
2127 continue;
2131 * Display the new page.
2133 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2135 if (psInfo->proppage[index].hasHelp)
2136 EnableWindow(hwndHelp, TRUE);
2137 else
2138 EnableWindow(hwndHelp, FALSE);
2140 return TRUE;
2143 /******************************************************************************
2144 * PROPSHEET_SetCurSelId
2146 * Selects the page, specified by resource id.
2148 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2150 int idx;
2151 PropSheetInfo* psInfo =
2152 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2154 idx = PROPSHEET_FindPageByResId(psInfo, id);
2155 if (idx < psInfo->nPages )
2157 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2158 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2162 /******************************************************************************
2163 * PROPSHEET_SetTitleA
2165 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2167 if(HIWORD(lpszText))
2169 WCHAR szTitle[256];
2170 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2171 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2172 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2174 else
2176 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2180 /******************************************************************************
2181 * PROPSHEET_SetTitleW
2183 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2185 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2186 WCHAR szTitle[256];
2188 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2189 if (HIWORD(lpszText) == 0) {
2190 if (!LoadStringW(psInfo->ppshheader.hInstance,
2191 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2192 return;
2193 lpszText = szTitle;
2195 if (dwStyle & PSH_PROPTITLE)
2197 WCHAR* dest;
2198 int lentitle = strlenW(lpszText);
2199 int lenprop = strlenW(psInfo->strPropertiesFor);
2201 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2202 strcpyW(dest, psInfo->strPropertiesFor);
2203 strcatW(dest, lpszText);
2205 SetWindowTextW(hwndDlg, dest);
2206 Free(dest);
2208 else
2209 SetWindowTextW(hwndDlg, lpszText);
2212 /******************************************************************************
2213 * PROPSHEET_SetFinishTextA
2215 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2217 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2218 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2220 TRACE("'%s'\n", lpszText);
2221 /* Set text, show and enable the Finish button */
2222 SetWindowTextA(hwndButton, lpszText);
2223 ShowWindow(hwndButton, SW_SHOW);
2224 EnableWindow(hwndButton, TRUE);
2226 /* Make it default pushbutton */
2227 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2229 /* Hide Back button */
2230 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2231 ShowWindow(hwndButton, SW_HIDE);
2233 if (!psInfo->hasFinish)
2235 /* Hide Next button */
2236 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2237 ShowWindow(hwndButton, SW_HIDE);
2241 /******************************************************************************
2242 * PROPSHEET_SetFinishTextW
2244 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2246 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2247 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2249 TRACE("'%s'\n", debugstr_w(lpszText));
2250 /* Set text, show and enable the Finish button */
2251 SetWindowTextW(hwndButton, lpszText);
2252 ShowWindow(hwndButton, SW_SHOW);
2253 EnableWindow(hwndButton, TRUE);
2255 /* Make it default pushbutton */
2256 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2258 /* Hide Back button */
2259 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2260 ShowWindow(hwndButton, SW_HIDE);
2262 if (!psInfo->hasFinish)
2264 /* Hide Next button */
2265 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2266 ShowWindow(hwndButton, SW_HIDE);
2270 /******************************************************************************
2271 * PROPSHEET_QuerySiblings
2273 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2274 WPARAM wParam, LPARAM lParam)
2276 int i = 0;
2277 HWND hwndPage;
2278 LRESULT msgResult = 0;
2279 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2281 while ((i < psInfo->nPages) && (msgResult == 0))
2283 hwndPage = psInfo->proppage[i].hwndPage;
2284 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2285 i++;
2288 return msgResult;
2292 /******************************************************************************
2293 * PROPSHEET_AddPage
2295 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2296 HPROPSHEETPAGE hpage)
2298 PropPageInfo * ppi;
2299 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2300 PropSheetInfoStr);
2301 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2302 TCITEMW item;
2303 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2305 TRACE("hpage %p\n", hpage);
2307 * Allocate and fill in a new PropPageInfo entry.
2309 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2310 sizeof(PropPageInfo) *
2311 (psInfo->nPages + 1));
2312 if (!ppi)
2313 return FALSE;
2315 psInfo->proppage = ppi;
2316 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2317 return FALSE;
2319 psInfo->proppage[psInfo->nPages].hpage = hpage;
2321 if (ppsp->dwFlags & PSP_PREMATURE)
2323 /* Create the page but don't show it */
2324 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2328 * Add a new tab to the tab control.
2330 item.mask = TCIF_TEXT;
2331 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2332 item.cchTextMax = MAX_TABTEXT_LENGTH;
2334 if (psInfo->hImageList)
2336 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2339 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2341 item.mask |= TCIF_IMAGE;
2342 item.iImage = psInfo->nPages;
2345 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2346 (LPARAM)&item);
2348 psInfo->nPages++;
2350 /* If it is the only page - show it */
2351 if(psInfo->nPages == 1)
2352 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2353 return TRUE;
2356 /******************************************************************************
2357 * PROPSHEET_RemovePage
2359 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2360 int index,
2361 HPROPSHEETPAGE hpage)
2363 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2364 PropSheetInfoStr);
2365 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2366 PropPageInfo* oldPages;
2368 TRACE("index %d, hpage %p\n", index, hpage);
2369 if (!psInfo) {
2370 return FALSE;
2373 * hpage takes precedence over index.
2375 if (hpage != 0)
2377 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2380 /* Make sure that index is within range */
2381 if (index < 0 || index >= psInfo->nPages)
2383 TRACE("Could not find page to remove!\n");
2384 return FALSE;
2387 TRACE("total pages %d removing page %d active page %d\n",
2388 psInfo->nPages, index, psInfo->active_page);
2390 * Check if we're removing the active page.
2392 if (index == psInfo->active_page)
2394 if (psInfo->nPages > 1)
2396 if (index > 0)
2398 /* activate previous page */
2399 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2401 else
2403 /* activate the next page */
2404 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2405 psInfo->active_page = index;
2408 else
2410 psInfo->active_page = -1;
2411 if (!psInfo->isModeless)
2413 psInfo->ended = TRUE;
2414 psInfo->returned = 0;
2415 return TRUE;
2419 else if (index < psInfo->active_page)
2420 psInfo->active_page--;
2422 /* Unsubclass the page dialog window */
2423 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2424 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2425 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2427 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2428 PROPSHEET_WizardSubclassProc, 1);
2431 /* Destroy page dialog window */
2432 DestroyWindow(psInfo->proppage[index].hwndPage);
2434 /* Free page resources */
2435 if(psInfo->proppage[index].hpage)
2437 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2439 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2440 Free ((LPVOID)psInfo->proppage[index].pszText);
2442 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2445 /* Remove the tab */
2446 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2448 oldPages = psInfo->proppage;
2449 psInfo->nPages--;
2450 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2452 if (index > 0)
2453 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2455 if (index < psInfo->nPages)
2456 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2457 (psInfo->nPages - index) * sizeof(PropPageInfo));
2459 Free(oldPages);
2461 return FALSE;
2464 /******************************************************************************
2465 * PROPSHEET_SetWizButtons
2467 * This code will work if (and assumes that) the Next button is on top of the
2468 * Finish button. ie. Finish comes after Next in the Z order.
2469 * This means make sure the dialog template reflects this.
2472 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2474 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2475 PropSheetInfoStr);
2476 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2477 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2478 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2480 TRACE("%ld\n", dwFlags);
2482 EnableWindow(hwndBack, FALSE);
2483 EnableWindow(hwndNext, FALSE);
2484 EnableWindow(hwndFinish, FALSE);
2486 if (dwFlags & PSWIZB_BACK)
2487 EnableWindow(hwndBack, TRUE);
2489 if (dwFlags & PSWIZB_NEXT)
2491 if (!psInfo->hasFinish)
2493 /* Hide the Finish button */
2494 ShowWindow(hwndFinish, SW_HIDE);
2497 /* Show and enable the Next button */
2498 ShowWindow(hwndNext, SW_SHOW);
2499 EnableWindow(hwndNext, TRUE);
2501 /* Set the Next button as the default pushbutton */
2502 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2505 if (!psInfo->hasFinish)
2507 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2509 /* Hide the Next button */
2510 ShowWindow(hwndNext, SW_HIDE);
2512 /* Show the Finish button */
2513 ShowWindow(hwndFinish, SW_SHOW);
2515 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2517 EnableWindow(hwndFinish, TRUE);
2519 /* Set the Finish button as the default pushbutton */
2520 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2524 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2525 EnableWindow(hwndFinish, TRUE);
2528 /******************************************************************************
2529 * PROPSHEET_InsertPage
2531 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2533 if (!HIWORD(hpageInsertAfter))
2534 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2535 else
2536 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2537 return FALSE;
2540 /******************************************************************************
2541 * PROPSHEET_SetHeaderTitleW
2543 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2545 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2548 /******************************************************************************
2549 * PROPSHEET_SetHeaderTitleA
2551 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2553 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2556 /******************************************************************************
2557 * PROPSHEET_SetHeaderSubTitleW
2559 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2561 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2564 /******************************************************************************
2565 * PROPSHEET_SetHeaderSubTitleA
2567 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2569 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2572 /******************************************************************************
2573 * PROPSHEET_HwndToIndex
2575 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2577 int index;
2578 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2579 PropSheetInfoStr);
2581 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2583 for (index = 0; index < psInfo->nPages; index++)
2584 if (psInfo->proppage[index].hwndPage == hPageDlg)
2585 return index;
2586 WARN("%p not found\n", hPageDlg);
2587 return -1;
2590 /******************************************************************************
2591 * PROPSHEET_IndexToHwnd
2593 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2595 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2596 PropSheetInfoStr);
2597 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2598 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2599 WARN("%d out of range.\n", iPageIndex);
2600 return 0;
2602 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2605 /******************************************************************************
2606 * PROPSHEET_PageToIndex
2608 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2610 int index;
2611 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2612 PropSheetInfoStr);
2614 TRACE("(%p, %p)\n", hwndDlg, hPage);
2616 for (index = 0; index < psInfo->nPages; index++)
2617 if (psInfo->proppage[index].hpage == hPage)
2618 return index;
2619 WARN("%p not found\n", hPage);
2620 return -1;
2623 /******************************************************************************
2624 * PROPSHEET_IndexToPage
2626 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2628 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2629 PropSheetInfoStr);
2630 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2631 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2632 WARN("%d out of range.\n", iPageIndex);
2633 return 0;
2635 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2638 /******************************************************************************
2639 * PROPSHEET_IdToIndex
2641 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2643 int index;
2644 LPCPROPSHEETPAGEW psp;
2645 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2646 PropSheetInfoStr);
2647 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2648 for (index = 0; index < psInfo->nPages; index++) {
2649 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2650 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2651 return index;
2654 return -1;
2657 /******************************************************************************
2658 * PROPSHEET_IndexToId
2660 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2662 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2663 PropSheetInfoStr);
2664 LPCPROPSHEETPAGEW psp;
2665 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2666 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2667 WARN("%d out of range.\n", iPageIndex);
2668 return 0;
2670 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2671 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2672 return 0;
2674 return (LRESULT)psp->u.pszTemplate;
2677 /******************************************************************************
2678 * PROPSHEET_GetResult
2680 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2682 FIXME("(%p): stub\n", hwndDlg);
2683 return -1;
2686 /******************************************************************************
2687 * PROPSHEET_RecalcPageSizes
2689 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2691 FIXME("(%p): stub\n", hwndDlg);
2692 return FALSE;
2695 /******************************************************************************
2696 * PROPSHEET_GetPageIndex
2698 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2699 * the array of PropPageInfo.
2701 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2703 BOOL found = FALSE;
2704 int index = 0;
2706 TRACE("hpage %p\n", hpage);
2707 while ((index < psInfo->nPages) && (found == FALSE))
2709 if (psInfo->proppage[index].hpage == hpage)
2710 found = TRUE;
2711 else
2712 index++;
2715 if (found == FALSE)
2716 index = -1;
2718 return index;
2721 /******************************************************************************
2722 * PROPSHEET_CleanUp
2724 static void PROPSHEET_CleanUp(HWND hwndDlg)
2726 int i;
2727 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2728 PropSheetInfoStr);
2730 TRACE("\n");
2731 if (!psInfo) return;
2732 if (HIWORD(psInfo->ppshheader.pszCaption))
2733 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2735 for (i = 0; i < psInfo->nPages; i++)
2737 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2739 /* Unsubclass the page dialog window */
2740 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2741 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2742 (psp->dwFlags & PSP_HIDEHEADER))
2744 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2745 PROPSHEET_WizardSubclassProc, 1);
2748 if(psInfo->proppage[i].hwndPage)
2749 DestroyWindow(psInfo->proppage[i].hwndPage);
2751 if(psp)
2753 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2754 Free ((LPVOID)psInfo->proppage[i].pszText);
2756 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2760 DeleteObject(psInfo->hFont);
2761 DeleteObject(psInfo->hFontBold);
2762 /* If we created the bitmaps, destroy them */
2763 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2764 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2765 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2766 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2767 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2768 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2770 Free(psInfo->proppage);
2771 Free(psInfo->strPropertiesFor);
2772 ImageList_Destroy(psInfo->hImageList);
2774 GlobalFree((HGLOBAL)psInfo);
2777 static INT do_loop(PropSheetInfo *psInfo)
2779 MSG msg;
2780 INT ret = -1;
2781 HWND hwnd = psInfo->hwnd;
2783 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2785 if(ret == -1)
2786 break;
2788 if(!IsDialogMessageW(hwnd, &msg))
2790 TranslateMessage(&msg);
2791 DispatchMessageW(&msg);
2796 if(ret == 0)
2798 PostQuitMessage(msg.wParam);
2799 ret = -1;
2802 if (psInfo->ended && ret > 0)
2803 ret = psInfo->returned;
2805 DestroyWindow(hwnd);
2806 return ret;
2809 /******************************************************************************
2810 * PropertySheet (COMCTL32.@)
2811 * PropertySheetA (COMCTL32.@)
2813 * Creates a property sheet in the specified property sheet header.
2815 * RETURNS
2816 * Modal property sheets: Positive if successful or -1 otherwise.
2817 * Modeless property sheets: Property sheet handle.
2818 * Or:
2819 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2820 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2822 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2824 INT_PTR bRet = 0;
2825 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2826 sizeof(PropSheetInfo));
2827 UINT i, n;
2828 BYTE* pByte;
2830 TRACE("(%p)\n", lppsh);
2832 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2834 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2835 lppsh->nPages);
2836 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2838 for (n = i = 0; i < lppsh->nPages; i++, n++)
2840 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2841 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2842 else
2844 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2845 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2848 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2849 psInfo, n))
2851 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2852 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2853 n--;
2854 psInfo->nPages--;
2858 psInfo->unicode = FALSE;
2859 psInfo->ended = FALSE;
2861 bRet = PROPSHEET_CreateDialog(psInfo);
2862 if(!psInfo->isModeless)
2863 bRet = do_loop(psInfo);
2865 return bRet;
2868 /******************************************************************************
2869 * PropertySheetW (COMCTL32.@)
2871 * See PropertySheetA.
2873 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2875 INT_PTR bRet = 0;
2876 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2877 sizeof(PropSheetInfo));
2878 UINT i, n;
2879 BYTE* pByte;
2881 TRACE("(%p)\n", lppsh);
2883 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2885 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2886 lppsh->nPages);
2887 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2889 for (n = i = 0; i < lppsh->nPages; i++, n++)
2891 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2892 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2893 else
2895 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2896 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2899 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2900 psInfo, n))
2902 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2903 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2904 n--;
2905 psInfo->nPages--;
2909 psInfo->unicode = TRUE;
2910 psInfo->ended = FALSE;
2912 bRet = PROPSHEET_CreateDialog(psInfo);
2913 if(!psInfo->isModeless)
2914 bRet = do_loop(psInfo);
2916 return bRet;
2919 /******************************************************************************
2920 * CreatePropertySheetPage (COMCTL32.@)
2921 * CreatePropertySheetPageA (COMCTL32.@)
2923 * Creates a new property sheet page.
2925 * RETURNS
2926 * Success: Handle to new property sheet page.
2927 * Failure: NULL.
2929 * NOTES
2930 * An application must use the PSM_ADDPAGE message to add the new page to
2931 * an existing property sheet.
2933 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2934 LPCPROPSHEETPAGEA lpPropSheetPage)
2936 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2938 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2940 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2941 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2943 int len = strlen(lpPropSheetPage->u.pszTemplate);
2945 ppsp->u.pszTemplate = Alloc( len+1 );
2946 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2948 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2950 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2953 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2955 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2957 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2958 ppsp->pszTitle = NULL;
2960 return (HPROPSHEETPAGE)ppsp;
2963 /******************************************************************************
2964 * CreatePropertySheetPageW (COMCTL32.@)
2966 * See CreatePropertySheetA.
2968 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2970 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2972 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2974 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2976 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2978 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2980 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2981 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2983 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2985 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2986 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2987 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2990 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2992 int len = strlenW(lpPropSheetPage->pszTitle);
2993 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2994 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2996 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2997 ppsp->pszTitle = NULL;
2999 return (HPROPSHEETPAGE)ppsp;
3002 /******************************************************************************
3003 * DestroyPropertySheetPage (COMCTL32.@)
3005 * Destroys a property sheet page previously created with
3006 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3007 * memory.
3009 * RETURNS
3010 * Success: TRUE
3011 * Failure: FALSE
3013 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3015 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3017 if (!psp)
3018 return FALSE;
3020 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3021 Free ((LPVOID)psp->u.pszTemplate);
3023 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3024 Free ((LPVOID)psp->u2.pszIcon);
3026 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3027 Free ((LPVOID)psp->pszTitle);
3029 Free(hPropPage);
3031 return TRUE;
3034 /******************************************************************************
3035 * PROPSHEET_IsDialogMessage
3037 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3039 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3041 TRACE("\n");
3042 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3043 return FALSE;
3045 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3047 int new_page = 0;
3048 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3050 if (!(dlgCode & DLGC_WANTMESSAGE))
3052 switch (lpMsg->wParam)
3054 case VK_TAB:
3055 if (GetKeyState(VK_SHIFT) & 0x8000)
3056 new_page = -1;
3057 else
3058 new_page = 1;
3059 break;
3061 case VK_NEXT: new_page = 1; break;
3062 case VK_PRIOR: new_page = -1; break;
3066 if (new_page)
3068 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3070 new_page += psInfo->active_page;
3072 if (new_page < 0)
3073 new_page = psInfo->nPages - 1;
3074 else if (new_page >= psInfo->nPages)
3075 new_page = 0;
3077 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3080 return TRUE;
3084 return IsDialogMessageW(hwnd, lpMsg);
3087 /******************************************************************************
3088 * PROPSHEET_DoCommand
3090 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3093 switch (wID) {
3095 case IDOK:
3096 case IDC_APPLY_BUTTON:
3098 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3100 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3101 break;
3103 if (wID == IDOK)
3105 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3106 PropSheetInfoStr);
3107 int result = TRUE;
3109 if (psInfo->restartWindows)
3110 result = ID_PSRESTARTWINDOWS;
3112 /* reboot system takes precedence over restart windows */
3113 if (psInfo->rebootSystem)
3114 result = ID_PSREBOOTSYSTEM;
3116 if (psInfo->isModeless)
3117 psInfo->activeValid = FALSE;
3118 else
3120 psInfo->ended = TRUE;
3121 psInfo->returned = 1;
3124 else
3125 EnableWindow(hwndApplyBtn, FALSE);
3127 break;
3130 case IDC_BACK_BUTTON:
3131 PROPSHEET_Back(hwnd);
3132 break;
3134 case IDC_NEXT_BUTTON:
3135 PROPSHEET_Next(hwnd);
3136 break;
3138 case IDC_FINISH_BUTTON:
3139 PROPSHEET_Finish(hwnd);
3140 break;
3142 case IDCANCEL:
3143 PROPSHEET_Cancel(hwnd, 0);
3144 break;
3146 case IDHELP:
3147 PROPSHEET_Help(hwnd);
3148 break;
3150 default:
3151 return FALSE;
3154 return TRUE;
3157 /******************************************************************************
3158 * PROPSHEET_Paint
3160 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3162 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3163 PAINTSTRUCT ps;
3164 HDC hdc, hdcSrc;
3165 BITMAP bm;
3166 HBITMAP hbmp;
3167 HPALETTE hOldPal = 0;
3168 int offsety = 0;
3169 HBRUSH hbr;
3170 RECT r, rzone;
3171 LPCPROPSHEETPAGEW ppshpage;
3172 WCHAR szBuffer[256];
3173 int nLength;
3175 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3176 if (!hdc) return 1;
3178 hdcSrc = CreateCompatibleDC(0);
3179 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3181 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3182 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3184 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3185 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3186 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3188 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3189 HFONT hOldFont;
3190 COLORREF clrOld = 0;
3191 int oldBkMode = 0;
3193 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3194 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3196 GetClientRect(hwndLineHeader, &r);
3197 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3198 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3200 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3202 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3204 /* Fill the unoccupied part of the header with color of the
3205 * left-top pixel, but do it only when needed.
3207 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3209 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3210 CopyRect(&r, &rzone);
3211 if (bm.bmWidth < r.right)
3213 r.left = bm.bmWidth;
3214 FillRect(hdc, &r, hbr);
3216 if (bm.bmHeight < r.bottom)
3218 r.left = 0;
3219 r.top = bm.bmHeight;
3220 FillRect(hdc, &r, hbr);
3222 DeleteObject(hbr);
3225 /* Draw the header itself. */
3226 BitBlt(hdc, 0, 0,
3227 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3228 hdcSrc, 0, 0, SRCCOPY);
3230 else
3232 hbr = GetSysColorBrush(COLOR_WINDOW);
3233 FillRect(hdc, &rzone, hbr);
3235 /* Draw the header bitmap. It's always centered like a
3236 * common 49 x 49 bitmap. */
3237 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3238 (rzone.bottom - 49) / 2,
3239 bm.bmWidth, bm.bmHeight,
3240 hdcSrc, 0, 0, SRCCOPY);
3242 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3243 * if its height is smaller than 49 pixels. Because the reason
3244 * for this bug is unknown the current code doesn't try to
3245 * replicate it. */
3248 clrOld = SetTextColor (hdc, 0x00000000);
3249 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3251 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3252 SetRect(&r, 20, 10, 0, 0);
3253 if (HIWORD(ppshpage->pszHeaderTitle))
3255 if (psInfo->unicode)
3256 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3257 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3258 else
3259 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3260 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3262 else
3264 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3265 szBuffer, 256);
3266 if (nLength != 0)
3268 DrawTextW(hdc, szBuffer, nLength,
3269 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3274 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3275 SelectObject(hdc, psInfo->hFont);
3276 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3277 if (HIWORD(ppshpage->pszHeaderTitle))
3279 if (psInfo->unicode)
3280 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3281 -1, &r, DT_LEFT | DT_SINGLELINE);
3282 else
3283 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3284 -1, &r, DT_LEFT | DT_SINGLELINE);
3286 else
3288 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3289 szBuffer, 256);
3290 if (nLength != 0)
3292 DrawTextW(hdc, szBuffer, nLength,
3293 &r, DT_LEFT | DT_SINGLELINE);
3298 offsety = rzone.bottom + 2;
3300 SetTextColor(hdc, clrOld);
3301 SetBkMode(hdc, oldBkMode);
3302 SelectObject(hdc, hOldFont);
3303 SelectObject(hdcSrc, hbmp);
3306 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3307 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3308 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3310 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3312 GetClientRect(hwndLine, &r);
3313 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3315 rzone.left = 0;
3316 rzone.top = 0;
3317 rzone.right = r.right;
3318 rzone.bottom = r.top - 1;
3320 hbr = GetSysColorBrush(COLOR_WINDOW);
3321 FillRect(hdc, &rzone, hbr);
3323 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3324 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3326 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3327 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3329 /* If the bitmap is not big enough, fill the remaining area
3330 with the color of pixel (0,0) of bitmap - see MSDN */
3331 if (r.top > bm.bmHeight) {
3332 r.bottom = r.top - 1;
3333 r.top = bm.bmHeight;
3334 r.left = 0;
3335 r.right = bm.bmWidth;
3336 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3337 FillRect(hdc, &r, hbr);
3338 DeleteObject(hbr);
3341 SelectObject(hdcSrc, hbmp);
3344 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3345 SelectPalette(hdc, hOldPal, FALSE);
3347 DeleteDC(hdcSrc);
3349 if (!hdcParam) EndPaint(hwnd, &ps);
3351 return 0;
3354 /******************************************************************************
3355 * PROPSHEET_DialogProc
3357 INT_PTR CALLBACK
3358 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3360 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3361 hwnd, uMsg, wParam, lParam);
3363 switch (uMsg)
3365 case WM_INITDIALOG:
3367 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3368 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3369 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3370 LPCPROPSHEETPAGEW ppshpage;
3371 int idx;
3372 LOGFONTW logFont;
3374 /* Using PropSheetInfoStr to store extra data doesn't match the native
3375 * common control: native uses TCM_[GS]ETITEM
3377 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3380 * psInfo->hwnd is not being used by WINE code - it exists
3381 * for compatibility with "real" Windoze. The same about
3382 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3383 * property.
3385 psInfo->hwnd = hwnd;
3386 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3388 /* set up the Next and Back buttons by default */
3389 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3391 /* Set up fonts */
3392 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3393 psInfo->hFont = CreateFontIndirectW (&logFont);
3394 logFont.lfWeight = FW_BOLD;
3395 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3398 * Small icon in the title bar.
3400 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3401 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3403 HICON hIcon;
3404 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3405 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3407 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3408 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3409 psInfo->ppshheader.u.pszIcon,
3410 IMAGE_ICON,
3411 icon_cx, icon_cy,
3412 LR_DEFAULTCOLOR);
3413 else
3414 hIcon = psInfo->ppshheader.u.hIcon;
3416 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3419 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3420 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3422 psInfo->strPropertiesFor = strCaption;
3424 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3426 PROPSHEET_CreateTabControl(hwnd, psInfo);
3428 PROPSHEET_LoadWizardBitmaps(psInfo);
3430 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3432 ShowWindow(hwndTabCtrl, SW_HIDE);
3433 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3434 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3436 else
3438 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3440 PROPSHEET_AdjustSize(hwnd, psInfo);
3441 PROPSHEET_AdjustButtons(hwnd, psInfo);
3445 if (psInfo->useCallback)
3446 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3447 PSCB_INITIALIZED, (LPARAM)0);
3449 idx = psInfo->active_page;
3450 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3451 psInfo->active_page = -1;
3453 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3455 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3456 * as some programs call TCM_GETCURSEL to get the current selection
3457 * from which to switch to the next page */
3458 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3460 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3461 psInfo->ppshheader.hInstance)
3463 WCHAR szText[256];
3465 if (LoadStringW(psInfo->ppshheader.hInstance,
3466 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3467 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3469 else
3471 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3472 psInfo->ppshheader.pszCaption);
3475 return TRUE;
3478 case WM_PRINTCLIENT:
3479 case WM_PAINT:
3480 PROPSHEET_Paint(hwnd, (HDC)wParam);
3481 return TRUE;
3483 case WM_DESTROY:
3484 PROPSHEET_CleanUp(hwnd);
3485 return TRUE;
3487 case WM_CLOSE:
3488 PROPSHEET_Cancel(hwnd, 1);
3489 return TRUE;
3491 case WM_COMMAND:
3492 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3494 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3496 if (!psInfo)
3497 return FALSE;
3499 /* No default handler, forward notification to active page */
3500 if (psInfo->activeValid && psInfo->active_page != -1)
3502 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3503 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3506 return TRUE;
3508 case WM_SYSCOMMAND:
3509 switch(wParam & 0xfff0)
3511 case SC_CLOSE:
3512 PROPSHEET_Cancel(hwnd, 1);
3513 return TRUE;
3515 default:
3516 return FALSE;
3519 case WM_NOTIFY:
3521 NMHDR* pnmh = (LPNMHDR) lParam;
3523 if (pnmh->code == TCN_SELCHANGE)
3525 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3526 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3529 if(pnmh->code == TCN_SELCHANGING)
3531 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3532 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3533 return TRUE;
3536 return FALSE;
3539 case WM_SYSCOLORCHANGE:
3540 COMCTL32_RefreshSysColors();
3541 return FALSE;
3543 case PSM_GETCURRENTPAGEHWND:
3545 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3546 PropSheetInfoStr);
3547 HWND hwndPage = 0;
3549 if (!psInfo)
3550 return FALSE;
3552 if (psInfo->activeValid && psInfo->active_page != -1)
3553 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3555 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3557 return TRUE;
3560 case PSM_CHANGED:
3561 PROPSHEET_Changed(hwnd, (HWND)wParam);
3562 return TRUE;
3564 case PSM_UNCHANGED:
3565 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3566 return TRUE;
3568 case PSM_GETTABCONTROL:
3570 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3572 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3574 return TRUE;
3577 case PSM_SETCURSEL:
3579 BOOL msgResult;
3581 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3582 if(msgResult != FALSE)
3584 msgResult = PROPSHEET_SetCurSel(hwnd,
3585 (int)wParam,
3587 (HPROPSHEETPAGE)lParam);
3590 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3592 return TRUE;
3595 case PSM_CANCELTOCLOSE:
3597 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3598 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3599 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3601 EnableWindow(hwndCancel, FALSE);
3602 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3603 SetWindowTextW(hwndOK, buf);
3605 return FALSE;
3608 case PSM_RESTARTWINDOWS:
3610 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3611 PropSheetInfoStr);
3613 if (!psInfo)
3614 return FALSE;
3616 psInfo->restartWindows = TRUE;
3617 return TRUE;
3620 case PSM_REBOOTSYSTEM:
3622 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3623 PropSheetInfoStr);
3625 if (!psInfo)
3626 return FALSE;
3628 psInfo->rebootSystem = TRUE;
3629 return TRUE;
3632 case PSM_SETTITLEA:
3633 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3634 return TRUE;
3636 case PSM_SETTITLEW:
3637 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3638 return TRUE;
3640 case PSM_APPLY:
3642 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3644 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3646 return TRUE;
3649 case PSM_QUERYSIBLINGS:
3651 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3653 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3655 return TRUE;
3658 case PSM_ADDPAGE:
3661 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3662 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3663 * on success or FALSE otherwise, as specified on MSDN Online.
3664 * Also see the MFC code for
3665 * CPropertySheet::AddPage(CPropertyPage* pPage).
3668 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3670 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3672 return TRUE;
3675 case PSM_REMOVEPAGE:
3676 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3677 return TRUE;
3679 case PSM_ISDIALOGMESSAGE:
3681 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3682 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3683 return TRUE;
3686 case PSM_PRESSBUTTON:
3687 PROPSHEET_PressButton(hwnd, (int)wParam);
3688 return TRUE;
3690 case PSM_SETFINISHTEXTA:
3691 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3692 return TRUE;
3694 case PSM_SETWIZBUTTONS:
3695 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3696 return TRUE;
3698 case PSM_SETCURSELID:
3699 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3700 return TRUE;
3702 case PSM_SETFINISHTEXTW:
3703 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3704 return FALSE;
3706 case PSM_INSERTPAGE:
3708 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3709 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3710 return TRUE;
3713 case PSM_SETHEADERTITLEW:
3714 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3715 return TRUE;
3717 case PSM_SETHEADERTITLEA:
3718 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3719 return TRUE;
3721 case PSM_SETHEADERSUBTITLEW:
3722 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3723 return TRUE;
3725 case PSM_SETHEADERSUBTITLEA:
3726 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3727 return TRUE;
3729 case PSM_HWNDTOINDEX:
3731 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3732 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3733 return TRUE;
3736 case PSM_INDEXTOHWND:
3738 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3739 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3740 return TRUE;
3743 case PSM_PAGETOINDEX:
3745 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3746 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3747 return TRUE;
3750 case PSM_INDEXTOPAGE:
3752 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3753 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3754 return TRUE;
3757 case PSM_IDTOINDEX:
3759 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3760 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3761 return TRUE;
3764 case PSM_INDEXTOID:
3766 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3767 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3768 return TRUE;
3771 case PSM_GETRESULT:
3773 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3774 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3775 return TRUE;
3778 case PSM_RECALCPAGESIZES:
3780 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3781 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3782 return TRUE;
3785 default:
3786 return FALSE;