stash
[wine/wine64.git] / dlls / comctl32 / propsheet.c
blob7c2f26a8ec5d6b7ed817fd9740333ed358d6c7c7
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 tabOffsetX, tabOffsetY, buttonHeight;
744 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
745 RECT units;
747 /* Get the height of buttons */
748 GetClientRect(hwndButton, &rc);
749 buttonHeight = rc.bottom;
752 * Biggest page size.
754 rc.left = 0;
755 rc.top = 0;
756 rc.right = psInfo->width;
757 rc.bottom = psInfo->height;
759 MapDialogRect(hwndDlg, &rc);
761 /* retrieve the dialog units */
762 units.left = units.right = 4;
763 units.top = units.bottom = 8;
764 MapDialogRect(hwndDlg, &units);
767 * Resize the tab control.
769 GetClientRect(hwndTabCtrl,&tabRect);
771 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
773 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
775 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
776 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
779 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
781 rc.right = rc.left + tabRect.right - tabRect.left;
782 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
785 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
787 tabOffsetX = -(rc.left);
788 tabOffsetY = -(rc.top);
790 rc.right -= rc.left;
791 rc.bottom -= rc.top;
792 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
793 hwndTabCtrl, rc.right, rc.bottom);
794 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
795 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
797 GetClientRect(hwndTabCtrl, &rc);
799 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
801 rc.right += ((padding.x * 2) + tabOffsetX);
802 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
805 * Resize the property sheet.
807 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
808 hwndDlg, rc.right, rc.bottom);
809 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
810 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
811 return TRUE;
814 /******************************************************************************
815 * PROPSHEET_AdjustSizeWizard
817 * Resizes the property sheet to fit the largest page.
819 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
821 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
822 RECT rc, lineRect, dialogRect;
824 /* Biggest page size */
825 rc.left = 0;
826 rc.top = 0;
827 rc.right = psInfo->width;
828 rc.bottom = psInfo->height;
829 MapDialogRect(hwndDlg, &rc);
831 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
833 /* Add space for the buttons row */
834 GetWindowRect(hwndLine, &lineRect);
835 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
836 GetClientRect(hwndDlg, &dialogRect);
837 rc.bottom += dialogRect.bottom - lineRect.top - 1;
839 /* Convert the client coordinates to window coordinates */
840 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
842 /* Resize the property sheet */
843 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
844 hwndDlg, rc.right, rc.bottom);
845 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
846 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
848 return TRUE;
851 /******************************************************************************
852 * PROPSHEET_AdjustButtons
854 * Adjusts the buttons' positions.
856 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
858 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
859 RECT rcSheet;
860 int x, y;
861 int num_buttons = 2;
862 int buttonWidth, buttonHeight;
863 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
865 if (psInfo->hasApply)
866 num_buttons++;
868 if (psInfo->hasHelp)
869 num_buttons++;
872 * Obtain the size of the buttons.
874 GetClientRect(hwndButton, &rcSheet);
875 buttonWidth = rcSheet.right;
876 buttonHeight = rcSheet.bottom;
879 * Get the size of the property sheet.
881 GetClientRect(hwndParent, &rcSheet);
884 * All buttons will be at this y coordinate.
886 y = rcSheet.bottom - (padding.y + buttonHeight);
889 * Position OK button and make it default.
891 hwndButton = GetDlgItem(hwndParent, IDOK);
893 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
895 SetWindowPos(hwndButton, 0, x, y, 0, 0,
896 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
898 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
902 * Position Cancel button.
904 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
906 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
908 SetWindowPos(hwndButton, 0, x, y, 0, 0,
909 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
912 * Position Apply button.
914 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
916 if (psInfo->hasApply)
918 if (psInfo->hasHelp)
919 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
920 else
921 x = rcSheet.right - (padding.x + buttonWidth);
923 SetWindowPos(hwndButton, 0, x, y, 0, 0,
924 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
926 EnableWindow(hwndButton, FALSE);
928 else
929 ShowWindow(hwndButton, SW_HIDE);
932 * Position Help button.
934 hwndButton = GetDlgItem(hwndParent, IDHELP);
936 if (psInfo->hasHelp)
938 x = rcSheet.right - (padding.x + buttonWidth);
940 SetWindowPos(hwndButton, 0, x, y, 0, 0,
941 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
943 else
944 ShowWindow(hwndButton, SW_HIDE);
946 return TRUE;
949 /******************************************************************************
950 * PROPSHEET_AdjustButtonsWizard
952 * Adjusts the buttons' positions.
954 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
955 const PropSheetInfo* psInfo)
957 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
958 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
959 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
960 RECT rcSheet;
961 int x, y;
962 int num_buttons = 3;
963 int buttonWidth, buttonHeight, lineHeight, lineWidth;
964 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
966 if (psInfo->hasHelp)
967 num_buttons++;
968 if (psInfo->hasFinish)
969 num_buttons++;
972 * Obtain the size of the buttons.
974 GetClientRect(hwndButton, &rcSheet);
975 buttonWidth = rcSheet.right;
976 buttonHeight = rcSheet.bottom;
978 GetClientRect(hwndLine, &rcSheet);
979 lineHeight = rcSheet.bottom;
982 * Get the size of the property sheet.
984 GetClientRect(hwndParent, &rcSheet);
987 * All buttons will be at this y coordinate.
989 y = rcSheet.bottom - (padding.y + buttonHeight);
992 * Position the Back button.
994 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
996 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
998 SetWindowPos(hwndButton, 0, x, y, 0, 0,
999 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1002 * Position the Next button.
1004 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1006 x += buttonWidth;
1008 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1009 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1012 * Position the Finish button.
1014 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1016 if (psInfo->hasFinish)
1017 x += padding.x + buttonWidth;
1019 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1020 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1022 if (!psInfo->hasFinish)
1023 ShowWindow(hwndButton, SW_HIDE);
1026 * Position the Cancel button.
1028 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1030 x += padding.x + buttonWidth;
1032 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1033 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1036 * Position Help button.
1038 hwndButton = GetDlgItem(hwndParent, IDHELP);
1040 if (psInfo->hasHelp)
1042 x += padding.x + buttonWidth;
1044 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1045 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1047 else
1048 ShowWindow(hwndButton, SW_HIDE);
1050 if (psInfo->ppshheader.dwFlags &
1051 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1052 padding.x = 0;
1055 * Position and resize the sunken line.
1057 x = padding.x;
1058 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1060 lineWidth = rcSheet.right - (padding.x * 2);
1061 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1062 SWP_NOZORDER | SWP_NOACTIVATE);
1065 * Position and resize the header sunken line.
1068 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1069 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1070 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1071 ShowWindow(hwndLineHeader, SW_HIDE);
1073 return TRUE;
1076 /******************************************************************************
1077 * PROPSHEET_GetPaddingInfo
1079 * Returns the layout information.
1081 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1083 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1084 RECT rcTab;
1085 POINT tl;
1086 PADDING_INFO padding;
1088 GetWindowRect(hwndTab, &rcTab);
1090 tl.x = rcTab.left;
1091 tl.y = rcTab.top;
1093 ScreenToClient(hwndDlg, &tl);
1095 padding.x = tl.x;
1096 padding.y = tl.y;
1098 return padding;
1101 /******************************************************************************
1102 * PROPSHEET_GetPaddingInfoWizard
1104 * Returns the layout information.
1105 * Vertical spacing is the distance between the line and the buttons.
1106 * Do NOT use the Help button to gather padding information when it isn't mapped
1107 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1108 * for it in this case !
1109 * FIXME: I'm not sure about any other coordinate problems with these evil
1110 * buttons. Fix it in case additional problems appear or maybe calculate
1111 * a padding in a completely different way, as this is somewhat messy.
1113 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1114 psInfo)
1116 PADDING_INFO padding;
1117 RECT rc;
1118 HWND hwndControl;
1119 INT idButton;
1120 POINT ptButton, ptLine;
1122 TRACE("\n");
1123 if (psInfo->hasHelp)
1125 idButton = IDHELP;
1127 else
1129 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1131 idButton = IDC_NEXT_BUTTON;
1133 else
1135 /* hopefully this is ok */
1136 idButton = IDCANCEL;
1140 hwndControl = GetDlgItem(hwndDlg, idButton);
1141 GetWindowRect(hwndControl, &rc);
1143 ptButton.x = rc.left;
1144 ptButton.y = rc.top;
1146 ScreenToClient(hwndDlg, &ptButton);
1148 /* Line */
1149 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1150 GetWindowRect(hwndControl, &rc);
1152 ptLine.x = rc.left;
1153 ptLine.y = rc.bottom;
1155 ScreenToClient(hwndDlg, &ptLine);
1157 padding.y = ptButton.y - ptLine.y;
1159 if (padding.y < 0)
1160 ERR("padding negative ! Please report this !\n");
1162 /* this is most probably not correct, but the best we have now */
1163 padding.x = padding.y;
1164 return padding;
1167 /******************************************************************************
1168 * PROPSHEET_CreateTabControl
1170 * Insert the tabs in the tab control.
1172 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1173 const PropSheetInfo * psInfo)
1175 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1176 TCITEMW item;
1177 int i, nTabs;
1178 int iImage = 0;
1180 TRACE("\n");
1181 item.mask = TCIF_TEXT;
1182 item.cchTextMax = MAX_TABTEXT_LENGTH;
1184 nTabs = psInfo->nPages;
1187 * Set the image list for icons.
1189 if (psInfo->hImageList)
1191 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1194 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1195 for (i = 0; i < nTabs; i++)
1197 if ( psInfo->proppage[i].hasIcon )
1199 item.mask |= TCIF_IMAGE;
1200 item.iImage = iImage++;
1202 else
1204 item.mask &= ~TCIF_IMAGE;
1207 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1208 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1210 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1212 return TRUE;
1215 /******************************************************************************
1216 * PROPSHEET_WizardSubclassProc
1218 * Subclassing window procedure for wizard exterior pages to prevent drawing
1219 * background and so drawing above the watermark.
1221 static LRESULT CALLBACK
1222 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1224 switch (uMsg)
1226 case WM_ERASEBKGND:
1227 return TRUE;
1229 case WM_CTLCOLORSTATIC:
1230 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1231 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1234 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1238 * Get the size of an in-memory Template
1240 *( Based on the code of PROPSHEET_CollectPageInfo)
1241 * See also dialog.c/DIALOG_ParseTemplate32().
1244 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1247 const WORD* p = (const WORD *)pTemplate;
1248 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1249 WORD nrofitems;
1250 UINT ret;
1252 if (istemplateex)
1254 /* DLGTEMPLATEEX (not defined in any std. header file) */
1256 TRACE("is DLGTEMPLATEEX\n");
1257 p++; /* dlgVer */
1258 p++; /* signature */
1259 p += 2; /* help ID */
1260 p += 2; /* ext style */
1261 p += 2; /* style */
1263 else
1265 /* DLGTEMPLATE */
1267 TRACE("is DLGTEMPLATE\n");
1268 p += 2; /* style */
1269 p += 2; /* ext style */
1272 nrofitems = (WORD)*p; p++; /* nb items */
1273 p++; /* x */
1274 p++; /* y */
1275 p++; /* width */
1276 p++; /* height */
1278 /* menu */
1279 switch ((WORD)*p)
1281 case 0x0000:
1282 p++;
1283 break;
1284 case 0xffff:
1285 p += 2;
1286 break;
1287 default:
1288 TRACE("menu %s\n",debugstr_w( p ));
1289 p += lstrlenW( p ) + 1;
1290 break;
1293 /* class */
1294 switch ((WORD)*p)
1296 case 0x0000:
1297 p++;
1298 break;
1299 case 0xffff:
1300 p += 2; /* 0xffff plus predefined window class ordinal value */
1301 break;
1302 default:
1303 TRACE("class %s\n",debugstr_w( p ));
1304 p += lstrlenW( p ) + 1;
1305 break;
1308 /* title */
1309 TRACE("title %s\n",debugstr_w( p ));
1310 p += lstrlenW( p ) + 1;
1312 /* font, if DS_SETFONT set */
1313 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1314 pTemplate->style)))
1316 p+=(istemplateex)?3:1;
1317 TRACE("font %s\n",debugstr_w( p ));
1318 p += lstrlenW( p ) + 1; /* the font name */
1321 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1322 * that are following the DLGTEMPLATE(EX) data */
1323 TRACE("%d items\n",nrofitems);
1324 while (nrofitems > 0)
1326 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1328 /* skip header */
1329 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1331 /* check class */
1332 switch ((WORD)*p)
1334 case 0x0000:
1335 p++;
1336 break;
1337 case 0xffff:
1338 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1339 p += 2;
1340 break;
1341 default:
1342 TRACE("class %s\n",debugstr_w( p ));
1343 p += lstrlenW( p ) + 1;
1344 break;
1347 /* check title text */
1348 switch ((WORD)*p)
1350 case 0x0000:
1351 p++;
1352 break;
1353 case 0xffff:
1354 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1355 p += 2;
1356 break;
1357 default:
1358 TRACE("text %s\n",debugstr_w( p ));
1359 p += lstrlenW( p ) + 1;
1360 break;
1362 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1363 --nrofitems;
1366 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1367 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1368 return ret;
1371 /******************************************************************************
1372 * PROPSHEET_CreatePage
1374 * Creates a page.
1376 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1377 int index,
1378 const PropSheetInfo * psInfo,
1379 LPCPROPSHEETPAGEW ppshpage)
1381 DLGTEMPLATE* pTemplate;
1382 HWND hwndPage;
1383 DWORD resSize;
1384 LPVOID temp = NULL;
1386 TRACE("index %d\n", index);
1388 if (ppshpage == NULL)
1390 return FALSE;
1393 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1395 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1396 resSize = GetTemplateSize(pTemplate);
1398 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1400 HRSRC hResource;
1401 HANDLE hTemplate;
1403 hResource = FindResourceW(ppshpage->hInstance,
1404 ppshpage->u.pszTemplate,
1405 (LPWSTR)RT_DIALOG);
1406 if(!hResource)
1407 return FALSE;
1409 resSize = SizeofResource(ppshpage->hInstance, hResource);
1411 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1412 if(!hTemplate)
1413 return FALSE;
1415 pTemplate = LockResource(hTemplate);
1417 * Make a copy of the dialog template to make it writable
1420 else
1422 HRSRC hResource;
1423 HANDLE hTemplate;
1425 hResource = FindResourceA(ppshpage->hInstance,
1426 (LPCSTR)ppshpage->u.pszTemplate,
1427 (LPSTR)RT_DIALOG);
1428 if(!hResource)
1429 return FALSE;
1431 resSize = SizeofResource(ppshpage->hInstance, hResource);
1433 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1434 if(!hTemplate)
1435 return FALSE;
1437 pTemplate = LockResource(hTemplate);
1439 * Make a copy of the dialog template to make it writable
1442 temp = Alloc(resSize);
1443 if (!temp)
1444 return FALSE;
1446 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1447 memcpy(temp, pTemplate, resSize);
1448 pTemplate = temp;
1450 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1452 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1453 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1454 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1457 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1459 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1461 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1463 else
1465 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1466 pTemplate->style &= ~DS_MODALFRAME;
1467 pTemplate->style &= ~WS_CAPTION;
1468 pTemplate->style &= ~WS_SYSMENU;
1469 pTemplate->style &= ~WS_POPUP;
1470 pTemplate->style &= ~WS_DISABLED;
1471 pTemplate->style &= ~WS_VISIBLE;
1472 pTemplate->style &= ~WS_THICKFRAME;
1474 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1477 if (psInfo->proppage[index].useCallback)
1478 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1479 (LPPROPSHEETPAGEW)ppshpage);
1481 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1482 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1483 pTemplate,
1484 hwndParent,
1485 ppshpage->pfnDlgProc,
1486 (LPARAM)ppshpage);
1487 else
1488 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1489 pTemplate,
1490 hwndParent,
1491 ppshpage->pfnDlgProc,
1492 (LPARAM)ppshpage);
1493 /* Free a no more needed copy */
1494 Free(temp);
1496 psInfo->proppage[index].hwndPage = hwndPage;
1498 /* Subclass exterior wizard pages */
1499 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1500 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1501 (ppshpage->dwFlags & PSP_HIDEHEADER))
1503 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1504 (DWORD_PTR)ppshpage);
1506 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1507 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1509 return TRUE;
1512 /******************************************************************************
1513 * PROPSHEET_LoadWizardBitmaps
1515 * Loads the watermark and header bitmaps for a wizard.
1517 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1519 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1521 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1522 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1523 considers hbmWatermark as valid. */
1524 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1525 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1527 psInfo->ppshheader.u4.hbmWatermark =
1528 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1531 /* Same behavior as for watermarks */
1532 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1533 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1535 psInfo->ppshheader.u5.hbmHeader =
1536 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1542 /******************************************************************************
1543 * PROPSHEET_ShowPage
1545 * Displays or creates the specified page.
1547 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1549 HWND hwndTabCtrl;
1550 HWND hwndLineHeader;
1551 LPCPROPSHEETPAGEW ppshpage;
1553 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1554 if (index == psInfo->active_page)
1556 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1557 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1558 return TRUE;
1561 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1562 if (psInfo->proppage[index].hwndPage == 0)
1564 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1567 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1569 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1570 psInfo->proppage[index].pszText);
1573 if (psInfo->active_page != -1)
1574 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1576 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1578 /* Synchronize current selection with tab control
1579 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1580 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1581 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1583 psInfo->active_page = index;
1584 psInfo->activeValid = TRUE;
1586 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1588 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1589 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1591 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1592 ShowWindow(hwndLineHeader, SW_HIDE);
1593 else
1594 ShowWindow(hwndLineHeader, SW_SHOW);
1597 return TRUE;
1600 /******************************************************************************
1601 * PROPSHEET_Back
1603 static BOOL PROPSHEET_Back(HWND hwndDlg)
1605 PSHNOTIFY psn;
1606 HWND hwndPage;
1607 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1608 LRESULT result;
1609 int idx;
1611 TRACE("active_page %d\n", psInfo->active_page);
1612 if (psInfo->active_page < 0)
1613 return FALSE;
1615 psn.hdr.code = PSN_WIZBACK;
1616 psn.hdr.hwndFrom = hwndDlg;
1617 psn.hdr.idFrom = 0;
1618 psn.lParam = 0;
1620 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1622 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1623 if (result == -1)
1624 return FALSE;
1625 else if (result == 0)
1626 idx = psInfo->active_page - 1;
1627 else
1628 idx = PROPSHEET_FindPageByResId(psInfo, result);
1630 if (idx >= 0 && idx < psInfo->nPages)
1632 if (PROPSHEET_CanSetCurSel(hwndDlg))
1633 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1635 return TRUE;
1638 /******************************************************************************
1639 * PROPSHEET_Next
1641 static BOOL PROPSHEET_Next(HWND hwndDlg)
1643 PSHNOTIFY psn;
1644 HWND hwndPage;
1645 LRESULT msgResult = 0;
1646 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1647 int idx;
1649 TRACE("active_page %d\n", psInfo->active_page);
1650 if (psInfo->active_page < 0)
1651 return FALSE;
1653 psn.hdr.code = PSN_WIZNEXT;
1654 psn.hdr.hwndFrom = hwndDlg;
1655 psn.hdr.idFrom = 0;
1656 psn.lParam = 0;
1658 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1660 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1661 if (msgResult == -1)
1662 return FALSE;
1663 else if (msgResult == 0)
1664 idx = psInfo->active_page + 1;
1665 else
1666 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1668 if (idx < psInfo->nPages )
1670 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1671 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1674 return TRUE;
1677 /******************************************************************************
1678 * PROPSHEET_Finish
1680 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1682 PSHNOTIFY psn;
1683 HWND hwndPage;
1684 LRESULT msgResult = 0;
1685 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1687 TRACE("active_page %d\n", psInfo->active_page);
1688 if (psInfo->active_page < 0)
1689 return FALSE;
1691 psn.hdr.code = PSN_WIZFINISH;
1692 psn.hdr.hwndFrom = hwndDlg;
1693 psn.hdr.idFrom = 0;
1694 psn.lParam = 0;
1696 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1698 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1700 TRACE("msg result %ld\n", msgResult);
1702 if (msgResult != 0)
1703 return FALSE;
1705 if (psInfo->result == 0)
1706 psInfo->result = IDOK;
1707 if (psInfo->isModeless)
1708 psInfo->activeValid = FALSE;
1709 else
1710 psInfo->ended = TRUE;
1712 return TRUE;
1715 /******************************************************************************
1716 * PROPSHEET_Apply
1718 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1720 int i;
1721 HWND hwndPage;
1722 PSHNOTIFY psn;
1723 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1725 TRACE("active_page %d\n", psInfo->active_page);
1726 if (psInfo->active_page < 0)
1727 return FALSE;
1729 psn.hdr.hwndFrom = hwndDlg;
1730 psn.hdr.idFrom = 0;
1731 psn.lParam = 0;
1735 * Send PSN_KILLACTIVE to the current page.
1737 psn.hdr.code = PSN_KILLACTIVE;
1739 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1741 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1742 return FALSE;
1745 * Send PSN_APPLY to all pages.
1747 psn.hdr.code = PSN_APPLY;
1748 psn.lParam = lParam;
1750 for (i = 0; i < psInfo->nPages; i++)
1752 hwndPage = psInfo->proppage[i].hwndPage;
1753 if (hwndPage)
1755 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1757 case PSNRET_INVALID:
1758 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1759 /* fall through */
1760 case PSNRET_INVALID_NOCHANGEPAGE:
1761 return FALSE;
1766 if(lParam)
1768 psInfo->activeValid = FALSE;
1770 else if(psInfo->active_page >= 0)
1772 psn.hdr.code = PSN_SETACTIVE;
1773 psn.lParam = 0;
1774 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1775 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1778 return TRUE;
1781 /******************************************************************************
1782 * PROPSHEET_Cancel
1784 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1786 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1787 HWND hwndPage;
1788 PSHNOTIFY psn;
1789 int i;
1791 TRACE("active_page %d\n", psInfo->active_page);
1792 if (psInfo->active_page < 0)
1793 return;
1795 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1796 psn.hdr.code = PSN_QUERYCANCEL;
1797 psn.hdr.hwndFrom = hwndDlg;
1798 psn.hdr.idFrom = 0;
1799 psn.lParam = 0;
1801 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1802 return;
1804 psn.hdr.code = PSN_RESET;
1805 psn.lParam = lParam;
1807 for (i = 0; i < psInfo->nPages; i++)
1809 hwndPage = psInfo->proppage[i].hwndPage;
1811 if (hwndPage)
1812 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1815 if (psInfo->isModeless)
1817 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1818 psInfo->activeValid = FALSE;
1820 else
1821 psInfo->ended = TRUE;
1824 /******************************************************************************
1825 * PROPSHEET_Help
1827 static void PROPSHEET_Help(HWND hwndDlg)
1829 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1830 HWND hwndPage;
1831 PSHNOTIFY psn;
1833 TRACE("active_page %d\n", psInfo->active_page);
1834 if (psInfo->active_page < 0)
1835 return;
1837 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1838 psn.hdr.code = PSN_HELP;
1839 psn.hdr.hwndFrom = hwndDlg;
1840 psn.hdr.idFrom = 0;
1841 psn.lParam = 0;
1843 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1846 /******************************************************************************
1847 * PROPSHEET_Changed
1849 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1851 int i;
1852 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1854 TRACE("\n");
1855 if (!psInfo) return;
1857 * Set the dirty flag of this page.
1859 for (i = 0; i < psInfo->nPages; i++)
1861 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1862 psInfo->proppage[i].isDirty = TRUE;
1866 * Enable the Apply button.
1868 if (psInfo->hasApply)
1870 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1872 EnableWindow(hwndApplyBtn, TRUE);
1876 /******************************************************************************
1877 * PROPSHEET_UnChanged
1879 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1881 int i;
1882 BOOL noPageDirty = TRUE;
1883 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1884 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1886 TRACE("\n");
1887 if ( !psInfo ) return;
1888 for (i = 0; i < psInfo->nPages; i++)
1890 /* set the specified page as clean */
1891 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1892 psInfo->proppage[i].isDirty = FALSE;
1894 /* look to see if there's any dirty pages */
1895 if (psInfo->proppage[i].isDirty)
1896 noPageDirty = FALSE;
1900 * Disable Apply button.
1902 if (noPageDirty)
1903 EnableWindow(hwndApplyBtn, FALSE);
1906 /******************************************************************************
1907 * PROPSHEET_PressButton
1909 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1911 TRACE("buttonID %d\n", buttonID);
1912 switch (buttonID)
1914 case PSBTN_APPLYNOW:
1915 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1916 break;
1917 case PSBTN_BACK:
1918 PROPSHEET_Back(hwndDlg);
1919 break;
1920 case PSBTN_CANCEL:
1921 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1922 break;
1923 case PSBTN_FINISH:
1924 PROPSHEET_Finish(hwndDlg);
1925 break;
1926 case PSBTN_HELP:
1927 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1928 break;
1929 case PSBTN_NEXT:
1930 PROPSHEET_Next(hwndDlg);
1931 break;
1932 case PSBTN_OK:
1933 PROPSHEET_DoCommand(hwndDlg, IDOK);
1934 break;
1935 default:
1936 FIXME("Invalid button index %d\n", buttonID);
1941 /*************************************************************************
1942 * BOOL PROPSHEET_CanSetCurSel [Internal]
1944 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1946 * PARAMS
1947 * hwndDlg [I] handle to a Dialog hWnd
1949 * RETURNS
1950 * TRUE if Current Selection can change
1952 * NOTES
1954 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1956 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1957 HWND hwndPage;
1958 PSHNOTIFY psn;
1959 BOOL res = FALSE;
1961 TRACE("active_page %d\n", psInfo->active_page);
1962 if (!psInfo)
1964 res = FALSE;
1965 goto end;
1968 if (psInfo->active_page < 0)
1970 res = TRUE;
1971 goto end;
1975 * Notify the current page.
1977 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1978 psn.hdr.code = PSN_KILLACTIVE;
1979 psn.hdr.hwndFrom = hwndDlg;
1980 psn.hdr.idFrom = 0;
1981 psn.lParam = 0;
1983 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1985 end:
1986 TRACE("<-- %d\n", res);
1987 return res;
1990 /******************************************************************************
1991 * PROPSHEET_SetCurSel
1993 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1994 int index,
1995 int skipdir,
1996 HPROPSHEETPAGE hpage
1999 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2000 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2001 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2003 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2004 /* hpage takes precedence over index */
2005 if (hpage != NULL)
2006 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2008 if (index < 0 || index >= psInfo->nPages)
2010 TRACE("Could not find page to select!\n");
2011 return FALSE;
2014 /* unset active page while doing this transition. */
2015 if (psInfo->active_page != -1)
2016 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2017 psInfo->active_page = -1;
2019 while (1) {
2020 int result;
2021 PSHNOTIFY psn;
2022 RECT rc;
2023 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2025 if (hwndTabControl)
2026 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2028 psn.hdr.code = PSN_SETACTIVE;
2029 psn.hdr.hwndFrom = hwndDlg;
2030 psn.hdr.idFrom = 0;
2031 psn.lParam = 0;
2033 if (!psInfo->proppage[index].hwndPage) {
2034 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2037 /* Resize the property sheet page to the fit in the Tab control
2038 * (for regular property sheets) or to fit in the client area (for
2039 * wizards).
2040 * NOTE: The resizing happens every time the page is selected and
2041 * not only when it's created (some applications depend on it). */
2042 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2043 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2044 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2045 rc.right - rc.left, rc.bottom - rc.top);
2046 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2047 rc.left, rc.top,
2048 rc.right - rc.left, rc.bottom - rc.top, 0);
2050 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2051 if (!result)
2052 break;
2053 if (result == -1) {
2054 index+=skipdir;
2055 if (index < 0) {
2056 index = 0;
2057 WARN("Tried to skip before first property sheet page!\n");
2058 break;
2060 if (index >= psInfo->nPages) {
2061 WARN("Tried to skip after last property sheet page!\n");
2062 index = psInfo->nPages-1;
2063 break;
2066 else if (result != 0)
2068 int old_index = index;
2069 index = PROPSHEET_FindPageByResId(psInfo, result);
2070 if(index >= psInfo->nPages) {
2071 index = old_index;
2072 WARN("Tried to skip to nonexistent page by res id\n");
2073 break;
2075 continue;
2079 /* Invalidate the header area */
2080 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2081 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2083 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2084 RECT r;
2086 GetClientRect(hwndLineHeader, &r);
2087 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2088 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2090 InvalidateRect(hwndDlg, &r, TRUE);
2094 * Display the new page.
2096 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2098 if (psInfo->proppage[index].hasHelp)
2099 EnableWindow(hwndHelp, TRUE);
2100 else
2101 EnableWindow(hwndHelp, FALSE);
2103 return TRUE;
2106 /******************************************************************************
2107 * PROPSHEET_SetCurSelId
2109 * Selects the page, specified by resource id.
2111 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2113 int idx;
2114 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2116 idx = PROPSHEET_FindPageByResId(psInfo, id);
2117 if (idx < psInfo->nPages )
2119 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2120 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2124 /******************************************************************************
2125 * PROPSHEET_SetTitleA
2127 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2129 if(HIWORD(lpszText))
2131 WCHAR szTitle[256];
2132 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2133 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2134 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2136 else
2138 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2142 /******************************************************************************
2143 * PROPSHEET_SetTitleW
2145 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2147 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2148 WCHAR szTitle[256];
2150 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2151 if (HIWORD(lpszText) == 0) {
2152 if (!LoadStringW(psInfo->ppshheader.hInstance,
2153 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2154 return;
2155 lpszText = szTitle;
2157 if (dwStyle & PSH_PROPTITLE)
2159 WCHAR* dest;
2160 int lentitle = strlenW(lpszText);
2161 int lenprop = strlenW(psInfo->strPropertiesFor);
2163 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2164 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2166 SetWindowTextW(hwndDlg, dest);
2167 Free(dest);
2169 else
2170 SetWindowTextW(hwndDlg, lpszText);
2173 /******************************************************************************
2174 * PROPSHEET_SetFinishTextA
2176 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2178 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2179 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2181 TRACE("'%s'\n", lpszText);
2182 /* Set text, show and enable the Finish button */
2183 SetWindowTextA(hwndButton, lpszText);
2184 ShowWindow(hwndButton, SW_SHOW);
2185 EnableWindow(hwndButton, TRUE);
2187 /* Make it default pushbutton */
2188 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2190 /* Hide Back button */
2191 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2192 ShowWindow(hwndButton, SW_HIDE);
2194 if (!psInfo->hasFinish)
2196 /* Hide Next button */
2197 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2198 ShowWindow(hwndButton, SW_HIDE);
2202 /******************************************************************************
2203 * PROPSHEET_SetFinishTextW
2205 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2207 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2208 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2210 TRACE("%s\n", debugstr_w(lpszText));
2211 /* Set text, show and enable the Finish button */
2212 SetWindowTextW(hwndButton, lpszText);
2213 ShowWindow(hwndButton, SW_SHOW);
2214 EnableWindow(hwndButton, TRUE);
2216 /* Make it default pushbutton */
2217 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2219 /* Hide Back button */
2220 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2221 ShowWindow(hwndButton, SW_HIDE);
2223 if (!psInfo->hasFinish)
2225 /* Hide Next button */
2226 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2227 ShowWindow(hwndButton, SW_HIDE);
2231 /******************************************************************************
2232 * PROPSHEET_QuerySiblings
2234 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2235 WPARAM wParam, LPARAM lParam)
2237 int i = 0;
2238 HWND hwndPage;
2239 LRESULT msgResult = 0;
2240 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2242 while ((i < psInfo->nPages) && (msgResult == 0))
2244 hwndPage = psInfo->proppage[i].hwndPage;
2245 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2246 i++;
2249 return msgResult;
2253 /******************************************************************************
2254 * PROPSHEET_AddPage
2256 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2257 HPROPSHEETPAGE hpage)
2259 PropPageInfo * ppi;
2260 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2261 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2262 TCITEMW item;
2263 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2265 TRACE("hpage %p\n", hpage);
2267 * Allocate and fill in a new PropPageInfo entry.
2269 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2270 if (!ppi)
2271 return FALSE;
2273 psInfo->proppage = ppi;
2274 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2275 return FALSE;
2277 psInfo->proppage[psInfo->nPages].hpage = hpage;
2279 if (ppsp->dwFlags & PSP_PREMATURE)
2281 /* Create the page but don't show it */
2282 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2286 * Add a new tab to the tab control.
2288 item.mask = TCIF_TEXT;
2289 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2290 item.cchTextMax = MAX_TABTEXT_LENGTH;
2292 if (psInfo->hImageList)
2294 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2297 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2299 item.mask |= TCIF_IMAGE;
2300 item.iImage = psInfo->nPages;
2303 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2304 (LPARAM)&item);
2306 psInfo->nPages++;
2308 /* If it is the only page - show it */
2309 if(psInfo->nPages == 1)
2310 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2311 return TRUE;
2314 /******************************************************************************
2315 * PROPSHEET_RemovePage
2317 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2318 int index,
2319 HPROPSHEETPAGE hpage)
2321 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2322 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2323 PropPageInfo* oldPages;
2325 TRACE("index %d, hpage %p\n", index, hpage);
2326 if (!psInfo) {
2327 return FALSE;
2330 * hpage takes precedence over index.
2332 if (hpage != 0)
2334 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2337 /* Make sure that index is within range */
2338 if (index < 0 || index >= psInfo->nPages)
2340 TRACE("Could not find page to remove!\n");
2341 return FALSE;
2344 TRACE("total pages %d removing page %d active page %d\n",
2345 psInfo->nPages, index, psInfo->active_page);
2347 * Check if we're removing the active page.
2349 if (index == psInfo->active_page)
2351 if (psInfo->nPages > 1)
2353 if (index > 0)
2355 /* activate previous page */
2356 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2358 else
2360 /* activate the next page */
2361 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2362 psInfo->active_page = index;
2365 else
2367 psInfo->active_page = -1;
2368 if (!psInfo->isModeless)
2370 psInfo->ended = TRUE;
2371 return TRUE;
2375 else if (index < psInfo->active_page)
2376 psInfo->active_page--;
2378 /* Unsubclass the page dialog window */
2379 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2380 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2381 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2383 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2384 PROPSHEET_WizardSubclassProc, 1);
2387 /* Destroy page dialog window */
2388 DestroyWindow(psInfo->proppage[index].hwndPage);
2390 /* Free page resources */
2391 if(psInfo->proppage[index].hpage)
2393 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2395 if (psp->dwFlags & PSP_USETITLE)
2396 Free ((LPVOID)psInfo->proppage[index].pszText);
2398 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2401 /* Remove the tab */
2402 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2404 oldPages = psInfo->proppage;
2405 psInfo->nPages--;
2406 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2408 if (index > 0)
2409 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2411 if (index < psInfo->nPages)
2412 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2413 (psInfo->nPages - index) * sizeof(PropPageInfo));
2415 Free(oldPages);
2417 return FALSE;
2420 /******************************************************************************
2421 * PROPSHEET_SetWizButtons
2423 * This code will work if (and assumes that) the Next button is on top of the
2424 * Finish button. ie. Finish comes after Next in the Z order.
2425 * This means make sure the dialog template reflects this.
2428 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2430 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2431 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2432 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2433 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2435 TRACE("%d\n", dwFlags);
2437 EnableWindow(hwndBack, FALSE);
2438 EnableWindow(hwndNext, FALSE);
2439 EnableWindow(hwndFinish, FALSE);
2441 /* set the default pushbutton to an enabled button */
2442 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2443 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2444 else if (dwFlags & PSWIZB_NEXT)
2445 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2446 else if (dwFlags & PSWIZB_BACK)
2447 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2448 else
2449 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2452 if (dwFlags & PSWIZB_BACK)
2453 EnableWindow(hwndBack, TRUE);
2455 if (dwFlags & PSWIZB_NEXT)
2456 EnableWindow(hwndNext, TRUE);
2458 if (!psInfo->hasFinish)
2460 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2462 /* Hide the Next button */
2463 ShowWindow(hwndNext, SW_HIDE);
2465 /* Show the Finish button */
2466 ShowWindow(hwndFinish, SW_SHOW);
2468 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2469 EnableWindow(hwndFinish, TRUE);
2471 else
2473 /* Hide the Finish button */
2474 ShowWindow(hwndFinish, SW_HIDE);
2475 /* Show the Next button */
2476 ShowWindow(hwndNext, SW_SHOW);
2479 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2480 EnableWindow(hwndFinish, TRUE);
2483 /******************************************************************************
2484 * PROPSHEET_InsertPage
2486 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2488 if (!HIWORD(hpageInsertAfter))
2489 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2490 else
2491 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2492 return FALSE;
2495 /******************************************************************************
2496 * PROPSHEET_SetHeaderTitleW
2498 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2500 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2503 /******************************************************************************
2504 * PROPSHEET_SetHeaderTitleA
2506 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2508 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2511 /******************************************************************************
2512 * PROPSHEET_SetHeaderSubTitleW
2514 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2516 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2519 /******************************************************************************
2520 * PROPSHEET_SetHeaderSubTitleA
2522 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2524 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2527 /******************************************************************************
2528 * PROPSHEET_HwndToIndex
2530 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2532 int index;
2533 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2535 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2537 for (index = 0; index < psInfo->nPages; index++)
2538 if (psInfo->proppage[index].hwndPage == hPageDlg)
2539 return index;
2540 WARN("%p not found\n", hPageDlg);
2541 return -1;
2544 /******************************************************************************
2545 * PROPSHEET_IndexToHwnd
2547 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2549 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2550 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2551 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2552 WARN("%d out of range.\n", iPageIndex);
2553 return 0;
2555 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2558 /******************************************************************************
2559 * PROPSHEET_PageToIndex
2561 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2563 int index;
2564 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2566 TRACE("(%p, %p)\n", hwndDlg, hPage);
2568 for (index = 0; index < psInfo->nPages; index++)
2569 if (psInfo->proppage[index].hpage == hPage)
2570 return index;
2571 WARN("%p not found\n", hPage);
2572 return -1;
2575 /******************************************************************************
2576 * PROPSHEET_IndexToPage
2578 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2580 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2581 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2582 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2583 WARN("%d out of range.\n", iPageIndex);
2584 return 0;
2586 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2589 /******************************************************************************
2590 * PROPSHEET_IdToIndex
2592 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2594 int index;
2595 LPCPROPSHEETPAGEW psp;
2596 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2597 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2598 for (index = 0; index < psInfo->nPages; index++) {
2599 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2600 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2601 return index;
2604 return -1;
2607 /******************************************************************************
2608 * PROPSHEET_IndexToId
2610 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2612 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2613 LPCPROPSHEETPAGEW psp;
2614 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2615 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2616 WARN("%d out of range.\n", iPageIndex);
2617 return 0;
2619 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2620 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2621 return 0;
2623 return (LRESULT)psp->u.pszTemplate;
2626 /******************************************************************************
2627 * PROPSHEET_GetResult
2629 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2631 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2632 return psInfo->result;
2635 /******************************************************************************
2636 * PROPSHEET_RecalcPageSizes
2638 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2640 FIXME("(%p): stub\n", hwndDlg);
2641 return FALSE;
2644 /******************************************************************************
2645 * PROPSHEET_GetPageIndex
2647 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2648 * the array of PropPageInfo.
2650 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2652 BOOL found = FALSE;
2653 int index = 0;
2655 TRACE("hpage %p\n", hpage);
2656 while ((index < psInfo->nPages) && (found == FALSE))
2658 if (psInfo->proppage[index].hpage == hpage)
2659 found = TRUE;
2660 else
2661 index++;
2664 if (found == FALSE)
2665 index = -1;
2667 return index;
2670 /******************************************************************************
2671 * PROPSHEET_CleanUp
2673 static void PROPSHEET_CleanUp(HWND hwndDlg)
2675 int i;
2676 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2678 TRACE("\n");
2679 if (!psInfo) return;
2680 if (HIWORD(psInfo->ppshheader.pszCaption))
2681 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2683 for (i = 0; i < psInfo->nPages; i++)
2685 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2687 /* Unsubclass the page dialog window */
2688 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2689 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2690 (psp->dwFlags & PSP_HIDEHEADER))
2692 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2693 PROPSHEET_WizardSubclassProc, 1);
2696 if(psInfo->proppage[i].hwndPage)
2697 DestroyWindow(psInfo->proppage[i].hwndPage);
2699 if(psp)
2701 if (psp->dwFlags & PSP_USETITLE)
2702 Free ((LPVOID)psInfo->proppage[i].pszText);
2704 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2708 DeleteObject(psInfo->hFont);
2709 DeleteObject(psInfo->hFontBold);
2710 /* If we created the bitmaps, destroy them */
2711 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2712 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2713 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2714 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2715 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2716 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2718 Free(psInfo->proppage);
2719 Free(psInfo->strPropertiesFor);
2720 ImageList_Destroy(psInfo->hImageList);
2722 GlobalFree((HGLOBAL)psInfo);
2725 static INT do_loop(const PropSheetInfo *psInfo)
2727 MSG msg;
2728 INT ret = -1;
2729 HWND hwnd = psInfo->hwnd;
2731 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2733 if(ret == -1)
2734 break;
2736 if(!IsDialogMessageW(hwnd, &msg))
2738 TranslateMessage(&msg);
2739 DispatchMessageW(&msg);
2743 if(ret == 0)
2745 PostQuitMessage(msg.wParam);
2746 ret = -1;
2749 if(ret != -1)
2750 ret = psInfo->result;
2752 DestroyWindow(hwnd);
2753 return ret;
2756 /******************************************************************************
2757 * PROPSHEET_PropertySheet
2759 * Common code between PropertySheetA/W
2761 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2763 INT_PTR bRet = 0;
2764 HWND parent = NULL;
2765 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2766 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2768 psInfo->unicode = unicode;
2769 psInfo->ended = FALSE;
2771 if(!psInfo->isModeless)
2773 parent = psInfo->ppshheader.hwndParent;
2774 if (parent) EnableWindow(parent, FALSE);
2776 bRet = PROPSHEET_CreateDialog(psInfo);
2777 if(!psInfo->isModeless)
2779 bRet = do_loop(psInfo);
2780 if (parent) EnableWindow(parent, TRUE);
2782 return bRet;
2785 /******************************************************************************
2786 * PropertySheet (COMCTL32.@)
2787 * PropertySheetA (COMCTL32.@)
2789 * Creates a property sheet in the specified property sheet header.
2791 * RETURNS
2792 * Modal property sheets: Positive if successful or -1 otherwise.
2793 * Modeless property sheets: Property sheet handle.
2794 * Or:
2795 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2796 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2798 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2800 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2801 UINT i, n;
2802 const BYTE* pByte;
2804 TRACE("(%p)\n", lppsh);
2806 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2808 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2809 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2811 for (n = i = 0; i < lppsh->nPages; i++, n++)
2813 if (!psInfo->usePropPage)
2814 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2815 else
2817 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2818 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2821 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2822 psInfo, n, TRUE))
2824 if (psInfo->usePropPage)
2825 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2826 n--;
2827 psInfo->nPages--;
2831 return PROPSHEET_PropertySheet(psInfo, FALSE);
2834 /******************************************************************************
2835 * PropertySheetW (COMCTL32.@)
2837 * See PropertySheetA.
2839 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2841 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2842 UINT i, n;
2843 const BYTE* pByte;
2845 TRACE("(%p)\n", lppsh);
2847 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2849 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2850 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2852 for (n = i = 0; i < lppsh->nPages; i++, n++)
2854 if (!psInfo->usePropPage)
2855 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2856 else
2858 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2859 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2862 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2863 psInfo, n, TRUE))
2865 if (psInfo->usePropPage)
2866 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2867 n--;
2868 psInfo->nPages--;
2872 return PROPSHEET_PropertySheet(psInfo, TRUE);
2875 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2877 LPWSTR ret;
2879 if (IS_INTRESOURCE(str))
2881 HRSRC hrsrc;
2882 HGLOBAL hmem;
2883 WCHAR *ptr;
2884 WORD i, id = LOWORD(str);
2885 UINT len;
2887 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2888 return NULL;
2889 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2890 if (!(ptr = LockResource( hmem ))) return NULL;
2891 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2892 len = *ptr;
2893 if (!len) return NULL;
2894 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2895 if (ret)
2897 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2898 ret[len] = 0;
2901 else
2903 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2904 ret = Alloc( len );
2905 if (ret) memcpy( ret, str, len );
2907 return ret;
2911 /******************************************************************************
2912 * CreatePropertySheetPage (COMCTL32.@)
2913 * CreatePropertySheetPageA (COMCTL32.@)
2915 * Creates a new property sheet page.
2917 * RETURNS
2918 * Success: Handle to new property sheet page.
2919 * Failure: NULL.
2921 * NOTES
2922 * An application must use the PSM_ADDPAGE message to add the new page to
2923 * an existing property sheet.
2925 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2926 LPCPROPSHEETPAGEA lpPropSheetPage)
2928 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2930 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2932 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2934 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2936 if (HIWORD( ppsp->u.pszTemplate ))
2938 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2939 char *template = Alloc( len );
2941 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2945 if (ppsp->dwFlags & PSP_USEICONID)
2947 if (HIWORD( ppsp->u2.pszIcon ))
2948 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2951 if (ppsp->dwFlags & PSP_USETITLE)
2953 if (HIWORD( ppsp->pszTitle ))
2954 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2955 else
2956 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2958 else
2959 ppsp->pszTitle = NULL;
2961 if (ppsp->dwFlags & PSP_HIDEHEADER)
2962 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2964 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2966 if (HIWORD( ppsp->pszHeaderTitle ))
2967 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2968 else
2969 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2971 else
2972 ppsp->pszHeaderTitle = NULL;
2974 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2976 if (HIWORD( ppsp->pszHeaderSubTitle ))
2977 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2978 else
2979 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2981 else
2982 ppsp->pszHeaderSubTitle = NULL;
2984 return (HPROPSHEETPAGE)ppsp;
2987 /******************************************************************************
2988 * CreatePropertySheetPageW (COMCTL32.@)
2990 * See CreatePropertySheetA.
2992 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2994 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2996 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2998 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3000 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3002 if (HIWORD( ppsp->u.pszTemplate ))
3004 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3005 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3007 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3011 if ( ppsp->dwFlags & PSP_USEICONID )
3013 if (HIWORD( ppsp->u2.pszIcon ))
3015 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3016 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3018 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3022 if (ppsp->dwFlags & PSP_USETITLE)
3023 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3024 else
3025 ppsp->pszTitle = NULL;
3027 if (ppsp->dwFlags & PSP_HIDEHEADER)
3028 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3030 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3031 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3032 else
3033 ppsp->pszHeaderTitle = NULL;
3035 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3036 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3037 else
3038 ppsp->pszHeaderSubTitle = NULL;
3040 return (HPROPSHEETPAGE)ppsp;
3043 /******************************************************************************
3044 * DestroyPropertySheetPage (COMCTL32.@)
3046 * Destroys a property sheet page previously created with
3047 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3048 * memory.
3050 * RETURNS
3051 * Success: TRUE
3052 * Failure: FALSE
3054 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3056 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3058 if (!psp)
3059 return FALSE;
3061 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3062 Free ((LPVOID)psp->u.pszTemplate);
3064 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3065 Free ((LPVOID)psp->u2.pszIcon);
3067 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3068 Free ((LPVOID)psp->pszTitle);
3070 Free(hPropPage);
3072 return TRUE;
3075 /******************************************************************************
3076 * PROPSHEET_IsDialogMessage
3078 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3080 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3082 TRACE("\n");
3083 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3084 return FALSE;
3086 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3088 int new_page = 0;
3089 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3091 if (!(dlgCode & DLGC_WANTMESSAGE))
3093 switch (lpMsg->wParam)
3095 case VK_TAB:
3096 if (GetKeyState(VK_SHIFT) & 0x8000)
3097 new_page = -1;
3098 else
3099 new_page = 1;
3100 break;
3102 case VK_NEXT: new_page = 1; break;
3103 case VK_PRIOR: new_page = -1; break;
3107 if (new_page)
3109 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3111 new_page += psInfo->active_page;
3113 if (new_page < 0)
3114 new_page = psInfo->nPages - 1;
3115 else if (new_page >= psInfo->nPages)
3116 new_page = 0;
3118 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3121 return TRUE;
3125 return IsDialogMessageW(hwnd, lpMsg);
3128 /******************************************************************************
3129 * PROPSHEET_DoCommand
3131 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3134 switch (wID) {
3136 case IDOK:
3137 case IDC_APPLY_BUTTON:
3139 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3141 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3142 break;
3144 if (wID == IDOK)
3146 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3148 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3149 if (psInfo->result == 0)
3150 psInfo->result = IDOK;
3152 if (psInfo->isModeless)
3153 psInfo->activeValid = FALSE;
3154 else
3155 psInfo->ended = TRUE;
3157 else
3158 EnableWindow(hwndApplyBtn, FALSE);
3160 break;
3163 case IDC_BACK_BUTTON:
3164 PROPSHEET_Back(hwnd);
3165 break;
3167 case IDC_NEXT_BUTTON:
3168 PROPSHEET_Next(hwnd);
3169 break;
3171 case IDC_FINISH_BUTTON:
3172 PROPSHEET_Finish(hwnd);
3173 break;
3175 case IDCANCEL:
3176 PROPSHEET_Cancel(hwnd, 0);
3177 break;
3179 case IDHELP:
3180 PROPSHEET_Help(hwnd);
3181 break;
3183 default:
3184 return FALSE;
3187 return TRUE;
3190 /******************************************************************************
3191 * PROPSHEET_Paint
3193 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3195 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3196 PAINTSTRUCT ps;
3197 HDC hdc, hdcSrc;
3198 BITMAP bm;
3199 HBITMAP hbmp;
3200 HPALETTE hOldPal = 0;
3201 int offsety = 0;
3202 HBRUSH hbr;
3203 RECT r, rzone;
3204 LPCPROPSHEETPAGEW ppshpage;
3205 WCHAR szBuffer[256];
3206 int nLength;
3208 if (psInfo->active_page < 0) return 1;
3209 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3210 if (!hdc) return 1;
3212 hdcSrc = CreateCompatibleDC(0);
3213 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3215 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3216 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3218 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3219 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3220 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3222 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3223 HFONT hOldFont;
3224 COLORREF clrOld = 0;
3225 int oldBkMode = 0;
3227 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3228 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3230 GetClientRect(hwndLineHeader, &r);
3231 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3232 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3234 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3236 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3238 /* Fill the unoccupied part of the header with color of the
3239 * left-top pixel, but do it only when needed.
3241 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3243 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3244 CopyRect(&r, &rzone);
3245 if (bm.bmWidth < r.right)
3247 r.left = bm.bmWidth;
3248 FillRect(hdc, &r, hbr);
3250 if (bm.bmHeight < r.bottom)
3252 r.left = 0;
3253 r.top = bm.bmHeight;
3254 FillRect(hdc, &r, hbr);
3256 DeleteObject(hbr);
3259 /* Draw the header itself. */
3260 BitBlt(hdc, 0, 0,
3261 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3262 hdcSrc, 0, 0, SRCCOPY);
3264 else
3266 int margin;
3267 hbr = GetSysColorBrush(COLOR_WINDOW);
3268 FillRect(hdc, &rzone, hbr);
3270 /* Draw the header bitmap. It's always centered like a
3271 * common 49 x 49 bitmap. */
3272 margin = (rzone.bottom - 49) / 2;
3273 BitBlt(hdc, rzone.right - 49 - margin, margin,
3274 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3275 hdcSrc, 0, 0, SRCCOPY);
3277 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3278 * if its height is smaller than 49 pixels. Because the reason
3279 * for this bug is unknown the current code doesn't try to
3280 * replicate it. */
3283 clrOld = SetTextColor (hdc, 0x00000000);
3284 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3286 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3287 SetRect(&r, 20, 10, 0, 0);
3288 if (HIWORD(ppshpage->pszHeaderTitle))
3289 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3290 else
3292 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3293 szBuffer, 256);
3294 if (nLength != 0)
3296 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3301 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3302 SelectObject(hdc, psInfo->hFont);
3303 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3304 if (HIWORD(ppshpage->pszHeaderTitle))
3305 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3306 else
3308 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3309 szBuffer, 256);
3310 if (nLength != 0)
3312 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3317 offsety = rzone.bottom + 2;
3319 SetTextColor(hdc, clrOld);
3320 SetBkMode(hdc, oldBkMode);
3321 SelectObject(hdc, hOldFont);
3322 SelectObject(hdcSrc, hbmp);
3325 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3326 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3327 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3329 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3331 GetClientRect(hwndLine, &r);
3332 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3334 rzone.left = 0;
3335 rzone.top = 0;
3336 rzone.right = r.right;
3337 rzone.bottom = r.top - 1;
3339 hbr = GetSysColorBrush(COLOR_WINDOW);
3340 FillRect(hdc, &rzone, hbr);
3342 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3343 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3345 /* The watermark is truncated to a width of 164 pixels */
3346 r.right = min(r.right, 164);
3347 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3348 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3350 /* If the bitmap is not big enough, fill the remaining area
3351 with the color of pixel (0,0) of bitmap - see MSDN */
3352 if (r.top > bm.bmHeight) {
3353 r.bottom = r.top - 1;
3354 r.top = bm.bmHeight;
3355 r.left = 0;
3356 r.right = bm.bmWidth;
3357 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3358 FillRect(hdc, &r, hbr);
3359 DeleteObject(hbr);
3362 SelectObject(hdcSrc, hbmp);
3365 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3366 SelectPalette(hdc, hOldPal, FALSE);
3368 DeleteDC(hdcSrc);
3370 if (!hdcParam) EndPaint(hwnd, &ps);
3372 return 0;
3375 /******************************************************************************
3376 * PROPSHEET_DialogProc
3378 static INT_PTR CALLBACK
3379 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3381 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3382 hwnd, uMsg, wParam, lParam);
3384 switch (uMsg)
3386 case WM_INITDIALOG:
3388 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3389 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3390 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3391 int idx;
3392 LOGFONTW logFont;
3394 /* Using PropSheetInfoStr to store extra data doesn't match the native
3395 * common control: native uses TCM_[GS]ETITEM
3397 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3400 * psInfo->hwnd is not being used by WINE code - it exists
3401 * for compatibility with "real" Windoze. The same about
3402 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3403 * property.
3405 psInfo->hwnd = hwnd;
3406 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3408 /* set up the Next and Back buttons by default */
3409 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3411 /* Set up fonts */
3412 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3413 psInfo->hFont = CreateFontIndirectW (&logFont);
3414 logFont.lfWeight = FW_BOLD;
3415 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3418 * Small icon in the title bar.
3420 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3421 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3423 HICON hIcon;
3424 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3425 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3427 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3428 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3429 psInfo->ppshheader.u.pszIcon,
3430 IMAGE_ICON,
3431 icon_cx, icon_cy,
3432 LR_DEFAULTCOLOR);
3433 else
3434 hIcon = psInfo->ppshheader.u.hIcon;
3436 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3439 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3440 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3442 psInfo->strPropertiesFor = strCaption;
3444 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3446 PROPSHEET_CreateTabControl(hwnd, psInfo);
3448 PROPSHEET_LoadWizardBitmaps(psInfo);
3450 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3452 ShowWindow(hwndTabCtrl, SW_HIDE);
3453 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3454 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3456 else
3458 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3460 PROPSHEET_AdjustSize(hwnd, psInfo);
3461 PROPSHEET_AdjustButtons(hwnd, psInfo);
3465 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3466 psInfo->ppshheader.hInstance)
3468 WCHAR szText[256];
3470 if (LoadStringW(psInfo->ppshheader.hInstance,
3471 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3472 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3474 else
3476 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3477 psInfo->ppshheader.pszCaption);
3481 if (psInfo->useCallback)
3482 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3484 idx = psInfo->active_page;
3485 psInfo->active_page = -1;
3487 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3489 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3490 * as some programs call TCM_GETCURSEL to get the current selection
3491 * from which to switch to the next page */
3492 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3494 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3496 return TRUE;
3499 case WM_PRINTCLIENT:
3500 case WM_PAINT:
3501 PROPSHEET_Paint(hwnd, (HDC)wParam);
3502 return TRUE;
3504 case WM_DESTROY:
3505 PROPSHEET_CleanUp(hwnd);
3506 return TRUE;
3508 case WM_CLOSE:
3509 PROPSHEET_Cancel(hwnd, 1);
3510 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3512 case WM_COMMAND:
3513 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3515 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3517 if (!psInfo)
3518 return FALSE;
3520 /* No default handler, forward notification to active page */
3521 if (psInfo->activeValid && psInfo->active_page != -1)
3523 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3524 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3527 return TRUE;
3529 case WM_NOTIFY:
3531 NMHDR* pnmh = (LPNMHDR) lParam;
3533 if (pnmh->code == TCN_SELCHANGE)
3535 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3536 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3539 if(pnmh->code == TCN_SELCHANGING)
3541 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3542 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3543 return TRUE;
3546 return FALSE;
3549 case WM_SYSCOLORCHANGE:
3550 COMCTL32_RefreshSysColors();
3551 return FALSE;
3553 case PSM_GETCURRENTPAGEHWND:
3555 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3556 HWND hwndPage = 0;
3558 if (!psInfo)
3559 return FALSE;
3561 if (psInfo->activeValid && psInfo->active_page != -1)
3562 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3564 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3566 return TRUE;
3569 case PSM_CHANGED:
3570 PROPSHEET_Changed(hwnd, (HWND)wParam);
3571 return TRUE;
3573 case PSM_UNCHANGED:
3574 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3575 return TRUE;
3577 case PSM_GETTABCONTROL:
3579 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3581 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3583 return TRUE;
3586 case PSM_SETCURSEL:
3588 BOOL msgResult;
3590 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3591 if(msgResult != FALSE)
3593 msgResult = PROPSHEET_SetCurSel(hwnd,
3594 (int)wParam,
3596 (HPROPSHEETPAGE)lParam);
3599 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3601 return TRUE;
3604 case PSM_CANCELTOCLOSE:
3606 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3607 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3608 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3610 EnableWindow(hwndCancel, FALSE);
3611 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3612 SetWindowTextW(hwndOK, buf);
3614 return FALSE;
3617 case PSM_RESTARTWINDOWS:
3619 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3621 if (!psInfo)
3622 return FALSE;
3624 /* reboot system takes precedence over restart windows */
3625 if (psInfo->result != ID_PSREBOOTSYSTEM)
3626 psInfo->result = ID_PSRESTARTWINDOWS;
3628 return TRUE;
3631 case PSM_REBOOTSYSTEM:
3633 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3635 if (!psInfo)
3636 return FALSE;
3638 psInfo->result = ID_PSREBOOTSYSTEM;
3640 return TRUE;
3643 case PSM_SETTITLEA:
3644 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3645 return TRUE;
3647 case PSM_SETTITLEW:
3648 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3649 return TRUE;
3651 case PSM_APPLY:
3653 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3655 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3657 return TRUE;
3660 case PSM_QUERYSIBLINGS:
3662 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3664 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3666 return TRUE;
3669 case PSM_ADDPAGE:
3672 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3673 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3674 * on success or FALSE otherwise, as specified on MSDN Online.
3675 * Also see the MFC code for
3676 * CPropertySheet::AddPage(CPropertyPage* pPage).
3679 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3681 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3683 return TRUE;
3686 case PSM_REMOVEPAGE:
3687 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3688 return TRUE;
3690 case PSM_ISDIALOGMESSAGE:
3692 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3693 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3694 return TRUE;
3697 case PSM_PRESSBUTTON:
3698 PROPSHEET_PressButton(hwnd, (int)wParam);
3699 return TRUE;
3701 case PSM_SETFINISHTEXTA:
3702 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3703 return TRUE;
3705 case PSM_SETWIZBUTTONS:
3706 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3707 return TRUE;
3709 case PSM_SETCURSELID:
3710 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3711 return TRUE;
3713 case PSM_SETFINISHTEXTW:
3714 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3715 return FALSE;
3717 case PSM_INSERTPAGE:
3719 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3720 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3721 return TRUE;
3724 case PSM_SETHEADERTITLEW:
3725 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3726 return TRUE;
3728 case PSM_SETHEADERTITLEA:
3729 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3730 return TRUE;
3732 case PSM_SETHEADERSUBTITLEW:
3733 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3734 return TRUE;
3736 case PSM_SETHEADERSUBTITLEA:
3737 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3738 return TRUE;
3740 case PSM_HWNDTOINDEX:
3742 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3743 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3744 return TRUE;
3747 case PSM_INDEXTOHWND:
3749 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3750 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3751 return TRUE;
3754 case PSM_PAGETOINDEX:
3756 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3757 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3758 return TRUE;
3761 case PSM_INDEXTOPAGE:
3763 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3764 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3765 return TRUE;
3768 case PSM_IDTOINDEX:
3770 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3771 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3772 return TRUE;
3775 case PSM_INDEXTOID:
3777 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3778 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3779 return TRUE;
3782 case PSM_GETRESULT:
3784 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3785 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3786 return TRUE;
3789 case PSM_RECALCPAGESIZES:
3791 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3792 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3793 return TRUE;
3796 default:
3797 return FALSE;