Release 1.9.16.
[wine.git] / dlls / comctl32 / propsheet.c
blob860084414b95752656b37a95342e692079b50129
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
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, int original_index);
172 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
173 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
176 static INT_PTR CALLBACK
177 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
179 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
181 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
182 /******************************************************************************
183 * PROPSHEET_UnImplementedFlags
185 * Document use of flags we don't implement yet.
187 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
189 CHAR string[256];
191 string[0] = '\0';
194 * unhandled header flags:
195 * PSH_RTLREADING 0x00000800
196 * PSH_STRETCHWATERMARK 0x00040000
197 * PSH_USEPAGELANG 0x00200000
200 add_flag(PSH_RTLREADING);
201 add_flag(PSH_STRETCHWATERMARK);
202 add_flag(PSH_USEPAGELANG);
203 if (string[0] != '\0')
204 FIXME("%s\n", string);
206 #undef add_flag
208 /******************************************************************************
209 * PROPSHEET_GetPageRect
211 * Retrieve rect from tab control and map into the dialog for SetWindowPos
213 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
214 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
216 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
217 HWND hwndChild;
218 RECT r;
220 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
221 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
222 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
223 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
225 rc->left = rc->top = WIZARD_PADDING;
227 else
229 rc->left = rc->top = 0;
231 rc->right = psInfo->width - rc->left;
232 rc->bottom = psInfo->height - rc->top;
233 MapDialogRect(hwndDlg, rc);
235 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
236 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
237 !(ppshpage->dwFlags & PSP_HIDEHEADER))
239 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
240 GetClientRect(hwndChild, &r);
241 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
242 rc->top += r.bottom + 1;
244 } else {
245 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
246 GetClientRect(hwndTabCtrl, rc);
247 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
248 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
252 /******************************************************************************
253 * PROPSHEET_FindPageByResId
255 * Find page index corresponding to page resource id.
257 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
259 INT i;
261 for (i = 0; i < psInfo->nPages; i++)
263 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
265 /* Fixme: if resource ID is a string shall we use strcmp ??? */
266 if (lppsp->u.pszTemplate == (LPVOID)resId)
267 break;
270 return i;
273 /******************************************************************************
274 * PROPSHEET_AtoW
276 * Convert ASCII to Unicode since all data is saved as Unicode.
278 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
280 INT len;
281 WCHAR *to;
283 TRACE("<%s>\n", frstr);
284 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
285 to = Alloc(len * sizeof(WCHAR));
286 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
287 *tostr = to;
290 /******************************************************************************
291 * PROPSHEET_CollectSheetInfoCommon
293 * Common code for PROPSHEET_CollectSheetInfoA/W
295 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
297 PROPSHEET_UnImplementedFlags(dwFlags);
299 psInfo->hasHelp = dwFlags & PSH_HASHELP;
300 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
301 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
302 psInfo->isModeless = dwFlags & PSH_MODELESS;
303 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
304 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
305 psInfo->active_page = 0;
307 psInfo->result = 0;
308 psInfo->hImageList = 0;
309 psInfo->activeValid = FALSE;
312 /******************************************************************************
313 * PROPSHEET_CollectSheetInfoA
315 * Collect relevant data.
317 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
318 PropSheetInfo * psInfo)
320 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
321 DWORD dwFlags = lppsh->dwFlags;
323 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
325 memcpy(&psInfo->ppshheader,lppsh,dwSize);
326 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",
327 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
328 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
330 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
331 psInfo->ppshheader.pszCaption = NULL;
332 else
334 if (!IS_INTRESOURCE(lppsh->pszCaption))
336 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
337 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
339 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
340 psInfo->ppshheader.pszCaption = caption;
343 psInfo->nPages = lppsh->nPages;
345 if (dwFlags & PSH_USEPSTARTPAGE)
347 TRACE("PSH_USEPSTARTPAGE is on\n");
348 psInfo->active_page = 0;
350 else
351 psInfo->active_page = lppsh->u2.nStartPage;
353 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
356 /******************************************************************************
357 * PROPSHEET_CollectSheetInfoW
359 * Collect relevant data.
361 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
362 PropSheetInfo * psInfo)
364 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
365 DWORD dwFlags = lppsh->dwFlags;
367 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
369 memcpy(&psInfo->ppshheader,lppsh,dwSize);
370 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",
371 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
373 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
374 psInfo->ppshheader.pszCaption = NULL;
375 else
377 if (!IS_INTRESOURCE(lppsh->pszCaption))
379 int len = strlenW(lppsh->pszCaption);
380 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
382 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
385 psInfo->nPages = lppsh->nPages;
387 if (dwFlags & PSH_USEPSTARTPAGE)
389 TRACE("PSH_USEPSTARTPAGE is on\n");
390 psInfo->active_page = 0;
392 else
393 psInfo->active_page = lppsh->u2.nStartPage;
395 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
398 /******************************************************************************
399 * PROPSHEET_CollectPageInfo
401 * Collect property sheet data.
402 * With code taken from DIALOG_ParseTemplate32.
404 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
405 PropSheetInfo * psInfo,
406 int index, BOOL resize)
408 const DLGTEMPLATE* pTemplate;
409 const WORD* p;
410 DWORD dwFlags;
411 int width, height;
413 if (!lppsp)
414 return FALSE;
416 TRACE("\n");
417 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
418 psInfo->proppage[index].hwndPage = 0;
419 psInfo->proppage[index].isDirty = FALSE;
422 * Process property page flags.
424 dwFlags = lppsp->dwFlags;
425 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
426 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
427 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
429 /* as soon as we have a page with the help flag, set the sheet flag on */
430 if (psInfo->proppage[index].hasHelp)
431 psInfo->hasHelp = TRUE;
434 * Process page template.
436 if (dwFlags & PSP_DLGINDIRECT)
437 pTemplate = lppsp->u.pResource;
438 else if(dwFlags & PSP_INTERNAL_UNICODE )
440 HRSRC hResource = FindResourceW(lppsp->hInstance,
441 lppsp->u.pszTemplate,
442 (LPWSTR)RT_DIALOG);
443 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
444 hResource);
445 pTemplate = LockResource(hTemplate);
447 else
449 HRSRC hResource = FindResourceA(lppsp->hInstance,
450 (LPCSTR)lppsp->u.pszTemplate,
451 (LPSTR)RT_DIALOG);
452 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
453 hResource);
454 pTemplate = LockResource(hTemplate);
458 * Extract the size of the page and the caption.
460 if (!pTemplate)
461 return FALSE;
463 p = (const WORD *)pTemplate;
465 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
467 /* DLGTEMPLATEEX (not defined in any std. header file) */
469 p++; /* dlgVer */
470 p++; /* signature */
471 p += 2; /* help ID */
472 p += 2; /* ext style */
473 p += 2; /* style */
475 else
477 /* DLGTEMPLATE */
479 p += 2; /* style */
480 p += 2; /* ext style */
483 p++; /* nb items */
484 p++; /* x */
485 p++; /* y */
486 width = (WORD)*p; p++;
487 height = (WORD)*p; p++;
489 /* Special calculation for interior wizard pages so the largest page is
490 * calculated correctly. We need to add all the padding and space occupied
491 * by the header so the width and height sums up to the whole wizard client
492 * area. */
493 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
494 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
495 !(dwFlags & PSP_HIDEHEADER))
497 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
498 width += 2 * WIZARD_PADDING;
500 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
502 height += 2 * WIZARD_PADDING;
503 width += 2 * WIZARD_PADDING;
506 /* remember the largest width and height */
507 if (resize)
509 if (width > psInfo->width)
510 psInfo->width = width;
512 if (height > psInfo->height)
513 psInfo->height = height;
516 /* menu */
517 switch ((WORD)*p)
519 case 0x0000:
520 p++;
521 break;
522 case 0xffff:
523 p += 2;
524 break;
525 default:
526 p += lstrlenW( p ) + 1;
527 break;
530 /* class */
531 switch ((WORD)*p)
533 case 0x0000:
534 p++;
535 break;
536 case 0xffff:
537 p += 2;
538 break;
539 default:
540 p += lstrlenW( p ) + 1;
541 break;
544 /* Extract the caption */
545 psInfo->proppage[index].pszText = p;
546 TRACE("Tab %d %s\n",index,debugstr_w( p ));
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 (IS_INTRESOURCE( lppsp->pszTitle ))
558 if (LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle, szTitle, sizeof(szTitle)/sizeof(szTitle[0]) ))
559 pTitle = szTitle;
560 else if (*p)
561 pTitle = p;
562 else
563 pTitle = pszNull;
565 else
566 pTitle = lppsp->pszTitle;
568 len = strlenW(pTitle);
569 text = Alloc( (len+1)*sizeof (WCHAR) );
570 psInfo->proppage[index].pszText = strcpyW( text, pTitle);
574 * Build the image list for icons
576 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
578 HICON hIcon;
579 int icon_cx = GetSystemMetrics(SM_CXSMICON);
580 int icon_cy = GetSystemMetrics(SM_CYSMICON);
582 if (dwFlags & PSP_USEICONID)
583 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
584 icon_cx, icon_cy, LR_DEFAULTCOLOR);
585 else
586 hIcon = lppsp->u2.hIcon;
588 if ( hIcon )
590 if (psInfo->hImageList == 0 )
591 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
593 ImageList_AddIcon(psInfo->hImageList, hIcon);
598 return TRUE;
601 /******************************************************************************
602 * PROPSHEET_CreateDialog
604 * Creates the actual property sheet.
606 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
608 LRESULT ret;
609 LPCVOID template;
610 LPVOID temp = 0;
611 HRSRC hRes;
612 DWORD resSize;
613 WORD resID = IDD_PROPSHEET;
615 TRACE("(%p)\n", psInfo);
616 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
617 resID = IDD_WIZARD;
619 if( psInfo->unicode )
621 if(!(hRes = FindResourceW(COMCTL32_hModule,
622 MAKEINTRESOURCEW(resID),
623 (LPWSTR)RT_DIALOG)))
624 return -1;
626 else
628 if(!(hRes = FindResourceA(COMCTL32_hModule,
629 MAKEINTRESOURCEA(resID),
630 (LPSTR)RT_DIALOG)))
631 return -1;
634 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
635 return -1;
638 * Make a copy of the dialog template.
640 resSize = SizeofResource(COMCTL32_hModule, hRes);
642 temp = Alloc(resSize);
644 if (!temp)
645 return -1;
647 memcpy(temp, template, resSize);
649 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
651 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
652 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
653 else
654 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
656 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
657 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
659 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
660 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
661 else
662 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
665 if (psInfo->useCallback)
666 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
668 /* NOTE: MSDN states "Returns a positive value if successful, or -1
669 * otherwise for modal property sheets.", but this is wrong. The
670 * actual return value is either TRUE (success), FALSE (cancel) or
671 * -1 (error). */
672 if( psInfo->unicode )
674 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
675 temp, psInfo->ppshheader.hwndParent,
676 PROPSHEET_DialogProc, (LPARAM)psInfo);
677 if ( !ret ) ret = -1;
679 else
681 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
682 temp, psInfo->ppshheader.hwndParent,
683 PROPSHEET_DialogProc, (LPARAM)psInfo);
684 if ( !ret ) ret = -1;
687 Free(temp);
689 return ret;
692 /******************************************************************************
693 * PROPSHEET_SizeMismatch
695 * Verify that the tab control and the "largest" property sheet page dlg. template
696 * match in size.
698 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
700 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
701 RECT rcOrigTab, rcPage;
704 * Original tab size.
706 GetClientRect(hwndTabCtrl, &rcOrigTab);
707 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
710 * Biggest page size.
712 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
713 MapDialogRect(hwndDlg, &rcPage);
714 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
716 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
717 return TRUE;
718 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
719 return TRUE;
721 return FALSE;
724 /******************************************************************************
725 * PROPSHEET_AdjustSize
727 * Resizes the property sheet and the tab control to fit the largest page.
729 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
731 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
732 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
733 RECT rc,tabRect;
734 int buttonHeight;
735 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
736 RECT units;
737 LONG style;
739 /* Get the height of buttons */
740 GetClientRect(hwndButton, &rc);
741 buttonHeight = rc.bottom;
744 * Biggest page size.
746 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
747 MapDialogRect(hwndDlg, &rc);
749 /* retrieve the dialog units */
750 units.left = units.right = 4;
751 units.top = units.bottom = 8;
752 MapDialogRect(hwndDlg, &units);
755 * Resize the tab control.
757 GetClientRect(hwndTabCtrl,&tabRect);
759 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
761 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
763 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
764 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
767 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
769 rc.right = rc.left + tabRect.right - tabRect.left;
770 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
773 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
775 rc.right -= rc.left;
776 rc.bottom -= rc.top;
777 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
778 hwndTabCtrl, rc.right, rc.bottom);
779 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
780 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
782 GetClientRect(hwndTabCtrl, &rc);
784 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
786 rc.right += (padding.x * 2);
787 rc.bottom += buttonHeight + (3 * padding.y);
789 style = GetWindowLongW(hwndDlg, GWL_STYLE);
790 if (!(style & WS_CHILD))
791 AdjustWindowRect(&rc, style, FALSE);
793 rc.right -= rc.left;
794 rc.bottom -= rc.top;
797 * Resize the property sheet.
799 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
800 hwndDlg, rc.right, rc.bottom);
801 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
802 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
803 return TRUE;
806 /******************************************************************************
807 * PROPSHEET_AdjustSizeWizard
809 * Resizes the property sheet to fit the largest page.
811 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
813 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
814 RECT rc, lineRect, dialogRect;
816 /* Biggest page size */
817 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
818 MapDialogRect(hwndDlg, &rc);
820 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
822 /* Add space for the buttons row */
823 GetWindowRect(hwndLine, &lineRect);
824 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
825 GetClientRect(hwndDlg, &dialogRect);
826 rc.bottom += dialogRect.bottom - lineRect.top - 1;
828 /* Convert the client coordinates to window coordinates */
829 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
831 /* Resize the property sheet */
832 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
833 hwndDlg, rc.right, rc.bottom);
834 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
835 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
837 return TRUE;
840 /******************************************************************************
841 * PROPSHEET_AdjustButtons
843 * Adjusts the buttons' positions.
845 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
847 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
848 RECT rcSheet;
849 int x, y;
850 int num_buttons = 2;
851 int buttonWidth, buttonHeight;
852 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
854 if (psInfo->hasApply)
855 num_buttons++;
857 if (psInfo->hasHelp)
858 num_buttons++;
861 * Obtain the size of the buttons.
863 GetClientRect(hwndButton, &rcSheet);
864 buttonWidth = rcSheet.right;
865 buttonHeight = rcSheet.bottom;
868 * Get the size of the property sheet.
870 GetClientRect(hwndParent, &rcSheet);
873 * All buttons will be at this y coordinate.
875 y = rcSheet.bottom - (padding.y + buttonHeight);
878 * Position OK button and make it default.
880 hwndButton = GetDlgItem(hwndParent, IDOK);
882 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
884 SetWindowPos(hwndButton, 0, x, y, 0, 0,
885 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
887 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
891 * Position Cancel button.
893 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
895 x += padding.x + buttonWidth;
897 SetWindowPos(hwndButton, 0, x, y, 0, 0,
898 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
901 * Position Apply button.
903 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
905 if(psInfo->hasApply)
906 x += padding.x + buttonWidth;
907 else
908 ShowWindow(hwndButton, SW_HIDE);
910 SetWindowPos(hwndButton, 0, x, y, 0, 0,
911 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
912 EnableWindow(hwndButton, FALSE);
915 * Position Help button.
917 hwndButton = GetDlgItem(hwndParent, IDHELP);
919 x += padding.x + buttonWidth;
920 SetWindowPos(hwndButton, 0, x, y, 0, 0,
921 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
923 if(!psInfo->hasHelp)
924 ShowWindow(hwndButton, SW_HIDE);
926 return TRUE;
929 /******************************************************************************
930 * PROPSHEET_AdjustButtonsWizard
932 * Adjusts the buttons' positions.
934 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
935 const PropSheetInfo* psInfo)
937 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
938 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
939 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
940 RECT rcSheet;
941 int x, y;
942 int num_buttons = 3;
943 int buttonWidth, buttonHeight, lineHeight, lineWidth;
944 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
946 if (psInfo->hasHelp)
947 num_buttons++;
948 if (psInfo->hasFinish)
949 num_buttons++;
952 * Obtain the size of the buttons.
954 GetClientRect(hwndButton, &rcSheet);
955 buttonWidth = rcSheet.right;
956 buttonHeight = rcSheet.bottom;
958 GetClientRect(hwndLine, &rcSheet);
959 lineHeight = rcSheet.bottom;
962 * Get the size of the property sheet.
964 GetClientRect(hwndParent, &rcSheet);
967 * All buttons will be at this y coordinate.
969 y = rcSheet.bottom - (padding.y + buttonHeight);
972 * Position the Back button.
974 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
976 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
978 SetWindowPos(hwndButton, 0, x, y, 0, 0,
979 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
982 * Position the Next button.
984 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
986 x += buttonWidth;
988 SetWindowPos(hwndButton, 0, x, y, 0, 0,
989 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
992 * Position the Finish button.
994 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
996 if (psInfo->hasFinish)
997 x += padding.x + buttonWidth;
999 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1000 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1002 if (!psInfo->hasFinish)
1003 ShowWindow(hwndButton, SW_HIDE);
1006 * Position the Cancel button.
1008 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1010 x += padding.x + buttonWidth;
1012 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1013 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1016 * Position Help button.
1018 hwndButton = GetDlgItem(hwndParent, IDHELP);
1020 if (psInfo->hasHelp)
1022 x += padding.x + buttonWidth;
1024 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1025 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1027 else
1028 ShowWindow(hwndButton, SW_HIDE);
1030 if (psInfo->ppshheader.dwFlags &
1031 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1032 padding.x = 0;
1035 * Position and resize the sunken line.
1037 x = padding.x;
1038 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1040 lineWidth = rcSheet.right - (padding.x * 2);
1041 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1042 SWP_NOZORDER | SWP_NOACTIVATE);
1045 * Position and resize the header sunken line.
1048 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1049 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1050 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1051 ShowWindow(hwndLineHeader, SW_HIDE);
1053 return TRUE;
1056 /******************************************************************************
1057 * PROPSHEET_GetPaddingInfo
1059 * Returns the layout information.
1061 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1063 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1064 RECT rcTab;
1065 PADDING_INFO padding;
1067 GetWindowRect(hwndTab, &rcTab);
1068 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1070 padding.x = rcTab.left;
1071 padding.y = rcTab.top;
1073 return padding;
1076 /******************************************************************************
1077 * PROPSHEET_GetPaddingInfoWizard
1079 * Returns the layout information.
1080 * Vertical spacing is the distance between the line and the buttons.
1081 * Do NOT use the Help button to gather padding information when it isn't mapped
1082 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1083 * for it in this case !
1084 * FIXME: I'm not sure about any other coordinate problems with these evil
1085 * buttons. Fix it in case additional problems appear or maybe calculate
1086 * a padding in a completely different way, as this is somewhat messy.
1088 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1089 psInfo)
1091 PADDING_INFO padding;
1092 RECT rc;
1093 HWND hwndControl;
1094 INT idButton;
1095 POINT ptButton, ptLine;
1097 TRACE("\n");
1098 if (psInfo->hasHelp)
1100 idButton = IDHELP;
1102 else
1104 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1106 idButton = IDC_NEXT_BUTTON;
1108 else
1110 /* hopefully this is ok */
1111 idButton = IDCANCEL;
1115 hwndControl = GetDlgItem(hwndDlg, idButton);
1116 GetWindowRect(hwndControl, &rc);
1117 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1118 ptButton.x = rc.left;
1119 ptButton.y = rc.top;
1121 /* Line */
1122 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1123 GetWindowRect(hwndControl, &rc);
1124 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1125 ptLine.x = rc.left;
1126 ptLine.y = rc.bottom;
1128 padding.y = ptButton.y - ptLine.y;
1130 if (padding.y < 0)
1131 ERR("padding negative ! Please report this !\n");
1133 /* this is most probably not correct, but the best we have now */
1134 padding.x = padding.y;
1135 return padding;
1138 /******************************************************************************
1139 * PROPSHEET_CreateTabControl
1141 * Insert the tabs in the tab control.
1143 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1144 const PropSheetInfo * psInfo)
1146 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1147 TCITEMW item;
1148 int i, nTabs;
1149 int iImage = 0;
1151 TRACE("\n");
1152 item.mask = TCIF_TEXT;
1153 item.cchTextMax = MAX_TABTEXT_LENGTH;
1155 nTabs = psInfo->nPages;
1158 * Set the image list for icons.
1160 if (psInfo->hImageList)
1162 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1165 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1166 for (i = 0; i < nTabs; i++)
1168 if ( psInfo->proppage[i].hasIcon )
1170 item.mask |= TCIF_IMAGE;
1171 item.iImage = iImage++;
1173 else
1175 item.mask &= ~TCIF_IMAGE;
1178 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1179 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1181 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1183 return TRUE;
1186 /******************************************************************************
1187 * PROPSHEET_WizardSubclassProc
1189 * Subclassing window procedure for wizard exterior pages to prevent drawing
1190 * background and so drawing above the watermark.
1192 static LRESULT CALLBACK
1193 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1195 switch (uMsg)
1197 case WM_ERASEBKGND:
1198 return TRUE;
1200 case WM_CTLCOLORSTATIC:
1201 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1202 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1205 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1209 * Get the size of an in-memory Template
1211 *( Based on the code of PROPSHEET_CollectPageInfo)
1212 * See also dialog.c/DIALOG_ParseTemplate32().
1215 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1218 const WORD* p = (const WORD *)pTemplate;
1219 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1220 WORD nrofitems;
1221 UINT ret;
1223 if (istemplateex)
1225 /* DLGTEMPLATEEX (not defined in any std. header file) */
1227 TRACE("is DLGTEMPLATEEX\n");
1228 p++; /* dlgVer */
1229 p++; /* signature */
1230 p += 2; /* help ID */
1231 p += 2; /* ext style */
1232 p += 2; /* style */
1234 else
1236 /* DLGTEMPLATE */
1238 TRACE("is DLGTEMPLATE\n");
1239 p += 2; /* style */
1240 p += 2; /* ext style */
1243 nrofitems = (WORD)*p; p++; /* nb items */
1244 p++; /* x */
1245 p++; /* y */
1246 p++; /* width */
1247 p++; /* height */
1249 /* menu */
1250 switch ((WORD)*p)
1252 case 0x0000:
1253 p++;
1254 break;
1255 case 0xffff:
1256 p += 2;
1257 break;
1258 default:
1259 TRACE("menu %s\n",debugstr_w( p ));
1260 p += lstrlenW( p ) + 1;
1261 break;
1264 /* class */
1265 switch ((WORD)*p)
1267 case 0x0000:
1268 p++;
1269 break;
1270 case 0xffff:
1271 p += 2; /* 0xffff plus predefined window class ordinal value */
1272 break;
1273 default:
1274 TRACE("class %s\n",debugstr_w( p ));
1275 p += lstrlenW( p ) + 1;
1276 break;
1279 /* title */
1280 TRACE("title %s\n",debugstr_w( p ));
1281 p += lstrlenW( p ) + 1;
1283 /* font, if DS_SETFONT set */
1284 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1285 pTemplate->style)))
1287 p+=(istemplateex)?3:1;
1288 TRACE("font %s\n",debugstr_w( p ));
1289 p += lstrlenW( p ) + 1; /* the font name */
1292 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1293 * that are following the DLGTEMPLATE(EX) data */
1294 TRACE("%d items\n",nrofitems);
1295 while (nrofitems > 0)
1297 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1299 /* skip header */
1300 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1302 /* check class */
1303 switch ((WORD)*p)
1305 case 0x0000:
1306 p++;
1307 break;
1308 case 0xffff:
1309 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1310 p += 2;
1311 break;
1312 default:
1313 TRACE("class %s\n",debugstr_w( p ));
1314 p += lstrlenW( p ) + 1;
1315 break;
1318 /* check title text */
1319 switch ((WORD)*p)
1321 case 0x0000:
1322 p++;
1323 break;
1324 case 0xffff:
1325 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1326 p += 2;
1327 break;
1328 default:
1329 TRACE("text %s\n",debugstr_w( p ));
1330 p += lstrlenW( p ) + 1;
1331 break;
1333 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1334 --nrofitems;
1337 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1338 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1339 return ret;
1342 /******************************************************************************
1343 * PROPSHEET_CreatePage
1345 * Creates a page.
1347 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1348 int index,
1349 const PropSheetInfo * psInfo,
1350 LPCPROPSHEETPAGEW ppshpage)
1352 const DLGTEMPLATE* pTemplate;
1353 HWND hwndPage;
1354 DWORD resSize;
1355 DLGTEMPLATE* pTemplateCopy = NULL;
1357 TRACE("index %d\n", index);
1359 if (ppshpage == NULL)
1361 return FALSE;
1364 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1366 pTemplate = ppshpage->u.pResource;
1367 resSize = GetTemplateSize(pTemplate);
1369 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1371 HRSRC hResource;
1372 HANDLE hTemplate;
1374 hResource = FindResourceW(ppshpage->hInstance,
1375 ppshpage->u.pszTemplate,
1376 (LPWSTR)RT_DIALOG);
1377 if(!hResource)
1378 return FALSE;
1380 resSize = SizeofResource(ppshpage->hInstance, hResource);
1382 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1383 if(!hTemplate)
1384 return FALSE;
1386 pTemplate = LockResource(hTemplate);
1388 * Make a copy of the dialog template to make it writable
1391 else
1393 HRSRC hResource;
1394 HANDLE hTemplate;
1396 hResource = FindResourceA(ppshpage->hInstance,
1397 (LPCSTR)ppshpage->u.pszTemplate,
1398 (LPSTR)RT_DIALOG);
1399 if(!hResource)
1400 return FALSE;
1402 resSize = SizeofResource(ppshpage->hInstance, hResource);
1404 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1405 if(!hTemplate)
1406 return FALSE;
1408 pTemplate = LockResource(hTemplate);
1410 * Make a copy of the dialog template to make it writable
1413 pTemplateCopy = Alloc(resSize);
1414 if (!pTemplateCopy)
1415 return FALSE;
1417 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1418 memcpy(pTemplateCopy, pTemplate, resSize);
1420 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1422 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1423 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1424 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1425 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1426 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1427 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1428 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1429 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1431 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1433 else
1435 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1436 pTemplateCopy->style &= ~DS_MODALFRAME;
1437 pTemplateCopy->style &= ~WS_CAPTION;
1438 pTemplateCopy->style &= ~WS_SYSMENU;
1439 pTemplateCopy->style &= ~WS_POPUP;
1440 pTemplateCopy->style &= ~WS_DISABLED;
1441 pTemplateCopy->style &= ~WS_VISIBLE;
1442 pTemplateCopy->style &= ~WS_THICKFRAME;
1444 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1447 if (psInfo->proppage[index].useCallback)
1448 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1449 (LPPROPSHEETPAGEW)ppshpage);
1451 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1452 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1453 pTemplateCopy,
1454 hwndParent,
1455 ppshpage->pfnDlgProc,
1456 (LPARAM)ppshpage);
1457 else
1458 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1459 pTemplateCopy,
1460 hwndParent,
1461 ppshpage->pfnDlgProc,
1462 (LPARAM)ppshpage);
1463 /* Free a no more needed copy */
1464 Free(pTemplateCopy);
1466 if(!hwndPage)
1467 return FALSE;
1469 psInfo->proppage[index].hwndPage = hwndPage;
1471 /* Subclass exterior wizard pages */
1472 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1473 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1474 (ppshpage->dwFlags & PSP_HIDEHEADER))
1476 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1477 (DWORD_PTR)ppshpage);
1479 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1480 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1482 return TRUE;
1485 /******************************************************************************
1486 * PROPSHEET_LoadWizardBitmaps
1488 * Loads the watermark and header bitmaps for a wizard.
1490 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1492 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1494 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1495 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1496 considers hbmWatermark as valid. */
1497 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1498 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1500 psInfo->ppshheader.u4.hbmWatermark =
1501 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1504 /* Same behavior as for watermarks */
1505 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1506 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1508 psInfo->ppshheader.u5.hbmHeader =
1509 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1515 /******************************************************************************
1516 * PROPSHEET_ShowPage
1518 * Displays or creates the specified page.
1520 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1522 HWND hwndTabCtrl;
1523 HWND hwndLineHeader;
1524 HWND control;
1525 LPCPROPSHEETPAGEW ppshpage;
1527 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1528 if (index == psInfo->active_page)
1530 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1531 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1532 return TRUE;
1535 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1536 if (psInfo->proppage[index].hwndPage == 0)
1538 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1541 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1543 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1544 psInfo->proppage[index].pszText);
1546 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1547 if(control != NULL)
1548 SetFocus(control);
1551 if (psInfo->active_page != -1)
1552 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1554 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1556 /* Synchronize current selection with tab control
1557 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1558 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1559 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1561 psInfo->active_page = index;
1562 psInfo->activeValid = TRUE;
1564 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1566 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1567 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1569 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1570 ShowWindow(hwndLineHeader, SW_HIDE);
1571 else
1572 ShowWindow(hwndLineHeader, SW_SHOW);
1575 return TRUE;
1578 /******************************************************************************
1579 * PROPSHEET_Back
1581 static BOOL PROPSHEET_Back(HWND hwndDlg)
1583 PSHNOTIFY psn;
1584 HWND hwndPage;
1585 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1586 LRESULT result;
1587 int idx;
1589 TRACE("active_page %d\n", psInfo->active_page);
1590 if (psInfo->active_page < 0)
1591 return FALSE;
1593 psn.hdr.code = PSN_WIZBACK;
1594 psn.hdr.hwndFrom = hwndDlg;
1595 psn.hdr.idFrom = 0;
1596 psn.lParam = 0;
1598 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1600 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1601 if (result == -1)
1602 return FALSE;
1603 else if (result == 0)
1604 idx = psInfo->active_page - 1;
1605 else
1606 idx = PROPSHEET_FindPageByResId(psInfo, result);
1608 if (idx >= 0 && idx < psInfo->nPages)
1610 if (PROPSHEET_CanSetCurSel(hwndDlg))
1612 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1613 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1614 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1617 return TRUE;
1620 /******************************************************************************
1621 * PROPSHEET_Next
1623 static BOOL PROPSHEET_Next(HWND hwndDlg)
1625 PSHNOTIFY psn;
1626 HWND hwndPage;
1627 LRESULT msgResult = 0;
1628 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1629 int idx;
1631 TRACE("active_page %d\n", psInfo->active_page);
1632 if (psInfo->active_page < 0)
1633 return FALSE;
1635 psn.hdr.code = PSN_WIZNEXT;
1636 psn.hdr.hwndFrom = hwndDlg;
1637 psn.hdr.idFrom = 0;
1638 psn.lParam = 0;
1640 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1642 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1643 if (msgResult == -1)
1644 return FALSE;
1645 else if (msgResult == 0)
1646 idx = psInfo->active_page + 1;
1647 else
1648 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1650 if (idx < psInfo->nPages )
1652 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1654 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1655 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1656 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1660 return TRUE;
1663 /******************************************************************************
1664 * PROPSHEET_Finish
1666 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1668 PSHNOTIFY psn;
1669 HWND hwndPage;
1670 LRESULT msgResult = 0;
1671 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1673 TRACE("active_page %d\n", psInfo->active_page);
1674 if (psInfo->active_page < 0)
1675 return FALSE;
1677 psn.hdr.code = PSN_WIZFINISH;
1678 psn.hdr.hwndFrom = hwndDlg;
1679 psn.hdr.idFrom = 0;
1680 psn.lParam = 0;
1682 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1684 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1686 TRACE("msg result %ld\n", msgResult);
1688 if (msgResult != 0)
1689 return FALSE;
1691 if (psInfo->result == 0)
1692 psInfo->result = IDOK;
1693 if (psInfo->isModeless)
1694 psInfo->activeValid = FALSE;
1695 else
1696 psInfo->ended = TRUE;
1698 return TRUE;
1701 /******************************************************************************
1702 * PROPSHEET_Apply
1704 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1706 int i;
1707 HWND hwndPage;
1708 PSHNOTIFY psn;
1709 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1711 TRACE("active_page %d\n", psInfo->active_page);
1712 if (psInfo->active_page < 0)
1713 return FALSE;
1715 psn.hdr.hwndFrom = hwndDlg;
1716 psn.hdr.idFrom = 0;
1717 psn.lParam = 0;
1721 * Send PSN_KILLACTIVE to the current page.
1723 psn.hdr.code = PSN_KILLACTIVE;
1725 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1727 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1728 return FALSE;
1731 * Send PSN_APPLY to all pages.
1733 psn.hdr.code = PSN_APPLY;
1734 psn.lParam = lParam;
1736 for (i = 0; i < psInfo->nPages; i++)
1738 hwndPage = psInfo->proppage[i].hwndPage;
1739 if (hwndPage)
1741 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1743 case PSNRET_INVALID:
1744 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1745 /* fall through */
1746 case PSNRET_INVALID_NOCHANGEPAGE:
1747 return FALSE;
1752 if(lParam)
1754 psInfo->activeValid = FALSE;
1756 else if(psInfo->active_page >= 0)
1758 psn.hdr.code = PSN_SETACTIVE;
1759 psn.lParam = 0;
1760 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1761 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1764 return TRUE;
1767 /******************************************************************************
1768 * PROPSHEET_Cancel
1770 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1772 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1773 HWND hwndPage;
1774 PSHNOTIFY psn;
1775 int i;
1777 TRACE("active_page %d\n", psInfo->active_page);
1778 if (psInfo->active_page < 0)
1779 return;
1781 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1782 psn.hdr.code = PSN_QUERYCANCEL;
1783 psn.hdr.hwndFrom = hwndDlg;
1784 psn.hdr.idFrom = 0;
1785 psn.lParam = 0;
1787 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1788 return;
1790 psn.hdr.code = PSN_RESET;
1791 psn.lParam = lParam;
1793 for (i = 0; i < psInfo->nPages; i++)
1795 hwndPage = psInfo->proppage[i].hwndPage;
1797 if (hwndPage)
1798 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1801 if (psInfo->isModeless)
1803 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1804 psInfo->activeValid = FALSE;
1806 else
1807 psInfo->ended = TRUE;
1810 /******************************************************************************
1811 * PROPSHEET_Help
1813 static void PROPSHEET_Help(HWND hwndDlg)
1815 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1816 HWND hwndPage;
1817 PSHNOTIFY psn;
1819 TRACE("active_page %d\n", psInfo->active_page);
1820 if (psInfo->active_page < 0)
1821 return;
1823 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1824 psn.hdr.code = PSN_HELP;
1825 psn.hdr.hwndFrom = hwndDlg;
1826 psn.hdr.idFrom = 0;
1827 psn.lParam = 0;
1829 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1832 /******************************************************************************
1833 * PROPSHEET_Changed
1835 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1837 int i;
1838 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1840 TRACE("\n");
1841 if (!psInfo) return;
1843 * Set the dirty flag of this page.
1845 for (i = 0; i < psInfo->nPages; i++)
1847 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1848 psInfo->proppage[i].isDirty = TRUE;
1852 * Enable the Apply button.
1854 if (psInfo->hasApply)
1856 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1858 EnableWindow(hwndApplyBtn, TRUE);
1862 /******************************************************************************
1863 * PROPSHEET_UnChanged
1865 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1867 int i;
1868 BOOL noPageDirty = TRUE;
1869 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1870 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1872 TRACE("\n");
1873 if ( !psInfo ) return;
1874 for (i = 0; i < psInfo->nPages; i++)
1876 /* set the specified page as clean */
1877 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1878 psInfo->proppage[i].isDirty = FALSE;
1880 /* look to see if there are any dirty pages */
1881 if (psInfo->proppage[i].isDirty)
1882 noPageDirty = FALSE;
1886 * Disable Apply button.
1888 if (noPageDirty)
1889 EnableWindow(hwndApplyBtn, FALSE);
1892 /******************************************************************************
1893 * PROPSHEET_PressButton
1895 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1897 TRACE("buttonID %d\n", buttonID);
1898 switch (buttonID)
1900 case PSBTN_APPLYNOW:
1901 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1902 break;
1903 case PSBTN_BACK:
1904 PROPSHEET_Back(hwndDlg);
1905 break;
1906 case PSBTN_CANCEL:
1907 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1908 break;
1909 case PSBTN_FINISH:
1910 PROPSHEET_Finish(hwndDlg);
1911 break;
1912 case PSBTN_HELP:
1913 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1914 break;
1915 case PSBTN_NEXT:
1916 PROPSHEET_Next(hwndDlg);
1917 break;
1918 case PSBTN_OK:
1919 PROPSHEET_DoCommand(hwndDlg, IDOK);
1920 break;
1921 default:
1922 FIXME("Invalid button index %d\n", buttonID);
1927 /*************************************************************************
1928 * BOOL PROPSHEET_CanSetCurSel [Internal]
1930 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1932 * PARAMS
1933 * hwndDlg [I] handle to a Dialog hWnd
1935 * RETURNS
1936 * TRUE if Current Selection can change
1938 * NOTES
1940 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1942 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1943 HWND hwndPage;
1944 PSHNOTIFY psn;
1945 BOOL res = FALSE;
1947 if (!psInfo)
1949 res = FALSE;
1950 goto end;
1953 TRACE("active_page %d\n", psInfo->active_page);
1954 if (psInfo->active_page < 0)
1956 res = TRUE;
1957 goto end;
1961 * Notify the current page.
1963 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1964 psn.hdr.code = PSN_KILLACTIVE;
1965 psn.hdr.hwndFrom = hwndDlg;
1966 psn.hdr.idFrom = 0;
1967 psn.lParam = 0;
1969 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1971 end:
1972 TRACE("<-- %d\n", res);
1973 return res;
1976 /******************************************************************************
1977 * PROPSHEET_SetCurSel
1979 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1980 int index,
1981 int skipdir,
1982 HPROPSHEETPAGE hpage
1985 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1986 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1987 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1989 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1991 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1993 if (index < 0 || index >= psInfo->nPages)
1995 TRACE("Could not find page to select!\n");
1996 return FALSE;
1999 /* unset active page while doing this transition. */
2000 if (psInfo->active_page != -1)
2001 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2002 psInfo->active_page = -1;
2004 while (1) {
2005 int result;
2006 PSHNOTIFY psn;
2007 RECT rc;
2008 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2010 if (hwndTabControl)
2011 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2013 psn.hdr.code = PSN_SETACTIVE;
2014 psn.hdr.hwndFrom = hwndDlg;
2015 psn.hdr.idFrom = 0;
2016 psn.lParam = 0;
2018 if (!psInfo->proppage[index].hwndPage) {
2019 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2020 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2021 if(index >= psInfo->nPages)
2022 index--;
2023 if(index < 0)
2024 return FALSE;
2025 continue;
2029 /* Resize the property sheet page to the fit in the Tab control
2030 * (for regular property sheets) or to fit in the client area (for
2031 * wizards).
2032 * NOTE: The resizing happens every time the page is selected and
2033 * not only when it's created (some applications depend on it). */
2034 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2035 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2036 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2037 rc.right - rc.left, rc.bottom - rc.top);
2038 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2039 rc.left, rc.top,
2040 rc.right - rc.left, rc.bottom - rc.top, 0);
2042 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2043 if (!result)
2044 break;
2045 if (result == -1) {
2046 index+=skipdir;
2047 if (index < 0) {
2048 index = 0;
2049 WARN("Tried to skip before first property sheet page!\n");
2050 break;
2052 if (index >= psInfo->nPages) {
2053 WARN("Tried to skip after last property sheet page!\n");
2054 index = psInfo->nPages-1;
2055 break;
2058 else if (result != 0)
2060 int old_index = index;
2061 index = PROPSHEET_FindPageByResId(psInfo, result);
2062 if(index >= psInfo->nPages) {
2063 index = old_index;
2064 WARN("Tried to skip to nonexistent page by res id\n");
2065 break;
2067 continue;
2071 /* Invalidate the header area */
2072 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2073 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2075 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2076 RECT r;
2078 GetClientRect(hwndLineHeader, &r);
2079 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2080 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2082 InvalidateRect(hwndDlg, &r, TRUE);
2086 * Display the new page.
2088 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2090 if (psInfo->proppage[index].hasHelp)
2091 EnableWindow(hwndHelp, TRUE);
2092 else
2093 EnableWindow(hwndHelp, FALSE);
2095 return TRUE;
2098 /******************************************************************************
2099 * PROPSHEET_SetCurSelId
2101 * Selects the page, specified by resource id.
2103 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2105 int idx;
2106 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2108 idx = PROPSHEET_FindPageByResId(psInfo, id);
2109 if (idx < psInfo->nPages )
2111 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2112 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2116 /******************************************************************************
2117 * PROPSHEET_SetTitleA
2119 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2121 if(!IS_INTRESOURCE(lpszText))
2123 WCHAR szTitle[256];
2124 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2125 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2126 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2128 else
2130 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2134 /******************************************************************************
2135 * PROPSHEET_SetTitleW
2137 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2139 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2140 WCHAR szTitle[256];
2142 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2143 if (IS_INTRESOURCE(lpszText)) {
2144 if (!LoadStringW(psInfo->ppshheader.hInstance,
2145 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2146 return;
2147 lpszText = szTitle;
2149 if (dwStyle & PSH_PROPTITLE)
2151 WCHAR* dest;
2152 int lentitle = strlenW(lpszText);
2153 int lenprop = strlenW(psInfo->strPropertiesFor);
2155 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2156 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2158 SetWindowTextW(hwndDlg, dest);
2159 Free(dest);
2161 else
2162 SetWindowTextW(hwndDlg, lpszText);
2165 /******************************************************************************
2166 * PROPSHEET_SetFinishTextA
2168 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2170 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2171 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2173 TRACE("'%s'\n", lpszText);
2174 /* Set text, show and enable the Finish button */
2175 SetWindowTextA(hwndButton, lpszText);
2176 ShowWindow(hwndButton, SW_SHOW);
2177 EnableWindow(hwndButton, TRUE);
2179 /* Make it default pushbutton */
2180 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2182 /* Hide Back button */
2183 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2184 ShowWindow(hwndButton, SW_HIDE);
2186 if (!psInfo->hasFinish)
2188 /* Hide Next button */
2189 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2190 ShowWindow(hwndButton, SW_HIDE);
2194 /******************************************************************************
2195 * PROPSHEET_SetFinishTextW
2197 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2199 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2200 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2202 TRACE("%s\n", debugstr_w(lpszText));
2203 /* Set text, show and enable the Finish button */
2204 SetWindowTextW(hwndButton, lpszText);
2205 ShowWindow(hwndButton, SW_SHOW);
2206 EnableWindow(hwndButton, TRUE);
2208 /* Make it default pushbutton */
2209 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2211 /* Hide Back button */
2212 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2213 ShowWindow(hwndButton, SW_HIDE);
2215 if (!psInfo->hasFinish)
2217 /* Hide Next button */
2218 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2219 ShowWindow(hwndButton, SW_HIDE);
2223 /******************************************************************************
2224 * PROPSHEET_QuerySiblings
2226 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2227 WPARAM wParam, LPARAM lParam)
2229 int i = 0;
2230 HWND hwndPage;
2231 LRESULT msgResult = 0;
2232 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2234 while ((i < psInfo->nPages) && (msgResult == 0))
2236 hwndPage = psInfo->proppage[i].hwndPage;
2237 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2238 i++;
2241 return msgResult;
2245 /******************************************************************************
2246 * PROPSHEET_AddPage
2248 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2249 HPROPSHEETPAGE hpage)
2251 PropPageInfo * ppi;
2252 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2253 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2254 TCITEMW item;
2255 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2257 TRACE("hpage %p\n", hpage);
2259 * Allocate and fill in a new PropPageInfo entry.
2261 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2262 if (!ppi)
2263 return FALSE;
2265 psInfo->proppage = ppi;
2266 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2267 return FALSE;
2269 psInfo->proppage[psInfo->nPages].hpage = hpage;
2271 if (ppsp->dwFlags & PSP_PREMATURE)
2273 /* Create the page but don't show it */
2274 if(!PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp))
2275 return FALSE;
2279 * Add a new tab to the tab control.
2281 item.mask = TCIF_TEXT;
2282 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2283 item.cchTextMax = MAX_TABTEXT_LENGTH;
2285 if (psInfo->hImageList)
2287 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2290 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2292 item.mask |= TCIF_IMAGE;
2293 item.iImage = psInfo->nPages;
2296 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2297 (LPARAM)&item);
2299 psInfo->nPages++;
2301 /* If it is the only page - show it */
2302 if(psInfo->nPages == 1)
2303 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2304 return TRUE;
2307 /******************************************************************************
2308 * PROPSHEET_RemovePage
2310 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2311 int index,
2312 HPROPSHEETPAGE hpage)
2314 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2315 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2316 PropPageInfo* oldPages;
2318 TRACE("index %d, hpage %p\n", index, hpage);
2319 if (!psInfo) {
2320 return FALSE;
2323 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2325 /* Make sure that index is within range */
2326 if (index < 0 || index >= psInfo->nPages)
2328 TRACE("Could not find page to remove!\n");
2329 return FALSE;
2332 TRACE("total pages %d removing page %d active page %d\n",
2333 psInfo->nPages, index, psInfo->active_page);
2335 * Check if we're removing the active page.
2337 if (index == psInfo->active_page)
2339 if (psInfo->nPages > 1)
2341 if (index > 0)
2343 /* activate previous page */
2344 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2346 else
2348 /* activate the next page */
2349 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2350 psInfo->active_page = index;
2353 else
2355 psInfo->active_page = -1;
2356 if (!psInfo->isModeless)
2358 psInfo->ended = TRUE;
2359 return TRUE;
2363 else if (index < psInfo->active_page)
2364 psInfo->active_page--;
2366 /* Unsubclass the page dialog window */
2367 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2368 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2369 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2371 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2372 PROPSHEET_WizardSubclassProc, 1);
2375 /* Destroy page dialog window */
2376 DestroyWindow(psInfo->proppage[index].hwndPage);
2378 /* Free page resources */
2379 if(psInfo->proppage[index].hpage)
2381 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2383 if (psp->dwFlags & PSP_USETITLE)
2384 Free ((LPVOID)psInfo->proppage[index].pszText);
2386 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2389 /* Remove the tab */
2390 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2392 oldPages = psInfo->proppage;
2393 psInfo->nPages--;
2394 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2396 if (index > 0)
2397 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2399 if (index < psInfo->nPages)
2400 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2401 (psInfo->nPages - index) * sizeof(PropPageInfo));
2403 Free(oldPages);
2405 return FALSE;
2408 /******************************************************************************
2409 * PROPSHEET_SetWizButtons
2411 * This code will work if (and assumes that) the Next button is on top of the
2412 * Finish button. ie. Finish comes after Next in the Z order.
2413 * This means make sure the dialog template reflects this.
2416 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2418 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2419 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2420 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2421 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2422 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2424 TRACE("%d\n", dwFlags);
2426 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2427 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2428 EnableWindow(hwndFinish, enable_finish);
2430 /* set the default pushbutton to an enabled button */
2431 if (enable_finish)
2432 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2433 else if (dwFlags & PSWIZB_NEXT)
2434 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2435 else if (dwFlags & PSWIZB_BACK)
2436 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2437 else
2438 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2440 if (!psInfo->hasFinish)
2442 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2444 /* Hide the Next button */
2445 ShowWindow(hwndNext, SW_HIDE);
2447 /* Show the Finish button */
2448 ShowWindow(hwndFinish, SW_SHOW);
2450 else
2452 /* Hide the Finish button */
2453 ShowWindow(hwndFinish, SW_HIDE);
2454 /* Show the Next button */
2455 ShowWindow(hwndNext, SW_SHOW);
2460 /******************************************************************************
2461 * PROPSHEET_InsertPage
2463 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2465 if (IS_INTRESOURCE(hpageInsertAfter))
2466 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2467 else
2468 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2469 return FALSE;
2472 /******************************************************************************
2473 * PROPSHEET_SetHeaderTitleW
2475 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2477 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2480 /******************************************************************************
2481 * PROPSHEET_SetHeaderTitleA
2483 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2485 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2488 /******************************************************************************
2489 * PROPSHEET_SetHeaderSubTitleW
2491 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2493 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2496 /******************************************************************************
2497 * PROPSHEET_SetHeaderSubTitleA
2499 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2501 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2504 /******************************************************************************
2505 * PROPSHEET_HwndToIndex
2507 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2509 int index;
2510 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2512 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2514 for (index = 0; index < psInfo->nPages; index++)
2515 if (psInfo->proppage[index].hwndPage == hPageDlg)
2516 return index;
2517 WARN("%p not found\n", hPageDlg);
2518 return -1;
2521 /******************************************************************************
2522 * PROPSHEET_IndexToHwnd
2524 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2526 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2527 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2528 if (!psInfo)
2529 return 0;
2530 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2531 WARN("%d out of range.\n", iPageIndex);
2532 return 0;
2534 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2537 /******************************************************************************
2538 * PROPSHEET_PageToIndex
2540 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2542 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2544 TRACE("(%p, %p)\n", hwndDlg, hPage);
2546 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2549 /******************************************************************************
2550 * PROPSHEET_IndexToPage
2552 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2554 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2555 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2556 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2557 WARN("%d out of range.\n", iPageIndex);
2558 return 0;
2560 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2563 /******************************************************************************
2564 * PROPSHEET_IdToIndex
2566 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2568 int index;
2569 LPCPROPSHEETPAGEW psp;
2570 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2571 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2572 for (index = 0; index < psInfo->nPages; index++) {
2573 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2574 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2575 return index;
2578 return -1;
2581 /******************************************************************************
2582 * PROPSHEET_IndexToId
2584 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2586 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2587 LPCPROPSHEETPAGEW psp;
2588 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2589 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2590 WARN("%d out of range.\n", iPageIndex);
2591 return 0;
2593 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2594 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2595 return 0;
2597 return (LRESULT)psp->u.pszTemplate;
2600 /******************************************************************************
2601 * PROPSHEET_GetResult
2603 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2605 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2606 return psInfo->result;
2609 /******************************************************************************
2610 * PROPSHEET_RecalcPageSizes
2612 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2614 FIXME("(%p): stub\n", hwndDlg);
2615 return FALSE;
2618 /******************************************************************************
2619 * PROPSHEET_GetPageIndex
2621 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2622 * the array of PropPageInfo. If page is not found original index is used
2623 * (page takes precedence over index).
2625 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2627 int index;
2629 TRACE("page %p index %d\n", page, original_index);
2631 for (index = 0; index < psInfo->nPages; index++)
2632 if (psInfo->proppage[index].hpage == page)
2633 return index;
2635 return original_index;
2638 /******************************************************************************
2639 * PROPSHEET_CleanUp
2641 static void PROPSHEET_CleanUp(HWND hwndDlg)
2643 int i;
2644 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2646 TRACE("\n");
2647 if (!psInfo) return;
2648 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2649 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2651 for (i = 0; i < psInfo->nPages; i++)
2653 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2655 /* Unsubclass the page dialog window */
2656 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2657 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2658 (psp->dwFlags & PSP_HIDEHEADER))
2660 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2661 PROPSHEET_WizardSubclassProc, 1);
2664 if(psInfo->proppage[i].hwndPage)
2665 DestroyWindow(psInfo->proppage[i].hwndPage);
2667 if(psp)
2669 if (psp->dwFlags & PSP_USETITLE)
2670 Free ((LPVOID)psInfo->proppage[i].pszText);
2672 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2676 DeleteObject(psInfo->hFont);
2677 DeleteObject(psInfo->hFontBold);
2678 /* If we created the bitmaps, destroy them */
2679 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2680 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2681 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2682 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2683 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2684 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2686 Free(psInfo->proppage);
2687 Free(psInfo->strPropertiesFor);
2688 ImageList_Destroy(psInfo->hImageList);
2690 GlobalFree(psInfo);
2693 static INT do_loop(const PropSheetInfo *psInfo)
2695 MSG msg;
2696 INT ret = -1;
2697 HWND hwnd = psInfo->hwnd;
2698 HWND parent = psInfo->ppshheader.hwndParent;
2700 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2702 if(ret == -1)
2703 break;
2705 if(!IsDialogMessageW(hwnd, &msg))
2707 TranslateMessage(&msg);
2708 DispatchMessageW(&msg);
2712 if(ret == 0)
2714 PostQuitMessage(msg.wParam);
2715 ret = -1;
2718 if(ret != -1)
2719 ret = psInfo->result;
2721 if(parent)
2722 EnableWindow(parent, TRUE);
2724 DestroyWindow(hwnd);
2725 return ret;
2728 /******************************************************************************
2729 * PROPSHEET_PropertySheet
2731 * Common code between PropertySheetA/W
2733 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2735 INT_PTR bRet = 0;
2736 HWND parent = NULL;
2737 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2738 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2740 psInfo->unicode = unicode;
2741 psInfo->ended = FALSE;
2743 if(!psInfo->isModeless)
2745 parent = psInfo->ppshheader.hwndParent;
2746 if (parent) EnableWindow(parent, FALSE);
2748 bRet = PROPSHEET_CreateDialog(psInfo);
2749 if(!psInfo->isModeless)
2750 bRet = do_loop(psInfo);
2751 return bRet;
2754 /******************************************************************************
2755 * PropertySheet (COMCTL32.@)
2756 * PropertySheetA (COMCTL32.@)
2758 * Creates a property sheet in the specified property sheet header.
2760 * RETURNS
2761 * Modal property sheets: Positive if successful or -1 otherwise.
2762 * Modeless property sheets: Property sheet handle.
2763 * Or:
2764 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2765 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2767 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2769 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2770 UINT i, n;
2771 const BYTE* pByte;
2773 TRACE("(%p)\n", lppsh);
2775 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2777 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2778 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2780 for (n = i = 0; i < lppsh->nPages; i++, n++)
2782 if (!psInfo->usePropPage)
2783 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2784 else
2786 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2787 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2790 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2791 psInfo, n, TRUE))
2793 if (psInfo->usePropPage)
2794 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2795 n--;
2796 psInfo->nPages--;
2800 return PROPSHEET_PropertySheet(psInfo, FALSE);
2803 /******************************************************************************
2804 * PropertySheetW (COMCTL32.@)
2806 * See PropertySheetA.
2808 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2810 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2811 UINT i, n;
2812 const BYTE* pByte;
2814 TRACE("(%p)\n", lppsh);
2816 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2818 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2819 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2821 for (n = i = 0; i < lppsh->nPages; i++, n++)
2823 if (!psInfo->usePropPage)
2824 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2825 else
2827 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2828 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2831 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2832 psInfo, n, TRUE))
2834 if (psInfo->usePropPage)
2835 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2836 n--;
2837 psInfo->nPages--;
2841 return PROPSHEET_PropertySheet(psInfo, TRUE);
2844 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2846 LPWSTR ret;
2848 if (IS_INTRESOURCE(str))
2850 HRSRC hrsrc;
2851 HGLOBAL hmem;
2852 WCHAR *ptr;
2853 WORD i, id = LOWORD(str);
2854 UINT len;
2856 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2857 return NULL;
2858 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2859 if (!(ptr = LockResource( hmem ))) return NULL;
2860 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2861 len = *ptr;
2862 if (!len) return NULL;
2863 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2864 if (ret)
2866 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2867 ret[len] = 0;
2870 else
2872 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2873 ret = Alloc( len );
2874 if (ret) memcpy( ret, str, len );
2876 return ret;
2880 /******************************************************************************
2881 * CreatePropertySheetPage (COMCTL32.@)
2882 * CreatePropertySheetPageA (COMCTL32.@)
2884 * Creates a new property sheet page.
2886 * RETURNS
2887 * Success: Handle to new property sheet page.
2888 * Failure: NULL.
2890 * NOTES
2891 * An application must use the PSM_ADDPAGE message to add the new page to
2892 * an existing property sheet.
2894 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2895 LPCPROPSHEETPAGEA lpPropSheetPage)
2897 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2899 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2901 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2903 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2905 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2907 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2908 char *template = Alloc( len );
2910 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2914 if (ppsp->dwFlags & PSP_USEICONID)
2916 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2917 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2920 if (ppsp->dwFlags & PSP_USETITLE)
2922 if (!IS_INTRESOURCE( ppsp->pszTitle ))
2923 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2924 else
2925 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2927 else
2928 ppsp->pszTitle = NULL;
2930 if (ppsp->dwFlags & PSP_HIDEHEADER)
2931 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2933 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2935 if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
2936 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2937 else
2938 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2940 else
2941 ppsp->pszHeaderTitle = NULL;
2943 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2945 if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
2946 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2947 else
2948 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2950 else
2951 ppsp->pszHeaderSubTitle = NULL;
2953 return (HPROPSHEETPAGE)ppsp;
2956 /******************************************************************************
2957 * CreatePropertySheetPageW (COMCTL32.@)
2959 * See CreatePropertySheetA.
2961 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2963 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2965 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2967 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2969 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2971 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2973 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
2974 WCHAR *template = Alloc( len * sizeof (WCHAR) );
2976 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
2980 if ( ppsp->dwFlags & PSP_USEICONID )
2982 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2984 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
2985 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
2987 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
2991 if (ppsp->dwFlags & PSP_USETITLE)
2992 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2993 else
2994 ppsp->pszTitle = NULL;
2996 if (ppsp->dwFlags & PSP_HIDEHEADER)
2997 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2999 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3000 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3001 else
3002 ppsp->pszHeaderTitle = NULL;
3004 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3005 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3006 else
3007 ppsp->pszHeaderSubTitle = NULL;
3009 return (HPROPSHEETPAGE)ppsp;
3012 /******************************************************************************
3013 * DestroyPropertySheetPage (COMCTL32.@)
3015 * Destroys a property sheet page previously created with
3016 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3017 * memory.
3019 * RETURNS
3020 * Success: TRUE
3021 * Failure: FALSE
3023 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3025 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3027 if (!psp)
3028 return FALSE;
3030 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3031 Free ((LPVOID)psp->u.pszTemplate);
3033 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3034 Free ((LPVOID)psp->u2.pszIcon);
3036 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3037 Free ((LPVOID)psp->pszTitle);
3039 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3040 Free ((LPVOID)psp->pszHeaderTitle);
3042 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3043 Free ((LPVOID)psp->pszHeaderSubTitle);
3045 Free(hPropPage);
3047 return TRUE;
3050 /******************************************************************************
3051 * PROPSHEET_IsDialogMessage
3053 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3055 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3057 TRACE("\n");
3058 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3059 return FALSE;
3061 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3063 int new_page = 0;
3064 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3066 if (!(dlgCode & DLGC_WANTMESSAGE))
3068 switch (lpMsg->wParam)
3070 case VK_TAB:
3071 if (GetKeyState(VK_SHIFT) & 0x8000)
3072 new_page = -1;
3073 else
3074 new_page = 1;
3075 break;
3077 case VK_NEXT: new_page = 1; break;
3078 case VK_PRIOR: new_page = -1; break;
3082 if (new_page)
3084 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3086 new_page += psInfo->active_page;
3088 if (new_page < 0)
3089 new_page = psInfo->nPages - 1;
3090 else if (new_page >= psInfo->nPages)
3091 new_page = 0;
3093 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3096 return TRUE;
3100 return IsDialogMessageW(hwnd, lpMsg);
3103 /******************************************************************************
3104 * PROPSHEET_DoCommand
3106 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3109 switch (wID) {
3111 case IDOK:
3112 case IDC_APPLY_BUTTON:
3114 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3116 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3117 break;
3119 if (wID == IDOK)
3121 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3123 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3124 if (psInfo->result == 0)
3125 psInfo->result = IDOK;
3127 if (psInfo->isModeless)
3128 psInfo->activeValid = FALSE;
3129 else
3130 psInfo->ended = TRUE;
3132 else
3133 EnableWindow(hwndApplyBtn, FALSE);
3135 break;
3138 case IDC_BACK_BUTTON:
3139 PROPSHEET_Back(hwnd);
3140 break;
3142 case IDC_NEXT_BUTTON:
3143 PROPSHEET_Next(hwnd);
3144 break;
3146 case IDC_FINISH_BUTTON:
3147 PROPSHEET_Finish(hwnd);
3148 break;
3150 case IDCANCEL:
3151 PROPSHEET_Cancel(hwnd, 0);
3152 break;
3154 case IDHELP:
3155 PROPSHEET_Help(hwnd);
3156 break;
3158 default:
3159 return FALSE;
3162 return TRUE;
3165 /******************************************************************************
3166 * PROPSHEET_Paint
3168 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3170 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3171 PAINTSTRUCT ps;
3172 HDC hdc, hdcSrc;
3173 BITMAP bm;
3174 HBITMAP hbmp;
3175 HPALETTE hOldPal = 0;
3176 int offsety = 0;
3177 HBRUSH hbr;
3178 RECT r, rzone;
3179 LPCPROPSHEETPAGEW ppshpage;
3180 WCHAR szBuffer[256];
3181 int nLength;
3183 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3184 if (!hdc) return 1;
3186 hdcSrc = CreateCompatibleDC(0);
3188 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3189 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3191 if (psInfo->active_page < 0)
3192 ppshpage = NULL;
3193 else
3194 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3196 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3197 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3198 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3200 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3201 HFONT hOldFont;
3202 COLORREF clrOld = 0;
3203 int oldBkMode = 0;
3205 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3206 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3208 GetClientRect(hwndLineHeader, &r);
3209 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3210 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3212 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3214 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3216 /* Fill the unoccupied part of the header with color of the
3217 * left-top pixel, but do it only when needed.
3219 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3221 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3222 r = rzone;
3223 if (bm.bmWidth < r.right)
3225 r.left = bm.bmWidth;
3226 FillRect(hdc, &r, hbr);
3228 if (bm.bmHeight < r.bottom)
3230 r.left = 0;
3231 r.top = bm.bmHeight;
3232 FillRect(hdc, &r, hbr);
3234 DeleteObject(hbr);
3237 /* Draw the header itself. */
3238 BitBlt(hdc, 0, 0,
3239 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3240 hdcSrc, 0, 0, SRCCOPY);
3242 else
3244 int margin;
3245 hbr = GetSysColorBrush(COLOR_WINDOW);
3246 FillRect(hdc, &rzone, hbr);
3248 /* Draw the header bitmap. It's always centered like a
3249 * common 49 x 49 bitmap. */
3250 margin = (rzone.bottom - 49) / 2;
3251 BitBlt(hdc, rzone.right - 49 - margin, margin,
3252 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3253 hdcSrc, 0, 0, SRCCOPY);
3255 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3256 * if its height is smaller than 49 pixels. Because the reason
3257 * for this bug is unknown the current code doesn't try to
3258 * replicate it. */
3261 clrOld = SetTextColor (hdc, 0x00000000);
3262 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3264 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3265 SetRect(&r, 20, 10, 0, 0);
3266 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3267 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3268 else
3270 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3271 szBuffer, 256);
3272 if (nLength != 0)
3274 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3279 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3280 SelectObject(hdc, psInfo->hFont);
3281 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3282 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3283 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3284 else
3286 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3287 szBuffer, 256);
3288 if (nLength != 0)
3290 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3295 offsety = rzone.bottom + 2;
3297 SetTextColor(hdc, clrOld);
3298 SetBkMode(hdc, oldBkMode);
3299 SelectObject(hdc, hOldFont);
3300 SelectObject(hdcSrc, hbmp);
3303 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3304 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3305 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3307 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3309 GetClientRect(hwndLine, &r);
3310 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3311 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3313 hbr = GetSysColorBrush(COLOR_WINDOW);
3314 FillRect(hdc, &rzone, hbr);
3316 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3317 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3319 /* The watermark is truncated to a width of 164 pixels */
3320 r.right = min(r.right, 164);
3321 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3322 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3324 /* If the bitmap is not big enough, fill the remaining area
3325 with the color of pixel (0,0) of bitmap - see MSDN */
3326 if (r.top > bm.bmHeight) {
3327 r.bottom = r.top - 1;
3328 r.top = bm.bmHeight;
3329 r.left = 0;
3330 r.right = bm.bmWidth;
3331 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3332 FillRect(hdc, &r, hbr);
3333 DeleteObject(hbr);
3336 SelectObject(hdcSrc, hbmp);
3339 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3340 SelectPalette(hdc, hOldPal, FALSE);
3342 DeleteDC(hdcSrc);
3344 if (!hdcParam) EndPaint(hwnd, &ps);
3346 return 0;
3349 /******************************************************************************
3350 * PROPSHEET_DialogProc
3352 static INT_PTR CALLBACK
3353 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3355 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3356 hwnd, uMsg, wParam, lParam);
3358 switch (uMsg)
3360 case WM_INITDIALOG:
3362 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3363 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3364 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3365 int idx;
3366 LOGFONTW logFont;
3368 /* Using PropSheetInfoStr to store extra data doesn't match the native
3369 * common control: native uses TCM_[GS]ETITEM
3371 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3374 * psInfo->hwnd is not being used by WINE code - it exists
3375 * for compatibility with "real" Windoze. The same about
3376 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3377 * property.
3379 psInfo->hwnd = hwnd;
3380 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3382 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3384 /* set up the Next and Back buttons by default */
3385 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3388 /* Set up fonts */
3389 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3390 psInfo->hFont = CreateFontIndirectW (&logFont);
3391 logFont.lfWeight = FW_BOLD;
3392 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3395 * Small icon in the title bar.
3397 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3398 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3400 HICON hIcon;
3401 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3402 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3404 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3405 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3406 psInfo->ppshheader.u.pszIcon,
3407 IMAGE_ICON,
3408 icon_cx, icon_cy,
3409 LR_DEFAULTCOLOR);
3410 else
3411 hIcon = psInfo->ppshheader.u.hIcon;
3413 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3416 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3417 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3419 psInfo->strPropertiesFor = strCaption;
3421 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3423 PROPSHEET_CreateTabControl(hwnd, psInfo);
3425 PROPSHEET_LoadWizardBitmaps(psInfo);
3427 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3429 ShowWindow(hwndTabCtrl, SW_HIDE);
3430 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3431 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3432 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3434 else
3436 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3438 PROPSHEET_AdjustSize(hwnd, psInfo);
3439 PROPSHEET_AdjustButtons(hwnd, psInfo);
3441 SetFocus(GetDlgItem(hwnd, IDOK));
3444 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3445 psInfo->ppshheader.hInstance)
3447 WCHAR szText[256];
3449 if (LoadStringW(psInfo->ppshheader.hInstance,
3450 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3451 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3453 else
3455 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3456 psInfo->ppshheader.pszCaption);
3460 if (psInfo->useCallback)
3461 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3463 idx = psInfo->active_page;
3464 psInfo->active_page = -1;
3466 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3468 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3469 * as some programs call TCM_GETCURSEL to get the current selection
3470 * from which to switch to the next page */
3471 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3473 PROPSHEET_UnChanged(hwnd, NULL);
3475 /* wizards set their focus during init */
3476 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3477 return FALSE;
3479 return TRUE;
3482 case WM_PRINTCLIENT:
3483 case WM_PAINT:
3484 PROPSHEET_Paint(hwnd, (HDC)wParam);
3485 return TRUE;
3487 case WM_DESTROY:
3488 PROPSHEET_CleanUp(hwnd);
3489 return TRUE;
3491 case WM_CLOSE:
3492 PROPSHEET_Cancel(hwnd, 1);
3493 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3495 case WM_COMMAND:
3496 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3498 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3500 if (!psInfo)
3501 return FALSE;
3503 /* No default handler, forward notification to active page */
3504 if (psInfo->activeValid && psInfo->active_page != -1)
3506 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3507 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3510 return TRUE;
3512 case WM_NOTIFY:
3514 NMHDR* pnmh = (LPNMHDR) lParam;
3516 if (pnmh->code == TCN_SELCHANGE)
3518 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3519 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3522 if(pnmh->code == TCN_SELCHANGING)
3524 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3525 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3526 return TRUE;
3529 return FALSE;
3532 case WM_SYSCOLORCHANGE:
3533 COMCTL32_RefreshSysColors();
3534 return FALSE;
3536 case PSM_GETCURRENTPAGEHWND:
3538 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3539 HWND hwndPage = 0;
3541 if (!psInfo)
3542 return FALSE;
3544 if (psInfo->activeValid && psInfo->active_page != -1)
3545 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3547 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3549 return TRUE;
3552 case PSM_CHANGED:
3553 PROPSHEET_Changed(hwnd, (HWND)wParam);
3554 return TRUE;
3556 case PSM_UNCHANGED:
3557 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3558 return TRUE;
3560 case PSM_GETTABCONTROL:
3562 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3564 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3566 return TRUE;
3569 case PSM_SETCURSEL:
3571 BOOL msgResult;
3573 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3574 if(msgResult != FALSE)
3576 msgResult = PROPSHEET_SetCurSel(hwnd,
3577 (int)wParam,
3579 (HPROPSHEETPAGE)lParam);
3582 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3584 return TRUE;
3587 case PSM_CANCELTOCLOSE:
3589 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3590 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3591 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3593 EnableWindow(hwndCancel, FALSE);
3594 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3595 SetWindowTextW(hwndOK, buf);
3597 return FALSE;
3600 case PSM_RESTARTWINDOWS:
3602 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3604 if (!psInfo)
3605 return FALSE;
3607 /* reboot system takes precedence over restart windows */
3608 if (psInfo->result != ID_PSREBOOTSYSTEM)
3609 psInfo->result = ID_PSRESTARTWINDOWS;
3611 return TRUE;
3614 case PSM_REBOOTSYSTEM:
3616 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3618 if (!psInfo)
3619 return FALSE;
3621 psInfo->result = ID_PSREBOOTSYSTEM;
3623 return TRUE;
3626 case PSM_SETTITLEA:
3627 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3628 return TRUE;
3630 case PSM_SETTITLEW:
3631 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3632 return TRUE;
3634 case PSM_APPLY:
3636 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3638 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3640 return TRUE;
3643 case PSM_QUERYSIBLINGS:
3645 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3647 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3649 return TRUE;
3652 case PSM_ADDPAGE:
3655 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3656 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3657 * on success or FALSE otherwise, as specified on MSDN Online.
3658 * Also see the MFC code for
3659 * CPropertySheet::AddPage(CPropertyPage* pPage).
3662 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3664 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3666 return TRUE;
3669 case PSM_REMOVEPAGE:
3670 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3671 return TRUE;
3673 case PSM_ISDIALOGMESSAGE:
3675 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3676 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3677 return TRUE;
3680 case PSM_PRESSBUTTON:
3681 PROPSHEET_PressButton(hwnd, (int)wParam);
3682 return TRUE;
3684 case PSM_SETFINISHTEXTA:
3685 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3686 return TRUE;
3688 case PSM_SETWIZBUTTONS:
3689 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3690 return TRUE;
3692 case PSM_SETCURSELID:
3693 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3694 return TRUE;
3696 case PSM_SETFINISHTEXTW:
3697 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3698 return FALSE;
3700 case PSM_INSERTPAGE:
3702 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3703 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3704 return TRUE;
3707 case PSM_SETHEADERTITLEW:
3708 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3709 return TRUE;
3711 case PSM_SETHEADERTITLEA:
3712 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3713 return TRUE;
3715 case PSM_SETHEADERSUBTITLEW:
3716 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3717 return TRUE;
3719 case PSM_SETHEADERSUBTITLEA:
3720 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3721 return TRUE;
3723 case PSM_HWNDTOINDEX:
3725 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3726 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3727 return TRUE;
3730 case PSM_INDEXTOHWND:
3732 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3733 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3734 return TRUE;
3737 case PSM_PAGETOINDEX:
3739 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3740 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3741 return TRUE;
3744 case PSM_INDEXTOPAGE:
3746 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3747 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3748 return TRUE;
3751 case PSM_IDTOINDEX:
3753 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3754 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3755 return TRUE;
3758 case PSM_INDEXTOID:
3760 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3761 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3762 return TRUE;
3765 case PSM_GETRESULT:
3767 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3768 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3769 return TRUE;
3772 case PSM_RECALCPAGESIZES:
3774 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3775 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3776 return TRUE;
3779 default:
3780 return FALSE;