dpwsockx: Implementation of SPInit
[wine/gsoc_dplay.git] / dlls / comctl32 / propsheet.c
blobe76744488895de8258209774e83ff1380c801d6a
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 temp, psInfo->ppshheader.hwndParent,
677 PROPSHEET_DialogProc, (LPARAM)psInfo);
678 if ( !ret ) ret = -1;
680 else
682 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
683 temp, psInfo->ppshheader.hwndParent,
684 PROPSHEET_DialogProc, (LPARAM)psInfo);
685 if ( !ret ) ret = -1;
688 Free(temp);
690 return ret;
693 /******************************************************************************
694 * PROPSHEET_SizeMismatch
696 * Verify that the tab control and the "largest" property sheet page dlg. template
697 * match in size.
699 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
701 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
702 RECT rcOrigTab, rcPage;
705 * Original tab size.
707 GetClientRect(hwndTabCtrl, &rcOrigTab);
708 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
711 * Biggest page size.
713 rcPage.left = 0;
714 rcPage.top = 0;
715 rcPage.right = psInfo->width;
716 rcPage.bottom = psInfo->height;
718 MapDialogRect(hwndDlg, &rcPage);
719 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
721 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
722 return TRUE;
723 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
724 return TRUE;
726 return FALSE;
729 /******************************************************************************
730 * PROPSHEET_AdjustSize
732 * Resizes the property sheet and the tab control to fit the largest page.
734 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
736 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
737 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
738 RECT rc,tabRect;
739 int buttonHeight;
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
741 RECT units;
742 LONG style;
744 /* Get the height of buttons */
745 GetClientRect(hwndButton, &rc);
746 buttonHeight = rc.bottom;
749 * Biggest page size.
751 rc.left = 0;
752 rc.top = 0;
753 rc.right = psInfo->width;
754 rc.bottom = psInfo->height;
756 MapDialogRect(hwndDlg, &rc);
758 /* retrieve the dialog units */
759 units.left = units.right = 4;
760 units.top = units.bottom = 8;
761 MapDialogRect(hwndDlg, &units);
764 * Resize the tab control.
766 GetClientRect(hwndTabCtrl,&tabRect);
768 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
770 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
772 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
773 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
776 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
778 rc.right = rc.left + tabRect.right - tabRect.left;
779 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
782 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
784 rc.right -= rc.left;
785 rc.bottom -= rc.top;
786 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
787 hwndTabCtrl, rc.right, rc.bottom);
788 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
789 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
791 GetClientRect(hwndTabCtrl, &rc);
793 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
795 rc.right += (padding.x * 2);
796 rc.bottom += buttonHeight + (3 * padding.y);
798 style = GetWindowLongW(hwndDlg, GWL_STYLE);
799 if (!(style & WS_CHILD))
800 AdjustWindowRect(&rc, style, FALSE);
802 rc.right -= rc.left;
803 rc.bottom -= rc.top;
806 * Resize the property sheet.
808 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
809 hwndDlg, rc.right, rc.bottom);
810 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
811 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
812 return TRUE;
815 /******************************************************************************
816 * PROPSHEET_AdjustSizeWizard
818 * Resizes the property sheet to fit the largest page.
820 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
822 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
823 RECT rc, lineRect, dialogRect;
825 /* Biggest page size */
826 rc.left = 0;
827 rc.top = 0;
828 rc.right = psInfo->width;
829 rc.bottom = psInfo->height;
830 MapDialogRect(hwndDlg, &rc);
832 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
834 /* Add space for the buttons row */
835 GetWindowRect(hwndLine, &lineRect);
836 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
837 GetClientRect(hwndDlg, &dialogRect);
838 rc.bottom += dialogRect.bottom - lineRect.top - 1;
840 /* Convert the client coordinates to window coordinates */
841 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
843 /* Resize the property sheet */
844 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
845 hwndDlg, rc.right, rc.bottom);
846 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
847 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
849 return TRUE;
852 /******************************************************************************
853 * PROPSHEET_AdjustButtons
855 * Adjusts the buttons' positions.
857 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
859 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
860 RECT rcSheet;
861 int x, y;
862 int num_buttons = 2;
863 int buttonWidth, buttonHeight;
864 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
866 if (psInfo->hasApply)
867 num_buttons++;
869 if (psInfo->hasHelp)
870 num_buttons++;
873 * Obtain the size of the buttons.
875 GetClientRect(hwndButton, &rcSheet);
876 buttonWidth = rcSheet.right;
877 buttonHeight = rcSheet.bottom;
880 * Get the size of the property sheet.
882 GetClientRect(hwndParent, &rcSheet);
885 * All buttons will be at this y coordinate.
887 y = rcSheet.bottom - (padding.y + buttonHeight);
890 * Position OK button and make it default.
892 hwndButton = GetDlgItem(hwndParent, IDOK);
894 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
896 SetWindowPos(hwndButton, 0, x, y, 0, 0,
897 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
899 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
903 * Position Cancel button.
905 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
907 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
909 SetWindowPos(hwndButton, 0, x, y, 0, 0,
910 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
913 * Position Apply button.
915 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
917 if (psInfo->hasApply)
919 if (psInfo->hasHelp)
920 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
921 else
922 x = rcSheet.right - (padding.x + buttonWidth);
924 SetWindowPos(hwndButton, 0, x, y, 0, 0,
925 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
927 EnableWindow(hwndButton, FALSE);
929 else
930 ShowWindow(hwndButton, SW_HIDE);
933 * Position Help button.
935 hwndButton = GetDlgItem(hwndParent, IDHELP);
937 if (psInfo->hasHelp)
939 x = rcSheet.right - (padding.x + buttonWidth);
941 SetWindowPos(hwndButton, 0, x, y, 0, 0,
942 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
944 else
945 ShowWindow(hwndButton, SW_HIDE);
947 return TRUE;
950 /******************************************************************************
951 * PROPSHEET_AdjustButtonsWizard
953 * Adjusts the buttons' positions.
955 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
956 const PropSheetInfo* psInfo)
958 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
959 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
960 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
961 RECT rcSheet;
962 int x, y;
963 int num_buttons = 3;
964 int buttonWidth, buttonHeight, lineHeight, lineWidth;
965 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
967 if (psInfo->hasHelp)
968 num_buttons++;
969 if (psInfo->hasFinish)
970 num_buttons++;
973 * Obtain the size of the buttons.
975 GetClientRect(hwndButton, &rcSheet);
976 buttonWidth = rcSheet.right;
977 buttonHeight = rcSheet.bottom;
979 GetClientRect(hwndLine, &rcSheet);
980 lineHeight = rcSheet.bottom;
983 * Get the size of the property sheet.
985 GetClientRect(hwndParent, &rcSheet);
988 * All buttons will be at this y coordinate.
990 y = rcSheet.bottom - (padding.y + buttonHeight);
993 * Position the Back button.
995 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
997 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
999 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1000 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1003 * Position the Next button.
1005 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1007 x += buttonWidth;
1009 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1010 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1013 * Position the Finish button.
1015 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1017 if (psInfo->hasFinish)
1018 x += padding.x + buttonWidth;
1020 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1021 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1023 if (!psInfo->hasFinish)
1024 ShowWindow(hwndButton, SW_HIDE);
1027 * Position the Cancel button.
1029 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1031 x += padding.x + buttonWidth;
1033 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1034 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1037 * Position Help button.
1039 hwndButton = GetDlgItem(hwndParent, IDHELP);
1041 if (psInfo->hasHelp)
1043 x += padding.x + buttonWidth;
1045 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1046 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1048 else
1049 ShowWindow(hwndButton, SW_HIDE);
1051 if (psInfo->ppshheader.dwFlags &
1052 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1053 padding.x = 0;
1056 * Position and resize the sunken line.
1058 x = padding.x;
1059 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1061 lineWidth = rcSheet.right - (padding.x * 2);
1062 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1063 SWP_NOZORDER | SWP_NOACTIVATE);
1066 * Position and resize the header sunken line.
1069 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1070 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1071 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1072 ShowWindow(hwndLineHeader, SW_HIDE);
1074 return TRUE;
1077 /******************************************************************************
1078 * PROPSHEET_GetPaddingInfo
1080 * Returns the layout information.
1082 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1084 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1085 RECT rcTab;
1086 POINT tl;
1087 PADDING_INFO padding;
1089 GetWindowRect(hwndTab, &rcTab);
1091 tl.x = rcTab.left;
1092 tl.y = rcTab.top;
1094 ScreenToClient(hwndDlg, &tl);
1096 padding.x = tl.x;
1097 padding.y = tl.y;
1099 return padding;
1102 /******************************************************************************
1103 * PROPSHEET_GetPaddingInfoWizard
1105 * Returns the layout information.
1106 * Vertical spacing is the distance between the line and the buttons.
1107 * Do NOT use the Help button to gather padding information when it isn't mapped
1108 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1109 * for it in this case !
1110 * FIXME: I'm not sure about any other coordinate problems with these evil
1111 * buttons. Fix it in case additional problems appear or maybe calculate
1112 * a padding in a completely different way, as this is somewhat messy.
1114 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1115 psInfo)
1117 PADDING_INFO padding;
1118 RECT rc;
1119 HWND hwndControl;
1120 INT idButton;
1121 POINT ptButton, ptLine;
1123 TRACE("\n");
1124 if (psInfo->hasHelp)
1126 idButton = IDHELP;
1128 else
1130 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1132 idButton = IDC_NEXT_BUTTON;
1134 else
1136 /* hopefully this is ok */
1137 idButton = IDCANCEL;
1141 hwndControl = GetDlgItem(hwndDlg, idButton);
1142 GetWindowRect(hwndControl, &rc);
1144 ptButton.x = rc.left;
1145 ptButton.y = rc.top;
1147 ScreenToClient(hwndDlg, &ptButton);
1149 /* Line */
1150 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1151 GetWindowRect(hwndControl, &rc);
1153 ptLine.x = rc.left;
1154 ptLine.y = rc.bottom;
1156 ScreenToClient(hwndDlg, &ptLine);
1158 padding.y = ptButton.y - ptLine.y;
1160 if (padding.y < 0)
1161 ERR("padding negative ! Please report this !\n");
1163 /* this is most probably not correct, but the best we have now */
1164 padding.x = padding.y;
1165 return padding;
1168 /******************************************************************************
1169 * PROPSHEET_CreateTabControl
1171 * Insert the tabs in the tab control.
1173 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1174 const PropSheetInfo * psInfo)
1176 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1177 TCITEMW item;
1178 int i, nTabs;
1179 int iImage = 0;
1181 TRACE("\n");
1182 item.mask = TCIF_TEXT;
1183 item.cchTextMax = MAX_TABTEXT_LENGTH;
1185 nTabs = psInfo->nPages;
1188 * Set the image list for icons.
1190 if (psInfo->hImageList)
1192 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1195 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1196 for (i = 0; i < nTabs; i++)
1198 if ( psInfo->proppage[i].hasIcon )
1200 item.mask |= TCIF_IMAGE;
1201 item.iImage = iImage++;
1203 else
1205 item.mask &= ~TCIF_IMAGE;
1208 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1209 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1211 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1213 return TRUE;
1216 /******************************************************************************
1217 * PROPSHEET_WizardSubclassProc
1219 * Subclassing window procedure for wizard exterior pages to prevent drawing
1220 * background and so drawing above the watermark.
1222 static LRESULT CALLBACK
1223 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1225 switch (uMsg)
1227 case WM_ERASEBKGND:
1228 return TRUE;
1230 case WM_CTLCOLORSTATIC:
1231 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1232 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1235 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1239 * Get the size of an in-memory Template
1241 *( Based on the code of PROPSHEET_CollectPageInfo)
1242 * See also dialog.c/DIALOG_ParseTemplate32().
1245 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1248 const WORD* p = (const WORD *)pTemplate;
1249 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1250 WORD nrofitems;
1251 UINT ret;
1253 if (istemplateex)
1255 /* DLGTEMPLATEEX (not defined in any std. header file) */
1257 TRACE("is DLGTEMPLATEEX\n");
1258 p++; /* dlgVer */
1259 p++; /* signature */
1260 p += 2; /* help ID */
1261 p += 2; /* ext style */
1262 p += 2; /* style */
1264 else
1266 /* DLGTEMPLATE */
1268 TRACE("is DLGTEMPLATE\n");
1269 p += 2; /* style */
1270 p += 2; /* ext style */
1273 nrofitems = (WORD)*p; p++; /* nb items */
1274 p++; /* x */
1275 p++; /* y */
1276 p++; /* width */
1277 p++; /* height */
1279 /* menu */
1280 switch ((WORD)*p)
1282 case 0x0000:
1283 p++;
1284 break;
1285 case 0xffff:
1286 p += 2;
1287 break;
1288 default:
1289 TRACE("menu %s\n",debugstr_w( p ));
1290 p += lstrlenW( p ) + 1;
1291 break;
1294 /* class */
1295 switch ((WORD)*p)
1297 case 0x0000:
1298 p++;
1299 break;
1300 case 0xffff:
1301 p += 2; /* 0xffff plus predefined window class ordinal value */
1302 break;
1303 default:
1304 TRACE("class %s\n",debugstr_w( p ));
1305 p += lstrlenW( p ) + 1;
1306 break;
1309 /* title */
1310 TRACE("title %s\n",debugstr_w( p ));
1311 p += lstrlenW( p ) + 1;
1313 /* font, if DS_SETFONT set */
1314 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1315 pTemplate->style)))
1317 p+=(istemplateex)?3:1;
1318 TRACE("font %s\n",debugstr_w( p ));
1319 p += lstrlenW( p ) + 1; /* the font name */
1322 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1323 * that are following the DLGTEMPLATE(EX) data */
1324 TRACE("%d items\n",nrofitems);
1325 while (nrofitems > 0)
1327 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1329 /* skip header */
1330 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1332 /* check class */
1333 switch ((WORD)*p)
1335 case 0x0000:
1336 p++;
1337 break;
1338 case 0xffff:
1339 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1340 p += 2;
1341 break;
1342 default:
1343 TRACE("class %s\n",debugstr_w( p ));
1344 p += lstrlenW( p ) + 1;
1345 break;
1348 /* check title text */
1349 switch ((WORD)*p)
1351 case 0x0000:
1352 p++;
1353 break;
1354 case 0xffff:
1355 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1356 p += 2;
1357 break;
1358 default:
1359 TRACE("text %s\n",debugstr_w( p ));
1360 p += lstrlenW( p ) + 1;
1361 break;
1363 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1364 --nrofitems;
1367 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1368 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1369 return ret;
1372 /******************************************************************************
1373 * PROPSHEET_CreatePage
1375 * Creates a page.
1377 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1378 int index,
1379 const PropSheetInfo * psInfo,
1380 LPCPROPSHEETPAGEW ppshpage)
1382 DLGTEMPLATE* pTemplate;
1383 HWND hwndPage;
1384 DWORD resSize;
1385 LPVOID temp = NULL;
1387 TRACE("index %d\n", index);
1389 if (ppshpage == NULL)
1391 return FALSE;
1394 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1396 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1397 resSize = GetTemplateSize(pTemplate);
1399 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1401 HRSRC hResource;
1402 HANDLE hTemplate;
1404 hResource = FindResourceW(ppshpage->hInstance,
1405 ppshpage->u.pszTemplate,
1406 (LPWSTR)RT_DIALOG);
1407 if(!hResource)
1408 return FALSE;
1410 resSize = SizeofResource(ppshpage->hInstance, hResource);
1412 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1413 if(!hTemplate)
1414 return FALSE;
1416 pTemplate = LockResource(hTemplate);
1418 * Make a copy of the dialog template to make it writable
1421 else
1423 HRSRC hResource;
1424 HANDLE hTemplate;
1426 hResource = FindResourceA(ppshpage->hInstance,
1427 (LPCSTR)ppshpage->u.pszTemplate,
1428 (LPSTR)RT_DIALOG);
1429 if(!hResource)
1430 return FALSE;
1432 resSize = SizeofResource(ppshpage->hInstance, hResource);
1434 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1435 if(!hTemplate)
1436 return FALSE;
1438 pTemplate = LockResource(hTemplate);
1440 * Make a copy of the dialog template to make it writable
1443 temp = Alloc(resSize);
1444 if (!temp)
1445 return FALSE;
1447 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1448 memcpy(temp, pTemplate, resSize);
1449 pTemplate = temp;
1451 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1453 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1454 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1457 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1459 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1460 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1462 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1464 else
1466 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1467 pTemplate->style &= ~DS_MODALFRAME;
1468 pTemplate->style &= ~WS_CAPTION;
1469 pTemplate->style &= ~WS_SYSMENU;
1470 pTemplate->style &= ~WS_POPUP;
1471 pTemplate->style &= ~WS_DISABLED;
1472 pTemplate->style &= ~WS_VISIBLE;
1473 pTemplate->style &= ~WS_THICKFRAME;
1475 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1478 if (psInfo->proppage[index].useCallback)
1479 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1480 (LPPROPSHEETPAGEW)ppshpage);
1482 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1483 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1484 pTemplate,
1485 hwndParent,
1486 ppshpage->pfnDlgProc,
1487 (LPARAM)ppshpage);
1488 else
1489 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1490 pTemplate,
1491 hwndParent,
1492 ppshpage->pfnDlgProc,
1493 (LPARAM)ppshpage);
1494 /* Free a no more needed copy */
1495 Free(temp);
1497 psInfo->proppage[index].hwndPage = hwndPage;
1499 /* Subclass exterior wizard pages */
1500 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1501 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1502 (ppshpage->dwFlags & PSP_HIDEHEADER))
1504 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1505 (DWORD_PTR)ppshpage);
1507 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1508 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1510 return TRUE;
1513 /******************************************************************************
1514 * PROPSHEET_LoadWizardBitmaps
1516 * Loads the watermark and header bitmaps for a wizard.
1518 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1520 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1522 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1523 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1524 considers hbmWatermark as valid. */
1525 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1526 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1528 psInfo->ppshheader.u4.hbmWatermark =
1529 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1532 /* Same behavior as for watermarks */
1533 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1534 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1536 psInfo->ppshheader.u5.hbmHeader =
1537 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1543 /******************************************************************************
1544 * PROPSHEET_ShowPage
1546 * Displays or creates the specified page.
1548 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1550 HWND hwndTabCtrl;
1551 HWND hwndLineHeader;
1552 HWND control;
1553 LPCPROPSHEETPAGEW ppshpage;
1555 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1556 if (index == psInfo->active_page)
1558 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1559 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1560 return TRUE;
1563 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1564 if (psInfo->proppage[index].hwndPage == 0)
1566 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1569 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1571 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1572 psInfo->proppage[index].pszText);
1574 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1575 if(control != NULL)
1576 SetFocus(control);
1579 if (psInfo->active_page != -1)
1580 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1582 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1584 /* Synchronize current selection with tab control
1585 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1586 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1587 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1589 psInfo->active_page = index;
1590 psInfo->activeValid = TRUE;
1592 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1594 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1595 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1597 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1598 ShowWindow(hwndLineHeader, SW_HIDE);
1599 else
1600 ShowWindow(hwndLineHeader, SW_SHOW);
1603 return TRUE;
1606 /******************************************************************************
1607 * PROPSHEET_Back
1609 static BOOL PROPSHEET_Back(HWND hwndDlg)
1611 PSHNOTIFY psn;
1612 HWND hwndPage;
1613 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1614 LRESULT result;
1615 int idx;
1617 TRACE("active_page %d\n", psInfo->active_page);
1618 if (psInfo->active_page < 0)
1619 return FALSE;
1621 psn.hdr.code = PSN_WIZBACK;
1622 psn.hdr.hwndFrom = hwndDlg;
1623 psn.hdr.idFrom = 0;
1624 psn.lParam = 0;
1626 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1628 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1629 if (result == -1)
1630 return FALSE;
1631 else if (result == 0)
1632 idx = psInfo->active_page - 1;
1633 else
1634 idx = PROPSHEET_FindPageByResId(psInfo, result);
1636 if (idx >= 0 && idx < psInfo->nPages)
1638 if (PROPSHEET_CanSetCurSel(hwndDlg))
1640 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1641 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1642 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1645 return TRUE;
1648 /******************************************************************************
1649 * PROPSHEET_Next
1651 static BOOL PROPSHEET_Next(HWND hwndDlg)
1653 PSHNOTIFY psn;
1654 HWND hwndPage;
1655 LRESULT msgResult = 0;
1656 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1657 int idx;
1659 TRACE("active_page %d\n", psInfo->active_page);
1660 if (psInfo->active_page < 0)
1661 return FALSE;
1663 psn.hdr.code = PSN_WIZNEXT;
1664 psn.hdr.hwndFrom = hwndDlg;
1665 psn.hdr.idFrom = 0;
1666 psn.lParam = 0;
1668 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1670 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1671 if (msgResult == -1)
1672 return FALSE;
1673 else if (msgResult == 0)
1674 idx = psInfo->active_page + 1;
1675 else
1676 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1678 if (idx < psInfo->nPages )
1680 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1682 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1683 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1684 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1688 return TRUE;
1691 /******************************************************************************
1692 * PROPSHEET_Finish
1694 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1696 PSHNOTIFY psn;
1697 HWND hwndPage;
1698 LRESULT msgResult = 0;
1699 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1701 TRACE("active_page %d\n", psInfo->active_page);
1702 if (psInfo->active_page < 0)
1703 return FALSE;
1705 psn.hdr.code = PSN_WIZFINISH;
1706 psn.hdr.hwndFrom = hwndDlg;
1707 psn.hdr.idFrom = 0;
1708 psn.lParam = 0;
1710 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1712 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1714 TRACE("msg result %ld\n", msgResult);
1716 if (msgResult != 0)
1717 return FALSE;
1719 if (psInfo->result == 0)
1720 psInfo->result = IDOK;
1721 if (psInfo->isModeless)
1722 psInfo->activeValid = FALSE;
1723 else
1724 psInfo->ended = TRUE;
1726 return TRUE;
1729 /******************************************************************************
1730 * PROPSHEET_Apply
1732 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1734 int i;
1735 HWND hwndPage;
1736 PSHNOTIFY psn;
1737 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1739 TRACE("active_page %d\n", psInfo->active_page);
1740 if (psInfo->active_page < 0)
1741 return FALSE;
1743 psn.hdr.hwndFrom = hwndDlg;
1744 psn.hdr.idFrom = 0;
1745 psn.lParam = 0;
1749 * Send PSN_KILLACTIVE to the current page.
1751 psn.hdr.code = PSN_KILLACTIVE;
1753 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1755 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1756 return FALSE;
1759 * Send PSN_APPLY to all pages.
1761 psn.hdr.code = PSN_APPLY;
1762 psn.lParam = lParam;
1764 for (i = 0; i < psInfo->nPages; i++)
1766 hwndPage = psInfo->proppage[i].hwndPage;
1767 if (hwndPage)
1769 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1771 case PSNRET_INVALID:
1772 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1773 /* fall through */
1774 case PSNRET_INVALID_NOCHANGEPAGE:
1775 return FALSE;
1780 if(lParam)
1782 psInfo->activeValid = FALSE;
1784 else if(psInfo->active_page >= 0)
1786 psn.hdr.code = PSN_SETACTIVE;
1787 psn.lParam = 0;
1788 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1789 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1792 return TRUE;
1795 /******************************************************************************
1796 * PROPSHEET_Cancel
1798 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1800 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1801 HWND hwndPage;
1802 PSHNOTIFY psn;
1803 int i;
1805 TRACE("active_page %d\n", psInfo->active_page);
1806 if (psInfo->active_page < 0)
1807 return;
1809 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1810 psn.hdr.code = PSN_QUERYCANCEL;
1811 psn.hdr.hwndFrom = hwndDlg;
1812 psn.hdr.idFrom = 0;
1813 psn.lParam = 0;
1815 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1816 return;
1818 psn.hdr.code = PSN_RESET;
1819 psn.lParam = lParam;
1821 for (i = 0; i < psInfo->nPages; i++)
1823 hwndPage = psInfo->proppage[i].hwndPage;
1825 if (hwndPage)
1826 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1829 if (psInfo->isModeless)
1831 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1832 psInfo->activeValid = FALSE;
1834 else
1835 psInfo->ended = TRUE;
1838 /******************************************************************************
1839 * PROPSHEET_Help
1841 static void PROPSHEET_Help(HWND hwndDlg)
1843 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1844 HWND hwndPage;
1845 PSHNOTIFY psn;
1847 TRACE("active_page %d\n", psInfo->active_page);
1848 if (psInfo->active_page < 0)
1849 return;
1851 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1852 psn.hdr.code = PSN_HELP;
1853 psn.hdr.hwndFrom = hwndDlg;
1854 psn.hdr.idFrom = 0;
1855 psn.lParam = 0;
1857 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1860 /******************************************************************************
1861 * PROPSHEET_Changed
1863 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1865 int i;
1866 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1868 TRACE("\n");
1869 if (!psInfo) return;
1871 * Set the dirty flag of this page.
1873 for (i = 0; i < psInfo->nPages; i++)
1875 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1876 psInfo->proppage[i].isDirty = TRUE;
1880 * Enable the Apply button.
1882 if (psInfo->hasApply)
1884 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1886 EnableWindow(hwndApplyBtn, TRUE);
1890 /******************************************************************************
1891 * PROPSHEET_UnChanged
1893 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1895 int i;
1896 BOOL noPageDirty = TRUE;
1897 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1898 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1900 TRACE("\n");
1901 if ( !psInfo ) return;
1902 for (i = 0; i < psInfo->nPages; i++)
1904 /* set the specified page as clean */
1905 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1906 psInfo->proppage[i].isDirty = FALSE;
1908 /* look to see if there's any dirty pages */
1909 if (psInfo->proppage[i].isDirty)
1910 noPageDirty = FALSE;
1914 * Disable Apply button.
1916 if (noPageDirty)
1917 EnableWindow(hwndApplyBtn, FALSE);
1920 /******************************************************************************
1921 * PROPSHEET_PressButton
1923 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1925 TRACE("buttonID %d\n", buttonID);
1926 switch (buttonID)
1928 case PSBTN_APPLYNOW:
1929 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1930 break;
1931 case PSBTN_BACK:
1932 PROPSHEET_Back(hwndDlg);
1933 break;
1934 case PSBTN_CANCEL:
1935 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1936 break;
1937 case PSBTN_FINISH:
1938 PROPSHEET_Finish(hwndDlg);
1939 break;
1940 case PSBTN_HELP:
1941 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1942 break;
1943 case PSBTN_NEXT:
1944 PROPSHEET_Next(hwndDlg);
1945 break;
1946 case PSBTN_OK:
1947 PROPSHEET_DoCommand(hwndDlg, IDOK);
1948 break;
1949 default:
1950 FIXME("Invalid button index %d\n", buttonID);
1955 /*************************************************************************
1956 * BOOL PROPSHEET_CanSetCurSel [Internal]
1958 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1960 * PARAMS
1961 * hwndDlg [I] handle to a Dialog hWnd
1963 * RETURNS
1964 * TRUE if Current Selection can change
1966 * NOTES
1968 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1970 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1971 HWND hwndPage;
1972 PSHNOTIFY psn;
1973 BOOL res = FALSE;
1975 TRACE("active_page %d\n", psInfo->active_page);
1976 if (!psInfo)
1978 res = FALSE;
1979 goto end;
1982 if (psInfo->active_page < 0)
1984 res = TRUE;
1985 goto end;
1989 * Notify the current page.
1991 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1992 psn.hdr.code = PSN_KILLACTIVE;
1993 psn.hdr.hwndFrom = hwndDlg;
1994 psn.hdr.idFrom = 0;
1995 psn.lParam = 0;
1997 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1999 end:
2000 TRACE("<-- %d\n", res);
2001 return res;
2004 /******************************************************************************
2005 * PROPSHEET_SetCurSel
2007 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2008 int index,
2009 int skipdir,
2010 HPROPSHEETPAGE hpage
2013 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2014 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2015 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2017 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2018 /* hpage takes precedence over index */
2019 if (hpage != NULL)
2020 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2022 if (index < 0 || index >= psInfo->nPages)
2024 TRACE("Could not find page to select!\n");
2025 return FALSE;
2028 /* unset active page while doing this transition. */
2029 if (psInfo->active_page != -1)
2030 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2031 psInfo->active_page = -1;
2033 while (1) {
2034 int result;
2035 PSHNOTIFY psn;
2036 RECT rc;
2037 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2039 if (hwndTabControl)
2040 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2042 psn.hdr.code = PSN_SETACTIVE;
2043 psn.hdr.hwndFrom = hwndDlg;
2044 psn.hdr.idFrom = 0;
2045 psn.lParam = 0;
2047 if (!psInfo->proppage[index].hwndPage) {
2048 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2051 /* Resize the property sheet page to the fit in the Tab control
2052 * (for regular property sheets) or to fit in the client area (for
2053 * wizards).
2054 * NOTE: The resizing happens every time the page is selected and
2055 * not only when it's created (some applications depend on it). */
2056 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2057 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2058 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2059 rc.right - rc.left, rc.bottom - rc.top);
2060 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2061 rc.left, rc.top,
2062 rc.right - rc.left, rc.bottom - rc.top, 0);
2064 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2065 if (!result)
2066 break;
2067 if (result == -1) {
2068 index+=skipdir;
2069 if (index < 0) {
2070 index = 0;
2071 WARN("Tried to skip before first property sheet page!\n");
2072 break;
2074 if (index >= psInfo->nPages) {
2075 WARN("Tried to skip after last property sheet page!\n");
2076 index = psInfo->nPages-1;
2077 break;
2080 else if (result != 0)
2082 int old_index = index;
2083 index = PROPSHEET_FindPageByResId(psInfo, result);
2084 if(index >= psInfo->nPages) {
2085 index = old_index;
2086 WARN("Tried to skip to nonexistent page by res id\n");
2087 break;
2089 continue;
2093 /* Invalidate the header area */
2094 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2095 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2097 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2098 RECT r;
2100 GetClientRect(hwndLineHeader, &r);
2101 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2102 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2104 InvalidateRect(hwndDlg, &r, TRUE);
2108 * Display the new page.
2110 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2112 if (psInfo->proppage[index].hasHelp)
2113 EnableWindow(hwndHelp, TRUE);
2114 else
2115 EnableWindow(hwndHelp, FALSE);
2117 return TRUE;
2120 /******************************************************************************
2121 * PROPSHEET_SetCurSelId
2123 * Selects the page, specified by resource id.
2125 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2127 int idx;
2128 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2130 idx = PROPSHEET_FindPageByResId(psInfo, id);
2131 if (idx < psInfo->nPages )
2133 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2134 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2138 /******************************************************************************
2139 * PROPSHEET_SetTitleA
2141 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2143 if(HIWORD(lpszText))
2145 WCHAR szTitle[256];
2146 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2147 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2148 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2150 else
2152 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2156 /******************************************************************************
2157 * PROPSHEET_SetTitleW
2159 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2161 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2162 WCHAR szTitle[256];
2164 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2165 if (HIWORD(lpszText) == 0) {
2166 if (!LoadStringW(psInfo->ppshheader.hInstance,
2167 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2168 return;
2169 lpszText = szTitle;
2171 if (dwStyle & PSH_PROPTITLE)
2173 WCHAR* dest;
2174 int lentitle = strlenW(lpszText);
2175 int lenprop = strlenW(psInfo->strPropertiesFor);
2177 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2178 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2180 SetWindowTextW(hwndDlg, dest);
2181 Free(dest);
2183 else
2184 SetWindowTextW(hwndDlg, lpszText);
2187 /******************************************************************************
2188 * PROPSHEET_SetFinishTextA
2190 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2192 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2193 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2195 TRACE("'%s'\n", lpszText);
2196 /* Set text, show and enable the Finish button */
2197 SetWindowTextA(hwndButton, lpszText);
2198 ShowWindow(hwndButton, SW_SHOW);
2199 EnableWindow(hwndButton, TRUE);
2201 /* Make it default pushbutton */
2202 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2204 /* Hide Back button */
2205 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2206 ShowWindow(hwndButton, SW_HIDE);
2208 if (!psInfo->hasFinish)
2210 /* Hide Next button */
2211 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2212 ShowWindow(hwndButton, SW_HIDE);
2216 /******************************************************************************
2217 * PROPSHEET_SetFinishTextW
2219 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2221 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2222 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2224 TRACE("%s\n", debugstr_w(lpszText));
2225 /* Set text, show and enable the Finish button */
2226 SetWindowTextW(hwndButton, lpszText);
2227 ShowWindow(hwndButton, SW_SHOW);
2228 EnableWindow(hwndButton, TRUE);
2230 /* Make it default pushbutton */
2231 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2233 /* Hide Back button */
2234 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2235 ShowWindow(hwndButton, SW_HIDE);
2237 if (!psInfo->hasFinish)
2239 /* Hide Next button */
2240 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2241 ShowWindow(hwndButton, SW_HIDE);
2245 /******************************************************************************
2246 * PROPSHEET_QuerySiblings
2248 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2249 WPARAM wParam, LPARAM lParam)
2251 int i = 0;
2252 HWND hwndPage;
2253 LRESULT msgResult = 0;
2254 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2256 while ((i < psInfo->nPages) && (msgResult == 0))
2258 hwndPage = psInfo->proppage[i].hwndPage;
2259 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2260 i++;
2263 return msgResult;
2267 /******************************************************************************
2268 * PROPSHEET_AddPage
2270 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2271 HPROPSHEETPAGE hpage)
2273 PropPageInfo * ppi;
2274 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2275 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2276 TCITEMW item;
2277 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2279 TRACE("hpage %p\n", hpage);
2281 * Allocate and fill in a new PropPageInfo entry.
2283 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2284 if (!ppi)
2285 return FALSE;
2287 psInfo->proppage = ppi;
2288 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2289 return FALSE;
2291 psInfo->proppage[psInfo->nPages].hpage = hpage;
2293 if (ppsp->dwFlags & PSP_PREMATURE)
2295 /* Create the page but don't show it */
2296 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2300 * Add a new tab to the tab control.
2302 item.mask = TCIF_TEXT;
2303 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2304 item.cchTextMax = MAX_TABTEXT_LENGTH;
2306 if (psInfo->hImageList)
2308 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2311 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2313 item.mask |= TCIF_IMAGE;
2314 item.iImage = psInfo->nPages;
2317 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2318 (LPARAM)&item);
2320 psInfo->nPages++;
2322 /* If it is the only page - show it */
2323 if(psInfo->nPages == 1)
2324 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2325 return TRUE;
2328 /******************************************************************************
2329 * PROPSHEET_RemovePage
2331 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2332 int index,
2333 HPROPSHEETPAGE hpage)
2335 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2336 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2337 PropPageInfo* oldPages;
2339 TRACE("index %d, hpage %p\n", index, hpage);
2340 if (!psInfo) {
2341 return FALSE;
2344 * hpage takes precedence over index.
2346 if (hpage != 0)
2348 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2351 /* Make sure that index is within range */
2352 if (index < 0 || index >= psInfo->nPages)
2354 TRACE("Could not find page to remove!\n");
2355 return FALSE;
2358 TRACE("total pages %d removing page %d active page %d\n",
2359 psInfo->nPages, index, psInfo->active_page);
2361 * Check if we're removing the active page.
2363 if (index == psInfo->active_page)
2365 if (psInfo->nPages > 1)
2367 if (index > 0)
2369 /* activate previous page */
2370 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2372 else
2374 /* activate the next page */
2375 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2376 psInfo->active_page = index;
2379 else
2381 psInfo->active_page = -1;
2382 if (!psInfo->isModeless)
2384 psInfo->ended = TRUE;
2385 return TRUE;
2389 else if (index < psInfo->active_page)
2390 psInfo->active_page--;
2392 /* Unsubclass the page dialog window */
2393 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2394 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2395 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2397 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2398 PROPSHEET_WizardSubclassProc, 1);
2401 /* Destroy page dialog window */
2402 DestroyWindow(psInfo->proppage[index].hwndPage);
2404 /* Free page resources */
2405 if(psInfo->proppage[index].hpage)
2407 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2409 if (psp->dwFlags & PSP_USETITLE)
2410 Free ((LPVOID)psInfo->proppage[index].pszText);
2412 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2415 /* Remove the tab */
2416 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2418 oldPages = psInfo->proppage;
2419 psInfo->nPages--;
2420 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2422 if (index > 0)
2423 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2425 if (index < psInfo->nPages)
2426 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2427 (psInfo->nPages - index) * sizeof(PropPageInfo));
2429 Free(oldPages);
2431 return FALSE;
2434 /******************************************************************************
2435 * PROPSHEET_SetWizButtons
2437 * This code will work if (and assumes that) the Next button is on top of the
2438 * Finish button. ie. Finish comes after Next in the Z order.
2439 * This means make sure the dialog template reflects this.
2442 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2444 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2445 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2446 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2447 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2449 TRACE("%d\n", dwFlags);
2451 EnableWindow(hwndBack, FALSE);
2452 EnableWindow(hwndNext, FALSE);
2453 EnableWindow(hwndFinish, FALSE);
2455 /* set the default pushbutton to an enabled button */
2456 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2457 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2458 else if (dwFlags & PSWIZB_NEXT)
2459 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2460 else if (dwFlags & PSWIZB_BACK)
2461 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2462 else
2463 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2466 if (dwFlags & PSWIZB_BACK)
2467 EnableWindow(hwndBack, TRUE);
2469 if (dwFlags & PSWIZB_NEXT)
2470 EnableWindow(hwndNext, TRUE);
2472 if (!psInfo->hasFinish)
2474 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2476 /* Hide the Next button */
2477 ShowWindow(hwndNext, SW_HIDE);
2479 /* Show the Finish button */
2480 ShowWindow(hwndFinish, SW_SHOW);
2482 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2483 EnableWindow(hwndFinish, TRUE);
2485 else
2487 /* Hide the Finish button */
2488 ShowWindow(hwndFinish, SW_HIDE);
2489 /* Show the Next button */
2490 ShowWindow(hwndNext, SW_SHOW);
2493 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2494 EnableWindow(hwndFinish, TRUE);
2497 /******************************************************************************
2498 * PROPSHEET_InsertPage
2500 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2502 if (!HIWORD(hpageInsertAfter))
2503 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2504 else
2505 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2506 return FALSE;
2509 /******************************************************************************
2510 * PROPSHEET_SetHeaderTitleW
2512 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2514 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2517 /******************************************************************************
2518 * PROPSHEET_SetHeaderTitleA
2520 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2522 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2525 /******************************************************************************
2526 * PROPSHEET_SetHeaderSubTitleW
2528 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2530 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2533 /******************************************************************************
2534 * PROPSHEET_SetHeaderSubTitleA
2536 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2538 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2541 /******************************************************************************
2542 * PROPSHEET_HwndToIndex
2544 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2546 int index;
2547 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2549 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2551 for (index = 0; index < psInfo->nPages; index++)
2552 if (psInfo->proppage[index].hwndPage == hPageDlg)
2553 return index;
2554 WARN("%p not found\n", hPageDlg);
2555 return -1;
2558 /******************************************************************************
2559 * PROPSHEET_IndexToHwnd
2561 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2563 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2564 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2565 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2566 WARN("%d out of range.\n", iPageIndex);
2567 return 0;
2569 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2572 /******************************************************************************
2573 * PROPSHEET_PageToIndex
2575 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2577 int index;
2578 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2580 TRACE("(%p, %p)\n", hwndDlg, hPage);
2582 for (index = 0; index < psInfo->nPages; index++)
2583 if (psInfo->proppage[index].hpage == hPage)
2584 return index;
2585 WARN("%p not found\n", hPage);
2586 return -1;
2589 /******************************************************************************
2590 * PROPSHEET_IndexToPage
2592 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2594 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2595 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2596 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2597 WARN("%d out of range.\n", iPageIndex);
2598 return 0;
2600 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2603 /******************************************************************************
2604 * PROPSHEET_IdToIndex
2606 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2608 int index;
2609 LPCPROPSHEETPAGEW psp;
2610 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2611 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2612 for (index = 0; index < psInfo->nPages; index++) {
2613 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2614 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2615 return index;
2618 return -1;
2621 /******************************************************************************
2622 * PROPSHEET_IndexToId
2624 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2626 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2627 LPCPROPSHEETPAGEW psp;
2628 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2629 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2630 WARN("%d out of range.\n", iPageIndex);
2631 return 0;
2633 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2634 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2635 return 0;
2637 return (LRESULT)psp->u.pszTemplate;
2640 /******************************************************************************
2641 * PROPSHEET_GetResult
2643 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2645 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2646 return psInfo->result;
2649 /******************************************************************************
2650 * PROPSHEET_RecalcPageSizes
2652 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2654 FIXME("(%p): stub\n", hwndDlg);
2655 return FALSE;
2658 /******************************************************************************
2659 * PROPSHEET_GetPageIndex
2661 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2662 * the array of PropPageInfo.
2664 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2666 BOOL found = FALSE;
2667 int index = 0;
2669 TRACE("hpage %p\n", hpage);
2670 while ((index < psInfo->nPages) && (found == FALSE))
2672 if (psInfo->proppage[index].hpage == hpage)
2673 found = TRUE;
2674 else
2675 index++;
2678 if (found == FALSE)
2679 index = -1;
2681 return index;
2684 /******************************************************************************
2685 * PROPSHEET_CleanUp
2687 static void PROPSHEET_CleanUp(HWND hwndDlg)
2689 int i;
2690 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2692 TRACE("\n");
2693 if (!psInfo) return;
2694 if (HIWORD(psInfo->ppshheader.pszCaption))
2695 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2697 for (i = 0; i < psInfo->nPages; i++)
2699 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2701 /* Unsubclass the page dialog window */
2702 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2703 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2704 (psp->dwFlags & PSP_HIDEHEADER))
2706 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2707 PROPSHEET_WizardSubclassProc, 1);
2710 if(psInfo->proppage[i].hwndPage)
2711 DestroyWindow(psInfo->proppage[i].hwndPage);
2713 if(psp)
2715 if (psp->dwFlags & PSP_USETITLE)
2716 Free ((LPVOID)psInfo->proppage[i].pszText);
2718 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2722 DeleteObject(psInfo->hFont);
2723 DeleteObject(psInfo->hFontBold);
2724 /* If we created the bitmaps, destroy them */
2725 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2726 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2727 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2728 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2729 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2730 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2732 Free(psInfo->proppage);
2733 Free(psInfo->strPropertiesFor);
2734 ImageList_Destroy(psInfo->hImageList);
2736 GlobalFree(psInfo);
2739 static INT do_loop(const PropSheetInfo *psInfo)
2741 MSG msg;
2742 INT ret = -1;
2743 HWND hwnd = psInfo->hwnd;
2745 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2747 if(ret == -1)
2748 break;
2750 if(!IsDialogMessageW(hwnd, &msg))
2752 TranslateMessage(&msg);
2753 DispatchMessageW(&msg);
2757 if(ret == 0)
2759 PostQuitMessage(msg.wParam);
2760 ret = -1;
2763 if(ret != -1)
2764 ret = psInfo->result;
2766 DestroyWindow(hwnd);
2767 return ret;
2770 /******************************************************************************
2771 * PROPSHEET_PropertySheet
2773 * Common code between PropertySheetA/W
2775 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2777 INT_PTR bRet = 0;
2778 HWND parent = NULL;
2779 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2780 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2782 psInfo->unicode = unicode;
2783 psInfo->ended = FALSE;
2785 if(!psInfo->isModeless)
2787 parent = psInfo->ppshheader.hwndParent;
2788 if (parent) EnableWindow(parent, FALSE);
2790 bRet = PROPSHEET_CreateDialog(psInfo);
2791 if(!psInfo->isModeless)
2793 bRet = do_loop(psInfo);
2794 if (parent) EnableWindow(parent, TRUE);
2796 return bRet;
2799 /******************************************************************************
2800 * PropertySheet (COMCTL32.@)
2801 * PropertySheetA (COMCTL32.@)
2803 * Creates a property sheet in the specified property sheet header.
2805 * RETURNS
2806 * Modal property sheets: Positive if successful or -1 otherwise.
2807 * Modeless property sheets: Property sheet handle.
2808 * Or:
2809 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2810 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2812 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2814 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2815 UINT i, n;
2816 const BYTE* pByte;
2818 TRACE("(%p)\n", lppsh);
2820 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2822 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2823 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2825 for (n = i = 0; i < lppsh->nPages; i++, n++)
2827 if (!psInfo->usePropPage)
2828 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2829 else
2831 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2832 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2835 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2836 psInfo, n, TRUE))
2838 if (psInfo->usePropPage)
2839 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2840 n--;
2841 psInfo->nPages--;
2845 return PROPSHEET_PropertySheet(psInfo, FALSE);
2848 /******************************************************************************
2849 * PropertySheetW (COMCTL32.@)
2851 * See PropertySheetA.
2853 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2855 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2856 UINT i, n;
2857 const BYTE* pByte;
2859 TRACE("(%p)\n", lppsh);
2861 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2863 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2864 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2866 for (n = i = 0; i < lppsh->nPages; i++, n++)
2868 if (!psInfo->usePropPage)
2869 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2870 else
2872 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2873 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2876 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2877 psInfo, n, TRUE))
2879 if (psInfo->usePropPage)
2880 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2881 n--;
2882 psInfo->nPages--;
2886 return PROPSHEET_PropertySheet(psInfo, TRUE);
2889 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2891 LPWSTR ret;
2893 if (IS_INTRESOURCE(str))
2895 HRSRC hrsrc;
2896 HGLOBAL hmem;
2897 WCHAR *ptr;
2898 WORD i, id = LOWORD(str);
2899 UINT len;
2901 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2902 return NULL;
2903 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2904 if (!(ptr = LockResource( hmem ))) return NULL;
2905 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2906 len = *ptr;
2907 if (!len) return NULL;
2908 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2909 if (ret)
2911 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2912 ret[len] = 0;
2915 else
2917 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2918 ret = Alloc( len );
2919 if (ret) memcpy( ret, str, len );
2921 return ret;
2925 /******************************************************************************
2926 * CreatePropertySheetPage (COMCTL32.@)
2927 * CreatePropertySheetPageA (COMCTL32.@)
2929 * Creates a new property sheet page.
2931 * RETURNS
2932 * Success: Handle to new property sheet page.
2933 * Failure: NULL.
2935 * NOTES
2936 * An application must use the PSM_ADDPAGE message to add the new page to
2937 * an existing property sheet.
2939 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2940 LPCPROPSHEETPAGEA lpPropSheetPage)
2942 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2944 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2946 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2948 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2950 if (HIWORD( ppsp->u.pszTemplate ))
2952 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2953 char *template = Alloc( len );
2955 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2959 if (ppsp->dwFlags & PSP_USEICONID)
2961 if (HIWORD( ppsp->u2.pszIcon ))
2962 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2965 if (ppsp->dwFlags & PSP_USETITLE)
2967 if (HIWORD( ppsp->pszTitle ))
2968 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2969 else
2970 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2972 else
2973 ppsp->pszTitle = NULL;
2975 if (ppsp->dwFlags & PSP_HIDEHEADER)
2976 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2978 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2980 if (HIWORD( ppsp->pszHeaderTitle ))
2981 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2982 else
2983 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2985 else
2986 ppsp->pszHeaderTitle = NULL;
2988 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2990 if (HIWORD( ppsp->pszHeaderSubTitle ))
2991 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2992 else
2993 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2995 else
2996 ppsp->pszHeaderSubTitle = NULL;
2998 return (HPROPSHEETPAGE)ppsp;
3001 /******************************************************************************
3002 * CreatePropertySheetPageW (COMCTL32.@)
3004 * See CreatePropertySheetA.
3006 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3008 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3010 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3012 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3014 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3016 if (HIWORD( ppsp->u.pszTemplate ))
3018 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3019 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3021 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3025 if ( ppsp->dwFlags & PSP_USEICONID )
3027 if (HIWORD( ppsp->u2.pszIcon ))
3029 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3030 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3032 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3036 if (ppsp->dwFlags & PSP_USETITLE)
3037 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3038 else
3039 ppsp->pszTitle = NULL;
3041 if (ppsp->dwFlags & PSP_HIDEHEADER)
3042 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3044 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3045 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3046 else
3047 ppsp->pszHeaderTitle = NULL;
3049 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3050 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3051 else
3052 ppsp->pszHeaderSubTitle = NULL;
3054 return (HPROPSHEETPAGE)ppsp;
3057 /******************************************************************************
3058 * DestroyPropertySheetPage (COMCTL32.@)
3060 * Destroys a property sheet page previously created with
3061 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3062 * memory.
3064 * RETURNS
3065 * Success: TRUE
3066 * Failure: FALSE
3068 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3070 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3072 if (!psp)
3073 return FALSE;
3075 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3076 Free ((LPVOID)psp->u.pszTemplate);
3078 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3079 Free ((LPVOID)psp->u2.pszIcon);
3081 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3082 Free ((LPVOID)psp->pszTitle);
3084 Free(hPropPage);
3086 return TRUE;
3089 /******************************************************************************
3090 * PROPSHEET_IsDialogMessage
3092 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3094 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3096 TRACE("\n");
3097 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3098 return FALSE;
3100 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3102 int new_page = 0;
3103 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3105 if (!(dlgCode & DLGC_WANTMESSAGE))
3107 switch (lpMsg->wParam)
3109 case VK_TAB:
3110 if (GetKeyState(VK_SHIFT) & 0x8000)
3111 new_page = -1;
3112 else
3113 new_page = 1;
3114 break;
3116 case VK_NEXT: new_page = 1; break;
3117 case VK_PRIOR: new_page = -1; break;
3121 if (new_page)
3123 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3125 new_page += psInfo->active_page;
3127 if (new_page < 0)
3128 new_page = psInfo->nPages - 1;
3129 else if (new_page >= psInfo->nPages)
3130 new_page = 0;
3132 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3135 return TRUE;
3139 return IsDialogMessageW(hwnd, lpMsg);
3142 /******************************************************************************
3143 * PROPSHEET_DoCommand
3145 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3148 switch (wID) {
3150 case IDOK:
3151 case IDC_APPLY_BUTTON:
3153 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3155 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3156 break;
3158 if (wID == IDOK)
3160 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3162 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3163 if (psInfo->result == 0)
3164 psInfo->result = IDOK;
3166 if (psInfo->isModeless)
3167 psInfo->activeValid = FALSE;
3168 else
3169 psInfo->ended = TRUE;
3171 else
3172 EnableWindow(hwndApplyBtn, FALSE);
3174 break;
3177 case IDC_BACK_BUTTON:
3178 PROPSHEET_Back(hwnd);
3179 break;
3181 case IDC_NEXT_BUTTON:
3182 PROPSHEET_Next(hwnd);
3183 break;
3185 case IDC_FINISH_BUTTON:
3186 PROPSHEET_Finish(hwnd);
3187 break;
3189 case IDCANCEL:
3190 PROPSHEET_Cancel(hwnd, 0);
3191 break;
3193 case IDHELP:
3194 PROPSHEET_Help(hwnd);
3195 break;
3197 default:
3198 return FALSE;
3201 return TRUE;
3204 /******************************************************************************
3205 * PROPSHEET_Paint
3207 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3209 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3210 PAINTSTRUCT ps;
3211 HDC hdc, hdcSrc;
3212 BITMAP bm;
3213 HBITMAP hbmp;
3214 HPALETTE hOldPal = 0;
3215 int offsety = 0;
3216 HBRUSH hbr;
3217 RECT r, rzone;
3218 LPCPROPSHEETPAGEW ppshpage;
3219 WCHAR szBuffer[256];
3220 int nLength;
3222 if (psInfo->active_page < 0) return 1;
3223 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3224 if (!hdc) return 1;
3226 hdcSrc = CreateCompatibleDC(0);
3227 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3229 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3230 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3232 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3233 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3234 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3236 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3237 HFONT hOldFont;
3238 COLORREF clrOld = 0;
3239 int oldBkMode = 0;
3241 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3242 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3244 GetClientRect(hwndLineHeader, &r);
3245 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3246 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3248 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3250 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3252 /* Fill the unoccupied part of the header with color of the
3253 * left-top pixel, but do it only when needed.
3255 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3257 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3258 CopyRect(&r, &rzone);
3259 if (bm.bmWidth < r.right)
3261 r.left = bm.bmWidth;
3262 FillRect(hdc, &r, hbr);
3264 if (bm.bmHeight < r.bottom)
3266 r.left = 0;
3267 r.top = bm.bmHeight;
3268 FillRect(hdc, &r, hbr);
3270 DeleteObject(hbr);
3273 /* Draw the header itself. */
3274 BitBlt(hdc, 0, 0,
3275 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3276 hdcSrc, 0, 0, SRCCOPY);
3278 else
3280 int margin;
3281 hbr = GetSysColorBrush(COLOR_WINDOW);
3282 FillRect(hdc, &rzone, hbr);
3284 /* Draw the header bitmap. It's always centered like a
3285 * common 49 x 49 bitmap. */
3286 margin = (rzone.bottom - 49) / 2;
3287 BitBlt(hdc, rzone.right - 49 - margin, margin,
3288 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3289 hdcSrc, 0, 0, SRCCOPY);
3291 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3292 * if its height is smaller than 49 pixels. Because the reason
3293 * for this bug is unknown the current code doesn't try to
3294 * replicate it. */
3297 clrOld = SetTextColor (hdc, 0x00000000);
3298 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3300 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3301 SetRect(&r, 20, 10, 0, 0);
3302 if (HIWORD(ppshpage->pszHeaderTitle))
3303 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3304 else
3306 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3307 szBuffer, 256);
3308 if (nLength != 0)
3310 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3315 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3316 SelectObject(hdc, psInfo->hFont);
3317 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3318 if (HIWORD(ppshpage->pszHeaderTitle))
3319 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3320 else
3322 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3323 szBuffer, 256);
3324 if (nLength != 0)
3326 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3331 offsety = rzone.bottom + 2;
3333 SetTextColor(hdc, clrOld);
3334 SetBkMode(hdc, oldBkMode);
3335 SelectObject(hdc, hOldFont);
3336 SelectObject(hdcSrc, hbmp);
3339 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3340 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3341 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3343 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3345 GetClientRect(hwndLine, &r);
3346 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3348 rzone.left = 0;
3349 rzone.top = 0;
3350 rzone.right = r.right;
3351 rzone.bottom = r.top - 1;
3353 hbr = GetSysColorBrush(COLOR_WINDOW);
3354 FillRect(hdc, &rzone, hbr);
3356 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3357 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3359 /* The watermark is truncated to a width of 164 pixels */
3360 r.right = min(r.right, 164);
3361 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3362 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3364 /* If the bitmap is not big enough, fill the remaining area
3365 with the color of pixel (0,0) of bitmap - see MSDN */
3366 if (r.top > bm.bmHeight) {
3367 r.bottom = r.top - 1;
3368 r.top = bm.bmHeight;
3369 r.left = 0;
3370 r.right = bm.bmWidth;
3371 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3372 FillRect(hdc, &r, hbr);
3373 DeleteObject(hbr);
3376 SelectObject(hdcSrc, hbmp);
3379 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3380 SelectPalette(hdc, hOldPal, FALSE);
3382 DeleteDC(hdcSrc);
3384 if (!hdcParam) EndPaint(hwnd, &ps);
3386 return 0;
3389 /******************************************************************************
3390 * PROPSHEET_DialogProc
3392 static INT_PTR CALLBACK
3393 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3395 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3396 hwnd, uMsg, wParam, lParam);
3398 switch (uMsg)
3400 case WM_INITDIALOG:
3402 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3403 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3404 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3405 int idx;
3406 LOGFONTW logFont;
3408 /* Using PropSheetInfoStr to store extra data doesn't match the native
3409 * common control: native uses TCM_[GS]ETITEM
3411 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3414 * psInfo->hwnd is not being used by WINE code - it exists
3415 * for compatibility with "real" Windoze. The same about
3416 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3417 * property.
3419 psInfo->hwnd = hwnd;
3420 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3422 /* set up the Next and Back buttons by default */
3423 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3424 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3426 /* Set up fonts */
3427 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3428 psInfo->hFont = CreateFontIndirectW (&logFont);
3429 logFont.lfWeight = FW_BOLD;
3430 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3433 * Small icon in the title bar.
3435 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3436 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3438 HICON hIcon;
3439 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3440 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3442 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3443 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3444 psInfo->ppshheader.u.pszIcon,
3445 IMAGE_ICON,
3446 icon_cx, icon_cy,
3447 LR_DEFAULTCOLOR);
3448 else
3449 hIcon = psInfo->ppshheader.u.hIcon;
3451 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3454 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3455 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3457 psInfo->strPropertiesFor = strCaption;
3459 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3461 PROPSHEET_CreateTabControl(hwnd, psInfo);
3463 PROPSHEET_LoadWizardBitmaps(psInfo);
3465 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3467 ShowWindow(hwndTabCtrl, SW_HIDE);
3468 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3469 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3471 else
3473 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3475 PROPSHEET_AdjustSize(hwnd, psInfo);
3476 PROPSHEET_AdjustButtons(hwnd, psInfo);
3480 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3481 psInfo->ppshheader.hInstance)
3483 WCHAR szText[256];
3485 if (LoadStringW(psInfo->ppshheader.hInstance,
3486 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3487 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3489 else
3491 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3492 psInfo->ppshheader.pszCaption);
3496 if (psInfo->useCallback)
3497 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3499 idx = psInfo->active_page;
3500 psInfo->active_page = -1;
3502 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3504 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3505 * as some programs call TCM_GETCURSEL to get the current selection
3506 * from which to switch to the next page */
3507 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3509 PROPSHEET_UnChanged(hwnd, NULL);
3511 /* wizards set their focus during init */
3512 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3513 return FALSE;
3515 return TRUE;
3518 case WM_PRINTCLIENT:
3519 case WM_PAINT:
3520 PROPSHEET_Paint(hwnd, (HDC)wParam);
3521 return TRUE;
3523 case WM_DESTROY:
3524 PROPSHEET_CleanUp(hwnd);
3525 return TRUE;
3527 case WM_CLOSE:
3528 PROPSHEET_Cancel(hwnd, 1);
3529 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3531 case WM_COMMAND:
3532 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3534 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3536 if (!psInfo)
3537 return FALSE;
3539 /* No default handler, forward notification to active page */
3540 if (psInfo->activeValid && psInfo->active_page != -1)
3542 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3543 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3546 return TRUE;
3548 case WM_NOTIFY:
3550 NMHDR* pnmh = (LPNMHDR) lParam;
3552 if (pnmh->code == TCN_SELCHANGE)
3554 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3555 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3558 if(pnmh->code == TCN_SELCHANGING)
3560 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3561 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3562 return TRUE;
3565 return FALSE;
3568 case WM_SYSCOLORCHANGE:
3569 COMCTL32_RefreshSysColors();
3570 return FALSE;
3572 case PSM_GETCURRENTPAGEHWND:
3574 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3575 HWND hwndPage = 0;
3577 if (!psInfo)
3578 return FALSE;
3580 if (psInfo->activeValid && psInfo->active_page != -1)
3581 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3583 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3585 return TRUE;
3588 case PSM_CHANGED:
3589 PROPSHEET_Changed(hwnd, (HWND)wParam);
3590 return TRUE;
3592 case PSM_UNCHANGED:
3593 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3594 return TRUE;
3596 case PSM_GETTABCONTROL:
3598 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3600 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3602 return TRUE;
3605 case PSM_SETCURSEL:
3607 BOOL msgResult;
3609 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3610 if(msgResult != FALSE)
3612 msgResult = PROPSHEET_SetCurSel(hwnd,
3613 (int)wParam,
3615 (HPROPSHEETPAGE)lParam);
3618 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3620 return TRUE;
3623 case PSM_CANCELTOCLOSE:
3625 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3626 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3627 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3629 EnableWindow(hwndCancel, FALSE);
3630 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3631 SetWindowTextW(hwndOK, buf);
3633 return FALSE;
3636 case PSM_RESTARTWINDOWS:
3638 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3640 if (!psInfo)
3641 return FALSE;
3643 /* reboot system takes precedence over restart windows */
3644 if (psInfo->result != ID_PSREBOOTSYSTEM)
3645 psInfo->result = ID_PSRESTARTWINDOWS;
3647 return TRUE;
3650 case PSM_REBOOTSYSTEM:
3652 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3654 if (!psInfo)
3655 return FALSE;
3657 psInfo->result = ID_PSREBOOTSYSTEM;
3659 return TRUE;
3662 case PSM_SETTITLEA:
3663 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3664 return TRUE;
3666 case PSM_SETTITLEW:
3667 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3668 return TRUE;
3670 case PSM_APPLY:
3672 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3674 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3676 return TRUE;
3679 case PSM_QUERYSIBLINGS:
3681 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3683 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3685 return TRUE;
3688 case PSM_ADDPAGE:
3691 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3692 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3693 * on success or FALSE otherwise, as specified on MSDN Online.
3694 * Also see the MFC code for
3695 * CPropertySheet::AddPage(CPropertyPage* pPage).
3698 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3700 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3702 return TRUE;
3705 case PSM_REMOVEPAGE:
3706 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3707 return TRUE;
3709 case PSM_ISDIALOGMESSAGE:
3711 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3712 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3713 return TRUE;
3716 case PSM_PRESSBUTTON:
3717 PROPSHEET_PressButton(hwnd, (int)wParam);
3718 return TRUE;
3720 case PSM_SETFINISHTEXTA:
3721 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3722 return TRUE;
3724 case PSM_SETWIZBUTTONS:
3725 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3726 return TRUE;
3728 case PSM_SETCURSELID:
3729 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3730 return TRUE;
3732 case PSM_SETFINISHTEXTW:
3733 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3734 return FALSE;
3736 case PSM_INSERTPAGE:
3738 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3739 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3740 return TRUE;
3743 case PSM_SETHEADERTITLEW:
3744 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3745 return TRUE;
3747 case PSM_SETHEADERTITLEA:
3748 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3749 return TRUE;
3751 case PSM_SETHEADERSUBTITLEW:
3752 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3753 return TRUE;
3755 case PSM_SETHEADERSUBTITLEA:
3756 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3757 return TRUE;
3759 case PSM_HWNDTOINDEX:
3761 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3762 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3763 return TRUE;
3766 case PSM_INDEXTOHWND:
3768 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3769 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3770 return TRUE;
3773 case PSM_PAGETOINDEX:
3775 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3776 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3777 return TRUE;
3780 case PSM_INDEXTOPAGE:
3782 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3783 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3784 return TRUE;
3787 case PSM_IDTOINDEX:
3789 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3790 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3791 return TRUE;
3794 case PSM_INDEXTOID:
3796 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3801 case PSM_GETRESULT:
3803 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3804 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3805 return TRUE;
3808 case PSM_RECALCPAGESIZES:
3810 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3811 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3812 return TRUE;
3815 default:
3816 return FALSE;