dbghelp: Remove DMT_ entries for .DBG and .PDB files.
[wine.git] / dlls / comctl32 / propsheet.c
blobb530a1a80943f0909e48e304c7191a665d55aca0
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 #include "windef.h"
56 #include "winbase.h"
57 #include "wingdi.h"
58 #include "winuser.h"
59 #include "winnls.h"
60 #include "commctrl.h"
61 #include "prsht.h"
62 #include "comctl32.h"
63 #include "uxtheme.h"
65 #include "wine/debug.h"
67 #define HPROPSHEETPAGE_MAGIC 0x5A9234E3
69 /******************************************************************************
70 * Data structures
72 #include "pshpack2.h"
74 typedef struct
76 WORD dlgVer;
77 WORD signature;
78 DWORD helpID;
79 DWORD exStyle;
80 DWORD style;
81 } MyDLGTEMPLATEEX;
83 typedef struct
85 DWORD helpid;
86 DWORD exStyle;
87 DWORD style;
88 short x;
89 short y;
90 short cx;
91 short cy;
92 DWORD id;
93 } MyDLGITEMTEMPLATEEX;
94 #include "poppack.h"
96 struct _PSP
98 DWORD magic;
99 BOOL unicode;
100 union
102 PROPSHEETPAGEA pspA;
103 PROPSHEETPAGEW pspW;
104 BYTE data[1];
108 typedef struct tagPropPageInfo
110 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
111 HWND hwndPage;
112 BOOL isDirty;
113 LPCWSTR pszText;
114 BOOL hasHelp;
115 BOOL hasIcon;
116 } PropPageInfo;
118 typedef struct tagPropSheetInfo
120 HWND hwnd;
121 PROPSHEETHEADERW ppshheader;
122 BOOL unicode;
123 LPWSTR strPropertiesFor;
124 int nPages;
125 int active_page;
126 BOOL isModeless;
127 BOOL hasHelp;
128 BOOL hasApply;
129 BOOL hasFinish;
130 BOOL usePropPage;
131 BOOL useCallback;
132 BOOL activeValid;
133 PropPageInfo* proppage;
134 HFONT hFont;
135 HFONT hFontBold;
136 int width;
137 int height;
138 HIMAGELIST hImageList;
139 BOOL ended;
140 INT result;
141 } PropSheetInfo;
143 typedef struct
145 int x;
146 int y;
147 } PADDING_INFO;
149 /******************************************************************************
150 * Defines and global variables
153 static const WCHAR PropSheetInfoStr[] = L"PropertySheetInfo";
155 #define MAX_CAPTION_LENGTH 255
156 #define MAX_TABTEXT_LENGTH 255
157 #define MAX_BUTTONTEXT_LENGTH 64
159 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
161 /* Wizard metrics specified in DLUs */
162 #define WIZARD_PADDING 7
163 #define WIZARD_HEADER_HEIGHT 36
165 /******************************************************************************
166 * Prototypes
168 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
169 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
170 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
171 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
172 int index,
173 int skipdir,
174 HPROPSHEETPAGE hpage);
175 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo, int original_index);
176 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
177 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
178 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
180 static INT_PTR CALLBACK
181 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
183 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
185 static char *heap_strdupA(const char *str)
187 int len = strlen(str) + 1;
188 char *ret = Alloc(len);
189 return strcpy(ret, str);
192 static WCHAR *heap_strdupW(const WCHAR *str)
194 int len = lstrlenW(str) + 1;
195 WCHAR *ret = Alloc(len * sizeof(WCHAR));
196 lstrcpyW(ret, str);
197 return ret;
200 static WCHAR *heap_strdupAtoW(const char *str)
202 WCHAR *ret;
203 INT len;
205 len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
206 ret = Alloc(len * sizeof(WCHAR));
207 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
209 return ret;
212 static char *heap_strdupWtoA(const WCHAR *str)
214 char *ret;
215 INT len;
217 len = WideCharToMultiByte(CP_ACP, 0, str, -1, 0, 0, 0, 0);
218 ret = Alloc(len);
219 WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, 0, 0);
221 return ret;
225 * Get the size of an in-memory template
227 *( Based on the code of PROPSHEET_CollectPageInfo)
228 * See also dialog.c/DIALOG_ParseTemplate32().
231 static UINT get_template_size(const DLGTEMPLATE *template)
233 const WORD *p = (const WORD *)template;
234 BOOL istemplateex = ((const MyDLGTEMPLATEEX *)template)->signature == 0xFFFF;
235 WORD nitems;
236 UINT ret;
238 if (istemplateex)
240 /* DLGTEMPLATEEX (not defined in any std. header file) */
241 TRACE("is DLGTEMPLATEEX\n");
242 p++; /* dlgVer */
243 p++; /* signature */
244 p += 2; /* help ID */
245 p += 2; /* ext style */
246 p += 2; /* style */
248 else
250 /* DLGTEMPLATE */
251 TRACE("is DLGTEMPLATE\n");
252 p += 2; /* style */
253 p += 2; /* ext style */
256 nitems = *p;
257 p++; /* nb items */
258 p++; /* x */
259 p++; /* y */
260 p++; /* width */
261 p++; /* height */
263 /* menu */
264 switch (*p)
266 case 0x0000:
267 p++;
268 break;
269 case 0xffff:
270 p += 2;
271 break;
272 default:
273 TRACE("menu %s\n", debugstr_w( p ));
274 p += lstrlenW( p ) + 1;
275 break;
278 /* class */
279 switch (*p)
281 case 0x0000:
282 p++;
283 break;
284 case 0xffff:
285 p += 2; /* 0xffff plus predefined window class ordinal value */
286 break;
287 default:
288 TRACE("class %s\n", debugstr_w( p ));
289 p += lstrlenW( p ) + 1;
290 break;
293 /* title */
294 TRACE("title %s\n", debugstr_w( p ));
295 p += lstrlenW( p ) + 1;
297 /* font, if DS_SETFONT set */
298 if ((DS_SETFONT & ((istemplateex) ? ((const MyDLGTEMPLATEEX *)template)->style :
299 template->style)))
301 p += istemplateex ? 3 : 1;
302 TRACE("font %s\n", debugstr_w( p ));
303 p += lstrlenW( p ) + 1; /* the font name */
306 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
307 * that are following the DLGTEMPLATE(EX) data */
308 TRACE("%d items\n", nitems);
309 while (nitems > 0)
311 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
313 /* skip header */
314 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))
315 / sizeof(WORD);
317 /* check class */
318 switch (*p)
320 case 0x0000:
321 p++;
322 break;
323 case 0xffff:
324 TRACE("class ordinal %#lx\n", *(const DWORD *)p);
325 p += 2;
326 break;
327 default:
328 TRACE("class %s\n", debugstr_w( p ));
329 p += lstrlenW( p ) + 1;
330 break;
333 /* check title text */
334 switch (*p)
336 case 0x0000:
337 p++;
338 break;
339 case 0xffff:
340 TRACE("text ordinal %#lx\n",*(const DWORD *)p);
341 p += 2;
342 break;
343 default:
344 TRACE("text %s\n",debugstr_w( p ));
345 p += lstrlenW( p ) + 1;
346 break;
348 p += *p / sizeof(WORD) + 1; /* Skip extra data */
349 --nitems;
352 ret = (p - (const WORD *)template) * sizeof(WORD);
353 TRACE("%p %p size 0x%08x\n", p, template, ret);
354 return ret;
357 static DWORD HPSP_get_flags(HPROPSHEETPAGE hpsp)
359 if (!hpsp) return 0;
360 return hpsp->unicode ? hpsp->pspW.dwFlags : hpsp->pspA.dwFlags;
363 static void HPSP_call_callback(HPROPSHEETPAGE hpsp, UINT msg)
365 if (hpsp->unicode)
367 if (!(hpsp->pspW.dwFlags & PSP_USECALLBACK) || !hpsp->pspW.pfnCallback ||
368 (msg == PSPCB_ADDREF && hpsp->pspW.dwSize <= PROPSHEETPAGEW_V1_SIZE))
369 return;
371 hpsp->pspW.pfnCallback(0, msg, &hpsp->pspW);
373 else
375 if (!(hpsp->pspA.dwFlags & PSP_USECALLBACK) || !hpsp->pspA.pfnCallback ||
376 (msg == PSPCB_ADDREF && hpsp->pspA.dwSize <= PROPSHEETPAGEA_V1_SIZE))
377 return;
379 hpsp->pspA.pfnCallback(0, msg, &hpsp->pspA);
383 static const DLGTEMPLATE* HPSP_load_template(HPROPSHEETPAGE hpsp, DWORD *size)
385 HGLOBAL template;
386 HINSTANCE hinst;
387 HRSRC res;
389 if (hpsp->unicode)
391 if (hpsp->pspW.dwFlags & PSP_DLGINDIRECT)
393 if (size)
394 *size = get_template_size(hpsp->pspW.pResource);
395 return hpsp->pspW.pResource;
398 hinst = hpsp->pspW.hInstance;
399 res = FindResourceW(hinst, hpsp->pspW.pszTemplate, (LPWSTR)RT_DIALOG);
401 else
403 if (hpsp->pspA.dwFlags & PSP_DLGINDIRECT)
405 if (size)
406 *size = get_template_size(hpsp->pspA.pResource);
407 return hpsp->pspA.pResource;
410 hinst = hpsp->pspA.hInstance;
411 res = FindResourceA(hinst, hpsp->pspA.pszTemplate, (LPSTR)RT_DIALOG);
414 if (size)
415 *size = SizeofResource(hinst, res);
417 template = LoadResource(hinst, res);
418 return LockResource(template);
421 static WCHAR* HPSP_get_title(HPROPSHEETPAGE hpsp, const WCHAR *template_title)
423 const WCHAR *pTitle;
424 WCHAR szTitle[256];
425 const void *title;
426 HINSTANCE hinst;
428 if (hpsp->unicode)
430 title = hpsp->pspW.pszTitle;
431 hinst = hpsp->pspW.hInstance;
433 else
435 title = hpsp->pspA.pszTitle;
436 hinst = hpsp->pspA.hInstance;
439 if (IS_INTRESOURCE(title))
441 if (LoadStringW(hinst, (DWORD_PTR)title, szTitle, ARRAY_SIZE(szTitle)))
442 pTitle = szTitle;
443 else if (*template_title)
444 pTitle = template_title;
445 else
446 pTitle = L"(null)";
448 return heap_strdupW(pTitle);
451 if (hpsp->unicode)
452 return heap_strdupW(title);
453 return heap_strdupAtoW(title);
456 static HICON HPSP_get_icon(HPROPSHEETPAGE hpsp)
458 HICON ret;
460 if (hpsp->unicode)
462 if (hpsp->pspW.dwFlags & PSP_USEICONID)
464 int cx = GetSystemMetrics(SM_CXSMICON);
465 int cy = GetSystemMetrics(SM_CYSMICON);
467 ret = LoadImageW(hpsp->pspW.hInstance, hpsp->pspW.pszIcon, IMAGE_ICON,
468 cx, cy, LR_DEFAULTCOLOR);
470 else
472 ret = hpsp->pspW.hIcon;
475 else
477 if (hpsp->pspA.dwFlags & PSP_USEICONID)
479 int cx = GetSystemMetrics(SM_CXSMICON);
480 int cy = GetSystemMetrics(SM_CYSMICON);
482 ret = LoadImageA(hpsp->pspA.hInstance, hpsp->pspA.pszIcon, IMAGE_ICON,
483 cx, cy, LR_DEFAULTCOLOR);
485 else
487 ret = hpsp->pspA.hIcon;
491 return ret;
494 static LRESULT HPSP_get_template(HPROPSHEETPAGE hpsp)
496 if (hpsp->unicode)
497 return (LRESULT)hpsp->pspW.pszTemplate;
498 return (LRESULT)hpsp->pspA.pszTemplate;
501 static HWND HPSP_create_page(HPROPSHEETPAGE hpsp, DLGTEMPLATE *template, HWND parent)
503 HWND hwnd;
505 if (hpsp->unicode)
507 hwnd = CreateDialogIndirectParamW(hpsp->pspW.hInstance, template,
508 parent, hpsp->pspW.pfnDlgProc, (LPARAM)&hpsp->pspW);
510 else
512 hwnd = CreateDialogIndirectParamA(hpsp->pspA.hInstance, template,
513 parent, hpsp->pspA.pfnDlgProc, (LPARAM)&hpsp->pspA);
516 return hwnd;
519 static void HPSP_set_header_title(HPROPSHEETPAGE hpsp, const WCHAR *title)
521 if (hpsp->unicode)
523 if (!IS_INTRESOURCE(hpsp->pspW.pszHeaderTitle))
524 Free((void *)hpsp->pspW.pszHeaderTitle);
526 hpsp->pspW.pszHeaderTitle = heap_strdupW(title);
527 hpsp->pspW.dwFlags |= PSP_USEHEADERTITLE;
529 else
531 if (!IS_INTRESOURCE(hpsp->pspA.pszHeaderTitle))
532 Free((void *)hpsp->pspA.pszHeaderTitle);
534 hpsp->pspA.pszHeaderTitle = heap_strdupWtoA(title);
535 hpsp->pspA.dwFlags |= PSP_USEHEADERTITLE;
539 static void HPSP_set_header_subtitle(HPROPSHEETPAGE hpsp, const WCHAR *subtitle)
541 if (hpsp->unicode)
543 if (!IS_INTRESOURCE(hpsp->pspW.pszHeaderTitle))
544 Free((void *)hpsp->pspW.pszHeaderTitle);
546 hpsp->pspW.pszHeaderTitle = heap_strdupW(subtitle);
547 hpsp->pspW.dwFlags |= PSP_USEHEADERSUBTITLE;
549 else
551 if (!IS_INTRESOURCE(hpsp->pspA.pszHeaderTitle))
552 Free((void *)hpsp->pspA.pszHeaderTitle);
554 hpsp->pspA.pszHeaderTitle = heap_strdupWtoA(subtitle);
555 hpsp->pspA.dwFlags |= PSP_USEHEADERSUBTITLE;
559 static void HPSP_draw_text(HPROPSHEETPAGE hpsp, HDC hdc, BOOL title, RECT *r, UINT format)
561 const void *text;
563 if (hpsp->unicode)
564 text = title ? hpsp->pspW.pszHeaderTitle : hpsp->pspW.pszHeaderSubTitle;
565 else
566 text = title ? hpsp->pspA.pszHeaderTitle : hpsp->pspA.pszHeaderSubTitle;
568 if (IS_INTRESOURCE(text))
570 WCHAR buf[256];
571 INT len;
573 len = LoadStringW(hpsp->unicode ? hpsp->pspW.hInstance : hpsp->pspA.hInstance,
574 (UINT_PTR)text, buf, ARRAY_SIZE(buf));
575 if (len != 0)
576 DrawTextW(hdc, buf, len, r, format);
578 else if (hpsp->unicode)
579 DrawTextW(hdc, text, -1, r, format);
580 else
581 DrawTextA(hdc, text, -1, r, format);
584 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
585 /******************************************************************************
586 * PROPSHEET_UnImplementedFlags
588 * Document use of flags we don't implement yet.
590 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
592 CHAR string[256];
594 string[0] = '\0';
597 * unhandled header flags:
598 * PSH_RTLREADING 0x00000800
599 * PSH_STRETCHWATERMARK 0x00040000
600 * PSH_USEPAGELANG 0x00200000
603 add_flag(PSH_RTLREADING);
604 add_flag(PSH_STRETCHWATERMARK);
605 add_flag(PSH_USEPAGELANG);
606 if (string[0] != '\0')
607 FIXME("%s\n", string);
609 #undef add_flag
611 /******************************************************************************
612 * PROPSHEET_GetPageRect
614 * Retrieve rect from tab control and map into the dialog for SetWindowPos
616 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
617 RECT *rc, HPROPSHEETPAGE hpsp)
619 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
620 HWND hwndChild;
621 RECT r;
623 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
624 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
625 !(HPSP_get_flags(hpsp) & PSP_HIDEHEADER)) ||
626 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
628 rc->left = rc->top = WIZARD_PADDING;
630 else
632 rc->left = rc->top = 0;
634 rc->right = psInfo->width - rc->left;
635 rc->bottom = psInfo->height - rc->top;
636 MapDialogRect(hwndDlg, rc);
638 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
639 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
640 !(HPSP_get_flags(hpsp) & PSP_HIDEHEADER))
642 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
643 GetClientRect(hwndChild, &r);
644 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
645 rc->top += r.bottom + 1;
647 } else {
648 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
649 GetClientRect(hwndTabCtrl, rc);
650 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
651 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
655 /******************************************************************************
656 * PROPSHEET_FindPageByResId
658 * Find page index corresponding to page resource id.
660 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
662 INT i;
664 for (i = 0; i < psInfo->nPages; i++)
666 /* Fixme: if resource ID is a string shall we use strcmp ??? */
667 if (HPSP_get_template(psInfo->proppage[i].hpage) == resId)
668 break;
671 return i;
674 /******************************************************************************
675 * PROPSHEET_CollectSheetInfoCommon
677 * Common code for PROPSHEET_CollectSheetInfoA/W
679 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
681 PROPSHEET_UnImplementedFlags(dwFlags);
683 psInfo->hasHelp = dwFlags & PSH_HASHELP;
684 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
685 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
686 psInfo->isModeless = dwFlags & PSH_MODELESS;
687 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
688 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
689 psInfo->active_page = 0;
691 psInfo->result = 0;
692 psInfo->hImageList = 0;
693 psInfo->activeValid = FALSE;
696 /******************************************************************************
697 * PROPSHEET_CollectSheetInfoA
699 * Collect relevant data.
701 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
702 PropSheetInfo * psInfo)
704 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
705 DWORD dwFlags = lppsh->dwFlags;
707 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
709 memcpy(&psInfo->ppshheader,lppsh,dwSize);
710 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%#lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
711 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
712 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
714 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
715 psInfo->ppshheader.pszCaption = NULL;
716 else
718 if (!IS_INTRESOURCE(lppsh->pszCaption))
720 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
721 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
723 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
724 psInfo->ppshheader.pszCaption = caption;
727 psInfo->nPages = lppsh->nPages;
729 if (dwFlags & PSH_USEPSTARTPAGE)
731 TRACE("PSH_USEPSTARTPAGE is on\n");
732 psInfo->active_page = 0;
734 else
735 psInfo->active_page = lppsh->nStartPage;
737 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
740 /******************************************************************************
741 * PROPSHEET_CollectSheetInfoW
743 * Collect relevant data.
745 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
746 PropSheetInfo * psInfo)
748 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
749 DWORD dwFlags = lppsh->dwFlags;
751 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
753 memcpy(&psInfo->ppshheader,lppsh,dwSize);
754 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%#lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
755 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
757 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
758 psInfo->ppshheader.pszCaption = NULL;
759 else
761 if (!IS_INTRESOURCE(lppsh->pszCaption))
762 psInfo->ppshheader.pszCaption = heap_strdupW( lppsh->pszCaption );
764 psInfo->nPages = lppsh->nPages;
766 if (dwFlags & PSH_USEPSTARTPAGE)
768 TRACE("PSH_USEPSTARTPAGE is on\n");
769 psInfo->active_page = 0;
771 else
772 psInfo->active_page = lppsh->nStartPage;
774 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
777 /******************************************************************************
778 * PROPSHEET_CollectPageInfo
780 * Collect property sheet data.
781 * With code taken from DIALOG_ParseTemplate32.
783 static BOOL PROPSHEET_CollectPageInfo(HPROPSHEETPAGE hpsp,
784 PropSheetInfo * psInfo,
785 int index, BOOL resize)
787 const DLGTEMPLATE* pTemplate;
788 const WORD* p;
789 DWORD dwFlags;
790 int width, height;
792 if (!hpsp)
793 return FALSE;
795 TRACE("\n");
796 psInfo->proppage[index].hpage = hpsp;
797 psInfo->proppage[index].hwndPage = 0;
798 psInfo->proppage[index].isDirty = FALSE;
801 * Process property page flags.
803 dwFlags = HPSP_get_flags(hpsp);
804 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
805 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
807 /* as soon as we have a page with the help flag, set the sheet flag on */
808 if (psInfo->proppage[index].hasHelp)
809 psInfo->hasHelp = TRUE;
812 * Process page template.
814 pTemplate = HPSP_load_template(hpsp, NULL);
817 * Extract the size of the page and the caption.
819 if (!pTemplate)
820 return FALSE;
822 p = (const WORD *)pTemplate;
824 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
826 /* DLGTEMPLATEEX (not defined in any std. header file) */
828 p++; /* dlgVer */
829 p++; /* signature */
830 p += 2; /* help ID */
831 p += 2; /* ext style */
832 p += 2; /* style */
834 else
836 /* DLGTEMPLATE */
838 p += 2; /* style */
839 p += 2; /* ext style */
842 p++; /* nb items */
843 p++; /* x */
844 p++; /* y */
845 width = (WORD)*p; p++;
846 height = (WORD)*p; p++;
848 if (HPSP_get_flags(hpsp) & (PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE))
849 psInfo->ppshheader.dwFlags |= PSH_HEADER;
851 /* Special calculation for interior wizard pages so the largest page is
852 * calculated correctly. We need to add all the padding and space occupied
853 * by the header so the width and height sums up to the whole wizard client
854 * area. */
855 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
856 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
857 !(dwFlags & PSP_HIDEHEADER))
859 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
860 width += 2 * WIZARD_PADDING;
862 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
864 height += 2 * WIZARD_PADDING;
865 width += 2 * WIZARD_PADDING;
868 /* remember the largest width and height */
869 if (resize)
871 if (width > psInfo->width)
872 psInfo->width = width;
874 if (height > psInfo->height)
875 psInfo->height = height;
878 /* menu */
879 switch ((WORD)*p)
881 case 0x0000:
882 p++;
883 break;
884 case 0xffff:
885 p += 2;
886 break;
887 default:
888 p += lstrlenW( p ) + 1;
889 break;
892 /* class */
893 switch ((WORD)*p)
895 case 0x0000:
896 p++;
897 break;
898 case 0xffff:
899 p += 2;
900 break;
901 default:
902 p += lstrlenW( p ) + 1;
903 break;
906 /* Extract the caption */
907 psInfo->proppage[index].pszText = p;
908 TRACE("Tab %d %s\n",index,debugstr_w( p ));
910 if (dwFlags & PSP_USETITLE)
911 psInfo->proppage[index].pszText = HPSP_get_title(hpsp, p);
914 * Build the image list for icons
916 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
918 HICON hIcon;
919 int icon_cx = GetSystemMetrics(SM_CXSMICON);
920 int icon_cy = GetSystemMetrics(SM_CYSMICON);
922 if ((hIcon = HPSP_get_icon(hpsp)))
924 if (psInfo->hImageList == 0 )
925 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
927 ImageList_AddIcon(psInfo->hImageList, hIcon);
932 return TRUE;
935 /******************************************************************************
936 * PROPSHEET_CreateDialog
938 * Creates the actual property sheet.
940 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
942 LRESULT ret;
943 LPCVOID template;
944 LPVOID temp = 0;
945 HRSRC hRes;
946 DWORD resSize;
947 WORD resID = IDD_PROPSHEET;
949 TRACE("(%p)\n", psInfo);
950 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
951 resID = IDD_WIZARD;
953 if( psInfo->unicode )
955 if(!(hRes = FindResourceW(COMCTL32_hModule,
956 MAKEINTRESOURCEW(resID),
957 (LPWSTR)RT_DIALOG)))
958 return -1;
960 else
962 if(!(hRes = FindResourceA(COMCTL32_hModule,
963 MAKEINTRESOURCEA(resID),
964 (LPSTR)RT_DIALOG)))
965 return -1;
968 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
969 return -1;
972 * Make a copy of the dialog template.
974 resSize = SizeofResource(COMCTL32_hModule, hRes);
976 temp = Alloc(2 * resSize);
978 if (!temp)
979 return -1;
981 memcpy(temp, template, resSize);
983 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
985 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
986 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
987 else
988 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
990 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
991 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
993 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
994 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
995 else
996 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
999 if (psInfo->useCallback)
1000 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
1002 /* NOTE: MSDN states "Returns a positive value if successful, or -1
1003 * otherwise for modal property sheets.", but this is wrong. The
1004 * actual return value is either TRUE (success), FALSE (cancel) or
1005 * -1 (error). */
1006 if( psInfo->unicode )
1008 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
1009 temp, psInfo->ppshheader.hwndParent,
1010 PROPSHEET_DialogProc, (LPARAM)psInfo);
1011 if ( !ret ) ret = -1;
1013 else
1015 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
1016 temp, psInfo->ppshheader.hwndParent,
1017 PROPSHEET_DialogProc, (LPARAM)psInfo);
1018 if ( !ret ) ret = -1;
1021 Free(temp);
1023 return ret;
1026 /******************************************************************************
1027 * PROPSHEET_SizeMismatch
1029 * Verify that the tab control and the "largest" property sheet page dlg. template
1030 * match in size.
1032 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
1034 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1035 RECT rcOrigTab, rcPage;
1038 * Original tab size.
1040 GetClientRect(hwndTabCtrl, &rcOrigTab);
1041 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
1044 * Biggest page size.
1046 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
1047 MapDialogRect(hwndDlg, &rcPage);
1048 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
1050 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
1051 return TRUE;
1052 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
1053 return TRUE;
1055 return FALSE;
1058 /******************************************************************************
1059 * PROPSHEET_AdjustSize
1061 * Resizes the property sheet and the tab control to fit the largest page.
1063 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
1065 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1066 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
1067 RECT rc,tabRect;
1068 int buttonHeight;
1069 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
1070 RECT units;
1071 LONG style;
1073 /* Get the height of buttons */
1074 GetClientRect(hwndButton, &rc);
1075 buttonHeight = rc.bottom;
1078 * Biggest page size.
1080 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
1081 MapDialogRect(hwndDlg, &rc);
1083 /* retrieve the dialog units */
1084 units.left = units.right = 4;
1085 units.top = units.bottom = 8;
1086 MapDialogRect(hwndDlg, &units);
1089 * Resize the tab control.
1091 GetClientRect(hwndTabCtrl,&tabRect);
1093 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
1095 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
1097 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
1098 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
1101 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
1103 rc.right = rc.left + tabRect.right - tabRect.left;
1104 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
1107 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
1109 rc.right -= rc.left;
1110 rc.bottom -= rc.top;
1111 TRACE("setting tab %p, rc (0,0)-(%ld,%ld)\n", hwndTabCtrl, rc.right, rc.bottom);
1112 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
1113 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1115 GetClientRect(hwndTabCtrl, &rc);
1117 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
1119 rc.right += (padding.x * 2);
1120 rc.bottom += buttonHeight + (3 * padding.y);
1122 style = GetWindowLongW(hwndDlg, GWL_STYLE);
1123 if (!(style & WS_CHILD))
1124 AdjustWindowRect(&rc, style, FALSE);
1126 rc.right -= rc.left;
1127 rc.bottom -= rc.top;
1130 * Resize the property sheet.
1132 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n", hwndDlg, rc.right, rc.bottom);
1133 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
1134 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1135 return TRUE;
1138 /******************************************************************************
1139 * PROPSHEET_AdjustSizeWizard
1141 * Resizes the property sheet to fit the largest page.
1143 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
1145 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1146 RECT rc, lineRect, dialogRect;
1148 /* Biggest page size */
1149 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
1150 MapDialogRect(hwndDlg, &rc);
1152 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
1154 /* Add space for the buttons row */
1155 GetWindowRect(hwndLine, &lineRect);
1156 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
1157 GetClientRect(hwndDlg, &dialogRect);
1158 rc.bottom += dialogRect.bottom - lineRect.top - 1;
1160 /* Convert the client coordinates to window coordinates */
1161 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
1163 /* Resize the property sheet */
1164 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n", hwndDlg, rc.right, rc.bottom);
1165 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
1166 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1168 return TRUE;
1171 /******************************************************************************
1172 * PROPSHEET_AdjustButtons
1174 * Adjusts the buttons' positions.
1176 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
1178 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
1179 RECT rcSheet;
1180 int x, y;
1181 int num_buttons = 2;
1182 int buttonWidth, buttonHeight;
1183 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
1185 if (psInfo->hasApply)
1186 num_buttons++;
1188 if (psInfo->hasHelp)
1189 num_buttons++;
1192 * Obtain the size of the buttons.
1194 GetClientRect(hwndButton, &rcSheet);
1195 buttonWidth = rcSheet.right;
1196 buttonHeight = rcSheet.bottom;
1199 * Get the size of the property sheet.
1201 GetClientRect(hwndParent, &rcSheet);
1204 * All buttons will be at this y coordinate.
1206 y = rcSheet.bottom - (padding.y + buttonHeight);
1209 * Position OK button and make it default.
1211 hwndButton = GetDlgItem(hwndParent, IDOK);
1213 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
1215 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1216 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1218 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
1222 * Position Cancel button.
1224 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1226 x += padding.x + buttonWidth;
1228 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1229 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1232 * Position Apply button.
1234 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
1236 if(psInfo->hasApply)
1237 x += padding.x + buttonWidth;
1238 else
1239 ShowWindow(hwndButton, SW_HIDE);
1241 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1242 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1243 EnableWindow(hwndButton, FALSE);
1246 * Position Help button.
1248 hwndButton = GetDlgItem(hwndParent, IDHELP);
1250 x += padding.x + buttonWidth;
1251 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1252 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1254 if(!psInfo->hasHelp)
1255 ShowWindow(hwndButton, SW_HIDE);
1257 return TRUE;
1260 /******************************************************************************
1261 * PROPSHEET_AdjustButtonsWizard
1263 * Adjusts the buttons' positions.
1265 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1266 const PropSheetInfo* psInfo)
1268 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1269 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1270 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1271 RECT rcSheet;
1272 int x, y;
1273 int num_buttons = 3;
1274 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1275 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1277 if (psInfo->hasHelp)
1278 num_buttons++;
1279 if (psInfo->hasFinish)
1280 num_buttons++;
1283 * Obtain the size of the buttons.
1285 GetClientRect(hwndButton, &rcSheet);
1286 buttonWidth = rcSheet.right;
1287 buttonHeight = rcSheet.bottom;
1289 GetClientRect(hwndLine, &rcSheet);
1290 lineHeight = rcSheet.bottom;
1293 * Get the size of the property sheet.
1295 GetClientRect(hwndParent, &rcSheet);
1298 * All buttons will be at this y coordinate.
1300 y = rcSheet.bottom - (padding.y + buttonHeight);
1303 * Position the Back button.
1305 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1307 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1309 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1310 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1313 * Position the Next button.
1315 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1317 x += buttonWidth;
1319 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1320 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1323 * Position the Finish button.
1325 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1327 if (psInfo->hasFinish)
1328 x += padding.x + buttonWidth;
1330 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1331 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1333 if (!psInfo->hasFinish)
1334 ShowWindow(hwndButton, SW_HIDE);
1337 * Position the Cancel button.
1339 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1341 x += padding.x + buttonWidth;
1343 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1344 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1347 * Position Help button.
1349 hwndButton = GetDlgItem(hwndParent, IDHELP);
1351 if (psInfo->hasHelp)
1353 x += padding.x + buttonWidth;
1355 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1356 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1358 else
1359 ShowWindow(hwndButton, SW_HIDE);
1361 if (psInfo->ppshheader.dwFlags &
1362 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1363 padding.x = 0;
1366 * Position and resize the sunken line.
1368 x = padding.x;
1369 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1371 lineWidth = rcSheet.right - (padding.x * 2);
1372 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1373 SWP_NOZORDER | SWP_NOACTIVATE);
1376 * Position and resize the header sunken line.
1379 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1380 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1381 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1382 ShowWindow(hwndLineHeader, SW_HIDE);
1384 return TRUE;
1387 /******************************************************************************
1388 * PROPSHEET_GetPaddingInfo
1390 * Returns the layout information.
1392 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1394 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1395 RECT rcTab;
1396 PADDING_INFO padding;
1398 GetWindowRect(hwndTab, &rcTab);
1399 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1401 padding.x = rcTab.left;
1402 padding.y = rcTab.top;
1404 return padding;
1407 /******************************************************************************
1408 * PROPSHEET_GetPaddingInfoWizard
1410 * Returns the layout information.
1411 * Vertical spacing is the distance between the line and the buttons.
1412 * Do NOT use the Help button to gather padding information when it isn't mapped
1413 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1414 * for it in this case !
1415 * FIXME: I'm not sure about any other coordinate problems with these evil
1416 * buttons. Fix it in case additional problems appear or maybe calculate
1417 * a padding in a completely different way, as this is somewhat messy.
1419 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1420 psInfo)
1422 PADDING_INFO padding;
1423 RECT rc;
1424 HWND hwndControl;
1425 INT idButton;
1426 POINT ptButton, ptLine;
1428 TRACE("\n");
1429 if (psInfo->hasHelp)
1431 idButton = IDHELP;
1433 else
1435 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1437 idButton = IDC_NEXT_BUTTON;
1439 else
1441 /* hopefully this is ok */
1442 idButton = IDCANCEL;
1446 hwndControl = GetDlgItem(hwndDlg, idButton);
1447 GetWindowRect(hwndControl, &rc);
1448 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1449 ptButton.x = rc.left;
1450 ptButton.y = rc.top;
1452 /* Line */
1453 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1454 GetWindowRect(hwndControl, &rc);
1455 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1456 ptLine.x = rc.left;
1457 ptLine.y = rc.bottom;
1459 padding.y = ptButton.y - ptLine.y;
1461 if (padding.y < 0)
1462 ERR("padding negative ! Please report this !\n");
1464 /* this is most probably not correct, but the best we have now */
1465 padding.x = padding.y;
1466 return padding;
1469 /******************************************************************************
1470 * PROPSHEET_CreateTabControl
1472 * Insert the tabs in the tab control.
1474 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1475 const PropSheetInfo * psInfo)
1477 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1478 TCITEMW item;
1479 int i, nTabs;
1480 int iImage = 0;
1482 TRACE("\n");
1483 item.mask = TCIF_TEXT;
1484 item.cchTextMax = MAX_TABTEXT_LENGTH;
1486 nTabs = psInfo->nPages;
1489 * Set the image list for icons.
1491 if (psInfo->hImageList)
1493 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1496 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1497 for (i = 0; i < nTabs; i++)
1499 if ( psInfo->proppage[i].hasIcon )
1501 item.mask |= TCIF_IMAGE;
1502 item.iImage = iImage++;
1504 else
1506 item.mask &= ~TCIF_IMAGE;
1509 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1510 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1512 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1514 return TRUE;
1517 /******************************************************************************
1518 * PROPSHEET_WizardSubclassProc
1520 * Subclassing window procedure for wizard exterior pages to prevent drawing
1521 * background and so drawing above the watermark.
1523 static LRESULT CALLBACK
1524 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1526 switch (uMsg)
1528 case WM_ERASEBKGND:
1529 return TRUE;
1531 case WM_CTLCOLORSTATIC:
1532 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1533 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1536 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1539 /******************************************************************************
1540 * PROPSHEET_CreatePage
1542 * Creates a page.
1544 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1545 int index,
1546 const PropSheetInfo * psInfo,
1547 HPROPSHEETPAGE hpsp)
1549 const DLGTEMPLATE* pTemplate;
1550 HWND hwndPage;
1551 DWORD resSize;
1552 DLGTEMPLATE* pTemplateCopy = NULL;
1554 TRACE("index %d\n", index);
1556 if (hpsp == NULL)
1558 return FALSE;
1561 pTemplate = HPSP_load_template(hpsp, &resSize);
1562 pTemplateCopy = Alloc(resSize);
1563 if (!pTemplateCopy)
1564 return FALSE;
1566 TRACE("copying pTemplate %p into pTemplateCopy %p (%ld)\n", pTemplate, pTemplateCopy, resSize);
1567 memcpy(pTemplateCopy, pTemplate, resSize);
1569 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1571 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1572 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1573 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1574 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1575 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1576 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1577 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1578 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1580 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1582 else
1584 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1585 pTemplateCopy->style &= ~DS_MODALFRAME;
1586 pTemplateCopy->style &= ~WS_CAPTION;
1587 pTemplateCopy->style &= ~WS_SYSMENU;
1588 pTemplateCopy->style &= ~WS_POPUP;
1589 pTemplateCopy->style &= ~WS_DISABLED;
1590 pTemplateCopy->style &= ~WS_VISIBLE;
1591 pTemplateCopy->style &= ~WS_THICKFRAME;
1593 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1596 HPSP_call_callback(hpsp, PSPCB_CREATE);
1597 hwndPage = HPSP_create_page(hpsp, pTemplateCopy, hwndParent);
1598 /* Free a no more needed copy */
1599 Free(pTemplateCopy);
1601 if(!hwndPage)
1602 return FALSE;
1604 psInfo->proppage[index].hwndPage = hwndPage;
1606 /* Subclass exterior wizard pages */
1607 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1608 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1609 (HPSP_get_flags(hpsp) & PSP_HIDEHEADER))
1611 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1, 0);
1613 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1614 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1616 return TRUE;
1619 /******************************************************************************
1620 * PROPSHEET_LoadWizardBitmaps
1622 * Loads the watermark and header bitmaps for a wizard.
1624 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1626 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1628 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1629 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1630 considers hbmWatermark as valid. */
1631 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1632 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1634 psInfo->ppshheader.hbmWatermark =
1635 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.pszbmWatermark, 0, NULL, 0);
1638 /* Same behavior as for watermarks */
1639 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1640 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1642 psInfo->ppshheader.hbmHeader =
1643 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.pszbmHeader, 0, NULL, 0);
1649 /******************************************************************************
1650 * PROPSHEET_ShowPage
1652 * Displays or creates the specified page.
1654 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1656 HWND hwndTabCtrl;
1657 HWND hwndLineHeader;
1658 HWND control;
1660 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1661 if (index == psInfo->active_page)
1663 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1664 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1665 return TRUE;
1668 if (psInfo->proppage[index].hwndPage == 0)
1670 PROPSHEET_CreatePage(hwndDlg, index, psInfo, psInfo->proppage[index].hpage);
1673 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1675 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1676 psInfo->proppage[index].pszText);
1678 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1679 if(control != NULL)
1680 SetFocus(control);
1683 if (psInfo->active_page != -1)
1684 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1686 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1688 /* Synchronize current selection with tab control
1689 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1690 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1691 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1693 psInfo->active_page = index;
1694 psInfo->activeValid = TRUE;
1696 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1698 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1700 if ((HPSP_get_flags(psInfo->proppage[index].hpage) & PSP_HIDEHEADER) ||
1701 (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1702 ShowWindow(hwndLineHeader, SW_HIDE);
1703 else
1704 ShowWindow(hwndLineHeader, SW_SHOW);
1707 return TRUE;
1710 /******************************************************************************
1711 * PROPSHEET_Back
1713 static BOOL PROPSHEET_Back(HWND hwndDlg)
1715 PSHNOTIFY psn;
1716 HWND hwndPage;
1717 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1718 LRESULT result;
1719 int idx;
1721 TRACE("active_page %d\n", psInfo->active_page);
1722 if (psInfo->active_page < 0)
1723 return FALSE;
1725 psn.hdr.code = PSN_WIZBACK;
1726 psn.hdr.hwndFrom = hwndDlg;
1727 psn.hdr.idFrom = 0;
1728 psn.lParam = 0;
1730 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1732 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1733 if (result == -1)
1734 return FALSE;
1735 else if (result == 0)
1736 idx = psInfo->active_page - 1;
1737 else
1738 idx = PROPSHEET_FindPageByResId(psInfo, result);
1740 if (idx >= 0 && idx < psInfo->nPages)
1742 if (PROPSHEET_CanSetCurSel(hwndDlg))
1744 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1745 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1746 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1749 return TRUE;
1752 /******************************************************************************
1753 * PROPSHEET_Next
1755 static BOOL PROPSHEET_Next(HWND hwndDlg)
1757 PSHNOTIFY psn;
1758 HWND hwndPage;
1759 LRESULT msgResult = 0;
1760 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1761 int idx;
1763 TRACE("active_page %d\n", psInfo->active_page);
1764 if (psInfo->active_page < 0)
1765 return FALSE;
1767 psn.hdr.code = PSN_WIZNEXT;
1768 psn.hdr.hwndFrom = hwndDlg;
1769 psn.hdr.idFrom = 0;
1770 psn.lParam = 0;
1772 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1774 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1775 if (msgResult == -1)
1776 return FALSE;
1777 else if (msgResult == 0)
1778 idx = psInfo->active_page + 1;
1779 else
1780 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1782 if (idx < psInfo->nPages )
1784 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1786 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1787 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1788 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1792 return TRUE;
1795 /******************************************************************************
1796 * PROPSHEET_Finish
1798 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1800 PSHNOTIFY psn;
1801 HWND hwndPage;
1802 LRESULT msgResult = 0;
1803 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1805 TRACE("active_page %d\n", psInfo->active_page);
1806 if (psInfo->active_page < 0)
1807 return FALSE;
1809 psn.hdr.code = PSN_WIZFINISH;
1810 psn.hdr.hwndFrom = hwndDlg;
1811 psn.hdr.idFrom = 0;
1812 psn.lParam = 0;
1814 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1816 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1818 TRACE("msg result %Id\n", msgResult);
1820 if (msgResult != 0)
1821 return FALSE;
1823 if (psInfo->result == 0)
1824 psInfo->result = IDOK;
1825 if (psInfo->isModeless)
1826 psInfo->activeValid = FALSE;
1827 else
1828 psInfo->ended = TRUE;
1830 return TRUE;
1833 /******************************************************************************
1834 * PROPSHEET_Apply
1836 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1838 int i;
1839 HWND hwndPage;
1840 PSHNOTIFY psn;
1841 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1843 TRACE("active_page %d\n", psInfo->active_page);
1844 if (psInfo->active_page < 0)
1845 return FALSE;
1847 psn.hdr.hwndFrom = hwndDlg;
1848 psn.hdr.idFrom = 0;
1849 psn.lParam = 0;
1853 * Send PSN_KILLACTIVE to the current page.
1855 psn.hdr.code = PSN_KILLACTIVE;
1857 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1859 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1860 return FALSE;
1863 * Send PSN_APPLY to all pages.
1865 psn.hdr.code = PSN_APPLY;
1866 psn.lParam = lParam;
1868 for (i = 0; i < psInfo->nPages; i++)
1870 hwndPage = psInfo->proppage[i].hwndPage;
1871 if (hwndPage)
1873 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1875 case PSNRET_INVALID:
1876 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1877 /* fall through */
1878 case PSNRET_INVALID_NOCHANGEPAGE:
1879 return FALSE;
1884 if(lParam)
1886 psInfo->activeValid = FALSE;
1888 else if(psInfo->active_page >= 0)
1890 psn.hdr.code = PSN_SETACTIVE;
1891 psn.lParam = 0;
1892 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1893 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1896 return TRUE;
1899 /******************************************************************************
1900 * PROPSHEET_Cancel
1902 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1904 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1905 HWND hwndPage;
1906 PSHNOTIFY psn;
1907 int i;
1909 TRACE("active_page %d\n", psInfo->active_page);
1910 if (psInfo->active_page < 0)
1911 return;
1913 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1914 psn.hdr.code = PSN_QUERYCANCEL;
1915 psn.hdr.hwndFrom = hwndDlg;
1916 psn.hdr.idFrom = 0;
1917 psn.lParam = 0;
1919 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1920 return;
1922 psn.hdr.code = PSN_RESET;
1923 psn.lParam = lParam;
1925 for (i = 0; i < psInfo->nPages; i++)
1927 hwndPage = psInfo->proppage[i].hwndPage;
1929 if (hwndPage)
1930 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1933 if (psInfo->isModeless)
1935 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1936 psInfo->activeValid = FALSE;
1938 else
1939 psInfo->ended = TRUE;
1942 /******************************************************************************
1943 * PROPSHEET_Help
1945 static void PROPSHEET_Help(HWND hwndDlg)
1947 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1948 HWND hwndPage;
1949 PSHNOTIFY psn;
1951 TRACE("active_page %d\n", psInfo->active_page);
1952 if (psInfo->active_page < 0)
1953 return;
1955 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1956 psn.hdr.code = PSN_HELP;
1957 psn.hdr.hwndFrom = hwndDlg;
1958 psn.hdr.idFrom = 0;
1959 psn.lParam = 0;
1961 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1964 /******************************************************************************
1965 * PROPSHEET_Changed
1967 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1969 int i;
1970 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1972 TRACE("\n");
1973 if (!psInfo) return;
1975 * Set the dirty flag of this page.
1977 for (i = 0; i < psInfo->nPages; i++)
1979 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1980 psInfo->proppage[i].isDirty = TRUE;
1984 * Enable the Apply button.
1986 if (psInfo->hasApply)
1988 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1990 EnableWindow(hwndApplyBtn, TRUE);
1994 /******************************************************************************
1995 * PROPSHEET_UnChanged
1997 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1999 int i;
2000 BOOL noPageDirty = TRUE;
2001 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
2002 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2004 TRACE("\n");
2005 if ( !psInfo ) return;
2006 for (i = 0; i < psInfo->nPages; i++)
2008 /* set the specified page as clean */
2009 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
2010 psInfo->proppage[i].isDirty = FALSE;
2012 /* look to see if there are any dirty pages */
2013 if (psInfo->proppage[i].isDirty)
2014 noPageDirty = FALSE;
2018 * Disable Apply button.
2020 if (noPageDirty)
2021 EnableWindow(hwndApplyBtn, FALSE);
2024 /******************************************************************************
2025 * PROPSHEET_PressButton
2027 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
2029 TRACE("buttonID %d\n", buttonID);
2030 switch (buttonID)
2032 case PSBTN_APPLYNOW:
2033 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
2034 break;
2035 case PSBTN_BACK:
2036 PROPSHEET_Back(hwndDlg);
2037 break;
2038 case PSBTN_CANCEL:
2039 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
2040 break;
2041 case PSBTN_FINISH:
2042 PROPSHEET_Finish(hwndDlg);
2043 break;
2044 case PSBTN_HELP:
2045 PROPSHEET_DoCommand(hwndDlg, IDHELP);
2046 break;
2047 case PSBTN_NEXT:
2048 PROPSHEET_Next(hwndDlg);
2049 break;
2050 case PSBTN_OK:
2051 PROPSHEET_DoCommand(hwndDlg, IDOK);
2052 break;
2053 default:
2054 FIXME("Invalid button index %d\n", buttonID);
2059 /*************************************************************************
2060 * BOOL PROPSHEET_CanSetCurSel [Internal]
2062 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2064 * PARAMS
2065 * hwndDlg [I] handle to a Dialog hWnd
2067 * RETURNS
2068 * TRUE if Current Selection can change
2070 * NOTES
2072 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2074 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2075 HWND hwndPage;
2076 PSHNOTIFY psn;
2077 BOOL res = FALSE;
2079 if (!psInfo)
2081 res = FALSE;
2082 goto end;
2085 TRACE("active_page %d\n", psInfo->active_page);
2086 if (psInfo->active_page < 0)
2088 res = TRUE;
2089 goto end;
2093 * Notify the current page.
2095 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2096 psn.hdr.code = PSN_KILLACTIVE;
2097 psn.hdr.hwndFrom = hwndDlg;
2098 psn.hdr.idFrom = 0;
2099 psn.lParam = 0;
2101 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2103 end:
2104 TRACE("<-- %d\n", res);
2105 return res;
2108 /******************************************************************************
2109 * PROPSHEET_SetCurSel
2111 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2112 int index,
2113 int skipdir,
2114 HPROPSHEETPAGE hpage
2117 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2118 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2119 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2121 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2123 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2125 if (index < 0 || index >= psInfo->nPages)
2127 TRACE("Could not find page to select!\n");
2128 return FALSE;
2131 /* unset active page while doing this transition. */
2132 if (psInfo->active_page != -1)
2133 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2134 psInfo->active_page = -1;
2136 while (1) {
2137 int result;
2138 PSHNOTIFY psn;
2139 RECT rc;
2141 if (hwndTabControl)
2142 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2144 psn.hdr.code = PSN_SETACTIVE;
2145 psn.hdr.hwndFrom = hwndDlg;
2146 psn.hdr.idFrom = 0;
2147 psn.lParam = 0;
2149 if (!psInfo->proppage[index].hwndPage) {
2150 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, psInfo->proppage[index].hpage)) {
2151 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2153 if (!psInfo->isModeless)
2155 DestroyWindow(hwndDlg);
2156 return FALSE;
2159 if(index >= psInfo->nPages)
2160 index--;
2161 if(index < 0)
2162 return FALSE;
2163 continue;
2167 /* Resize the property sheet page to the fit in the Tab control
2168 * (for regular property sheets) or to fit in the client area (for
2169 * wizards).
2170 * NOTE: The resizing happens every time the page is selected and
2171 * not only when it's created (some applications depend on it). */
2172 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, psInfo->proppage[index].hpage);
2173 TRACE("setting page %p, rc (%s) w=%ld, h=%ld\n",
2174 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2175 rc.right - rc.left, rc.bottom - rc.top);
2176 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2177 rc.left, rc.top,
2178 rc.right - rc.left, rc.bottom - rc.top, 0);
2180 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2181 if (!result)
2182 break;
2183 if (result == -1) {
2184 index+=skipdir;
2185 if (index < 0) {
2186 index = 0;
2187 WARN("Tried to skip before first property sheet page!\n");
2188 break;
2190 if (index >= psInfo->nPages) {
2191 WARN("Tried to skip after last property sheet page!\n");
2192 index = psInfo->nPages-1;
2193 break;
2196 else if (result != 0)
2198 int old_index = index;
2199 index = PROPSHEET_FindPageByResId(psInfo, result);
2200 if(index >= psInfo->nPages) {
2201 index = old_index;
2202 WARN("Tried to skip to nonexistent page by res id\n");
2203 break;
2205 continue;
2209 /* Invalidate the header area */
2210 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2211 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2213 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2214 RECT r;
2216 GetClientRect(hwndLineHeader, &r);
2217 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2218 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2220 InvalidateRect(hwndDlg, &r, TRUE);
2224 * Display the new page.
2226 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2228 if (psInfo->proppage[index].hasHelp)
2229 EnableWindow(hwndHelp, TRUE);
2230 else
2231 EnableWindow(hwndHelp, FALSE);
2233 return TRUE;
2236 /******************************************************************************
2237 * PROPSHEET_SetCurSelId
2239 * Selects the page, specified by resource id.
2241 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2243 int idx;
2244 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2246 idx = PROPSHEET_FindPageByResId(psInfo, id);
2247 if (idx < psInfo->nPages )
2249 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2250 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2254 /******************************************************************************
2255 * PROPSHEET_SetTitleA
2257 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2259 if(!IS_INTRESOURCE(lpszText))
2261 WCHAR szTitle[256];
2262 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTitle, ARRAY_SIZE(szTitle));
2263 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2265 else
2267 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2271 /******************************************************************************
2272 * PROPSHEET_SetTitleW
2274 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2276 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2277 WCHAR szTitle[256];
2279 TRACE("%s (style %#lx)\n", debugstr_w(lpszText), dwStyle);
2280 if (IS_INTRESOURCE(lpszText)) {
2281 if (!LoadStringW(psInfo->ppshheader.hInstance, LOWORD(lpszText), szTitle, ARRAY_SIZE(szTitle)))
2282 return;
2283 lpszText = szTitle;
2285 if (dwStyle & PSH_PROPTITLE)
2287 WCHAR* dest;
2288 int lentitle = lstrlenW(lpszText);
2289 int lenprop = lstrlenW(psInfo->strPropertiesFor);
2291 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2292 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2294 SetWindowTextW(hwndDlg, dest);
2295 Free(dest);
2297 else
2298 SetWindowTextW(hwndDlg, lpszText);
2301 /******************************************************************************
2302 * PROPSHEET_SetFinishTextA
2304 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2306 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2307 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2309 TRACE("'%s'\n", lpszText);
2310 /* Set text, show and enable the Finish button */
2311 SetWindowTextA(hwndButton, lpszText);
2312 ShowWindow(hwndButton, SW_SHOW);
2313 EnableWindow(hwndButton, TRUE);
2315 /* Make it default pushbutton */
2316 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2318 /* Hide Back button */
2319 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2320 ShowWindow(hwndButton, SW_HIDE);
2322 if (!psInfo->hasFinish)
2324 /* Hide Next button */
2325 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2326 ShowWindow(hwndButton, SW_HIDE);
2330 /******************************************************************************
2331 * PROPSHEET_SetFinishTextW
2333 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2335 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2336 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2338 TRACE("%s\n", debugstr_w(lpszText));
2339 /* Set text, show and enable the Finish button */
2340 SetWindowTextW(hwndButton, lpszText);
2341 ShowWindow(hwndButton, SW_SHOW);
2342 EnableWindow(hwndButton, TRUE);
2344 /* Make it default pushbutton */
2345 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2347 /* Hide Back button */
2348 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2349 ShowWindow(hwndButton, SW_HIDE);
2351 if (!psInfo->hasFinish)
2353 /* Hide Next button */
2354 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2355 ShowWindow(hwndButton, SW_HIDE);
2359 /******************************************************************************
2360 * PROPSHEET_QuerySiblings
2362 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2363 WPARAM wParam, LPARAM lParam)
2365 int i = 0;
2366 HWND hwndPage;
2367 LRESULT msgResult = 0;
2368 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2370 while ((i < psInfo->nPages) && (msgResult == 0))
2372 hwndPage = psInfo->proppage[i].hwndPage;
2373 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2374 i++;
2377 return msgResult;
2380 /******************************************************************************
2381 * PROPSHEET_InsertPage
2383 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2385 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2386 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2387 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2388 TCITEMW item;
2389 int index;
2391 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2393 if (IS_INTRESOURCE(hpageInsertAfter))
2394 index = LOWORD(hpageInsertAfter);
2395 else
2397 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2398 if (index < 0)
2400 TRACE("Could not find page to insert after!\n");
2401 return FALSE;
2403 index++;
2406 if (index > psInfo->nPages)
2407 index = psInfo->nPages;
2409 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2410 if (!ppi)
2411 return FALSE;
2413 if (hpage && hpage->magic != HPROPSHEETPAGE_MAGIC)
2415 if (psInfo->unicode)
2416 hpage = CreatePropertySheetPageW((const PROPSHEETPAGEW *)hpage);
2417 else
2418 hpage = CreatePropertySheetPageA((const PROPSHEETPAGEA *)hpage);
2422 * Fill in a new PropPageInfo entry.
2424 if (index > 0)
2425 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2426 memset(&ppi[index], 0, sizeof(PropPageInfo));
2427 if (index < psInfo->nPages)
2428 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2429 psInfo->proppage = ppi;
2431 if (!PROPSHEET_CollectPageInfo(hpage, psInfo, index, FALSE))
2433 psInfo->proppage = prev_ppi;
2434 Free(ppi);
2435 return FALSE;
2438 psInfo->proppage[index].hpage = hpage;
2440 if (HPSP_get_flags(hpage) & PSP_PREMATURE)
2442 /* Create the page but don't show it */
2443 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, hpage))
2445 psInfo->proppage = prev_ppi;
2446 Free(ppi);
2447 return FALSE;
2451 Free(prev_ppi);
2452 psInfo->nPages++;
2453 if (index <= psInfo->active_page)
2454 psInfo->active_page++;
2457 * Add a new tab to the tab control.
2459 item.mask = TCIF_TEXT;
2460 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2461 item.cchTextMax = MAX_TABTEXT_LENGTH;
2463 if (psInfo->hImageList)
2464 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2466 if (psInfo->proppage[index].hasIcon)
2468 item.mask |= TCIF_IMAGE;
2469 item.iImage = index;
2472 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2474 /* If it is the only page - show it */
2475 if (psInfo->nPages == 1)
2476 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2478 return TRUE;
2481 /******************************************************************************
2482 * PROPSHEET_AddPage
2484 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2486 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2487 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2488 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2491 /******************************************************************************
2492 * PROPSHEET_RemovePage
2494 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2495 int index,
2496 HPROPSHEETPAGE hpage)
2498 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2499 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2500 PropPageInfo* oldPages;
2502 TRACE("index %d, hpage %p\n", index, hpage);
2503 if (!psInfo) {
2504 return FALSE;
2507 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2509 /* Make sure that index is within range */
2510 if (index < 0 || index >= psInfo->nPages)
2512 TRACE("Could not find page to remove!\n");
2513 return FALSE;
2516 TRACE("total pages %d removing page %d active page %d\n",
2517 psInfo->nPages, index, psInfo->active_page);
2519 * Check if we're removing the active page.
2521 if (index == psInfo->active_page)
2523 if (psInfo->nPages > 1)
2525 if (index > 0)
2527 /* activate previous page */
2528 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2530 else
2532 /* activate the next page */
2533 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2534 psInfo->active_page = index;
2537 else
2539 psInfo->active_page = -1;
2540 if (!psInfo->isModeless)
2542 psInfo->ended = TRUE;
2543 return TRUE;
2547 else if (index < psInfo->active_page)
2548 psInfo->active_page--;
2550 /* Unsubclass the page dialog window */
2551 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2552 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2553 (HPSP_get_flags(psInfo->proppage[index].hpage) & PSP_HIDEHEADER))
2555 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2556 PROPSHEET_WizardSubclassProc, 1);
2559 /* Destroy page dialog window */
2560 DestroyWindow(psInfo->proppage[index].hwndPage);
2562 /* Free page resources */
2563 if(psInfo->proppage[index].hpage)
2565 if (HPSP_get_flags(psInfo->proppage[index].hpage) & PSP_USETITLE)
2566 Free ((LPVOID)psInfo->proppage[index].pszText);
2568 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2571 /* Remove the tab */
2572 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2574 oldPages = psInfo->proppage;
2575 psInfo->nPages--;
2576 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2578 if (index > 0)
2579 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2581 if (index < psInfo->nPages)
2582 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2583 (psInfo->nPages - index) * sizeof(PropPageInfo));
2585 Free(oldPages);
2587 return FALSE;
2590 /******************************************************************************
2591 * PROPSHEET_SetWizButtons
2593 * This code will work if (and assumes that) the Next button is on top of the
2594 * Finish button. ie. Finish comes after Next in the Z order.
2595 * This means make sure the dialog template reflects this.
2598 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2600 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2601 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2602 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2603 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2604 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2606 TRACE("%lx\n", dwFlags);
2608 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2609 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2610 EnableWindow(hwndFinish, enable_finish);
2612 /* set the default pushbutton to an enabled button */
2613 if (enable_finish)
2614 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2615 else if (dwFlags & PSWIZB_NEXT)
2616 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2617 else if (dwFlags & PSWIZB_BACK)
2618 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2619 else
2620 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2622 if (!psInfo->hasFinish)
2624 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2626 /* Hide the Next button */
2627 ShowWindow(hwndNext, SW_HIDE);
2629 /* Show the Finish button */
2630 ShowWindow(hwndFinish, SW_SHOW);
2632 else
2634 /* Hide the Finish button */
2635 ShowWindow(hwndFinish, SW_HIDE);
2636 /* Show the Next button */
2637 ShowWindow(hwndNext, SW_SHOW);
2642 /******************************************************************************
2643 * PROPSHEET_SetHeaderTitleW
2645 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2647 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2649 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2651 if (page_index >= psInfo->nPages)
2652 return;
2654 HPSP_set_header_title(psInfo->proppage[page_index].hpage, title);
2657 /******************************************************************************
2658 * PROPSHEET_SetHeaderTitleA
2660 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2662 WCHAR *titleW;
2664 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2666 titleW = heap_strdupAtoW(title);
2667 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2668 Free(titleW);
2671 /******************************************************************************
2672 * PROPSHEET_SetHeaderSubTitleW
2674 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2676 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2678 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2680 if (page_index >= psInfo->nPages)
2681 return;
2683 HPSP_set_header_subtitle(psInfo->proppage[page_index].hpage, subtitle);
2686 /******************************************************************************
2687 * PROPSHEET_SetHeaderSubTitleA
2689 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2691 WCHAR *subtitleW;
2693 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2695 subtitleW = heap_strdupAtoW(subtitle);
2696 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2697 Free(subtitleW);
2700 /******************************************************************************
2701 * PROPSHEET_HwndToIndex
2703 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2705 int index;
2706 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2708 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2710 for (index = 0; index < psInfo->nPages; index++)
2711 if (psInfo->proppage[index].hwndPage == hPageDlg)
2712 return index;
2713 WARN("%p not found\n", hPageDlg);
2714 return -1;
2717 /******************************************************************************
2718 * PROPSHEET_IndexToHwnd
2720 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2722 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2723 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2724 if (!psInfo)
2725 return 0;
2726 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2727 WARN("%d out of range.\n", iPageIndex);
2728 return 0;
2730 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2733 /******************************************************************************
2734 * PROPSHEET_PageToIndex
2736 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2738 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2740 TRACE("(%p, %p)\n", hwndDlg, hPage);
2742 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2745 /******************************************************************************
2746 * PROPSHEET_IndexToPage
2748 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2750 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2751 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2752 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2753 WARN("%d out of range.\n", iPageIndex);
2754 return 0;
2756 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2759 /******************************************************************************
2760 * PROPSHEET_IdToIndex
2762 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2764 int index;
2765 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2766 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2767 for (index = 0; index < psInfo->nPages; index++) {
2768 if (HPSP_get_template(psInfo->proppage[index].hpage) == iPageId)
2769 return index;
2772 return -1;
2775 /******************************************************************************
2776 * PROPSHEET_IndexToId
2778 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2780 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2781 HPROPSHEETPAGE hpsp;
2782 LRESULT template;
2784 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2786 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2787 WARN("%d out of range.\n", iPageIndex);
2788 return 0;
2790 hpsp = psInfo->proppage[iPageIndex].hpage;
2791 template = HPSP_get_template(hpsp);
2792 if (HPSP_get_flags(hpsp) & PSP_DLGINDIRECT || !IS_INTRESOURCE(template))
2793 return 0;
2794 return template;
2797 /******************************************************************************
2798 * PROPSHEET_GetResult
2800 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2802 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2803 return psInfo->result;
2806 /******************************************************************************
2807 * PROPSHEET_RecalcPageSizes
2809 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2811 FIXME("(%p): stub\n", hwndDlg);
2812 return FALSE;
2815 /******************************************************************************
2816 * PROPSHEET_GetPageIndex
2818 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2819 * the array of PropPageInfo. If page is not found original index is used
2820 * (page takes precedence over index).
2822 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2824 int index;
2826 TRACE("page %p index %d\n", page, original_index);
2828 for (index = 0; index < psInfo->nPages; index++)
2829 if (psInfo->proppage[index].hpage == page)
2830 return index;
2832 return original_index;
2835 /******************************************************************************
2836 * PROPSHEET_CleanUp
2838 static void PROPSHEET_CleanUp(HWND hwndDlg)
2840 int i;
2841 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2843 TRACE("\n");
2844 if (!psInfo) return;
2845 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2846 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2848 for (i = 0; i < psInfo->nPages; i++)
2850 DWORD flags = HPSP_get_flags(psInfo->proppage[i].hpage);
2852 /* Unsubclass the page dialog window */
2853 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2854 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2855 (flags & PSP_HIDEHEADER))
2857 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2858 PROPSHEET_WizardSubclassProc, 1);
2861 if(psInfo->proppage[i].hwndPage)
2862 DestroyWindow(psInfo->proppage[i].hwndPage);
2864 if (flags & PSP_USETITLE)
2865 Free ((LPVOID)psInfo->proppage[i].pszText);
2867 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2870 DeleteObject(psInfo->hFont);
2871 DeleteObject(psInfo->hFontBold);
2872 /* If we created the bitmaps, destroy them */
2873 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2874 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2875 DeleteObject(psInfo->ppshheader.hbmWatermark);
2876 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2877 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2878 DeleteObject(psInfo->ppshheader.hbmHeader);
2880 Free(psInfo->proppage);
2881 Free(psInfo->strPropertiesFor);
2882 ImageList_Destroy(psInfo->hImageList);
2884 GlobalFree(psInfo);
2887 static INT do_loop(const PropSheetInfo *psInfo)
2889 MSG msg = { 0 };
2890 INT ret = 0;
2891 HWND hwnd = psInfo->hwnd;
2892 HWND parent = psInfo->ppshheader.hwndParent;
2894 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2896 if(ret == -1)
2897 break;
2899 if(!IsDialogMessageW(hwnd, &msg))
2901 TranslateMessage(&msg);
2902 DispatchMessageW(&msg);
2906 if(ret == 0 && msg.message)
2907 PostQuitMessage(msg.wParam);
2909 if(ret != -1)
2910 ret = psInfo->result;
2912 if(parent)
2913 EnableWindow(parent, TRUE);
2915 DestroyWindow(hwnd);
2916 return ret;
2919 /******************************************************************************
2920 * PROPSHEET_PropertySheet
2922 * Common code between PropertySheetA/W
2924 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2926 INT_PTR bRet = 0;
2927 HWND parent = NULL;
2928 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2929 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2931 psInfo->unicode = unicode;
2932 psInfo->ended = FALSE;
2934 if(!psInfo->isModeless)
2936 parent = psInfo->ppshheader.hwndParent;
2937 if (parent) EnableWindow(parent, FALSE);
2939 bRet = PROPSHEET_CreateDialog(psInfo);
2940 if(!psInfo->isModeless)
2941 bRet = do_loop(psInfo);
2942 return bRet;
2945 /******************************************************************************
2946 * PropertySheet (COMCTL32.@)
2947 * PropertySheetA (COMCTL32.@)
2949 * Creates a property sheet in the specified property sheet header.
2951 * RETURNS
2952 * Modal property sheets: Positive if successful or -1 otherwise.
2953 * Modeless property sheets: Property sheet handle.
2954 * Or:
2955 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2956 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2958 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2960 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2961 UINT i, n;
2962 const BYTE* pByte;
2964 TRACE("(%p)\n", lppsh);
2966 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2968 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2969 pByte = (const BYTE*) psInfo->ppshheader.ppsp;
2971 for (n = i = 0; i < lppsh->nPages; i++, n++)
2973 if (!psInfo->usePropPage)
2975 if (psInfo->ppshheader.phpage[i] &&
2976 psInfo->ppshheader.phpage[i]->magic == HPROPSHEETPAGE_MAGIC)
2978 psInfo->proppage[n].hpage = psInfo->ppshheader.phpage[i];
2980 else
2982 psInfo->proppage[n].hpage = CreatePropertySheetPageA(
2983 (const PROPSHEETPAGEA *)psInfo->ppshheader.phpage[i]);
2986 else
2988 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2989 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2992 if (!PROPSHEET_CollectPageInfo(psInfo->proppage[n].hpage, psInfo, n, TRUE))
2994 if (psInfo->usePropPage)
2995 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2996 n--;
2997 psInfo->nPages--;
3001 return PROPSHEET_PropertySheet(psInfo, FALSE);
3004 /******************************************************************************
3005 * PropertySheetW (COMCTL32.@)
3007 * See PropertySheetA.
3009 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
3011 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
3012 UINT i, n;
3013 const BYTE* pByte;
3015 TRACE("(%p)\n", lppsh);
3017 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
3019 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
3020 pByte = (const BYTE*) psInfo->ppshheader.ppsp;
3022 for (n = i = 0; i < lppsh->nPages; i++, n++)
3024 if (!psInfo->usePropPage)
3026 if (psInfo->ppshheader.phpage[i] &&
3027 psInfo->ppshheader.phpage[i]->magic == HPROPSHEETPAGE_MAGIC)
3029 psInfo->proppage[n].hpage = psInfo->ppshheader.phpage[i];
3031 else
3033 psInfo->proppage[n].hpage = CreatePropertySheetPageW(
3034 (const PROPSHEETPAGEW *)psInfo->ppshheader.phpage[i]);
3037 else
3039 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
3040 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
3043 if (!PROPSHEET_CollectPageInfo(psInfo->proppage[n].hpage, psInfo, n, TRUE))
3045 if (psInfo->usePropPage)
3046 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
3047 n--;
3048 psInfo->nPages--;
3052 return PROPSHEET_PropertySheet(psInfo, TRUE);
3055 /******************************************************************************
3056 * CreatePropertySheetPage (COMCTL32.@)
3057 * CreatePropertySheetPageA (COMCTL32.@)
3059 * Creates a new property sheet page.
3061 * RETURNS
3062 * Success: Handle to new property sheet page.
3063 * Failure: NULL.
3065 * NOTES
3066 * An application must use the PSM_ADDPAGE message to add the new page to
3067 * an existing property sheet.
3069 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
3070 LPCPROPSHEETPAGEA lpPropSheetPage)
3072 PROPSHEETPAGEA *ppsp;
3073 HPROPSHEETPAGE ret;
3075 if (lpPropSheetPage->dwSize < PROPSHEETPAGEA_V1_SIZE)
3076 return NULL;
3078 ret = Alloc(FIELD_OFFSET(struct _PSP, data[lpPropSheetPage->dwSize]));
3079 ret->magic = HPROPSHEETPAGE_MAGIC;
3080 ppsp = &ret->pspA;
3081 memcpy(ppsp, lpPropSheetPage, lpPropSheetPage->dwSize);
3083 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3085 if (!IS_INTRESOURCE( ppsp->pszTemplate ))
3086 ppsp->pszTemplate = heap_strdupA( lpPropSheetPage->pszTemplate );
3089 if (ppsp->dwFlags & PSP_USEICONID)
3091 if (!IS_INTRESOURCE( ppsp->pszIcon ))
3092 ppsp->pszIcon = heap_strdupA( lpPropSheetPage->pszIcon );
3095 if (ppsp->dwFlags & PSP_USETITLE)
3097 if (!IS_INTRESOURCE( ppsp->pszTitle ))
3098 ppsp->pszTitle = heap_strdupA( lpPropSheetPage->pszTitle );
3101 if (ppsp->dwFlags & PSP_HIDEHEADER)
3102 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3104 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3106 if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3107 ppsp->pszHeaderTitle = heap_strdupA( lpPropSheetPage->pszHeaderTitle );
3110 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3112 if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3113 ppsp->pszHeaderSubTitle = heap_strdupA( lpPropSheetPage->pszHeaderSubTitle );
3116 HPSP_call_callback(ret, PSPCB_ADDREF);
3117 return ret;
3120 /******************************************************************************
3121 * CreatePropertySheetPageW (COMCTL32.@)
3123 * See CreatePropertySheetA.
3125 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3127 PROPSHEETPAGEW *ppsp;
3128 HPROPSHEETPAGE ret;
3130 if (lpPropSheetPage->dwSize < PROPSHEETPAGEW_V1_SIZE)
3131 return NULL;
3133 ret = Alloc(FIELD_OFFSET(struct _PSP, data[lpPropSheetPage->dwSize]));
3134 ret->magic = HPROPSHEETPAGE_MAGIC;
3135 ret->unicode = TRUE;
3136 ppsp = &ret->pspW;
3137 memcpy(ppsp, lpPropSheetPage, lpPropSheetPage->dwSize);
3139 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3141 if (!IS_INTRESOURCE( ppsp->pszTemplate ))
3142 ppsp->pszTemplate = heap_strdupW( lpPropSheetPage->pszTemplate );
3145 if ( ppsp->dwFlags & PSP_USEICONID )
3147 if (!IS_INTRESOURCE( ppsp->pszIcon ))
3148 ppsp->pszIcon = heap_strdupW( lpPropSheetPage->pszIcon );
3151 if (ppsp->dwFlags & PSP_USETITLE)
3153 if (!IS_INTRESOURCE( ppsp->pszTitle ))
3154 ppsp->pszTitle = heap_strdupW( lpPropSheetPage->pszTitle );
3157 if (ppsp->dwFlags & PSP_HIDEHEADER)
3158 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3160 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3162 if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3163 ppsp->pszHeaderTitle = heap_strdupW( ppsp->pszHeaderTitle );
3166 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3168 if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3169 ppsp->pszHeaderSubTitle = heap_strdupW( ppsp->pszHeaderSubTitle );
3172 HPSP_call_callback(ret, PSPCB_ADDREF);
3173 return ret;
3176 /******************************************************************************
3177 * DestroyPropertySheetPage (COMCTL32.@)
3179 * Destroys a property sheet page previously created with
3180 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3181 * memory.
3183 * RETURNS
3184 * Success: TRUE
3185 * Failure: FALSE
3187 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hpsp)
3189 if (!hpsp)
3190 return FALSE;
3192 HPSP_call_callback(hpsp, PSPCB_RELEASE);
3194 if (hpsp->unicode)
3196 PROPSHEETPAGEW *psp = &hpsp->pspW;
3198 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE(psp->pszTemplate))
3199 Free((void *)psp->pszTemplate);
3201 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE(psp->pszIcon))
3202 Free((void *)psp->pszIcon);
3204 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE(psp->pszTitle))
3205 Free((void *)psp->pszTitle);
3207 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE(psp->pszHeaderTitle))
3208 Free((void *)psp->pszHeaderTitle);
3210 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE(psp->pszHeaderSubTitle))
3211 Free((void *)psp->pszHeaderSubTitle);
3213 else
3215 PROPSHEETPAGEA *psp = &hpsp->pspA;
3217 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE(psp->pszTemplate))
3218 Free((void *)psp->pszTemplate);
3220 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE(psp->pszIcon))
3221 Free((void *)psp->pszIcon);
3223 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE(psp->pszTitle))
3224 Free((void *)psp->pszTitle);
3226 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE(psp->pszHeaderTitle))
3227 Free((void *)psp->pszHeaderTitle);
3229 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE(psp->pszHeaderSubTitle))
3230 Free((void *)psp->pszHeaderSubTitle);
3233 Free(hpsp);
3234 return TRUE;
3237 /******************************************************************************
3238 * PROPSHEET_IsDialogMessage
3240 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3242 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3244 TRACE("\n");
3245 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3246 return FALSE;
3248 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3250 int new_page = 0;
3251 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3253 if (!(dlgCode & DLGC_WANTMESSAGE))
3255 switch (lpMsg->wParam)
3257 case VK_TAB:
3258 if (GetKeyState(VK_SHIFT) & 0x8000)
3259 new_page = -1;
3260 else
3261 new_page = 1;
3262 break;
3264 case VK_NEXT: new_page = 1; break;
3265 case VK_PRIOR: new_page = -1; break;
3269 if (new_page)
3271 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3273 new_page += psInfo->active_page;
3275 if (new_page < 0)
3276 new_page = psInfo->nPages - 1;
3277 else if (new_page >= psInfo->nPages)
3278 new_page = 0;
3280 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3283 return TRUE;
3287 return IsDialogMessageW(hwnd, lpMsg);
3290 /******************************************************************************
3291 * PROPSHEET_DoCommand
3293 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3296 switch (wID) {
3298 case IDOK:
3299 case IDC_APPLY_BUTTON:
3301 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3303 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3304 break;
3306 if (wID == IDOK)
3308 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3310 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3311 if (psInfo->result == 0)
3312 psInfo->result = IDOK;
3314 if (psInfo->isModeless)
3315 psInfo->activeValid = FALSE;
3316 else
3317 psInfo->ended = TRUE;
3319 else
3320 EnableWindow(hwndApplyBtn, FALSE);
3322 break;
3325 case IDC_BACK_BUTTON:
3326 PROPSHEET_Back(hwnd);
3327 break;
3329 case IDC_NEXT_BUTTON:
3330 PROPSHEET_Next(hwnd);
3331 break;
3333 case IDC_FINISH_BUTTON:
3334 PROPSHEET_Finish(hwnd);
3335 break;
3337 case IDCANCEL:
3338 PROPSHEET_Cancel(hwnd, 0);
3339 break;
3341 case IDHELP:
3342 PROPSHEET_Help(hwnd);
3343 break;
3345 default:
3346 return FALSE;
3349 return TRUE;
3352 /******************************************************************************
3353 * PROPSHEET_Paint
3355 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3357 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3358 PAINTSTRUCT ps;
3359 HDC hdc, hdcSrc;
3360 BITMAP bm;
3361 HBITMAP hbmp;
3362 HPALETTE hOldPal = 0;
3363 int offsety = 0;
3364 HBRUSH hbr;
3365 RECT r, rzone;
3366 HPROPSHEETPAGE hpsp;
3367 DWORD flags;
3369 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3370 if (!hdc) return 1;
3372 hdcSrc = CreateCompatibleDC(0);
3374 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3375 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3377 if (psInfo->active_page < 0)
3378 hpsp = NULL;
3379 else
3380 hpsp = psInfo->proppage[psInfo->active_page].hpage;
3381 flags = HPSP_get_flags(hpsp);
3383 if ( hpsp && !(flags & PSP_HIDEHEADER) &&
3384 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3385 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3387 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3388 HFONT hOldFont;
3389 COLORREF clrOld = 0;
3390 int oldBkMode = 0;
3392 GetClientRect(hwndLineHeader, &r);
3393 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3394 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3396 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3398 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3400 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.hbmHeader);
3402 GetObjectW(psInfo->ppshheader.hbmHeader, sizeof(BITMAP), &bm);
3403 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3405 /* Fill the unoccupied part of the header with color of the
3406 * left-top pixel, but do it only when needed.
3408 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3410 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3411 r = rzone;
3412 if (bm.bmWidth < r.right)
3414 r.left = bm.bmWidth;
3415 FillRect(hdc, &r, hbr);
3417 if (bm.bmHeight < r.bottom)
3419 r.left = 0;
3420 r.top = bm.bmHeight;
3421 FillRect(hdc, &r, hbr);
3423 DeleteObject(hbr);
3426 /* Draw the header itself. */
3427 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3428 hdcSrc, 0, 0, SRCCOPY);
3430 else
3432 int margin;
3433 hbr = GetSysColorBrush(COLOR_WINDOW);
3434 FillRect(hdc, &rzone, hbr);
3436 /* Draw the header bitmap. It's always centered like a
3437 * common 49 x 49 bitmap. */
3438 margin = (rzone.bottom - 49) / 2;
3439 BitBlt(hdc, rzone.right - 49 - margin, margin,
3440 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3441 hdcSrc, 0, 0, SRCCOPY);
3443 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3444 * if its height is smaller than 49 pixels. Because the reason
3445 * for this bug is unknown the current code doesn't try to
3446 * replicate it. */
3449 SelectObject(hdcSrc, hbmp);
3452 clrOld = SetTextColor (hdc, 0x00000000);
3453 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3455 if (flags & PSP_USEHEADERTITLE) {
3456 SetRect(&r, 20, 10, 0, 0);
3457 HPSP_draw_text(hpsp, hdc, TRUE, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3460 if (flags & PSP_USEHEADERSUBTITLE) {
3461 SelectObject(hdc, psInfo->hFont);
3462 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3463 HPSP_draw_text(hpsp, hdc, FALSE, &r, DT_LEFT | DT_WORDBREAK);
3466 offsety = rzone.bottom + 2;
3468 SetTextColor(hdc, clrOld);
3469 SetBkMode(hdc, oldBkMode);
3470 SelectObject(hdc, hOldFont);
3473 if ( (flags & PSP_HIDEHEADER) &&
3474 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3475 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3477 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3479 GetClientRect(hwndLine, &r);
3480 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3481 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3483 hbr = GetSysColorBrush(COLOR_WINDOW);
3484 FillRect(hdc, &rzone, hbr);
3486 GetObjectW(psInfo->ppshheader.hbmWatermark, sizeof(BITMAP), &bm);
3487 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.hbmWatermark);
3489 /* The watermark is truncated to a width of 164 pixels */
3490 r.right = min(r.right, 164);
3491 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3492 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3494 /* If the bitmap is not big enough, fill the remaining area
3495 with the color of pixel (0,0) of bitmap - see MSDN */
3496 if (r.top > bm.bmHeight) {
3497 r.bottom = r.top - 1;
3498 r.top = bm.bmHeight;
3499 r.left = 0;
3500 r.right = bm.bmWidth;
3501 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3502 FillRect(hdc, &r, hbr);
3503 DeleteObject(hbr);
3506 SelectObject(hdcSrc, hbmp);
3509 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3510 SelectPalette(hdc, hOldPal, FALSE);
3512 DeleteDC(hdcSrc);
3514 if (!hdcParam) EndPaint(hwnd, &ps);
3516 return 0;
3519 /******************************************************************************
3520 * PROPSHEET_DialogProc
3522 static INT_PTR CALLBACK
3523 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3525 TRACE("hwnd %p, msg=0x%04x, wparam %Ix, lparam %Ix\n", hwnd, uMsg, wParam, lParam);
3527 switch (uMsg)
3529 case WM_INITDIALOG:
3531 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3532 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3533 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3534 int idx;
3535 LOGFONTW logFont;
3537 /* Using PropSheetInfoStr to store extra data doesn't match the native
3538 * common control: native uses TCM_[GS]ETITEM
3540 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3543 * psInfo->hwnd is not being used by WINE code - it exists
3544 * for compatibility with "real" Windoze. The same about
3545 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3546 * property.
3548 psInfo->hwnd = hwnd;
3549 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3551 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3553 /* set up the Next and Back buttons by default */
3554 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3557 /* Set up fonts */
3558 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3559 psInfo->hFont = CreateFontIndirectW (&logFont);
3560 logFont.lfWeight = FW_BOLD;
3561 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3564 * Small icon in the title bar.
3566 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3567 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3569 HICON hIcon;
3570 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3571 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3573 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3574 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3575 psInfo->ppshheader.pszIcon,
3576 IMAGE_ICON,
3577 icon_cx, icon_cy,
3578 LR_DEFAULTCOLOR);
3579 else
3580 hIcon = psInfo->ppshheader.hIcon;
3582 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3585 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3586 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.hIcon);
3588 psInfo->strPropertiesFor = strCaption;
3590 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3592 PROPSHEET_CreateTabControl(hwnd, psInfo);
3594 PROPSHEET_LoadWizardBitmaps(psInfo);
3596 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3598 ShowWindow(hwndTabCtrl, SW_HIDE);
3599 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3600 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3601 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3603 else
3605 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3607 PROPSHEET_AdjustSize(hwnd, psInfo);
3608 PROPSHEET_AdjustButtons(hwnd, psInfo);
3610 SetFocus(GetDlgItem(hwnd, IDOK));
3613 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3614 psInfo->ppshheader.hInstance)
3616 WCHAR szText[256];
3618 if (LoadStringW(psInfo->ppshheader.hInstance,
3619 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3620 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3622 else
3624 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3625 psInfo->ppshheader.pszCaption);
3629 if (psInfo->useCallback)
3630 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3632 idx = psInfo->active_page;
3633 psInfo->active_page = -1;
3635 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3637 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3638 * as some programs call TCM_GETCURSEL to get the current selection
3639 * from which to switch to the next page */
3640 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3642 PROPSHEET_UnChanged(hwnd, NULL);
3644 /* wizards set their focus during init */
3645 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3646 return FALSE;
3648 return TRUE;
3651 case WM_PRINTCLIENT:
3652 case WM_PAINT:
3653 PROPSHEET_Paint(hwnd, (HDC)wParam);
3654 return TRUE;
3656 case WM_DESTROY:
3657 PROPSHEET_CleanUp(hwnd);
3658 return TRUE;
3660 case WM_CLOSE:
3661 PROPSHEET_Cancel(hwnd, 1);
3662 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3664 case WM_COMMAND:
3665 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3667 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3669 if (!psInfo)
3670 return FALSE;
3672 /* No default handler, forward notification to active page */
3673 if (psInfo->activeValid && psInfo->active_page != -1)
3675 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3676 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3679 return TRUE;
3681 case WM_NOTIFY:
3683 NMHDR* pnmh = (LPNMHDR) lParam;
3685 if (pnmh->code == TCN_SELCHANGE)
3687 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3688 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3691 if(pnmh->code == TCN_SELCHANGING)
3693 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3694 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3695 return TRUE;
3698 return FALSE;
3701 case WM_SYSCOLORCHANGE:
3702 COMCTL32_RefreshSysColors();
3703 return FALSE;
3705 case PSM_GETCURRENTPAGEHWND:
3707 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3708 HWND hwndPage = 0;
3710 if (!psInfo)
3711 return FALSE;
3713 if (psInfo->activeValid && psInfo->active_page != -1)
3714 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3716 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3718 return TRUE;
3721 case PSM_CHANGED:
3722 PROPSHEET_Changed(hwnd, (HWND)wParam);
3723 return TRUE;
3725 case PSM_UNCHANGED:
3726 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3727 return TRUE;
3729 case PSM_GETTABCONTROL:
3731 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3733 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3735 return TRUE;
3738 case PSM_SETCURSEL:
3740 BOOL msgResult;
3742 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3743 if(msgResult != FALSE)
3745 msgResult = PROPSHEET_SetCurSel(hwnd,
3746 (int)wParam,
3748 (HPROPSHEETPAGE)lParam);
3751 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3753 return TRUE;
3756 case PSM_CANCELTOCLOSE:
3758 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3759 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3760 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3762 EnableWindow(hwndCancel, FALSE);
3763 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, ARRAY_SIZE(buf)))
3764 SetWindowTextW(hwndOK, buf);
3766 return FALSE;
3769 case PSM_RESTARTWINDOWS:
3771 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3773 if (!psInfo)
3774 return FALSE;
3776 /* reboot system takes precedence over restart windows */
3777 if (psInfo->result != ID_PSREBOOTSYSTEM)
3778 psInfo->result = ID_PSRESTARTWINDOWS;
3780 return TRUE;
3783 case PSM_REBOOTSYSTEM:
3785 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3787 if (!psInfo)
3788 return FALSE;
3790 psInfo->result = ID_PSREBOOTSYSTEM;
3792 return TRUE;
3795 case PSM_SETTITLEA:
3796 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3797 return TRUE;
3799 case PSM_SETTITLEW:
3800 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3801 return TRUE;
3803 case PSM_APPLY:
3805 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3807 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3809 return TRUE;
3812 case PSM_QUERYSIBLINGS:
3814 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3816 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3818 return TRUE;
3821 case PSM_ADDPAGE:
3824 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3825 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3826 * on success or FALSE otherwise, as specified on MSDN Online.
3827 * Also see the MFC code for
3828 * CPropertySheet::AddPage(CPropertyPage* pPage).
3831 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3833 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3835 return TRUE;
3838 case PSM_REMOVEPAGE:
3839 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3840 return TRUE;
3842 case PSM_ISDIALOGMESSAGE:
3844 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3845 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3846 return TRUE;
3849 case PSM_PRESSBUTTON:
3850 PROPSHEET_PressButton(hwnd, (int)wParam);
3851 return TRUE;
3853 case PSM_SETFINISHTEXTA:
3854 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3855 return TRUE;
3857 case PSM_SETWIZBUTTONS:
3858 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3859 return TRUE;
3861 case PSM_SETCURSELID:
3862 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3863 return TRUE;
3865 case PSM_SETFINISHTEXTW:
3866 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3867 return FALSE;
3869 case PSM_INSERTPAGE:
3871 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3872 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3873 return TRUE;
3876 case PSM_SETHEADERTITLEW:
3877 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3878 return TRUE;
3880 case PSM_SETHEADERTITLEA:
3881 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3882 return TRUE;
3884 case PSM_SETHEADERSUBTITLEW:
3885 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3886 return TRUE;
3888 case PSM_SETHEADERSUBTITLEA:
3889 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3890 return TRUE;
3892 case PSM_HWNDTOINDEX:
3894 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3895 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3896 return TRUE;
3899 case PSM_INDEXTOHWND:
3901 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3902 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3903 return TRUE;
3906 case PSM_PAGETOINDEX:
3908 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3909 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3910 return TRUE;
3913 case PSM_INDEXTOPAGE:
3915 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3916 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3917 return TRUE;
3920 case PSM_IDTOINDEX:
3922 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3923 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3924 return TRUE;
3927 case PSM_INDEXTOID:
3929 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3930 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3931 return TRUE;
3934 case PSM_GETRESULT:
3936 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3937 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3938 return TRUE;
3941 case PSM_RECALCPAGESIZES:
3943 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3944 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3945 return TRUE;
3948 default:
3949 return FALSE;