push c669110d8ebd04a85775e86a8310fabd7dc4466e
[wine/hacks.git] / dlls / comctl32 / propsheet.c
blob4640e9f5eb5155609dfd96757d30d105d8ad506e
1 /*
2 * Property Sheets
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_INSERTPAGE
36 * o PSM_RECALCPAGESIZES
37 * o PSM_SETHEADERSUBTITLE
38 * o PSM_SETHEADERTITLE
39 * o WM_HELP
40 * o WM_CONTEXTMENU
41 * - Notifications:
42 * o PSN_GETOBJECT
43 * o PSN_QUERYINITIALFOCUS
44 * o PSN_TRANSLATEACCELERATOR
45 * - Styles:
46 * o PSH_RTLREADING
47 * o PSH_STRETCHWATERMARK
48 * o PSH_USEPAGELANG
49 * o PSH_USEPSTARTPAGE
50 * - Page styles:
51 * o PSP_USEFUSIONCONTEXT
52 * o PSP_USEREFPARENT
55 #include <stdarg.h>
56 #include <string.h>
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winuser.h"
64 #include "winnls.h"
65 #include "commctrl.h"
66 #include "prsht.h"
67 #include "comctl32.h"
68 #include "uxtheme.h"
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
73 /******************************************************************************
74 * Data structures
76 #include "pshpack2.h"
78 typedef struct
80 WORD dlgVer;
81 WORD signature;
82 DWORD helpID;
83 DWORD exStyle;
84 DWORD style;
85 } MyDLGTEMPLATEEX;
87 typedef struct
89 DWORD helpid;
90 DWORD exStyle;
91 DWORD style;
92 short x;
93 short y;
94 short cx;
95 short cy;
96 DWORD id;
97 } MyDLGITEMTEMPLATEEX;
98 #include "poppack.h"
100 typedef struct tagPropPageInfo
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 HWND hwndPage;
104 BOOL isDirty;
105 LPCWSTR pszText;
106 BOOL hasHelp;
107 BOOL useCallback;
108 BOOL hasIcon;
109 } PropPageInfo;
111 typedef struct tagPropSheetInfo
113 HWND hwnd;
114 PROPSHEETHEADERW ppshheader;
115 BOOL unicode;
116 LPWSTR strPropertiesFor;
117 int nPages;
118 int active_page;
119 BOOL isModeless;
120 BOOL hasHelp;
121 BOOL hasApply;
122 BOOL hasFinish;
123 BOOL usePropPage;
124 BOOL useCallback;
125 BOOL activeValid;
126 PropPageInfo* proppage;
127 HFONT hFont;
128 HFONT hFontBold;
129 int width;
130 int height;
131 HIMAGELIST hImageList;
132 BOOL ended;
133 INT result;
134 } PropSheetInfo;
136 typedef struct
138 int x;
139 int y;
140 } PADDING_INFO;
142 /******************************************************************************
143 * Defines and global variables
146 static const WCHAR PropSheetInfoStr[] =
147 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
149 #define PSP_INTERNAL_UNICODE 0x80000000
151 #define MAX_CAPTION_LENGTH 255
152 #define MAX_TABTEXT_LENGTH 255
153 #define MAX_BUTTONTEXT_LENGTH 64
155 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
157 /* Wizard metrics specified in DLUs */
158 #define WIZARD_PADDING 7
159 #define WIZARD_HEADER_HEIGHT 36
161 /******************************************************************************
162 * Prototypes
164 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
165 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
166 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
167 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
168 int index,
169 int skipdir,
170 HPROPSHEETPAGE hpage);
171 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo);
172 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
173 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
175 static INT_PTR CALLBACK
176 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
178 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
180 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
181 /******************************************************************************
182 * PROPSHEET_UnImplementedFlags
184 * Document use of flags we don't implement yet.
186 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
188 CHAR string[256];
190 string[0] = '\0';
193 * unhandled header flags:
194 * PSH_RTLREADING 0x00000800
195 * PSH_STRETCHWATERMARK 0x00040000
196 * PSH_USEPAGELANG 0x00200000
199 add_flag(PSH_RTLREADING);
200 add_flag(PSH_STRETCHWATERMARK);
201 add_flag(PSH_USEPAGELANG);
202 if (string[0] != '\0')
203 FIXME("%s\n", string);
205 #undef add_flag
207 /******************************************************************************
208 * PROPSHEET_GetPageRect
210 * Retrieve rect from tab control and map into the dialog for SetWindowPos
212 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
213 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
215 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
216 HWND hwndChild;
217 RECT r;
219 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
220 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
221 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
222 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
224 rc->left = rc->top = WIZARD_PADDING;
226 else
228 rc->left = rc->top = 0;
230 rc->right = psInfo->width - rc->left;
231 rc->bottom = psInfo->height - rc->top;
232 MapDialogRect(hwndDlg, rc);
234 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
235 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
236 !(ppshpage->dwFlags & PSP_HIDEHEADER))
238 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
239 GetClientRect(hwndChild, &r);
240 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
241 rc->top += r.bottom + 1;
243 } else {
244 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
245 GetClientRect(hwndTabCtrl, rc);
246 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
247 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
251 /******************************************************************************
252 * PROPSHEET_FindPageByResId
254 * Find page index corresponding to page resource id.
256 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
258 INT i;
260 for (i = 0; i < psInfo->nPages; i++)
262 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
264 /* Fixme: if resource ID is a string shall we use strcmp ??? */
265 if (lppsp->u.pszTemplate == (LPVOID)resId)
266 break;
269 return i;
272 /******************************************************************************
273 * PROPSHEET_AtoW
275 * Convert ASCII to Unicode since all data is saved as Unicode.
277 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
279 INT len;
280 WCHAR *to;
282 TRACE("<%s>\n", frstr);
283 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
284 to = Alloc(len * sizeof(WCHAR));
285 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
286 *tostr = to;
289 /******************************************************************************
290 * PROPSHEET_CollectSheetInfoCommon
292 * Common code for PROPSHEET_CollectSheetInfoA/W
294 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
296 PROPSHEET_UnImplementedFlags(dwFlags);
298 psInfo->hasHelp = dwFlags & PSH_HASHELP;
299 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
300 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
302 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
303 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
304 psInfo->active_page = 0;
306 psInfo->result = 0;
307 psInfo->hImageList = 0;
308 psInfo->activeValid = FALSE;
311 /******************************************************************************
312 * PROPSHEET_CollectSheetInfoA
314 * Collect relevant data.
316 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
317 PropSheetInfo * psInfo)
319 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
320 DWORD dwFlags = lppsh->dwFlags;
322 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
324 memcpy(&psInfo->ppshheader,lppsh,dwSize);
325 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
326 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
327 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
329 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
330 psInfo->ppshheader.pszCaption = NULL;
331 else
333 if (HIWORD(lppsh->pszCaption))
335 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
336 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
338 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
339 psInfo->ppshheader.pszCaption = caption;
342 psInfo->nPages = lppsh->nPages;
344 if (dwFlags & PSH_USEPSTARTPAGE)
346 TRACE("PSH_USEPSTARTPAGE is on\n");
347 psInfo->active_page = 0;
349 else
350 psInfo->active_page = lppsh->u2.nStartPage;
352 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
355 /******************************************************************************
356 * PROPSHEET_CollectSheetInfoW
358 * Collect relevant data.
360 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
361 PropSheetInfo * psInfo)
363 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
364 DWORD dwFlags = lppsh->dwFlags;
366 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
368 memcpy(&psInfo->ppshheader,lppsh,dwSize);
369 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
370 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
372 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
373 psInfo->ppshheader.pszCaption = NULL;
374 else
376 if (HIWORD(lppsh->pszCaption))
378 int len = strlenW(lppsh->pszCaption);
379 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
381 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
384 psInfo->nPages = lppsh->nPages;
386 if (dwFlags & PSH_USEPSTARTPAGE)
388 TRACE("PSH_USEPSTARTPAGE is on\n");
389 psInfo->active_page = 0;
391 else
392 psInfo->active_page = lppsh->u2.nStartPage;
394 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
397 /******************************************************************************
398 * PROPSHEET_CollectPageInfo
400 * Collect property sheet data.
401 * With code taken from DIALOG_ParseTemplate32.
403 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
404 PropSheetInfo * psInfo,
405 int index, BOOL resize)
407 const DLGTEMPLATE* pTemplate;
408 const WORD* p;
409 DWORD dwFlags;
410 int width, height;
412 if (!lppsp)
413 return FALSE;
415 TRACE("\n");
416 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
417 psInfo->proppage[index].hwndPage = 0;
418 psInfo->proppage[index].isDirty = FALSE;
421 * Process property page flags.
423 dwFlags = lppsp->dwFlags;
424 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
425 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
426 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
428 /* as soon as we have a page with the help flag, set the sheet flag on */
429 if (psInfo->proppage[index].hasHelp)
430 psInfo->hasHelp = TRUE;
433 * Process page template.
435 if (dwFlags & PSP_DLGINDIRECT)
436 pTemplate = lppsp->u.pResource;
437 else if(dwFlags & PSP_INTERNAL_UNICODE )
439 HRSRC hResource = FindResourceW(lppsp->hInstance,
440 lppsp->u.pszTemplate,
441 (LPWSTR)RT_DIALOG);
442 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
443 hResource);
444 pTemplate = LockResource(hTemplate);
446 else
448 HRSRC hResource = FindResourceA(lppsp->hInstance,
449 (LPCSTR)lppsp->u.pszTemplate,
450 (LPSTR)RT_DIALOG);
451 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
452 hResource);
453 pTemplate = LockResource(hTemplate);
457 * Extract the size of the page and the caption.
459 if (!pTemplate)
460 return FALSE;
462 p = (const WORD *)pTemplate;
464 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
466 /* DLGTEMPLATEEX (not defined in any std. header file) */
468 p++; /* dlgVer */
469 p++; /* signature */
470 p += 2; /* help ID */
471 p += 2; /* ext style */
472 p += 2; /* style */
474 else
476 /* DLGTEMPLATE */
478 p += 2; /* style */
479 p += 2; /* ext style */
482 p++; /* nb items */
483 p++; /* x */
484 p++; /* y */
485 width = (WORD)*p; p++;
486 height = (WORD)*p; p++;
488 /* Special calculation for interior wizard pages so the largest page is
489 * calculated correctly. We need to add all the padding and space occupied
490 * by the header so the width and height sums up to the whole wizard client
491 * area. */
492 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
493 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
494 !(dwFlags & PSP_HIDEHEADER))
496 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
497 width += 2 * WIZARD_PADDING;
499 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
501 height += 2 * WIZARD_PADDING;
502 width += 2 * WIZARD_PADDING;
505 /* remember the largest width and height */
506 if (resize)
508 if (width > psInfo->width)
509 psInfo->width = width;
511 if (height > psInfo->height)
512 psInfo->height = height;
515 /* menu */
516 switch ((WORD)*p)
518 case 0x0000:
519 p++;
520 break;
521 case 0xffff:
522 p += 2;
523 break;
524 default:
525 p += lstrlenW( p ) + 1;
526 break;
529 /* class */
530 switch ((WORD)*p)
532 case 0x0000:
533 p++;
534 break;
535 case 0xffff:
536 p += 2;
537 break;
538 default:
539 p += lstrlenW( p ) + 1;
540 break;
543 /* Extract the caption */
544 psInfo->proppage[index].pszText = p;
545 TRACE("Tab %d %s\n",index,debugstr_w( p ));
546 p += lstrlenW( p ) + 1;
548 if (dwFlags & PSP_USETITLE)
550 WCHAR szTitle[256];
551 const WCHAR *pTitle;
552 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
553 WCHAR *text;
554 int len;
556 if ( !HIWORD( lppsp->pszTitle ) )
558 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle)/sizeof(szTitle[0]) ))
560 pTitle = pszNull;
561 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
563 else
564 pTitle = szTitle;
566 else
567 pTitle = lppsp->pszTitle;
569 len = strlenW(pTitle);
570 text = Alloc( (len+1)*sizeof (WCHAR) );
571 psInfo->proppage[index].pszText = strcpyW( text, pTitle);
575 * Build the image list for icons
577 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
579 HICON hIcon;
580 int icon_cx = GetSystemMetrics(SM_CXSMICON);
581 int icon_cy = GetSystemMetrics(SM_CYSMICON);
583 if (dwFlags & PSP_USEICONID)
584 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
585 icon_cx, icon_cy, LR_DEFAULTCOLOR);
586 else
587 hIcon = lppsp->u2.hIcon;
589 if ( hIcon )
591 if (psInfo->hImageList == 0 )
592 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
594 ImageList_AddIcon(psInfo->hImageList, hIcon);
599 return TRUE;
602 /******************************************************************************
603 * PROPSHEET_CreateDialog
605 * Creates the actual property sheet.
607 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
609 LRESULT ret;
610 LPCVOID template;
611 LPVOID temp = 0;
612 HRSRC hRes;
613 DWORD resSize;
614 WORD resID = IDD_PROPSHEET;
616 TRACE("\n");
617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
618 resID = IDD_WIZARD;
620 if( psInfo->unicode )
622 if(!(hRes = FindResourceW(COMCTL32_hModule,
623 MAKEINTRESOURCEW(resID),
624 (LPWSTR)RT_DIALOG)))
625 return -1;
627 else
629 if(!(hRes = FindResourceA(COMCTL32_hModule,
630 MAKEINTRESOURCEA(resID),
631 (LPSTR)RT_DIALOG)))
632 return -1;
635 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
636 return -1;
639 * Make a copy of the dialog template.
641 resSize = SizeofResource(COMCTL32_hModule, hRes);
643 temp = Alloc(resSize);
645 if (!temp)
646 return -1;
648 memcpy(temp, template, resSize);
650 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
654 else
655 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
657 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
658 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
660 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
661 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
662 else
663 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
666 if (psInfo->useCallback)
667 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
669 /* NOTE: MSDN states "Returns a positive value if successful, or -1
670 * otherwise for modal property sheets.", but this is wrong. The
671 * actual return value is either TRUE (success), FALSE (cancel) or
672 * -1 (error). */
673 if( psInfo->unicode )
675 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
676 (LPDLGTEMPLATEW) temp,
677 psInfo->ppshheader.hwndParent,
678 PROPSHEET_DialogProc,
679 (LPARAM)psInfo);
680 if ( !ret ) ret = -1;
682 else
684 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
685 (LPDLGTEMPLATEA) temp,
686 psInfo->ppshheader.hwndParent,
687 PROPSHEET_DialogProc,
688 (LPARAM)psInfo);
689 if ( !ret ) ret = -1;
692 Free(temp);
694 return ret;
697 /******************************************************************************
698 * PROPSHEET_SizeMismatch
700 * Verify that the tab control and the "largest" property sheet page dlg. template
701 * match in size.
703 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
705 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
706 RECT rcOrigTab, rcPage;
709 * Original tab size.
711 GetClientRect(hwndTabCtrl, &rcOrigTab);
712 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
715 * Biggest page size.
717 rcPage.left = 0;
718 rcPage.top = 0;
719 rcPage.right = psInfo->width;
720 rcPage.bottom = psInfo->height;
722 MapDialogRect(hwndDlg, &rcPage);
723 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
725 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
726 return TRUE;
727 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
728 return TRUE;
730 return FALSE;
733 /******************************************************************************
734 * PROPSHEET_AdjustSize
736 * Resizes the property sheet and the tab control to fit the largest page.
738 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
740 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
741 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
742 RECT rc,tabRect;
743 int buttonHeight;
744 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
745 RECT units;
746 LONG style;
748 /* Get the height of buttons */
749 GetClientRect(hwndButton, &rc);
750 buttonHeight = rc.bottom;
753 * Biggest page size.
755 rc.left = 0;
756 rc.top = 0;
757 rc.right = psInfo->width;
758 rc.bottom = psInfo->height;
760 MapDialogRect(hwndDlg, &rc);
762 /* retrieve the dialog units */
763 units.left = units.right = 4;
764 units.top = units.bottom = 8;
765 MapDialogRect(hwndDlg, &units);
768 * Resize the tab control.
770 GetClientRect(hwndTabCtrl,&tabRect);
772 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
774 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
776 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
777 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
780 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
782 rc.right = rc.left + tabRect.right - tabRect.left;
783 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
786 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
788 rc.right -= rc.left;
789 rc.bottom -= rc.top;
790 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
791 hwndTabCtrl, rc.right, rc.bottom);
792 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
793 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
795 GetClientRect(hwndTabCtrl, &rc);
797 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
799 rc.right += (padding.x * 2);
800 rc.bottom += buttonHeight + (3 * padding.y);
802 style = GetWindowLongW(hwndDlg, GWL_STYLE);
803 if (!(style & WS_CHILD))
804 AdjustWindowRect(&rc, style, FALSE);
806 rc.right -= rc.left;
807 rc.bottom -= rc.top;
810 * Resize the property sheet.
812 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
813 hwndDlg, rc.right, rc.bottom);
814 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
815 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
816 return TRUE;
819 /******************************************************************************
820 * PROPSHEET_AdjustSizeWizard
822 * Resizes the property sheet to fit the largest page.
824 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
826 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
827 RECT rc, lineRect, dialogRect;
829 /* Biggest page size */
830 rc.left = 0;
831 rc.top = 0;
832 rc.right = psInfo->width;
833 rc.bottom = psInfo->height;
834 MapDialogRect(hwndDlg, &rc);
836 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
838 /* Add space for the buttons row */
839 GetWindowRect(hwndLine, &lineRect);
840 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
841 GetClientRect(hwndDlg, &dialogRect);
842 rc.bottom += dialogRect.bottom - lineRect.top - 1;
844 /* Convert the client coordinates to window coordinates */
845 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
847 /* Resize the property sheet */
848 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
849 hwndDlg, rc.right, rc.bottom);
850 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
851 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
853 return TRUE;
856 /******************************************************************************
857 * PROPSHEET_AdjustButtons
859 * Adjusts the buttons' positions.
861 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
863 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
864 RECT rcSheet;
865 int x, y;
866 int num_buttons = 2;
867 int buttonWidth, buttonHeight;
868 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
870 if (psInfo->hasApply)
871 num_buttons++;
873 if (psInfo->hasHelp)
874 num_buttons++;
877 * Obtain the size of the buttons.
879 GetClientRect(hwndButton, &rcSheet);
880 buttonWidth = rcSheet.right;
881 buttonHeight = rcSheet.bottom;
884 * Get the size of the property sheet.
886 GetClientRect(hwndParent, &rcSheet);
889 * All buttons will be at this y coordinate.
891 y = rcSheet.bottom - (padding.y + buttonHeight);
894 * Position OK button and make it default.
896 hwndButton = GetDlgItem(hwndParent, IDOK);
898 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
900 SetWindowPos(hwndButton, 0, x, y, 0, 0,
901 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
903 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
907 * Position Cancel button.
909 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
911 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
913 SetWindowPos(hwndButton, 0, x, y, 0, 0,
914 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
917 * Position Apply button.
919 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
921 if (psInfo->hasApply)
923 if (psInfo->hasHelp)
924 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
925 else
926 x = rcSheet.right - (padding.x + buttonWidth);
928 SetWindowPos(hwndButton, 0, x, y, 0, 0,
929 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
931 EnableWindow(hwndButton, FALSE);
933 else
934 ShowWindow(hwndButton, SW_HIDE);
937 * Position Help button.
939 hwndButton = GetDlgItem(hwndParent, IDHELP);
941 if (psInfo->hasHelp)
943 x = rcSheet.right - (padding.x + buttonWidth);
945 SetWindowPos(hwndButton, 0, x, y, 0, 0,
946 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
948 else
949 ShowWindow(hwndButton, SW_HIDE);
951 return TRUE;
954 /******************************************************************************
955 * PROPSHEET_AdjustButtonsWizard
957 * Adjusts the buttons' positions.
959 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
960 const PropSheetInfo* psInfo)
962 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
963 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
964 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
965 RECT rcSheet;
966 int x, y;
967 int num_buttons = 3;
968 int buttonWidth, buttonHeight, lineHeight, lineWidth;
969 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
971 if (psInfo->hasHelp)
972 num_buttons++;
973 if (psInfo->hasFinish)
974 num_buttons++;
977 * Obtain the size of the buttons.
979 GetClientRect(hwndButton, &rcSheet);
980 buttonWidth = rcSheet.right;
981 buttonHeight = rcSheet.bottom;
983 GetClientRect(hwndLine, &rcSheet);
984 lineHeight = rcSheet.bottom;
987 * Get the size of the property sheet.
989 GetClientRect(hwndParent, &rcSheet);
992 * All buttons will be at this y coordinate.
994 y = rcSheet.bottom - (padding.y + buttonHeight);
997 * Position the Back button.
999 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1001 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1003 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1004 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1007 * Position the Next button.
1009 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1011 x += buttonWidth;
1013 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1014 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1017 * Position the Finish button.
1019 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1021 if (psInfo->hasFinish)
1022 x += padding.x + buttonWidth;
1024 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1025 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1027 if (!psInfo->hasFinish)
1028 ShowWindow(hwndButton, SW_HIDE);
1031 * Position the Cancel button.
1033 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1035 x += padding.x + buttonWidth;
1037 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1038 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1041 * Position Help button.
1043 hwndButton = GetDlgItem(hwndParent, IDHELP);
1045 if (psInfo->hasHelp)
1047 x += padding.x + buttonWidth;
1049 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1050 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1052 else
1053 ShowWindow(hwndButton, SW_HIDE);
1055 if (psInfo->ppshheader.dwFlags &
1056 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1057 padding.x = 0;
1060 * Position and resize the sunken line.
1062 x = padding.x;
1063 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1065 lineWidth = rcSheet.right - (padding.x * 2);
1066 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1067 SWP_NOZORDER | SWP_NOACTIVATE);
1070 * Position and resize the header sunken line.
1073 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1074 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1075 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1076 ShowWindow(hwndLineHeader, SW_HIDE);
1078 return TRUE;
1081 /******************************************************************************
1082 * PROPSHEET_GetPaddingInfo
1084 * Returns the layout information.
1086 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1088 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1089 RECT rcTab;
1090 POINT tl;
1091 PADDING_INFO padding;
1093 GetWindowRect(hwndTab, &rcTab);
1095 tl.x = rcTab.left;
1096 tl.y = rcTab.top;
1098 ScreenToClient(hwndDlg, &tl);
1100 padding.x = tl.x;
1101 padding.y = tl.y;
1103 return padding;
1106 /******************************************************************************
1107 * PROPSHEET_GetPaddingInfoWizard
1109 * Returns the layout information.
1110 * Vertical spacing is the distance between the line and the buttons.
1111 * Do NOT use the Help button to gather padding information when it isn't mapped
1112 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1113 * for it in this case !
1114 * FIXME: I'm not sure about any other coordinate problems with these evil
1115 * buttons. Fix it in case additional problems appear or maybe calculate
1116 * a padding in a completely different way, as this is somewhat messy.
1118 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1119 psInfo)
1121 PADDING_INFO padding;
1122 RECT rc;
1123 HWND hwndControl;
1124 INT idButton;
1125 POINT ptButton, ptLine;
1127 TRACE("\n");
1128 if (psInfo->hasHelp)
1130 idButton = IDHELP;
1132 else
1134 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1136 idButton = IDC_NEXT_BUTTON;
1138 else
1140 /* hopefully this is ok */
1141 idButton = IDCANCEL;
1145 hwndControl = GetDlgItem(hwndDlg, idButton);
1146 GetWindowRect(hwndControl, &rc);
1148 ptButton.x = rc.left;
1149 ptButton.y = rc.top;
1151 ScreenToClient(hwndDlg, &ptButton);
1153 /* Line */
1154 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1155 GetWindowRect(hwndControl, &rc);
1157 ptLine.x = rc.left;
1158 ptLine.y = rc.bottom;
1160 ScreenToClient(hwndDlg, &ptLine);
1162 padding.y = ptButton.y - ptLine.y;
1164 if (padding.y < 0)
1165 ERR("padding negative ! Please report this !\n");
1167 /* this is most probably not correct, but the best we have now */
1168 padding.x = padding.y;
1169 return padding;
1172 /******************************************************************************
1173 * PROPSHEET_CreateTabControl
1175 * Insert the tabs in the tab control.
1177 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1178 const PropSheetInfo * psInfo)
1180 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1181 TCITEMW item;
1182 int i, nTabs;
1183 int iImage = 0;
1185 TRACE("\n");
1186 item.mask = TCIF_TEXT;
1187 item.cchTextMax = MAX_TABTEXT_LENGTH;
1189 nTabs = psInfo->nPages;
1192 * Set the image list for icons.
1194 if (psInfo->hImageList)
1196 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1199 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1200 for (i = 0; i < nTabs; i++)
1202 if ( psInfo->proppage[i].hasIcon )
1204 item.mask |= TCIF_IMAGE;
1205 item.iImage = iImage++;
1207 else
1209 item.mask &= ~TCIF_IMAGE;
1212 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1213 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1215 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1217 return TRUE;
1220 /******************************************************************************
1221 * PROPSHEET_WizardSubclassProc
1223 * Subclassing window procedure for wizard exterior pages to prevent drawing
1224 * background and so drawing above the watermark.
1226 static LRESULT CALLBACK
1227 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1229 switch (uMsg)
1231 case WM_ERASEBKGND:
1232 return TRUE;
1234 case WM_CTLCOLORSTATIC:
1235 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1236 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1239 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1243 * Get the size of an in-memory Template
1245 *( Based on the code of PROPSHEET_CollectPageInfo)
1246 * See also dialog.c/DIALOG_ParseTemplate32().
1249 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1252 const WORD* p = (const WORD *)pTemplate;
1253 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1254 WORD nrofitems;
1255 UINT ret;
1257 if (istemplateex)
1259 /* DLGTEMPLATEEX (not defined in any std. header file) */
1261 TRACE("is DLGTEMPLATEEX\n");
1262 p++; /* dlgVer */
1263 p++; /* signature */
1264 p += 2; /* help ID */
1265 p += 2; /* ext style */
1266 p += 2; /* style */
1268 else
1270 /* DLGTEMPLATE */
1272 TRACE("is DLGTEMPLATE\n");
1273 p += 2; /* style */
1274 p += 2; /* ext style */
1277 nrofitems = (WORD)*p; p++; /* nb items */
1278 p++; /* x */
1279 p++; /* y */
1280 p++; /* width */
1281 p++; /* height */
1283 /* menu */
1284 switch ((WORD)*p)
1286 case 0x0000:
1287 p++;
1288 break;
1289 case 0xffff:
1290 p += 2;
1291 break;
1292 default:
1293 TRACE("menu %s\n",debugstr_w( p ));
1294 p += lstrlenW( p ) + 1;
1295 break;
1298 /* class */
1299 switch ((WORD)*p)
1301 case 0x0000:
1302 p++;
1303 break;
1304 case 0xffff:
1305 p += 2; /* 0xffff plus predefined window class ordinal value */
1306 break;
1307 default:
1308 TRACE("class %s\n",debugstr_w( p ));
1309 p += lstrlenW( p ) + 1;
1310 break;
1313 /* title */
1314 TRACE("title %s\n",debugstr_w( p ));
1315 p += lstrlenW( p ) + 1;
1317 /* font, if DS_SETFONT set */
1318 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1319 pTemplate->style)))
1321 p+=(istemplateex)?3:1;
1322 TRACE("font %s\n",debugstr_w( p ));
1323 p += lstrlenW( p ) + 1; /* the font name */
1326 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1327 * that are following the DLGTEMPLATE(EX) data */
1328 TRACE("%d items\n",nrofitems);
1329 while (nrofitems > 0)
1331 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1333 /* skip header */
1334 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1336 /* check class */
1337 switch ((WORD)*p)
1339 case 0x0000:
1340 p++;
1341 break;
1342 case 0xffff:
1343 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1344 p += 2;
1345 break;
1346 default:
1347 TRACE("class %s\n",debugstr_w( p ));
1348 p += lstrlenW( p ) + 1;
1349 break;
1352 /* check title text */
1353 switch ((WORD)*p)
1355 case 0x0000:
1356 p++;
1357 break;
1358 case 0xffff:
1359 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1360 p += 2;
1361 break;
1362 default:
1363 TRACE("text %s\n",debugstr_w( p ));
1364 p += lstrlenW( p ) + 1;
1365 break;
1367 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1368 --nrofitems;
1371 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1372 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1373 return ret;
1376 /******************************************************************************
1377 * PROPSHEET_CreatePage
1379 * Creates a page.
1381 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1382 int index,
1383 const PropSheetInfo * psInfo,
1384 LPCPROPSHEETPAGEW ppshpage)
1386 DLGTEMPLATE* pTemplate;
1387 HWND hwndPage;
1388 DWORD resSize;
1389 LPVOID temp = NULL;
1391 TRACE("index %d\n", index);
1393 if (ppshpage == NULL)
1395 return FALSE;
1398 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1400 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1401 resSize = GetTemplateSize(pTemplate);
1403 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1405 HRSRC hResource;
1406 HANDLE hTemplate;
1408 hResource = FindResourceW(ppshpage->hInstance,
1409 ppshpage->u.pszTemplate,
1410 (LPWSTR)RT_DIALOG);
1411 if(!hResource)
1412 return FALSE;
1414 resSize = SizeofResource(ppshpage->hInstance, hResource);
1416 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1417 if(!hTemplate)
1418 return FALSE;
1420 pTemplate = LockResource(hTemplate);
1422 * Make a copy of the dialog template to make it writable
1425 else
1427 HRSRC hResource;
1428 HANDLE hTemplate;
1430 hResource = FindResourceA(ppshpage->hInstance,
1431 (LPCSTR)ppshpage->u.pszTemplate,
1432 (LPSTR)RT_DIALOG);
1433 if(!hResource)
1434 return FALSE;
1436 resSize = SizeofResource(ppshpage->hInstance, hResource);
1438 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1439 if(!hTemplate)
1440 return FALSE;
1442 pTemplate = LockResource(hTemplate);
1444 * Make a copy of the dialog template to make it writable
1447 temp = Alloc(resSize);
1448 if (!temp)
1449 return FALSE;
1451 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1452 memcpy(temp, pTemplate, resSize);
1453 pTemplate = temp;
1455 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1457 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1459 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1460 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1461 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1462 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1463 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1464 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1466 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1468 else
1470 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1471 pTemplate->style &= ~DS_MODALFRAME;
1472 pTemplate->style &= ~WS_CAPTION;
1473 pTemplate->style &= ~WS_SYSMENU;
1474 pTemplate->style &= ~WS_POPUP;
1475 pTemplate->style &= ~WS_DISABLED;
1476 pTemplate->style &= ~WS_VISIBLE;
1477 pTemplate->style &= ~WS_THICKFRAME;
1479 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1482 if (psInfo->proppage[index].useCallback)
1483 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1484 (LPPROPSHEETPAGEW)ppshpage);
1486 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1487 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1488 pTemplate,
1489 hwndParent,
1490 ppshpage->pfnDlgProc,
1491 (LPARAM)ppshpage);
1492 else
1493 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1494 pTemplate,
1495 hwndParent,
1496 ppshpage->pfnDlgProc,
1497 (LPARAM)ppshpage);
1498 /* Free a no more needed copy */
1499 Free(temp);
1501 psInfo->proppage[index].hwndPage = hwndPage;
1503 /* Subclass exterior wizard pages */
1504 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1505 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1506 (ppshpage->dwFlags & PSP_HIDEHEADER))
1508 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1509 (DWORD_PTR)ppshpage);
1511 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1512 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1514 return TRUE;
1517 /******************************************************************************
1518 * PROPSHEET_LoadWizardBitmaps
1520 * Loads the watermark and header bitmaps for a wizard.
1522 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1524 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1526 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1527 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1528 considers hbmWatermark as valid. */
1529 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1530 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1532 psInfo->ppshheader.u4.hbmWatermark =
1533 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1536 /* Same behavior as for watermarks */
1537 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1538 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1540 psInfo->ppshheader.u5.hbmHeader =
1541 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1547 /******************************************************************************
1548 * PROPSHEET_ShowPage
1550 * Displays or creates the specified page.
1552 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1554 HWND hwndTabCtrl;
1555 HWND hwndLineHeader;
1556 LPCPROPSHEETPAGEW ppshpage;
1558 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1559 if (index == psInfo->active_page)
1561 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1562 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1563 return TRUE;
1566 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1567 if (psInfo->proppage[index].hwndPage == 0)
1569 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1572 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1574 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1575 psInfo->proppage[index].pszText);
1578 if (psInfo->active_page != -1)
1579 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1581 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1583 /* Synchronize current selection with tab control
1584 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1585 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1586 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1588 psInfo->active_page = index;
1589 psInfo->activeValid = TRUE;
1591 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1593 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1594 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1596 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1597 ShowWindow(hwndLineHeader, SW_HIDE);
1598 else
1599 ShowWindow(hwndLineHeader, SW_SHOW);
1602 return TRUE;
1605 /******************************************************************************
1606 * PROPSHEET_Back
1608 static BOOL PROPSHEET_Back(HWND hwndDlg)
1610 PSHNOTIFY psn;
1611 HWND hwndPage;
1612 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1613 LRESULT result;
1614 int idx;
1616 TRACE("active_page %d\n", psInfo->active_page);
1617 if (psInfo->active_page < 0)
1618 return FALSE;
1620 psn.hdr.code = PSN_WIZBACK;
1621 psn.hdr.hwndFrom = hwndDlg;
1622 psn.hdr.idFrom = 0;
1623 psn.lParam = 0;
1625 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1627 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1628 if (result == -1)
1629 return FALSE;
1630 else if (result == 0)
1631 idx = psInfo->active_page - 1;
1632 else
1633 idx = PROPSHEET_FindPageByResId(psInfo, result);
1635 if (idx >= 0 && idx < psInfo->nPages)
1637 if (PROPSHEET_CanSetCurSel(hwndDlg))
1638 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1640 return TRUE;
1643 /******************************************************************************
1644 * PROPSHEET_Next
1646 static BOOL PROPSHEET_Next(HWND hwndDlg)
1648 PSHNOTIFY psn;
1649 HWND hwndPage;
1650 LRESULT msgResult = 0;
1651 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1652 int idx;
1654 TRACE("active_page %d\n", psInfo->active_page);
1655 if (psInfo->active_page < 0)
1656 return FALSE;
1658 psn.hdr.code = PSN_WIZNEXT;
1659 psn.hdr.hwndFrom = hwndDlg;
1660 psn.hdr.idFrom = 0;
1661 psn.lParam = 0;
1663 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1665 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1666 if (msgResult == -1)
1667 return FALSE;
1668 else if (msgResult == 0)
1669 idx = psInfo->active_page + 1;
1670 else
1671 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1673 if (idx < psInfo->nPages )
1675 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1676 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1679 return TRUE;
1682 /******************************************************************************
1683 * PROPSHEET_Finish
1685 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1687 PSHNOTIFY psn;
1688 HWND hwndPage;
1689 LRESULT msgResult = 0;
1690 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1692 TRACE("active_page %d\n", psInfo->active_page);
1693 if (psInfo->active_page < 0)
1694 return FALSE;
1696 psn.hdr.code = PSN_WIZFINISH;
1697 psn.hdr.hwndFrom = hwndDlg;
1698 psn.hdr.idFrom = 0;
1699 psn.lParam = 0;
1701 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1703 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1705 TRACE("msg result %ld\n", msgResult);
1707 if (msgResult != 0)
1708 return FALSE;
1710 if (psInfo->result == 0)
1711 psInfo->result = IDOK;
1712 if (psInfo->isModeless)
1713 psInfo->activeValid = FALSE;
1714 else
1715 psInfo->ended = TRUE;
1717 return TRUE;
1720 /******************************************************************************
1721 * PROPSHEET_Apply
1723 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1725 int i;
1726 HWND hwndPage;
1727 PSHNOTIFY psn;
1728 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1730 TRACE("active_page %d\n", psInfo->active_page);
1731 if (psInfo->active_page < 0)
1732 return FALSE;
1734 psn.hdr.hwndFrom = hwndDlg;
1735 psn.hdr.idFrom = 0;
1736 psn.lParam = 0;
1740 * Send PSN_KILLACTIVE to the current page.
1742 psn.hdr.code = PSN_KILLACTIVE;
1744 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1746 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1747 return FALSE;
1750 * Send PSN_APPLY to all pages.
1752 psn.hdr.code = PSN_APPLY;
1753 psn.lParam = lParam;
1755 for (i = 0; i < psInfo->nPages; i++)
1757 hwndPage = psInfo->proppage[i].hwndPage;
1758 if (hwndPage)
1760 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1762 case PSNRET_INVALID:
1763 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1764 /* fall through */
1765 case PSNRET_INVALID_NOCHANGEPAGE:
1766 return FALSE;
1771 if(lParam)
1773 psInfo->activeValid = FALSE;
1775 else if(psInfo->active_page >= 0)
1777 psn.hdr.code = PSN_SETACTIVE;
1778 psn.lParam = 0;
1779 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1780 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1783 return TRUE;
1786 /******************************************************************************
1787 * PROPSHEET_Cancel
1789 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1791 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1792 HWND hwndPage;
1793 PSHNOTIFY psn;
1794 int i;
1796 TRACE("active_page %d\n", psInfo->active_page);
1797 if (psInfo->active_page < 0)
1798 return;
1800 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1801 psn.hdr.code = PSN_QUERYCANCEL;
1802 psn.hdr.hwndFrom = hwndDlg;
1803 psn.hdr.idFrom = 0;
1804 psn.lParam = 0;
1806 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1807 return;
1809 psn.hdr.code = PSN_RESET;
1810 psn.lParam = lParam;
1812 for (i = 0; i < psInfo->nPages; i++)
1814 hwndPage = psInfo->proppage[i].hwndPage;
1816 if (hwndPage)
1817 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1820 if (psInfo->isModeless)
1822 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1823 psInfo->activeValid = FALSE;
1825 else
1826 psInfo->ended = TRUE;
1829 /******************************************************************************
1830 * PROPSHEET_Help
1832 static void PROPSHEET_Help(HWND hwndDlg)
1834 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1835 HWND hwndPage;
1836 PSHNOTIFY psn;
1838 TRACE("active_page %d\n", psInfo->active_page);
1839 if (psInfo->active_page < 0)
1840 return;
1842 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1843 psn.hdr.code = PSN_HELP;
1844 psn.hdr.hwndFrom = hwndDlg;
1845 psn.hdr.idFrom = 0;
1846 psn.lParam = 0;
1848 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1851 /******************************************************************************
1852 * PROPSHEET_Changed
1854 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1856 int i;
1857 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1859 TRACE("\n");
1860 if (!psInfo) return;
1862 * Set the dirty flag of this page.
1864 for (i = 0; i < psInfo->nPages; i++)
1866 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1867 psInfo->proppage[i].isDirty = TRUE;
1871 * Enable the Apply button.
1873 if (psInfo->hasApply)
1875 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1877 EnableWindow(hwndApplyBtn, TRUE);
1881 /******************************************************************************
1882 * PROPSHEET_UnChanged
1884 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1886 int i;
1887 BOOL noPageDirty = TRUE;
1888 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1889 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1891 TRACE("\n");
1892 if ( !psInfo ) return;
1893 for (i = 0; i < psInfo->nPages; i++)
1895 /* set the specified page as clean */
1896 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1897 psInfo->proppage[i].isDirty = FALSE;
1899 /* look to see if there's any dirty pages */
1900 if (psInfo->proppage[i].isDirty)
1901 noPageDirty = FALSE;
1905 * Disable Apply button.
1907 if (noPageDirty)
1908 EnableWindow(hwndApplyBtn, FALSE);
1911 /******************************************************************************
1912 * PROPSHEET_PressButton
1914 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1916 TRACE("buttonID %d\n", buttonID);
1917 switch (buttonID)
1919 case PSBTN_APPLYNOW:
1920 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1921 break;
1922 case PSBTN_BACK:
1923 PROPSHEET_Back(hwndDlg);
1924 break;
1925 case PSBTN_CANCEL:
1926 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1927 break;
1928 case PSBTN_FINISH:
1929 PROPSHEET_Finish(hwndDlg);
1930 break;
1931 case PSBTN_HELP:
1932 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1933 break;
1934 case PSBTN_NEXT:
1935 PROPSHEET_Next(hwndDlg);
1936 break;
1937 case PSBTN_OK:
1938 PROPSHEET_DoCommand(hwndDlg, IDOK);
1939 break;
1940 default:
1941 FIXME("Invalid button index %d\n", buttonID);
1946 /*************************************************************************
1947 * BOOL PROPSHEET_CanSetCurSel [Internal]
1949 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1951 * PARAMS
1952 * hwndDlg [I] handle to a Dialog hWnd
1954 * RETURNS
1955 * TRUE if Current Selection can change
1957 * NOTES
1959 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1961 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1962 HWND hwndPage;
1963 PSHNOTIFY psn;
1964 BOOL res = FALSE;
1966 TRACE("active_page %d\n", psInfo->active_page);
1967 if (!psInfo)
1969 res = FALSE;
1970 goto end;
1973 if (psInfo->active_page < 0)
1975 res = TRUE;
1976 goto end;
1980 * Notify the current page.
1982 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1983 psn.hdr.code = PSN_KILLACTIVE;
1984 psn.hdr.hwndFrom = hwndDlg;
1985 psn.hdr.idFrom = 0;
1986 psn.lParam = 0;
1988 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1990 end:
1991 TRACE("<-- %d\n", res);
1992 return res;
1995 /******************************************************************************
1996 * PROPSHEET_SetCurSel
1998 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1999 int index,
2000 int skipdir,
2001 HPROPSHEETPAGE hpage
2004 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2005 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2006 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2008 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2009 /* hpage takes precedence over index */
2010 if (hpage != NULL)
2011 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2013 if (index < 0 || index >= psInfo->nPages)
2015 TRACE("Could not find page to select!\n");
2016 return FALSE;
2019 /* unset active page while doing this transition. */
2020 if (psInfo->active_page != -1)
2021 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2022 psInfo->active_page = -1;
2024 while (1) {
2025 int result;
2026 PSHNOTIFY psn;
2027 RECT rc;
2028 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2030 if (hwndTabControl)
2031 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2033 psn.hdr.code = PSN_SETACTIVE;
2034 psn.hdr.hwndFrom = hwndDlg;
2035 psn.hdr.idFrom = 0;
2036 psn.lParam = 0;
2038 if (!psInfo->proppage[index].hwndPage) {
2039 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2042 /* Resize the property sheet page to the fit in the Tab control
2043 * (for regular property sheets) or to fit in the client area (for
2044 * wizards).
2045 * NOTE: The resizing happens every time the page is selected and
2046 * not only when it's created (some applications depend on it). */
2047 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2048 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2049 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2050 rc.right - rc.left, rc.bottom - rc.top);
2051 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2052 rc.left, rc.top,
2053 rc.right - rc.left, rc.bottom - rc.top, 0);
2055 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2056 if (!result)
2057 break;
2058 if (result == -1) {
2059 index+=skipdir;
2060 if (index < 0) {
2061 index = 0;
2062 WARN("Tried to skip before first property sheet page!\n");
2063 break;
2065 if (index >= psInfo->nPages) {
2066 WARN("Tried to skip after last property sheet page!\n");
2067 index = psInfo->nPages-1;
2068 break;
2071 else if (result != 0)
2073 int old_index = index;
2074 index = PROPSHEET_FindPageByResId(psInfo, result);
2075 if(index >= psInfo->nPages) {
2076 index = old_index;
2077 WARN("Tried to skip to nonexistent page by res id\n");
2078 break;
2080 continue;
2084 /* Invalidate the header area */
2085 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2086 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2088 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2089 RECT r;
2091 GetClientRect(hwndLineHeader, &r);
2092 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2093 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2095 InvalidateRect(hwndDlg, &r, TRUE);
2099 * Display the new page.
2101 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2103 if (psInfo->proppage[index].hasHelp)
2104 EnableWindow(hwndHelp, TRUE);
2105 else
2106 EnableWindow(hwndHelp, FALSE);
2108 return TRUE;
2111 /******************************************************************************
2112 * PROPSHEET_SetCurSelId
2114 * Selects the page, specified by resource id.
2116 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2118 int idx;
2119 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2121 idx = PROPSHEET_FindPageByResId(psInfo, id);
2122 if (idx < psInfo->nPages )
2124 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2125 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2129 /******************************************************************************
2130 * PROPSHEET_SetTitleA
2132 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2134 if(HIWORD(lpszText))
2136 WCHAR szTitle[256];
2137 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2138 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2139 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2141 else
2143 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2147 /******************************************************************************
2148 * PROPSHEET_SetTitleW
2150 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2152 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2153 WCHAR szTitle[256];
2155 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2156 if (HIWORD(lpszText) == 0) {
2157 if (!LoadStringW(psInfo->ppshheader.hInstance,
2158 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2159 return;
2160 lpszText = szTitle;
2162 if (dwStyle & PSH_PROPTITLE)
2164 WCHAR* dest;
2165 int lentitle = strlenW(lpszText);
2166 int lenprop = strlenW(psInfo->strPropertiesFor);
2168 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2169 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2171 SetWindowTextW(hwndDlg, dest);
2172 Free(dest);
2174 else
2175 SetWindowTextW(hwndDlg, lpszText);
2178 /******************************************************************************
2179 * PROPSHEET_SetFinishTextA
2181 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2183 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2184 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2186 TRACE("'%s'\n", lpszText);
2187 /* Set text, show and enable the Finish button */
2188 SetWindowTextA(hwndButton, lpszText);
2189 ShowWindow(hwndButton, SW_SHOW);
2190 EnableWindow(hwndButton, TRUE);
2192 /* Make it default pushbutton */
2193 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2195 /* Hide Back button */
2196 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2197 ShowWindow(hwndButton, SW_HIDE);
2199 if (!psInfo->hasFinish)
2201 /* Hide Next button */
2202 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2203 ShowWindow(hwndButton, SW_HIDE);
2207 /******************************************************************************
2208 * PROPSHEET_SetFinishTextW
2210 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2212 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2213 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2215 TRACE("%s\n", debugstr_w(lpszText));
2216 /* Set text, show and enable the Finish button */
2217 SetWindowTextW(hwndButton, lpszText);
2218 ShowWindow(hwndButton, SW_SHOW);
2219 EnableWindow(hwndButton, TRUE);
2221 /* Make it default pushbutton */
2222 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2224 /* Hide Back button */
2225 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2226 ShowWindow(hwndButton, SW_HIDE);
2228 if (!psInfo->hasFinish)
2230 /* Hide Next button */
2231 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2232 ShowWindow(hwndButton, SW_HIDE);
2236 /******************************************************************************
2237 * PROPSHEET_QuerySiblings
2239 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2240 WPARAM wParam, LPARAM lParam)
2242 int i = 0;
2243 HWND hwndPage;
2244 LRESULT msgResult = 0;
2245 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2247 while ((i < psInfo->nPages) && (msgResult == 0))
2249 hwndPage = psInfo->proppage[i].hwndPage;
2250 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2251 i++;
2254 return msgResult;
2258 /******************************************************************************
2259 * PROPSHEET_AddPage
2261 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2262 HPROPSHEETPAGE hpage)
2264 PropPageInfo * ppi;
2265 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2266 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2267 TCITEMW item;
2268 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2270 TRACE("hpage %p\n", hpage);
2272 * Allocate and fill in a new PropPageInfo entry.
2274 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2275 if (!ppi)
2276 return FALSE;
2278 psInfo->proppage = ppi;
2279 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2280 return FALSE;
2282 psInfo->proppage[psInfo->nPages].hpage = hpage;
2284 if (ppsp->dwFlags & PSP_PREMATURE)
2286 /* Create the page but don't show it */
2287 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2291 * Add a new tab to the tab control.
2293 item.mask = TCIF_TEXT;
2294 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2295 item.cchTextMax = MAX_TABTEXT_LENGTH;
2297 if (psInfo->hImageList)
2299 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2302 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2304 item.mask |= TCIF_IMAGE;
2305 item.iImage = psInfo->nPages;
2308 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2309 (LPARAM)&item);
2311 psInfo->nPages++;
2313 /* If it is the only page - show it */
2314 if(psInfo->nPages == 1)
2315 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2316 return TRUE;
2319 /******************************************************************************
2320 * PROPSHEET_RemovePage
2322 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2323 int index,
2324 HPROPSHEETPAGE hpage)
2326 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2327 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2328 PropPageInfo* oldPages;
2330 TRACE("index %d, hpage %p\n", index, hpage);
2331 if (!psInfo) {
2332 return FALSE;
2335 * hpage takes precedence over index.
2337 if (hpage != 0)
2339 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2342 /* Make sure that index is within range */
2343 if (index < 0 || index >= psInfo->nPages)
2345 TRACE("Could not find page to remove!\n");
2346 return FALSE;
2349 TRACE("total pages %d removing page %d active page %d\n",
2350 psInfo->nPages, index, psInfo->active_page);
2352 * Check if we're removing the active page.
2354 if (index == psInfo->active_page)
2356 if (psInfo->nPages > 1)
2358 if (index > 0)
2360 /* activate previous page */
2361 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2363 else
2365 /* activate the next page */
2366 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2367 psInfo->active_page = index;
2370 else
2372 psInfo->active_page = -1;
2373 if (!psInfo->isModeless)
2375 psInfo->ended = TRUE;
2376 return TRUE;
2380 else if (index < psInfo->active_page)
2381 psInfo->active_page--;
2383 /* Unsubclass the page dialog window */
2384 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2385 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2386 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2388 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2389 PROPSHEET_WizardSubclassProc, 1);
2392 /* Destroy page dialog window */
2393 DestroyWindow(psInfo->proppage[index].hwndPage);
2395 /* Free page resources */
2396 if(psInfo->proppage[index].hpage)
2398 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2400 if (psp->dwFlags & PSP_USETITLE)
2401 Free ((LPVOID)psInfo->proppage[index].pszText);
2403 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2406 /* Remove the tab */
2407 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2409 oldPages = psInfo->proppage;
2410 psInfo->nPages--;
2411 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2413 if (index > 0)
2414 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2416 if (index < psInfo->nPages)
2417 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2418 (psInfo->nPages - index) * sizeof(PropPageInfo));
2420 Free(oldPages);
2422 return FALSE;
2425 /******************************************************************************
2426 * PROPSHEET_SetWizButtons
2428 * This code will work if (and assumes that) the Next button is on top of the
2429 * Finish button. ie. Finish comes after Next in the Z order.
2430 * This means make sure the dialog template reflects this.
2433 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2435 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2436 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2437 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2438 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2440 TRACE("%d\n", dwFlags);
2442 EnableWindow(hwndBack, FALSE);
2443 EnableWindow(hwndNext, FALSE);
2444 EnableWindow(hwndFinish, FALSE);
2446 /* set the default pushbutton to an enabled button */
2447 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2448 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2449 else if (dwFlags & PSWIZB_NEXT)
2450 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2451 else if (dwFlags & PSWIZB_BACK)
2452 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2453 else
2454 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2457 if (dwFlags & PSWIZB_BACK)
2458 EnableWindow(hwndBack, TRUE);
2460 if (dwFlags & PSWIZB_NEXT)
2461 EnableWindow(hwndNext, TRUE);
2463 if (!psInfo->hasFinish)
2465 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2467 /* Hide the Next button */
2468 ShowWindow(hwndNext, SW_HIDE);
2470 /* Show the Finish button */
2471 ShowWindow(hwndFinish, SW_SHOW);
2473 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2474 EnableWindow(hwndFinish, TRUE);
2476 else
2478 /* Hide the Finish button */
2479 ShowWindow(hwndFinish, SW_HIDE);
2480 /* Show the Next button */
2481 ShowWindow(hwndNext, SW_SHOW);
2484 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2485 EnableWindow(hwndFinish, TRUE);
2488 /******************************************************************************
2489 * PROPSHEET_InsertPage
2491 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2493 if (!HIWORD(hpageInsertAfter))
2494 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2495 else
2496 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2497 return FALSE;
2500 /******************************************************************************
2501 * PROPSHEET_SetHeaderTitleW
2503 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2505 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2508 /******************************************************************************
2509 * PROPSHEET_SetHeaderTitleA
2511 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2513 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2516 /******************************************************************************
2517 * PROPSHEET_SetHeaderSubTitleW
2519 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2521 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2524 /******************************************************************************
2525 * PROPSHEET_SetHeaderSubTitleA
2527 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2529 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2532 /******************************************************************************
2533 * PROPSHEET_HwndToIndex
2535 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2537 int index;
2538 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2540 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2542 for (index = 0; index < psInfo->nPages; index++)
2543 if (psInfo->proppage[index].hwndPage == hPageDlg)
2544 return index;
2545 WARN("%p not found\n", hPageDlg);
2546 return -1;
2549 /******************************************************************************
2550 * PROPSHEET_IndexToHwnd
2552 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2554 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2555 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2556 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2557 WARN("%d out of range.\n", iPageIndex);
2558 return 0;
2560 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2563 /******************************************************************************
2564 * PROPSHEET_PageToIndex
2566 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2568 int index;
2569 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2571 TRACE("(%p, %p)\n", hwndDlg, hPage);
2573 for (index = 0; index < psInfo->nPages; index++)
2574 if (psInfo->proppage[index].hpage == hPage)
2575 return index;
2576 WARN("%p not found\n", hPage);
2577 return -1;
2580 /******************************************************************************
2581 * PROPSHEET_IndexToPage
2583 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2585 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2586 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2587 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2588 WARN("%d out of range.\n", iPageIndex);
2589 return 0;
2591 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2594 /******************************************************************************
2595 * PROPSHEET_IdToIndex
2597 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2599 int index;
2600 LPCPROPSHEETPAGEW psp;
2601 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2602 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2603 for (index = 0; index < psInfo->nPages; index++) {
2604 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2605 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2606 return index;
2609 return -1;
2612 /******************************************************************************
2613 * PROPSHEET_IndexToId
2615 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2617 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2618 LPCPROPSHEETPAGEW psp;
2619 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2620 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2621 WARN("%d out of range.\n", iPageIndex);
2622 return 0;
2624 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2625 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2626 return 0;
2628 return (LRESULT)psp->u.pszTemplate;
2631 /******************************************************************************
2632 * PROPSHEET_GetResult
2634 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2636 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2637 return psInfo->result;
2640 /******************************************************************************
2641 * PROPSHEET_RecalcPageSizes
2643 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2645 FIXME("(%p): stub\n", hwndDlg);
2646 return FALSE;
2649 /******************************************************************************
2650 * PROPSHEET_GetPageIndex
2652 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2653 * the array of PropPageInfo.
2655 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2657 BOOL found = FALSE;
2658 int index = 0;
2660 TRACE("hpage %p\n", hpage);
2661 while ((index < psInfo->nPages) && (found == FALSE))
2663 if (psInfo->proppage[index].hpage == hpage)
2664 found = TRUE;
2665 else
2666 index++;
2669 if (found == FALSE)
2670 index = -1;
2672 return index;
2675 /******************************************************************************
2676 * PROPSHEET_CleanUp
2678 static void PROPSHEET_CleanUp(HWND hwndDlg)
2680 int i;
2681 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2683 TRACE("\n");
2684 if (!psInfo) return;
2685 if (HIWORD(psInfo->ppshheader.pszCaption))
2686 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2688 for (i = 0; i < psInfo->nPages; i++)
2690 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2692 /* Unsubclass the page dialog window */
2693 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2694 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2695 (psp->dwFlags & PSP_HIDEHEADER))
2697 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2698 PROPSHEET_WizardSubclassProc, 1);
2701 if(psInfo->proppage[i].hwndPage)
2702 DestroyWindow(psInfo->proppage[i].hwndPage);
2704 if(psp)
2706 if (psp->dwFlags & PSP_USETITLE)
2707 Free ((LPVOID)psInfo->proppage[i].pszText);
2709 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2713 DeleteObject(psInfo->hFont);
2714 DeleteObject(psInfo->hFontBold);
2715 /* If we created the bitmaps, destroy them */
2716 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2717 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2718 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2719 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2720 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2721 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2723 Free(psInfo->proppage);
2724 Free(psInfo->strPropertiesFor);
2725 ImageList_Destroy(psInfo->hImageList);
2727 GlobalFree((HGLOBAL)psInfo);
2730 static INT do_loop(const PropSheetInfo *psInfo)
2732 MSG msg;
2733 INT ret = -1;
2734 HWND hwnd = psInfo->hwnd;
2736 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2738 if(ret == -1)
2739 break;
2741 if(!IsDialogMessageW(hwnd, &msg))
2743 TranslateMessage(&msg);
2744 DispatchMessageW(&msg);
2748 if(ret == 0)
2750 PostQuitMessage(msg.wParam);
2751 ret = -1;
2754 if(ret != -1)
2755 ret = psInfo->result;
2757 DestroyWindow(hwnd);
2758 return ret;
2761 /******************************************************************************
2762 * PROPSHEET_PropertySheet
2764 * Common code between PropertySheetA/W
2766 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2768 INT_PTR bRet = 0;
2769 HWND parent = NULL;
2770 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2771 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2773 psInfo->unicode = unicode;
2774 psInfo->ended = FALSE;
2776 if(!psInfo->isModeless)
2778 parent = psInfo->ppshheader.hwndParent;
2779 if (parent) EnableWindow(parent, FALSE);
2781 bRet = PROPSHEET_CreateDialog(psInfo);
2782 if(!psInfo->isModeless)
2784 bRet = do_loop(psInfo);
2785 if (parent) EnableWindow(parent, TRUE);
2787 return bRet;
2790 /******************************************************************************
2791 * PropertySheet (COMCTL32.@)
2792 * PropertySheetA (COMCTL32.@)
2794 * Creates a property sheet in the specified property sheet header.
2796 * RETURNS
2797 * Modal property sheets: Positive if successful or -1 otherwise.
2798 * Modeless property sheets: Property sheet handle.
2799 * Or:
2800 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2801 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2803 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2805 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2806 UINT i, n;
2807 const BYTE* pByte;
2809 TRACE("(%p)\n", lppsh);
2811 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2813 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2814 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2816 for (n = i = 0; i < lppsh->nPages; i++, n++)
2818 if (!psInfo->usePropPage)
2819 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2820 else
2822 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2823 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2826 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2827 psInfo, n, TRUE))
2829 if (psInfo->usePropPage)
2830 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2831 n--;
2832 psInfo->nPages--;
2836 return PROPSHEET_PropertySheet(psInfo, FALSE);
2839 /******************************************************************************
2840 * PropertySheetW (COMCTL32.@)
2842 * See PropertySheetA.
2844 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2846 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2847 UINT i, n;
2848 const BYTE* pByte;
2850 TRACE("(%p)\n", lppsh);
2852 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2854 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2855 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2857 for (n = i = 0; i < lppsh->nPages; i++, n++)
2859 if (!psInfo->usePropPage)
2860 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2861 else
2863 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2864 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2867 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2868 psInfo, n, TRUE))
2870 if (psInfo->usePropPage)
2871 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2872 n--;
2873 psInfo->nPages--;
2877 return PROPSHEET_PropertySheet(psInfo, TRUE);
2880 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2882 LPWSTR ret;
2884 if (IS_INTRESOURCE(str))
2886 HRSRC hrsrc;
2887 HGLOBAL hmem;
2888 WCHAR *ptr;
2889 WORD i, id = LOWORD(str);
2890 UINT len;
2892 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2893 return NULL;
2894 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2895 if (!(ptr = LockResource( hmem ))) return NULL;
2896 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2897 len = *ptr;
2898 if (!len) return NULL;
2899 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2900 if (ret)
2902 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2903 ret[len] = 0;
2906 else
2908 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2909 ret = Alloc( len );
2910 if (ret) memcpy( ret, str, len );
2912 return ret;
2916 /******************************************************************************
2917 * CreatePropertySheetPage (COMCTL32.@)
2918 * CreatePropertySheetPageA (COMCTL32.@)
2920 * Creates a new property sheet page.
2922 * RETURNS
2923 * Success: Handle to new property sheet page.
2924 * Failure: NULL.
2926 * NOTES
2927 * An application must use the PSM_ADDPAGE message to add the new page to
2928 * an existing property sheet.
2930 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2931 LPCPROPSHEETPAGEA lpPropSheetPage)
2933 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2935 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2937 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2939 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2941 if (HIWORD( ppsp->u.pszTemplate ))
2943 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2944 char *template = Alloc( len );
2946 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2950 if (ppsp->dwFlags & PSP_USEICONID)
2952 if (HIWORD( ppsp->u2.pszIcon ))
2953 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2956 if (ppsp->dwFlags & PSP_USETITLE)
2958 if (HIWORD( ppsp->pszTitle ))
2959 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2960 else
2961 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2963 else
2964 ppsp->pszTitle = NULL;
2966 if (ppsp->dwFlags & PSP_HIDEHEADER)
2967 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2969 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2971 if (HIWORD( ppsp->pszHeaderTitle ))
2972 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2973 else
2974 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2976 else
2977 ppsp->pszHeaderTitle = NULL;
2979 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2981 if (HIWORD( ppsp->pszHeaderSubTitle ))
2982 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2983 else
2984 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2986 else
2987 ppsp->pszHeaderSubTitle = NULL;
2989 return (HPROPSHEETPAGE)ppsp;
2992 /******************************************************************************
2993 * CreatePropertySheetPageW (COMCTL32.@)
2995 * See CreatePropertySheetA.
2997 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2999 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3001 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3003 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3005 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3007 if (HIWORD( ppsp->u.pszTemplate ))
3009 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3010 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3012 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3016 if ( ppsp->dwFlags & PSP_USEICONID )
3018 if (HIWORD( ppsp->u2.pszIcon ))
3020 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3021 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3023 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3027 if (ppsp->dwFlags & PSP_USETITLE)
3028 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3029 else
3030 ppsp->pszTitle = NULL;
3032 if (ppsp->dwFlags & PSP_HIDEHEADER)
3033 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3035 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3036 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3037 else
3038 ppsp->pszHeaderTitle = NULL;
3040 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3041 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3042 else
3043 ppsp->pszHeaderSubTitle = NULL;
3045 return (HPROPSHEETPAGE)ppsp;
3048 /******************************************************************************
3049 * DestroyPropertySheetPage (COMCTL32.@)
3051 * Destroys a property sheet page previously created with
3052 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3053 * memory.
3055 * RETURNS
3056 * Success: TRUE
3057 * Failure: FALSE
3059 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3061 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3063 if (!psp)
3064 return FALSE;
3066 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3067 Free ((LPVOID)psp->u.pszTemplate);
3069 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3070 Free ((LPVOID)psp->u2.pszIcon);
3072 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3073 Free ((LPVOID)psp->pszTitle);
3075 Free(hPropPage);
3077 return TRUE;
3080 /******************************************************************************
3081 * PROPSHEET_IsDialogMessage
3083 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3085 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3087 TRACE("\n");
3088 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3089 return FALSE;
3091 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3093 int new_page = 0;
3094 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3096 if (!(dlgCode & DLGC_WANTMESSAGE))
3098 switch (lpMsg->wParam)
3100 case VK_TAB:
3101 if (GetKeyState(VK_SHIFT) & 0x8000)
3102 new_page = -1;
3103 else
3104 new_page = 1;
3105 break;
3107 case VK_NEXT: new_page = 1; break;
3108 case VK_PRIOR: new_page = -1; break;
3112 if (new_page)
3114 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3116 new_page += psInfo->active_page;
3118 if (new_page < 0)
3119 new_page = psInfo->nPages - 1;
3120 else if (new_page >= psInfo->nPages)
3121 new_page = 0;
3123 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3126 return TRUE;
3130 return IsDialogMessageW(hwnd, lpMsg);
3133 /******************************************************************************
3134 * PROPSHEET_DoCommand
3136 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3139 switch (wID) {
3141 case IDOK:
3142 case IDC_APPLY_BUTTON:
3144 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3146 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3147 break;
3149 if (wID == IDOK)
3151 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3153 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3154 if (psInfo->result == 0)
3155 psInfo->result = IDOK;
3157 if (psInfo->isModeless)
3158 psInfo->activeValid = FALSE;
3159 else
3160 psInfo->ended = TRUE;
3162 else
3163 EnableWindow(hwndApplyBtn, FALSE);
3165 break;
3168 case IDC_BACK_BUTTON:
3169 PROPSHEET_Back(hwnd);
3170 break;
3172 case IDC_NEXT_BUTTON:
3173 PROPSHEET_Next(hwnd);
3174 break;
3176 case IDC_FINISH_BUTTON:
3177 PROPSHEET_Finish(hwnd);
3178 break;
3180 case IDCANCEL:
3181 PROPSHEET_Cancel(hwnd, 0);
3182 break;
3184 case IDHELP:
3185 PROPSHEET_Help(hwnd);
3186 break;
3188 default:
3189 return FALSE;
3192 return TRUE;
3195 /******************************************************************************
3196 * PROPSHEET_Paint
3198 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3200 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3201 PAINTSTRUCT ps;
3202 HDC hdc, hdcSrc;
3203 BITMAP bm;
3204 HBITMAP hbmp;
3205 HPALETTE hOldPal = 0;
3206 int offsety = 0;
3207 HBRUSH hbr;
3208 RECT r, rzone;
3209 LPCPROPSHEETPAGEW ppshpage;
3210 WCHAR szBuffer[256];
3211 int nLength;
3213 if (psInfo->active_page < 0) return 1;
3214 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3215 if (!hdc) return 1;
3217 hdcSrc = CreateCompatibleDC(0);
3218 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3220 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3221 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3223 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3224 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3225 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3227 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3228 HFONT hOldFont;
3229 COLORREF clrOld = 0;
3230 int oldBkMode = 0;
3232 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3233 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3235 GetClientRect(hwndLineHeader, &r);
3236 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3237 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3239 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3241 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3243 /* Fill the unoccupied part of the header with color of the
3244 * left-top pixel, but do it only when needed.
3246 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3248 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3249 CopyRect(&r, &rzone);
3250 if (bm.bmWidth < r.right)
3252 r.left = bm.bmWidth;
3253 FillRect(hdc, &r, hbr);
3255 if (bm.bmHeight < r.bottom)
3257 r.left = 0;
3258 r.top = bm.bmHeight;
3259 FillRect(hdc, &r, hbr);
3261 DeleteObject(hbr);
3264 /* Draw the header itself. */
3265 BitBlt(hdc, 0, 0,
3266 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3267 hdcSrc, 0, 0, SRCCOPY);
3269 else
3271 int margin;
3272 hbr = GetSysColorBrush(COLOR_WINDOW);
3273 FillRect(hdc, &rzone, hbr);
3275 /* Draw the header bitmap. It's always centered like a
3276 * common 49 x 49 bitmap. */
3277 margin = (rzone.bottom - 49) / 2;
3278 BitBlt(hdc, rzone.right - 49 - margin, margin,
3279 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3280 hdcSrc, 0, 0, SRCCOPY);
3282 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3283 * if its height is smaller than 49 pixels. Because the reason
3284 * for this bug is unknown the current code doesn't try to
3285 * replicate it. */
3288 clrOld = SetTextColor (hdc, 0x00000000);
3289 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3291 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3292 SetRect(&r, 20, 10, 0, 0);
3293 if (HIWORD(ppshpage->pszHeaderTitle))
3294 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3295 else
3297 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3298 szBuffer, 256);
3299 if (nLength != 0)
3301 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3306 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3307 SelectObject(hdc, psInfo->hFont);
3308 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3309 if (HIWORD(ppshpage->pszHeaderTitle))
3310 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3311 else
3313 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3314 szBuffer, 256);
3315 if (nLength != 0)
3317 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3322 offsety = rzone.bottom + 2;
3324 SetTextColor(hdc, clrOld);
3325 SetBkMode(hdc, oldBkMode);
3326 SelectObject(hdc, hOldFont);
3327 SelectObject(hdcSrc, hbmp);
3330 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3331 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3332 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3334 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3336 GetClientRect(hwndLine, &r);
3337 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3339 rzone.left = 0;
3340 rzone.top = 0;
3341 rzone.right = r.right;
3342 rzone.bottom = r.top - 1;
3344 hbr = GetSysColorBrush(COLOR_WINDOW);
3345 FillRect(hdc, &rzone, hbr);
3347 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3348 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3350 /* The watermark is truncated to a width of 164 pixels */
3351 r.right = min(r.right, 164);
3352 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3353 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3355 /* If the bitmap is not big enough, fill the remaining area
3356 with the color of pixel (0,0) of bitmap - see MSDN */
3357 if (r.top > bm.bmHeight) {
3358 r.bottom = r.top - 1;
3359 r.top = bm.bmHeight;
3360 r.left = 0;
3361 r.right = bm.bmWidth;
3362 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3363 FillRect(hdc, &r, hbr);
3364 DeleteObject(hbr);
3367 SelectObject(hdcSrc, hbmp);
3370 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3371 SelectPalette(hdc, hOldPal, FALSE);
3373 DeleteDC(hdcSrc);
3375 if (!hdcParam) EndPaint(hwnd, &ps);
3377 return 0;
3380 /******************************************************************************
3381 * PROPSHEET_DialogProc
3383 static INT_PTR CALLBACK
3384 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3386 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3387 hwnd, uMsg, wParam, lParam);
3389 switch (uMsg)
3391 case WM_INITDIALOG:
3393 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3394 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3395 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3396 int idx;
3397 LOGFONTW logFont;
3399 /* Using PropSheetInfoStr to store extra data doesn't match the native
3400 * common control: native uses TCM_[GS]ETITEM
3402 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3405 * psInfo->hwnd is not being used by WINE code - it exists
3406 * for compatibility with "real" Windoze. The same about
3407 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3408 * property.
3410 psInfo->hwnd = hwnd;
3411 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3413 /* set up the Next and Back buttons by default */
3414 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3416 /* Set up fonts */
3417 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3418 psInfo->hFont = CreateFontIndirectW (&logFont);
3419 logFont.lfWeight = FW_BOLD;
3420 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3423 * Small icon in the title bar.
3425 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3426 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3428 HICON hIcon;
3429 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3430 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3432 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3433 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3434 psInfo->ppshheader.u.pszIcon,
3435 IMAGE_ICON,
3436 icon_cx, icon_cy,
3437 LR_DEFAULTCOLOR);
3438 else
3439 hIcon = psInfo->ppshheader.u.hIcon;
3441 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3444 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3445 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3447 psInfo->strPropertiesFor = strCaption;
3449 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3451 PROPSHEET_CreateTabControl(hwnd, psInfo);
3453 PROPSHEET_LoadWizardBitmaps(psInfo);
3455 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3457 ShowWindow(hwndTabCtrl, SW_HIDE);
3458 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3459 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3461 else
3463 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3465 PROPSHEET_AdjustSize(hwnd, psInfo);
3466 PROPSHEET_AdjustButtons(hwnd, psInfo);
3470 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3471 psInfo->ppshheader.hInstance)
3473 WCHAR szText[256];
3475 if (LoadStringW(psInfo->ppshheader.hInstance,
3476 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3477 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3479 else
3481 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3482 psInfo->ppshheader.pszCaption);
3486 if (psInfo->useCallback)
3487 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3489 idx = psInfo->active_page;
3490 psInfo->active_page = -1;
3492 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3494 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3495 * as some programs call TCM_GETCURSEL to get the current selection
3496 * from which to switch to the next page */
3497 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3499 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3501 return TRUE;
3504 case WM_PRINTCLIENT:
3505 case WM_PAINT:
3506 PROPSHEET_Paint(hwnd, (HDC)wParam);
3507 return TRUE;
3509 case WM_DESTROY:
3510 PROPSHEET_CleanUp(hwnd);
3511 return TRUE;
3513 case WM_CLOSE:
3514 PROPSHEET_Cancel(hwnd, 1);
3515 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3517 case WM_COMMAND:
3518 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3520 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3522 if (!psInfo)
3523 return FALSE;
3525 /* No default handler, forward notification to active page */
3526 if (psInfo->activeValid && psInfo->active_page != -1)
3528 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3529 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3532 return TRUE;
3534 case WM_NOTIFY:
3536 NMHDR* pnmh = (LPNMHDR) lParam;
3538 if (pnmh->code == TCN_SELCHANGE)
3540 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3541 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3544 if(pnmh->code == TCN_SELCHANGING)
3546 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3547 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3548 return TRUE;
3551 return FALSE;
3554 case WM_SYSCOLORCHANGE:
3555 COMCTL32_RefreshSysColors();
3556 return FALSE;
3558 case PSM_GETCURRENTPAGEHWND:
3560 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3561 HWND hwndPage = 0;
3563 if (!psInfo)
3564 return FALSE;
3566 if (psInfo->activeValid && psInfo->active_page != -1)
3567 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3569 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3571 return TRUE;
3574 case PSM_CHANGED:
3575 PROPSHEET_Changed(hwnd, (HWND)wParam);
3576 return TRUE;
3578 case PSM_UNCHANGED:
3579 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3580 return TRUE;
3582 case PSM_GETTABCONTROL:
3584 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3586 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3588 return TRUE;
3591 case PSM_SETCURSEL:
3593 BOOL msgResult;
3595 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3596 if(msgResult != FALSE)
3598 msgResult = PROPSHEET_SetCurSel(hwnd,
3599 (int)wParam,
3601 (HPROPSHEETPAGE)lParam);
3604 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3606 return TRUE;
3609 case PSM_CANCELTOCLOSE:
3611 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3612 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3613 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3615 EnableWindow(hwndCancel, FALSE);
3616 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3617 SetWindowTextW(hwndOK, buf);
3619 return FALSE;
3622 case PSM_RESTARTWINDOWS:
3624 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3626 if (!psInfo)
3627 return FALSE;
3629 /* reboot system takes precedence over restart windows */
3630 if (psInfo->result != ID_PSREBOOTSYSTEM)
3631 psInfo->result = ID_PSRESTARTWINDOWS;
3633 return TRUE;
3636 case PSM_REBOOTSYSTEM:
3638 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3640 if (!psInfo)
3641 return FALSE;
3643 psInfo->result = ID_PSREBOOTSYSTEM;
3645 return TRUE;
3648 case PSM_SETTITLEA:
3649 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3650 return TRUE;
3652 case PSM_SETTITLEW:
3653 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3654 return TRUE;
3656 case PSM_APPLY:
3658 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3660 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3662 return TRUE;
3665 case PSM_QUERYSIBLINGS:
3667 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3669 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3671 return TRUE;
3674 case PSM_ADDPAGE:
3677 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3678 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3679 * on success or FALSE otherwise, as specified on MSDN Online.
3680 * Also see the MFC code for
3681 * CPropertySheet::AddPage(CPropertyPage* pPage).
3684 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3686 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3688 return TRUE;
3691 case PSM_REMOVEPAGE:
3692 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3693 return TRUE;
3695 case PSM_ISDIALOGMESSAGE:
3697 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3698 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3699 return TRUE;
3702 case PSM_PRESSBUTTON:
3703 PROPSHEET_PressButton(hwnd, (int)wParam);
3704 return TRUE;
3706 case PSM_SETFINISHTEXTA:
3707 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3708 return TRUE;
3710 case PSM_SETWIZBUTTONS:
3711 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3712 return TRUE;
3714 case PSM_SETCURSELID:
3715 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3716 return TRUE;
3718 case PSM_SETFINISHTEXTW:
3719 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3720 return FALSE;
3722 case PSM_INSERTPAGE:
3724 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3725 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3726 return TRUE;
3729 case PSM_SETHEADERTITLEW:
3730 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3731 return TRUE;
3733 case PSM_SETHEADERTITLEA:
3734 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3735 return TRUE;
3737 case PSM_SETHEADERSUBTITLEW:
3738 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3739 return TRUE;
3741 case PSM_SETHEADERSUBTITLEA:
3742 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3743 return TRUE;
3745 case PSM_HWNDTOINDEX:
3747 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3748 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3749 return TRUE;
3752 case PSM_INDEXTOHWND:
3754 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3755 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3756 return TRUE;
3759 case PSM_PAGETOINDEX:
3761 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3762 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3763 return TRUE;
3766 case PSM_INDEXTOPAGE:
3768 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3769 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3770 return TRUE;
3773 case PSM_IDTOINDEX:
3775 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3776 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3777 return TRUE;
3780 case PSM_INDEXTOID:
3782 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3783 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3784 return TRUE;
3787 case PSM_GETRESULT:
3789 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3790 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3791 return TRUE;
3794 case PSM_RECALCPAGESIZES:
3796 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3801 default:
3802 return FALSE;