comctl32: Don't ignore page creation error for a non-modal propery sheet.
[wine.git] / dlls / comctl32 / propsheet.c
blob09a455121cbc8f7dae1fbcbb7f2dc83a494baed7
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_RECALCPAGESIZES
36 * o WM_HELP
37 * o WM_CONTEXTMENU
38 * - Notifications:
39 * o PSN_GETOBJECT
40 * o PSN_QUERYINITIALFOCUS
41 * o PSN_TRANSLATEACCELERATOR
42 * - Styles:
43 * o PSH_RTLREADING
44 * o PSH_STRETCHWATERMARK
45 * o PSH_USEPAGELANG
46 * o PSH_USEPSTARTPAGE
47 * - Page styles:
48 * o PSP_USEFUSIONCONTEXT
49 * o PSP_USEREFPARENT
52 #include <stdarg.h>
53 #include <string.h>
55 #define NONAMELESSUNION
57 #include "windef.h"
58 #include "winbase.h"
59 #include "wingdi.h"
60 #include "winuser.h"
61 #include "winnls.h"
62 #include "commctrl.h"
63 #include "prsht.h"
64 #include "comctl32.h"
65 #include "uxtheme.h"
67 #include "wine/debug.h"
68 #include "wine/unicode.h"
70 /******************************************************************************
71 * Data structures
73 #include "pshpack2.h"
75 typedef struct
77 WORD dlgVer;
78 WORD signature;
79 DWORD helpID;
80 DWORD exStyle;
81 DWORD style;
82 } MyDLGTEMPLATEEX;
84 typedef struct
86 DWORD helpid;
87 DWORD exStyle;
88 DWORD style;
89 short x;
90 short y;
91 short cx;
92 short cy;
93 DWORD id;
94 } MyDLGITEMTEMPLATEEX;
95 #include "poppack.h"
97 typedef struct tagPropPageInfo
99 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
100 HWND hwndPage;
101 BOOL isDirty;
102 LPCWSTR pszText;
103 BOOL hasHelp;
104 BOOL useCallback;
105 BOOL hasIcon;
106 } PropPageInfo;
108 typedef struct tagPropSheetInfo
110 HWND hwnd;
111 PROPSHEETHEADERW ppshheader;
112 BOOL unicode;
113 LPWSTR strPropertiesFor;
114 int nPages;
115 int active_page;
116 BOOL isModeless;
117 BOOL hasHelp;
118 BOOL hasApply;
119 BOOL hasFinish;
120 BOOL usePropPage;
121 BOOL useCallback;
122 BOOL activeValid;
123 PropPageInfo* proppage;
124 HFONT hFont;
125 HFONT hFontBold;
126 int width;
127 int height;
128 HIMAGELIST hImageList;
129 BOOL ended;
130 INT result;
131 } PropSheetInfo;
133 typedef struct
135 int x;
136 int y;
137 } PADDING_INFO;
139 /******************************************************************************
140 * Defines and global variables
143 static const WCHAR PropSheetInfoStr[] =
144 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
146 #define PSP_INTERNAL_UNICODE 0x80000000
148 #define MAX_CAPTION_LENGTH 255
149 #define MAX_TABTEXT_LENGTH 255
150 #define MAX_BUTTONTEXT_LENGTH 64
152 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
154 /* Wizard metrics specified in DLUs */
155 #define WIZARD_PADDING 7
156 #define WIZARD_HEADER_HEIGHT 36
158 /******************************************************************************
159 * Prototypes
161 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
162 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
163 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
164 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
165 int index,
166 int skipdir,
167 HPROPSHEETPAGE hpage);
168 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo, int original_index);
169 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
170 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
171 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
173 static INT_PTR CALLBACK
174 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
176 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
178 static WCHAR *heap_strdupW(const WCHAR *str)
180 int len = strlenW(str) + 1;
181 WCHAR *ret = Alloc(len * sizeof(WCHAR));
182 strcpyW(ret, str);
183 return ret;
186 static WCHAR *heap_strdupAtoW(const char *str)
188 WCHAR *ret;
189 INT len;
191 len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
192 ret = Alloc(len * sizeof(WCHAR));
193 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
195 return ret;
198 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
199 /******************************************************************************
200 * PROPSHEET_UnImplementedFlags
202 * Document use of flags we don't implement yet.
204 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
206 CHAR string[256];
208 string[0] = '\0';
211 * unhandled header flags:
212 * PSH_RTLREADING 0x00000800
213 * PSH_STRETCHWATERMARK 0x00040000
214 * PSH_USEPAGELANG 0x00200000
217 add_flag(PSH_RTLREADING);
218 add_flag(PSH_STRETCHWATERMARK);
219 add_flag(PSH_USEPAGELANG);
220 if (string[0] != '\0')
221 FIXME("%s\n", string);
223 #undef add_flag
225 /******************************************************************************
226 * PROPSHEET_GetPageRect
228 * Retrieve rect from tab control and map into the dialog for SetWindowPos
230 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
231 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
233 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
234 HWND hwndChild;
235 RECT r;
237 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
238 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
239 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
240 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
242 rc->left = rc->top = WIZARD_PADDING;
244 else
246 rc->left = rc->top = 0;
248 rc->right = psInfo->width - rc->left;
249 rc->bottom = psInfo->height - rc->top;
250 MapDialogRect(hwndDlg, rc);
252 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
253 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
254 !(ppshpage->dwFlags & PSP_HIDEHEADER))
256 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
257 GetClientRect(hwndChild, &r);
258 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
259 rc->top += r.bottom + 1;
261 } else {
262 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
263 GetClientRect(hwndTabCtrl, rc);
264 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
265 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
269 /******************************************************************************
270 * PROPSHEET_FindPageByResId
272 * Find page index corresponding to page resource id.
274 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
276 INT i;
278 for (i = 0; i < psInfo->nPages; i++)
280 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
282 /* Fixme: if resource ID is a string shall we use strcmp ??? */
283 if (lppsp->u.pszTemplate == (LPVOID)resId)
284 break;
287 return i;
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))
378 psInfo->ppshheader.pszCaption = heap_strdupW( lppsh->pszCaption );
380 psInfo->nPages = lppsh->nPages;
382 if (dwFlags & PSH_USEPSTARTPAGE)
384 TRACE("PSH_USEPSTARTPAGE is on\n");
385 psInfo->active_page = 0;
387 else
388 psInfo->active_page = lppsh->u2.nStartPage;
390 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
393 /******************************************************************************
394 * PROPSHEET_CollectPageInfo
396 * Collect property sheet data.
397 * With code taken from DIALOG_ParseTemplate32.
399 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
400 PropSheetInfo * psInfo,
401 int index, BOOL resize)
403 const DLGTEMPLATE* pTemplate;
404 const WORD* p;
405 DWORD dwFlags;
406 int width, height;
408 if (!lppsp)
409 return FALSE;
411 TRACE("\n");
412 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
413 psInfo->proppage[index].hwndPage = 0;
414 psInfo->proppage[index].isDirty = FALSE;
417 * Process property page flags.
419 dwFlags = lppsp->dwFlags;
420 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
421 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
422 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
424 /* as soon as we have a page with the help flag, set the sheet flag on */
425 if (psInfo->proppage[index].hasHelp)
426 psInfo->hasHelp = TRUE;
429 * Process page template.
431 if (dwFlags & PSP_DLGINDIRECT)
432 pTemplate = lppsp->u.pResource;
433 else if(dwFlags & PSP_INTERNAL_UNICODE )
435 HRSRC hResource = FindResourceW(lppsp->hInstance,
436 lppsp->u.pszTemplate,
437 (LPWSTR)RT_DIALOG);
438 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
439 hResource);
440 pTemplate = LockResource(hTemplate);
442 else
444 HRSRC hResource = FindResourceA(lppsp->hInstance,
445 (LPCSTR)lppsp->u.pszTemplate,
446 (LPSTR)RT_DIALOG);
447 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
448 hResource);
449 pTemplate = LockResource(hTemplate);
453 * Extract the size of the page and the caption.
455 if (!pTemplate)
456 return FALSE;
458 p = (const WORD *)pTemplate;
460 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
462 /* DLGTEMPLATEEX (not defined in any std. header file) */
464 p++; /* dlgVer */
465 p++; /* signature */
466 p += 2; /* help ID */
467 p += 2; /* ext style */
468 p += 2; /* style */
470 else
472 /* DLGTEMPLATE */
474 p += 2; /* style */
475 p += 2; /* ext style */
478 p++; /* nb items */
479 p++; /* x */
480 p++; /* y */
481 width = (WORD)*p; p++;
482 height = (WORD)*p; p++;
484 if (lppsp->dwFlags & (PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE))
485 psInfo->ppshheader.dwFlags |= PSH_HEADER;
487 /* Special calculation for interior wizard pages so the largest page is
488 * calculated correctly. We need to add all the padding and space occupied
489 * by the header so the width and height sums up to the whole wizard client
490 * area. */
491 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
492 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
493 !(dwFlags & PSP_HIDEHEADER))
495 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
496 width += 2 * WIZARD_PADDING;
498 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
500 height += 2 * WIZARD_PADDING;
501 width += 2 * WIZARD_PADDING;
504 /* remember the largest width and height */
505 if (resize)
507 if (width > psInfo->width)
508 psInfo->width = width;
510 if (height > psInfo->height)
511 psInfo->height = height;
514 /* menu */
515 switch ((WORD)*p)
517 case 0x0000:
518 p++;
519 break;
520 case 0xffff:
521 p += 2;
522 break;
523 default:
524 p += lstrlenW( p ) + 1;
525 break;
528 /* class */
529 switch ((WORD)*p)
531 case 0x0000:
532 p++;
533 break;
534 case 0xffff:
535 p += 2;
536 break;
537 default:
538 p += lstrlenW( p ) + 1;
539 break;
542 /* Extract the caption */
543 psInfo->proppage[index].pszText = p;
544 TRACE("Tab %d %s\n",index,debugstr_w( p ));
546 if (dwFlags & PSP_USETITLE)
548 WCHAR szTitle[256];
549 const WCHAR *pTitle;
550 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
552 if (IS_INTRESOURCE( lppsp->pszTitle ))
554 if (LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle, szTitle, ARRAY_SIZE(szTitle)))
555 pTitle = szTitle;
556 else if (*p)
557 pTitle = p;
558 else
559 pTitle = pszNull;
561 else
562 pTitle = lppsp->pszTitle;
564 psInfo->proppage[index].pszText = heap_strdupW( pTitle );
568 * Build the image list for icons
570 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
572 HICON hIcon;
573 int icon_cx = GetSystemMetrics(SM_CXSMICON);
574 int icon_cy = GetSystemMetrics(SM_CYSMICON);
576 if (dwFlags & PSP_USEICONID)
577 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
578 icon_cx, icon_cy, LR_DEFAULTCOLOR);
579 else
580 hIcon = lppsp->u2.hIcon;
582 if ( hIcon )
584 if (psInfo->hImageList == 0 )
585 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
587 ImageList_AddIcon(psInfo->hImageList, hIcon);
592 return TRUE;
595 /******************************************************************************
596 * PROPSHEET_CreateDialog
598 * Creates the actual property sheet.
600 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
602 LRESULT ret;
603 LPCVOID template;
604 LPVOID temp = 0;
605 HRSRC hRes;
606 DWORD resSize;
607 WORD resID = IDD_PROPSHEET;
609 TRACE("(%p)\n", psInfo);
610 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
611 resID = IDD_WIZARD;
613 if( psInfo->unicode )
615 if(!(hRes = FindResourceW(COMCTL32_hModule,
616 MAKEINTRESOURCEW(resID),
617 (LPWSTR)RT_DIALOG)))
618 return -1;
620 else
622 if(!(hRes = FindResourceA(COMCTL32_hModule,
623 MAKEINTRESOURCEA(resID),
624 (LPSTR)RT_DIALOG)))
625 return -1;
628 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
629 return -1;
632 * Make a copy of the dialog template.
634 resSize = SizeofResource(COMCTL32_hModule, hRes);
636 temp = Alloc(2 * resSize);
638 if (!temp)
639 return -1;
641 memcpy(temp, template, resSize);
643 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
645 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
646 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
647 else
648 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
650 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
651 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
653 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
654 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
655 else
656 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
659 if (psInfo->useCallback)
660 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
662 /* NOTE: MSDN states "Returns a positive value if successful, or -1
663 * otherwise for modal property sheets.", but this is wrong. The
664 * actual return value is either TRUE (success), FALSE (cancel) or
665 * -1 (error). */
666 if( psInfo->unicode )
668 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
669 temp, psInfo->ppshheader.hwndParent,
670 PROPSHEET_DialogProc, (LPARAM)psInfo);
671 if ( !ret ) ret = -1;
673 else
675 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
676 temp, psInfo->ppshheader.hwndParent,
677 PROPSHEET_DialogProc, (LPARAM)psInfo);
678 if ( !ret ) ret = -1;
681 Free(temp);
683 return ret;
686 /******************************************************************************
687 * PROPSHEET_SizeMismatch
689 * Verify that the tab control and the "largest" property sheet page dlg. template
690 * match in size.
692 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
694 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
695 RECT rcOrigTab, rcPage;
698 * Original tab size.
700 GetClientRect(hwndTabCtrl, &rcOrigTab);
701 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
704 * Biggest page size.
706 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
707 MapDialogRect(hwndDlg, &rcPage);
708 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
710 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
711 return TRUE;
712 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
713 return TRUE;
715 return FALSE;
718 /******************************************************************************
719 * PROPSHEET_AdjustSize
721 * Resizes the property sheet and the tab control to fit the largest page.
723 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
725 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
726 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
727 RECT rc,tabRect;
728 int buttonHeight;
729 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
730 RECT units;
731 LONG style;
733 /* Get the height of buttons */
734 GetClientRect(hwndButton, &rc);
735 buttonHeight = rc.bottom;
738 * Biggest page size.
740 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
741 MapDialogRect(hwndDlg, &rc);
743 /* retrieve the dialog units */
744 units.left = units.right = 4;
745 units.top = units.bottom = 8;
746 MapDialogRect(hwndDlg, &units);
749 * Resize the tab control.
751 GetClientRect(hwndTabCtrl,&tabRect);
753 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
755 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
757 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
758 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
761 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
763 rc.right = rc.left + tabRect.right - tabRect.left;
764 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
767 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
769 rc.right -= rc.left;
770 rc.bottom -= rc.top;
771 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
772 hwndTabCtrl, rc.right, rc.bottom);
773 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
774 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
776 GetClientRect(hwndTabCtrl, &rc);
778 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
780 rc.right += (padding.x * 2);
781 rc.bottom += buttonHeight + (3 * padding.y);
783 style = GetWindowLongW(hwndDlg, GWL_STYLE);
784 if (!(style & WS_CHILD))
785 AdjustWindowRect(&rc, style, FALSE);
787 rc.right -= rc.left;
788 rc.bottom -= rc.top;
791 * Resize the property sheet.
793 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
794 hwndDlg, rc.right, rc.bottom);
795 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
796 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
797 return TRUE;
800 /******************************************************************************
801 * PROPSHEET_AdjustSizeWizard
803 * Resizes the property sheet to fit the largest page.
805 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
807 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
808 RECT rc, lineRect, dialogRect;
810 /* Biggest page size */
811 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
812 MapDialogRect(hwndDlg, &rc);
814 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
816 /* Add space for the buttons row */
817 GetWindowRect(hwndLine, &lineRect);
818 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
819 GetClientRect(hwndDlg, &dialogRect);
820 rc.bottom += dialogRect.bottom - lineRect.top - 1;
822 /* Convert the client coordinates to window coordinates */
823 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
825 /* Resize the property sheet */
826 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
827 hwndDlg, rc.right, rc.bottom);
828 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
829 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
831 return TRUE;
834 /******************************************************************************
835 * PROPSHEET_AdjustButtons
837 * Adjusts the buttons' positions.
839 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
841 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
842 RECT rcSheet;
843 int x, y;
844 int num_buttons = 2;
845 int buttonWidth, buttonHeight;
846 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
848 if (psInfo->hasApply)
849 num_buttons++;
851 if (psInfo->hasHelp)
852 num_buttons++;
855 * Obtain the size of the buttons.
857 GetClientRect(hwndButton, &rcSheet);
858 buttonWidth = rcSheet.right;
859 buttonHeight = rcSheet.bottom;
862 * Get the size of the property sheet.
864 GetClientRect(hwndParent, &rcSheet);
867 * All buttons will be at this y coordinate.
869 y = rcSheet.bottom - (padding.y + buttonHeight);
872 * Position OK button and make it default.
874 hwndButton = GetDlgItem(hwndParent, IDOK);
876 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
878 SetWindowPos(hwndButton, 0, x, y, 0, 0,
879 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
881 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
885 * Position Cancel button.
887 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
889 x += padding.x + buttonWidth;
891 SetWindowPos(hwndButton, 0, x, y, 0, 0,
892 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
895 * Position Apply button.
897 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
899 if(psInfo->hasApply)
900 x += padding.x + buttonWidth;
901 else
902 ShowWindow(hwndButton, SW_HIDE);
904 SetWindowPos(hwndButton, 0, x, y, 0, 0,
905 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
906 EnableWindow(hwndButton, FALSE);
909 * Position Help button.
911 hwndButton = GetDlgItem(hwndParent, IDHELP);
913 x += padding.x + buttonWidth;
914 SetWindowPos(hwndButton, 0, x, y, 0, 0,
915 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
917 if(!psInfo->hasHelp)
918 ShowWindow(hwndButton, SW_HIDE);
920 return TRUE;
923 /******************************************************************************
924 * PROPSHEET_AdjustButtonsWizard
926 * Adjusts the buttons' positions.
928 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
929 const PropSheetInfo* psInfo)
931 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
932 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
933 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
934 RECT rcSheet;
935 int x, y;
936 int num_buttons = 3;
937 int buttonWidth, buttonHeight, lineHeight, lineWidth;
938 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
940 if (psInfo->hasHelp)
941 num_buttons++;
942 if (psInfo->hasFinish)
943 num_buttons++;
946 * Obtain the size of the buttons.
948 GetClientRect(hwndButton, &rcSheet);
949 buttonWidth = rcSheet.right;
950 buttonHeight = rcSheet.bottom;
952 GetClientRect(hwndLine, &rcSheet);
953 lineHeight = rcSheet.bottom;
956 * Get the size of the property sheet.
958 GetClientRect(hwndParent, &rcSheet);
961 * All buttons will be at this y coordinate.
963 y = rcSheet.bottom - (padding.y + buttonHeight);
966 * Position the Back button.
968 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
970 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
972 SetWindowPos(hwndButton, 0, x, y, 0, 0,
973 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
976 * Position the Next button.
978 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
980 x += buttonWidth;
982 SetWindowPos(hwndButton, 0, x, y, 0, 0,
983 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
986 * Position the Finish button.
988 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
990 if (psInfo->hasFinish)
991 x += padding.x + buttonWidth;
993 SetWindowPos(hwndButton, 0, x, y, 0, 0,
994 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
996 if (!psInfo->hasFinish)
997 ShowWindow(hwndButton, SW_HIDE);
1000 * Position the Cancel button.
1002 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1004 x += padding.x + buttonWidth;
1006 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1007 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1010 * Position Help button.
1012 hwndButton = GetDlgItem(hwndParent, IDHELP);
1014 if (psInfo->hasHelp)
1016 x += padding.x + buttonWidth;
1018 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1019 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1021 else
1022 ShowWindow(hwndButton, SW_HIDE);
1024 if (psInfo->ppshheader.dwFlags &
1025 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1026 padding.x = 0;
1029 * Position and resize the sunken line.
1031 x = padding.x;
1032 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1034 lineWidth = rcSheet.right - (padding.x * 2);
1035 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1036 SWP_NOZORDER | SWP_NOACTIVATE);
1039 * Position and resize the header sunken line.
1042 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1043 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1044 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1045 ShowWindow(hwndLineHeader, SW_HIDE);
1047 return TRUE;
1050 /******************************************************************************
1051 * PROPSHEET_GetPaddingInfo
1053 * Returns the layout information.
1055 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1057 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1058 RECT rcTab;
1059 PADDING_INFO padding;
1061 GetWindowRect(hwndTab, &rcTab);
1062 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1064 padding.x = rcTab.left;
1065 padding.y = rcTab.top;
1067 return padding;
1070 /******************************************************************************
1071 * PROPSHEET_GetPaddingInfoWizard
1073 * Returns the layout information.
1074 * Vertical spacing is the distance between the line and the buttons.
1075 * Do NOT use the Help button to gather padding information when it isn't mapped
1076 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1077 * for it in this case !
1078 * FIXME: I'm not sure about any other coordinate problems with these evil
1079 * buttons. Fix it in case additional problems appear or maybe calculate
1080 * a padding in a completely different way, as this is somewhat messy.
1082 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1083 psInfo)
1085 PADDING_INFO padding;
1086 RECT rc;
1087 HWND hwndControl;
1088 INT idButton;
1089 POINT ptButton, ptLine;
1091 TRACE("\n");
1092 if (psInfo->hasHelp)
1094 idButton = IDHELP;
1096 else
1098 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1100 idButton = IDC_NEXT_BUTTON;
1102 else
1104 /* hopefully this is ok */
1105 idButton = IDCANCEL;
1109 hwndControl = GetDlgItem(hwndDlg, idButton);
1110 GetWindowRect(hwndControl, &rc);
1111 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1112 ptButton.x = rc.left;
1113 ptButton.y = rc.top;
1115 /* Line */
1116 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1117 GetWindowRect(hwndControl, &rc);
1118 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1119 ptLine.x = rc.left;
1120 ptLine.y = rc.bottom;
1122 padding.y = ptButton.y - ptLine.y;
1124 if (padding.y < 0)
1125 ERR("padding negative ! Please report this !\n");
1127 /* this is most probably not correct, but the best we have now */
1128 padding.x = padding.y;
1129 return padding;
1132 /******************************************************************************
1133 * PROPSHEET_CreateTabControl
1135 * Insert the tabs in the tab control.
1137 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1138 const PropSheetInfo * psInfo)
1140 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1141 TCITEMW item;
1142 int i, nTabs;
1143 int iImage = 0;
1145 TRACE("\n");
1146 item.mask = TCIF_TEXT;
1147 item.cchTextMax = MAX_TABTEXT_LENGTH;
1149 nTabs = psInfo->nPages;
1152 * Set the image list for icons.
1154 if (psInfo->hImageList)
1156 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1159 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1160 for (i = 0; i < nTabs; i++)
1162 if ( psInfo->proppage[i].hasIcon )
1164 item.mask |= TCIF_IMAGE;
1165 item.iImage = iImage++;
1167 else
1169 item.mask &= ~TCIF_IMAGE;
1172 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1173 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1175 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1177 return TRUE;
1180 /******************************************************************************
1181 * PROPSHEET_WizardSubclassProc
1183 * Subclassing window procedure for wizard exterior pages to prevent drawing
1184 * background and so drawing above the watermark.
1186 static LRESULT CALLBACK
1187 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1189 switch (uMsg)
1191 case WM_ERASEBKGND:
1192 return TRUE;
1194 case WM_CTLCOLORSTATIC:
1195 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1196 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1199 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1203 * Get the size of an in-memory Template
1205 *( Based on the code of PROPSHEET_CollectPageInfo)
1206 * See also dialog.c/DIALOG_ParseTemplate32().
1209 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1212 const WORD* p = (const WORD *)pTemplate;
1213 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1214 WORD nrofitems;
1215 UINT ret;
1217 if (istemplateex)
1219 /* DLGTEMPLATEEX (not defined in any std. header file) */
1221 TRACE("is DLGTEMPLATEEX\n");
1222 p++; /* dlgVer */
1223 p++; /* signature */
1224 p += 2; /* help ID */
1225 p += 2; /* ext style */
1226 p += 2; /* style */
1228 else
1230 /* DLGTEMPLATE */
1232 TRACE("is DLGTEMPLATE\n");
1233 p += 2; /* style */
1234 p += 2; /* ext style */
1237 nrofitems = (WORD)*p; p++; /* nb items */
1238 p++; /* x */
1239 p++; /* y */
1240 p++; /* width */
1241 p++; /* height */
1243 /* menu */
1244 switch ((WORD)*p)
1246 case 0x0000:
1247 p++;
1248 break;
1249 case 0xffff:
1250 p += 2;
1251 break;
1252 default:
1253 TRACE("menu %s\n",debugstr_w( p ));
1254 p += lstrlenW( p ) + 1;
1255 break;
1258 /* class */
1259 switch ((WORD)*p)
1261 case 0x0000:
1262 p++;
1263 break;
1264 case 0xffff:
1265 p += 2; /* 0xffff plus predefined window class ordinal value */
1266 break;
1267 default:
1268 TRACE("class %s\n",debugstr_w( p ));
1269 p += lstrlenW( p ) + 1;
1270 break;
1273 /* title */
1274 TRACE("title %s\n",debugstr_w( p ));
1275 p += lstrlenW( p ) + 1;
1277 /* font, if DS_SETFONT set */
1278 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1279 pTemplate->style)))
1281 p+=(istemplateex)?3:1;
1282 TRACE("font %s\n",debugstr_w( p ));
1283 p += lstrlenW( p ) + 1; /* the font name */
1286 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1287 * that are following the DLGTEMPLATE(EX) data */
1288 TRACE("%d items\n",nrofitems);
1289 while (nrofitems > 0)
1291 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1293 /* skip header */
1294 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1296 /* check class */
1297 switch ((WORD)*p)
1299 case 0x0000:
1300 p++;
1301 break;
1302 case 0xffff:
1303 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1304 p += 2;
1305 break;
1306 default:
1307 TRACE("class %s\n",debugstr_w( p ));
1308 p += lstrlenW( p ) + 1;
1309 break;
1312 /* check title text */
1313 switch ((WORD)*p)
1315 case 0x0000:
1316 p++;
1317 break;
1318 case 0xffff:
1319 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1320 p += 2;
1321 break;
1322 default:
1323 TRACE("text %s\n",debugstr_w( p ));
1324 p += lstrlenW( p ) + 1;
1325 break;
1327 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1328 --nrofitems;
1331 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1332 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1333 return ret;
1336 /******************************************************************************
1337 * PROPSHEET_CreatePage
1339 * Creates a page.
1341 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1342 int index,
1343 const PropSheetInfo * psInfo,
1344 LPCPROPSHEETPAGEW ppshpage)
1346 const DLGTEMPLATE* pTemplate;
1347 HWND hwndPage;
1348 DWORD resSize;
1349 DLGTEMPLATE* pTemplateCopy = NULL;
1351 TRACE("index %d\n", index);
1353 if (ppshpage == NULL)
1355 return FALSE;
1358 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1360 pTemplate = ppshpage->u.pResource;
1361 resSize = GetTemplateSize(pTemplate);
1363 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1365 HRSRC hResource;
1366 HANDLE hTemplate;
1368 hResource = FindResourceW(ppshpage->hInstance,
1369 ppshpage->u.pszTemplate,
1370 (LPWSTR)RT_DIALOG);
1371 if(!hResource)
1372 return FALSE;
1374 resSize = SizeofResource(ppshpage->hInstance, hResource);
1376 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1377 if(!hTemplate)
1378 return FALSE;
1380 pTemplate = LockResource(hTemplate);
1382 * Make a copy of the dialog template to make it writable
1385 else
1387 HRSRC hResource;
1388 HANDLE hTemplate;
1390 hResource = FindResourceA(ppshpage->hInstance,
1391 (LPCSTR)ppshpage->u.pszTemplate,
1392 (LPSTR)RT_DIALOG);
1393 if(!hResource)
1394 return FALSE;
1396 resSize = SizeofResource(ppshpage->hInstance, hResource);
1398 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1399 if(!hTemplate)
1400 return FALSE;
1402 pTemplate = LockResource(hTemplate);
1404 * Make a copy of the dialog template to make it writable
1407 pTemplateCopy = Alloc(resSize);
1408 if (!pTemplateCopy)
1409 return FALSE;
1411 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1412 memcpy(pTemplateCopy, pTemplate, resSize);
1414 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1416 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1417 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1418 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1419 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1420 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1421 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1422 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1423 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1425 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1427 else
1429 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1430 pTemplateCopy->style &= ~DS_MODALFRAME;
1431 pTemplateCopy->style &= ~WS_CAPTION;
1432 pTemplateCopy->style &= ~WS_SYSMENU;
1433 pTemplateCopy->style &= ~WS_POPUP;
1434 pTemplateCopy->style &= ~WS_DISABLED;
1435 pTemplateCopy->style &= ~WS_VISIBLE;
1436 pTemplateCopy->style &= ~WS_THICKFRAME;
1438 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1441 if (psInfo->proppage[index].useCallback)
1442 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1443 (LPPROPSHEETPAGEW)ppshpage);
1445 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1446 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1447 pTemplateCopy,
1448 hwndParent,
1449 ppshpage->pfnDlgProc,
1450 (LPARAM)ppshpage);
1451 else
1452 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1453 pTemplateCopy,
1454 hwndParent,
1455 ppshpage->pfnDlgProc,
1456 (LPARAM)ppshpage);
1457 /* Free a no more needed copy */
1458 Free(pTemplateCopy);
1460 if(!hwndPage)
1461 return FALSE;
1463 psInfo->proppage[index].hwndPage = hwndPage;
1465 /* Subclass exterior wizard pages */
1466 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1467 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1468 (ppshpage->dwFlags & PSP_HIDEHEADER))
1470 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1471 (DWORD_PTR)ppshpage);
1473 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1474 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1476 return TRUE;
1479 /******************************************************************************
1480 * PROPSHEET_LoadWizardBitmaps
1482 * Loads the watermark and header bitmaps for a wizard.
1484 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1486 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1488 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1489 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1490 considers hbmWatermark as valid. */
1491 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1492 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1494 psInfo->ppshheader.u4.hbmWatermark =
1495 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1498 /* Same behavior as for watermarks */
1499 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1500 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1502 psInfo->ppshheader.u5.hbmHeader =
1503 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1509 /******************************************************************************
1510 * PROPSHEET_ShowPage
1512 * Displays or creates the specified page.
1514 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1516 HWND hwndTabCtrl;
1517 HWND hwndLineHeader;
1518 HWND control;
1519 LPCPROPSHEETPAGEW ppshpage;
1521 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1522 if (index == psInfo->active_page)
1524 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1525 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1526 return TRUE;
1529 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1530 if (psInfo->proppage[index].hwndPage == 0)
1532 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1535 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1537 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1538 psInfo->proppage[index].pszText);
1540 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1541 if(control != NULL)
1542 SetFocus(control);
1545 if (psInfo->active_page != -1)
1546 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1548 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1550 /* Synchronize current selection with tab control
1551 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1552 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1553 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1555 psInfo->active_page = index;
1556 psInfo->activeValid = TRUE;
1558 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1560 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1561 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1563 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1564 ShowWindow(hwndLineHeader, SW_HIDE);
1565 else
1566 ShowWindow(hwndLineHeader, SW_SHOW);
1569 return TRUE;
1572 /******************************************************************************
1573 * PROPSHEET_Back
1575 static BOOL PROPSHEET_Back(HWND hwndDlg)
1577 PSHNOTIFY psn;
1578 HWND hwndPage;
1579 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1580 LRESULT result;
1581 int idx;
1583 TRACE("active_page %d\n", psInfo->active_page);
1584 if (psInfo->active_page < 0)
1585 return FALSE;
1587 psn.hdr.code = PSN_WIZBACK;
1588 psn.hdr.hwndFrom = hwndDlg;
1589 psn.hdr.idFrom = 0;
1590 psn.lParam = 0;
1592 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1594 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1595 if (result == -1)
1596 return FALSE;
1597 else if (result == 0)
1598 idx = psInfo->active_page - 1;
1599 else
1600 idx = PROPSHEET_FindPageByResId(psInfo, result);
1602 if (idx >= 0 && idx < psInfo->nPages)
1604 if (PROPSHEET_CanSetCurSel(hwndDlg))
1606 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1607 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1608 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1611 return TRUE;
1614 /******************************************************************************
1615 * PROPSHEET_Next
1617 static BOOL PROPSHEET_Next(HWND hwndDlg)
1619 PSHNOTIFY psn;
1620 HWND hwndPage;
1621 LRESULT msgResult = 0;
1622 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1623 int idx;
1625 TRACE("active_page %d\n", psInfo->active_page);
1626 if (psInfo->active_page < 0)
1627 return FALSE;
1629 psn.hdr.code = PSN_WIZNEXT;
1630 psn.hdr.hwndFrom = hwndDlg;
1631 psn.hdr.idFrom = 0;
1632 psn.lParam = 0;
1634 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1636 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1637 if (msgResult == -1)
1638 return FALSE;
1639 else if (msgResult == 0)
1640 idx = psInfo->active_page + 1;
1641 else
1642 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1644 if (idx < psInfo->nPages )
1646 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1648 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1649 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1650 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1654 return TRUE;
1657 /******************************************************************************
1658 * PROPSHEET_Finish
1660 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1662 PSHNOTIFY psn;
1663 HWND hwndPage;
1664 LRESULT msgResult = 0;
1665 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1667 TRACE("active_page %d\n", psInfo->active_page);
1668 if (psInfo->active_page < 0)
1669 return FALSE;
1671 psn.hdr.code = PSN_WIZFINISH;
1672 psn.hdr.hwndFrom = hwndDlg;
1673 psn.hdr.idFrom = 0;
1674 psn.lParam = 0;
1676 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1678 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1680 TRACE("msg result %ld\n", msgResult);
1682 if (msgResult != 0)
1683 return FALSE;
1685 if (psInfo->result == 0)
1686 psInfo->result = IDOK;
1687 if (psInfo->isModeless)
1688 psInfo->activeValid = FALSE;
1689 else
1690 psInfo->ended = TRUE;
1692 return TRUE;
1695 /******************************************************************************
1696 * PROPSHEET_Apply
1698 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1700 int i;
1701 HWND hwndPage;
1702 PSHNOTIFY psn;
1703 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1705 TRACE("active_page %d\n", psInfo->active_page);
1706 if (psInfo->active_page < 0)
1707 return FALSE;
1709 psn.hdr.hwndFrom = hwndDlg;
1710 psn.hdr.idFrom = 0;
1711 psn.lParam = 0;
1715 * Send PSN_KILLACTIVE to the current page.
1717 psn.hdr.code = PSN_KILLACTIVE;
1719 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1721 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1722 return FALSE;
1725 * Send PSN_APPLY to all pages.
1727 psn.hdr.code = PSN_APPLY;
1728 psn.lParam = lParam;
1730 for (i = 0; i < psInfo->nPages; i++)
1732 hwndPage = psInfo->proppage[i].hwndPage;
1733 if (hwndPage)
1735 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1737 case PSNRET_INVALID:
1738 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1739 /* fall through */
1740 case PSNRET_INVALID_NOCHANGEPAGE:
1741 return FALSE;
1746 if(lParam)
1748 psInfo->activeValid = FALSE;
1750 else if(psInfo->active_page >= 0)
1752 psn.hdr.code = PSN_SETACTIVE;
1753 psn.lParam = 0;
1754 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1755 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1758 return TRUE;
1761 /******************************************************************************
1762 * PROPSHEET_Cancel
1764 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1766 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1767 HWND hwndPage;
1768 PSHNOTIFY psn;
1769 int i;
1771 TRACE("active_page %d\n", psInfo->active_page);
1772 if (psInfo->active_page < 0)
1773 return;
1775 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1776 psn.hdr.code = PSN_QUERYCANCEL;
1777 psn.hdr.hwndFrom = hwndDlg;
1778 psn.hdr.idFrom = 0;
1779 psn.lParam = 0;
1781 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1782 return;
1784 psn.hdr.code = PSN_RESET;
1785 psn.lParam = lParam;
1787 for (i = 0; i < psInfo->nPages; i++)
1789 hwndPage = psInfo->proppage[i].hwndPage;
1791 if (hwndPage)
1792 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1795 if (psInfo->isModeless)
1797 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1798 psInfo->activeValid = FALSE;
1800 else
1801 psInfo->ended = TRUE;
1804 /******************************************************************************
1805 * PROPSHEET_Help
1807 static void PROPSHEET_Help(HWND hwndDlg)
1809 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1810 HWND hwndPage;
1811 PSHNOTIFY psn;
1813 TRACE("active_page %d\n", psInfo->active_page);
1814 if (psInfo->active_page < 0)
1815 return;
1817 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1818 psn.hdr.code = PSN_HELP;
1819 psn.hdr.hwndFrom = hwndDlg;
1820 psn.hdr.idFrom = 0;
1821 psn.lParam = 0;
1823 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1826 /******************************************************************************
1827 * PROPSHEET_Changed
1829 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1831 int i;
1832 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1834 TRACE("\n");
1835 if (!psInfo) return;
1837 * Set the dirty flag of this page.
1839 for (i = 0; i < psInfo->nPages; i++)
1841 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1842 psInfo->proppage[i].isDirty = TRUE;
1846 * Enable the Apply button.
1848 if (psInfo->hasApply)
1850 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1852 EnableWindow(hwndApplyBtn, TRUE);
1856 /******************************************************************************
1857 * PROPSHEET_UnChanged
1859 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1861 int i;
1862 BOOL noPageDirty = TRUE;
1863 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1864 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1866 TRACE("\n");
1867 if ( !psInfo ) return;
1868 for (i = 0; i < psInfo->nPages; i++)
1870 /* set the specified page as clean */
1871 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1872 psInfo->proppage[i].isDirty = FALSE;
1874 /* look to see if there are any dirty pages */
1875 if (psInfo->proppage[i].isDirty)
1876 noPageDirty = FALSE;
1880 * Disable Apply button.
1882 if (noPageDirty)
1883 EnableWindow(hwndApplyBtn, FALSE);
1886 /******************************************************************************
1887 * PROPSHEET_PressButton
1889 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1891 TRACE("buttonID %d\n", buttonID);
1892 switch (buttonID)
1894 case PSBTN_APPLYNOW:
1895 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1896 break;
1897 case PSBTN_BACK:
1898 PROPSHEET_Back(hwndDlg);
1899 break;
1900 case PSBTN_CANCEL:
1901 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1902 break;
1903 case PSBTN_FINISH:
1904 PROPSHEET_Finish(hwndDlg);
1905 break;
1906 case PSBTN_HELP:
1907 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1908 break;
1909 case PSBTN_NEXT:
1910 PROPSHEET_Next(hwndDlg);
1911 break;
1912 case PSBTN_OK:
1913 PROPSHEET_DoCommand(hwndDlg, IDOK);
1914 break;
1915 default:
1916 FIXME("Invalid button index %d\n", buttonID);
1921 /*************************************************************************
1922 * BOOL PROPSHEET_CanSetCurSel [Internal]
1924 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1926 * PARAMS
1927 * hwndDlg [I] handle to a Dialog hWnd
1929 * RETURNS
1930 * TRUE if Current Selection can change
1932 * NOTES
1934 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1936 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1937 HWND hwndPage;
1938 PSHNOTIFY psn;
1939 BOOL res = FALSE;
1941 if (!psInfo)
1943 res = FALSE;
1944 goto end;
1947 TRACE("active_page %d\n", psInfo->active_page);
1948 if (psInfo->active_page < 0)
1950 res = TRUE;
1951 goto end;
1955 * Notify the current page.
1957 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1958 psn.hdr.code = PSN_KILLACTIVE;
1959 psn.hdr.hwndFrom = hwndDlg;
1960 psn.hdr.idFrom = 0;
1961 psn.lParam = 0;
1963 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1965 end:
1966 TRACE("<-- %d\n", res);
1967 return res;
1970 /******************************************************************************
1971 * PROPSHEET_SetCurSel
1973 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1974 int index,
1975 int skipdir,
1976 HPROPSHEETPAGE hpage
1979 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1980 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1981 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1983 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1985 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1987 if (index < 0 || index >= psInfo->nPages)
1989 TRACE("Could not find page to select!\n");
1990 return FALSE;
1993 /* unset active page while doing this transition. */
1994 if (psInfo->active_page != -1)
1995 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1996 psInfo->active_page = -1;
1998 while (1) {
1999 int result;
2000 PSHNOTIFY psn;
2001 RECT rc;
2002 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2004 if (hwndTabControl)
2005 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2007 psn.hdr.code = PSN_SETACTIVE;
2008 psn.hdr.hwndFrom = hwndDlg;
2009 psn.hdr.idFrom = 0;
2010 psn.lParam = 0;
2012 if (!psInfo->proppage[index].hwndPage) {
2013 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2014 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2016 if (!psInfo->isModeless)
2018 DestroyWindow(hwndDlg);
2019 return FALSE;
2022 if(index >= psInfo->nPages)
2023 index--;
2024 if(index < 0)
2025 return FALSE;
2026 continue;
2030 /* Resize the property sheet page to the fit in the Tab control
2031 * (for regular property sheets) or to fit in the client area (for
2032 * wizards).
2033 * NOTE: The resizing happens every time the page is selected and
2034 * not only when it's created (some applications depend on it). */
2035 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2036 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2037 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2038 rc.right - rc.left, rc.bottom - rc.top);
2039 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2040 rc.left, rc.top,
2041 rc.right - rc.left, rc.bottom - rc.top, 0);
2043 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2044 if (!result)
2045 break;
2046 if (result == -1) {
2047 index+=skipdir;
2048 if (index < 0) {
2049 index = 0;
2050 WARN("Tried to skip before first property sheet page!\n");
2051 break;
2053 if (index >= psInfo->nPages) {
2054 WARN("Tried to skip after last property sheet page!\n");
2055 index = psInfo->nPages-1;
2056 break;
2059 else if (result != 0)
2061 int old_index = index;
2062 index = PROPSHEET_FindPageByResId(psInfo, result);
2063 if(index >= psInfo->nPages) {
2064 index = old_index;
2065 WARN("Tried to skip to nonexistent page by res id\n");
2066 break;
2068 continue;
2072 /* Invalidate the header area */
2073 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2074 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2076 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2077 RECT r;
2079 GetClientRect(hwndLineHeader, &r);
2080 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2081 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2083 InvalidateRect(hwndDlg, &r, TRUE);
2087 * Display the new page.
2089 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2091 if (psInfo->proppage[index].hasHelp)
2092 EnableWindow(hwndHelp, TRUE);
2093 else
2094 EnableWindow(hwndHelp, FALSE);
2096 return TRUE;
2099 /******************************************************************************
2100 * PROPSHEET_SetCurSelId
2102 * Selects the page, specified by resource id.
2104 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2106 int idx;
2107 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2109 idx = PROPSHEET_FindPageByResId(psInfo, id);
2110 if (idx < psInfo->nPages )
2112 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2113 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2117 /******************************************************************************
2118 * PROPSHEET_SetTitleA
2120 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2122 if(!IS_INTRESOURCE(lpszText))
2124 WCHAR szTitle[256];
2125 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTitle, ARRAY_SIZE(szTitle));
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, LOWORD(lpszText), szTitle, ARRAY_SIZE(szTitle)))
2145 return;
2146 lpszText = szTitle;
2148 if (dwStyle & PSH_PROPTITLE)
2150 WCHAR* dest;
2151 int lentitle = strlenW(lpszText);
2152 int lenprop = strlenW(psInfo->strPropertiesFor);
2154 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2155 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2157 SetWindowTextW(hwndDlg, dest);
2158 Free(dest);
2160 else
2161 SetWindowTextW(hwndDlg, lpszText);
2164 /******************************************************************************
2165 * PROPSHEET_SetFinishTextA
2167 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2169 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2170 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2172 TRACE("'%s'\n", lpszText);
2173 /* Set text, show and enable the Finish button */
2174 SetWindowTextA(hwndButton, lpszText);
2175 ShowWindow(hwndButton, SW_SHOW);
2176 EnableWindow(hwndButton, TRUE);
2178 /* Make it default pushbutton */
2179 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2181 /* Hide Back button */
2182 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2183 ShowWindow(hwndButton, SW_HIDE);
2185 if (!psInfo->hasFinish)
2187 /* Hide Next button */
2188 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2189 ShowWindow(hwndButton, SW_HIDE);
2193 /******************************************************************************
2194 * PROPSHEET_SetFinishTextW
2196 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2198 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2199 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2201 TRACE("%s\n", debugstr_w(lpszText));
2202 /* Set text, show and enable the Finish button */
2203 SetWindowTextW(hwndButton, lpszText);
2204 ShowWindow(hwndButton, SW_SHOW);
2205 EnableWindow(hwndButton, TRUE);
2207 /* Make it default pushbutton */
2208 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2210 /* Hide Back button */
2211 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2212 ShowWindow(hwndButton, SW_HIDE);
2214 if (!psInfo->hasFinish)
2216 /* Hide Next button */
2217 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2218 ShowWindow(hwndButton, SW_HIDE);
2222 /******************************************************************************
2223 * PROPSHEET_QuerySiblings
2225 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2226 WPARAM wParam, LPARAM lParam)
2228 int i = 0;
2229 HWND hwndPage;
2230 LRESULT msgResult = 0;
2231 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2233 while ((i < psInfo->nPages) && (msgResult == 0))
2235 hwndPage = psInfo->proppage[i].hwndPage;
2236 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2237 i++;
2240 return msgResult;
2243 /******************************************************************************
2244 * PROPSHEET_InsertPage
2246 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2248 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2249 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2250 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2251 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2252 TCITEMW item;
2253 int index;
2255 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2257 if (IS_INTRESOURCE(hpageInsertAfter))
2258 index = LOWORD(hpageInsertAfter);
2259 else
2261 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2262 if (index < 0)
2264 TRACE("Could not find page to insert after!\n");
2265 return FALSE;
2267 index++;
2270 if (index > psInfo->nPages)
2271 index = psInfo->nPages;
2273 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2274 if (!ppi)
2275 return FALSE;
2278 * Fill in a new PropPageInfo entry.
2280 if (index > 0)
2281 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2282 memset(&ppi[index], 0, sizeof(PropPageInfo));
2283 if (index < psInfo->nPages)
2284 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2285 psInfo->proppage = ppi;
2287 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
2289 psInfo->proppage = prev_ppi;
2290 Free(ppi);
2291 return FALSE;
2294 psInfo->proppage[index].hpage = hpage;
2296 if (ppsp->dwFlags & PSP_PREMATURE)
2298 /* Create the page but don't show it */
2299 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
2301 psInfo->proppage = prev_ppi;
2302 Free(ppi);
2303 return FALSE;
2307 Free(prev_ppi);
2308 psInfo->nPages++;
2309 if (index <= psInfo->active_page)
2310 psInfo->active_page++;
2313 * Add a new tab to the tab control.
2315 item.mask = TCIF_TEXT;
2316 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2317 item.cchTextMax = MAX_TABTEXT_LENGTH;
2319 if (psInfo->hImageList)
2320 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2322 if (psInfo->proppage[index].hasIcon)
2324 item.mask |= TCIF_IMAGE;
2325 item.iImage = index;
2328 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2330 /* If it is the only page - show it */
2331 if (psInfo->nPages == 1)
2332 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2334 return TRUE;
2337 /******************************************************************************
2338 * PROPSHEET_AddPage
2340 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2342 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2343 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2344 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2347 /******************************************************************************
2348 * PROPSHEET_RemovePage
2350 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2351 int index,
2352 HPROPSHEETPAGE hpage)
2354 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2355 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2356 PropPageInfo* oldPages;
2358 TRACE("index %d, hpage %p\n", index, hpage);
2359 if (!psInfo) {
2360 return FALSE;
2363 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2365 /* Make sure that index is within range */
2366 if (index < 0 || index >= psInfo->nPages)
2368 TRACE("Could not find page to remove!\n");
2369 return FALSE;
2372 TRACE("total pages %d removing page %d active page %d\n",
2373 psInfo->nPages, index, psInfo->active_page);
2375 * Check if we're removing the active page.
2377 if (index == psInfo->active_page)
2379 if (psInfo->nPages > 1)
2381 if (index > 0)
2383 /* activate previous page */
2384 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2386 else
2388 /* activate the next page */
2389 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2390 psInfo->active_page = index;
2393 else
2395 psInfo->active_page = -1;
2396 if (!psInfo->isModeless)
2398 psInfo->ended = TRUE;
2399 return TRUE;
2403 else if (index < psInfo->active_page)
2404 psInfo->active_page--;
2406 /* Unsubclass the page dialog window */
2407 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2408 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2409 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2411 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2412 PROPSHEET_WizardSubclassProc, 1);
2415 /* Destroy page dialog window */
2416 DestroyWindow(psInfo->proppage[index].hwndPage);
2418 /* Free page resources */
2419 if(psInfo->proppage[index].hpage)
2421 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2423 if (psp->dwFlags & PSP_USETITLE)
2424 Free ((LPVOID)psInfo->proppage[index].pszText);
2426 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2429 /* Remove the tab */
2430 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2432 oldPages = psInfo->proppage;
2433 psInfo->nPages--;
2434 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2436 if (index > 0)
2437 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2439 if (index < psInfo->nPages)
2440 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2441 (psInfo->nPages - index) * sizeof(PropPageInfo));
2443 Free(oldPages);
2445 return FALSE;
2448 /******************************************************************************
2449 * PROPSHEET_SetWizButtons
2451 * This code will work if (and assumes that) the Next button is on top of the
2452 * Finish button. ie. Finish comes after Next in the Z order.
2453 * This means make sure the dialog template reflects this.
2456 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2458 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2459 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2460 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2461 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2462 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2464 TRACE("%d\n", dwFlags);
2466 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2467 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2468 EnableWindow(hwndFinish, enable_finish);
2470 /* set the default pushbutton to an enabled button */
2471 if (enable_finish)
2472 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2473 else if (dwFlags & PSWIZB_NEXT)
2474 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2475 else if (dwFlags & PSWIZB_BACK)
2476 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2477 else
2478 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2480 if (!psInfo->hasFinish)
2482 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2484 /* Hide the Next button */
2485 ShowWindow(hwndNext, SW_HIDE);
2487 /* Show the Finish button */
2488 ShowWindow(hwndFinish, SW_SHOW);
2490 else
2492 /* Hide the Finish button */
2493 ShowWindow(hwndFinish, SW_HIDE);
2494 /* Show the Next button */
2495 ShowWindow(hwndNext, SW_SHOW);
2500 /******************************************************************************
2501 * PROPSHEET_SetHeaderTitleW
2503 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2505 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2506 PROPSHEETPAGEW *page;
2508 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2510 if (page_index >= psInfo->nPages)
2511 return;
2513 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2515 if (!IS_INTRESOURCE(page->pszHeaderTitle))
2516 Free((void *)page->pszHeaderTitle);
2518 page->pszHeaderTitle = heap_strdupW(title);
2519 page->dwFlags |= PSP_USEHEADERTITLE;
2522 /******************************************************************************
2523 * PROPSHEET_SetHeaderTitleA
2525 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2527 WCHAR *titleW;
2529 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2531 titleW = heap_strdupAtoW(title);
2532 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2533 Free(titleW);
2536 /******************************************************************************
2537 * PROPSHEET_SetHeaderSubTitleW
2539 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2541 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2542 PROPSHEETPAGEW *page;
2544 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2546 if (page_index >= psInfo->nPages)
2547 return;
2549 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2551 if (!IS_INTRESOURCE(page->pszHeaderSubTitle))
2552 Free((void *)page->pszHeaderSubTitle);
2554 page->pszHeaderSubTitle = heap_strdupW(subtitle);
2555 page->dwFlags |= PSP_USEHEADERSUBTITLE;
2558 /******************************************************************************
2559 * PROPSHEET_SetHeaderSubTitleA
2561 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2563 WCHAR *subtitleW;
2565 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2567 subtitleW = heap_strdupAtoW(subtitle);
2568 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2569 Free(subtitleW);
2572 /******************************************************************************
2573 * PROPSHEET_HwndToIndex
2575 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2577 int index;
2578 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2580 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2582 for (index = 0; index < psInfo->nPages; index++)
2583 if (psInfo->proppage[index].hwndPage == hPageDlg)
2584 return index;
2585 WARN("%p not found\n", hPageDlg);
2586 return -1;
2589 /******************************************************************************
2590 * PROPSHEET_IndexToHwnd
2592 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2594 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2595 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2596 if (!psInfo)
2597 return 0;
2598 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2599 WARN("%d out of range.\n", iPageIndex);
2600 return 0;
2602 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2605 /******************************************************************************
2606 * PROPSHEET_PageToIndex
2608 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2610 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2612 TRACE("(%p, %p)\n", hwndDlg, hPage);
2614 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2617 /******************************************************************************
2618 * PROPSHEET_IndexToPage
2620 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2622 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2623 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2624 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2625 WARN("%d out of range.\n", iPageIndex);
2626 return 0;
2628 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2631 /******************************************************************************
2632 * PROPSHEET_IdToIndex
2634 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2636 int index;
2637 LPCPROPSHEETPAGEW psp;
2638 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2639 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2640 for (index = 0; index < psInfo->nPages; index++) {
2641 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2642 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2643 return index;
2646 return -1;
2649 /******************************************************************************
2650 * PROPSHEET_IndexToId
2652 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2654 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2655 LPCPROPSHEETPAGEW psp;
2656 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2657 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2658 WARN("%d out of range.\n", iPageIndex);
2659 return 0;
2661 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2662 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2663 return 0;
2665 return (LRESULT)psp->u.pszTemplate;
2668 /******************************************************************************
2669 * PROPSHEET_GetResult
2671 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2673 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2674 return psInfo->result;
2677 /******************************************************************************
2678 * PROPSHEET_RecalcPageSizes
2680 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2682 FIXME("(%p): stub\n", hwndDlg);
2683 return FALSE;
2686 /******************************************************************************
2687 * PROPSHEET_GetPageIndex
2689 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2690 * the array of PropPageInfo. If page is not found original index is used
2691 * (page takes precedence over index).
2693 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2695 int index;
2697 TRACE("page %p index %d\n", page, original_index);
2699 for (index = 0; index < psInfo->nPages; index++)
2700 if (psInfo->proppage[index].hpage == page)
2701 return index;
2703 return original_index;
2706 /******************************************************************************
2707 * PROPSHEET_CleanUp
2709 static void PROPSHEET_CleanUp(HWND hwndDlg)
2711 int i;
2712 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2714 TRACE("\n");
2715 if (!psInfo) return;
2716 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2717 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2719 for (i = 0; i < psInfo->nPages; i++)
2721 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2723 /* Unsubclass the page dialog window */
2724 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2725 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2726 (psp->dwFlags & PSP_HIDEHEADER))
2728 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2729 PROPSHEET_WizardSubclassProc, 1);
2732 if(psInfo->proppage[i].hwndPage)
2733 DestroyWindow(psInfo->proppage[i].hwndPage);
2735 if(psp)
2737 if (psp->dwFlags & PSP_USETITLE)
2738 Free ((LPVOID)psInfo->proppage[i].pszText);
2740 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2744 DeleteObject(psInfo->hFont);
2745 DeleteObject(psInfo->hFontBold);
2746 /* If we created the bitmaps, destroy them */
2747 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2748 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2749 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2750 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2751 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2752 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2754 Free(psInfo->proppage);
2755 Free(psInfo->strPropertiesFor);
2756 ImageList_Destroy(psInfo->hImageList);
2758 GlobalFree(psInfo);
2761 static INT do_loop(const PropSheetInfo *psInfo)
2763 MSG msg;
2764 INT ret = 0;
2765 HWND hwnd = psInfo->hwnd;
2766 HWND parent = psInfo->ppshheader.hwndParent;
2768 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2770 if(ret == -1)
2771 break;
2773 if(!IsDialogMessageW(hwnd, &msg))
2775 TranslateMessage(&msg);
2776 DispatchMessageW(&msg);
2780 if(ret == 0)
2781 PostQuitMessage(msg.wParam);
2783 if(ret != -1)
2784 ret = psInfo->result;
2786 if(parent)
2787 EnableWindow(parent, TRUE);
2789 DestroyWindow(hwnd);
2790 return ret;
2793 /******************************************************************************
2794 * PROPSHEET_PropertySheet
2796 * Common code between PropertySheetA/W
2798 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2800 INT_PTR bRet = 0;
2801 HWND parent = NULL;
2802 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2803 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2805 psInfo->unicode = unicode;
2806 psInfo->ended = FALSE;
2808 if(!psInfo->isModeless)
2810 parent = psInfo->ppshheader.hwndParent;
2811 if (parent) EnableWindow(parent, FALSE);
2813 bRet = PROPSHEET_CreateDialog(psInfo);
2814 if(!psInfo->isModeless)
2815 bRet = do_loop(psInfo);
2816 return bRet;
2819 /******************************************************************************
2820 * PropertySheet (COMCTL32.@)
2821 * PropertySheetA (COMCTL32.@)
2823 * Creates a property sheet in the specified property sheet header.
2825 * RETURNS
2826 * Modal property sheets: Positive if successful or -1 otherwise.
2827 * Modeless property sheets: Property sheet handle.
2828 * Or:
2829 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2830 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2832 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2834 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2835 UINT i, n;
2836 const BYTE* pByte;
2838 TRACE("(%p)\n", lppsh);
2840 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2842 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2843 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2845 for (n = i = 0; i < lppsh->nPages; i++, n++)
2847 if (!psInfo->usePropPage)
2848 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2849 else
2851 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2852 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2855 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2856 psInfo, n, TRUE))
2858 if (psInfo->usePropPage)
2859 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2860 n--;
2861 psInfo->nPages--;
2865 return PROPSHEET_PropertySheet(psInfo, FALSE);
2868 /******************************************************************************
2869 * PropertySheetW (COMCTL32.@)
2871 * See PropertySheetA.
2873 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2875 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2876 UINT i, n;
2877 const BYTE* pByte;
2879 TRACE("(%p)\n", lppsh);
2881 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2883 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2884 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2886 for (n = i = 0; i < lppsh->nPages; i++, n++)
2888 if (!psInfo->usePropPage)
2889 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2890 else
2892 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2893 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2896 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2897 psInfo, n, TRUE))
2899 if (psInfo->usePropPage)
2900 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2901 n--;
2902 psInfo->nPages--;
2906 return PROPSHEET_PropertySheet(psInfo, TRUE);
2909 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2911 LPWSTR ret;
2913 if (IS_INTRESOURCE(str))
2915 HRSRC hrsrc;
2916 HGLOBAL hmem;
2917 WCHAR *ptr;
2918 WORD i, id = LOWORD(str);
2919 UINT len;
2921 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2922 return NULL;
2923 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2924 if (!(ptr = LockResource( hmem ))) return NULL;
2925 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2926 len = *ptr;
2927 if (!len) return NULL;
2928 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2929 if (ret)
2931 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2932 ret[len] = 0;
2935 else
2937 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2938 ret = Alloc( len );
2939 if (ret) memcpy( ret, str, len );
2941 return ret;
2945 /******************************************************************************
2946 * CreatePropertySheetPage (COMCTL32.@)
2947 * CreatePropertySheetPageA (COMCTL32.@)
2949 * Creates a new property sheet page.
2951 * RETURNS
2952 * Success: Handle to new property sheet page.
2953 * Failure: NULL.
2955 * NOTES
2956 * An application must use the PSM_ADDPAGE message to add the new page to
2957 * an existing property sheet.
2959 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2960 LPCPROPSHEETPAGEA lpPropSheetPage)
2962 PROPSHEETPAGEW *ppsp;
2964 if (lpPropSheetPage->dwSize < PROPSHEETPAGEA_V1_SIZE)
2965 return NULL;
2967 /* original data is used for callback notifications */
2968 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
2970 ppsp = Alloc(2 * sizeof(*ppsp));
2971 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2972 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2974 else
2976 ppsp = Alloc(sizeof(*ppsp));
2977 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2980 ppsp->dwFlags &= ~PSP_INTERNAL_UNICODE;
2982 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2984 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2986 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2987 char *template = Alloc( len );
2989 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2993 if (ppsp->dwFlags & PSP_USEICONID)
2995 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2996 ppsp->u2.pszIcon = heap_strdupAtoW( lpPropSheetPage->u2.pszIcon );
2999 if (ppsp->dwFlags & PSP_USETITLE)
3001 if (IS_INTRESOURCE( ppsp->pszTitle ))
3002 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3003 else
3004 ppsp->pszTitle = heap_strdupAtoW( lpPropSheetPage->pszTitle );
3006 else
3007 ppsp->pszTitle = NULL;
3009 if (ppsp->dwFlags & PSP_HIDEHEADER)
3010 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3012 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3014 if (IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3015 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3016 else
3017 ppsp->pszHeaderTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderTitle );
3019 else
3020 ppsp->pszHeaderTitle = NULL;
3022 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3024 if (IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3025 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3026 else
3027 ppsp->pszHeaderSubTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderSubTitle );
3029 else
3030 ppsp->pszHeaderSubTitle = NULL;
3032 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEA_V1_SIZE && ppsp->pfnCallback)
3033 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3035 return (HPROPSHEETPAGE)ppsp;
3038 /******************************************************************************
3039 * CreatePropertySheetPageW (COMCTL32.@)
3041 * See CreatePropertySheetA.
3043 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3045 PROPSHEETPAGEW *ppsp;
3047 if (lpPropSheetPage->dwSize < PROPSHEETPAGEW_V1_SIZE)
3048 return NULL;
3050 /* original data is used for callback notifications */
3051 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
3053 ppsp = Alloc(2 * sizeof(*ppsp));
3054 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3055 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3057 else
3059 ppsp = Alloc(sizeof(*ppsp));
3060 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3063 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3065 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3067 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3068 ppsp->u.pszTemplate = heap_strdupW( lpPropSheetPage->u.pszTemplate );
3071 if ( ppsp->dwFlags & PSP_USEICONID )
3073 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3074 ppsp->u2.pszIcon = heap_strdupW( lpPropSheetPage->u2.pszIcon );
3077 if (ppsp->dwFlags & PSP_USETITLE)
3078 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3079 else
3080 ppsp->pszTitle = NULL;
3082 if (ppsp->dwFlags & PSP_HIDEHEADER)
3083 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3085 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3086 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3087 else
3088 ppsp->pszHeaderTitle = NULL;
3090 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3091 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3092 else
3093 ppsp->pszHeaderSubTitle = NULL;
3095 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEW_V1_SIZE && ppsp->pfnCallback)
3096 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3098 return (HPROPSHEETPAGE)ppsp;
3101 /******************************************************************************
3102 * DestroyPropertySheetPage (COMCTL32.@)
3104 * Destroys a property sheet page previously created with
3105 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3106 * memory.
3108 * RETURNS
3109 * Success: TRUE
3110 * Failure: FALSE
3112 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3114 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3116 if (!psp)
3117 return FALSE;
3119 if ((psp->dwFlags & PSP_USECALLBACK) && psp->pfnCallback)
3120 psp->pfnCallback(0, PSPCB_RELEASE, psp + 1);
3122 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3123 Free ((LPVOID)psp->u.pszTemplate);
3125 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3126 Free ((LPVOID)psp->u2.pszIcon);
3128 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3129 Free ((LPVOID)psp->pszTitle);
3131 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3132 Free ((LPVOID)psp->pszHeaderTitle);
3134 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3135 Free ((LPVOID)psp->pszHeaderSubTitle);
3137 Free(hPropPage);
3139 return TRUE;
3142 /******************************************************************************
3143 * PROPSHEET_IsDialogMessage
3145 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3147 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3149 TRACE("\n");
3150 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3151 return FALSE;
3153 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3155 int new_page = 0;
3156 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3158 if (!(dlgCode & DLGC_WANTMESSAGE))
3160 switch (lpMsg->wParam)
3162 case VK_TAB:
3163 if (GetKeyState(VK_SHIFT) & 0x8000)
3164 new_page = -1;
3165 else
3166 new_page = 1;
3167 break;
3169 case VK_NEXT: new_page = 1; break;
3170 case VK_PRIOR: new_page = -1; break;
3174 if (new_page)
3176 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3178 new_page += psInfo->active_page;
3180 if (new_page < 0)
3181 new_page = psInfo->nPages - 1;
3182 else if (new_page >= psInfo->nPages)
3183 new_page = 0;
3185 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3188 return TRUE;
3192 return IsDialogMessageW(hwnd, lpMsg);
3195 /******************************************************************************
3196 * PROPSHEET_DoCommand
3198 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3201 switch (wID) {
3203 case IDOK:
3204 case IDC_APPLY_BUTTON:
3206 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3208 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3209 break;
3211 if (wID == IDOK)
3213 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3215 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3216 if (psInfo->result == 0)
3217 psInfo->result = IDOK;
3219 if (psInfo->isModeless)
3220 psInfo->activeValid = FALSE;
3221 else
3222 psInfo->ended = TRUE;
3224 else
3225 EnableWindow(hwndApplyBtn, FALSE);
3227 break;
3230 case IDC_BACK_BUTTON:
3231 PROPSHEET_Back(hwnd);
3232 break;
3234 case IDC_NEXT_BUTTON:
3235 PROPSHEET_Next(hwnd);
3236 break;
3238 case IDC_FINISH_BUTTON:
3239 PROPSHEET_Finish(hwnd);
3240 break;
3242 case IDCANCEL:
3243 PROPSHEET_Cancel(hwnd, 0);
3244 break;
3246 case IDHELP:
3247 PROPSHEET_Help(hwnd);
3248 break;
3250 default:
3251 return FALSE;
3254 return TRUE;
3257 /******************************************************************************
3258 * PROPSHEET_Paint
3260 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3262 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3263 PAINTSTRUCT ps;
3264 HDC hdc, hdcSrc;
3265 BITMAP bm;
3266 HBITMAP hbmp;
3267 HPALETTE hOldPal = 0;
3268 int offsety = 0;
3269 HBRUSH hbr;
3270 RECT r, rzone;
3271 LPCPROPSHEETPAGEW ppshpage;
3272 WCHAR szBuffer[256];
3273 int nLength;
3275 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3276 if (!hdc) return 1;
3278 hdcSrc = CreateCompatibleDC(0);
3280 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3281 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3283 if (psInfo->active_page < 0)
3284 ppshpage = NULL;
3285 else
3286 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3288 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3289 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3290 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3292 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3293 HFONT hOldFont;
3294 COLORREF clrOld = 0;
3295 int oldBkMode = 0;
3297 GetClientRect(hwndLineHeader, &r);
3298 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3299 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3301 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3303 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3305 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3307 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3308 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3310 /* Fill the unoccupied part of the header with color of the
3311 * left-top pixel, but do it only when needed.
3313 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3315 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3316 r = rzone;
3317 if (bm.bmWidth < r.right)
3319 r.left = bm.bmWidth;
3320 FillRect(hdc, &r, hbr);
3322 if (bm.bmHeight < r.bottom)
3324 r.left = 0;
3325 r.top = bm.bmHeight;
3326 FillRect(hdc, &r, hbr);
3328 DeleteObject(hbr);
3331 /* Draw the header itself. */
3332 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3333 hdcSrc, 0, 0, SRCCOPY);
3335 else
3337 int margin;
3338 hbr = GetSysColorBrush(COLOR_WINDOW);
3339 FillRect(hdc, &rzone, hbr);
3341 /* Draw the header bitmap. It's always centered like a
3342 * common 49 x 49 bitmap. */
3343 margin = (rzone.bottom - 49) / 2;
3344 BitBlt(hdc, rzone.right - 49 - margin, margin,
3345 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3346 hdcSrc, 0, 0, SRCCOPY);
3348 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3349 * if its height is smaller than 49 pixels. Because the reason
3350 * for this bug is unknown the current code doesn't try to
3351 * replicate it. */
3354 SelectObject(hdcSrc, hbmp);
3357 clrOld = SetTextColor (hdc, 0x00000000);
3358 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3360 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3361 SetRect(&r, 20, 10, 0, 0);
3362 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3363 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3364 else
3366 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3367 szBuffer, 256);
3368 if (nLength != 0)
3370 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3375 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3376 SelectObject(hdc, psInfo->hFont);
3377 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3378 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3379 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3380 else
3382 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3383 szBuffer, 256);
3384 if (nLength != 0)
3386 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3391 offsety = rzone.bottom + 2;
3393 SetTextColor(hdc, clrOld);
3394 SetBkMode(hdc, oldBkMode);
3395 SelectObject(hdc, hOldFont);
3398 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3399 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3400 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3402 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3404 GetClientRect(hwndLine, &r);
3405 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3406 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3408 hbr = GetSysColorBrush(COLOR_WINDOW);
3409 FillRect(hdc, &rzone, hbr);
3411 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3412 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3414 /* The watermark is truncated to a width of 164 pixels */
3415 r.right = min(r.right, 164);
3416 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3417 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3419 /* If the bitmap is not big enough, fill the remaining area
3420 with the color of pixel (0,0) of bitmap - see MSDN */
3421 if (r.top > bm.bmHeight) {
3422 r.bottom = r.top - 1;
3423 r.top = bm.bmHeight;
3424 r.left = 0;
3425 r.right = bm.bmWidth;
3426 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3427 FillRect(hdc, &r, hbr);
3428 DeleteObject(hbr);
3431 SelectObject(hdcSrc, hbmp);
3434 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3435 SelectPalette(hdc, hOldPal, FALSE);
3437 DeleteDC(hdcSrc);
3439 if (!hdcParam) EndPaint(hwnd, &ps);
3441 return 0;
3444 /******************************************************************************
3445 * PROPSHEET_DialogProc
3447 static INT_PTR CALLBACK
3448 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3450 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3451 hwnd, uMsg, wParam, lParam);
3453 switch (uMsg)
3455 case WM_INITDIALOG:
3457 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3458 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3459 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3460 int idx;
3461 LOGFONTW logFont;
3463 /* Using PropSheetInfoStr to store extra data doesn't match the native
3464 * common control: native uses TCM_[GS]ETITEM
3466 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3469 * psInfo->hwnd is not being used by WINE code - it exists
3470 * for compatibility with "real" Windoze. The same about
3471 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3472 * property.
3474 psInfo->hwnd = hwnd;
3475 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3477 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3479 /* set up the Next and Back buttons by default */
3480 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3483 /* Set up fonts */
3484 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3485 psInfo->hFont = CreateFontIndirectW (&logFont);
3486 logFont.lfWeight = FW_BOLD;
3487 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3490 * Small icon in the title bar.
3492 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3493 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3495 HICON hIcon;
3496 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3497 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3499 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3500 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3501 psInfo->ppshheader.u.pszIcon,
3502 IMAGE_ICON,
3503 icon_cx, icon_cy,
3504 LR_DEFAULTCOLOR);
3505 else
3506 hIcon = psInfo->ppshheader.u.hIcon;
3508 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3511 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3512 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3514 psInfo->strPropertiesFor = strCaption;
3516 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3518 PROPSHEET_CreateTabControl(hwnd, psInfo);
3520 PROPSHEET_LoadWizardBitmaps(psInfo);
3522 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3524 ShowWindow(hwndTabCtrl, SW_HIDE);
3525 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3526 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3527 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3529 else
3531 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3533 PROPSHEET_AdjustSize(hwnd, psInfo);
3534 PROPSHEET_AdjustButtons(hwnd, psInfo);
3536 SetFocus(GetDlgItem(hwnd, IDOK));
3539 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3540 psInfo->ppshheader.hInstance)
3542 WCHAR szText[256];
3544 if (LoadStringW(psInfo->ppshheader.hInstance,
3545 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3546 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3548 else
3550 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3551 psInfo->ppshheader.pszCaption);
3555 if (psInfo->useCallback)
3556 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3558 idx = psInfo->active_page;
3559 psInfo->active_page = -1;
3561 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3563 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3564 * as some programs call TCM_GETCURSEL to get the current selection
3565 * from which to switch to the next page */
3566 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3568 PROPSHEET_UnChanged(hwnd, NULL);
3570 /* wizards set their focus during init */
3571 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3572 return FALSE;
3574 return TRUE;
3577 case WM_PRINTCLIENT:
3578 case WM_PAINT:
3579 PROPSHEET_Paint(hwnd, (HDC)wParam);
3580 return TRUE;
3582 case WM_DESTROY:
3583 PROPSHEET_CleanUp(hwnd);
3584 return TRUE;
3586 case WM_CLOSE:
3587 PROPSHEET_Cancel(hwnd, 1);
3588 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3590 case WM_COMMAND:
3591 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3593 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3595 if (!psInfo)
3596 return FALSE;
3598 /* No default handler, forward notification to active page */
3599 if (psInfo->activeValid && psInfo->active_page != -1)
3601 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3602 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3605 return TRUE;
3607 case WM_NOTIFY:
3609 NMHDR* pnmh = (LPNMHDR) lParam;
3611 if (pnmh->code == TCN_SELCHANGE)
3613 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3614 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3617 if(pnmh->code == TCN_SELCHANGING)
3619 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3620 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3621 return TRUE;
3624 return FALSE;
3627 case WM_SYSCOLORCHANGE:
3628 COMCTL32_RefreshSysColors();
3629 return FALSE;
3631 case PSM_GETCURRENTPAGEHWND:
3633 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3634 HWND hwndPage = 0;
3636 if (!psInfo)
3637 return FALSE;
3639 if (psInfo->activeValid && psInfo->active_page != -1)
3640 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3642 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3644 return TRUE;
3647 case PSM_CHANGED:
3648 PROPSHEET_Changed(hwnd, (HWND)wParam);
3649 return TRUE;
3651 case PSM_UNCHANGED:
3652 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3653 return TRUE;
3655 case PSM_GETTABCONTROL:
3657 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3659 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3661 return TRUE;
3664 case PSM_SETCURSEL:
3666 BOOL msgResult;
3668 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3669 if(msgResult != FALSE)
3671 msgResult = PROPSHEET_SetCurSel(hwnd,
3672 (int)wParam,
3674 (HPROPSHEETPAGE)lParam);
3677 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3679 return TRUE;
3682 case PSM_CANCELTOCLOSE:
3684 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3685 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3686 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3688 EnableWindow(hwndCancel, FALSE);
3689 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, ARRAY_SIZE(buf)))
3690 SetWindowTextW(hwndOK, buf);
3692 return FALSE;
3695 case PSM_RESTARTWINDOWS:
3697 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3699 if (!psInfo)
3700 return FALSE;
3702 /* reboot system takes precedence over restart windows */
3703 if (psInfo->result != ID_PSREBOOTSYSTEM)
3704 psInfo->result = ID_PSRESTARTWINDOWS;
3706 return TRUE;
3709 case PSM_REBOOTSYSTEM:
3711 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3713 if (!psInfo)
3714 return FALSE;
3716 psInfo->result = ID_PSREBOOTSYSTEM;
3718 return TRUE;
3721 case PSM_SETTITLEA:
3722 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3723 return TRUE;
3725 case PSM_SETTITLEW:
3726 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3727 return TRUE;
3729 case PSM_APPLY:
3731 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3733 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3735 return TRUE;
3738 case PSM_QUERYSIBLINGS:
3740 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3742 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3744 return TRUE;
3747 case PSM_ADDPAGE:
3750 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3751 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3752 * on success or FALSE otherwise, as specified on MSDN Online.
3753 * Also see the MFC code for
3754 * CPropertySheet::AddPage(CPropertyPage* pPage).
3757 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3759 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3761 return TRUE;
3764 case PSM_REMOVEPAGE:
3765 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3766 return TRUE;
3768 case PSM_ISDIALOGMESSAGE:
3770 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3771 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3772 return TRUE;
3775 case PSM_PRESSBUTTON:
3776 PROPSHEET_PressButton(hwnd, (int)wParam);
3777 return TRUE;
3779 case PSM_SETFINISHTEXTA:
3780 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3781 return TRUE;
3783 case PSM_SETWIZBUTTONS:
3784 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3785 return TRUE;
3787 case PSM_SETCURSELID:
3788 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3789 return TRUE;
3791 case PSM_SETFINISHTEXTW:
3792 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3793 return FALSE;
3795 case PSM_INSERTPAGE:
3797 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3798 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3799 return TRUE;
3802 case PSM_SETHEADERTITLEW:
3803 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3804 return TRUE;
3806 case PSM_SETHEADERTITLEA:
3807 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3808 return TRUE;
3810 case PSM_SETHEADERSUBTITLEW:
3811 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3812 return TRUE;
3814 case PSM_SETHEADERSUBTITLEA:
3815 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3816 return TRUE;
3818 case PSM_HWNDTOINDEX:
3820 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3821 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3822 return TRUE;
3825 case PSM_INDEXTOHWND:
3827 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3828 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3829 return TRUE;
3832 case PSM_PAGETOINDEX:
3834 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3835 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3836 return TRUE;
3839 case PSM_INDEXTOPAGE:
3841 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3842 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3843 return TRUE;
3846 case PSM_IDTOINDEX:
3848 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3849 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3850 return TRUE;
3853 case PSM_INDEXTOID:
3855 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3856 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3857 return TRUE;
3860 case PSM_GETRESULT:
3862 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3863 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3864 return TRUE;
3867 case PSM_RECALCPAGESIZES:
3869 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3870 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3871 return TRUE;
3874 default:
3875 return FALSE;