Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / comctl32 / propsheet.c
blob7a29a126cb4c591a796964d7e7743063df3dfa82
1 /*
2 * Property Sheets
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_INSERTPAGE
36 * o PSM_RECALCPAGESIZES
37 * o PSM_SETHEADERSUBTITLE
38 * o PSM_SETHEADERTITLE
39 * o WM_HELP
40 * o WM_CONTEXTMENU
41 * - Notifications:
42 * o PSN_GETOBJECT
43 * o PSN_QUERYINITIALFOCUS
44 * o PSN_TRANSLATEACCELERATOR
45 * - Styles:
46 * o PSH_RTLREADING
47 * o PSH_STRETCHWATERMARK
48 * o PSH_USEPAGELANG
49 * o PSH_USEPSTARTPAGE
50 * - Page styles:
51 * o PSP_USEFUSIONCONTEXT
52 * o PSP_USEREFPARENT
55 #include <stdarg.h>
56 #include <string.h>
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winuser.h"
64 #include "winnls.h"
65 #include "commctrl.h"
66 #include "prsht.h"
67 #include "comctl32.h"
68 #include "uxtheme.h"
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
73 /******************************************************************************
74 * Data structures
76 #include "pshpack2.h"
78 typedef struct
80 WORD dlgVer;
81 WORD signature;
82 DWORD helpID;
83 DWORD exStyle;
84 DWORD style;
85 } MyDLGTEMPLATEEX;
87 typedef struct
89 DWORD helpid;
90 DWORD exStyle;
91 DWORD style;
92 short x;
93 short y;
94 short cx;
95 short cy;
96 DWORD id;
97 } MyDLGITEMTEMPLATEEX;
98 #include "poppack.h"
100 typedef struct tagPropPageInfo
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 HWND hwndPage;
104 BOOL isDirty;
105 LPCWSTR pszText;
106 BOOL hasHelp;
107 BOOL useCallback;
108 BOOL hasIcon;
109 } PropPageInfo;
111 typedef struct tagPropSheetInfo
113 HWND hwnd;
114 PROPSHEETHEADERW ppshheader;
115 BOOL unicode;
116 LPWSTR strPropertiesFor;
117 int nPages;
118 int active_page;
119 BOOL isModeless;
120 BOOL hasHelp;
121 BOOL hasApply;
122 BOOL hasFinish;
123 BOOL useCallback;
124 BOOL activeValid;
125 PropPageInfo* proppage;
126 HFONT hFont;
127 HFONT hFontBold;
128 int width;
129 int height;
130 HIMAGELIST hImageList;
131 BOOL ended;
132 INT result;
133 } PropSheetInfo;
135 typedef struct
137 int x;
138 int y;
139 } PADDING_INFO;
141 /******************************************************************************
142 * Defines and global variables
145 static const WCHAR PropSheetInfoStr[] =
146 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
148 #define PSP_INTERNAL_UNICODE 0x80000000
150 #define MAX_CAPTION_LENGTH 255
151 #define MAX_TABTEXT_LENGTH 255
152 #define MAX_BUTTONTEXT_LENGTH 64
154 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
156 /* Wizard metrics specified in DLUs */
157 #define WIZARD_PADDING 7
158 #define WIZARD_HEADER_HEIGHT 36
160 /******************************************************************************
161 * Prototypes
163 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
164 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
165 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
166 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
167 int index,
168 int skipdir,
169 HPROPSHEETPAGE hpage);
170 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
171 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
172 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 static INT_PTR CALLBACK
175 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
179 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
180 /******************************************************************************
181 * PROPSHEET_UnImplementedFlags
183 * Document use of flags we don't implement yet.
185 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
187 CHAR string[256];
189 string[0] = '\0';
192 * unhandled header flags:
193 * PSH_RTLREADING 0x00000800
194 * PSH_STRETCHWATERMARK 0x00040000
195 * PSH_USEPAGELANG 0x00200000
198 add_flag(PSH_RTLREADING);
199 add_flag(PSH_STRETCHWATERMARK);
200 add_flag(PSH_USEPAGELANG);
201 if (string[0] != '\0')
202 FIXME("%s\n", string);
204 #undef add_flag
206 /******************************************************************************
207 * PROPSHEET_GetPageRect
209 * Retrieve rect from tab control and map into the dialog for SetWindowPos
211 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
212 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
214 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
215 HWND hwndChild;
216 RECT r;
218 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
219 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
220 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
221 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
223 rc->left = rc->top = WIZARD_PADDING;
225 else
227 rc->left = rc->top = 0;
229 rc->right = psInfo->width - rc->left;
230 rc->bottom = psInfo->height - rc->top;
231 MapDialogRect(hwndDlg, rc);
233 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
234 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
235 !(ppshpage->dwFlags & PSP_HIDEHEADER))
237 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
238 GetClientRect(hwndChild, &r);
239 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
240 rc->top += r.bottom + 1;
242 } else {
243 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
244 GetClientRect(hwndTabCtrl, rc);
245 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
246 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
250 /******************************************************************************
251 * PROPSHEET_FindPageByResId
253 * Find page index corresponding to page resource id.
255 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
257 INT i;
259 for (i = 0; i < psInfo->nPages; i++)
261 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
263 /* Fixme: if resource ID is a string shall we use strcmp ??? */
264 if (lppsp->u.pszTemplate == (LPVOID)resId)
265 break;
268 return i;
271 /******************************************************************************
272 * PROPSHEET_AtoW
274 * Convert ASCII to Unicode since all data is saved as Unicode.
276 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
278 INT len;
279 WCHAR *to;
281 TRACE("<%s>\n", frstr);
282 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
283 to = Alloc(len * sizeof(WCHAR));
284 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
285 *tostr = to;
288 /******************************************************************************
289 * PROPSHEET_CollectSheetInfoA
291 * Collect relevant data.
293 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
294 PropSheetInfo * psInfo)
296 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
297 DWORD dwFlags = lppsh->dwFlags;
299 psInfo->hasHelp = dwFlags & PSH_HASHELP;
300 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
301 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
302 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
303 psInfo->isModeless = dwFlags & PSH_MODELESS;
305 memcpy(&psInfo->ppshheader,lppsh,dwSize);
306 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
307 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
308 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
310 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
312 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
313 psInfo->ppshheader.pszCaption = NULL;
314 else
316 if (HIWORD(lppsh->pszCaption))
318 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
319 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
321 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
322 psInfo->ppshheader.pszCaption = caption;
325 psInfo->nPages = lppsh->nPages;
327 if (dwFlags & PSH_USEPSTARTPAGE)
329 TRACE("PSH_USEPSTARTPAGE is on\n");
330 psInfo->active_page = 0;
332 else
333 psInfo->active_page = lppsh->u2.nStartPage;
335 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
336 psInfo->active_page = 0;
338 psInfo->result = 0;
339 psInfo->hImageList = 0;
340 psInfo->activeValid = FALSE;
342 return TRUE;
345 /******************************************************************************
346 * PROPSHEET_CollectSheetInfoW
348 * Collect relevant data.
350 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
351 PropSheetInfo * psInfo)
353 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
354 DWORD dwFlags = lppsh->dwFlags;
356 psInfo->hasHelp = dwFlags & PSH_HASHELP;
357 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
358 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
359 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
360 psInfo->isModeless = dwFlags & PSH_MODELESS;
362 memcpy(&psInfo->ppshheader,lppsh,dwSize);
363 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
364 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
366 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
368 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
369 psInfo->ppshheader.pszCaption = NULL;
370 else
372 if (HIWORD(lppsh->pszCaption))
374 int len = strlenW(lppsh->pszCaption);
375 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
377 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
380 psInfo->nPages = lppsh->nPages;
382 if (dwFlags & PSH_USEPSTARTPAGE)
384 TRACE("PSH_USEPSTARTPAGE is on\n");
385 psInfo->active_page = 0;
387 else
388 psInfo->active_page = lppsh->u2.nStartPage;
390 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
391 psInfo->active_page = 0;
393 psInfo->result = 0;
394 psInfo->hImageList = 0;
395 psInfo->activeValid = FALSE;
397 return TRUE;
400 /******************************************************************************
401 * PROPSHEET_CollectPageInfo
403 * Collect property sheet data.
404 * With code taken from DIALOG_ParseTemplate32.
406 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
407 PropSheetInfo * psInfo,
408 int index)
410 const DLGTEMPLATE* pTemplate;
411 const WORD* p;
412 DWORD dwFlags;
413 int width, height;
415 if (!lppsp)
416 return FALSE;
418 TRACE("\n");
419 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
420 psInfo->proppage[index].hwndPage = 0;
421 psInfo->proppage[index].isDirty = FALSE;
424 * Process property page flags.
426 dwFlags = lppsp->dwFlags;
427 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
428 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
429 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
431 /* as soon as we have a page with the help flag, set the sheet flag on */
432 if (psInfo->proppage[index].hasHelp)
433 psInfo->hasHelp = TRUE;
436 * Process page template.
438 if (dwFlags & PSP_DLGINDIRECT)
439 pTemplate = lppsp->u.pResource;
440 else if(dwFlags & PSP_INTERNAL_UNICODE )
442 HRSRC hResource = FindResourceW(lppsp->hInstance,
443 lppsp->u.pszTemplate,
444 (LPWSTR)RT_DIALOG);
445 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
446 hResource);
447 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
449 else
451 HRSRC hResource = FindResourceA(lppsp->hInstance,
452 (LPCSTR)lppsp->u.pszTemplate,
453 (LPSTR)RT_DIALOG);
454 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
455 hResource);
456 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
460 * Extract the size of the page and the caption.
462 if (!pTemplate)
463 return FALSE;
465 p = (const WORD *)pTemplate;
467 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
469 /* DLGTEMPLATEEX (not defined in any std. header file) */
471 p++; /* dlgVer */
472 p++; /* signature */
473 p += 2; /* help ID */
474 p += 2; /* ext style */
475 p += 2; /* style */
477 else
479 /* DLGTEMPLATE */
481 p += 2; /* style */
482 p += 2; /* ext style */
485 p++; /* nb items */
486 p++; /* x */
487 p++; /* y */
488 width = (WORD)*p; p++;
489 height = (WORD)*p; p++;
491 /* Special calculation for interior wizard pages so the largest page is
492 * calculated correctly. We need to add all the padding and space occupied
493 * by the header so the width and height sums up to the whole wizard client
494 * area. */
495 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
496 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
497 !(dwFlags & PSP_HIDEHEADER))
499 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
500 width += 2 * WIZARD_PADDING;
502 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
504 height += 2 * WIZARD_PADDING;
505 width += 2 * WIZARD_PADDING;
508 /* remember the largest width and height */
509 if (width > psInfo->width)
510 psInfo->width = width;
512 if (height > psInfo->height)
513 psInfo->height = height;
515 /* menu */
516 switch ((WORD)*p)
518 case 0x0000:
519 p++;
520 break;
521 case 0xffff:
522 p += 2;
523 break;
524 default:
525 p += lstrlenW( (LPCWSTR)p ) + 1;
526 break;
529 /* class */
530 switch ((WORD)*p)
532 case 0x0000:
533 p++;
534 break;
535 case 0xffff:
536 p += 2;
537 break;
538 default:
539 p += lstrlenW( (LPCWSTR)p ) + 1;
540 break;
543 /* Extract the caption */
544 psInfo->proppage[index].pszText = (LPCWSTR)p;
545 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
546 p += lstrlenW((LPCWSTR)p) + 1;
548 if (dwFlags & PSP_USETITLE)
550 WCHAR szTitle[256];
551 const WCHAR *pTitle;
552 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
553 WCHAR *text;
554 int len;
556 if ( !HIWORD( lppsp->pszTitle ) )
558 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
560 pTitle = pszNull;
561 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
563 else
564 pTitle = szTitle;
566 else
567 pTitle = lppsp->pszTitle;
569 len = strlenW(pTitle);
570 text = Alloc( (len+1)*sizeof (WCHAR) );
571 psInfo->proppage[index].pszText = strcpyW( text, pTitle);
575 * Build the image list for icons
577 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
579 HICON hIcon;
580 int icon_cx = GetSystemMetrics(SM_CXSMICON);
581 int icon_cy = GetSystemMetrics(SM_CYSMICON);
583 if (dwFlags & PSP_USEICONID)
584 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
585 icon_cx, icon_cy, LR_DEFAULTCOLOR);
586 else
587 hIcon = lppsp->u2.hIcon;
589 if ( hIcon )
591 if (psInfo->hImageList == 0 )
592 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
594 ImageList_AddIcon(psInfo->hImageList, hIcon);
599 return TRUE;
602 /******************************************************************************
603 * PROPSHEET_CreateDialog
605 * Creates the actual property sheet.
607 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
609 LRESULT ret;
610 LPCVOID template;
611 LPVOID temp = 0;
612 HRSRC hRes;
613 DWORD resSize;
614 WORD resID = IDD_PROPSHEET;
616 TRACE("\n");
617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
618 resID = IDD_WIZARD;
620 if( psInfo->unicode )
622 if(!(hRes = FindResourceW(COMCTL32_hModule,
623 MAKEINTRESOURCEW(resID),
624 (LPWSTR)RT_DIALOG)))
625 return -1;
627 else
629 if(!(hRes = FindResourceA(COMCTL32_hModule,
630 MAKEINTRESOURCEA(resID),
631 (LPSTR)RT_DIALOG)))
632 return -1;
635 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
636 return -1;
639 * Make a copy of the dialog template.
641 resSize = SizeofResource(COMCTL32_hModule, hRes);
643 temp = Alloc(resSize);
645 if (!temp)
646 return -1;
648 memcpy(temp, template, resSize);
650 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
654 else
655 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
657 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
658 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
660 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
661 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
662 else
663 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
666 if (psInfo->useCallback)
667 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
669 /* NOTE: MSDN states "Returns a positive value if successful, or -1
670 * otherwise for modal property sheets.", but this is wrong. The
671 * actual return value is either TRUE (success), FALSE (cancel) or
672 * -1 (error). */
673 if( psInfo->unicode )
675 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
676 (LPDLGTEMPLATEW) temp,
677 psInfo->ppshheader.hwndParent,
678 PROPSHEET_DialogProc,
679 (LPARAM)psInfo);
680 if ( !ret ) ret = -1;
682 else
684 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
685 (LPDLGTEMPLATEA) temp,
686 psInfo->ppshheader.hwndParent,
687 PROPSHEET_DialogProc,
688 (LPARAM)psInfo);
689 if ( !ret ) ret = -1;
692 Free(temp);
694 return ret;
697 /******************************************************************************
698 * PROPSHEET_SizeMismatch
700 * Verify that the tab control and the "largest" property sheet page dlg. template
701 * match in size.
703 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
705 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
706 RECT rcOrigTab, rcPage;
709 * Original tab size.
711 GetClientRect(hwndTabCtrl, &rcOrigTab);
712 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
713 rcOrigTab.right, rcOrigTab.bottom);
716 * Biggest page size.
718 rcPage.left = 0;
719 rcPage.top = 0;
720 rcPage.right = psInfo->width;
721 rcPage.bottom = psInfo->height;
723 MapDialogRect(hwndDlg, &rcPage);
724 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
725 rcPage.right, rcPage.bottom);
727 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
728 return TRUE;
729 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
730 return TRUE;
732 return FALSE;
735 /******************************************************************************
736 * PROPSHEET_AdjustSize
738 * Resizes the property sheet and the tab control to fit the largest page.
740 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
742 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
743 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
744 RECT rc,tabRect;
745 int tabOffsetX, tabOffsetY, buttonHeight;
746 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
747 RECT units;
749 /* Get the height of buttons */
750 GetClientRect(hwndButton, &rc);
751 buttonHeight = rc.bottom;
754 * Biggest page size.
756 rc.left = 0;
757 rc.top = 0;
758 rc.right = psInfo->width;
759 rc.bottom = psInfo->height;
761 MapDialogRect(hwndDlg, &rc);
763 /* retrieve the dialog units */
764 units.left = units.right = 4;
765 units.top = units.bottom = 8;
766 MapDialogRect(hwndDlg, &units);
769 * Resize the tab control.
771 GetClientRect(hwndTabCtrl,&tabRect);
773 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
775 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
777 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
778 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
781 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
783 rc.right = rc.left + tabRect.right - tabRect.left;
784 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
787 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
789 tabOffsetX = -(rc.left);
790 tabOffsetY = -(rc.top);
792 rc.right -= rc.left;
793 rc.bottom -= rc.top;
794 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
795 hwndTabCtrl, rc.right, rc.bottom);
796 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
797 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
799 GetClientRect(hwndTabCtrl, &rc);
801 TRACE("tab client rc %d %d %d %d\n",
802 rc.left, rc.top, rc.right, rc.bottom);
804 rc.right += ((padding.x * 2) + tabOffsetX);
805 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
808 * Resize the property sheet.
810 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
811 hwndDlg, rc.right, rc.bottom);
812 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
813 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
814 return TRUE;
817 /******************************************************************************
818 * PROPSHEET_AdjustSizeWizard
820 * Resizes the property sheet to fit the largest page.
822 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
824 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
825 RECT rc, lineRect, dialogRect;
827 /* Biggest page size */
828 rc.left = 0;
829 rc.top = 0;
830 rc.right = psInfo->width;
831 rc.bottom = psInfo->height;
832 MapDialogRect(hwndDlg, &rc);
834 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
836 /* Add space for the buttons row */
837 GetWindowRect(hwndLine, &lineRect);
838 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
839 GetClientRect(hwndDlg, &dialogRect);
840 rc.bottom += dialogRect.bottom - lineRect.top - 1;
842 /* Convert the client coordinates to window coordinates */
843 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
845 /* Resize the property sheet */
846 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
847 hwndDlg, rc.right, rc.bottom);
848 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
849 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
851 return TRUE;
854 /******************************************************************************
855 * PROPSHEET_AdjustButtons
857 * Adjusts the buttons' positions.
859 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
861 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
862 RECT rcSheet;
863 int x, y;
864 int num_buttons = 2;
865 int buttonWidth, buttonHeight;
866 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
868 if (psInfo->hasApply)
869 num_buttons++;
871 if (psInfo->hasHelp)
872 num_buttons++;
875 * Obtain the size of the buttons.
877 GetClientRect(hwndButton, &rcSheet);
878 buttonWidth = rcSheet.right;
879 buttonHeight = rcSheet.bottom;
882 * Get the size of the property sheet.
884 GetClientRect(hwndParent, &rcSheet);
887 * All buttons will be at this y coordinate.
889 y = rcSheet.bottom - (padding.y + buttonHeight);
892 * Position OK button and make it default.
894 hwndButton = GetDlgItem(hwndParent, IDOK);
896 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
898 SetWindowPos(hwndButton, 0, x, y, 0, 0,
899 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
901 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
905 * Position Cancel button.
907 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
909 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
911 SetWindowPos(hwndButton, 0, x, y, 0, 0,
912 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
915 * Position Apply button.
917 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
919 if (psInfo->hasApply)
921 if (psInfo->hasHelp)
922 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
923 else
924 x = rcSheet.right - (padding.x + buttonWidth);
926 SetWindowPos(hwndButton, 0, x, y, 0, 0,
927 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
929 EnableWindow(hwndButton, FALSE);
931 else
932 ShowWindow(hwndButton, SW_HIDE);
935 * Position Help button.
937 hwndButton = GetDlgItem(hwndParent, IDHELP);
939 if (psInfo->hasHelp)
941 x = rcSheet.right - (padding.x + buttonWidth);
943 SetWindowPos(hwndButton, 0, x, y, 0, 0,
944 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
946 else
947 ShowWindow(hwndButton, SW_HIDE);
949 return TRUE;
952 /******************************************************************************
953 * PROPSHEET_AdjustButtonsWizard
955 * Adjusts the buttons' positions.
957 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
958 PropSheetInfo* psInfo)
960 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
961 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
962 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
963 RECT rcSheet;
964 int x, y;
965 int num_buttons = 3;
966 int buttonWidth, buttonHeight, lineHeight, lineWidth;
967 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
969 if (psInfo->hasHelp)
970 num_buttons++;
971 if (psInfo->hasFinish)
972 num_buttons++;
975 * Obtain the size of the buttons.
977 GetClientRect(hwndButton, &rcSheet);
978 buttonWidth = rcSheet.right;
979 buttonHeight = rcSheet.bottom;
981 GetClientRect(hwndLine, &rcSheet);
982 lineHeight = rcSheet.bottom;
985 * Get the size of the property sheet.
987 GetClientRect(hwndParent, &rcSheet);
990 * All buttons will be at this y coordinate.
992 y = rcSheet.bottom - (padding.y + buttonHeight);
995 * Position the Back button.
997 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
999 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1001 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1002 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1005 * Position the Next button.
1007 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1009 x += buttonWidth;
1011 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1012 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1015 * Position the Finish button.
1017 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1019 if (psInfo->hasFinish)
1020 x += padding.x + buttonWidth;
1022 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1023 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1025 if (!psInfo->hasFinish)
1026 ShowWindow(hwndButton, SW_HIDE);
1029 * Position the Cancel button.
1031 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1033 x += padding.x + buttonWidth;
1035 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1036 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1039 * Position Help button.
1041 hwndButton = GetDlgItem(hwndParent, IDHELP);
1043 if (psInfo->hasHelp)
1045 x += padding.x + buttonWidth;
1047 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1048 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1050 else
1051 ShowWindow(hwndButton, SW_HIDE);
1053 if (psInfo->ppshheader.dwFlags &
1054 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1055 padding.x = 0;
1058 * Position and resize the sunken line.
1060 x = padding.x;
1061 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1063 lineWidth = rcSheet.right - (padding.x * 2);
1064 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1065 SWP_NOZORDER | SWP_NOACTIVATE);
1068 * Position and resize the header sunken line.
1071 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1072 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1073 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1074 ShowWindow(hwndLineHeader, SW_HIDE);
1076 return TRUE;
1079 /******************************************************************************
1080 * PROPSHEET_GetPaddingInfo
1082 * Returns the layout information.
1084 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1086 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1087 RECT rcTab;
1088 POINT tl;
1089 PADDING_INFO padding;
1091 GetWindowRect(hwndTab, &rcTab);
1093 tl.x = rcTab.left;
1094 tl.y = rcTab.top;
1096 ScreenToClient(hwndDlg, &tl);
1098 padding.x = tl.x;
1099 padding.y = tl.y;
1101 return padding;
1104 /******************************************************************************
1105 * PROPSHEET_GetPaddingInfoWizard
1107 * Returns the layout information.
1108 * Vertical spacing is the distance between the line and the buttons.
1109 * Do NOT use the Help button to gather padding information when it isn't mapped
1110 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1111 * for it in this case !
1112 * FIXME: I'm not sure about any other coordinate problems with these evil
1113 * buttons. Fix it in case additional problems appear or maybe calculate
1114 * a padding in a completely different way, as this is somewhat messy.
1116 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1117 psInfo)
1119 PADDING_INFO padding;
1120 RECT rc;
1121 HWND hwndControl;
1122 INT idButton;
1123 POINT ptButton, ptLine;
1125 TRACE("\n");
1126 if (psInfo->hasHelp)
1128 idButton = IDHELP;
1130 else
1132 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1134 idButton = IDC_NEXT_BUTTON;
1136 else
1138 /* hopefully this is ok */
1139 idButton = IDCANCEL;
1143 hwndControl = GetDlgItem(hwndDlg, idButton);
1144 GetWindowRect(hwndControl, &rc);
1146 ptButton.x = rc.left;
1147 ptButton.y = rc.top;
1149 ScreenToClient(hwndDlg, &ptButton);
1151 /* Line */
1152 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1153 GetWindowRect(hwndControl, &rc);
1155 ptLine.x = rc.left;
1156 ptLine.y = rc.bottom;
1158 ScreenToClient(hwndDlg, &ptLine);
1160 padding.y = ptButton.y - ptLine.y;
1162 if (padding.y < 0)
1163 ERR("padding negative ! Please report this !\n");
1165 /* this is most probably not correct, but the best we have now */
1166 padding.x = padding.y;
1167 return padding;
1170 /******************************************************************************
1171 * PROPSHEET_CreateTabControl
1173 * Insert the tabs in the tab control.
1175 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1176 PropSheetInfo * psInfo)
1178 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1179 TCITEMW item;
1180 int i, nTabs;
1181 int iImage = 0;
1183 TRACE("\n");
1184 item.mask = TCIF_TEXT;
1185 item.cchTextMax = MAX_TABTEXT_LENGTH;
1187 nTabs = psInfo->nPages;
1190 * Set the image list for icons.
1192 if (psInfo->hImageList)
1194 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1197 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1198 for (i = 0; i < nTabs; i++)
1200 if ( psInfo->proppage[i].hasIcon )
1202 item.mask |= TCIF_IMAGE;
1203 item.iImage = iImage++;
1205 else
1207 item.mask &= ~TCIF_IMAGE;
1210 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1211 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1213 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1215 return TRUE;
1218 /******************************************************************************
1219 * PROPSHEET_WizardSubclassProc
1221 * Subclassing window procedure for wizard extrior pages to prevent drawing
1222 * background and so drawing above the watermark.
1224 static LRESULT CALLBACK
1225 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1227 switch (uMsg)
1229 case WM_ERASEBKGND:
1230 return TRUE;
1232 case WM_CTLCOLORSTATIC:
1233 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1234 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1237 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1241 * Get the size of an in-memory Template
1243 *( Based on the code of PROPSHEET_CollectPageInfo)
1244 * See also dialog.c/DIALOG_ParseTemplate32().
1247 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1250 const WORD* p = (const WORD *)pTemplate;
1251 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1252 WORD nrofitems;
1253 UINT ret;
1255 if (istemplateex)
1257 /* DLGTEMPLATEEX (not defined in any std. header file) */
1259 TRACE("is DLGTEMPLATEEX\n");
1260 p++; /* dlgVer */
1261 p++; /* signature */
1262 p += 2; /* help ID */
1263 p += 2; /* ext style */
1264 p += 2; /* style */
1266 else
1268 /* DLGTEMPLATE */
1270 TRACE("is DLGTEMPLATE\n");
1271 p += 2; /* style */
1272 p += 2; /* ext style */
1275 nrofitems = (WORD)*p; p++; /* nb items */
1276 p++; /* x */
1277 p++; /* y */
1278 p++; /* width */
1279 p++; /* height */
1281 /* menu */
1282 switch ((WORD)*p)
1284 case 0x0000:
1285 p++;
1286 break;
1287 case 0xffff:
1288 p += 2;
1289 break;
1290 default:
1291 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1292 p += lstrlenW( (LPCWSTR)p ) + 1;
1293 break;
1296 /* class */
1297 switch ((WORD)*p)
1299 case 0x0000:
1300 p++;
1301 break;
1302 case 0xffff:
1303 p += 2; /* 0xffff plus predefined window class ordinal value */
1304 break;
1305 default:
1306 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1307 p += lstrlenW( (LPCWSTR)p ) + 1;
1308 break;
1311 /* title */
1312 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1313 p += lstrlenW((LPCWSTR)p) + 1;
1315 /* font, if DS_SETFONT set */
1316 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1317 pTemplate->style)))
1319 p+=(istemplateex)?3:1;
1320 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1321 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1324 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1325 * that are following the DLGTEMPLATE(EX) data */
1326 TRACE("%d items\n",nrofitems);
1327 while (nrofitems > 0)
1329 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1331 /* skip header */
1332 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1334 /* check class */
1335 switch ((WORD)*p)
1337 case 0x0000:
1338 p++;
1339 break;
1340 case 0xffff:
1341 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1342 p += 2;
1343 break;
1344 default:
1345 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1346 p += lstrlenW( (LPCWSTR)p ) + 1;
1347 break;
1350 /* check title text */
1351 switch ((WORD)*p)
1353 case 0x0000:
1354 p++;
1355 break;
1356 case 0xffff:
1357 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1358 p += 2;
1359 break;
1360 default:
1361 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1362 p += lstrlenW( (LPCWSTR)p ) + 1;
1363 break;
1365 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1366 --nrofitems;
1369 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1370 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1371 return ret;
1374 /******************************************************************************
1375 * PROPSHEET_CreatePage
1377 * Creates a page.
1379 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1380 int index,
1381 const PropSheetInfo * psInfo,
1382 LPCPROPSHEETPAGEW ppshpage)
1384 DLGTEMPLATE* pTemplate;
1385 HWND hwndPage;
1386 DWORD resSize;
1387 LPVOID temp = NULL;
1389 TRACE("index %d\n", index);
1391 if (ppshpage == NULL)
1393 return FALSE;
1396 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1398 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1399 resSize = GetTemplateSize(pTemplate);
1401 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1403 HRSRC hResource;
1404 HANDLE hTemplate;
1406 hResource = FindResourceW(ppshpage->hInstance,
1407 ppshpage->u.pszTemplate,
1408 (LPWSTR)RT_DIALOG);
1409 if(!hResource)
1410 return FALSE;
1412 resSize = SizeofResource(ppshpage->hInstance, hResource);
1414 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1415 if(!hTemplate)
1416 return FALSE;
1418 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1420 * Make a copy of the dialog template to make it writable
1423 else
1425 HRSRC hResource;
1426 HANDLE hTemplate;
1428 hResource = FindResourceA(ppshpage->hInstance,
1429 (LPCSTR)ppshpage->u.pszTemplate,
1430 (LPSTR)RT_DIALOG);
1431 if(!hResource)
1432 return FALSE;
1434 resSize = SizeofResource(ppshpage->hInstance, hResource);
1436 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1437 if(!hTemplate)
1438 return FALSE;
1440 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1442 * Make a copy of the dialog template to make it writable
1445 temp = Alloc(resSize);
1446 if (!temp)
1447 return FALSE;
1449 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1450 memcpy(temp, pTemplate, resSize);
1451 pTemplate = temp;
1453 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1457 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1459 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1460 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1461 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1462 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1464 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1466 else
1468 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1469 pTemplate->style &= ~DS_MODALFRAME;
1470 pTemplate->style &= ~WS_CAPTION;
1471 pTemplate->style &= ~WS_SYSMENU;
1472 pTemplate->style &= ~WS_POPUP;
1473 pTemplate->style &= ~WS_DISABLED;
1474 pTemplate->style &= ~WS_VISIBLE;
1475 pTemplate->style &= ~WS_THICKFRAME;
1477 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1480 if (psInfo->proppage[index].useCallback)
1481 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1482 (LPPROPSHEETPAGEW)ppshpage);
1484 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1485 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1486 pTemplate,
1487 hwndParent,
1488 ppshpage->pfnDlgProc,
1489 (LPARAM)ppshpage);
1490 else
1491 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1492 pTemplate,
1493 hwndParent,
1494 ppshpage->pfnDlgProc,
1495 (LPARAM)ppshpage);
1496 /* Free a no more needed copy */
1497 Free(temp);
1499 psInfo->proppage[index].hwndPage = hwndPage;
1501 /* Subclass exterior wizard pages */
1502 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1503 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1504 (ppshpage->dwFlags & PSP_HIDEHEADER))
1506 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1507 (DWORD_PTR)ppshpage);
1509 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1510 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1512 return TRUE;
1515 /******************************************************************************
1516 * PROPSHEET_LoadWizardBitmaps
1518 * Loads the watermark and header bitmaps for a wizard.
1520 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1522 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1524 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1525 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1526 considers hbmWatermark as valid. */
1527 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1528 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1530 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1531 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1534 /* Same behavior as for watermarks */
1535 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1536 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1538 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1539 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1545 /******************************************************************************
1546 * PROPSHEET_ShowPage
1548 * Displays or creates the specified page.
1550 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1552 HWND hwndTabCtrl;
1553 HWND hwndLineHeader;
1554 LPCPROPSHEETPAGEW ppshpage;
1556 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1557 if (index == psInfo->active_page)
1559 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1560 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1561 return TRUE;
1564 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1565 if (psInfo->proppage[index].hwndPage == 0)
1567 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1570 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1572 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1573 psInfo->proppage[index].pszText);
1576 if (psInfo->active_page != -1)
1577 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1579 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1581 /* Synchronize current selection with tab control
1582 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1583 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1584 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1586 psInfo->active_page = index;
1587 psInfo->activeValid = TRUE;
1589 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1591 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1592 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1594 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1595 ShowWindow(hwndLineHeader, SW_HIDE);
1596 else
1597 ShowWindow(hwndLineHeader, SW_SHOW);
1600 return TRUE;
1603 /******************************************************************************
1604 * PROPSHEET_Back
1606 static BOOL PROPSHEET_Back(HWND hwndDlg)
1608 PSHNOTIFY psn;
1609 HWND hwndPage;
1610 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1611 PropSheetInfoStr);
1612 LRESULT result;
1613 int idx;
1615 TRACE("active_page %d\n", psInfo->active_page);
1616 if (psInfo->active_page < 0)
1617 return FALSE;
1619 psn.hdr.code = PSN_WIZBACK;
1620 psn.hdr.hwndFrom = hwndDlg;
1621 psn.hdr.idFrom = 0;
1622 psn.lParam = 0;
1624 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1626 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1627 if (result == -1)
1628 return FALSE;
1629 else if (result == 0)
1630 idx = psInfo->active_page - 1;
1631 else
1632 idx = PROPSHEET_FindPageByResId(psInfo, result);
1634 if (idx >= 0 && idx < psInfo->nPages)
1636 if (PROPSHEET_CanSetCurSel(hwndDlg))
1637 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1639 return TRUE;
1642 /******************************************************************************
1643 * PROPSHEET_Next
1645 static BOOL PROPSHEET_Next(HWND hwndDlg)
1647 PSHNOTIFY psn;
1648 HWND hwndPage;
1649 LRESULT msgResult = 0;
1650 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1651 PropSheetInfoStr);
1652 int idx;
1654 TRACE("active_page %d\n", psInfo->active_page);
1655 if (psInfo->active_page < 0)
1656 return FALSE;
1658 psn.hdr.code = PSN_WIZNEXT;
1659 psn.hdr.hwndFrom = hwndDlg;
1660 psn.hdr.idFrom = 0;
1661 psn.lParam = 0;
1663 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1665 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1666 if (msgResult == -1)
1667 return FALSE;
1668 else if (msgResult == 0)
1669 idx = psInfo->active_page + 1;
1670 else
1671 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1673 if (idx < psInfo->nPages )
1675 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1676 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1679 return TRUE;
1682 /******************************************************************************
1683 * PROPSHEET_Finish
1685 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1687 PSHNOTIFY psn;
1688 HWND hwndPage;
1689 LRESULT msgResult = 0;
1690 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1691 PropSheetInfoStr);
1693 TRACE("active_page %d\n", psInfo->active_page);
1694 if (psInfo->active_page < 0)
1695 return FALSE;
1697 psn.hdr.code = PSN_WIZFINISH;
1698 psn.hdr.hwndFrom = hwndDlg;
1699 psn.hdr.idFrom = 0;
1700 psn.lParam = 0;
1702 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1704 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1706 TRACE("msg result %ld\n", msgResult);
1708 if (msgResult != 0)
1709 return FALSE;
1711 if (psInfo->result == 0)
1712 psInfo->result = IDOK;
1713 if (psInfo->isModeless)
1714 psInfo->activeValid = FALSE;
1715 else
1716 psInfo->ended = TRUE;
1718 return TRUE;
1721 /******************************************************************************
1722 * PROPSHEET_Apply
1724 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1726 int i;
1727 HWND hwndPage;
1728 PSHNOTIFY psn;
1729 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1730 PropSheetInfoStr);
1732 TRACE("active_page %d\n", psInfo->active_page);
1733 if (psInfo->active_page < 0)
1734 return FALSE;
1736 psn.hdr.hwndFrom = hwndDlg;
1737 psn.hdr.idFrom = 0;
1738 psn.lParam = 0;
1742 * Send PSN_KILLACTIVE to the current page.
1744 psn.hdr.code = PSN_KILLACTIVE;
1746 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1748 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1749 return FALSE;
1752 * Send PSN_APPLY to all pages.
1754 psn.hdr.code = PSN_APPLY;
1755 psn.lParam = lParam;
1757 for (i = 0; i < psInfo->nPages; i++)
1759 hwndPage = psInfo->proppage[i].hwndPage;
1760 if (hwndPage)
1762 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1764 case PSNRET_INVALID:
1765 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1766 /* fall through */
1767 case PSNRET_INVALID_NOCHANGEPAGE:
1768 return FALSE;
1773 if(lParam)
1775 psInfo->activeValid = FALSE;
1777 else if(psInfo->active_page >= 0)
1779 psn.hdr.code = PSN_SETACTIVE;
1780 psn.lParam = 0;
1781 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1782 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1785 return TRUE;
1788 /******************************************************************************
1789 * PROPSHEET_Cancel
1791 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1793 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1794 PropSheetInfoStr);
1795 HWND hwndPage;
1796 PSHNOTIFY psn;
1797 int i;
1799 TRACE("active_page %d\n", psInfo->active_page);
1800 if (psInfo->active_page < 0)
1801 return;
1803 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1804 psn.hdr.code = PSN_QUERYCANCEL;
1805 psn.hdr.hwndFrom = hwndDlg;
1806 psn.hdr.idFrom = 0;
1807 psn.lParam = 0;
1809 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1810 return;
1812 psn.hdr.code = PSN_RESET;
1813 psn.lParam = lParam;
1815 for (i = 0; i < psInfo->nPages; i++)
1817 hwndPage = psInfo->proppage[i].hwndPage;
1819 if (hwndPage)
1820 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1823 if (psInfo->isModeless)
1825 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1826 psInfo->activeValid = FALSE;
1828 else
1829 psInfo->ended = TRUE;
1832 /******************************************************************************
1833 * PROPSHEET_Help
1835 static void PROPSHEET_Help(HWND hwndDlg)
1837 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1838 PropSheetInfoStr);
1839 HWND hwndPage;
1840 PSHNOTIFY psn;
1842 TRACE("active_page %d\n", psInfo->active_page);
1843 if (psInfo->active_page < 0)
1844 return;
1846 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1847 psn.hdr.code = PSN_HELP;
1848 psn.hdr.hwndFrom = hwndDlg;
1849 psn.hdr.idFrom = 0;
1850 psn.lParam = 0;
1852 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1855 /******************************************************************************
1856 * PROPSHEET_Changed
1858 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1860 int i;
1861 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1862 PropSheetInfoStr);
1864 TRACE("\n");
1865 if (!psInfo) return;
1867 * Set the dirty flag of this page.
1869 for (i = 0; i < psInfo->nPages; i++)
1871 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1872 psInfo->proppage[i].isDirty = TRUE;
1876 * Enable the Apply button.
1878 if (psInfo->hasApply)
1880 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1882 EnableWindow(hwndApplyBtn, TRUE);
1886 /******************************************************************************
1887 * PROPSHEET_UnChanged
1889 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1891 int i;
1892 BOOL noPageDirty = TRUE;
1893 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1894 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1895 PropSheetInfoStr);
1897 TRACE("\n");
1898 if ( !psInfo ) return;
1899 for (i = 0; i < psInfo->nPages; i++)
1901 /* set the specified page as clean */
1902 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1903 psInfo->proppage[i].isDirty = FALSE;
1905 /* look to see if there's any dirty pages */
1906 if (psInfo->proppage[i].isDirty)
1907 noPageDirty = FALSE;
1911 * Disable Apply button.
1913 if (noPageDirty)
1914 EnableWindow(hwndApplyBtn, FALSE);
1917 /******************************************************************************
1918 * PROPSHEET_PressButton
1920 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1922 TRACE("buttonID %d\n", buttonID);
1923 switch (buttonID)
1925 case PSBTN_APPLYNOW:
1926 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1927 break;
1928 case PSBTN_BACK:
1929 PROPSHEET_Back(hwndDlg);
1930 break;
1931 case PSBTN_CANCEL:
1932 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1933 break;
1934 case PSBTN_FINISH:
1935 PROPSHEET_Finish(hwndDlg);
1936 break;
1937 case PSBTN_HELP:
1938 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1939 break;
1940 case PSBTN_NEXT:
1941 PROPSHEET_Next(hwndDlg);
1942 break;
1943 case PSBTN_OK:
1944 PROPSHEET_DoCommand(hwndDlg, IDOK);
1945 break;
1946 default:
1947 FIXME("Invalid button index %d\n", buttonID);
1952 /*************************************************************************
1953 * BOOL PROPSHEET_CanSetCurSel [Internal]
1955 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1957 * PARAMS
1958 * hwndDlg [I] handle to a Dialog hWnd
1960 * RETURNS
1961 * TRUE if Current Selection can change
1963 * NOTES
1965 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1967 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1968 PropSheetInfoStr);
1969 HWND hwndPage;
1970 PSHNOTIFY psn;
1971 BOOL res = FALSE;
1972 HWND hwndTabControl;
1973 RECT rect;
1975 TRACE("active_page %d\n", psInfo->active_page);
1976 if (!psInfo)
1978 res = FALSE;
1979 goto end;
1982 if (psInfo->active_page < 0)
1984 res = TRUE;
1985 goto end;
1989 * Notify the current page.
1991 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1992 psn.hdr.code = PSN_KILLACTIVE;
1993 psn.hdr.hwndFrom = hwndDlg;
1994 psn.hdr.idFrom = 0;
1995 psn.lParam = 0;
1997 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2000 * Re-adjust the tab control's contents
2002 hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2003 memset( &rect, 0, sizeof rect );
2004 GetClientRect( hwndTabControl, &rect );
2005 SendMessageW( hwndTabControl, TCM_ADJUSTRECT, 0, (LPARAM) &rect );
2006 SetWindowPos( hwndPage, NULL, rect.left, rect.top,
2007 rect.right - rect.left, rect.bottom - rect.top, 0 );
2009 end:
2010 TRACE("<-- %d\n", res);
2011 return res;
2014 /******************************************************************************
2015 * PROPSHEET_SetCurSel
2017 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2018 int index,
2019 int skipdir,
2020 HPROPSHEETPAGE hpage
2023 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2024 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2025 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2027 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2028 /* hpage takes precedence over index */
2029 if (hpage != NULL)
2030 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2032 if (index < 0 || index >= psInfo->nPages)
2034 TRACE("Could not find page to select!\n");
2035 return FALSE;
2038 /* unset active page while doing this transition. */
2039 if (psInfo->active_page != -1)
2040 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2041 psInfo->active_page = -1;
2043 while (1) {
2044 int result;
2045 PSHNOTIFY psn;
2046 RECT rc;
2047 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2049 if (hwndTabControl)
2050 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2052 psn.hdr.code = PSN_SETACTIVE;
2053 psn.hdr.hwndFrom = hwndDlg;
2054 psn.hdr.idFrom = 0;
2055 psn.lParam = 0;
2057 if (!psInfo->proppage[index].hwndPage) {
2058 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2061 /* Resize the property sheet page to the fit in the Tab control
2062 * (for regular property sheets) or to fit in the client area (for
2063 * wizards).
2064 * NOTE: The resizing happens every time the page is selected and
2065 * not only when it's created (some applications depend on it). */
2066 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2067 TRACE("setting page %p, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
2068 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2069 rc.right - rc.left, rc.bottom - rc.top);
2070 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2071 rc.left, rc.top,
2072 rc.right - rc.left, rc.bottom - rc.top, 0);
2074 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2075 if (!result)
2076 break;
2077 if (result == -1) {
2078 index+=skipdir;
2079 if (index < 0) {
2080 index = 0;
2081 WARN("Tried to skip before first property sheet page!\n");
2082 break;
2084 if (index >= psInfo->nPages) {
2085 WARN("Tried to skip after last property sheet page!\n");
2086 index = psInfo->nPages-1;
2087 break;
2090 else if (result != 0)
2092 int old_index = index;
2093 index = PROPSHEET_FindPageByResId(psInfo, result);
2094 if(index >= psInfo->nPages) {
2095 index = old_index;
2096 WARN("Tried to skip to nonexistant page by res id\n");
2097 break;
2099 continue;
2103 /* Invalidate the header area */
2104 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2105 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2107 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2108 RECT r;
2110 GetClientRect(hwndLineHeader, &r);
2111 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2112 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2114 InvalidateRect(hwndDlg, &r, TRUE);
2118 * Display the new page.
2120 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2122 if (psInfo->proppage[index].hasHelp)
2123 EnableWindow(hwndHelp, TRUE);
2124 else
2125 EnableWindow(hwndHelp, FALSE);
2127 return TRUE;
2130 /******************************************************************************
2131 * PROPSHEET_SetCurSelId
2133 * Selects the page, specified by resource id.
2135 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2137 int idx;
2138 PropSheetInfo* psInfo =
2139 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2141 idx = PROPSHEET_FindPageByResId(psInfo, id);
2142 if (idx < psInfo->nPages )
2144 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2145 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2149 /******************************************************************************
2150 * PROPSHEET_SetTitleA
2152 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2154 if(HIWORD(lpszText))
2156 WCHAR szTitle[256];
2157 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2158 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2159 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2161 else
2163 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2167 /******************************************************************************
2168 * PROPSHEET_SetTitleW
2170 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2172 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2173 WCHAR szTitle[256];
2175 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2176 if (HIWORD(lpszText) == 0) {
2177 if (!LoadStringW(psInfo->ppshheader.hInstance,
2178 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2179 return;
2180 lpszText = szTitle;
2182 if (dwStyle & PSH_PROPTITLE)
2184 WCHAR* dest;
2185 int lentitle = strlenW(lpszText);
2186 int lenprop = strlenW(psInfo->strPropertiesFor);
2188 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2189 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2191 SetWindowTextW(hwndDlg, dest);
2192 Free(dest);
2194 else
2195 SetWindowTextW(hwndDlg, lpszText);
2198 /******************************************************************************
2199 * PROPSHEET_SetFinishTextA
2201 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2203 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2204 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2206 TRACE("'%s'\n", lpszText);
2207 /* Set text, show and enable the Finish button */
2208 SetWindowTextA(hwndButton, lpszText);
2209 ShowWindow(hwndButton, SW_SHOW);
2210 EnableWindow(hwndButton, TRUE);
2212 /* Make it default pushbutton */
2213 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2215 /* Hide Back button */
2216 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2217 ShowWindow(hwndButton, SW_HIDE);
2219 if (!psInfo->hasFinish)
2221 /* Hide Next button */
2222 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2223 ShowWindow(hwndButton, SW_HIDE);
2227 /******************************************************************************
2228 * PROPSHEET_SetFinishTextW
2230 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2232 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2233 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2235 TRACE("%s\n", debugstr_w(lpszText));
2236 /* Set text, show and enable the Finish button */
2237 SetWindowTextW(hwndButton, lpszText);
2238 ShowWindow(hwndButton, SW_SHOW);
2239 EnableWindow(hwndButton, TRUE);
2241 /* Make it default pushbutton */
2242 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2244 /* Hide Back button */
2245 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2246 ShowWindow(hwndButton, SW_HIDE);
2248 if (!psInfo->hasFinish)
2250 /* Hide Next button */
2251 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2252 ShowWindow(hwndButton, SW_HIDE);
2256 /******************************************************************************
2257 * PROPSHEET_QuerySiblings
2259 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2260 WPARAM wParam, LPARAM lParam)
2262 int i = 0;
2263 HWND hwndPage;
2264 LRESULT msgResult = 0;
2265 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2267 while ((i < psInfo->nPages) && (msgResult == 0))
2269 hwndPage = psInfo->proppage[i].hwndPage;
2270 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2271 i++;
2274 return msgResult;
2278 /******************************************************************************
2279 * PROPSHEET_AddPage
2281 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2282 HPROPSHEETPAGE hpage)
2284 PropPageInfo * ppi;
2285 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2286 PropSheetInfoStr);
2287 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2288 TCITEMW item;
2289 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2291 TRACE("hpage %p\n", hpage);
2293 * Allocate and fill in a new PropPageInfo entry.
2295 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2296 sizeof(PropPageInfo) *
2297 (psInfo->nPages + 1));
2298 if (!ppi)
2299 return FALSE;
2301 psInfo->proppage = ppi;
2302 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2303 return FALSE;
2305 psInfo->proppage[psInfo->nPages].hpage = hpage;
2307 if (ppsp->dwFlags & PSP_PREMATURE)
2309 /* Create the page but don't show it */
2310 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2314 * Add a new tab to the tab control.
2316 item.mask = TCIF_TEXT;
2317 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2318 item.cchTextMax = MAX_TABTEXT_LENGTH;
2320 if (psInfo->hImageList)
2322 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2325 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2327 item.mask |= TCIF_IMAGE;
2328 item.iImage = psInfo->nPages;
2331 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2332 (LPARAM)&item);
2334 psInfo->nPages++;
2336 /* If it is the only page - show it */
2337 if(psInfo->nPages == 1)
2338 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2339 return TRUE;
2342 /******************************************************************************
2343 * PROPSHEET_RemovePage
2345 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2346 int index,
2347 HPROPSHEETPAGE hpage)
2349 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2350 PropSheetInfoStr);
2351 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2352 PropPageInfo* oldPages;
2354 TRACE("index %d, hpage %p\n", index, hpage);
2355 if (!psInfo) {
2356 return FALSE;
2359 * hpage takes precedence over index.
2361 if (hpage != 0)
2363 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2366 /* Make sure that index is within range */
2367 if (index < 0 || index >= psInfo->nPages)
2369 TRACE("Could not find page to remove!\n");
2370 return FALSE;
2373 TRACE("total pages %d removing page %d active page %d\n",
2374 psInfo->nPages, index, psInfo->active_page);
2376 * Check if we're removing the active page.
2378 if (index == psInfo->active_page)
2380 if (psInfo->nPages > 1)
2382 if (index > 0)
2384 /* activate previous page */
2385 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2387 else
2389 /* activate the next page */
2390 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2391 psInfo->active_page = index;
2394 else
2396 psInfo->active_page = -1;
2397 if (!psInfo->isModeless)
2399 psInfo->ended = TRUE;
2400 return TRUE;
2404 else if (index < psInfo->active_page)
2405 psInfo->active_page--;
2407 /* Unsubclass the page dialog window */
2408 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2409 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2410 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2412 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2413 PROPSHEET_WizardSubclassProc, 1);
2416 /* Destroy page dialog window */
2417 DestroyWindow(psInfo->proppage[index].hwndPage);
2419 /* Free page resources */
2420 if(psInfo->proppage[index].hpage)
2422 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2424 if (psp->dwFlags & PSP_USETITLE)
2425 Free ((LPVOID)psInfo->proppage[index].pszText);
2427 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2430 /* Remove the tab */
2431 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2433 oldPages = psInfo->proppage;
2434 psInfo->nPages--;
2435 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2437 if (index > 0)
2438 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2440 if (index < psInfo->nPages)
2441 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2442 (psInfo->nPages - index) * sizeof(PropPageInfo));
2444 Free(oldPages);
2446 return FALSE;
2449 /******************************************************************************
2450 * PROPSHEET_SetWizButtons
2452 * This code will work if (and assumes that) the Next button is on top of the
2453 * Finish button. ie. Finish comes after Next in the Z order.
2454 * This means make sure the dialog template reflects this.
2457 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2459 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2460 PropSheetInfoStr);
2461 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2462 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2463 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2465 TRACE("%d\n", dwFlags);
2467 EnableWindow(hwndBack, FALSE);
2468 EnableWindow(hwndNext, FALSE);
2469 EnableWindow(hwndFinish, FALSE);
2471 /* set the default pushbutton to an enabled button */
2472 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2473 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2474 else if (dwFlags & PSWIZB_NEXT)
2475 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2476 else if (dwFlags & PSWIZB_BACK)
2477 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2478 else
2479 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2482 if (dwFlags & PSWIZB_BACK)
2483 EnableWindow(hwndBack, TRUE);
2485 if (dwFlags & PSWIZB_NEXT)
2486 EnableWindow(hwndNext, TRUE);
2488 if (!psInfo->hasFinish)
2490 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2492 /* Hide the Next button */
2493 ShowWindow(hwndNext, SW_HIDE);
2495 /* Show the Finish button */
2496 ShowWindow(hwndFinish, SW_SHOW);
2498 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2499 EnableWindow(hwndFinish, TRUE);
2501 else
2503 /* Hide the Finish button */
2504 ShowWindow(hwndFinish, SW_HIDE);
2505 /* Show the Next button */
2506 ShowWindow(hwndNext, SW_SHOW);
2509 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2510 EnableWindow(hwndFinish, TRUE);
2513 /******************************************************************************
2514 * PROPSHEET_InsertPage
2516 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2518 if (!HIWORD(hpageInsertAfter))
2519 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2520 else
2521 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2522 return FALSE;
2525 /******************************************************************************
2526 * PROPSHEET_SetHeaderTitleW
2528 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2530 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2533 /******************************************************************************
2534 * PROPSHEET_SetHeaderTitleA
2536 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2538 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2541 /******************************************************************************
2542 * PROPSHEET_SetHeaderSubTitleW
2544 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2546 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2549 /******************************************************************************
2550 * PROPSHEET_SetHeaderSubTitleA
2552 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2554 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2557 /******************************************************************************
2558 * PROPSHEET_HwndToIndex
2560 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2562 int index;
2563 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2564 PropSheetInfoStr);
2566 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2568 for (index = 0; index < psInfo->nPages; index++)
2569 if (psInfo->proppage[index].hwndPage == hPageDlg)
2570 return index;
2571 WARN("%p not found\n", hPageDlg);
2572 return -1;
2575 /******************************************************************************
2576 * PROPSHEET_IndexToHwnd
2578 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2580 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2581 PropSheetInfoStr);
2582 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2583 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2584 WARN("%d out of range.\n", iPageIndex);
2585 return 0;
2587 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2590 /******************************************************************************
2591 * PROPSHEET_PageToIndex
2593 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2595 int index;
2596 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2597 PropSheetInfoStr);
2599 TRACE("(%p, %p)\n", hwndDlg, hPage);
2601 for (index = 0; index < psInfo->nPages; index++)
2602 if (psInfo->proppage[index].hpage == hPage)
2603 return index;
2604 WARN("%p not found\n", hPage);
2605 return -1;
2608 /******************************************************************************
2609 * PROPSHEET_IndexToPage
2611 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2613 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2614 PropSheetInfoStr);
2615 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2616 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2617 WARN("%d out of range.\n", iPageIndex);
2618 return 0;
2620 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2623 /******************************************************************************
2624 * PROPSHEET_IdToIndex
2626 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2628 int index;
2629 LPCPROPSHEETPAGEW psp;
2630 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2631 PropSheetInfoStr);
2632 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2633 for (index = 0; index < psInfo->nPages; index++) {
2634 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2635 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2636 return index;
2639 return -1;
2642 /******************************************************************************
2643 * PROPSHEET_IndexToId
2645 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2647 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2648 PropSheetInfoStr);
2649 LPCPROPSHEETPAGEW psp;
2650 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2651 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2652 WARN("%d out of range.\n", iPageIndex);
2653 return 0;
2655 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2656 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2657 return 0;
2659 return (LRESULT)psp->u.pszTemplate;
2662 /******************************************************************************
2663 * PROPSHEET_GetResult
2665 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2667 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2668 PropSheetInfoStr);
2669 return psInfo->result;
2672 /******************************************************************************
2673 * PROPSHEET_RecalcPageSizes
2675 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2677 FIXME("(%p): stub\n", hwndDlg);
2678 return FALSE;
2681 /******************************************************************************
2682 * PROPSHEET_GetPageIndex
2684 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2685 * the array of PropPageInfo.
2687 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2689 BOOL found = FALSE;
2690 int index = 0;
2692 TRACE("hpage %p\n", hpage);
2693 while ((index < psInfo->nPages) && (found == FALSE))
2695 if (psInfo->proppage[index].hpage == hpage)
2696 found = TRUE;
2697 else
2698 index++;
2701 if (found == FALSE)
2702 index = -1;
2704 return index;
2707 /******************************************************************************
2708 * PROPSHEET_CleanUp
2710 static void PROPSHEET_CleanUp(HWND hwndDlg)
2712 int i;
2713 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2714 PropSheetInfoStr);
2716 TRACE("\n");
2717 if (!psInfo) return;
2718 if (HIWORD(psInfo->ppshheader.pszCaption))
2719 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2721 for (i = 0; i < psInfo->nPages; i++)
2723 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2725 /* Unsubclass the page dialog window */
2726 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2727 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2728 (psp->dwFlags & PSP_HIDEHEADER))
2730 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2731 PROPSHEET_WizardSubclassProc, 1);
2734 if(psInfo->proppage[i].hwndPage)
2735 DestroyWindow(psInfo->proppage[i].hwndPage);
2737 if(psp)
2739 if (psp->dwFlags & PSP_USETITLE)
2740 Free ((LPVOID)psInfo->proppage[i].pszText);
2742 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2746 DeleteObject(psInfo->hFont);
2747 DeleteObject(psInfo->hFontBold);
2748 /* If we created the bitmaps, destroy them */
2749 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2750 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2751 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2752 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2753 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2754 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2756 Free(psInfo->proppage);
2757 Free(psInfo->strPropertiesFor);
2758 ImageList_Destroy(psInfo->hImageList);
2760 GlobalFree((HGLOBAL)psInfo);
2763 static INT do_loop(PropSheetInfo *psInfo)
2765 MSG msg;
2766 INT ret = -1;
2767 HWND hwnd = psInfo->hwnd;
2769 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2771 if(ret == -1)
2772 break;
2774 if(!IsDialogMessageW(hwnd, &msg))
2776 TranslateMessage(&msg);
2777 DispatchMessageW(&msg);
2781 if(ret == 0)
2783 PostQuitMessage(msg.wParam);
2784 ret = -1;
2787 if(ret != -1)
2788 ret = psInfo->result;
2790 DestroyWindow(hwnd);
2791 return ret;
2794 /******************************************************************************
2795 * PropertySheet (COMCTL32.@)
2796 * PropertySheetA (COMCTL32.@)
2798 * Creates a property sheet in the specified property sheet header.
2800 * RETURNS
2801 * Modal property sheets: Positive if successful or -1 otherwise.
2802 * Modeless property sheets: Property sheet handle.
2803 * Or:
2804 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2805 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2807 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2809 INT_PTR bRet = 0;
2810 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2811 sizeof(PropSheetInfo));
2812 UINT i, n;
2813 const BYTE* pByte;
2815 TRACE("(%p)\n", lppsh);
2817 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2819 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2820 lppsh->nPages);
2821 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2823 for (n = i = 0; i < lppsh->nPages; i++, n++)
2825 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2826 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2827 else
2829 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2830 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2833 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2834 psInfo, n))
2836 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2837 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2838 n--;
2839 psInfo->nPages--;
2843 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2844 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2846 psInfo->unicode = FALSE;
2847 psInfo->ended = FALSE;
2849 bRet = PROPSHEET_CreateDialog(psInfo);
2850 if(!psInfo->isModeless)
2851 bRet = do_loop(psInfo);
2853 return bRet;
2856 /******************************************************************************
2857 * PropertySheetW (COMCTL32.@)
2859 * See PropertySheetA.
2861 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2863 INT_PTR bRet = 0;
2864 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2865 sizeof(PropSheetInfo));
2866 UINT i, n;
2867 const BYTE* pByte;
2869 TRACE("(%p)\n", lppsh);
2871 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2873 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2874 lppsh->nPages);
2875 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2877 for (n = i = 0; i < lppsh->nPages; i++, n++)
2879 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2880 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2881 else
2883 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2884 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2887 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2888 psInfo, n))
2890 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2891 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2892 n--;
2893 psInfo->nPages--;
2897 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2898 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2900 psInfo->unicode = TRUE;
2901 psInfo->ended = FALSE;
2903 bRet = PROPSHEET_CreateDialog(psInfo);
2904 if(!psInfo->isModeless)
2905 bRet = do_loop(psInfo);
2907 return bRet;
2910 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2912 LPWSTR ret;
2913 UINT len;
2915 if (IS_INTRESOURCE(str))
2917 HRSRC hrsrc;
2918 HGLOBAL hmem;
2919 WCHAR *ptr;
2920 WORD i, id = LOWORD(str);
2922 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2923 return NULL;
2924 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2925 if (!(ptr = LockResource( hmem ))) return NULL;
2926 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2927 len = *ptr;
2928 if (!len) return NULL;
2929 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2930 if (ret)
2932 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2933 ret[len] = 0;
2936 else
2938 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2939 ret = Alloc( len );
2940 if (ret) memcpy( ret, str, len );
2942 return ret;
2946 /******************************************************************************
2947 * CreatePropertySheetPage (COMCTL32.@)
2948 * CreatePropertySheetPageA (COMCTL32.@)
2950 * Creates a new property sheet page.
2952 * RETURNS
2953 * Success: Handle to new property sheet page.
2954 * Failure: NULL.
2956 * NOTES
2957 * An application must use the PSM_ADDPAGE message to add the new page to
2958 * an existing property sheet.
2960 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2961 LPCPROPSHEETPAGEA lpPropSheetPage)
2963 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2965 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2967 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2969 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2971 if (HIWORD( ppsp->u.pszTemplate ))
2973 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2974 char *template = Alloc( len );
2976 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2980 if (ppsp->dwFlags & PSP_USEICONID)
2982 if (HIWORD( ppsp->u2.pszIcon ))
2983 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2986 if (ppsp->dwFlags & PSP_USETITLE)
2988 if (HIWORD( ppsp->pszTitle ))
2989 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2990 else
2991 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2993 else
2994 ppsp->pszTitle = NULL;
2996 if (ppsp->dwFlags & PSP_HIDEHEADER)
2997 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2999 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3001 if (HIWORD( ppsp->pszHeaderTitle ))
3002 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
3003 else
3004 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3006 else
3007 ppsp->pszHeaderTitle = NULL;
3009 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3011 if (HIWORD( ppsp->pszHeaderSubTitle ))
3012 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
3013 else
3014 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3016 else
3017 ppsp->pszHeaderSubTitle = NULL;
3019 return (HPROPSHEETPAGE)ppsp;
3022 /******************************************************************************
3023 * CreatePropertySheetPageW (COMCTL32.@)
3025 * See CreatePropertySheetA.
3027 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3029 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3031 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3033 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3035 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3037 if (HIWORD( ppsp->u.pszTemplate ))
3039 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3040 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3042 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3046 if ( ppsp->dwFlags & PSP_USEICONID )
3048 if (HIWORD( ppsp->u2.pszIcon ))
3050 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3051 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3053 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3057 if (ppsp->dwFlags & PSP_USETITLE)
3058 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3059 else
3060 ppsp->pszTitle = NULL;
3062 if (ppsp->dwFlags & PSP_HIDEHEADER)
3063 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3065 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3066 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3067 else
3068 ppsp->pszHeaderTitle = NULL;
3070 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3071 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3072 else
3073 ppsp->pszHeaderSubTitle = NULL;
3075 return (HPROPSHEETPAGE)ppsp;
3078 /******************************************************************************
3079 * DestroyPropertySheetPage (COMCTL32.@)
3081 * Destroys a property sheet page previously created with
3082 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3083 * memory.
3085 * RETURNS
3086 * Success: TRUE
3087 * Failure: FALSE
3089 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3091 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3093 if (!psp)
3094 return FALSE;
3096 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3097 Free ((LPVOID)psp->u.pszTemplate);
3099 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3100 Free ((LPVOID)psp->u2.pszIcon);
3102 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3103 Free ((LPVOID)psp->pszTitle);
3105 Free(hPropPage);
3107 return TRUE;
3110 /******************************************************************************
3111 * PROPSHEET_IsDialogMessage
3113 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3115 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3117 TRACE("\n");
3118 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3119 return FALSE;
3121 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3123 int new_page = 0;
3124 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3126 if (!(dlgCode & DLGC_WANTMESSAGE))
3128 switch (lpMsg->wParam)
3130 case VK_TAB:
3131 if (GetKeyState(VK_SHIFT) & 0x8000)
3132 new_page = -1;
3133 else
3134 new_page = 1;
3135 break;
3137 case VK_NEXT: new_page = 1; break;
3138 case VK_PRIOR: new_page = -1; break;
3142 if (new_page)
3144 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3146 new_page += psInfo->active_page;
3148 if (new_page < 0)
3149 new_page = psInfo->nPages - 1;
3150 else if (new_page >= psInfo->nPages)
3151 new_page = 0;
3153 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3156 return TRUE;
3160 return IsDialogMessageW(hwnd, lpMsg);
3163 /******************************************************************************
3164 * PROPSHEET_DoCommand
3166 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3169 switch (wID) {
3171 case IDOK:
3172 case IDC_APPLY_BUTTON:
3174 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3176 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3177 break;
3179 if (wID == IDOK)
3181 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3182 PropSheetInfoStr);
3184 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3185 if (psInfo->result == 0)
3186 psInfo->result = IDOK;
3188 if (psInfo->isModeless)
3189 psInfo->activeValid = FALSE;
3190 else
3191 psInfo->ended = TRUE;
3193 else
3194 EnableWindow(hwndApplyBtn, FALSE);
3196 break;
3199 case IDC_BACK_BUTTON:
3200 PROPSHEET_Back(hwnd);
3201 break;
3203 case IDC_NEXT_BUTTON:
3204 PROPSHEET_Next(hwnd);
3205 break;
3207 case IDC_FINISH_BUTTON:
3208 PROPSHEET_Finish(hwnd);
3209 break;
3211 case IDCANCEL:
3212 PROPSHEET_Cancel(hwnd, 0);
3213 break;
3215 case IDHELP:
3216 PROPSHEET_Help(hwnd);
3217 break;
3219 default:
3220 return FALSE;
3223 return TRUE;
3226 /******************************************************************************
3227 * PROPSHEET_Paint
3229 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3231 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3232 PAINTSTRUCT ps;
3233 HDC hdc, hdcSrc;
3234 BITMAP bm;
3235 HBITMAP hbmp;
3236 HPALETTE hOldPal = 0;
3237 int offsety = 0;
3238 HBRUSH hbr;
3239 RECT r, rzone;
3240 LPCPROPSHEETPAGEW ppshpage;
3241 WCHAR szBuffer[256];
3242 int nLength;
3244 if (psInfo->active_page < 0) return 1;
3245 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3246 if (!hdc) return 1;
3248 hdcSrc = CreateCompatibleDC(0);
3249 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3251 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3252 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3254 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3255 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3256 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3258 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3259 HFONT hOldFont;
3260 COLORREF clrOld = 0;
3261 int oldBkMode = 0;
3263 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3264 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3266 GetClientRect(hwndLineHeader, &r);
3267 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3268 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3270 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3272 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3274 /* Fill the unoccupied part of the header with color of the
3275 * left-top pixel, but do it only when needed.
3277 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3279 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3280 CopyRect(&r, &rzone);
3281 if (bm.bmWidth < r.right)
3283 r.left = bm.bmWidth;
3284 FillRect(hdc, &r, hbr);
3286 if (bm.bmHeight < r.bottom)
3288 r.left = 0;
3289 r.top = bm.bmHeight;
3290 FillRect(hdc, &r, hbr);
3292 DeleteObject(hbr);
3295 /* Draw the header itself. */
3296 BitBlt(hdc, 0, 0,
3297 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3298 hdcSrc, 0, 0, SRCCOPY);
3300 else
3302 int margin;
3303 hbr = GetSysColorBrush(COLOR_WINDOW);
3304 FillRect(hdc, &rzone, hbr);
3306 /* Draw the header bitmap. It's always centered like a
3307 * common 49 x 49 bitmap. */
3308 margin = (rzone.bottom - 49) / 2;
3309 BitBlt(hdc, rzone.right - 49 - margin, margin,
3310 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3311 hdcSrc, 0, 0, SRCCOPY);
3313 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3314 * if its height is smaller than 49 pixels. Because the reason
3315 * for this bug is unknown the current code doesn't try to
3316 * replicate it. */
3319 clrOld = SetTextColor (hdc, 0x00000000);
3320 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3322 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3323 SetRect(&r, 20, 10, 0, 0);
3324 if (HIWORD(ppshpage->pszHeaderTitle))
3325 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3326 else
3328 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3329 szBuffer, 256);
3330 if (nLength != 0)
3332 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3337 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3338 SelectObject(hdc, psInfo->hFont);
3339 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3340 if (HIWORD(ppshpage->pszHeaderTitle))
3341 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3342 else
3344 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3345 szBuffer, 256);
3346 if (nLength != 0)
3348 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3353 offsety = rzone.bottom + 2;
3355 SetTextColor(hdc, clrOld);
3356 SetBkMode(hdc, oldBkMode);
3357 SelectObject(hdc, hOldFont);
3358 SelectObject(hdcSrc, hbmp);
3361 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3362 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3363 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3365 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3367 GetClientRect(hwndLine, &r);
3368 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3370 rzone.left = 0;
3371 rzone.top = 0;
3372 rzone.right = r.right;
3373 rzone.bottom = r.top - 1;
3375 hbr = GetSysColorBrush(COLOR_WINDOW);
3376 FillRect(hdc, &rzone, hbr);
3378 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3379 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3381 /* The watermark is truncated to a width of 164 pixels */
3382 r.right = min(r.right, 164);
3383 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3384 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3386 /* If the bitmap is not big enough, fill the remaining area
3387 with the color of pixel (0,0) of bitmap - see MSDN */
3388 if (r.top > bm.bmHeight) {
3389 r.bottom = r.top - 1;
3390 r.top = bm.bmHeight;
3391 r.left = 0;
3392 r.right = bm.bmWidth;
3393 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3394 FillRect(hdc, &r, hbr);
3395 DeleteObject(hbr);
3398 SelectObject(hdcSrc, hbmp);
3401 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3402 SelectPalette(hdc, hOldPal, FALSE);
3404 DeleteDC(hdcSrc);
3406 if (!hdcParam) EndPaint(hwnd, &ps);
3408 return 0;
3411 /******************************************************************************
3412 * PROPSHEET_DialogProc
3414 static INT_PTR CALLBACK
3415 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3417 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3418 hwnd, uMsg, wParam, lParam);
3420 switch (uMsg)
3422 case WM_INITDIALOG:
3424 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3425 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3426 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3427 LPCPROPSHEETPAGEW ppshpage;
3428 int idx;
3429 LOGFONTW logFont;
3431 /* Using PropSheetInfoStr to store extra data doesn't match the native
3432 * common control: native uses TCM_[GS]ETITEM
3434 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3437 * psInfo->hwnd is not being used by WINE code - it exists
3438 * for compatibility with "real" Windoze. The same about
3439 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3440 * property.
3442 psInfo->hwnd = hwnd;
3443 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3445 /* set up the Next and Back buttons by default */
3446 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3448 /* Set up fonts */
3449 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3450 psInfo->hFont = CreateFontIndirectW (&logFont);
3451 logFont.lfWeight = FW_BOLD;
3452 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3455 * Small icon in the title bar.
3457 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3458 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3460 HICON hIcon;
3461 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3462 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3464 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3465 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3466 psInfo->ppshheader.u.pszIcon,
3467 IMAGE_ICON,
3468 icon_cx, icon_cy,
3469 LR_DEFAULTCOLOR);
3470 else
3471 hIcon = psInfo->ppshheader.u.hIcon;
3473 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3476 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3477 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3479 psInfo->strPropertiesFor = strCaption;
3481 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3483 PROPSHEET_CreateTabControl(hwnd, psInfo);
3485 PROPSHEET_LoadWizardBitmaps(psInfo);
3487 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3489 ShowWindow(hwndTabCtrl, SW_HIDE);
3490 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3491 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3493 else
3495 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3497 PROPSHEET_AdjustSize(hwnd, psInfo);
3498 PROPSHEET_AdjustButtons(hwnd, psInfo);
3502 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3503 psInfo->ppshheader.hInstance)
3505 WCHAR szText[256];
3507 if (LoadStringW(psInfo->ppshheader.hInstance,
3508 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3509 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3511 else
3513 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3514 psInfo->ppshheader.pszCaption);
3518 if (psInfo->useCallback)
3519 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3520 PSCB_INITIALIZED, (LPARAM)0);
3522 idx = psInfo->active_page;
3523 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3524 psInfo->active_page = -1;
3526 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3528 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3529 * as some programs call TCM_GETCURSEL to get the current selection
3530 * from which to switch to the next page */
3531 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3533 return TRUE;
3536 case WM_PRINTCLIENT:
3537 case WM_PAINT:
3538 PROPSHEET_Paint(hwnd, (HDC)wParam);
3539 return TRUE;
3541 case WM_DESTROY:
3542 PROPSHEET_CleanUp(hwnd);
3543 return TRUE;
3545 case WM_CLOSE:
3546 PROPSHEET_Cancel(hwnd, 1);
3547 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3549 case WM_COMMAND:
3550 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3552 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3554 if (!psInfo)
3555 return FALSE;
3557 /* No default handler, forward notification to active page */
3558 if (psInfo->activeValid && psInfo->active_page != -1)
3560 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3561 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3564 return TRUE;
3566 case WM_NOTIFY:
3568 NMHDR* pnmh = (LPNMHDR) lParam;
3570 if (pnmh->code == TCN_SELCHANGE)
3572 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3573 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3576 if(pnmh->code == TCN_SELCHANGING)
3578 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3579 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3580 return TRUE;
3583 return FALSE;
3586 case WM_SYSCOLORCHANGE:
3587 COMCTL32_RefreshSysColors();
3588 return FALSE;
3590 case PSM_GETCURRENTPAGEHWND:
3592 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3593 PropSheetInfoStr);
3594 HWND hwndPage = 0;
3596 if (!psInfo)
3597 return FALSE;
3599 if (psInfo->activeValid && psInfo->active_page != -1)
3600 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3602 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3604 return TRUE;
3607 case PSM_CHANGED:
3608 PROPSHEET_Changed(hwnd, (HWND)wParam);
3609 return TRUE;
3611 case PSM_UNCHANGED:
3612 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3613 return TRUE;
3615 case PSM_GETTABCONTROL:
3617 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3619 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3621 return TRUE;
3624 case PSM_SETCURSEL:
3626 BOOL msgResult;
3628 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3629 if(msgResult != FALSE)
3631 msgResult = PROPSHEET_SetCurSel(hwnd,
3632 (int)wParam,
3634 (HPROPSHEETPAGE)lParam);
3637 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3639 return TRUE;
3642 case PSM_CANCELTOCLOSE:
3644 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3645 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3646 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3648 EnableWindow(hwndCancel, FALSE);
3649 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3650 SetWindowTextW(hwndOK, buf);
3652 return FALSE;
3655 case PSM_RESTARTWINDOWS:
3657 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3658 PropSheetInfoStr);
3660 if (!psInfo)
3661 return FALSE;
3663 /* reboot system takes precedence over restart windows */
3664 if (psInfo->result != ID_PSREBOOTSYSTEM)
3665 psInfo->result = ID_PSRESTARTWINDOWS;
3667 return TRUE;
3670 case PSM_REBOOTSYSTEM:
3672 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3673 PropSheetInfoStr);
3675 if (!psInfo)
3676 return FALSE;
3678 psInfo->result = ID_PSREBOOTSYSTEM;
3680 return TRUE;
3683 case PSM_SETTITLEA:
3684 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3685 return TRUE;
3687 case PSM_SETTITLEW:
3688 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3689 return TRUE;
3691 case PSM_APPLY:
3693 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3695 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3697 return TRUE;
3700 case PSM_QUERYSIBLINGS:
3702 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3704 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3706 return TRUE;
3709 case PSM_ADDPAGE:
3712 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3713 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3714 * on success or FALSE otherwise, as specified on MSDN Online.
3715 * Also see the MFC code for
3716 * CPropertySheet::AddPage(CPropertyPage* pPage).
3719 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3721 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3723 return TRUE;
3726 case PSM_REMOVEPAGE:
3727 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3728 return TRUE;
3730 case PSM_ISDIALOGMESSAGE:
3732 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3733 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3734 return TRUE;
3737 case PSM_PRESSBUTTON:
3738 PROPSHEET_PressButton(hwnd, (int)wParam);
3739 return TRUE;
3741 case PSM_SETFINISHTEXTA:
3742 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3743 return TRUE;
3745 case PSM_SETWIZBUTTONS:
3746 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3747 return TRUE;
3749 case PSM_SETCURSELID:
3750 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3751 return TRUE;
3753 case PSM_SETFINISHTEXTW:
3754 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3755 return FALSE;
3757 case PSM_INSERTPAGE:
3759 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3760 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3761 return TRUE;
3764 case PSM_SETHEADERTITLEW:
3765 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3766 return TRUE;
3768 case PSM_SETHEADERTITLEA:
3769 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3770 return TRUE;
3772 case PSM_SETHEADERSUBTITLEW:
3773 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3774 return TRUE;
3776 case PSM_SETHEADERSUBTITLEA:
3777 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3778 return TRUE;
3780 case PSM_HWNDTOINDEX:
3782 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3783 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3784 return TRUE;
3787 case PSM_INDEXTOHWND:
3789 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3790 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3791 return TRUE;
3794 case PSM_PAGETOINDEX:
3796 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3801 case PSM_INDEXTOPAGE:
3803 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3804 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3805 return TRUE;
3808 case PSM_IDTOINDEX:
3810 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3811 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3812 return TRUE;
3815 case PSM_INDEXTOID:
3817 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3818 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3819 return TRUE;
3822 case PSM_GETRESULT:
3824 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3825 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3826 return TRUE;
3829 case PSM_RECALCPAGESIZES:
3831 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3832 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3833 return TRUE;
3836 default:
3837 return FALSE;