po: Update Lithuanian translation.
[wine.git] / dlls / comctl32 / propsheet.c
blob05ab4aa48d8ac7d624a94a67afac60920a8e6e2d
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[] =
143 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
145 #define PSP_INTERNAL_UNICODE 0x80000000
147 #define MAX_CAPTION_LENGTH 255
148 #define MAX_TABTEXT_LENGTH 255
149 #define MAX_BUTTONTEXT_LENGTH 64
151 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
153 /* Wizard metrics specified in DLUs */
154 #define WIZARD_PADDING 7
155 #define WIZARD_HEADER_HEIGHT 36
157 /******************************************************************************
158 * Prototypes
160 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
161 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
162 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
163 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
164 int index,
165 int skipdir,
166 HPROPSHEETPAGE hpage);
167 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo, int original_index);
168 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
169 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
170 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
172 static INT_PTR CALLBACK
173 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
175 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
177 static WCHAR *heap_strdupW(const WCHAR *str)
179 int len = lstrlenW(str) + 1;
180 WCHAR *ret = Alloc(len * sizeof(WCHAR));
181 lstrcpyW(ret, str);
182 return ret;
185 static WCHAR *heap_strdupAtoW(const char *str)
187 WCHAR *ret;
188 INT len;
190 len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
191 ret = Alloc(len * sizeof(WCHAR));
192 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
194 return ret;
197 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
198 /******************************************************************************
199 * PROPSHEET_UnImplementedFlags
201 * Document use of flags we don't implement yet.
203 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
205 CHAR string[256];
207 string[0] = '\0';
210 * unhandled header flags:
211 * PSH_RTLREADING 0x00000800
212 * PSH_STRETCHWATERMARK 0x00040000
213 * PSH_USEPAGELANG 0x00200000
216 add_flag(PSH_RTLREADING);
217 add_flag(PSH_STRETCHWATERMARK);
218 add_flag(PSH_USEPAGELANG);
219 if (string[0] != '\0')
220 FIXME("%s\n", string);
222 #undef add_flag
224 /******************************************************************************
225 * PROPSHEET_GetPageRect
227 * Retrieve rect from tab control and map into the dialog for SetWindowPos
229 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
230 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
232 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
233 HWND hwndChild;
234 RECT r;
236 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
237 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
238 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
239 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
241 rc->left = rc->top = WIZARD_PADDING;
243 else
245 rc->left = rc->top = 0;
247 rc->right = psInfo->width - rc->left;
248 rc->bottom = psInfo->height - rc->top;
249 MapDialogRect(hwndDlg, rc);
251 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
252 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
253 !(ppshpage->dwFlags & PSP_HIDEHEADER))
255 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
256 GetClientRect(hwndChild, &r);
257 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
258 rc->top += r.bottom + 1;
260 } else {
261 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
262 GetClientRect(hwndTabCtrl, rc);
263 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
264 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
268 /******************************************************************************
269 * PROPSHEET_FindPageByResId
271 * Find page index corresponding to page resource id.
273 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
275 INT i;
277 for (i = 0; i < psInfo->nPages; i++)
279 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
281 /* Fixme: if resource ID is a string shall we use strcmp ??? */
282 if (lppsp->u.pszTemplate == (LPVOID)resId)
283 break;
286 return i;
289 /******************************************************************************
290 * PROPSHEET_CollectSheetInfoCommon
292 * Common code for PROPSHEET_CollectSheetInfoA/W
294 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
296 PROPSHEET_UnImplementedFlags(dwFlags);
298 psInfo->hasHelp = dwFlags & PSH_HASHELP;
299 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
300 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
302 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
303 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
304 psInfo->active_page = 0;
306 psInfo->result = 0;
307 psInfo->hImageList = 0;
308 psInfo->activeValid = FALSE;
311 /******************************************************************************
312 * PROPSHEET_CollectSheetInfoA
314 * Collect relevant data.
316 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
317 PropSheetInfo * psInfo)
319 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
320 DWORD dwFlags = lppsh->dwFlags;
322 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
324 memcpy(&psInfo->ppshheader,lppsh,dwSize);
325 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",
326 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
327 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
329 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
330 psInfo->ppshheader.pszCaption = NULL;
331 else
333 if (!IS_INTRESOURCE(lppsh->pszCaption))
335 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
336 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
338 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
339 psInfo->ppshheader.pszCaption = caption;
342 psInfo->nPages = lppsh->nPages;
344 if (dwFlags & PSH_USEPSTARTPAGE)
346 TRACE("PSH_USEPSTARTPAGE is on\n");
347 psInfo->active_page = 0;
349 else
350 psInfo->active_page = lppsh->u2.nStartPage;
352 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
355 /******************************************************************************
356 * PROPSHEET_CollectSheetInfoW
358 * Collect relevant data.
360 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
361 PropSheetInfo * psInfo)
363 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
364 DWORD dwFlags = lppsh->dwFlags;
366 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
368 memcpy(&psInfo->ppshheader,lppsh,dwSize);
369 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",
370 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
372 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
373 psInfo->ppshheader.pszCaption = NULL;
374 else
376 if (!IS_INTRESOURCE(lppsh->pszCaption))
377 psInfo->ppshheader.pszCaption = heap_strdupW( lppsh->pszCaption );
379 psInfo->nPages = lppsh->nPages;
381 if (dwFlags & PSH_USEPSTARTPAGE)
383 TRACE("PSH_USEPSTARTPAGE is on\n");
384 psInfo->active_page = 0;
386 else
387 psInfo->active_page = lppsh->u2.nStartPage;
389 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
392 /******************************************************************************
393 * PROPSHEET_CollectPageInfo
395 * Collect property sheet data.
396 * With code taken from DIALOG_ParseTemplate32.
398 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
399 PropSheetInfo * psInfo,
400 int index, BOOL resize)
402 const DLGTEMPLATE* pTemplate;
403 const WORD* p;
404 DWORD dwFlags;
405 int width, height;
407 if (!lppsp)
408 return FALSE;
410 TRACE("\n");
411 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
412 psInfo->proppage[index].hwndPage = 0;
413 psInfo->proppage[index].isDirty = FALSE;
416 * Process property page flags.
418 dwFlags = lppsp->dwFlags;
419 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
420 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
421 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
423 /* as soon as we have a page with the help flag, set the sheet flag on */
424 if (psInfo->proppage[index].hasHelp)
425 psInfo->hasHelp = TRUE;
428 * Process page template.
430 if (dwFlags & PSP_DLGINDIRECT)
431 pTemplate = lppsp->u.pResource;
432 else if(dwFlags & PSP_INTERNAL_UNICODE )
434 HRSRC hResource = FindResourceW(lppsp->hInstance,
435 lppsp->u.pszTemplate,
436 (LPWSTR)RT_DIALOG);
437 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
438 hResource);
439 pTemplate = LockResource(hTemplate);
441 else
443 HRSRC hResource = FindResourceA(lppsp->hInstance,
444 (LPCSTR)lppsp->u.pszTemplate,
445 (LPSTR)RT_DIALOG);
446 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
447 hResource);
448 pTemplate = LockResource(hTemplate);
452 * Extract the size of the page and the caption.
454 if (!pTemplate)
455 return FALSE;
457 p = (const WORD *)pTemplate;
459 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
461 /* DLGTEMPLATEEX (not defined in any std. header file) */
463 p++; /* dlgVer */
464 p++; /* signature */
465 p += 2; /* help ID */
466 p += 2; /* ext style */
467 p += 2; /* style */
469 else
471 /* DLGTEMPLATE */
473 p += 2; /* style */
474 p += 2; /* ext style */
477 p++; /* nb items */
478 p++; /* x */
479 p++; /* y */
480 width = (WORD)*p; p++;
481 height = (WORD)*p; p++;
483 if (lppsp->dwFlags & (PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE))
484 psInfo->ppshheader.dwFlags |= PSH_HEADER;
486 /* Special calculation for interior wizard pages so the largest page is
487 * calculated correctly. We need to add all the padding and space occupied
488 * by the header so the width and height sums up to the whole wizard client
489 * area. */
490 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
491 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
492 !(dwFlags & PSP_HIDEHEADER))
494 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
495 width += 2 * WIZARD_PADDING;
497 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
499 height += 2 * WIZARD_PADDING;
500 width += 2 * WIZARD_PADDING;
503 /* remember the largest width and height */
504 if (resize)
506 if (width > psInfo->width)
507 psInfo->width = width;
509 if (height > psInfo->height)
510 psInfo->height = height;
513 /* menu */
514 switch ((WORD)*p)
516 case 0x0000:
517 p++;
518 break;
519 case 0xffff:
520 p += 2;
521 break;
522 default:
523 p += lstrlenW( p ) + 1;
524 break;
527 /* class */
528 switch ((WORD)*p)
530 case 0x0000:
531 p++;
532 break;
533 case 0xffff:
534 p += 2;
535 break;
536 default:
537 p += lstrlenW( p ) + 1;
538 break;
541 /* Extract the caption */
542 psInfo->proppage[index].pszText = p;
543 TRACE("Tab %d %s\n",index,debugstr_w( p ));
545 if (dwFlags & PSP_USETITLE)
547 WCHAR szTitle[256];
548 const WCHAR *pTitle;
549 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
551 if (IS_INTRESOURCE( lppsp->pszTitle ))
553 if (LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle, szTitle, ARRAY_SIZE(szTitle)))
554 pTitle = szTitle;
555 else if (*p)
556 pTitle = p;
557 else
558 pTitle = pszNull;
560 else
561 pTitle = lppsp->pszTitle;
563 psInfo->proppage[index].pszText = heap_strdupW( pTitle );
567 * Build the image list for icons
569 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
571 HICON hIcon;
572 int icon_cx = GetSystemMetrics(SM_CXSMICON);
573 int icon_cy = GetSystemMetrics(SM_CYSMICON);
575 if (dwFlags & PSP_USEICONID)
576 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
577 icon_cx, icon_cy, LR_DEFAULTCOLOR);
578 else
579 hIcon = lppsp->u2.hIcon;
581 if ( hIcon )
583 if (psInfo->hImageList == 0 )
584 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
586 ImageList_AddIcon(psInfo->hImageList, hIcon);
591 return TRUE;
594 /******************************************************************************
595 * PROPSHEET_CreateDialog
597 * Creates the actual property sheet.
599 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
601 LRESULT ret;
602 LPCVOID template;
603 LPVOID temp = 0;
604 HRSRC hRes;
605 DWORD resSize;
606 WORD resID = IDD_PROPSHEET;
608 TRACE("(%p)\n", psInfo);
609 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
610 resID = IDD_WIZARD;
612 if( psInfo->unicode )
614 if(!(hRes = FindResourceW(COMCTL32_hModule,
615 MAKEINTRESOURCEW(resID),
616 (LPWSTR)RT_DIALOG)))
617 return -1;
619 else
621 if(!(hRes = FindResourceA(COMCTL32_hModule,
622 MAKEINTRESOURCEA(resID),
623 (LPSTR)RT_DIALOG)))
624 return -1;
627 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
628 return -1;
631 * Make a copy of the dialog template.
633 resSize = SizeofResource(COMCTL32_hModule, hRes);
635 temp = Alloc(2 * resSize);
637 if (!temp)
638 return -1;
640 memcpy(temp, template, resSize);
642 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
644 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
645 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
646 else
647 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
649 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
650 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
654 else
655 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
658 if (psInfo->useCallback)
659 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
661 /* NOTE: MSDN states "Returns a positive value if successful, or -1
662 * otherwise for modal property sheets.", but this is wrong. The
663 * actual return value is either TRUE (success), FALSE (cancel) or
664 * -1 (error). */
665 if( psInfo->unicode )
667 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
668 temp, psInfo->ppshheader.hwndParent,
669 PROPSHEET_DialogProc, (LPARAM)psInfo);
670 if ( !ret ) ret = -1;
672 else
674 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
675 temp, psInfo->ppshheader.hwndParent,
676 PROPSHEET_DialogProc, (LPARAM)psInfo);
677 if ( !ret ) ret = -1;
680 Free(temp);
682 return ret;
685 /******************************************************************************
686 * PROPSHEET_SizeMismatch
688 * Verify that the tab control and the "largest" property sheet page dlg. template
689 * match in size.
691 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
693 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
694 RECT rcOrigTab, rcPage;
697 * Original tab size.
699 GetClientRect(hwndTabCtrl, &rcOrigTab);
700 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
703 * Biggest page size.
705 SetRect(&rcPage, 0, 0, psInfo->width, psInfo->height);
706 MapDialogRect(hwndDlg, &rcPage);
707 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
709 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
710 return TRUE;
711 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
712 return TRUE;
714 return FALSE;
717 /******************************************************************************
718 * PROPSHEET_AdjustSize
720 * Resizes the property sheet and the tab control to fit the largest page.
722 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
724 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
725 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
726 RECT rc,tabRect;
727 int buttonHeight;
728 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
729 RECT units;
730 LONG style;
732 /* Get the height of buttons */
733 GetClientRect(hwndButton, &rc);
734 buttonHeight = rc.bottom;
737 * Biggest page size.
739 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
740 MapDialogRect(hwndDlg, &rc);
742 /* retrieve the dialog units */
743 units.left = units.right = 4;
744 units.top = units.bottom = 8;
745 MapDialogRect(hwndDlg, &units);
748 * Resize the tab control.
750 GetClientRect(hwndTabCtrl,&tabRect);
752 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
754 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
756 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
757 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
760 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
762 rc.right = rc.left + tabRect.right - tabRect.left;
763 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
766 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
768 rc.right -= rc.left;
769 rc.bottom -= rc.top;
770 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
771 hwndTabCtrl, rc.right, rc.bottom);
772 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
773 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
775 GetClientRect(hwndTabCtrl, &rc);
777 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
779 rc.right += (padding.x * 2);
780 rc.bottom += buttonHeight + (3 * padding.y);
782 style = GetWindowLongW(hwndDlg, GWL_STYLE);
783 if (!(style & WS_CHILD))
784 AdjustWindowRect(&rc, style, FALSE);
786 rc.right -= rc.left;
787 rc.bottom -= rc.top;
790 * Resize the property sheet.
792 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
793 hwndDlg, rc.right, rc.bottom);
794 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
795 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
796 return TRUE;
799 /******************************************************************************
800 * PROPSHEET_AdjustSizeWizard
802 * Resizes the property sheet to fit the largest page.
804 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
806 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
807 RECT rc, lineRect, dialogRect;
809 /* Biggest page size */
810 SetRect(&rc, 0, 0, psInfo->width, psInfo->height);
811 MapDialogRect(hwndDlg, &rc);
813 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
815 /* Add space for the buttons row */
816 GetWindowRect(hwndLine, &lineRect);
817 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
818 GetClientRect(hwndDlg, &dialogRect);
819 rc.bottom += dialogRect.bottom - lineRect.top - 1;
821 /* Convert the client coordinates to window coordinates */
822 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
824 /* Resize the property sheet */
825 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
826 hwndDlg, rc.right, rc.bottom);
827 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
828 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
830 return TRUE;
833 /******************************************************************************
834 * PROPSHEET_AdjustButtons
836 * Adjusts the buttons' positions.
838 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
840 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
841 RECT rcSheet;
842 int x, y;
843 int num_buttons = 2;
844 int buttonWidth, buttonHeight;
845 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
847 if (psInfo->hasApply)
848 num_buttons++;
850 if (psInfo->hasHelp)
851 num_buttons++;
854 * Obtain the size of the buttons.
856 GetClientRect(hwndButton, &rcSheet);
857 buttonWidth = rcSheet.right;
858 buttonHeight = rcSheet.bottom;
861 * Get the size of the property sheet.
863 GetClientRect(hwndParent, &rcSheet);
866 * All buttons will be at this y coordinate.
868 y = rcSheet.bottom - (padding.y + buttonHeight);
871 * Position OK button and make it default.
873 hwndButton = GetDlgItem(hwndParent, IDOK);
875 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
877 SetWindowPos(hwndButton, 0, x, y, 0, 0,
878 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
880 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
884 * Position Cancel button.
886 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
888 x += padding.x + buttonWidth;
890 SetWindowPos(hwndButton, 0, x, y, 0, 0,
891 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
894 * Position Apply button.
896 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
898 if(psInfo->hasApply)
899 x += padding.x + buttonWidth;
900 else
901 ShowWindow(hwndButton, SW_HIDE);
903 SetWindowPos(hwndButton, 0, x, y, 0, 0,
904 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
905 EnableWindow(hwndButton, FALSE);
908 * Position Help button.
910 hwndButton = GetDlgItem(hwndParent, IDHELP);
912 x += padding.x + buttonWidth;
913 SetWindowPos(hwndButton, 0, x, y, 0, 0,
914 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
916 if(!psInfo->hasHelp)
917 ShowWindow(hwndButton, SW_HIDE);
919 return TRUE;
922 /******************************************************************************
923 * PROPSHEET_AdjustButtonsWizard
925 * Adjusts the buttons' positions.
927 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
928 const PropSheetInfo* psInfo)
930 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
931 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
932 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
933 RECT rcSheet;
934 int x, y;
935 int num_buttons = 3;
936 int buttonWidth, buttonHeight, lineHeight, lineWidth;
937 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
939 if (psInfo->hasHelp)
940 num_buttons++;
941 if (psInfo->hasFinish)
942 num_buttons++;
945 * Obtain the size of the buttons.
947 GetClientRect(hwndButton, &rcSheet);
948 buttonWidth = rcSheet.right;
949 buttonHeight = rcSheet.bottom;
951 GetClientRect(hwndLine, &rcSheet);
952 lineHeight = rcSheet.bottom;
955 * Get the size of the property sheet.
957 GetClientRect(hwndParent, &rcSheet);
960 * All buttons will be at this y coordinate.
962 y = rcSheet.bottom - (padding.y + buttonHeight);
965 * Position the Back button.
967 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
969 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
971 SetWindowPos(hwndButton, 0, x, y, 0, 0,
972 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
975 * Position the Next button.
977 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
979 x += buttonWidth;
981 SetWindowPos(hwndButton, 0, x, y, 0, 0,
982 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
985 * Position the Finish button.
987 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
989 if (psInfo->hasFinish)
990 x += padding.x + buttonWidth;
992 SetWindowPos(hwndButton, 0, x, y, 0, 0,
993 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
995 if (!psInfo->hasFinish)
996 ShowWindow(hwndButton, SW_HIDE);
999 * Position the Cancel button.
1001 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1003 x += padding.x + buttonWidth;
1005 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1006 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1009 * Position Help button.
1011 hwndButton = GetDlgItem(hwndParent, IDHELP);
1013 if (psInfo->hasHelp)
1015 x += padding.x + buttonWidth;
1017 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1018 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1020 else
1021 ShowWindow(hwndButton, SW_HIDE);
1023 if (psInfo->ppshheader.dwFlags &
1024 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1025 padding.x = 0;
1028 * Position and resize the sunken line.
1030 x = padding.x;
1031 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1033 lineWidth = rcSheet.right - (padding.x * 2);
1034 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1035 SWP_NOZORDER | SWP_NOACTIVATE);
1038 * Position and resize the header sunken line.
1041 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1042 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1043 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1044 ShowWindow(hwndLineHeader, SW_HIDE);
1046 return TRUE;
1049 /******************************************************************************
1050 * PROPSHEET_GetPaddingInfo
1052 * Returns the layout information.
1054 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1056 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1057 RECT rcTab;
1058 PADDING_INFO padding;
1060 GetWindowRect(hwndTab, &rcTab);
1061 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1063 padding.x = rcTab.left;
1064 padding.y = rcTab.top;
1066 return padding;
1069 /******************************************************************************
1070 * PROPSHEET_GetPaddingInfoWizard
1072 * Returns the layout information.
1073 * Vertical spacing is the distance between the line and the buttons.
1074 * Do NOT use the Help button to gather padding information when it isn't mapped
1075 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1076 * for it in this case !
1077 * FIXME: I'm not sure about any other coordinate problems with these evil
1078 * buttons. Fix it in case additional problems appear or maybe calculate
1079 * a padding in a completely different way, as this is somewhat messy.
1081 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1082 psInfo)
1084 PADDING_INFO padding;
1085 RECT rc;
1086 HWND hwndControl;
1087 INT idButton;
1088 POINT ptButton, ptLine;
1090 TRACE("\n");
1091 if (psInfo->hasHelp)
1093 idButton = IDHELP;
1095 else
1097 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1099 idButton = IDC_NEXT_BUTTON;
1101 else
1103 /* hopefully this is ok */
1104 idButton = IDCANCEL;
1108 hwndControl = GetDlgItem(hwndDlg, idButton);
1109 GetWindowRect(hwndControl, &rc);
1110 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1111 ptButton.x = rc.left;
1112 ptButton.y = rc.top;
1114 /* Line */
1115 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1116 GetWindowRect(hwndControl, &rc);
1117 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1118 ptLine.x = rc.left;
1119 ptLine.y = rc.bottom;
1121 padding.y = ptButton.y - ptLine.y;
1123 if (padding.y < 0)
1124 ERR("padding negative ! Please report this !\n");
1126 /* this is most probably not correct, but the best we have now */
1127 padding.x = padding.y;
1128 return padding;
1131 /******************************************************************************
1132 * PROPSHEET_CreateTabControl
1134 * Insert the tabs in the tab control.
1136 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1137 const PropSheetInfo * psInfo)
1139 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1140 TCITEMW item;
1141 int i, nTabs;
1142 int iImage = 0;
1144 TRACE("\n");
1145 item.mask = TCIF_TEXT;
1146 item.cchTextMax = MAX_TABTEXT_LENGTH;
1148 nTabs = psInfo->nPages;
1151 * Set the image list for icons.
1153 if (psInfo->hImageList)
1155 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1158 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1159 for (i = 0; i < nTabs; i++)
1161 if ( psInfo->proppage[i].hasIcon )
1163 item.mask |= TCIF_IMAGE;
1164 item.iImage = iImage++;
1166 else
1168 item.mask &= ~TCIF_IMAGE;
1171 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1172 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1174 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1176 return TRUE;
1179 /******************************************************************************
1180 * PROPSHEET_WizardSubclassProc
1182 * Subclassing window procedure for wizard exterior pages to prevent drawing
1183 * background and so drawing above the watermark.
1185 static LRESULT CALLBACK
1186 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1188 switch (uMsg)
1190 case WM_ERASEBKGND:
1191 return TRUE;
1193 case WM_CTLCOLORSTATIC:
1194 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1195 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1198 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1202 * Get the size of an in-memory Template
1204 *( Based on the code of PROPSHEET_CollectPageInfo)
1205 * See also dialog.c/DIALOG_ParseTemplate32().
1208 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1211 const WORD* p = (const WORD *)pTemplate;
1212 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1213 WORD nrofitems;
1214 UINT ret;
1216 if (istemplateex)
1218 /* DLGTEMPLATEEX (not defined in any std. header file) */
1220 TRACE("is DLGTEMPLATEEX\n");
1221 p++; /* dlgVer */
1222 p++; /* signature */
1223 p += 2; /* help ID */
1224 p += 2; /* ext style */
1225 p += 2; /* style */
1227 else
1229 /* DLGTEMPLATE */
1231 TRACE("is DLGTEMPLATE\n");
1232 p += 2; /* style */
1233 p += 2; /* ext style */
1236 nrofitems = (WORD)*p; p++; /* nb items */
1237 p++; /* x */
1238 p++; /* y */
1239 p++; /* width */
1240 p++; /* height */
1242 /* menu */
1243 switch ((WORD)*p)
1245 case 0x0000:
1246 p++;
1247 break;
1248 case 0xffff:
1249 p += 2;
1250 break;
1251 default:
1252 TRACE("menu %s\n",debugstr_w( p ));
1253 p += lstrlenW( p ) + 1;
1254 break;
1257 /* class */
1258 switch ((WORD)*p)
1260 case 0x0000:
1261 p++;
1262 break;
1263 case 0xffff:
1264 p += 2; /* 0xffff plus predefined window class ordinal value */
1265 break;
1266 default:
1267 TRACE("class %s\n",debugstr_w( p ));
1268 p += lstrlenW( p ) + 1;
1269 break;
1272 /* title */
1273 TRACE("title %s\n",debugstr_w( p ));
1274 p += lstrlenW( p ) + 1;
1276 /* font, if DS_SETFONT set */
1277 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1278 pTemplate->style)))
1280 p+=(istemplateex)?3:1;
1281 TRACE("font %s\n",debugstr_w( p ));
1282 p += lstrlenW( p ) + 1; /* the font name */
1285 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1286 * that are following the DLGTEMPLATE(EX) data */
1287 TRACE("%d items\n",nrofitems);
1288 while (nrofitems > 0)
1290 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1292 /* skip header */
1293 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1295 /* check class */
1296 switch ((WORD)*p)
1298 case 0x0000:
1299 p++;
1300 break;
1301 case 0xffff:
1302 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1303 p += 2;
1304 break;
1305 default:
1306 TRACE("class %s\n",debugstr_w( p ));
1307 p += lstrlenW( p ) + 1;
1308 break;
1311 /* check title text */
1312 switch ((WORD)*p)
1314 case 0x0000:
1315 p++;
1316 break;
1317 case 0xffff:
1318 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1319 p += 2;
1320 break;
1321 default:
1322 TRACE("text %s\n",debugstr_w( p ));
1323 p += lstrlenW( p ) + 1;
1324 break;
1326 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1327 --nrofitems;
1330 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1331 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1332 return ret;
1335 /******************************************************************************
1336 * PROPSHEET_CreatePage
1338 * Creates a page.
1340 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1341 int index,
1342 const PropSheetInfo * psInfo,
1343 LPCPROPSHEETPAGEW ppshpage)
1345 const DLGTEMPLATE* pTemplate;
1346 HWND hwndPage;
1347 DWORD resSize;
1348 DLGTEMPLATE* pTemplateCopy = NULL;
1350 TRACE("index %d\n", index);
1352 if (ppshpage == NULL)
1354 return FALSE;
1357 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1359 pTemplate = ppshpage->u.pResource;
1360 resSize = GetTemplateSize(pTemplate);
1362 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1364 HRSRC hResource;
1365 HANDLE hTemplate;
1367 hResource = FindResourceW(ppshpage->hInstance,
1368 ppshpage->u.pszTemplate,
1369 (LPWSTR)RT_DIALOG);
1370 if(!hResource)
1371 return FALSE;
1373 resSize = SizeofResource(ppshpage->hInstance, hResource);
1375 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1376 if(!hTemplate)
1377 return FALSE;
1379 pTemplate = LockResource(hTemplate);
1381 * Make a copy of the dialog template to make it writable
1384 else
1386 HRSRC hResource;
1387 HANDLE hTemplate;
1389 hResource = FindResourceA(ppshpage->hInstance,
1390 (LPCSTR)ppshpage->u.pszTemplate,
1391 (LPSTR)RT_DIALOG);
1392 if(!hResource)
1393 return FALSE;
1395 resSize = SizeofResource(ppshpage->hInstance, hResource);
1397 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1398 if(!hTemplate)
1399 return FALSE;
1401 pTemplate = LockResource(hTemplate);
1403 * Make a copy of the dialog template to make it writable
1406 pTemplateCopy = Alloc(resSize);
1407 if (!pTemplateCopy)
1408 return FALSE;
1410 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1411 memcpy(pTemplateCopy, pTemplate, resSize);
1413 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1415 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1416 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1417 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1418 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1419 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1420 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1421 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1422 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1424 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1426 else
1428 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1429 pTemplateCopy->style &= ~DS_MODALFRAME;
1430 pTemplateCopy->style &= ~WS_CAPTION;
1431 pTemplateCopy->style &= ~WS_SYSMENU;
1432 pTemplateCopy->style &= ~WS_POPUP;
1433 pTemplateCopy->style &= ~WS_DISABLED;
1434 pTemplateCopy->style &= ~WS_VISIBLE;
1435 pTemplateCopy->style &= ~WS_THICKFRAME;
1437 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1440 if (psInfo->proppage[index].useCallback)
1441 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1442 (LPPROPSHEETPAGEW)ppshpage);
1444 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1445 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1446 pTemplateCopy,
1447 hwndParent,
1448 ppshpage->pfnDlgProc,
1449 (LPARAM)ppshpage);
1450 else
1451 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1452 pTemplateCopy,
1453 hwndParent,
1454 ppshpage->pfnDlgProc,
1455 (LPARAM)ppshpage);
1456 /* Free a no more needed copy */
1457 Free(pTemplateCopy);
1459 if(!hwndPage)
1460 return FALSE;
1462 psInfo->proppage[index].hwndPage = hwndPage;
1464 /* Subclass exterior wizard pages */
1465 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1466 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1467 (ppshpage->dwFlags & PSP_HIDEHEADER))
1469 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1470 (DWORD_PTR)ppshpage);
1472 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1473 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1475 return TRUE;
1478 /******************************************************************************
1479 * PROPSHEET_LoadWizardBitmaps
1481 * Loads the watermark and header bitmaps for a wizard.
1483 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1485 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1487 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1488 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1489 considers hbmWatermark as valid. */
1490 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1491 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1493 psInfo->ppshheader.u4.hbmWatermark =
1494 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1497 /* Same behavior as for watermarks */
1498 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1499 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1501 psInfo->ppshheader.u5.hbmHeader =
1502 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1508 /******************************************************************************
1509 * PROPSHEET_ShowPage
1511 * Displays or creates the specified page.
1513 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1515 HWND hwndTabCtrl;
1516 HWND hwndLineHeader;
1517 HWND control;
1518 LPCPROPSHEETPAGEW ppshpage;
1520 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1521 if (index == psInfo->active_page)
1523 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1524 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1525 return TRUE;
1528 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1529 if (psInfo->proppage[index].hwndPage == 0)
1531 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1534 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1536 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1537 psInfo->proppage[index].pszText);
1539 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1540 if(control != NULL)
1541 SetFocus(control);
1544 if (psInfo->active_page != -1)
1545 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1547 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1549 /* Synchronize current selection with tab control
1550 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1551 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1552 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1554 psInfo->active_page = index;
1555 psInfo->activeValid = TRUE;
1557 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1559 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1560 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1562 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1563 ShowWindow(hwndLineHeader, SW_HIDE);
1564 else
1565 ShowWindow(hwndLineHeader, SW_SHOW);
1568 return TRUE;
1571 /******************************************************************************
1572 * PROPSHEET_Back
1574 static BOOL PROPSHEET_Back(HWND hwndDlg)
1576 PSHNOTIFY psn;
1577 HWND hwndPage;
1578 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1579 LRESULT result;
1580 int idx;
1582 TRACE("active_page %d\n", psInfo->active_page);
1583 if (psInfo->active_page < 0)
1584 return FALSE;
1586 psn.hdr.code = PSN_WIZBACK;
1587 psn.hdr.hwndFrom = hwndDlg;
1588 psn.hdr.idFrom = 0;
1589 psn.lParam = 0;
1591 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1593 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1594 if (result == -1)
1595 return FALSE;
1596 else if (result == 0)
1597 idx = psInfo->active_page - 1;
1598 else
1599 idx = PROPSHEET_FindPageByResId(psInfo, result);
1601 if (idx >= 0 && idx < psInfo->nPages)
1603 if (PROPSHEET_CanSetCurSel(hwndDlg))
1605 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1606 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1607 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1610 return TRUE;
1613 /******************************************************************************
1614 * PROPSHEET_Next
1616 static BOOL PROPSHEET_Next(HWND hwndDlg)
1618 PSHNOTIFY psn;
1619 HWND hwndPage;
1620 LRESULT msgResult = 0;
1621 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1622 int idx;
1624 TRACE("active_page %d\n", psInfo->active_page);
1625 if (psInfo->active_page < 0)
1626 return FALSE;
1628 psn.hdr.code = PSN_WIZNEXT;
1629 psn.hdr.hwndFrom = hwndDlg;
1630 psn.hdr.idFrom = 0;
1631 psn.lParam = 0;
1633 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1635 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1636 if (msgResult == -1)
1637 return FALSE;
1638 else if (msgResult == 0)
1639 idx = psInfo->active_page + 1;
1640 else
1641 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1643 if (idx < psInfo->nPages )
1645 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1647 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1648 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1649 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1653 return TRUE;
1656 /******************************************************************************
1657 * PROPSHEET_Finish
1659 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1661 PSHNOTIFY psn;
1662 HWND hwndPage;
1663 LRESULT msgResult = 0;
1664 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1666 TRACE("active_page %d\n", psInfo->active_page);
1667 if (psInfo->active_page < 0)
1668 return FALSE;
1670 psn.hdr.code = PSN_WIZFINISH;
1671 psn.hdr.hwndFrom = hwndDlg;
1672 psn.hdr.idFrom = 0;
1673 psn.lParam = 0;
1675 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1677 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1679 TRACE("msg result %ld\n", msgResult);
1681 if (msgResult != 0)
1682 return FALSE;
1684 if (psInfo->result == 0)
1685 psInfo->result = IDOK;
1686 if (psInfo->isModeless)
1687 psInfo->activeValid = FALSE;
1688 else
1689 psInfo->ended = TRUE;
1691 return TRUE;
1694 /******************************************************************************
1695 * PROPSHEET_Apply
1697 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1699 int i;
1700 HWND hwndPage;
1701 PSHNOTIFY psn;
1702 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1704 TRACE("active_page %d\n", psInfo->active_page);
1705 if (psInfo->active_page < 0)
1706 return FALSE;
1708 psn.hdr.hwndFrom = hwndDlg;
1709 psn.hdr.idFrom = 0;
1710 psn.lParam = 0;
1714 * Send PSN_KILLACTIVE to the current page.
1716 psn.hdr.code = PSN_KILLACTIVE;
1718 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1720 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1721 return FALSE;
1724 * Send PSN_APPLY to all pages.
1726 psn.hdr.code = PSN_APPLY;
1727 psn.lParam = lParam;
1729 for (i = 0; i < psInfo->nPages; i++)
1731 hwndPage = psInfo->proppage[i].hwndPage;
1732 if (hwndPage)
1734 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1736 case PSNRET_INVALID:
1737 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1738 /* fall through */
1739 case PSNRET_INVALID_NOCHANGEPAGE:
1740 return FALSE;
1745 if(lParam)
1747 psInfo->activeValid = FALSE;
1749 else if(psInfo->active_page >= 0)
1751 psn.hdr.code = PSN_SETACTIVE;
1752 psn.lParam = 0;
1753 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1754 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1757 return TRUE;
1760 /******************************************************************************
1761 * PROPSHEET_Cancel
1763 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1765 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1766 HWND hwndPage;
1767 PSHNOTIFY psn;
1768 int i;
1770 TRACE("active_page %d\n", psInfo->active_page);
1771 if (psInfo->active_page < 0)
1772 return;
1774 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1775 psn.hdr.code = PSN_QUERYCANCEL;
1776 psn.hdr.hwndFrom = hwndDlg;
1777 psn.hdr.idFrom = 0;
1778 psn.lParam = 0;
1780 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1781 return;
1783 psn.hdr.code = PSN_RESET;
1784 psn.lParam = lParam;
1786 for (i = 0; i < psInfo->nPages; i++)
1788 hwndPage = psInfo->proppage[i].hwndPage;
1790 if (hwndPage)
1791 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1794 if (psInfo->isModeless)
1796 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1797 psInfo->activeValid = FALSE;
1799 else
1800 psInfo->ended = TRUE;
1803 /******************************************************************************
1804 * PROPSHEET_Help
1806 static void PROPSHEET_Help(HWND hwndDlg)
1808 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1809 HWND hwndPage;
1810 PSHNOTIFY psn;
1812 TRACE("active_page %d\n", psInfo->active_page);
1813 if (psInfo->active_page < 0)
1814 return;
1816 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1817 psn.hdr.code = PSN_HELP;
1818 psn.hdr.hwndFrom = hwndDlg;
1819 psn.hdr.idFrom = 0;
1820 psn.lParam = 0;
1822 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1825 /******************************************************************************
1826 * PROPSHEET_Changed
1828 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1830 int i;
1831 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1833 TRACE("\n");
1834 if (!psInfo) return;
1836 * Set the dirty flag of this page.
1838 for (i = 0; i < psInfo->nPages; i++)
1840 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1841 psInfo->proppage[i].isDirty = TRUE;
1845 * Enable the Apply button.
1847 if (psInfo->hasApply)
1849 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1851 EnableWindow(hwndApplyBtn, TRUE);
1855 /******************************************************************************
1856 * PROPSHEET_UnChanged
1858 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1860 int i;
1861 BOOL noPageDirty = TRUE;
1862 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1863 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1865 TRACE("\n");
1866 if ( !psInfo ) return;
1867 for (i = 0; i < psInfo->nPages; i++)
1869 /* set the specified page as clean */
1870 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1871 psInfo->proppage[i].isDirty = FALSE;
1873 /* look to see if there are any dirty pages */
1874 if (psInfo->proppage[i].isDirty)
1875 noPageDirty = FALSE;
1879 * Disable Apply button.
1881 if (noPageDirty)
1882 EnableWindow(hwndApplyBtn, FALSE);
1885 /******************************************************************************
1886 * PROPSHEET_PressButton
1888 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1890 TRACE("buttonID %d\n", buttonID);
1891 switch (buttonID)
1893 case PSBTN_APPLYNOW:
1894 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1895 break;
1896 case PSBTN_BACK:
1897 PROPSHEET_Back(hwndDlg);
1898 break;
1899 case PSBTN_CANCEL:
1900 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1901 break;
1902 case PSBTN_FINISH:
1903 PROPSHEET_Finish(hwndDlg);
1904 break;
1905 case PSBTN_HELP:
1906 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1907 break;
1908 case PSBTN_NEXT:
1909 PROPSHEET_Next(hwndDlg);
1910 break;
1911 case PSBTN_OK:
1912 PROPSHEET_DoCommand(hwndDlg, IDOK);
1913 break;
1914 default:
1915 FIXME("Invalid button index %d\n", buttonID);
1920 /*************************************************************************
1921 * BOOL PROPSHEET_CanSetCurSel [Internal]
1923 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1925 * PARAMS
1926 * hwndDlg [I] handle to a Dialog hWnd
1928 * RETURNS
1929 * TRUE if Current Selection can change
1931 * NOTES
1933 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1935 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1936 HWND hwndPage;
1937 PSHNOTIFY psn;
1938 BOOL res = FALSE;
1940 if (!psInfo)
1942 res = FALSE;
1943 goto end;
1946 TRACE("active_page %d\n", psInfo->active_page);
1947 if (psInfo->active_page < 0)
1949 res = TRUE;
1950 goto end;
1954 * Notify the current page.
1956 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1957 psn.hdr.code = PSN_KILLACTIVE;
1958 psn.hdr.hwndFrom = hwndDlg;
1959 psn.hdr.idFrom = 0;
1960 psn.lParam = 0;
1962 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1964 end:
1965 TRACE("<-- %d\n", res);
1966 return res;
1969 /******************************************************************************
1970 * PROPSHEET_SetCurSel
1972 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1973 int index,
1974 int skipdir,
1975 HPROPSHEETPAGE hpage
1978 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1979 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1980 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1982 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1984 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
1986 if (index < 0 || index >= psInfo->nPages)
1988 TRACE("Could not find page to select!\n");
1989 return FALSE;
1992 /* unset active page while doing this transition. */
1993 if (psInfo->active_page != -1)
1994 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1995 psInfo->active_page = -1;
1997 while (1) {
1998 int result;
1999 PSHNOTIFY psn;
2000 RECT rc;
2001 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2003 if (hwndTabControl)
2004 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2006 psn.hdr.code = PSN_SETACTIVE;
2007 psn.hdr.hwndFrom = hwndDlg;
2008 psn.hdr.idFrom = 0;
2009 psn.lParam = 0;
2011 if (!psInfo->proppage[index].hwndPage) {
2012 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2013 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2015 if (!psInfo->isModeless)
2017 DestroyWindow(hwndDlg);
2018 return FALSE;
2021 if(index >= psInfo->nPages)
2022 index--;
2023 if(index < 0)
2024 return FALSE;
2025 continue;
2029 /* Resize the property sheet page to the fit in the Tab control
2030 * (for regular property sheets) or to fit in the client area (for
2031 * wizards).
2032 * NOTE: The resizing happens every time the page is selected and
2033 * not only when it's created (some applications depend on it). */
2034 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2035 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2036 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2037 rc.right - rc.left, rc.bottom - rc.top);
2038 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2039 rc.left, rc.top,
2040 rc.right - rc.left, rc.bottom - rc.top, 0);
2042 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2043 if (!result)
2044 break;
2045 if (result == -1) {
2046 index+=skipdir;
2047 if (index < 0) {
2048 index = 0;
2049 WARN("Tried to skip before first property sheet page!\n");
2050 break;
2052 if (index >= psInfo->nPages) {
2053 WARN("Tried to skip after last property sheet page!\n");
2054 index = psInfo->nPages-1;
2055 break;
2058 else if (result != 0)
2060 int old_index = index;
2061 index = PROPSHEET_FindPageByResId(psInfo, result);
2062 if(index >= psInfo->nPages) {
2063 index = old_index;
2064 WARN("Tried to skip to nonexistent page by res id\n");
2065 break;
2067 continue;
2071 /* Invalidate the header area */
2072 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2073 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2075 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2076 RECT r;
2078 GetClientRect(hwndLineHeader, &r);
2079 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2080 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2082 InvalidateRect(hwndDlg, &r, TRUE);
2086 * Display the new page.
2088 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2090 if (psInfo->proppage[index].hasHelp)
2091 EnableWindow(hwndHelp, TRUE);
2092 else
2093 EnableWindow(hwndHelp, FALSE);
2095 return TRUE;
2098 /******************************************************************************
2099 * PROPSHEET_SetCurSelId
2101 * Selects the page, specified by resource id.
2103 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2105 int idx;
2106 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2108 idx = PROPSHEET_FindPageByResId(psInfo, id);
2109 if (idx < psInfo->nPages )
2111 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2112 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2116 /******************************************************************************
2117 * PROPSHEET_SetTitleA
2119 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2121 if(!IS_INTRESOURCE(lpszText))
2123 WCHAR szTitle[256];
2124 MultiByteToWideChar(CP_ACP, 0, lpszText, -1, szTitle, ARRAY_SIZE(szTitle));
2125 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2127 else
2129 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2133 /******************************************************************************
2134 * PROPSHEET_SetTitleW
2136 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2138 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2139 WCHAR szTitle[256];
2141 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2142 if (IS_INTRESOURCE(lpszText)) {
2143 if (!LoadStringW(psInfo->ppshheader.hInstance, LOWORD(lpszText), szTitle, ARRAY_SIZE(szTitle)))
2144 return;
2145 lpszText = szTitle;
2147 if (dwStyle & PSH_PROPTITLE)
2149 WCHAR* dest;
2150 int lentitle = lstrlenW(lpszText);
2151 int lenprop = lstrlenW(psInfo->strPropertiesFor);
2153 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2154 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2156 SetWindowTextW(hwndDlg, dest);
2157 Free(dest);
2159 else
2160 SetWindowTextW(hwndDlg, lpszText);
2163 /******************************************************************************
2164 * PROPSHEET_SetFinishTextA
2166 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2168 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2169 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2171 TRACE("'%s'\n", lpszText);
2172 /* Set text, show and enable the Finish button */
2173 SetWindowTextA(hwndButton, lpszText);
2174 ShowWindow(hwndButton, SW_SHOW);
2175 EnableWindow(hwndButton, TRUE);
2177 /* Make it default pushbutton */
2178 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2180 /* Hide Back button */
2181 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2182 ShowWindow(hwndButton, SW_HIDE);
2184 if (!psInfo->hasFinish)
2186 /* Hide Next button */
2187 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2188 ShowWindow(hwndButton, SW_HIDE);
2192 /******************************************************************************
2193 * PROPSHEET_SetFinishTextW
2195 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2197 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2198 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2200 TRACE("%s\n", debugstr_w(lpszText));
2201 /* Set text, show and enable the Finish button */
2202 SetWindowTextW(hwndButton, lpszText);
2203 ShowWindow(hwndButton, SW_SHOW);
2204 EnableWindow(hwndButton, TRUE);
2206 /* Make it default pushbutton */
2207 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2209 /* Hide Back button */
2210 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2211 ShowWindow(hwndButton, SW_HIDE);
2213 if (!psInfo->hasFinish)
2215 /* Hide Next button */
2216 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2217 ShowWindow(hwndButton, SW_HIDE);
2221 /******************************************************************************
2222 * PROPSHEET_QuerySiblings
2224 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2225 WPARAM wParam, LPARAM lParam)
2227 int i = 0;
2228 HWND hwndPage;
2229 LRESULT msgResult = 0;
2230 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2232 while ((i < psInfo->nPages) && (msgResult == 0))
2234 hwndPage = psInfo->proppage[i].hwndPage;
2235 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2236 i++;
2239 return msgResult;
2242 /******************************************************************************
2243 * PROPSHEET_InsertPage
2245 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2247 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2248 PropPageInfo *ppi, *prev_ppi = psInfo->proppage;
2249 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2250 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2251 TCITEMW item;
2252 int index;
2254 TRACE("hwndDlg %p, hpageInsertAfter %p, hpage %p\n", hwndDlg, hpageInsertAfter, hpage);
2256 if (IS_INTRESOURCE(hpageInsertAfter))
2257 index = LOWORD(hpageInsertAfter);
2258 else
2260 index = PROPSHEET_GetPageIndex(hpageInsertAfter, psInfo, -1);
2261 if (index < 0)
2263 TRACE("Could not find page to insert after!\n");
2264 return FALSE;
2266 index++;
2269 if (index > psInfo->nPages)
2270 index = psInfo->nPages;
2272 ppi = Alloc(sizeof(PropPageInfo) * (psInfo->nPages + 1));
2273 if (!ppi)
2274 return FALSE;
2277 * Fill in a new PropPageInfo entry.
2279 if (index > 0)
2280 memcpy(ppi, prev_ppi, index * sizeof(PropPageInfo));
2281 memset(&ppi[index], 0, sizeof(PropPageInfo));
2282 if (index < psInfo->nPages)
2283 memcpy(&ppi[index + 1], &prev_ppi[index], (psInfo->nPages - index) * sizeof(PropPageInfo));
2284 psInfo->proppage = ppi;
2286 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, index, FALSE))
2288 psInfo->proppage = prev_ppi;
2289 Free(ppi);
2290 return FALSE;
2293 psInfo->proppage[index].hpage = hpage;
2295 if (ppsp->dwFlags & PSP_PREMATURE)
2297 /* Create the page but don't show it */
2298 if (!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppsp))
2300 psInfo->proppage = prev_ppi;
2301 Free(ppi);
2302 return FALSE;
2306 Free(prev_ppi);
2307 psInfo->nPages++;
2308 if (index <= psInfo->active_page)
2309 psInfo->active_page++;
2312 * Add a new tab to the tab control.
2314 item.mask = TCIF_TEXT;
2315 item.pszText = (LPWSTR) psInfo->proppage[index].pszText;
2316 item.cchTextMax = MAX_TABTEXT_LENGTH;
2318 if (psInfo->hImageList)
2319 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2321 if (psInfo->proppage[index].hasIcon)
2323 item.mask |= TCIF_IMAGE;
2324 item.iImage = index;
2327 SendMessageW(hwndTabControl, TCM_INSERTITEMW, index, (LPARAM)&item);
2329 /* If it is the only page - show it */
2330 if (psInfo->nPages == 1)
2331 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2333 return TRUE;
2336 /******************************************************************************
2337 * PROPSHEET_AddPage
2339 static BOOL PROPSHEET_AddPage(HWND hwndDlg, HPROPSHEETPAGE hpage)
2341 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2342 TRACE("hwndDlg %p, hpage %p\n", hwndDlg, hpage);
2343 return PROPSHEET_InsertPage(hwndDlg, UlongToPtr(psInfo->nPages), hpage);
2346 /******************************************************************************
2347 * PROPSHEET_RemovePage
2349 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2350 int index,
2351 HPROPSHEETPAGE hpage)
2353 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2354 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2355 PropPageInfo* oldPages;
2357 TRACE("index %d, hpage %p\n", index, hpage);
2358 if (!psInfo) {
2359 return FALSE;
2362 index = PROPSHEET_GetPageIndex(hpage, psInfo, index);
2364 /* Make sure that index is within range */
2365 if (index < 0 || index >= psInfo->nPages)
2367 TRACE("Could not find page to remove!\n");
2368 return FALSE;
2371 TRACE("total pages %d removing page %d active page %d\n",
2372 psInfo->nPages, index, psInfo->active_page);
2374 * Check if we're removing the active page.
2376 if (index == psInfo->active_page)
2378 if (psInfo->nPages > 1)
2380 if (index > 0)
2382 /* activate previous page */
2383 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2385 else
2387 /* activate the next page */
2388 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2389 psInfo->active_page = index;
2392 else
2394 psInfo->active_page = -1;
2395 if (!psInfo->isModeless)
2397 psInfo->ended = TRUE;
2398 return TRUE;
2402 else if (index < psInfo->active_page)
2403 psInfo->active_page--;
2405 /* Unsubclass the page dialog window */
2406 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2407 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2408 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2410 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2411 PROPSHEET_WizardSubclassProc, 1);
2414 /* Destroy page dialog window */
2415 DestroyWindow(psInfo->proppage[index].hwndPage);
2417 /* Free page resources */
2418 if(psInfo->proppage[index].hpage)
2420 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2422 if (psp->dwFlags & PSP_USETITLE)
2423 Free ((LPVOID)psInfo->proppage[index].pszText);
2425 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2428 /* Remove the tab */
2429 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2431 oldPages = psInfo->proppage;
2432 psInfo->nPages--;
2433 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2435 if (index > 0)
2436 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2438 if (index < psInfo->nPages)
2439 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2440 (psInfo->nPages - index) * sizeof(PropPageInfo));
2442 Free(oldPages);
2444 return FALSE;
2447 /******************************************************************************
2448 * PROPSHEET_SetWizButtons
2450 * This code will work if (and assumes that) the Next button is on top of the
2451 * Finish button. ie. Finish comes after Next in the Z order.
2452 * This means make sure the dialog template reflects this.
2455 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2457 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2458 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2459 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2460 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2461 BOOL enable_finish = ((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH);
2463 TRACE("%d\n", dwFlags);
2465 EnableWindow(hwndBack, dwFlags & PSWIZB_BACK);
2466 EnableWindow(hwndNext, dwFlags & PSWIZB_NEXT);
2467 EnableWindow(hwndFinish, enable_finish);
2469 /* set the default pushbutton to an enabled button */
2470 if (enable_finish)
2471 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2472 else if (dwFlags & PSWIZB_NEXT)
2473 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2474 else if (dwFlags & PSWIZB_BACK)
2475 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2476 else
2477 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2479 if (!psInfo->hasFinish)
2481 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2483 /* Hide the Next button */
2484 ShowWindow(hwndNext, SW_HIDE);
2486 /* Show the Finish button */
2487 ShowWindow(hwndFinish, SW_SHOW);
2489 else
2491 /* Hide the Finish button */
2492 ShowWindow(hwndFinish, SW_HIDE);
2493 /* Show the Next button */
2494 ShowWindow(hwndNext, SW_SHOW);
2499 /******************************************************************************
2500 * PROPSHEET_SetHeaderTitleW
2502 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, UINT page_index, const WCHAR *title)
2504 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2505 PROPSHEETPAGEW *page;
2507 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(title));
2509 if (page_index >= psInfo->nPages)
2510 return;
2512 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2514 if (!IS_INTRESOURCE(page->pszHeaderTitle))
2515 Free((void *)page->pszHeaderTitle);
2517 page->pszHeaderTitle = heap_strdupW(title);
2518 page->dwFlags |= PSP_USEHEADERTITLE;
2521 /******************************************************************************
2522 * PROPSHEET_SetHeaderTitleA
2524 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, UINT page_index, const char *title)
2526 WCHAR *titleW;
2528 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(title));
2530 titleW = heap_strdupAtoW(title);
2531 PROPSHEET_SetHeaderTitleW(hwndDlg, page_index, titleW);
2532 Free(titleW);
2535 /******************************************************************************
2536 * PROPSHEET_SetHeaderSubTitleW
2538 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, UINT page_index, const WCHAR *subtitle)
2540 PropSheetInfo *psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2541 PROPSHEETPAGEW *page;
2543 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_w(subtitle));
2545 if (page_index >= psInfo->nPages)
2546 return;
2548 page = (PROPSHEETPAGEW *)psInfo->proppage[page_index].hpage;
2550 if (!IS_INTRESOURCE(page->pszHeaderSubTitle))
2551 Free((void *)page->pszHeaderSubTitle);
2553 page->pszHeaderSubTitle = heap_strdupW(subtitle);
2554 page->dwFlags |= PSP_USEHEADERSUBTITLE;
2557 /******************************************************************************
2558 * PROPSHEET_SetHeaderSubTitleA
2560 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, UINT page_index, const char *subtitle)
2562 WCHAR *subtitleW;
2564 TRACE("(%p, %u, %s)\n", hwndDlg, page_index, debugstr_a(subtitle));
2566 subtitleW = heap_strdupAtoW(subtitle);
2567 PROPSHEET_SetHeaderSubTitleW(hwndDlg, page_index, subtitleW);
2568 Free(subtitleW);
2571 /******************************************************************************
2572 * PROPSHEET_HwndToIndex
2574 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2576 int index;
2577 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2579 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2581 for (index = 0; index < psInfo->nPages; index++)
2582 if (psInfo->proppage[index].hwndPage == hPageDlg)
2583 return index;
2584 WARN("%p not found\n", hPageDlg);
2585 return -1;
2588 /******************************************************************************
2589 * PROPSHEET_IndexToHwnd
2591 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2593 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2594 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2595 if (!psInfo)
2596 return 0;
2597 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2598 WARN("%d out of range.\n", iPageIndex);
2599 return 0;
2601 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2604 /******************************************************************************
2605 * PROPSHEET_PageToIndex
2607 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2609 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2611 TRACE("(%p, %p)\n", hwndDlg, hPage);
2613 return PROPSHEET_GetPageIndex(hPage, psInfo, -1);
2616 /******************************************************************************
2617 * PROPSHEET_IndexToPage
2619 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2621 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2622 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2623 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2624 WARN("%d out of range.\n", iPageIndex);
2625 return 0;
2627 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2630 /******************************************************************************
2631 * PROPSHEET_IdToIndex
2633 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2635 int index;
2636 LPCPROPSHEETPAGEW psp;
2637 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2638 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2639 for (index = 0; index < psInfo->nPages; index++) {
2640 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2641 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2642 return index;
2645 return -1;
2648 /******************************************************************************
2649 * PROPSHEET_IndexToId
2651 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2653 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2654 LPCPROPSHEETPAGEW psp;
2655 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2656 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2657 WARN("%d out of range.\n", iPageIndex);
2658 return 0;
2660 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2661 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2662 return 0;
2664 return (LRESULT)psp->u.pszTemplate;
2667 /******************************************************************************
2668 * PROPSHEET_GetResult
2670 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2672 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2673 return psInfo->result;
2676 /******************************************************************************
2677 * PROPSHEET_RecalcPageSizes
2679 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2681 FIXME("(%p): stub\n", hwndDlg);
2682 return FALSE;
2685 /******************************************************************************
2686 * PROPSHEET_GetPageIndex
2688 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2689 * the array of PropPageInfo. If page is not found original index is used
2690 * (page takes precedence over index).
2692 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE page, const PropSheetInfo* psInfo, int original_index)
2694 int index;
2696 TRACE("page %p index %d\n", page, original_index);
2698 for (index = 0; index < psInfo->nPages; index++)
2699 if (psInfo->proppage[index].hpage == page)
2700 return index;
2702 return original_index;
2705 /******************************************************************************
2706 * PROPSHEET_CleanUp
2708 static void PROPSHEET_CleanUp(HWND hwndDlg)
2710 int i;
2711 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2713 TRACE("\n");
2714 if (!psInfo) return;
2715 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2716 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2718 for (i = 0; i < psInfo->nPages; i++)
2720 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2722 /* Unsubclass the page dialog window */
2723 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2724 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2725 (psp->dwFlags & PSP_HIDEHEADER))
2727 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2728 PROPSHEET_WizardSubclassProc, 1);
2731 if(psInfo->proppage[i].hwndPage)
2732 DestroyWindow(psInfo->proppage[i].hwndPage);
2734 if(psp)
2736 if (psp->dwFlags & PSP_USETITLE)
2737 Free ((LPVOID)psInfo->proppage[i].pszText);
2739 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2743 DeleteObject(psInfo->hFont);
2744 DeleteObject(psInfo->hFontBold);
2745 /* If we created the bitmaps, destroy them */
2746 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2747 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2748 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2749 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2750 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2751 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2753 Free(psInfo->proppage);
2754 Free(psInfo->strPropertiesFor);
2755 ImageList_Destroy(psInfo->hImageList);
2757 GlobalFree(psInfo);
2760 static INT do_loop(const PropSheetInfo *psInfo)
2762 MSG msg = { 0 };
2763 INT ret = 0;
2764 HWND hwnd = psInfo->hwnd;
2765 HWND parent = psInfo->ppshheader.hwndParent;
2767 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2769 if(ret == -1)
2770 break;
2772 if(!IsDialogMessageW(hwnd, &msg))
2774 TranslateMessage(&msg);
2775 DispatchMessageW(&msg);
2779 if(ret == 0 && msg.message)
2780 PostQuitMessage(msg.wParam);
2782 if(ret != -1)
2783 ret = psInfo->result;
2785 if(parent)
2786 EnableWindow(parent, TRUE);
2788 DestroyWindow(hwnd);
2789 return ret;
2792 /******************************************************************************
2793 * PROPSHEET_PropertySheet
2795 * Common code between PropertySheetA/W
2797 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2799 INT_PTR bRet = 0;
2800 HWND parent = NULL;
2801 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2802 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2804 psInfo->unicode = unicode;
2805 psInfo->ended = FALSE;
2807 if(!psInfo->isModeless)
2809 parent = psInfo->ppshheader.hwndParent;
2810 if (parent) EnableWindow(parent, FALSE);
2812 bRet = PROPSHEET_CreateDialog(psInfo);
2813 if(!psInfo->isModeless)
2814 bRet = do_loop(psInfo);
2815 return bRet;
2818 /******************************************************************************
2819 * PropertySheet (COMCTL32.@)
2820 * PropertySheetA (COMCTL32.@)
2822 * Creates a property sheet in the specified property sheet header.
2824 * RETURNS
2825 * Modal property sheets: Positive if successful or -1 otherwise.
2826 * Modeless property sheets: Property sheet handle.
2827 * Or:
2828 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2829 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2831 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2833 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2834 UINT i, n;
2835 const BYTE* pByte;
2837 TRACE("(%p)\n", lppsh);
2839 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2841 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2842 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2844 for (n = i = 0; i < lppsh->nPages; i++, n++)
2846 if (!psInfo->usePropPage)
2847 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2848 else
2850 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2851 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2854 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2855 psInfo, n, TRUE))
2857 if (psInfo->usePropPage)
2858 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2859 n--;
2860 psInfo->nPages--;
2864 return PROPSHEET_PropertySheet(psInfo, FALSE);
2867 /******************************************************************************
2868 * PropertySheetW (COMCTL32.@)
2870 * See PropertySheetA.
2872 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2874 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2875 UINT i, n;
2876 const BYTE* pByte;
2878 TRACE("(%p)\n", lppsh);
2880 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2882 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2883 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2885 for (n = i = 0; i < lppsh->nPages; i++, n++)
2887 if (!psInfo->usePropPage)
2888 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2889 else
2891 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2892 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2895 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2896 psInfo, n, TRUE))
2898 if (psInfo->usePropPage)
2899 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2900 n--;
2901 psInfo->nPages--;
2905 return PROPSHEET_PropertySheet(psInfo, TRUE);
2908 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2910 LPWSTR ret;
2912 if (IS_INTRESOURCE(str))
2914 HRSRC hrsrc;
2915 HGLOBAL hmem;
2916 WCHAR *ptr;
2917 WORD i, id = LOWORD(str);
2918 UINT len;
2920 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2921 return NULL;
2922 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2923 if (!(ptr = LockResource( hmem ))) return NULL;
2924 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2925 len = *ptr;
2926 if (!len) return NULL;
2927 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2928 if (ret)
2930 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2931 ret[len] = 0;
2934 else
2936 int len = (lstrlenW(str) + 1) * sizeof(WCHAR);
2937 ret = Alloc( len );
2938 if (ret) memcpy( ret, str, len );
2940 return ret;
2944 /******************************************************************************
2945 * CreatePropertySheetPage (COMCTL32.@)
2946 * CreatePropertySheetPageA (COMCTL32.@)
2948 * Creates a new property sheet page.
2950 * RETURNS
2951 * Success: Handle to new property sheet page.
2952 * Failure: NULL.
2954 * NOTES
2955 * An application must use the PSM_ADDPAGE message to add the new page to
2956 * an existing property sheet.
2958 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2959 LPCPROPSHEETPAGEA lpPropSheetPage)
2961 PROPSHEETPAGEW *ppsp;
2963 if (lpPropSheetPage->dwSize < PROPSHEETPAGEA_V1_SIZE)
2964 return NULL;
2966 /* original data is used for callback notifications */
2967 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
2969 ppsp = Alloc(2 * sizeof(*ppsp));
2970 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2971 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2973 else
2975 ppsp = Alloc(sizeof(*ppsp));
2976 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEA)));
2979 ppsp->dwFlags &= ~PSP_INTERNAL_UNICODE;
2981 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2983 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2985 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2986 char *template = Alloc( len );
2988 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2992 if (ppsp->dwFlags & PSP_USEICONID)
2994 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2995 ppsp->u2.pszIcon = heap_strdupAtoW( lpPropSheetPage->u2.pszIcon );
2998 if (ppsp->dwFlags & PSP_USETITLE)
3000 if (IS_INTRESOURCE( ppsp->pszTitle ))
3001 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3002 else
3003 ppsp->pszTitle = heap_strdupAtoW( lpPropSheetPage->pszTitle );
3005 else
3006 ppsp->pszTitle = NULL;
3008 if (ppsp->dwFlags & PSP_HIDEHEADER)
3009 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3011 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3013 if (IS_INTRESOURCE( ppsp->pszHeaderTitle ))
3014 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3015 else
3016 ppsp->pszHeaderTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderTitle );
3018 else
3019 ppsp->pszHeaderTitle = NULL;
3021 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3023 if (IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
3024 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3025 else
3026 ppsp->pszHeaderSubTitle = heap_strdupAtoW( lpPropSheetPage->pszHeaderSubTitle );
3028 else
3029 ppsp->pszHeaderSubTitle = NULL;
3031 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEA_V1_SIZE && ppsp->pfnCallback)
3032 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3034 return (HPROPSHEETPAGE)ppsp;
3037 /******************************************************************************
3038 * CreatePropertySheetPageW (COMCTL32.@)
3040 * See CreatePropertySheetA.
3042 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3044 PROPSHEETPAGEW *ppsp;
3046 if (lpPropSheetPage->dwSize < PROPSHEETPAGEW_V1_SIZE)
3047 return NULL;
3049 /* original data is used for callback notifications */
3050 if ((lpPropSheetPage->dwFlags & PSP_USECALLBACK) && lpPropSheetPage->pfnCallback)
3052 ppsp = Alloc(2 * sizeof(*ppsp));
3053 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3054 memcpy(ppsp + 1, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3056 else
3058 ppsp = Alloc(sizeof(*ppsp));
3059 memcpy(ppsp, lpPropSheetPage, min(lpPropSheetPage->dwSize, sizeof(PROPSHEETPAGEW)));
3062 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3064 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3066 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3067 ppsp->u.pszTemplate = heap_strdupW( lpPropSheetPage->u.pszTemplate );
3070 if ( ppsp->dwFlags & PSP_USEICONID )
3072 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3073 ppsp->u2.pszIcon = heap_strdupW( lpPropSheetPage->u2.pszIcon );
3076 if (ppsp->dwFlags & PSP_USETITLE)
3077 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3078 else
3079 ppsp->pszTitle = NULL;
3081 if (ppsp->dwFlags & PSP_HIDEHEADER)
3082 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3084 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3085 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3086 else
3087 ppsp->pszHeaderTitle = NULL;
3089 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3090 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3091 else
3092 ppsp->pszHeaderSubTitle = NULL;
3094 if ((ppsp->dwFlags & PSP_USECALLBACK) && ppsp->dwSize > PROPSHEETPAGEW_V1_SIZE && ppsp->pfnCallback)
3095 ppsp->pfnCallback(0, PSPCB_ADDREF, ppsp + 1);
3097 return (HPROPSHEETPAGE)ppsp;
3100 /******************************************************************************
3101 * DestroyPropertySheetPage (COMCTL32.@)
3103 * Destroys a property sheet page previously created with
3104 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3105 * memory.
3107 * RETURNS
3108 * Success: TRUE
3109 * Failure: FALSE
3111 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3113 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3115 if (!psp)
3116 return FALSE;
3118 if ((psp->dwFlags & PSP_USECALLBACK) && psp->pfnCallback)
3119 psp->pfnCallback(0, PSPCB_RELEASE, psp + 1);
3121 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3122 Free ((LPVOID)psp->u.pszTemplate);
3124 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3125 Free ((LPVOID)psp->u2.pszIcon);
3127 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3128 Free ((LPVOID)psp->pszTitle);
3130 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3131 Free ((LPVOID)psp->pszHeaderTitle);
3133 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3134 Free ((LPVOID)psp->pszHeaderSubTitle);
3136 Free(hPropPage);
3138 return TRUE;
3141 /******************************************************************************
3142 * PROPSHEET_IsDialogMessage
3144 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3146 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3148 TRACE("\n");
3149 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3150 return FALSE;
3152 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3154 int new_page = 0;
3155 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3157 if (!(dlgCode & DLGC_WANTMESSAGE))
3159 switch (lpMsg->wParam)
3161 case VK_TAB:
3162 if (GetKeyState(VK_SHIFT) & 0x8000)
3163 new_page = -1;
3164 else
3165 new_page = 1;
3166 break;
3168 case VK_NEXT: new_page = 1; break;
3169 case VK_PRIOR: new_page = -1; break;
3173 if (new_page)
3175 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3177 new_page += psInfo->active_page;
3179 if (new_page < 0)
3180 new_page = psInfo->nPages - 1;
3181 else if (new_page >= psInfo->nPages)
3182 new_page = 0;
3184 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3187 return TRUE;
3191 return IsDialogMessageW(hwnd, lpMsg);
3194 /******************************************************************************
3195 * PROPSHEET_DoCommand
3197 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3200 switch (wID) {
3202 case IDOK:
3203 case IDC_APPLY_BUTTON:
3205 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3207 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3208 break;
3210 if (wID == IDOK)
3212 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3214 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3215 if (psInfo->result == 0)
3216 psInfo->result = IDOK;
3218 if (psInfo->isModeless)
3219 psInfo->activeValid = FALSE;
3220 else
3221 psInfo->ended = TRUE;
3223 else
3224 EnableWindow(hwndApplyBtn, FALSE);
3226 break;
3229 case IDC_BACK_BUTTON:
3230 PROPSHEET_Back(hwnd);
3231 break;
3233 case IDC_NEXT_BUTTON:
3234 PROPSHEET_Next(hwnd);
3235 break;
3237 case IDC_FINISH_BUTTON:
3238 PROPSHEET_Finish(hwnd);
3239 break;
3241 case IDCANCEL:
3242 PROPSHEET_Cancel(hwnd, 0);
3243 break;
3245 case IDHELP:
3246 PROPSHEET_Help(hwnd);
3247 break;
3249 default:
3250 return FALSE;
3253 return TRUE;
3256 /******************************************************************************
3257 * PROPSHEET_Paint
3259 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3261 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3262 PAINTSTRUCT ps;
3263 HDC hdc, hdcSrc;
3264 BITMAP bm;
3265 HBITMAP hbmp;
3266 HPALETTE hOldPal = 0;
3267 int offsety = 0;
3268 HBRUSH hbr;
3269 RECT r, rzone;
3270 LPCPROPSHEETPAGEW ppshpage;
3271 WCHAR szBuffer[256];
3272 int nLength;
3274 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3275 if (!hdc) return 1;
3277 hdcSrc = CreateCompatibleDC(0);
3279 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3280 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3282 if (psInfo->active_page < 0)
3283 ppshpage = NULL;
3284 else
3285 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3287 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3288 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3289 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3291 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3292 HFONT hOldFont;
3293 COLORREF clrOld = 0;
3294 int oldBkMode = 0;
3296 GetClientRect(hwndLineHeader, &r);
3297 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3298 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3300 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3302 if (psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)
3304 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3306 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3307 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3309 /* Fill the unoccupied part of the header with color of the
3310 * left-top pixel, but do it only when needed.
3312 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3314 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3315 r = rzone;
3316 if (bm.bmWidth < r.right)
3318 r.left = bm.bmWidth;
3319 FillRect(hdc, &r, hbr);
3321 if (bm.bmHeight < r.bottom)
3323 r.left = 0;
3324 r.top = bm.bmHeight;
3325 FillRect(hdc, &r, hbr);
3327 DeleteObject(hbr);
3330 /* Draw the header itself. */
3331 BitBlt(hdc, 0, 0, bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3332 hdcSrc, 0, 0, SRCCOPY);
3334 else
3336 int margin;
3337 hbr = GetSysColorBrush(COLOR_WINDOW);
3338 FillRect(hdc, &rzone, hbr);
3340 /* Draw the header bitmap. It's always centered like a
3341 * common 49 x 49 bitmap. */
3342 margin = (rzone.bottom - 49) / 2;
3343 BitBlt(hdc, rzone.right - 49 - margin, margin,
3344 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3345 hdcSrc, 0, 0, SRCCOPY);
3347 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3348 * if its height is smaller than 49 pixels. Because the reason
3349 * for this bug is unknown the current code doesn't try to
3350 * replicate it. */
3353 SelectObject(hdcSrc, hbmp);
3356 clrOld = SetTextColor (hdc, 0x00000000);
3357 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3359 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3360 SetRect(&r, 20, 10, 0, 0);
3361 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3362 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3363 else
3365 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3366 szBuffer, 256);
3367 if (nLength != 0)
3369 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3374 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3375 SelectObject(hdc, psInfo->hFont);
3376 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3377 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3378 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3379 else
3381 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3382 szBuffer, 256);
3383 if (nLength != 0)
3385 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3390 offsety = rzone.bottom + 2;
3392 SetTextColor(hdc, clrOld);
3393 SetBkMode(hdc, oldBkMode);
3394 SelectObject(hdc, hOldFont);
3397 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3398 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3399 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3401 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3403 GetClientRect(hwndLine, &r);
3404 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3405 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3407 hbr = GetSysColorBrush(COLOR_WINDOW);
3408 FillRect(hdc, &rzone, hbr);
3410 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3411 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3413 /* The watermark is truncated to a width of 164 pixels */
3414 r.right = min(r.right, 164);
3415 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3416 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3418 /* If the bitmap is not big enough, fill the remaining area
3419 with the color of pixel (0,0) of bitmap - see MSDN */
3420 if (r.top > bm.bmHeight) {
3421 r.bottom = r.top - 1;
3422 r.top = bm.bmHeight;
3423 r.left = 0;
3424 r.right = bm.bmWidth;
3425 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3426 FillRect(hdc, &r, hbr);
3427 DeleteObject(hbr);
3430 SelectObject(hdcSrc, hbmp);
3433 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3434 SelectPalette(hdc, hOldPal, FALSE);
3436 DeleteDC(hdcSrc);
3438 if (!hdcParam) EndPaint(hwnd, &ps);
3440 return 0;
3443 /******************************************************************************
3444 * PROPSHEET_DialogProc
3446 static INT_PTR CALLBACK
3447 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3449 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3450 hwnd, uMsg, wParam, lParam);
3452 switch (uMsg)
3454 case WM_INITDIALOG:
3456 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3457 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3458 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3459 int idx;
3460 LOGFONTW logFont;
3462 /* Using PropSheetInfoStr to store extra data doesn't match the native
3463 * common control: native uses TCM_[GS]ETITEM
3465 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3468 * psInfo->hwnd is not being used by WINE code - it exists
3469 * for compatibility with "real" Windoze. The same about
3470 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3471 * property.
3473 psInfo->hwnd = hwnd;
3474 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3476 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3478 /* set up the Next and Back buttons by default */
3479 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3482 /* Set up fonts */
3483 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3484 psInfo->hFont = CreateFontIndirectW (&logFont);
3485 logFont.lfWeight = FW_BOLD;
3486 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3489 * Small icon in the title bar.
3491 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3492 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3494 HICON hIcon;
3495 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3496 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3498 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3499 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3500 psInfo->ppshheader.u.pszIcon,
3501 IMAGE_ICON,
3502 icon_cx, icon_cy,
3503 LR_DEFAULTCOLOR);
3504 else
3505 hIcon = psInfo->ppshheader.u.hIcon;
3507 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3510 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3511 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3513 psInfo->strPropertiesFor = strCaption;
3515 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3517 PROPSHEET_CreateTabControl(hwnd, psInfo);
3519 PROPSHEET_LoadWizardBitmaps(psInfo);
3521 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3523 ShowWindow(hwndTabCtrl, SW_HIDE);
3524 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3525 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3526 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3528 else
3530 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3532 PROPSHEET_AdjustSize(hwnd, psInfo);
3533 PROPSHEET_AdjustButtons(hwnd, psInfo);
3535 SetFocus(GetDlgItem(hwnd, IDOK));
3538 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3539 psInfo->ppshheader.hInstance)
3541 WCHAR szText[256];
3543 if (LoadStringW(psInfo->ppshheader.hInstance,
3544 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3545 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3547 else
3549 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3550 psInfo->ppshheader.pszCaption);
3554 if (psInfo->useCallback)
3555 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3557 idx = psInfo->active_page;
3558 psInfo->active_page = -1;
3560 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3562 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3563 * as some programs call TCM_GETCURSEL to get the current selection
3564 * from which to switch to the next page */
3565 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3567 PROPSHEET_UnChanged(hwnd, NULL);
3569 /* wizards set their focus during init */
3570 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3571 return FALSE;
3573 return TRUE;
3576 case WM_PRINTCLIENT:
3577 case WM_PAINT:
3578 PROPSHEET_Paint(hwnd, (HDC)wParam);
3579 return TRUE;
3581 case WM_DESTROY:
3582 PROPSHEET_CleanUp(hwnd);
3583 return TRUE;
3585 case WM_CLOSE:
3586 PROPSHEET_Cancel(hwnd, 1);
3587 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3589 case WM_COMMAND:
3590 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3592 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3594 if (!psInfo)
3595 return FALSE;
3597 /* No default handler, forward notification to active page */
3598 if (psInfo->activeValid && psInfo->active_page != -1)
3600 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3601 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3604 return TRUE;
3606 case WM_NOTIFY:
3608 NMHDR* pnmh = (LPNMHDR) lParam;
3610 if (pnmh->code == TCN_SELCHANGE)
3612 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3613 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3616 if(pnmh->code == TCN_SELCHANGING)
3618 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3619 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3620 return TRUE;
3623 return FALSE;
3626 case WM_SYSCOLORCHANGE:
3627 COMCTL32_RefreshSysColors();
3628 return FALSE;
3630 case PSM_GETCURRENTPAGEHWND:
3632 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3633 HWND hwndPage = 0;
3635 if (!psInfo)
3636 return FALSE;
3638 if (psInfo->activeValid && psInfo->active_page != -1)
3639 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3641 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3643 return TRUE;
3646 case PSM_CHANGED:
3647 PROPSHEET_Changed(hwnd, (HWND)wParam);
3648 return TRUE;
3650 case PSM_UNCHANGED:
3651 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3652 return TRUE;
3654 case PSM_GETTABCONTROL:
3656 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3658 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3660 return TRUE;
3663 case PSM_SETCURSEL:
3665 BOOL msgResult;
3667 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3668 if(msgResult != FALSE)
3670 msgResult = PROPSHEET_SetCurSel(hwnd,
3671 (int)wParam,
3673 (HPROPSHEETPAGE)lParam);
3676 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3678 return TRUE;
3681 case PSM_CANCELTOCLOSE:
3683 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3684 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3685 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3687 EnableWindow(hwndCancel, FALSE);
3688 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, ARRAY_SIZE(buf)))
3689 SetWindowTextW(hwndOK, buf);
3691 return FALSE;
3694 case PSM_RESTARTWINDOWS:
3696 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3698 if (!psInfo)
3699 return FALSE;
3701 /* reboot system takes precedence over restart windows */
3702 if (psInfo->result != ID_PSREBOOTSYSTEM)
3703 psInfo->result = ID_PSRESTARTWINDOWS;
3705 return TRUE;
3708 case PSM_REBOOTSYSTEM:
3710 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3712 if (!psInfo)
3713 return FALSE;
3715 psInfo->result = ID_PSREBOOTSYSTEM;
3717 return TRUE;
3720 case PSM_SETTITLEA:
3721 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3722 return TRUE;
3724 case PSM_SETTITLEW:
3725 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3726 return TRUE;
3728 case PSM_APPLY:
3730 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3732 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3734 return TRUE;
3737 case PSM_QUERYSIBLINGS:
3739 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3741 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3743 return TRUE;
3746 case PSM_ADDPAGE:
3749 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3750 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3751 * on success or FALSE otherwise, as specified on MSDN Online.
3752 * Also see the MFC code for
3753 * CPropertySheet::AddPage(CPropertyPage* pPage).
3756 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3758 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3760 return TRUE;
3763 case PSM_REMOVEPAGE:
3764 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3765 return TRUE;
3767 case PSM_ISDIALOGMESSAGE:
3769 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3770 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3771 return TRUE;
3774 case PSM_PRESSBUTTON:
3775 PROPSHEET_PressButton(hwnd, (int)wParam);
3776 return TRUE;
3778 case PSM_SETFINISHTEXTA:
3779 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3780 return TRUE;
3782 case PSM_SETWIZBUTTONS:
3783 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3784 return TRUE;
3786 case PSM_SETCURSELID:
3787 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3788 return TRUE;
3790 case PSM_SETFINISHTEXTW:
3791 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3792 return FALSE;
3794 case PSM_INSERTPAGE:
3796 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3801 case PSM_SETHEADERTITLEW:
3802 PROPSHEET_SetHeaderTitleW(hwnd, wParam, (LPCWSTR)lParam);
3803 return TRUE;
3805 case PSM_SETHEADERTITLEA:
3806 PROPSHEET_SetHeaderTitleA(hwnd, wParam, (LPCSTR)lParam);
3807 return TRUE;
3809 case PSM_SETHEADERSUBTITLEW:
3810 PROPSHEET_SetHeaderSubTitleW(hwnd, wParam, (LPCWSTR)lParam);
3811 return TRUE;
3813 case PSM_SETHEADERSUBTITLEA:
3814 PROPSHEET_SetHeaderSubTitleA(hwnd, wParam, (LPCSTR)lParam);
3815 return TRUE;
3817 case PSM_HWNDTOINDEX:
3819 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3820 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3821 return TRUE;
3824 case PSM_INDEXTOHWND:
3826 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3827 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3828 return TRUE;
3831 case PSM_PAGETOINDEX:
3833 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3834 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3835 return TRUE;
3838 case PSM_INDEXTOPAGE:
3840 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3841 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3842 return TRUE;
3845 case PSM_IDTOINDEX:
3847 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3848 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3849 return TRUE;
3852 case PSM_INDEXTOID:
3854 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3855 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3856 return TRUE;
3859 case PSM_GETRESULT:
3861 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3862 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3863 return TRUE;
3866 case PSM_RECALCPAGESIZES:
3868 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3869 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3870 return TRUE;
3873 default:
3874 return FALSE;