mfreadwrite/reader: Add missing allocation check (Coverity).
[wine/zf.git] / dlls / comctl32 / propsheet.c
blob1604b9e9619f11495492a767d155b86587f1b5e6
1 /*
2 * Property Sheets
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_RECALCPAGESIZES
36 * o WM_HELP
37 * o WM_CONTEXTMENU
38 * - Notifications:
39 * o PSN_GETOBJECT
40 * o PSN_QUERYINITIALFOCUS
41 * o PSN_TRANSLATEACCELERATOR
42 * - Styles:
43 * o PSH_RTLREADING
44 * o PSH_STRETCHWATERMARK
45 * o PSH_USEPAGELANG
46 * o PSH_USEPSTARTPAGE
47 * - Page styles:
48 * o PSP_USEFUSIONCONTEXT
49 * o PSP_USEREFPARENT
52 #include <stdarg.h>
53 #include <string.h>
55 #define NONAMELESSUNION
57 #include "windef.h"
58 #include "winbase.h"
59 #include "wingdi.h"
60 #include "winuser.h"
61 #include "winnls.h"
62 #include "commctrl.h"
63 #include "prsht.h"
64 #include "comctl32.h"
65 #include "uxtheme.h"
67 #include "wine/debug.h"
69 /******************************************************************************
70 * Data structures
72 #include "pshpack2.h"
74 typedef struct
76 WORD dlgVer;
77 WORD signature;
78 DWORD helpID;
79 DWORD exStyle;
80 DWORD style;
81 } MyDLGTEMPLATEEX;
83 typedef struct
85 DWORD helpid;
86 DWORD exStyle;
87 DWORD style;
88 short x;
89 short y;
90 short cx;
91 short cy;
92 DWORD id;
93 } MyDLGITEMTEMPLATEEX;
94 #include "poppack.h"
96 typedef struct tagPropPageInfo
98 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
99 HWND hwndPage;
100 BOOL isDirty;
101 LPCWSTR pszText;
102 BOOL hasHelp;
103 BOOL useCallback;
104 BOOL hasIcon;
105 } PropPageInfo;
107 typedef struct tagPropSheetInfo
109 HWND hwnd;
110 PROPSHEETHEADERW ppshheader;
111 BOOL unicode;
112 LPWSTR strPropertiesFor;
113 int nPages;
114 int active_page;
115 BOOL isModeless;
116 BOOL hasHelp;
117 BOOL hasApply;
118 BOOL hasFinish;
119 BOOL usePropPage;
120 BOOL useCallback;
121 BOOL activeValid;
122 PropPageInfo* proppage;
123 HFONT hFont;
124 HFONT hFontBold;
125 int width;
126 int height;
127 HIMAGELIST hImageList;
128 BOOL ended;
129 INT result;
130 } PropSheetInfo;
132 typedef struct
134 int x;
135 int y;
136 } PADDING_INFO;
138 /******************************************************************************
139 * Defines and global variables
142 static const WCHAR PropSheetInfoStr[] = L"PropertySheetInfo";
144 #define PSP_INTERNAL_UNICODE 0x80000000
146 #define MAX_CAPTION_LENGTH 255
147 #define MAX_TABTEXT_LENGTH 255
148 #define MAX_BUTTONTEXT_LENGTH 64
150 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
152 /* Wizard metrics specified in DLUs */
153 #define WIZARD_PADDING 7
154 #define WIZARD_HEADER_HEIGHT 36
156 /******************************************************************************
157 * Prototypes
159 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
160 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
161 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
162 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
163 int index,
164 int skipdir,
165 HPROPSHEETPAGE hpage);
166 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo, int original_index);
167 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
169 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
171 static INT_PTR CALLBACK
172 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
174 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
176 static WCHAR *heap_strdupW(const WCHAR *str)
178 int len = lstrlenW(str) + 1;
179 WCHAR *ret = Alloc(len * sizeof(WCHAR));
180 lstrcpyW(ret, str);
181 return ret;
184 static WCHAR *heap_strdupAtoW(const char *str)
186 WCHAR *ret;
187 INT len;
189 len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
190 ret = Alloc(len * sizeof(WCHAR));
191 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
193 return ret;
196 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
197 /******************************************************************************
198 * PROPSHEET_UnImplementedFlags
200 * Document use of flags we don't implement yet.
202 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
204 CHAR string[256];
206 string[0] = '\0';
209 * unhandled header flags:
210 * PSH_RTLREADING 0x00000800
211 * PSH_STRETCHWATERMARK 0x00040000
212 * PSH_USEPAGELANG 0x00200000
215 add_flag(PSH_RTLREADING);
216 add_flag(PSH_STRETCHWATERMARK);
217 add_flag(PSH_USEPAGELANG);
218 if (string[0] != '\0')
219 FIXME("%s\n", string);
221 #undef add_flag
223 /******************************************************************************
224 * PROPSHEET_GetPageRect
226 * Retrieve rect from tab control and map into the dialog for SetWindowPos
228 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
229 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
231 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
232 HWND hwndChild;
233 RECT r;
235 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
236 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
237 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
238 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
240 rc->left = rc->top = WIZARD_PADDING;
242 else
244 rc->left = rc->top = 0;
246 rc->right = psInfo->width - rc->left;
247 rc->bottom = psInfo->height - rc->top;
248 MapDialogRect(hwndDlg, rc);
250 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
251 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
252 !(ppshpage->dwFlags & PSP_HIDEHEADER))
254 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
255 GetClientRect(hwndChild, &r);
256 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
257 rc->top += r.bottom + 1;
259 } else {
260 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
261 GetClientRect(hwndTabCtrl, rc);
262 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
263 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
267 /******************************************************************************
268 * PROPSHEET_FindPageByResId
270 * Find page index corresponding to page resource id.
272 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
274 INT i;
276 for (i = 0; i < psInfo->nPages; i++)
278 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
280 /* Fixme: if resource ID is a string shall we use strcmp ??? */
281 if (lppsp->u.pszTemplate == (LPVOID)resId)
282 break;
285 return i;
288 /******************************************************************************
289 * PROPSHEET_CollectSheetInfoCommon
291 * Common code for PROPSHEET_CollectSheetInfoA/W
293 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
295 PROPSHEET_UnImplementedFlags(dwFlags);
297 psInfo->hasHelp = dwFlags & PSH_HASHELP;
298 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
299 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
300 psInfo->isModeless = dwFlags & PSH_MODELESS;
301 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
302 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
303 psInfo->active_page = 0;
305 psInfo->result = 0;
306 psInfo->hImageList = 0;
307 psInfo->activeValid = FALSE;
310 /******************************************************************************
311 * PROPSHEET_CollectSheetInfoA
313 * Collect relevant data.
315 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
316 PropSheetInfo * psInfo)
318 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
319 DWORD dwFlags = lppsh->dwFlags;
321 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
323 memcpy(&psInfo->ppshheader,lppsh,dwSize);
324 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",
325 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
326 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
328 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
329 psInfo->ppshheader.pszCaption = NULL;
330 else
332 if (!IS_INTRESOURCE(lppsh->pszCaption))
334 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
335 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
337 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
338 psInfo->ppshheader.pszCaption = caption;
341 psInfo->nPages = lppsh->nPages;
343 if (dwFlags & PSH_USEPSTARTPAGE)
345 TRACE("PSH_USEPSTARTPAGE is on\n");
346 psInfo->active_page = 0;
348 else
349 psInfo->active_page = lppsh->u2.nStartPage;
351 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
354 /******************************************************************************
355 * PROPSHEET_CollectSheetInfoW
357 * Collect relevant data.
359 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
360 PropSheetInfo * psInfo)
362 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
363 DWORD dwFlags = lppsh->dwFlags;
365 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
367 memcpy(&psInfo->ppshheader,lppsh,dwSize);
368 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",
369 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
371 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
372 psInfo->ppshheader.pszCaption = NULL;
373 else
375 if (!IS_INTRESOURCE(lppsh->pszCaption))
376 psInfo->ppshheader.pszCaption = heap_strdupW( lppsh->pszCaption );
378 psInfo->nPages = lppsh->nPages;
380 if (dwFlags & PSH_USEPSTARTPAGE)
382 TRACE("PSH_USEPSTARTPAGE is on\n");
383 psInfo->active_page = 0;
385 else
386 psInfo->active_page = lppsh->u2.nStartPage;
388 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
391 /******************************************************************************
392 * PROPSHEET_CollectPageInfo
394 * Collect property sheet data.
395 * With code taken from DIALOG_ParseTemplate32.
397 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
398 PropSheetInfo * psInfo,
399 int index, BOOL resize)
401 const DLGTEMPLATE* pTemplate;
402 const WORD* p;
403 DWORD dwFlags;
404 int width, height;
406 if (!lppsp)
407 return FALSE;
409 TRACE("\n");
410 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
411 psInfo->proppage[index].hwndPage = 0;
412 psInfo->proppage[index].isDirty = FALSE;
415 * Process property page flags.
417 dwFlags = lppsp->dwFlags;
418 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
419 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
420 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
422 /* as soon as we have a page with the help flag, set the sheet flag on */
423 if (psInfo->proppage[index].hasHelp)
424 psInfo->hasHelp = TRUE;
427 * Process page template.
429 if (dwFlags & PSP_DLGINDIRECT)
430 pTemplate = lppsp->u.pResource;
431 else if(dwFlags & PSP_INTERNAL_UNICODE )
433 HRSRC hResource = FindResourceW(lppsp->hInstance,
434 lppsp->u.pszTemplate,
435 (LPWSTR)RT_DIALOG);
436 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
437 hResource);
438 pTemplate = LockResource(hTemplate);
440 else
442 HRSRC hResource = FindResourceA(lppsp->hInstance,
443 (LPCSTR)lppsp->u.pszTemplate,
444 (LPSTR)RT_DIALOG);
445 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
446 hResource);
447 pTemplate = LockResource(hTemplate);
451 * Extract the size of the page and the caption.
453 if (!pTemplate)
454 return FALSE;
456 p = (const WORD *)pTemplate;
458 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
460 /* DLGTEMPLATEEX (not defined in any std. header file) */
462 p++; /* dlgVer */
463 p++; /* signature */
464 p += 2; /* help ID */
465 p += 2; /* ext style */
466 p += 2; /* style */
468 else
470 /* DLGTEMPLATE */
472 p += 2; /* style */
473 p += 2; /* ext style */
476 p++; /* nb items */
477 p++; /* x */
478 p++; /* y */
479 width = (WORD)*p; p++;
480 height = (WORD)*p; p++;
482 if (lppsp->dwFlags & (PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE))
483 psInfo->ppshheader.dwFlags |= PSH_HEADER;
485 /* Special calculation for interior wizard pages so the largest page is
486 * calculated correctly. We need to add all the padding and space occupied
487 * by the header so the width and height sums up to the whole wizard client
488 * area. */
489 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
490 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
491 !(dwFlags & PSP_HIDEHEADER))
493 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
494 width += 2 * WIZARD_PADDING;
496 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
498 height += 2 * WIZARD_PADDING;
499 width += 2 * WIZARD_PADDING;
502 /* remember the largest width and height */
503 if (resize)
505 if (width > psInfo->width)
506 psInfo->width = width;
508 if (height > psInfo->height)
509 psInfo->height = height;
512 /* menu */
513 switch ((WORD)*p)
515 case 0x0000:
516 p++;
517 break;
518 case 0xffff:
519 p += 2;
520 break;
521 default:
522 p += lstrlenW( p ) + 1;
523 break;
526 /* class */
527 switch ((WORD)*p)
529 case 0x0000:
530 p++;
531 break;
532 case 0xffff:
533 p += 2;
534 break;
535 default:
536 p += lstrlenW( p ) + 1;
537 break;
540 /* Extract the caption */
541 psInfo->proppage[index].pszText = p;
542 TRACE("Tab %d %s\n",index,debugstr_w( p ));
544 if (dwFlags & PSP_USETITLE)
546 WCHAR szTitle[256];
547 const WCHAR *pTitle;
549 if (IS_INTRESOURCE( lppsp->pszTitle ))
551 if (LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle, szTitle, ARRAY_SIZE(szTitle)))
552 pTitle = szTitle;
553 else if (*p)
554 pTitle = p;
555 else
556 pTitle = L"(null)";
558 else
559 pTitle = lppsp->pszTitle;
561 psInfo->proppage[index].pszText = heap_strdupW( pTitle );
565 * Build the image list for icons
567 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
569 HICON hIcon;
570 int icon_cx = GetSystemMetrics(SM_CXSMICON);
571 int icon_cy = GetSystemMetrics(SM_CYSMICON);
573 if (dwFlags & PSP_USEICONID)
574 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
575 icon_cx, icon_cy, LR_DEFAULTCOLOR);
576 else
577 hIcon = lppsp->u2.hIcon;
579 if ( hIcon )
581 if (psInfo->hImageList == 0 )
582 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
584 ImageList_AddIcon(psInfo->hImageList, hIcon);
589 return TRUE;
592 /******************************************************************************
593 * PROPSHEET_CreateDialog
595 * Creates the actual property sheet.
597 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
599 LRESULT ret;
600 LPCVOID template;
601 LPVOID temp = 0;
602 HRSRC hRes;
603 DWORD resSize;
604 WORD resID = IDD_PROPSHEET;
606 TRACE("(%p)\n", psInfo);
607 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
608 resID = IDD_WIZARD;
610 if( psInfo->unicode )
612 if(!(hRes = FindResourceW(COMCTL32_hModule,
613 MAKEINTRESOURCEW(resID),
614 (LPWSTR)RT_DIALOG)))
615 return -1;
617 else
619 if(!(hRes = FindResourceA(COMCTL32_hModule,
620 MAKEINTRESOURCEA(resID),
621 (LPSTR)RT_DIALOG)))
622 return -1;
625 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
626 return -1;
629 * Make a copy of the dialog template.
631 resSize = SizeofResource(COMCTL32_hModule, hRes);
633 temp = Alloc(2 * resSize);
635 if (!temp)
636 return -1;
638 memcpy(temp, template, resSize);
640 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
642 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
643 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
644 else
645 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
647 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
648 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
650 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
651 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
652 else
653 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
656 if (psInfo->useCallback)
657 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
659 /* NOTE: MSDN states "Returns a positive value if successful, or -1
660 * otherwise for modal property sheets.", but this is wrong. The
661 * actual return value is either TRUE (success), FALSE (cancel) or
662 * -1 (error). */
663 if( psInfo->unicode )
665 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
666 temp, psInfo->ppshheader.hwndParent,
667 PROPSHEET_DialogProc, (LPARAM)psInfo);
668 if ( !ret ) ret = -1;
670 else
672 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
673 temp, psInfo->ppshheader.hwndParent,
674 PROPSHEET_DialogProc, (LPARAM)psInfo);
675 if ( !ret ) ret = -1;
678 Free(temp);
680 return ret;
683 /******************************************************************************
684 * PROPSHEET_SizeMismatch
686 * Verify that the tab control and the "largest" property sheet page dlg. template
687 * match in size.
689 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
691 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
692 RECT rcOrigTab, rcPage;
695 * Original tab size.
697 GetClientRect(hwndTabCtrl, &rcOrigTab);
698 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
701 * Biggest page size.
703 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
704 MapDialogRect(hwndDlg, &rcPage);
705 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
707 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
708 return TRUE;
709 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
710 return TRUE;
712 return FALSE;
715 /******************************************************************************
716 * PROPSHEET_AdjustSize
718 * Resizes the property sheet and the tab control to fit the largest page.
720 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
722 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
723 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
724 RECT rc,tabRect;
725 int buttonHeight;
726 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
727 RECT units;
728 LONG style;
730 /* Get the height of buttons */
731 GetClientRect(hwndButton, &rc);
732 buttonHeight = rc.bottom;
735 * Biggest page size.
737 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
738 MapDialogRect(hwndDlg, &rc);
740 /* retrieve the dialog units */
741 units.left = units.right = 4;
742 units.top = units.bottom = 8;
743 MapDialogRect(hwndDlg, &units);
746 * Resize the tab control.
748 GetClientRect(hwndTabCtrl,&tabRect);
750 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
752 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
754 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
755 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
758 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
760 rc.right = rc.left + tabRect.right - tabRect.left;
761 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
764 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
766 rc.right -= rc.left;
767 rc.bottom -= rc.top;
768 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
769 hwndTabCtrl, rc.right, rc.bottom);
770 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
771 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
773 GetClientRect(hwndTabCtrl, &rc);
775 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
777 rc.right += (padding.x * 2);
778 rc.bottom += buttonHeight + (3 * padding.y);
780 style = GetWindowLongW(hwndDlg, GWL_STYLE);
781 if (!(style & WS_CHILD))
782 AdjustWindowRect(&rc, style, FALSE);
784 rc.right -= rc.left;
785 rc.bottom -= rc.top;
788 * Resize the property sheet.
790 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
791 hwndDlg, rc.right, rc.bottom);
792 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
793 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
794 return TRUE;
797 /******************************************************************************
798 * PROPSHEET_AdjustSizeWizard
800 * Resizes the property sheet to fit the largest page.
802 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
804 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
805 RECT rc, lineRect, dialogRect;
807 /* Biggest page size */
808 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
809 MapDialogRect(hwndDlg, &rc);
811 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
813 /* Add space for the buttons row */
814 GetWindowRect(hwndLine, &lineRect);
815 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
816 GetClientRect(hwndDlg, &dialogRect);
817 rc.bottom += dialogRect.bottom - lineRect.top - 1;
819 /* Convert the client coordinates to window coordinates */
820 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
822 /* Resize the property sheet */
823 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
824 hwndDlg, rc.right, rc.bottom);
825 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
826 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
828 return TRUE;
831 /******************************************************************************
832 * PROPSHEET_AdjustButtons
834 * Adjusts the buttons' positions.
836 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
838 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
839 RECT rcSheet;
840 int x, y;
841 int num_buttons = 2;
842 int buttonWidth, buttonHeight;
843 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
845 if (psInfo->hasApply)
846 num_buttons++;
848 if (psInfo->hasHelp)
849 num_buttons++;
852 * Obtain the size of the buttons.
854 GetClientRect(hwndButton, &rcSheet);
855 buttonWidth = rcSheet.right;
856 buttonHeight = rcSheet.bottom;
859 * Get the size of the property sheet.
861 GetClientRect(hwndParent, &rcSheet);
864 * All buttons will be at this y coordinate.
866 y = rcSheet.bottom - (padding.y + buttonHeight);
869 * Position OK button and make it default.
871 hwndButton = GetDlgItem(hwndParent, IDOK);
873 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
875 SetWindowPos(hwndButton, 0, x, y, 0, 0,
876 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
878 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
882 * Position Cancel button.
884 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
886 x += padding.x + buttonWidth;
888 SetWindowPos(hwndButton, 0, x, y, 0, 0,
889 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
892 * Position Apply button.
894 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
896 if(psInfo->hasApply)
897 x += padding.x + buttonWidth;
898 else
899 ShowWindow(hwndButton, SW_HIDE);
901 SetWindowPos(hwndButton, 0, x, y, 0, 0,
902 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
903 EnableWindow(hwndButton, FALSE);
906 * Position Help button.
908 hwndButton = GetDlgItem(hwndParent, IDHELP);
910 x += padding.x + buttonWidth;
911 SetWindowPos(hwndButton, 0, x, y, 0, 0,
912 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
914 if(!psInfo->hasHelp)
915 ShowWindow(hwndButton, SW_HIDE);
917 return TRUE;
920 /******************************************************************************
921 * PROPSHEET_AdjustButtonsWizard
923 * Adjusts the buttons' positions.
925 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
926 const PropSheetInfo* psInfo)
928 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
929 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
930 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
931 RECT rcSheet;
932 int x, y;
933 int num_buttons = 3;
934 int buttonWidth, buttonHeight, lineHeight, lineWidth;
935 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
937 if (psInfo->hasHelp)
938 num_buttons++;
939 if (psInfo->hasFinish)
940 num_buttons++;
943 * Obtain the size of the buttons.
945 GetClientRect(hwndButton, &rcSheet);
946 buttonWidth = rcSheet.right;
947 buttonHeight = rcSheet.bottom;
949 GetClientRect(hwndLine, &rcSheet);
950 lineHeight = rcSheet.bottom;
953 * Get the size of the property sheet.
955 GetClientRect(hwndParent, &rcSheet);
958 * All buttons will be at this y coordinate.
960 y = rcSheet.bottom - (padding.y + buttonHeight);
963 * Position the Back button.
965 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
967 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
969 SetWindowPos(hwndButton, 0, x, y, 0, 0,
970 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
973 * Position the Next button.
975 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
977 x += buttonWidth;
979 SetWindowPos(hwndButton, 0, x, y, 0, 0,
980 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
983 * Position the Finish button.
985 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
987 if (psInfo->hasFinish)
988 x += padding.x + buttonWidth;
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
993 if (!psInfo->hasFinish)
994 ShowWindow(hwndButton, SW_HIDE);
997 * Position the Cancel button.
999 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1001 x += padding.x + buttonWidth;
1003 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1004 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1007 * Position Help button.
1009 hwndButton = GetDlgItem(hwndParent, IDHELP);
1011 if (psInfo->hasHelp)
1013 x += padding.x + buttonWidth;
1015 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1016 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1018 else
1019 ShowWindow(hwndButton, SW_HIDE);
1021 if (psInfo->ppshheader.dwFlags &
1022 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1023 padding.x = 0;
1026 * Position and resize the sunken line.
1028 x = padding.x;
1029 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1031 lineWidth = rcSheet.right - (padding.x * 2);
1032 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1033 SWP_NOZORDER | SWP_NOACTIVATE);
1036 * Position and resize the header sunken line.
1039 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1040 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1041 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1042 ShowWindow(hwndLineHeader, SW_HIDE);
1044 return TRUE;
1047 /******************************************************************************
1048 * PROPSHEET_GetPaddingInfo
1050 * Returns the layout information.
1052 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1054 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1055 RECT rcTab;
1056 PADDING_INFO padding;
1058 GetWindowRect(hwndTab, &rcTab);
1059 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1061 padding.x = rcTab.left;
1062 padding.y = rcTab.top;
1064 return padding;
1067 /******************************************************************************
1068 * PROPSHEET_GetPaddingInfoWizard
1070 * Returns the layout information.
1071 * Vertical spacing is the distance between the line and the buttons.
1072 * Do NOT use the Help button to gather padding information when it isn't mapped
1073 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1074 * for it in this case !
1075 * FIXME: I'm not sure about any other coordinate problems with these evil
1076 * buttons. Fix it in case additional problems appear or maybe calculate
1077 * a padding in a completely different way, as this is somewhat messy.
1079 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1080 psInfo)
1082 PADDING_INFO padding;
1083 RECT rc;
1084 HWND hwndControl;
1085 INT idButton;
1086 POINT ptButton, ptLine;
1088 TRACE("\n");
1089 if (psInfo->hasHelp)
1091 idButton = IDHELP;
1093 else
1095 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1097 idButton = IDC_NEXT_BUTTON;
1099 else
1101 /* hopefully this is ok */
1102 idButton = IDCANCEL;
1106 hwndControl = GetDlgItem(hwndDlg, idButton);
1107 GetWindowRect(hwndControl, &rc);
1108 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1109 ptButton.x = rc.left;
1110 ptButton.y = rc.top;
1112 /* Line */
1113 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1114 GetWindowRect(hwndControl, &rc);
1115 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1116 ptLine.x = rc.left;
1117 ptLine.y = rc.bottom;
1119 padding.y = ptButton.y - ptLine.y;
1121 if (padding.y < 0)
1122 ERR("padding negative ! Please report this !\n");
1124 /* this is most probably not correct, but the best we have now */
1125 padding.x = padding.y;
1126 return padding;
1129 /******************************************************************************
1130 * PROPSHEET_CreateTabControl
1132 * Insert the tabs in the tab control.
1134 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1135 const PropSheetInfo * psInfo)
1137 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1138 TCITEMW item;
1139 int i, nTabs;
1140 int iImage = 0;
1142 TRACE("\n");
1143 item.mask = TCIF_TEXT;
1144 item.cchTextMax = MAX_TABTEXT_LENGTH;
1146 nTabs = psInfo->nPages;
1149 * Set the image list for icons.
1151 if (psInfo->hImageList)
1153 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1156 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1157 for (i = 0; i < nTabs; i++)
1159 if ( psInfo->proppage[i].hasIcon )
1161 item.mask |= TCIF_IMAGE;
1162 item.iImage = iImage++;
1164 else
1166 item.mask &= ~TCIF_IMAGE;
1169 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1170 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1172 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1174 return TRUE;
1177 /******************************************************************************
1178 * PROPSHEET_WizardSubclassProc
1180 * Subclassing window procedure for wizard exterior pages to prevent drawing
1181 * background and so drawing above the watermark.
1183 static LRESULT CALLBACK
1184 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1186 switch (uMsg)
1188 case WM_ERASEBKGND:
1189 return TRUE;
1191 case WM_CTLCOLORSTATIC:
1192 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1193 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1196 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1200 * Get the size of an in-memory Template
1202 *( Based on the code of PROPSHEET_CollectPageInfo)
1203 * See also dialog.c/DIALOG_ParseTemplate32().
1206 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1209 const WORD* p = (const WORD *)pTemplate;
1210 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1211 WORD nrofitems;
1212 UINT ret;
1214 if (istemplateex)
1216 /* DLGTEMPLATEEX (not defined in any std. header file) */
1218 TRACE("is DLGTEMPLATEEX\n");
1219 p++; /* dlgVer */
1220 p++; /* signature */
1221 p += 2; /* help ID */
1222 p += 2; /* ext style */
1223 p += 2; /* style */
1225 else
1227 /* DLGTEMPLATE */
1229 TRACE("is DLGTEMPLATE\n");
1230 p += 2; /* style */
1231 p += 2; /* ext style */
1234 nrofitems = (WORD)*p; p++; /* nb items */
1235 p++; /* x */
1236 p++; /* y */
1237 p++; /* width */
1238 p++; /* height */
1240 /* menu */
1241 switch ((WORD)*p)
1243 case 0x0000:
1244 p++;
1245 break;
1246 case 0xffff:
1247 p += 2;
1248 break;
1249 default:
1250 TRACE("menu %s\n",debugstr_w( p ));
1251 p += lstrlenW( p ) + 1;
1252 break;
1255 /* class */
1256 switch ((WORD)*p)
1258 case 0x0000:
1259 p++;
1260 break;
1261 case 0xffff:
1262 p += 2; /* 0xffff plus predefined window class ordinal value */
1263 break;
1264 default:
1265 TRACE("class %s\n",debugstr_w( p ));
1266 p += lstrlenW( p ) + 1;
1267 break;
1270 /* title */
1271 TRACE("title %s\n",debugstr_w( p ));
1272 p += lstrlenW( p ) + 1;
1274 /* font, if DS_SETFONT set */
1275 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1276 pTemplate->style)))
1278 p+=(istemplateex)?3:1;
1279 TRACE("font %s\n",debugstr_w( p ));
1280 p += lstrlenW( p ) + 1; /* the font name */
1283 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1284 * that are following the DLGTEMPLATE(EX) data */
1285 TRACE("%d items\n",nrofitems);
1286 while (nrofitems > 0)
1288 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1290 /* skip header */
1291 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1293 /* check class */
1294 switch ((WORD)*p)
1296 case 0x0000:
1297 p++;
1298 break;
1299 case 0xffff:
1300 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1301 p += 2;
1302 break;
1303 default:
1304 TRACE("class %s\n",debugstr_w( p ));
1305 p += lstrlenW( p ) + 1;
1306 break;
1309 /* check title text */
1310 switch ((WORD)*p)
1312 case 0x0000:
1313 p++;
1314 break;
1315 case 0xffff:
1316 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1317 p += 2;
1318 break;
1319 default:
1320 TRACE("text %s\n",debugstr_w( p ));
1321 p += lstrlenW( p ) + 1;
1322 break;
1324 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1325 --nrofitems;
1328 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1329 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1330 return ret;
1333 /******************************************************************************
1334 * PROPSHEET_CreatePage
1336 * Creates a page.
1338 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1339 int index,
1340 const PropSheetInfo * psInfo,
1341 LPCPROPSHEETPAGEW ppshpage)
1343 const DLGTEMPLATE* pTemplate;
1344 HWND hwndPage;
1345 DWORD resSize;
1346 DLGTEMPLATE* pTemplateCopy = NULL;
1348 TRACE("index %d\n", index);
1350 if (ppshpage == NULL)
1352 return FALSE;
1355 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1357 pTemplate = ppshpage->u.pResource;
1358 resSize = GetTemplateSize(pTemplate);
1360 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1362 HRSRC hResource;
1363 HANDLE hTemplate;
1365 hResource = FindResourceW(ppshpage->hInstance,
1366 ppshpage->u.pszTemplate,
1367 (LPWSTR)RT_DIALOG);
1368 if(!hResource)
1369 return FALSE;
1371 resSize = SizeofResource(ppshpage->hInstance, hResource);
1373 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1374 if(!hTemplate)
1375 return FALSE;
1377 pTemplate = LockResource(hTemplate);
1379 * Make a copy of the dialog template to make it writable
1382 else
1384 HRSRC hResource;
1385 HANDLE hTemplate;
1387 hResource = FindResourceA(ppshpage->hInstance,
1388 (LPCSTR)ppshpage->u.pszTemplate,
1389 (LPSTR)RT_DIALOG);
1390 if(!hResource)
1391 return FALSE;
1393 resSize = SizeofResource(ppshpage->hInstance, hResource);
1395 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1396 if(!hTemplate)
1397 return FALSE;
1399 pTemplate = LockResource(hTemplate);
1401 * Make a copy of the dialog template to make it writable
1404 pTemplateCopy = Alloc(resSize);
1405 if (!pTemplateCopy)
1406 return FALSE;
1408 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1409 memcpy(pTemplateCopy, pTemplate, resSize);
1411 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1413 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1414 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1415 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1416 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1417 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1418 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1419 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1420 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1422 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1424 else
1426 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1427 pTemplateCopy->style &= ~DS_MODALFRAME;
1428 pTemplateCopy->style &= ~WS_CAPTION;
1429 pTemplateCopy->style &= ~WS_SYSMENU;
1430 pTemplateCopy->style &= ~WS_POPUP;
1431 pTemplateCopy->style &= ~WS_DISABLED;
1432 pTemplateCopy->style &= ~WS_VISIBLE;
1433 pTemplateCopy->style &= ~WS_THICKFRAME;
1435 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1438 if (psInfo->proppage[index].useCallback)
1439 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1440 (LPPROPSHEETPAGEW)ppshpage);
1442 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1443 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1444 pTemplateCopy,
1445 hwndParent,
1446 ppshpage->pfnDlgProc,
1447 (LPARAM)ppshpage);
1448 else
1449 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1450 pTemplateCopy,
1451 hwndParent,
1452 ppshpage->pfnDlgProc,
1453 (LPARAM)ppshpage);
1454 /* Free a no more needed copy */
1455 Free(pTemplateCopy);
1457 if(!hwndPage)
1458 return FALSE;
1460 psInfo->proppage[index].hwndPage = hwndPage;
1462 /* Subclass exterior wizard pages */
1463 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1464 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1465 (ppshpage->dwFlags & PSP_HIDEHEADER))
1467 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1468 (DWORD_PTR)ppshpage);
1470 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1471 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1473 return TRUE;
1476 /******************************************************************************
1477 * PROPSHEET_LoadWizardBitmaps
1479 * Loads the watermark and header bitmaps for a wizard.
1481 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1483 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1485 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1486 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1487 considers hbmWatermark as valid. */
1488 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1489 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1491 psInfo->ppshheader.u4.hbmWatermark =
1492 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1495 /* Same behavior as for watermarks */
1496 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1497 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1499 psInfo->ppshheader.u5.hbmHeader =
1500 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1506 /******************************************************************************
1507 * PROPSHEET_ShowPage
1509 * Displays or creates the specified page.
1511 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1513 HWND hwndTabCtrl;
1514 HWND hwndLineHeader;
1515 HWND control;
1516 LPCPROPSHEETPAGEW ppshpage;
1518 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1519 if (index == psInfo->active_page)
1521 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1522 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1523 return TRUE;
1526 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1527 if (psInfo->proppage[index].hwndPage == 0)
1529 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1532 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1534 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1535 psInfo->proppage[index].pszText);
1537 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1538 if(control != NULL)
1539 SetFocus(control);
1542 if (psInfo->active_page != -1)
1543 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1545 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1547 /* Synchronize current selection with tab control
1548 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1549 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1550 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1552 psInfo->active_page = index;
1553 psInfo->activeValid = TRUE;
1555 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1557 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1558 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1560 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1561 ShowWindow(hwndLineHeader, SW_HIDE);
1562 else
1563 ShowWindow(hwndLineHeader, SW_SHOW);
1566 return TRUE;
1569 /******************************************************************************
1570 * PROPSHEET_Back
1572 static BOOL PROPSHEET_Back(HWND hwndDlg)
1574 PSHNOTIFY psn;
1575 HWND hwndPage;
1576 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1577 LRESULT result;
1578 int idx;
1580 TRACE("active_page %d\n", psInfo->active_page);
1581 if (psInfo->active_page < 0)
1582 return FALSE;
1584 psn.hdr.code = PSN_WIZBACK;
1585 psn.hdr.hwndFrom = hwndDlg;
1586 psn.hdr.idFrom = 0;
1587 psn.lParam = 0;
1589 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1591 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1592 if (result == -1)
1593 return FALSE;
1594 else if (result == 0)
1595 idx = psInfo->active_page - 1;
1596 else
1597 idx = PROPSHEET_FindPageByResId(psInfo, result);
1599 if (idx >= 0 && idx < psInfo->nPages)
1601 if (PROPSHEET_CanSetCurSel(hwndDlg))
1603 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1604 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1605 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1608 return TRUE;
1611 /******************************************************************************
1612 * PROPSHEET_Next
1614 static BOOL PROPSHEET_Next(HWND hwndDlg)
1616 PSHNOTIFY psn;
1617 HWND hwndPage;
1618 LRESULT msgResult = 0;
1619 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1620 int idx;
1622 TRACE("active_page %d\n", psInfo->active_page);
1623 if (psInfo->active_page < 0)
1624 return FALSE;
1626 psn.hdr.code = PSN_WIZNEXT;
1627 psn.hdr.hwndFrom = hwndDlg;
1628 psn.hdr.idFrom = 0;
1629 psn.lParam = 0;
1631 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1633 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1634 if (msgResult == -1)
1635 return FALSE;
1636 else if (msgResult == 0)
1637 idx = psInfo->active_page + 1;
1638 else
1639 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1641 if (idx < psInfo->nPages )
1643 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1645 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1646 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1647 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1651 return TRUE;
1654 /******************************************************************************
1655 * PROPSHEET_Finish
1657 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1659 PSHNOTIFY psn;
1660 HWND hwndPage;
1661 LRESULT msgResult = 0;
1662 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1664 TRACE("active_page %d\n", psInfo->active_page);
1665 if (psInfo->active_page < 0)
1666 return FALSE;
1668 psn.hdr.code = PSN_WIZFINISH;
1669 psn.hdr.hwndFrom = hwndDlg;
1670 psn.hdr.idFrom = 0;
1671 psn.lParam = 0;
1673 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1675 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1677 TRACE("msg result %ld\n", msgResult);
1679 if (msgResult != 0)
1680 return FALSE;
1682 if (psInfo->result == 0)
1683 psInfo->result = IDOK;
1684 if (psInfo->isModeless)
1685 psInfo->activeValid = FALSE;
1686 else
1687 psInfo->ended = TRUE;
1689 return TRUE;
1692 /******************************************************************************
1693 * PROPSHEET_Apply
1695 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1697 int i;
1698 HWND hwndPage;
1699 PSHNOTIFY psn;
1700 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1702 TRACE("active_page %d\n", psInfo->active_page);
1703 if (psInfo->active_page < 0)
1704 return FALSE;
1706 psn.hdr.hwndFrom = hwndDlg;
1707 psn.hdr.idFrom = 0;
1708 psn.lParam = 0;
1712 * Send PSN_KILLACTIVE to the current page.
1714 psn.hdr.code = PSN_KILLACTIVE;
1716 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1718 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1719 return FALSE;
1722 * Send PSN_APPLY to all pages.
1724 psn.hdr.code = PSN_APPLY;
1725 psn.lParam = lParam;
1727 for (i = 0; i < psInfo->nPages; i++)
1729 hwndPage = psInfo->proppage[i].hwndPage;
1730 if (hwndPage)
1732 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1734 case PSNRET_INVALID:
1735 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1736 /* fall through */
1737 case PSNRET_INVALID_NOCHANGEPAGE:
1738 return FALSE;
1743 if(lParam)
1745 psInfo->activeValid = FALSE;
1747 else if(psInfo->active_page >= 0)
1749 psn.hdr.code = PSN_SETACTIVE;
1750 psn.lParam = 0;
1751 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1752 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1755 return TRUE;
1758 /******************************************************************************
1759 * PROPSHEET_Cancel
1761 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1763 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1764 HWND hwndPage;
1765 PSHNOTIFY psn;
1766 int i;
1768 TRACE("active_page %d\n", psInfo->active_page);
1769 if (psInfo->active_page < 0)
1770 return;
1772 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1773 psn.hdr.code = PSN_QUERYCANCEL;
1774 psn.hdr.hwndFrom = hwndDlg;
1775 psn.hdr.idFrom = 0;
1776 psn.lParam = 0;
1778 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1779 return;
1781 psn.hdr.code = PSN_RESET;
1782 psn.lParam = lParam;
1784 for (i = 0; i < psInfo->nPages; i++)
1786 hwndPage = psInfo->proppage[i].hwndPage;
1788 if (hwndPage)
1789 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1792 if (psInfo->isModeless)
1794 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1795 psInfo->activeValid = FALSE;
1797 else
1798 psInfo->ended = TRUE;
1801 /******************************************************************************
1802 * PROPSHEET_Help
1804 static void PROPSHEET_Help(HWND hwndDlg)
1806 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1807 HWND hwndPage;
1808 PSHNOTIFY psn;
1810 TRACE("active_page %d\n", psInfo->active_page);
1811 if (psInfo->active_page < 0)
1812 return;
1814 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1815 psn.hdr.code = PSN_HELP;
1816 psn.hdr.hwndFrom = hwndDlg;
1817 psn.hdr.idFrom = 0;
1818 psn.lParam = 0;
1820 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1823 /******************************************************************************
1824 * PROPSHEET_Changed
1826 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1828 int i;
1829 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1831 TRACE("\n");
1832 if (!psInfo) return;
1834 * Set the dirty flag of this page.
1836 for (i = 0; i < psInfo->nPages; i++)
1838 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1839 psInfo->proppage[i].isDirty = TRUE;
1843 * Enable the Apply button.
1845 if (psInfo->hasApply)
1847 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1849 EnableWindow(hwndApplyBtn, TRUE);
1853 /******************************************************************************
1854 * PROPSHEET_UnChanged
1856 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1858 int i;
1859 BOOL noPageDirty = TRUE;
1860 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1861 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1863 TRACE("\n");
1864 if ( !psInfo ) return;
1865 for (i = 0; i < psInfo->nPages; i++)
1867 /* set the specified page as clean */
1868 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1869 psInfo->proppage[i].isDirty = FALSE;
1871 /* look to see if there are any dirty pages */
1872 if (psInfo->proppage[i].isDirty)
1873 noPageDirty = FALSE;
1877 * Disable Apply button.
1879 if (noPageDirty)
1880 EnableWindow(hwndApplyBtn, FALSE);
1883 /******************************************************************************
1884 * PROPSHEET_PressButton
1886 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1888 TRACE("buttonID %d\n", buttonID);
1889 switch (buttonID)
1891 case PSBTN_APPLYNOW:
1892 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1893 break;
1894 case PSBTN_BACK:
1895 PROPSHEET_Back(hwndDlg);
1896 break;
1897 case PSBTN_CANCEL:
1898 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1899 break;
1900 case PSBTN_FINISH:
1901 PROPSHEET_Finish(hwndDlg);
1902 break;
1903 case PSBTN_HELP:
1904 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1905 break;
1906 case PSBTN_NEXT:
1907 PROPSHEET_Next(hwndDlg);
1908 break;
1909 case PSBTN_OK:
1910 PROPSHEET_DoCommand(hwndDlg, IDOK);
1911 break;
1912 default:
1913 FIXME("Invalid button index %d\n", buttonID);
1918 /*************************************************************************
1919 * BOOL PROPSHEET_CanSetCurSel [Internal]
1921 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1923 * PARAMS
1924 * hwndDlg [I] handle to a Dialog hWnd
1926 * RETURNS
1927 * TRUE if Current Selection can change
1929 * NOTES
1931 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1933 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1934 HWND hwndPage;
1935 PSHNOTIFY psn;
1936 BOOL res = FALSE;
1938 if (!psInfo)
1940 res = FALSE;
1941 goto end;
1944 TRACE("active_page %d\n", psInfo->active_page);
1945 if (psInfo->active_page < 0)
1947 res = TRUE;
1948 goto end;
1952 * Notify the current page.
1954 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1955 psn.hdr.code = PSN_KILLACTIVE;
1956 psn.hdr.hwndFrom = hwndDlg;
1957 psn.hdr.idFrom = 0;
1958 psn.lParam = 0;
1960 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1962 end:
1963 TRACE("<-- %d\n", res);
1964 return res;
1967 /******************************************************************************
1968 * PROPSHEET_SetCurSel
1970 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1971 int index,
1972 int skipdir,
1973 HPROPSHEETPAGE hpage
1976 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1977 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1978 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1980 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1982 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1984 if (index < 0 || index >= psInfo->nPages)
1986 TRACE("Could not find page to select!\n");
1987 return FALSE;
1990 /* unset active page while doing this transition. */
1991 if (psInfo->active_page != -1)
1992 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1993 psInfo->active_page = -1;
1995 while (1) {
1996 int result;
1997 PSHNOTIFY psn;
1998 RECT rc;
1999 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2001 if (hwndTabControl)
2002 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2004 psn.hdr.code = PSN_SETACTIVE;
2005 psn.hdr.hwndFrom = hwndDlg;
2006 psn.hdr.idFrom = 0;
2007 psn.lParam = 0;
2009 if (!psInfo->proppage[index].hwndPage) {
2010 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2011 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2013 if (!psInfo->isModeless)
2015 DestroyWindow(hwndDlg);
2016 return FALSE;
2019 if(index >= psInfo->nPages)
2020 index--;
2021 if(index < 0)
2022 return FALSE;
2023 continue;
2027 /* Resize the property sheet page to the fit in the Tab control
2028 * (for regular property sheets) or to fit in the client area (for
2029 * wizards).
2030 * NOTE: The resizing happens every time the page is selected and
2031 * not only when it's created (some applications depend on it). */
2032 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2033 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2034 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2035 rc.right - rc.left, rc.bottom - rc.top);
2036 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2037 rc.left, rc.top,
2038 rc.right - rc.left, rc.bottom - rc.top, 0);
2040 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2041 if (!result)
2042 break;
2043 if (result == -1) {
2044 index+=skipdir;
2045 if (index < 0) {
2046 index = 0;
2047 WARN("Tried to skip before first property sheet page!\n");
2048 break;
2050 if (index >= psInfo->nPages) {
2051 WARN("Tried to skip after last property sheet page!\n");
2052 index = psInfo->nPages-1;
2053 break;
2056 else if (result != 0)
2058 int old_index = index;
2059 index = PROPSHEET_FindPageByResId(psInfo, result);
2060 if(index >= psInfo->nPages) {
2061 index = old_index;
2062 WARN("Tried to skip to nonexistent page by res id\n");
2063 break;
2065 continue;
2069 /* Invalidate the header area */
2070 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2071 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2073 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2074 RECT r;
2076 GetClientRect(hwndLineHeader, &r);
2077 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2078 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2080 InvalidateRect(hwndDlg, &r, TRUE);
2084 * Display the new page.
2086 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2088 if (psInfo->proppage[index].hasHelp)
2089 EnableWindow(hwndHelp, TRUE);
2090 else
2091 EnableWindow(hwndHelp, FALSE);
2093 return TRUE;
2096 /******************************************************************************
2097 * PROPSHEET_SetCurSelId
2099 * Selects the page, specified by resource id.
2101 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2103 int idx;
2104 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2106 idx = PROPSHEET_FindPageByResId(psInfo, id);
2107 if (idx < psInfo->nPages )
2109 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2110 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2114 /******************************************************************************
2115 * PROPSHEET_SetTitleA
2117 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2119 if(!IS_INTRESOURCE(lpszText))
2121 WCHAR szTitle[256];
2122 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTitle, ARRAY_SIZE(szTitle));
2123 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2125 else
2127 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2131 /******************************************************************************
2132 * PROPSHEET_SetTitleW
2134 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2136 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2137 WCHAR szTitle[256];
2139 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2140 if (IS_INTRESOURCE(lpszText)) {
2141 if (!LoadStringW(psInfo->ppshheader.hInstance, LOWORD(lpszText), szTitle, ARRAY_SIZE(szTitle)))
2142 return;
2143 lpszText = szTitle;
2145 if (dwStyle & PSH_PROPTITLE)
2147 WCHAR* dest;
2148 int lentitle = lstrlenW(lpszText);
2149 int lenprop = lstrlenW(psInfo->strPropertiesFor);
2151 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2152 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2154 SetWindowTextW(hwndDlg, dest);
2155 Free(dest);
2157 else
2158 SetWindowTextW(hwndDlg, lpszText);
2161 /******************************************************************************
2162 * PROPSHEET_SetFinishTextA
2164 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2166 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2167 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2169 TRACE("'%s'\n", lpszText);
2170 /* Set text, show and enable the Finish button */
2171 SetWindowTextA(hwndButton, lpszText);
2172 ShowWindow(hwndButton, SW_SHOW);
2173 EnableWindow(hwndButton, TRUE);
2175 /* Make it default pushbutton */
2176 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2178 /* Hide Back button */
2179 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2180 ShowWindow(hwndButton, SW_HIDE);
2182 if (!psInfo->hasFinish)
2184 /* Hide Next button */
2185 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2186 ShowWindow(hwndButton, SW_HIDE);
2190 /******************************************************************************
2191 * PROPSHEET_SetFinishTextW
2193 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2195 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2196 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2198 TRACE("%s\n", debugstr_w(lpszText));
2199 /* Set text, show and enable the Finish button */
2200 SetWindowTextW(hwndButton, lpszText);
2201 ShowWindow(hwndButton, SW_SHOW);
2202 EnableWindow(hwndButton, TRUE);
2204 /* Make it default pushbutton */
2205 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2207 /* Hide Back button */
2208 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2209 ShowWindow(hwndButton, SW_HIDE);
2211 if (!psInfo->hasFinish)
2213 /* Hide Next button */
2214 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2215 ShowWindow(hwndButton, SW_HIDE);
2219 /******************************************************************************
2220 * PROPSHEET_QuerySiblings
2222 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2223 WPARAM wParam, LPARAM lParam)
2225 int i = 0;
2226 HWND hwndPage;
2227 LRESULT msgResult = 0;
2228 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2230 while ((i < psInfo->nPages) && (msgResult == 0))
2232 hwndPage = psInfo->proppage[i].hwndPage;
2233 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2234 i++;
2237 return msgResult;
2240 /******************************************************************************
2241 * PROPSHEET_InsertPage
2243 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2245 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2246 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2247 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2248 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2249 TCITEMW item;
2250 int index;
2252 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2254 if (IS_INTRESOURCE(hpageInsertAfter))
2255 index = LOWORD(hpageInsertAfter);
2256 else
2258 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2259 if (index < 0)
2261 TRACE("Could not find page to insert after!\n");
2262 return FALSE;
2264 index++;
2267 if (index > psInfo->nPages)
2268 index = psInfo->nPages;
2270 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2271 if (!ppi)
2272 return FALSE;
2275 * Fill in a new PropPageInfo entry.
2277 if (index > 0)
2278 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2279 memset(&ppi[index], 0, sizeof(PropPageInfo));
2280 if (index < psInfo->nPages)
2281 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2282 psInfo->proppage = ppi;
2284 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
2286 psInfo->proppage = prev_ppi;
2287 Free(ppi);
2288 return FALSE;
2291 psInfo->proppage[index].hpage = hpage;
2293 if (ppsp->dwFlags & PSP_PREMATURE)
2295 /* Create the page but don't show it */
2296 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
2298 psInfo->proppage = prev_ppi;
2299 Free(ppi);
2300 return FALSE;
2304 Free(prev_ppi);
2305 psInfo->nPages++;
2306 if (index <= psInfo->active_page)
2307 psInfo->active_page++;
2310 * Add a new tab to the tab control.
2312 item.mask = TCIF_TEXT;
2313 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2314 item.cchTextMax = MAX_TABTEXT_LENGTH;
2316 if (psInfo->hImageList)
2317 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2319 if (psInfo->proppage[index].hasIcon)
2321 item.mask |= TCIF_IMAGE;
2322 item.iImage = index;
2325 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2327 /* If it is the only page - show it */
2328 if (psInfo->nPages == 1)
2329 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2331 return TRUE;
2334 /******************************************************************************
2335 * PROPSHEET_AddPage
2337 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2339 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2340 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2341 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2344 /******************************************************************************
2345 * PROPSHEET_RemovePage
2347 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2348 int index,
2349 HPROPSHEETPAGE hpage)
2351 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2352 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2353 PropPageInfo* oldPages;
2355 TRACE("index %d, hpage %p\n", index, hpage);
2356 if (!psInfo) {
2357 return FALSE;
2360 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2362 /* Make sure that index is within range */
2363 if (index < 0 || index >= psInfo->nPages)
2365 TRACE("Could not find page to remove!\n");
2366 return FALSE;
2369 TRACE("total pages %d removing page %d active page %d\n",
2370 psInfo->nPages, index, psInfo->active_page);
2372 * Check if we're removing the active page.
2374 if (index == psInfo->active_page)
2376 if (psInfo->nPages > 1)
2378 if (index > 0)
2380 /* activate previous page */
2381 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2383 else
2385 /* activate the next page */
2386 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2387 psInfo->active_page = index;
2390 else
2392 psInfo->active_page = -1;
2393 if (!psInfo->isModeless)
2395 psInfo->ended = TRUE;
2396 return TRUE;
2400 else if (index < psInfo->active_page)
2401 psInfo->active_page--;
2403 /* Unsubclass the page dialog window */
2404 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2405 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2406 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2408 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2409 PROPSHEET_WizardSubclassProc, 1);
2412 /* Destroy page dialog window */
2413 DestroyWindow(psInfo->proppage[index].hwndPage);
2415 /* Free page resources */
2416 if(psInfo->proppage[index].hpage)
2418 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2420 if (psp->dwFlags & PSP_USETITLE)
2421 Free ((LPVOID)psInfo->proppage[index].pszText);
2423 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2426 /* Remove the tab */
2427 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2429 oldPages = psInfo->proppage;
2430 psInfo->nPages--;
2431 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2433 if (index > 0)
2434 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2436 if (index < psInfo->nPages)
2437 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2438 (psInfo->nPages - index) * sizeof(PropPageInfo));
2440 Free(oldPages);
2442 return FALSE;
2445 /******************************************************************************
2446 * PROPSHEET_SetWizButtons
2448 * This code will work if (and assumes that) the Next button is on top of the
2449 * Finish button. ie. Finish comes after Next in the Z order.
2450 * This means make sure the dialog template reflects this.
2453 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2455 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2456 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2457 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2458 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2459 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2461 TRACE("%d\n", dwFlags);
2463 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2464 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2465 EnableWindow(hwndFinish, enable_finish);
2467 /* set the default pushbutton to an enabled button */
2468 if (enable_finish)
2469 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2470 else if (dwFlags & PSWIZB_NEXT)
2471 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2472 else if (dwFlags & PSWIZB_BACK)
2473 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2474 else
2475 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2477 if (!psInfo->hasFinish)
2479 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2481 /* Hide the Next button */
2482 ShowWindow(hwndNext, SW_HIDE);
2484 /* Show the Finish button */
2485 ShowWindow(hwndFinish, SW_SHOW);
2487 else
2489 /* Hide the Finish button */
2490 ShowWindow(hwndFinish, SW_HIDE);
2491 /* Show the Next button */
2492 ShowWindow(hwndNext, SW_SHOW);
2497 /******************************************************************************
2498 * PROPSHEET_SetHeaderTitleW
2500 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2502 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2503 PROPSHEETPAGEW *page;
2505 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2507 if (page_index >= psInfo->nPages)
2508 return;
2510 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2512 if (!IS_INTRESOURCE(page->pszHeaderTitle))
2513 Free((void *)page->pszHeaderTitle);
2515 page->pszHeaderTitle = heap_strdupW(title);
2516 page->dwFlags |= PSP_USEHEADERTITLE;
2519 /******************************************************************************
2520 * PROPSHEET_SetHeaderTitleA
2522 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2524 WCHAR *titleW;
2526 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2528 titleW = heap_strdupAtoW(title);
2529 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2530 Free(titleW);
2533 /******************************************************************************
2534 * PROPSHEET_SetHeaderSubTitleW
2536 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2538 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2539 PROPSHEETPAGEW *page;
2541 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2543 if (page_index >= psInfo->nPages)
2544 return;
2546 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2548 if (!IS_INTRESOURCE(page->pszHeaderSubTitle))
2549 Free((void *)page->pszHeaderSubTitle);
2551 page->pszHeaderSubTitle = heap_strdupW(subtitle);
2552 page->dwFlags |= PSP_USEHEADERSUBTITLE;
2555 /******************************************************************************
2556 * PROPSHEET_SetHeaderSubTitleA
2558 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2560 WCHAR *subtitleW;
2562 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2564 subtitleW = heap_strdupAtoW(subtitle);
2565 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2566 Free(subtitleW);
2569 /******************************************************************************
2570 * PROPSHEET_HwndToIndex
2572 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2574 int index;
2575 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2577 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2579 for (index = 0; index < psInfo->nPages; index++)
2580 if (psInfo->proppage[index].hwndPage == hPageDlg)
2581 return index;
2582 WARN("%p not found\n", hPageDlg);
2583 return -1;
2586 /******************************************************************************
2587 * PROPSHEET_IndexToHwnd
2589 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2591 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2592 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2593 if (!psInfo)
2594 return 0;
2595 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2596 WARN("%d out of range.\n", iPageIndex);
2597 return 0;
2599 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2602 /******************************************************************************
2603 * PROPSHEET_PageToIndex
2605 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2607 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2609 TRACE("(%p, %p)\n", hwndDlg, hPage);
2611 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2614 /******************************************************************************
2615 * PROPSHEET_IndexToPage
2617 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2619 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2620 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2621 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2622 WARN("%d out of range.\n", iPageIndex);
2623 return 0;
2625 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2628 /******************************************************************************
2629 * PROPSHEET_IdToIndex
2631 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2633 int index;
2634 LPCPROPSHEETPAGEW psp;
2635 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2636 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2637 for (index = 0; index < psInfo->nPages; index++) {
2638 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2639 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2640 return index;
2643 return -1;
2646 /******************************************************************************
2647 * PROPSHEET_IndexToId
2649 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2651 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2652 LPCPROPSHEETPAGEW psp;
2653 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2654 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2655 WARN("%d out of range.\n", iPageIndex);
2656 return 0;
2658 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2659 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2660 return 0;
2662 return (LRESULT)psp->u.pszTemplate;
2665 /******************************************************************************
2666 * PROPSHEET_GetResult
2668 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2670 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2671 return psInfo->result;
2674 /******************************************************************************
2675 * PROPSHEET_RecalcPageSizes
2677 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2679 FIXME("(%p): stub\n", hwndDlg);
2680 return FALSE;
2683 /******************************************************************************
2684 * PROPSHEET_GetPageIndex
2686 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2687 * the array of PropPageInfo. If page is not found original index is used
2688 * (page takes precedence over index).
2690 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2692 int index;
2694 TRACE("page %p index %d\n", page, original_index);
2696 for (index = 0; index < psInfo->nPages; index++)
2697 if (psInfo->proppage[index].hpage == page)
2698 return index;
2700 return original_index;
2703 /******************************************************************************
2704 * PROPSHEET_CleanUp
2706 static void PROPSHEET_CleanUp(HWND hwndDlg)
2708 int i;
2709 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2711 TRACE("\n");
2712 if (!psInfo) return;
2713 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2714 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2716 for (i = 0; i < psInfo->nPages; i++)
2718 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2720 /* Unsubclass the page dialog window */
2721 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2722 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2723 (psp->dwFlags & PSP_HIDEHEADER))
2725 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2726 PROPSHEET_WizardSubclassProc, 1);
2729 if(psInfo->proppage[i].hwndPage)
2730 DestroyWindow(psInfo->proppage[i].hwndPage);
2732 if(psp)
2734 if (psp->dwFlags & PSP_USETITLE)
2735 Free ((LPVOID)psInfo->proppage[i].pszText);
2737 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2741 DeleteObject(psInfo->hFont);
2742 DeleteObject(psInfo->hFontBold);
2743 /* If we created the bitmaps, destroy them */
2744 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2745 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2746 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2747 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2748 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2749 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2751 Free(psInfo->proppage);
2752 Free(psInfo->strPropertiesFor);
2753 ImageList_Destroy(psInfo->hImageList);
2755 GlobalFree(psInfo);
2758 static INT do_loop(const PropSheetInfo *psInfo)
2760 MSG msg = { 0 };
2761 INT ret = 0;
2762 HWND hwnd = psInfo->hwnd;
2763 HWND parent = psInfo->ppshheader.hwndParent;
2765 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2767 if(ret == -1)
2768 break;
2770 if(!IsDialogMessageW(hwnd, &msg))
2772 TranslateMessage(&msg);
2773 DispatchMessageW(&msg);
2777 if(ret == 0 && msg.message)
2778 PostQuitMessage(msg.wParam);
2780 if(ret != -1)
2781 ret = psInfo->result;
2783 if(parent)
2784 EnableWindow(parent, TRUE);
2786 DestroyWindow(hwnd);
2787 return ret;
2790 /******************************************************************************
2791 * PROPSHEET_PropertySheet
2793 * Common code between PropertySheetA/W
2795 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2797 INT_PTR bRet = 0;
2798 HWND parent = NULL;
2799 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2800 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2802 psInfo->unicode = unicode;
2803 psInfo->ended = FALSE;
2805 if(!psInfo->isModeless)
2807 parent = psInfo->ppshheader.hwndParent;
2808 if (parent) EnableWindow(parent, FALSE);
2810 bRet = PROPSHEET_CreateDialog(psInfo);
2811 if(!psInfo->isModeless)
2812 bRet = do_loop(psInfo);
2813 return bRet;
2816 /******************************************************************************
2817 * PropertySheet (COMCTL32.@)
2818 * PropertySheetA (COMCTL32.@)
2820 * Creates a property sheet in the specified property sheet header.
2822 * RETURNS
2823 * Modal property sheets: Positive if successful or -1 otherwise.
2824 * Modeless property sheets: Property sheet handle.
2825 * Or:
2826 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2827 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2829 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2831 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2832 UINT i, n;
2833 const BYTE* pByte;
2835 TRACE("(%p)\n", lppsh);
2837 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2839 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2840 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2842 for (n = i = 0; i < lppsh->nPages; i++, n++)
2844 if (!psInfo->usePropPage)
2845 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2846 else
2848 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2849 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2852 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2853 psInfo, n, TRUE))
2855 if (psInfo->usePropPage)
2856 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2857 n--;
2858 psInfo->nPages--;
2862 return PROPSHEET_PropertySheet(psInfo, FALSE);
2865 /******************************************************************************
2866 * PropertySheetW (COMCTL32.@)
2868 * See PropertySheetA.
2870 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2872 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2873 UINT i, n;
2874 const BYTE* pByte;
2876 TRACE("(%p)\n", lppsh);
2878 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2880 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2881 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2883 for (n = i = 0; i < lppsh->nPages; i++, n++)
2885 if (!psInfo->usePropPage)
2886 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2887 else
2889 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2890 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2893 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2894 psInfo, n, TRUE))
2896 if (psInfo->usePropPage)
2897 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2898 n--;
2899 psInfo->nPages--;
2903 return PROPSHEET_PropertySheet(psInfo, TRUE);
2906 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2908 LPWSTR ret;
2910 if (IS_INTRESOURCE(str))
2912 HRSRC hrsrc;
2913 HGLOBAL hmem;
2914 WCHAR *ptr;
2915 WORD i, id = LOWORD(str);
2916 UINT len;
2918 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2919 return NULL;
2920 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2921 if (!(ptr = LockResource( hmem ))) return NULL;
2922 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2923 len = *ptr;
2924 if (!len) return NULL;
2925 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2926 if (ret)
2928 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2929 ret[len] = 0;
2932 else
2934 int len = (lstrlenW(str) + 1) * sizeof(WCHAR);
2935 ret = Alloc( len );
2936 if (ret) memcpy( ret, str, len );
2938 return ret;
2942 /******************************************************************************
2943 * CreatePropertySheetPage (COMCTL32.@)
2944 * CreatePropertySheetPageA (COMCTL32.@)
2946 * Creates a new property sheet page.
2948 * RETURNS
2949 * Success: Handle to new property sheet page.
2950 * Failure: NULL.
2952 * NOTES
2953 * An application must use the PSM_ADDPAGE message to add the new page to
2954 * an existing property sheet.
2956 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2957 LPCPROPSHEETPAGEA lpPropSheetPage)
2959 PROPSHEETPAGEW *ppsp;
2961 if (lpPropSheetPage->dwSize < PROPSHEETPAGEA_V1_SIZE)
2962 return NULL;
2964 /* original data is used for callback notifications */
2965 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
2967 ppsp = Alloc(2 * sizeof(*ppsp));
2968 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2969 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2971 else
2973 ppsp = Alloc(sizeof(*ppsp));
2974 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2977 ppsp->dwFlags &= ~PSP_INTERNAL_UNICODE;
2979 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2981 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2983 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2984 char *template = Alloc( len );
2986 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2990 if (ppsp->dwFlags & PSP_USEICONID)
2992 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2993 ppsp->u2.pszIcon = heap_strdupAtoW( lpPropSheetPage->u2.pszIcon );
2996 if (ppsp->dwFlags & PSP_USETITLE)
2998 if (IS_INTRESOURCE( ppsp->pszTitle ))
2999 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3000 else
3001 ppsp->pszTitle = heap_strdupAtoW( lpPropSheetPage->pszTitle );
3003 else
3004 ppsp->pszTitle = NULL;
3006 if (ppsp->dwFlags & PSP_HIDEHEADER)
3007 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3009 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3011 if (IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3012 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3013 else
3014 ppsp->pszHeaderTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderTitle );
3016 else
3017 ppsp->pszHeaderTitle = NULL;
3019 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3021 if (IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3022 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3023 else
3024 ppsp->pszHeaderSubTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderSubTitle );
3026 else
3027 ppsp->pszHeaderSubTitle = NULL;
3029 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEA_V1_SIZE && ppsp->pfnCallback)
3030 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3032 return (HPROPSHEETPAGE)ppsp;
3035 /******************************************************************************
3036 * CreatePropertySheetPageW (COMCTL32.@)
3038 * See CreatePropertySheetA.
3040 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3042 PROPSHEETPAGEW *ppsp;
3044 if (lpPropSheetPage->dwSize < PROPSHEETPAGEW_V1_SIZE)
3045 return NULL;
3047 /* original data is used for callback notifications */
3048 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
3050 ppsp = Alloc(2 * sizeof(*ppsp));
3051 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3052 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3054 else
3056 ppsp = Alloc(sizeof(*ppsp));
3057 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3060 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3062 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3064 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3065 ppsp->u.pszTemplate = heap_strdupW( lpPropSheetPage->u.pszTemplate );
3068 if ( ppsp->dwFlags & PSP_USEICONID )
3070 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3071 ppsp->u2.pszIcon = heap_strdupW( lpPropSheetPage->u2.pszIcon );
3074 if (ppsp->dwFlags & PSP_USETITLE)
3075 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3076 else
3077 ppsp->pszTitle = NULL;
3079 if (ppsp->dwFlags & PSP_HIDEHEADER)
3080 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3082 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3083 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3084 else
3085 ppsp->pszHeaderTitle = NULL;
3087 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3088 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3089 else
3090 ppsp->pszHeaderSubTitle = NULL;
3092 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEW_V1_SIZE && ppsp->pfnCallback)
3093 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3095 return (HPROPSHEETPAGE)ppsp;
3098 /******************************************************************************
3099 * DestroyPropertySheetPage (COMCTL32.@)
3101 * Destroys a property sheet page previously created with
3102 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3103 * memory.
3105 * RETURNS
3106 * Success: TRUE
3107 * Failure: FALSE
3109 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3111 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3113 if (!psp)
3114 return FALSE;
3116 if ((psp->dwFlags & PSP_USECALLBACK) && psp->pfnCallback)
3117 psp->pfnCallback(0, PSPCB_RELEASE, psp + 1);
3119 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3120 Free ((LPVOID)psp->u.pszTemplate);
3122 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3123 Free ((LPVOID)psp->u2.pszIcon);
3125 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3126 Free ((LPVOID)psp->pszTitle);
3128 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3129 Free ((LPVOID)psp->pszHeaderTitle);
3131 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3132 Free ((LPVOID)psp->pszHeaderSubTitle);
3134 Free(hPropPage);
3136 return TRUE;
3139 /******************************************************************************
3140 * PROPSHEET_IsDialogMessage
3142 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3144 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3146 TRACE("\n");
3147 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3148 return FALSE;
3150 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3152 int new_page = 0;
3153 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3155 if (!(dlgCode & DLGC_WANTMESSAGE))
3157 switch (lpMsg->wParam)
3159 case VK_TAB:
3160 if (GetKeyState(VK_SHIFT) & 0x8000)
3161 new_page = -1;
3162 else
3163 new_page = 1;
3164 break;
3166 case VK_NEXT: new_page = 1; break;
3167 case VK_PRIOR: new_page = -1; break;
3171 if (new_page)
3173 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3175 new_page += psInfo->active_page;
3177 if (new_page < 0)
3178 new_page = psInfo->nPages - 1;
3179 else if (new_page >= psInfo->nPages)
3180 new_page = 0;
3182 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3185 return TRUE;
3189 return IsDialogMessageW(hwnd, lpMsg);
3192 /******************************************************************************
3193 * PROPSHEET_DoCommand
3195 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3198 switch (wID) {
3200 case IDOK:
3201 case IDC_APPLY_BUTTON:
3203 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3205 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3206 break;
3208 if (wID == IDOK)
3210 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3212 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3213 if (psInfo->result == 0)
3214 psInfo->result = IDOK;
3216 if (psInfo->isModeless)
3217 psInfo->activeValid = FALSE;
3218 else
3219 psInfo->ended = TRUE;
3221 else
3222 EnableWindow(hwndApplyBtn, FALSE);
3224 break;
3227 case IDC_BACK_BUTTON:
3228 PROPSHEET_Back(hwnd);
3229 break;
3231 case IDC_NEXT_BUTTON:
3232 PROPSHEET_Next(hwnd);
3233 break;
3235 case IDC_FINISH_BUTTON:
3236 PROPSHEET_Finish(hwnd);
3237 break;
3239 case IDCANCEL:
3240 PROPSHEET_Cancel(hwnd, 0);
3241 break;
3243 case IDHELP:
3244 PROPSHEET_Help(hwnd);
3245 break;
3247 default:
3248 return FALSE;
3251 return TRUE;
3254 /******************************************************************************
3255 * PROPSHEET_Paint
3257 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3259 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3260 PAINTSTRUCT ps;
3261 HDC hdc, hdcSrc;
3262 BITMAP bm;
3263 HBITMAP hbmp;
3264 HPALETTE hOldPal = 0;
3265 int offsety = 0;
3266 HBRUSH hbr;
3267 RECT r, rzone;
3268 LPCPROPSHEETPAGEW ppshpage;
3269 WCHAR szBuffer[256];
3270 int nLength;
3272 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3273 if (!hdc) return 1;
3275 hdcSrc = CreateCompatibleDC(0);
3277 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3278 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3280 if (psInfo->active_page < 0)
3281 ppshpage = NULL;
3282 else
3283 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3285 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3286 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3287 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3289 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3290 HFONT hOldFont;
3291 COLORREF clrOld = 0;
3292 int oldBkMode = 0;
3294 GetClientRect(hwndLineHeader, &r);
3295 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3296 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3298 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3300 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3302 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3304 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3305 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3307 /* Fill the unoccupied part of the header with color of the
3308 * left-top pixel, but do it only when needed.
3310 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3312 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3313 r = rzone;
3314 if (bm.bmWidth < r.right)
3316 r.left = bm.bmWidth;
3317 FillRect(hdc, &r, hbr);
3319 if (bm.bmHeight < r.bottom)
3321 r.left = 0;
3322 r.top = bm.bmHeight;
3323 FillRect(hdc, &r, hbr);
3325 DeleteObject(hbr);
3328 /* Draw the header itself. */
3329 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3330 hdcSrc, 0, 0, SRCCOPY);
3332 else
3334 int margin;
3335 hbr = GetSysColorBrush(COLOR_WINDOW);
3336 FillRect(hdc, &rzone, hbr);
3338 /* Draw the header bitmap. It's always centered like a
3339 * common 49 x 49 bitmap. */
3340 margin = (rzone.bottom - 49) / 2;
3341 BitBlt(hdc, rzone.right - 49 - margin, margin,
3342 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3343 hdcSrc, 0, 0, SRCCOPY);
3345 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3346 * if its height is smaller than 49 pixels. Because the reason
3347 * for this bug is unknown the current code doesn't try to
3348 * replicate it. */
3351 SelectObject(hdcSrc, hbmp);
3354 clrOld = SetTextColor (hdc, 0x00000000);
3355 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3357 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3358 SetRect(&r, 20, 10, 0, 0);
3359 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3360 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3361 else
3363 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3364 szBuffer, 256);
3365 if (nLength != 0)
3367 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3372 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3373 SelectObject(hdc, psInfo->hFont);
3374 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3375 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3376 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3377 else
3379 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3380 szBuffer, 256);
3381 if (nLength != 0)
3383 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3388 offsety = rzone.bottom + 2;
3390 SetTextColor(hdc, clrOld);
3391 SetBkMode(hdc, oldBkMode);
3392 SelectObject(hdc, hOldFont);
3395 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3396 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3397 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3399 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3401 GetClientRect(hwndLine, &r);
3402 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3403 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3405 hbr = GetSysColorBrush(COLOR_WINDOW);
3406 FillRect(hdc, &rzone, hbr);
3408 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3409 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3411 /* The watermark is truncated to a width of 164 pixels */
3412 r.right = min(r.right, 164);
3413 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3414 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3416 /* If the bitmap is not big enough, fill the remaining area
3417 with the color of pixel (0,0) of bitmap - see MSDN */
3418 if (r.top > bm.bmHeight) {
3419 r.bottom = r.top - 1;
3420 r.top = bm.bmHeight;
3421 r.left = 0;
3422 r.right = bm.bmWidth;
3423 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3424 FillRect(hdc, &r, hbr);
3425 DeleteObject(hbr);
3428 SelectObject(hdcSrc, hbmp);
3431 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3432 SelectPalette(hdc, hOldPal, FALSE);
3434 DeleteDC(hdcSrc);
3436 if (!hdcParam) EndPaint(hwnd, &ps);
3438 return 0;
3441 /******************************************************************************
3442 * PROPSHEET_DialogProc
3444 static INT_PTR CALLBACK
3445 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3447 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3448 hwnd, uMsg, wParam, lParam);
3450 switch (uMsg)
3452 case WM_INITDIALOG:
3454 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3455 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3456 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3457 int idx;
3458 LOGFONTW logFont;
3460 /* Using PropSheetInfoStr to store extra data doesn't match the native
3461 * common control: native uses TCM_[GS]ETITEM
3463 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3466 * psInfo->hwnd is not being used by WINE code - it exists
3467 * for compatibility with "real" Windoze. The same about
3468 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3469 * property.
3471 psInfo->hwnd = hwnd;
3472 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3474 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3476 /* set up the Next and Back buttons by default */
3477 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3480 /* Set up fonts */
3481 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3482 psInfo->hFont = CreateFontIndirectW (&logFont);
3483 logFont.lfWeight = FW_BOLD;
3484 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3487 * Small icon in the title bar.
3489 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3490 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3492 HICON hIcon;
3493 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3494 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3496 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3497 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3498 psInfo->ppshheader.u.pszIcon,
3499 IMAGE_ICON,
3500 icon_cx, icon_cy,
3501 LR_DEFAULTCOLOR);
3502 else
3503 hIcon = psInfo->ppshheader.u.hIcon;
3505 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3508 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3509 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3511 psInfo->strPropertiesFor = strCaption;
3513 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3515 PROPSHEET_CreateTabControl(hwnd, psInfo);
3517 PROPSHEET_LoadWizardBitmaps(psInfo);
3519 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3521 ShowWindow(hwndTabCtrl, SW_HIDE);
3522 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3523 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3524 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3526 else
3528 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3530 PROPSHEET_AdjustSize(hwnd, psInfo);
3531 PROPSHEET_AdjustButtons(hwnd, psInfo);
3533 SetFocus(GetDlgItem(hwnd, IDOK));
3536 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3537 psInfo->ppshheader.hInstance)
3539 WCHAR szText[256];
3541 if (LoadStringW(psInfo->ppshheader.hInstance,
3542 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3543 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3545 else
3547 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3548 psInfo->ppshheader.pszCaption);
3552 if (psInfo->useCallback)
3553 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3555 idx = psInfo->active_page;
3556 psInfo->active_page = -1;
3558 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3560 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3561 * as some programs call TCM_GETCURSEL to get the current selection
3562 * from which to switch to the next page */
3563 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3565 PROPSHEET_UnChanged(hwnd, NULL);
3567 /* wizards set their focus during init */
3568 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3569 return FALSE;
3571 return TRUE;
3574 case WM_PRINTCLIENT:
3575 case WM_PAINT:
3576 PROPSHEET_Paint(hwnd, (HDC)wParam);
3577 return TRUE;
3579 case WM_DESTROY:
3580 PROPSHEET_CleanUp(hwnd);
3581 return TRUE;
3583 case WM_CLOSE:
3584 PROPSHEET_Cancel(hwnd, 1);
3585 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3587 case WM_COMMAND:
3588 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3590 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3592 if (!psInfo)
3593 return FALSE;
3595 /* No default handler, forward notification to active page */
3596 if (psInfo->activeValid && psInfo->active_page != -1)
3598 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3599 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3602 return TRUE;
3604 case WM_NOTIFY:
3606 NMHDR* pnmh = (LPNMHDR) lParam;
3608 if (pnmh->code == TCN_SELCHANGE)
3610 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3611 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3614 if(pnmh->code == TCN_SELCHANGING)
3616 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3617 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3618 return TRUE;
3621 return FALSE;
3624 case WM_SYSCOLORCHANGE:
3625 COMCTL32_RefreshSysColors();
3626 return FALSE;
3628 case PSM_GETCURRENTPAGEHWND:
3630 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3631 HWND hwndPage = 0;
3633 if (!psInfo)
3634 return FALSE;
3636 if (psInfo->activeValid && psInfo->active_page != -1)
3637 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3641 return TRUE;
3644 case PSM_CHANGED:
3645 PROPSHEET_Changed(hwnd, (HWND)wParam);
3646 return TRUE;
3648 case PSM_UNCHANGED:
3649 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3650 return TRUE;
3652 case PSM_GETTABCONTROL:
3654 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3656 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3658 return TRUE;
3661 case PSM_SETCURSEL:
3663 BOOL msgResult;
3665 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3666 if(msgResult != FALSE)
3668 msgResult = PROPSHEET_SetCurSel(hwnd,
3669 (int)wParam,
3671 (HPROPSHEETPAGE)lParam);
3674 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3676 return TRUE;
3679 case PSM_CANCELTOCLOSE:
3681 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3682 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3683 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3685 EnableWindow(hwndCancel, FALSE);
3686 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, ARRAY_SIZE(buf)))
3687 SetWindowTextW(hwndOK, buf);
3689 return FALSE;
3692 case PSM_RESTARTWINDOWS:
3694 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3696 if (!psInfo)
3697 return FALSE;
3699 /* reboot system takes precedence over restart windows */
3700 if (psInfo->result != ID_PSREBOOTSYSTEM)
3701 psInfo->result = ID_PSRESTARTWINDOWS;
3703 return TRUE;
3706 case PSM_REBOOTSYSTEM:
3708 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3710 if (!psInfo)
3711 return FALSE;
3713 psInfo->result = ID_PSREBOOTSYSTEM;
3715 return TRUE;
3718 case PSM_SETTITLEA:
3719 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3720 return TRUE;
3722 case PSM_SETTITLEW:
3723 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3724 return TRUE;
3726 case PSM_APPLY:
3728 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3730 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3732 return TRUE;
3735 case PSM_QUERYSIBLINGS:
3737 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3739 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3741 return TRUE;
3744 case PSM_ADDPAGE:
3747 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3748 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3749 * on success or FALSE otherwise, as specified on MSDN Online.
3750 * Also see the MFC code for
3751 * CPropertySheet::AddPage(CPropertyPage* pPage).
3754 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3756 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3758 return TRUE;
3761 case PSM_REMOVEPAGE:
3762 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3763 return TRUE;
3765 case PSM_ISDIALOGMESSAGE:
3767 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3768 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3769 return TRUE;
3772 case PSM_PRESSBUTTON:
3773 PROPSHEET_PressButton(hwnd, (int)wParam);
3774 return TRUE;
3776 case PSM_SETFINISHTEXTA:
3777 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3778 return TRUE;
3780 case PSM_SETWIZBUTTONS:
3781 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3782 return TRUE;
3784 case PSM_SETCURSELID:
3785 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3786 return TRUE;
3788 case PSM_SETFINISHTEXTW:
3789 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3790 return FALSE;
3792 case PSM_INSERTPAGE:
3794 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3795 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3796 return TRUE;
3799 case PSM_SETHEADERTITLEW:
3800 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3801 return TRUE;
3803 case PSM_SETHEADERTITLEA:
3804 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3805 return TRUE;
3807 case PSM_SETHEADERSUBTITLEW:
3808 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3809 return TRUE;
3811 case PSM_SETHEADERSUBTITLEA:
3812 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3813 return TRUE;
3815 case PSM_HWNDTOINDEX:
3817 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3818 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3819 return TRUE;
3822 case PSM_INDEXTOHWND:
3824 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3825 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3826 return TRUE;
3829 case PSM_PAGETOINDEX:
3831 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3832 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3833 return TRUE;
3836 case PSM_INDEXTOPAGE:
3838 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3839 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3840 return TRUE;
3843 case PSM_IDTOINDEX:
3845 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3846 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3847 return TRUE;
3850 case PSM_INDEXTOID:
3852 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3853 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3854 return TRUE;
3857 case PSM_GETRESULT:
3859 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3860 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3861 return TRUE;
3864 case PSM_RECALCPAGESIZES:
3866 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3867 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3868 return TRUE;
3871 default:
3872 return FALSE;