winedbg: Add enhanced Coprocessor move operators to Thumb2 disassembler.
[wine.git] / dlls / comctl32 / propsheet.c
blobb2ceee885619dd9f0a84a69aeb8e2f21c842aa43
1 /*
2 * Property Sheets
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_INSERTPAGE
36 * o PSM_RECALCPAGESIZES
37 * o PSM_SETHEADERSUBTITLE
38 * o PSM_SETHEADERTITLE
39 * o WM_HELP
40 * o WM_CONTEXTMENU
41 * - Notifications:
42 * o PSN_GETOBJECT
43 * o PSN_QUERYINITIALFOCUS
44 * o PSN_TRANSLATEACCELERATOR
45 * - Styles:
46 * o PSH_RTLREADING
47 * o PSH_STRETCHWATERMARK
48 * o PSH_USEPAGELANG
49 * o PSH_USEPSTARTPAGE
50 * - Page styles:
51 * o PSP_USEFUSIONCONTEXT
52 * o PSP_USEREFPARENT
55 #include <stdarg.h>
56 #include <string.h>
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winuser.h"
64 #include "winnls.h"
65 #include "commctrl.h"
66 #include "prsht.h"
67 #include "comctl32.h"
68 #include "uxtheme.h"
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
73 /******************************************************************************
74 * Data structures
76 #include "pshpack2.h"
78 typedef struct
80 WORD dlgVer;
81 WORD signature;
82 DWORD helpID;
83 DWORD exStyle;
84 DWORD style;
85 } MyDLGTEMPLATEEX;
87 typedef struct
89 DWORD helpid;
90 DWORD exStyle;
91 DWORD style;
92 short x;
93 short y;
94 short cx;
95 short cy;
96 DWORD id;
97 } MyDLGITEMTEMPLATEEX;
98 #include "poppack.h"
100 typedef struct tagPropPageInfo
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 HWND hwndPage;
104 BOOL isDirty;
105 LPCWSTR pszText;
106 BOOL hasHelp;
107 BOOL useCallback;
108 BOOL hasIcon;
109 } PropPageInfo;
111 typedef struct tagPropSheetInfo
113 HWND hwnd;
114 PROPSHEETHEADERW ppshheader;
115 BOOL unicode;
116 LPWSTR strPropertiesFor;
117 int nPages;
118 int active_page;
119 BOOL isModeless;
120 BOOL hasHelp;
121 BOOL hasApply;
122 BOOL hasFinish;
123 BOOL usePropPage;
124 BOOL useCallback;
125 BOOL activeValid;
126 PropPageInfo* proppage;
127 HFONT hFont;
128 HFONT hFontBold;
129 int width;
130 int height;
131 HIMAGELIST hImageList;
132 BOOL ended;
133 INT result;
134 } PropSheetInfo;
136 typedef struct
138 int x;
139 int y;
140 } PADDING_INFO;
142 /******************************************************************************
143 * Defines and global variables
146 static const WCHAR PropSheetInfoStr[] =
147 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
149 #define PSP_INTERNAL_UNICODE 0x80000000
151 #define MAX_CAPTION_LENGTH 255
152 #define MAX_TABTEXT_LENGTH 255
153 #define MAX_BUTTONTEXT_LENGTH 64
155 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
157 /* Wizard metrics specified in DLUs */
158 #define WIZARD_PADDING 7
159 #define WIZARD_HEADER_HEIGHT 36
161 /******************************************************************************
162 * Prototypes
164 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
165 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
166 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
167 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
168 int index,
169 int skipdir,
170 HPROPSHEETPAGE hpage);
171 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo);
172 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
173 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 static BOOL PROPSHEET_RemovePage(HWND hwndDlg, int index, HPROPSHEETPAGE hpage);
176 static INT_PTR CALLBACK
177 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
179 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
181 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
182 /******************************************************************************
183 * PROPSHEET_UnImplementedFlags
185 * Document use of flags we don't implement yet.
187 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
189 CHAR string[256];
191 string[0] = '\0';
194 * unhandled header flags:
195 * PSH_RTLREADING 0x00000800
196 * PSH_STRETCHWATERMARK 0x00040000
197 * PSH_USEPAGELANG 0x00200000
200 add_flag(PSH_RTLREADING);
201 add_flag(PSH_STRETCHWATERMARK);
202 add_flag(PSH_USEPAGELANG);
203 if (string[0] != '\0')
204 FIXME("%s\n", string);
206 #undef add_flag
208 /******************************************************************************
209 * PROPSHEET_GetPageRect
211 * Retrieve rect from tab control and map into the dialog for SetWindowPos
213 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
214 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
216 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
217 HWND hwndChild;
218 RECT r;
220 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
221 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
222 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
223 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
225 rc->left = rc->top = WIZARD_PADDING;
227 else
229 rc->left = rc->top = 0;
231 rc->right = psInfo->width - rc->left;
232 rc->bottom = psInfo->height - rc->top;
233 MapDialogRect(hwndDlg, rc);
235 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
236 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
237 !(ppshpage->dwFlags & PSP_HIDEHEADER))
239 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
240 GetClientRect(hwndChild, &r);
241 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
242 rc->top += r.bottom + 1;
244 } else {
245 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
246 GetClientRect(hwndTabCtrl, rc);
247 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
248 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
252 /******************************************************************************
253 * PROPSHEET_FindPageByResId
255 * Find page index corresponding to page resource id.
257 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
259 INT i;
261 for (i = 0; i < psInfo->nPages; i++)
263 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
265 /* Fixme: if resource ID is a string shall we use strcmp ??? */
266 if (lppsp->u.pszTemplate == (LPVOID)resId)
267 break;
270 return i;
273 /******************************************************************************
274 * PROPSHEET_AtoW
276 * Convert ASCII to Unicode since all data is saved as Unicode.
278 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
280 INT len;
281 WCHAR *to;
283 TRACE("<%s>\n", frstr);
284 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
285 to = Alloc(len * sizeof(WCHAR));
286 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
287 *tostr = to;
290 /******************************************************************************
291 * PROPSHEET_CollectSheetInfoCommon
293 * Common code for PROPSHEET_CollectSheetInfoA/W
295 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
297 PROPSHEET_UnImplementedFlags(dwFlags);
299 psInfo->hasHelp = dwFlags & PSH_HASHELP;
300 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
301 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
302 psInfo->isModeless = dwFlags & PSH_MODELESS;
303 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
304 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
305 psInfo->active_page = 0;
307 psInfo->result = 0;
308 psInfo->hImageList = 0;
309 psInfo->activeValid = FALSE;
312 /******************************************************************************
313 * PROPSHEET_CollectSheetInfoA
315 * Collect relevant data.
317 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
318 PropSheetInfo * psInfo)
320 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
321 DWORD dwFlags = lppsh->dwFlags;
323 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
325 memcpy(&psInfo->ppshheader,lppsh,dwSize);
326 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
327 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
328 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
330 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
331 psInfo->ppshheader.pszCaption = NULL;
332 else
334 if (!IS_INTRESOURCE(lppsh->pszCaption))
336 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
337 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
339 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
340 psInfo->ppshheader.pszCaption = caption;
343 psInfo->nPages = lppsh->nPages;
345 if (dwFlags & PSH_USEPSTARTPAGE)
347 TRACE("PSH_USEPSTARTPAGE is on\n");
348 psInfo->active_page = 0;
350 else
351 psInfo->active_page = lppsh->u2.nStartPage;
353 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
356 /******************************************************************************
357 * PROPSHEET_CollectSheetInfoW
359 * Collect relevant data.
361 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
362 PropSheetInfo * psInfo)
364 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
365 DWORD dwFlags = lppsh->dwFlags;
367 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
369 memcpy(&psInfo->ppshheader,lppsh,dwSize);
370 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
371 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
373 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
374 psInfo->ppshheader.pszCaption = NULL;
375 else
377 if (!IS_INTRESOURCE(lppsh->pszCaption))
379 int len = strlenW(lppsh->pszCaption);
380 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
382 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
385 psInfo->nPages = lppsh->nPages;
387 if (dwFlags & PSH_USEPSTARTPAGE)
389 TRACE("PSH_USEPSTARTPAGE is on\n");
390 psInfo->active_page = 0;
392 else
393 psInfo->active_page = lppsh->u2.nStartPage;
395 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
398 /******************************************************************************
399 * PROPSHEET_CollectPageInfo
401 * Collect property sheet data.
402 * With code taken from DIALOG_ParseTemplate32.
404 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
405 PropSheetInfo * psInfo,
406 int index, BOOL resize)
408 const DLGTEMPLATE* pTemplate;
409 const WORD* p;
410 DWORD dwFlags;
411 int width, height;
413 if (!lppsp)
414 return FALSE;
416 TRACE("\n");
417 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
418 psInfo->proppage[index].hwndPage = 0;
419 psInfo->proppage[index].isDirty = FALSE;
422 * Process property page flags.
424 dwFlags = lppsp->dwFlags;
425 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
426 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
427 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
429 /* as soon as we have a page with the help flag, set the sheet flag on */
430 if (psInfo->proppage[index].hasHelp)
431 psInfo->hasHelp = TRUE;
434 * Process page template.
436 if (dwFlags & PSP_DLGINDIRECT)
437 pTemplate = lppsp->u.pResource;
438 else if(dwFlags & PSP_INTERNAL_UNICODE )
440 HRSRC hResource = FindResourceW(lppsp->hInstance,
441 lppsp->u.pszTemplate,
442 (LPWSTR)RT_DIALOG);
443 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
444 hResource);
445 pTemplate = LockResource(hTemplate);
447 else
449 HRSRC hResource = FindResourceA(lppsp->hInstance,
450 (LPCSTR)lppsp->u.pszTemplate,
451 (LPSTR)RT_DIALOG);
452 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
453 hResource);
454 pTemplate = LockResource(hTemplate);
458 * Extract the size of the page and the caption.
460 if (!pTemplate)
461 return FALSE;
463 p = (const WORD *)pTemplate;
465 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
467 /* DLGTEMPLATEEX (not defined in any std. header file) */
469 p++; /* dlgVer */
470 p++; /* signature */
471 p += 2; /* help ID */
472 p += 2; /* ext style */
473 p += 2; /* style */
475 else
477 /* DLGTEMPLATE */
479 p += 2; /* style */
480 p += 2; /* ext style */
483 p++; /* nb items */
484 p++; /* x */
485 p++; /* y */
486 width = (WORD)*p; p++;
487 height = (WORD)*p; p++;
489 /* Special calculation for interior wizard pages so the largest page is
490 * calculated correctly. We need to add all the padding and space occupied
491 * by the header so the width and height sums up to the whole wizard client
492 * area. */
493 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
494 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
495 !(dwFlags & PSP_HIDEHEADER))
497 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
498 width += 2 * WIZARD_PADDING;
500 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
502 height += 2 * WIZARD_PADDING;
503 width += 2 * WIZARD_PADDING;
506 /* remember the largest width and height */
507 if (resize)
509 if (width > psInfo->width)
510 psInfo->width = width;
512 if (height > psInfo->height)
513 psInfo->height = height;
516 /* menu */
517 switch ((WORD)*p)
519 case 0x0000:
520 p++;
521 break;
522 case 0xffff:
523 p += 2;
524 break;
525 default:
526 p += lstrlenW( p ) + 1;
527 break;
530 /* class */
531 switch ((WORD)*p)
533 case 0x0000:
534 p++;
535 break;
536 case 0xffff:
537 p += 2;
538 break;
539 default:
540 p += lstrlenW( p ) + 1;
541 break;
544 /* Extract the caption */
545 psInfo->proppage[index].pszText = p;
546 TRACE("Tab %d %s\n",index,debugstr_w( p ));
548 if (dwFlags & PSP_USETITLE)
550 WCHAR szTitle[256];
551 const WCHAR *pTitle;
552 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
553 WCHAR *text;
554 int len;
556 if (IS_INTRESOURCE( lppsp->pszTitle ))
558 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle)/sizeof(szTitle[0]) ))
560 pTitle = pszNull;
561 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
563 else
564 pTitle = szTitle;
566 else
567 pTitle = lppsp->pszTitle;
569 len = strlenW(pTitle);
570 text = Alloc( (len+1)*sizeof (WCHAR) );
571 psInfo->proppage[index].pszText = strcpyW( text, pTitle);
575 * Build the image list for icons
577 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
579 HICON hIcon;
580 int icon_cx = GetSystemMetrics(SM_CXSMICON);
581 int icon_cy = GetSystemMetrics(SM_CYSMICON);
583 if (dwFlags & PSP_USEICONID)
584 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
585 icon_cx, icon_cy, LR_DEFAULTCOLOR);
586 else
587 hIcon = lppsp->u2.hIcon;
589 if ( hIcon )
591 if (psInfo->hImageList == 0 )
592 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
594 ImageList_AddIcon(psInfo->hImageList, hIcon);
599 return TRUE;
602 /******************************************************************************
603 * PROPSHEET_CreateDialog
605 * Creates the actual property sheet.
607 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
609 LRESULT ret;
610 LPCVOID template;
611 LPVOID temp = 0;
612 HRSRC hRes;
613 DWORD resSize;
614 WORD resID = IDD_PROPSHEET;
616 TRACE("(%p)\n", psInfo);
617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
618 resID = IDD_WIZARD;
620 if( psInfo->unicode )
622 if(!(hRes = FindResourceW(COMCTL32_hModule,
623 MAKEINTRESOURCEW(resID),
624 (LPWSTR)RT_DIALOG)))
625 return -1;
627 else
629 if(!(hRes = FindResourceA(COMCTL32_hModule,
630 MAKEINTRESOURCEA(resID),
631 (LPSTR)RT_DIALOG)))
632 return -1;
635 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
636 return -1;
639 * Make a copy of the dialog template.
641 resSize = SizeofResource(COMCTL32_hModule, hRes);
643 temp = Alloc(resSize);
645 if (!temp)
646 return -1;
648 memcpy(temp, template, resSize);
650 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
654 else
655 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
657 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
658 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
660 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
661 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
662 else
663 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
666 if (psInfo->useCallback)
667 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
669 /* NOTE: MSDN states "Returns a positive value if successful, or -1
670 * otherwise for modal property sheets.", but this is wrong. The
671 * actual return value is either TRUE (success), FALSE (cancel) or
672 * -1 (error). */
673 if( psInfo->unicode )
675 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
676 temp, psInfo->ppshheader.hwndParent,
677 PROPSHEET_DialogProc, (LPARAM)psInfo);
678 if ( !ret ) ret = -1;
680 else
682 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
683 temp, psInfo->ppshheader.hwndParent,
684 PROPSHEET_DialogProc, (LPARAM)psInfo);
685 if ( !ret ) ret = -1;
688 Free(temp);
690 return ret;
693 /******************************************************************************
694 * PROPSHEET_SizeMismatch
696 * Verify that the tab control and the "largest" property sheet page dlg. template
697 * match in size.
699 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
701 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
702 RECT rcOrigTab, rcPage;
705 * Original tab size.
707 GetClientRect(hwndTabCtrl, &rcOrigTab);
708 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
711 * Biggest page size.
713 rcPage.left = 0;
714 rcPage.top = 0;
715 rcPage.right = psInfo->width;
716 rcPage.bottom = psInfo->height;
718 MapDialogRect(hwndDlg, &rcPage);
719 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
721 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
722 return TRUE;
723 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
724 return TRUE;
726 return FALSE;
729 /******************************************************************************
730 * PROPSHEET_AdjustSize
732 * Resizes the property sheet and the tab control to fit the largest page.
734 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
736 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
737 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
738 RECT rc,tabRect;
739 int buttonHeight;
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
741 RECT units;
742 LONG style;
744 /* Get the height of buttons */
745 GetClientRect(hwndButton, &rc);
746 buttonHeight = rc.bottom;
749 * Biggest page size.
751 rc.left = 0;
752 rc.top = 0;
753 rc.right = psInfo->width;
754 rc.bottom = psInfo->height;
756 MapDialogRect(hwndDlg, &rc);
758 /* retrieve the dialog units */
759 units.left = units.right = 4;
760 units.top = units.bottom = 8;
761 MapDialogRect(hwndDlg, &units);
764 * Resize the tab control.
766 GetClientRect(hwndTabCtrl,&tabRect);
768 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
770 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
772 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
773 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
776 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
778 rc.right = rc.left + tabRect.right - tabRect.left;
779 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
782 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
784 rc.right -= rc.left;
785 rc.bottom -= rc.top;
786 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
787 hwndTabCtrl, rc.right, rc.bottom);
788 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
789 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
791 GetClientRect(hwndTabCtrl, &rc);
793 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
795 rc.right += (padding.x * 2);
796 rc.bottom += buttonHeight + (3 * padding.y);
798 style = GetWindowLongW(hwndDlg, GWL_STYLE);
799 if (!(style & WS_CHILD))
800 AdjustWindowRect(&rc, style, FALSE);
802 rc.right -= rc.left;
803 rc.bottom -= rc.top;
806 * Resize the property sheet.
808 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
809 hwndDlg, rc.right, rc.bottom);
810 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
811 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
812 return TRUE;
815 /******************************************************************************
816 * PROPSHEET_AdjustSizeWizard
818 * Resizes the property sheet to fit the largest page.
820 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
822 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
823 RECT rc, lineRect, dialogRect;
825 /* Biggest page size */
826 rc.left = 0;
827 rc.top = 0;
828 rc.right = psInfo->width;
829 rc.bottom = psInfo->height;
830 MapDialogRect(hwndDlg, &rc);
832 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
834 /* Add space for the buttons row */
835 GetWindowRect(hwndLine, &lineRect);
836 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
837 GetClientRect(hwndDlg, &dialogRect);
838 rc.bottom += dialogRect.bottom - lineRect.top - 1;
840 /* Convert the client coordinates to window coordinates */
841 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
843 /* Resize the property sheet */
844 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
845 hwndDlg, rc.right, rc.bottom);
846 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
847 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
849 return TRUE;
852 /******************************************************************************
853 * PROPSHEET_AdjustButtons
855 * Adjusts the buttons' positions.
857 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
859 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
860 RECT rcSheet;
861 int x, y;
862 int num_buttons = 2;
863 int buttonWidth, buttonHeight;
864 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
866 if (psInfo->hasApply)
867 num_buttons++;
869 if (psInfo->hasHelp)
870 num_buttons++;
873 * Obtain the size of the buttons.
875 GetClientRect(hwndButton, &rcSheet);
876 buttonWidth = rcSheet.right;
877 buttonHeight = rcSheet.bottom;
880 * Get the size of the property sheet.
882 GetClientRect(hwndParent, &rcSheet);
885 * All buttons will be at this y coordinate.
887 y = rcSheet.bottom - (padding.y + buttonHeight);
890 * Position OK button and make it default.
892 hwndButton = GetDlgItem(hwndParent, IDOK);
894 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
896 SetWindowPos(hwndButton, 0, x, y, 0, 0,
897 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
899 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
903 * Position Cancel button.
905 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
907 x += padding.x + buttonWidth;
909 SetWindowPos(hwndButton, 0, x, y, 0, 0,
910 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
913 * Position Apply button.
915 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
917 if(psInfo->hasApply)
918 x += padding.x + buttonWidth;
919 else
920 ShowWindow(hwndButton, SW_HIDE);
922 SetWindowPos(hwndButton, 0, x, y, 0, 0,
923 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
924 EnableWindow(hwndButton, FALSE);
927 * Position Help button.
929 hwndButton = GetDlgItem(hwndParent, IDHELP);
931 x += padding.x + buttonWidth;
932 SetWindowPos(hwndButton, 0, x, y, 0, 0,
933 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
935 if(!psInfo->hasHelp)
936 ShowWindow(hwndButton, SW_HIDE);
938 return TRUE;
941 /******************************************************************************
942 * PROPSHEET_AdjustButtonsWizard
944 * Adjusts the buttons' positions.
946 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
947 const PropSheetInfo* psInfo)
949 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
950 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
951 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
952 RECT rcSheet;
953 int x, y;
954 int num_buttons = 3;
955 int buttonWidth, buttonHeight, lineHeight, lineWidth;
956 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
958 if (psInfo->hasHelp)
959 num_buttons++;
960 if (psInfo->hasFinish)
961 num_buttons++;
964 * Obtain the size of the buttons.
966 GetClientRect(hwndButton, &rcSheet);
967 buttonWidth = rcSheet.right;
968 buttonHeight = rcSheet.bottom;
970 GetClientRect(hwndLine, &rcSheet);
971 lineHeight = rcSheet.bottom;
974 * Get the size of the property sheet.
976 GetClientRect(hwndParent, &rcSheet);
979 * All buttons will be at this y coordinate.
981 y = rcSheet.bottom - (padding.y + buttonHeight);
984 * Position the Back button.
986 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
988 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
994 * Position the Next button.
996 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
998 x += buttonWidth;
1000 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1001 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1004 * Position the Finish button.
1006 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1008 if (psInfo->hasFinish)
1009 x += padding.x + buttonWidth;
1011 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1012 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1014 if (!psInfo->hasFinish)
1015 ShowWindow(hwndButton, SW_HIDE);
1018 * Position the Cancel button.
1020 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1022 x += padding.x + buttonWidth;
1024 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1025 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1028 * Position Help button.
1030 hwndButton = GetDlgItem(hwndParent, IDHELP);
1032 if (psInfo->hasHelp)
1034 x += padding.x + buttonWidth;
1036 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1037 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1039 else
1040 ShowWindow(hwndButton, SW_HIDE);
1042 if (psInfo->ppshheader.dwFlags &
1043 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1044 padding.x = 0;
1047 * Position and resize the sunken line.
1049 x = padding.x;
1050 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1052 lineWidth = rcSheet.right - (padding.x * 2);
1053 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1054 SWP_NOZORDER | SWP_NOACTIVATE);
1057 * Position and resize the header sunken line.
1060 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1061 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1062 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1063 ShowWindow(hwndLineHeader, SW_HIDE);
1065 return TRUE;
1068 /******************************************************************************
1069 * PROPSHEET_GetPaddingInfo
1071 * Returns the layout information.
1073 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1075 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1076 RECT rcTab;
1077 PADDING_INFO padding;
1079 GetWindowRect(hwndTab, &rcTab);
1080 MapWindowPoints( 0, hwndDlg, (POINT *)&rcTab, 2 );
1082 padding.x = rcTab.left;
1083 padding.y = rcTab.top;
1085 return padding;
1088 /******************************************************************************
1089 * PROPSHEET_GetPaddingInfoWizard
1091 * Returns the layout information.
1092 * Vertical spacing is the distance between the line and the buttons.
1093 * Do NOT use the Help button to gather padding information when it isn't mapped
1094 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1095 * for it in this case !
1096 * FIXME: I'm not sure about any other coordinate problems with these evil
1097 * buttons. Fix it in case additional problems appear or maybe calculate
1098 * a padding in a completely different way, as this is somewhat messy.
1100 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1101 psInfo)
1103 PADDING_INFO padding;
1104 RECT rc;
1105 HWND hwndControl;
1106 INT idButton;
1107 POINT ptButton, ptLine;
1109 TRACE("\n");
1110 if (psInfo->hasHelp)
1112 idButton = IDHELP;
1114 else
1116 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1118 idButton = IDC_NEXT_BUTTON;
1120 else
1122 /* hopefully this is ok */
1123 idButton = IDCANCEL;
1127 hwndControl = GetDlgItem(hwndDlg, idButton);
1128 GetWindowRect(hwndControl, &rc);
1129 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1130 ptButton.x = rc.left;
1131 ptButton.y = rc.top;
1133 /* Line */
1134 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1135 GetWindowRect(hwndControl, &rc);
1136 MapWindowPoints( 0, hwndDlg, (POINT *)&rc, 2 );
1137 ptLine.x = rc.left;
1138 ptLine.y = rc.bottom;
1140 padding.y = ptButton.y - ptLine.y;
1142 if (padding.y < 0)
1143 ERR("padding negative ! Please report this !\n");
1145 /* this is most probably not correct, but the best we have now */
1146 padding.x = padding.y;
1147 return padding;
1150 /******************************************************************************
1151 * PROPSHEET_CreateTabControl
1153 * Insert the tabs in the tab control.
1155 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1156 const PropSheetInfo * psInfo)
1158 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1159 TCITEMW item;
1160 int i, nTabs;
1161 int iImage = 0;
1163 TRACE("\n");
1164 item.mask = TCIF_TEXT;
1165 item.cchTextMax = MAX_TABTEXT_LENGTH;
1167 nTabs = psInfo->nPages;
1170 * Set the image list for icons.
1172 if (psInfo->hImageList)
1174 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1177 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 0, 0);
1178 for (i = 0; i < nTabs; i++)
1180 if ( psInfo->proppage[i].hasIcon )
1182 item.mask |= TCIF_IMAGE;
1183 item.iImage = iImage++;
1185 else
1187 item.mask &= ~TCIF_IMAGE;
1190 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1191 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1193 SendMessageW(hwndTabCtrl, WM_SETREDRAW, 1, 0);
1195 return TRUE;
1198 /******************************************************************************
1199 * PROPSHEET_WizardSubclassProc
1201 * Subclassing window procedure for wizard exterior pages to prevent drawing
1202 * background and so drawing above the watermark.
1204 static LRESULT CALLBACK
1205 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1207 switch (uMsg)
1209 case WM_ERASEBKGND:
1210 return TRUE;
1212 case WM_CTLCOLORSTATIC:
1213 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1214 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1217 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1221 * Get the size of an in-memory Template
1223 *( Based on the code of PROPSHEET_CollectPageInfo)
1224 * See also dialog.c/DIALOG_ParseTemplate32().
1227 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1230 const WORD* p = (const WORD *)pTemplate;
1231 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1232 WORD nrofitems;
1233 UINT ret;
1235 if (istemplateex)
1237 /* DLGTEMPLATEEX (not defined in any std. header file) */
1239 TRACE("is DLGTEMPLATEEX\n");
1240 p++; /* dlgVer */
1241 p++; /* signature */
1242 p += 2; /* help ID */
1243 p += 2; /* ext style */
1244 p += 2; /* style */
1246 else
1248 /* DLGTEMPLATE */
1250 TRACE("is DLGTEMPLATE\n");
1251 p += 2; /* style */
1252 p += 2; /* ext style */
1255 nrofitems = (WORD)*p; p++; /* nb items */
1256 p++; /* x */
1257 p++; /* y */
1258 p++; /* width */
1259 p++; /* height */
1261 /* menu */
1262 switch ((WORD)*p)
1264 case 0x0000:
1265 p++;
1266 break;
1267 case 0xffff:
1268 p += 2;
1269 break;
1270 default:
1271 TRACE("menu %s\n",debugstr_w( p ));
1272 p += lstrlenW( p ) + 1;
1273 break;
1276 /* class */
1277 switch ((WORD)*p)
1279 case 0x0000:
1280 p++;
1281 break;
1282 case 0xffff:
1283 p += 2; /* 0xffff plus predefined window class ordinal value */
1284 break;
1285 default:
1286 TRACE("class %s\n",debugstr_w( p ));
1287 p += lstrlenW( p ) + 1;
1288 break;
1291 /* title */
1292 TRACE("title %s\n",debugstr_w( p ));
1293 p += lstrlenW( p ) + 1;
1295 /* font, if DS_SETFONT set */
1296 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1297 pTemplate->style)))
1299 p+=(istemplateex)?3:1;
1300 TRACE("font %s\n",debugstr_w( p ));
1301 p += lstrlenW( p ) + 1; /* the font name */
1304 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1305 * that are following the DLGTEMPLATE(EX) data */
1306 TRACE("%d items\n",nrofitems);
1307 while (nrofitems > 0)
1309 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1311 /* skip header */
1312 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1314 /* check class */
1315 switch ((WORD)*p)
1317 case 0x0000:
1318 p++;
1319 break;
1320 case 0xffff:
1321 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1322 p += 2;
1323 break;
1324 default:
1325 TRACE("class %s\n",debugstr_w( p ));
1326 p += lstrlenW( p ) + 1;
1327 break;
1330 /* check title text */
1331 switch ((WORD)*p)
1333 case 0x0000:
1334 p++;
1335 break;
1336 case 0xffff:
1337 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1338 p += 2;
1339 break;
1340 default:
1341 TRACE("text %s\n",debugstr_w( p ));
1342 p += lstrlenW( p ) + 1;
1343 break;
1345 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1346 --nrofitems;
1349 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1350 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1351 return ret;
1354 /******************************************************************************
1355 * PROPSHEET_CreatePage
1357 * Creates a page.
1359 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1360 int index,
1361 const PropSheetInfo * psInfo,
1362 LPCPROPSHEETPAGEW ppshpage)
1364 const DLGTEMPLATE* pTemplate;
1365 HWND hwndPage;
1366 DWORD resSize;
1367 DLGTEMPLATE* pTemplateCopy = NULL;
1369 TRACE("index %d\n", index);
1371 if (ppshpage == NULL)
1373 return FALSE;
1376 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1378 pTemplate = ppshpage->u.pResource;
1379 resSize = GetTemplateSize(pTemplate);
1381 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1383 HRSRC hResource;
1384 HANDLE hTemplate;
1386 hResource = FindResourceW(ppshpage->hInstance,
1387 ppshpage->u.pszTemplate,
1388 (LPWSTR)RT_DIALOG);
1389 if(!hResource)
1390 return FALSE;
1392 resSize = SizeofResource(ppshpage->hInstance, hResource);
1394 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1395 if(!hTemplate)
1396 return FALSE;
1398 pTemplate = LockResource(hTemplate);
1400 * Make a copy of the dialog template to make it writable
1403 else
1405 HRSRC hResource;
1406 HANDLE hTemplate;
1408 hResource = FindResourceA(ppshpage->hInstance,
1409 (LPCSTR)ppshpage->u.pszTemplate,
1410 (LPSTR)RT_DIALOG);
1411 if(!hResource)
1412 return FALSE;
1414 resSize = SizeofResource(ppshpage->hInstance, hResource);
1416 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1417 if(!hTemplate)
1418 return FALSE;
1420 pTemplate = LockResource(hTemplate);
1422 * Make a copy of the dialog template to make it writable
1425 pTemplateCopy = Alloc(resSize);
1426 if (!pTemplateCopy)
1427 return FALSE;
1429 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1430 memcpy(pTemplateCopy, pTemplate, resSize);
1432 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1434 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1435 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1436 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1437 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1438 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1439 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1440 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1441 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1443 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1445 else
1447 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1448 pTemplateCopy->style &= ~DS_MODALFRAME;
1449 pTemplateCopy->style &= ~WS_CAPTION;
1450 pTemplateCopy->style &= ~WS_SYSMENU;
1451 pTemplateCopy->style &= ~WS_POPUP;
1452 pTemplateCopy->style &= ~WS_DISABLED;
1453 pTemplateCopy->style &= ~WS_VISIBLE;
1454 pTemplateCopy->style &= ~WS_THICKFRAME;
1456 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1459 if (psInfo->proppage[index].useCallback)
1460 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1461 (LPPROPSHEETPAGEW)ppshpage);
1463 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1464 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1465 pTemplateCopy,
1466 hwndParent,
1467 ppshpage->pfnDlgProc,
1468 (LPARAM)ppshpage);
1469 else
1470 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1471 pTemplateCopy,
1472 hwndParent,
1473 ppshpage->pfnDlgProc,
1474 (LPARAM)ppshpage);
1475 /* Free a no more needed copy */
1476 Free(pTemplateCopy);
1478 if(!hwndPage)
1479 return FALSE;
1481 psInfo->proppage[index].hwndPage = hwndPage;
1483 /* Subclass exterior wizard pages */
1484 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1485 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1486 (ppshpage->dwFlags & PSP_HIDEHEADER))
1488 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1489 (DWORD_PTR)ppshpage);
1491 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1492 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1494 return TRUE;
1497 /******************************************************************************
1498 * PROPSHEET_LoadWizardBitmaps
1500 * Loads the watermark and header bitmaps for a wizard.
1502 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1504 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1506 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1507 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1508 considers hbmWatermark as valid. */
1509 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1510 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1512 psInfo->ppshheader.u4.hbmWatermark =
1513 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1516 /* Same behavior as for watermarks */
1517 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1518 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1520 psInfo->ppshheader.u5.hbmHeader =
1521 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1527 /******************************************************************************
1528 * PROPSHEET_ShowPage
1530 * Displays or creates the specified page.
1532 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1534 HWND hwndTabCtrl;
1535 HWND hwndLineHeader;
1536 HWND control;
1537 LPCPROPSHEETPAGEW ppshpage;
1539 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1540 if (index == psInfo->active_page)
1542 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1543 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1544 return TRUE;
1547 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1548 if (psInfo->proppage[index].hwndPage == 0)
1550 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1553 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1555 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1556 psInfo->proppage[index].pszText);
1558 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1559 if(control != NULL)
1560 SetFocus(control);
1563 if (psInfo->active_page != -1)
1564 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1566 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1568 /* Synchronize current selection with tab control
1569 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1570 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1571 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1573 psInfo->active_page = index;
1574 psInfo->activeValid = TRUE;
1576 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1578 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1579 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1581 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1582 ShowWindow(hwndLineHeader, SW_HIDE);
1583 else
1584 ShowWindow(hwndLineHeader, SW_SHOW);
1587 return TRUE;
1590 /******************************************************************************
1591 * PROPSHEET_Back
1593 static BOOL PROPSHEET_Back(HWND hwndDlg)
1595 PSHNOTIFY psn;
1596 HWND hwndPage;
1597 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1598 LRESULT result;
1599 int idx;
1601 TRACE("active_page %d\n", psInfo->active_page);
1602 if (psInfo->active_page < 0)
1603 return FALSE;
1605 psn.hdr.code = PSN_WIZBACK;
1606 psn.hdr.hwndFrom = hwndDlg;
1607 psn.hdr.idFrom = 0;
1608 psn.lParam = 0;
1610 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1612 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1613 if (result == -1)
1614 return FALSE;
1615 else if (result == 0)
1616 idx = psInfo->active_page - 1;
1617 else
1618 idx = PROPSHEET_FindPageByResId(psInfo, result);
1620 if (idx >= 0 && idx < psInfo->nPages)
1622 if (PROPSHEET_CanSetCurSel(hwndDlg))
1624 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1625 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1626 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1629 return TRUE;
1632 /******************************************************************************
1633 * PROPSHEET_Next
1635 static BOOL PROPSHEET_Next(HWND hwndDlg)
1637 PSHNOTIFY psn;
1638 HWND hwndPage;
1639 LRESULT msgResult = 0;
1640 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1641 int idx;
1643 TRACE("active_page %d\n", psInfo->active_page);
1644 if (psInfo->active_page < 0)
1645 return FALSE;
1647 psn.hdr.code = PSN_WIZNEXT;
1648 psn.hdr.hwndFrom = hwndDlg;
1649 psn.hdr.idFrom = 0;
1650 psn.lParam = 0;
1652 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1654 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1655 if (msgResult == -1)
1656 return FALSE;
1657 else if (msgResult == 0)
1658 idx = psInfo->active_page + 1;
1659 else
1660 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1662 if (idx < psInfo->nPages )
1664 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1666 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1667 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1668 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1672 return TRUE;
1675 /******************************************************************************
1676 * PROPSHEET_Finish
1678 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1680 PSHNOTIFY psn;
1681 HWND hwndPage;
1682 LRESULT msgResult = 0;
1683 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1685 TRACE("active_page %d\n", psInfo->active_page);
1686 if (psInfo->active_page < 0)
1687 return FALSE;
1689 psn.hdr.code = PSN_WIZFINISH;
1690 psn.hdr.hwndFrom = hwndDlg;
1691 psn.hdr.idFrom = 0;
1692 psn.lParam = 0;
1694 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1696 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1698 TRACE("msg result %ld\n", msgResult);
1700 if (msgResult != 0)
1701 return FALSE;
1703 if (psInfo->result == 0)
1704 psInfo->result = IDOK;
1705 if (psInfo->isModeless)
1706 psInfo->activeValid = FALSE;
1707 else
1708 psInfo->ended = TRUE;
1710 return TRUE;
1713 /******************************************************************************
1714 * PROPSHEET_Apply
1716 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1718 int i;
1719 HWND hwndPage;
1720 PSHNOTIFY psn;
1721 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1723 TRACE("active_page %d\n", psInfo->active_page);
1724 if (psInfo->active_page < 0)
1725 return FALSE;
1727 psn.hdr.hwndFrom = hwndDlg;
1728 psn.hdr.idFrom = 0;
1729 psn.lParam = 0;
1733 * Send PSN_KILLACTIVE to the current page.
1735 psn.hdr.code = PSN_KILLACTIVE;
1737 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1739 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1740 return FALSE;
1743 * Send PSN_APPLY to all pages.
1745 psn.hdr.code = PSN_APPLY;
1746 psn.lParam = lParam;
1748 for (i = 0; i < psInfo->nPages; i++)
1750 hwndPage = psInfo->proppage[i].hwndPage;
1751 if (hwndPage)
1753 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1755 case PSNRET_INVALID:
1756 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1757 /* fall through */
1758 case PSNRET_INVALID_NOCHANGEPAGE:
1759 return FALSE;
1764 if(lParam)
1766 psInfo->activeValid = FALSE;
1768 else if(psInfo->active_page >= 0)
1770 psn.hdr.code = PSN_SETACTIVE;
1771 psn.lParam = 0;
1772 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1773 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1776 return TRUE;
1779 /******************************************************************************
1780 * PROPSHEET_Cancel
1782 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1784 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1785 HWND hwndPage;
1786 PSHNOTIFY psn;
1787 int i;
1789 TRACE("active_page %d\n", psInfo->active_page);
1790 if (psInfo->active_page < 0)
1791 return;
1793 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1794 psn.hdr.code = PSN_QUERYCANCEL;
1795 psn.hdr.hwndFrom = hwndDlg;
1796 psn.hdr.idFrom = 0;
1797 psn.lParam = 0;
1799 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1800 return;
1802 psn.hdr.code = PSN_RESET;
1803 psn.lParam = lParam;
1805 for (i = 0; i < psInfo->nPages; i++)
1807 hwndPage = psInfo->proppage[i].hwndPage;
1809 if (hwndPage)
1810 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1813 if (psInfo->isModeless)
1815 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1816 psInfo->activeValid = FALSE;
1818 else
1819 psInfo->ended = TRUE;
1822 /******************************************************************************
1823 * PROPSHEET_Help
1825 static void PROPSHEET_Help(HWND hwndDlg)
1827 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1828 HWND hwndPage;
1829 PSHNOTIFY psn;
1831 TRACE("active_page %d\n", psInfo->active_page);
1832 if (psInfo->active_page < 0)
1833 return;
1835 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1836 psn.hdr.code = PSN_HELP;
1837 psn.hdr.hwndFrom = hwndDlg;
1838 psn.hdr.idFrom = 0;
1839 psn.lParam = 0;
1841 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1844 /******************************************************************************
1845 * PROPSHEET_Changed
1847 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1849 int i;
1850 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1852 TRACE("\n");
1853 if (!psInfo) return;
1855 * Set the dirty flag of this page.
1857 for (i = 0; i < psInfo->nPages; i++)
1859 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1860 psInfo->proppage[i].isDirty = TRUE;
1864 * Enable the Apply button.
1866 if (psInfo->hasApply)
1868 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1870 EnableWindow(hwndApplyBtn, TRUE);
1874 /******************************************************************************
1875 * PROPSHEET_UnChanged
1877 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1879 int i;
1880 BOOL noPageDirty = TRUE;
1881 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1882 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1884 TRACE("\n");
1885 if ( !psInfo ) return;
1886 for (i = 0; i < psInfo->nPages; i++)
1888 /* set the specified page as clean */
1889 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1890 psInfo->proppage[i].isDirty = FALSE;
1892 /* look to see if there's any dirty pages */
1893 if (psInfo->proppage[i].isDirty)
1894 noPageDirty = FALSE;
1898 * Disable Apply button.
1900 if (noPageDirty)
1901 EnableWindow(hwndApplyBtn, FALSE);
1904 /******************************************************************************
1905 * PROPSHEET_PressButton
1907 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1909 TRACE("buttonID %d\n", buttonID);
1910 switch (buttonID)
1912 case PSBTN_APPLYNOW:
1913 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1914 break;
1915 case PSBTN_BACK:
1916 PROPSHEET_Back(hwndDlg);
1917 break;
1918 case PSBTN_CANCEL:
1919 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1920 break;
1921 case PSBTN_FINISH:
1922 PROPSHEET_Finish(hwndDlg);
1923 break;
1924 case PSBTN_HELP:
1925 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1926 break;
1927 case PSBTN_NEXT:
1928 PROPSHEET_Next(hwndDlg);
1929 break;
1930 case PSBTN_OK:
1931 PROPSHEET_DoCommand(hwndDlg, IDOK);
1932 break;
1933 default:
1934 FIXME("Invalid button index %d\n", buttonID);
1939 /*************************************************************************
1940 * BOOL PROPSHEET_CanSetCurSel [Internal]
1942 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1944 * PARAMS
1945 * hwndDlg [I] handle to a Dialog hWnd
1947 * RETURNS
1948 * TRUE if Current Selection can change
1950 * NOTES
1952 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1954 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1955 HWND hwndPage;
1956 PSHNOTIFY psn;
1957 BOOL res = FALSE;
1959 if (!psInfo)
1961 res = FALSE;
1962 goto end;
1965 TRACE("active_page %d\n", psInfo->active_page);
1966 if (psInfo->active_page < 0)
1968 res = TRUE;
1969 goto end;
1973 * Notify the current page.
1975 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1976 psn.hdr.code = PSN_KILLACTIVE;
1977 psn.hdr.hwndFrom = hwndDlg;
1978 psn.hdr.idFrom = 0;
1979 psn.lParam = 0;
1981 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1983 end:
1984 TRACE("<-- %d\n", res);
1985 return res;
1988 /******************************************************************************
1989 * PROPSHEET_SetCurSel
1991 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1992 int index,
1993 int skipdir,
1994 HPROPSHEETPAGE hpage
1997 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1998 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1999 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2001 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2002 /* hpage takes precedence over index */
2003 if (hpage != NULL)
2004 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2006 if (index < 0 || index >= psInfo->nPages)
2008 TRACE("Could not find page to select!\n");
2009 return FALSE;
2012 /* unset active page while doing this transition. */
2013 if (psInfo->active_page != -1)
2014 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2015 psInfo->active_page = -1;
2017 while (1) {
2018 int result;
2019 PSHNOTIFY psn;
2020 RECT rc;
2021 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2023 if (hwndTabControl)
2024 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2026 psn.hdr.code = PSN_SETACTIVE;
2027 psn.hdr.hwndFrom = hwndDlg;
2028 psn.hdr.idFrom = 0;
2029 psn.lParam = 0;
2031 if (!psInfo->proppage[index].hwndPage) {
2032 if(!PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage)) {
2033 PROPSHEET_RemovePage(hwndDlg, index, NULL);
2034 if(index >= psInfo->nPages)
2035 index--;
2036 if(index < 0)
2037 return FALSE;
2038 continue;
2042 /* Resize the property sheet page to the fit in the Tab control
2043 * (for regular property sheets) or to fit in the client area (for
2044 * wizards).
2045 * NOTE: The resizing happens every time the page is selected and
2046 * not only when it's created (some applications depend on it). */
2047 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2048 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2049 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2050 rc.right - rc.left, rc.bottom - rc.top);
2051 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2052 rc.left, rc.top,
2053 rc.right - rc.left, rc.bottom - rc.top, 0);
2055 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2056 if (!result)
2057 break;
2058 if (result == -1) {
2059 index+=skipdir;
2060 if (index < 0) {
2061 index = 0;
2062 WARN("Tried to skip before first property sheet page!\n");
2063 break;
2065 if (index >= psInfo->nPages) {
2066 WARN("Tried to skip after last property sheet page!\n");
2067 index = psInfo->nPages-1;
2068 break;
2071 else if (result != 0)
2073 int old_index = index;
2074 index = PROPSHEET_FindPageByResId(psInfo, result);
2075 if(index >= psInfo->nPages) {
2076 index = old_index;
2077 WARN("Tried to skip to nonexistent page by res id\n");
2078 break;
2080 continue;
2084 /* Invalidate the header area */
2085 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2086 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2088 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2089 RECT r;
2091 GetClientRect(hwndLineHeader, &r);
2092 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2093 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2095 InvalidateRect(hwndDlg, &r, TRUE);
2099 * Display the new page.
2101 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2103 if (psInfo->proppage[index].hasHelp)
2104 EnableWindow(hwndHelp, TRUE);
2105 else
2106 EnableWindow(hwndHelp, FALSE);
2108 return TRUE;
2111 /******************************************************************************
2112 * PROPSHEET_SetCurSelId
2114 * Selects the page, specified by resource id.
2116 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2118 int idx;
2119 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2121 idx = PROPSHEET_FindPageByResId(psInfo, id);
2122 if (idx < psInfo->nPages )
2124 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2125 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2129 /******************************************************************************
2130 * PROPSHEET_SetTitleA
2132 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2134 if(!IS_INTRESOURCE(lpszText))
2136 WCHAR szTitle[256];
2137 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2138 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2139 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2141 else
2143 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2147 /******************************************************************************
2148 * PROPSHEET_SetTitleW
2150 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2152 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2153 WCHAR szTitle[256];
2155 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2156 if (IS_INTRESOURCE(lpszText)) {
2157 if (!LoadStringW(psInfo->ppshheader.hInstance,
2158 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2159 return;
2160 lpszText = szTitle;
2162 if (dwStyle & PSH_PROPTITLE)
2164 WCHAR* dest;
2165 int lentitle = strlenW(lpszText);
2166 int lenprop = strlenW(psInfo->strPropertiesFor);
2168 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2169 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2171 SetWindowTextW(hwndDlg, dest);
2172 Free(dest);
2174 else
2175 SetWindowTextW(hwndDlg, lpszText);
2178 /******************************************************************************
2179 * PROPSHEET_SetFinishTextA
2181 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2183 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2184 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2186 TRACE("'%s'\n", lpszText);
2187 /* Set text, show and enable the Finish button */
2188 SetWindowTextA(hwndButton, lpszText);
2189 ShowWindow(hwndButton, SW_SHOW);
2190 EnableWindow(hwndButton, TRUE);
2192 /* Make it default pushbutton */
2193 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2195 /* Hide Back button */
2196 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2197 ShowWindow(hwndButton, SW_HIDE);
2199 if (!psInfo->hasFinish)
2201 /* Hide Next button */
2202 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2203 ShowWindow(hwndButton, SW_HIDE);
2207 /******************************************************************************
2208 * PROPSHEET_SetFinishTextW
2210 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2212 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2213 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2215 TRACE("%s\n", debugstr_w(lpszText));
2216 /* Set text, show and enable the Finish button */
2217 SetWindowTextW(hwndButton, lpszText);
2218 ShowWindow(hwndButton, SW_SHOW);
2219 EnableWindow(hwndButton, TRUE);
2221 /* Make it default pushbutton */
2222 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2224 /* Hide Back button */
2225 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2226 ShowWindow(hwndButton, SW_HIDE);
2228 if (!psInfo->hasFinish)
2230 /* Hide Next button */
2231 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2232 ShowWindow(hwndButton, SW_HIDE);
2236 /******************************************************************************
2237 * PROPSHEET_QuerySiblings
2239 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2240 WPARAM wParam, LPARAM lParam)
2242 int i = 0;
2243 HWND hwndPage;
2244 LRESULT msgResult = 0;
2245 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2247 while ((i < psInfo->nPages) && (msgResult == 0))
2249 hwndPage = psInfo->proppage[i].hwndPage;
2250 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2251 i++;
2254 return msgResult;
2258 /******************************************************************************
2259 * PROPSHEET_AddPage
2261 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2262 HPROPSHEETPAGE hpage)
2264 PropPageInfo * ppi;
2265 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2266 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2267 TCITEMW item;
2268 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2270 TRACE("hpage %p\n", hpage);
2272 * Allocate and fill in a new PropPageInfo entry.
2274 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2275 if (!ppi)
2276 return FALSE;
2278 psInfo->proppage = ppi;
2279 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2280 return FALSE;
2282 psInfo->proppage[psInfo->nPages].hpage = hpage;
2284 if (ppsp->dwFlags & PSP_PREMATURE)
2286 /* Create the page but don't show it */
2287 if(!PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp))
2288 return FALSE;
2292 * Add a new tab to the tab control.
2294 item.mask = TCIF_TEXT;
2295 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2296 item.cchTextMax = MAX_TABTEXT_LENGTH;
2298 if (psInfo->hImageList)
2300 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2303 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2305 item.mask |= TCIF_IMAGE;
2306 item.iImage = psInfo->nPages;
2309 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2310 (LPARAM)&item);
2312 psInfo->nPages++;
2314 /* If it is the only page - show it */
2315 if(psInfo->nPages == 1)
2316 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2317 return TRUE;
2320 /******************************************************************************
2321 * PROPSHEET_RemovePage
2323 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2324 int index,
2325 HPROPSHEETPAGE hpage)
2327 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2328 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2329 PropPageInfo* oldPages;
2331 TRACE("index %d, hpage %p\n", index, hpage);
2332 if (!psInfo) {
2333 return FALSE;
2336 * hpage takes precedence over index.
2338 if (hpage != 0)
2340 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2343 /* Make sure that index is within range */
2344 if (index < 0 || index >= psInfo->nPages)
2346 TRACE("Could not find page to remove!\n");
2347 return FALSE;
2350 TRACE("total pages %d removing page %d active page %d\n",
2351 psInfo->nPages, index, psInfo->active_page);
2353 * Check if we're removing the active page.
2355 if (index == psInfo->active_page)
2357 if (psInfo->nPages > 1)
2359 if (index > 0)
2361 /* activate previous page */
2362 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2364 else
2366 /* activate the next page */
2367 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2368 psInfo->active_page = index;
2371 else
2373 psInfo->active_page = -1;
2374 if (!psInfo->isModeless)
2376 psInfo->ended = TRUE;
2377 return TRUE;
2381 else if (index < psInfo->active_page)
2382 psInfo->active_page--;
2384 /* Unsubclass the page dialog window */
2385 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2386 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2387 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2389 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2390 PROPSHEET_WizardSubclassProc, 1);
2393 /* Destroy page dialog window */
2394 DestroyWindow(psInfo->proppage[index].hwndPage);
2396 /* Free page resources */
2397 if(psInfo->proppage[index].hpage)
2399 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2401 if (psp->dwFlags & PSP_USETITLE)
2402 Free ((LPVOID)psInfo->proppage[index].pszText);
2404 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2407 /* Remove the tab */
2408 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2410 oldPages = psInfo->proppage;
2411 psInfo->nPages--;
2412 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2414 if (index > 0)
2415 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2417 if (index < psInfo->nPages)
2418 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2419 (psInfo->nPages - index) * sizeof(PropPageInfo));
2421 Free(oldPages);
2423 return FALSE;
2426 /******************************************************************************
2427 * PROPSHEET_SetWizButtons
2429 * This code will work if (and assumes that) the Next button is on top of the
2430 * Finish button. ie. Finish comes after Next in the Z order.
2431 * This means make sure the dialog template reflects this.
2434 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2436 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2437 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2438 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2439 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2441 TRACE("%d\n", dwFlags);
2443 EnableWindow(hwndBack, FALSE);
2444 EnableWindow(hwndNext, FALSE);
2445 EnableWindow(hwndFinish, FALSE);
2447 /* set the default pushbutton to an enabled button */
2448 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2449 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2450 else if (dwFlags & PSWIZB_NEXT)
2451 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2452 else if (dwFlags & PSWIZB_BACK)
2453 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2454 else
2455 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2458 if (dwFlags & PSWIZB_BACK)
2459 EnableWindow(hwndBack, TRUE);
2461 if (dwFlags & PSWIZB_NEXT)
2462 EnableWindow(hwndNext, TRUE);
2464 if (!psInfo->hasFinish)
2466 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2468 /* Hide the Next button */
2469 ShowWindow(hwndNext, SW_HIDE);
2471 /* Show the Finish button */
2472 ShowWindow(hwndFinish, SW_SHOW);
2474 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2475 EnableWindow(hwndFinish, TRUE);
2477 else
2479 /* Hide the Finish button */
2480 ShowWindow(hwndFinish, SW_HIDE);
2481 /* Show the Next button */
2482 ShowWindow(hwndNext, SW_SHOW);
2485 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2486 EnableWindow(hwndFinish, TRUE);
2489 /******************************************************************************
2490 * PROPSHEET_InsertPage
2492 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2494 if (IS_INTRESOURCE(hpageInsertAfter))
2495 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2496 else
2497 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2498 return FALSE;
2501 /******************************************************************************
2502 * PROPSHEET_SetHeaderTitleW
2504 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2506 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2509 /******************************************************************************
2510 * PROPSHEET_SetHeaderTitleA
2512 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2514 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2517 /******************************************************************************
2518 * PROPSHEET_SetHeaderSubTitleW
2520 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2522 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2525 /******************************************************************************
2526 * PROPSHEET_SetHeaderSubTitleA
2528 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2530 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2533 /******************************************************************************
2534 * PROPSHEET_HwndToIndex
2536 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2538 int index;
2539 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2541 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2543 for (index = 0; index < psInfo->nPages; index++)
2544 if (psInfo->proppage[index].hwndPage == hPageDlg)
2545 return index;
2546 WARN("%p not found\n", hPageDlg);
2547 return -1;
2550 /******************************************************************************
2551 * PROPSHEET_IndexToHwnd
2553 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2555 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2556 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2557 if (!psInfo)
2558 return 0;
2559 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2560 WARN("%d out of range.\n", iPageIndex);
2561 return 0;
2563 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2566 /******************************************************************************
2567 * PROPSHEET_PageToIndex
2569 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2571 int index;
2572 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2574 TRACE("(%p, %p)\n", hwndDlg, hPage);
2576 for (index = 0; index < psInfo->nPages; index++)
2577 if (psInfo->proppage[index].hpage == hPage)
2578 return index;
2579 WARN("%p not found\n", hPage);
2580 return -1;
2583 /******************************************************************************
2584 * PROPSHEET_IndexToPage
2586 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2588 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2589 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2590 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2591 WARN("%d out of range.\n", iPageIndex);
2592 return 0;
2594 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2597 /******************************************************************************
2598 * PROPSHEET_IdToIndex
2600 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2602 int index;
2603 LPCPROPSHEETPAGEW psp;
2604 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2605 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2606 for (index = 0; index < psInfo->nPages; index++) {
2607 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2608 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2609 return index;
2612 return -1;
2615 /******************************************************************************
2616 * PROPSHEET_IndexToId
2618 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2620 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2621 LPCPROPSHEETPAGEW psp;
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 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2628 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2629 return 0;
2631 return (LRESULT)psp->u.pszTemplate;
2634 /******************************************************************************
2635 * PROPSHEET_GetResult
2637 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2639 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2640 return psInfo->result;
2643 /******************************************************************************
2644 * PROPSHEET_RecalcPageSizes
2646 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2648 FIXME("(%p): stub\n", hwndDlg);
2649 return FALSE;
2652 /******************************************************************************
2653 * PROPSHEET_GetPageIndex
2655 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2656 * the array of PropPageInfo.
2658 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2660 BOOL found = FALSE;
2661 int index = 0;
2663 TRACE("hpage %p\n", hpage);
2664 while ((index < psInfo->nPages) && (found == FALSE))
2666 if (psInfo->proppage[index].hpage == hpage)
2667 found = TRUE;
2668 else
2669 index++;
2672 if (found == FALSE)
2673 index = -1;
2675 return index;
2678 /******************************************************************************
2679 * PROPSHEET_CleanUp
2681 static void PROPSHEET_CleanUp(HWND hwndDlg)
2683 int i;
2684 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2686 TRACE("\n");
2687 if (!psInfo) return;
2688 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2689 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2691 for (i = 0; i < psInfo->nPages; i++)
2693 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2695 /* Unsubclass the page dialog window */
2696 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2697 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2698 (psp->dwFlags & PSP_HIDEHEADER))
2700 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2701 PROPSHEET_WizardSubclassProc, 1);
2704 if(psInfo->proppage[i].hwndPage)
2705 DestroyWindow(psInfo->proppage[i].hwndPage);
2707 if(psp)
2709 if (psp->dwFlags & PSP_USETITLE)
2710 Free ((LPVOID)psInfo->proppage[i].pszText);
2712 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2716 DeleteObject(psInfo->hFont);
2717 DeleteObject(psInfo->hFontBold);
2718 /* If we created the bitmaps, destroy them */
2719 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2720 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2721 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2722 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2723 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2724 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2726 Free(psInfo->proppage);
2727 Free(psInfo->strPropertiesFor);
2728 ImageList_Destroy(psInfo->hImageList);
2730 GlobalFree(psInfo);
2733 static INT do_loop(const PropSheetInfo *psInfo)
2735 MSG msg;
2736 INT ret = -1;
2737 HWND hwnd = psInfo->hwnd;
2739 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2741 if(ret == -1)
2742 break;
2744 if(!IsDialogMessageW(hwnd, &msg))
2746 TranslateMessage(&msg);
2747 DispatchMessageW(&msg);
2751 if(ret == 0)
2753 PostQuitMessage(msg.wParam);
2754 ret = -1;
2757 if(ret != -1)
2758 ret = psInfo->result;
2760 DestroyWindow(hwnd);
2761 return ret;
2764 /******************************************************************************
2765 * PROPSHEET_PropertySheet
2767 * Common code between PropertySheetA/W
2769 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2771 INT_PTR bRet = 0;
2772 HWND parent = NULL;
2773 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2774 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2776 psInfo->unicode = unicode;
2777 psInfo->ended = FALSE;
2779 if(!psInfo->isModeless)
2781 parent = psInfo->ppshheader.hwndParent;
2782 if (parent) EnableWindow(parent, FALSE);
2784 bRet = PROPSHEET_CreateDialog(psInfo);
2785 if(!psInfo->isModeless)
2787 bRet = do_loop(psInfo);
2788 if (parent) EnableWindow(parent, TRUE);
2790 return bRet;
2793 /******************************************************************************
2794 * PropertySheet (COMCTL32.@)
2795 * PropertySheetA (COMCTL32.@)
2797 * Creates a property sheet in the specified property sheet header.
2799 * RETURNS
2800 * Modal property sheets: Positive if successful or -1 otherwise.
2801 * Modeless property sheets: Property sheet handle.
2802 * Or:
2803 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2804 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2806 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2808 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2809 UINT i, n;
2810 const BYTE* pByte;
2812 TRACE("(%p)\n", lppsh);
2814 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2816 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2817 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2819 for (n = i = 0; i < lppsh->nPages; i++, n++)
2821 if (!psInfo->usePropPage)
2822 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2823 else
2825 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2826 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2829 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2830 psInfo, n, TRUE))
2832 if (psInfo->usePropPage)
2833 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2834 n--;
2835 psInfo->nPages--;
2839 return PROPSHEET_PropertySheet(psInfo, FALSE);
2842 /******************************************************************************
2843 * PropertySheetW (COMCTL32.@)
2845 * See PropertySheetA.
2847 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2849 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2850 UINT i, n;
2851 const BYTE* pByte;
2853 TRACE("(%p)\n", lppsh);
2855 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2857 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2858 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2860 for (n = i = 0; i < lppsh->nPages; i++, n++)
2862 if (!psInfo->usePropPage)
2863 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2864 else
2866 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2867 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2870 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2871 psInfo, n, TRUE))
2873 if (psInfo->usePropPage)
2874 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2875 n--;
2876 psInfo->nPages--;
2880 return PROPSHEET_PropertySheet(psInfo, TRUE);
2883 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2885 LPWSTR ret;
2887 if (IS_INTRESOURCE(str))
2889 HRSRC hrsrc;
2890 HGLOBAL hmem;
2891 WCHAR *ptr;
2892 WORD i, id = LOWORD(str);
2893 UINT len;
2895 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2896 return NULL;
2897 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2898 if (!(ptr = LockResource( hmem ))) return NULL;
2899 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2900 len = *ptr;
2901 if (!len) return NULL;
2902 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2903 if (ret)
2905 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2906 ret[len] = 0;
2909 else
2911 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2912 ret = Alloc( len );
2913 if (ret) memcpy( ret, str, len );
2915 return ret;
2919 /******************************************************************************
2920 * CreatePropertySheetPage (COMCTL32.@)
2921 * CreatePropertySheetPageA (COMCTL32.@)
2923 * Creates a new property sheet page.
2925 * RETURNS
2926 * Success: Handle to new property sheet page.
2927 * Failure: NULL.
2929 * NOTES
2930 * An application must use the PSM_ADDPAGE message to add the new page to
2931 * an existing property sheet.
2933 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2934 LPCPROPSHEETPAGEA lpPropSheetPage)
2936 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2938 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2940 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2942 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2944 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2946 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2947 char *template = Alloc( len );
2949 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2953 if (ppsp->dwFlags & PSP_USEICONID)
2955 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2956 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2959 if (ppsp->dwFlags & PSP_USETITLE)
2961 if (!IS_INTRESOURCE( ppsp->pszTitle ))
2962 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2963 else
2964 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2966 else
2967 ppsp->pszTitle = NULL;
2969 if (ppsp->dwFlags & PSP_HIDEHEADER)
2970 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2972 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2974 if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
2975 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2976 else
2977 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2979 else
2980 ppsp->pszHeaderTitle = NULL;
2982 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2984 if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
2985 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2986 else
2987 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2989 else
2990 ppsp->pszHeaderSubTitle = NULL;
2992 return (HPROPSHEETPAGE)ppsp;
2995 /******************************************************************************
2996 * CreatePropertySheetPageW (COMCTL32.@)
2998 * See CreatePropertySheetA.
3000 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3002 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3004 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3006 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3008 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3010 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3012 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3013 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3015 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3019 if ( ppsp->dwFlags & PSP_USEICONID )
3021 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3023 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3024 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3026 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3030 if (ppsp->dwFlags & PSP_USETITLE)
3031 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3032 else
3033 ppsp->pszTitle = NULL;
3035 if (ppsp->dwFlags & PSP_HIDEHEADER)
3036 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3038 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3039 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3040 else
3041 ppsp->pszHeaderTitle = NULL;
3043 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3044 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3045 else
3046 ppsp->pszHeaderSubTitle = NULL;
3048 return (HPROPSHEETPAGE)ppsp;
3051 /******************************************************************************
3052 * DestroyPropertySheetPage (COMCTL32.@)
3054 * Destroys a property sheet page previously created with
3055 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3056 * memory.
3058 * RETURNS
3059 * Success: TRUE
3060 * Failure: FALSE
3062 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3064 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3066 if (!psp)
3067 return FALSE;
3069 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3070 Free ((LPVOID)psp->u.pszTemplate);
3072 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3073 Free ((LPVOID)psp->u2.pszIcon);
3075 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3076 Free ((LPVOID)psp->pszTitle);
3078 if ((psp->dwFlags & PSP_USEHEADERTITLE) && !IS_INTRESOURCE( psp->pszHeaderTitle ))
3079 Free ((LPVOID)psp->pszHeaderTitle);
3081 if ((psp->dwFlags & PSP_USEHEADERSUBTITLE) && !IS_INTRESOURCE( psp->pszHeaderSubTitle ))
3082 Free ((LPVOID)psp->pszHeaderSubTitle);
3084 Free(hPropPage);
3086 return TRUE;
3089 /******************************************************************************
3090 * PROPSHEET_IsDialogMessage
3092 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3094 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3096 TRACE("\n");
3097 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3098 return FALSE;
3100 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3102 int new_page = 0;
3103 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3105 if (!(dlgCode & DLGC_WANTMESSAGE))
3107 switch (lpMsg->wParam)
3109 case VK_TAB:
3110 if (GetKeyState(VK_SHIFT) & 0x8000)
3111 new_page = -1;
3112 else
3113 new_page = 1;
3114 break;
3116 case VK_NEXT: new_page = 1; break;
3117 case VK_PRIOR: new_page = -1; break;
3121 if (new_page)
3123 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3125 new_page += psInfo->active_page;
3127 if (new_page < 0)
3128 new_page = psInfo->nPages - 1;
3129 else if (new_page >= psInfo->nPages)
3130 new_page = 0;
3132 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3135 return TRUE;
3139 return IsDialogMessageW(hwnd, lpMsg);
3142 /******************************************************************************
3143 * PROPSHEET_DoCommand
3145 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3148 switch (wID) {
3150 case IDOK:
3151 case IDC_APPLY_BUTTON:
3153 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3155 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3156 break;
3158 if (wID == IDOK)
3160 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3162 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3163 if (psInfo->result == 0)
3164 psInfo->result = IDOK;
3166 if (psInfo->isModeless)
3167 psInfo->activeValid = FALSE;
3168 else
3169 psInfo->ended = TRUE;
3171 else
3172 EnableWindow(hwndApplyBtn, FALSE);
3174 break;
3177 case IDC_BACK_BUTTON:
3178 PROPSHEET_Back(hwnd);
3179 break;
3181 case IDC_NEXT_BUTTON:
3182 PROPSHEET_Next(hwnd);
3183 break;
3185 case IDC_FINISH_BUTTON:
3186 PROPSHEET_Finish(hwnd);
3187 break;
3189 case IDCANCEL:
3190 PROPSHEET_Cancel(hwnd, 0);
3191 break;
3193 case IDHELP:
3194 PROPSHEET_Help(hwnd);
3195 break;
3197 default:
3198 return FALSE;
3201 return TRUE;
3204 /******************************************************************************
3205 * PROPSHEET_Paint
3207 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3209 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3210 PAINTSTRUCT ps;
3211 HDC hdc, hdcSrc;
3212 BITMAP bm;
3213 HBITMAP hbmp;
3214 HPALETTE hOldPal = 0;
3215 int offsety = 0;
3216 HBRUSH hbr;
3217 RECT r, rzone;
3218 LPCPROPSHEETPAGEW ppshpage;
3219 WCHAR szBuffer[256];
3220 int nLength;
3222 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3223 if (!hdc) return 1;
3225 hdcSrc = CreateCompatibleDC(0);
3227 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3228 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3230 if (psInfo->active_page < 0)
3231 ppshpage = NULL;
3232 else
3233 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3235 if ( (ppshpage && !(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3236 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3237 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3239 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3240 HFONT hOldFont;
3241 COLORREF clrOld = 0;
3242 int oldBkMode = 0;
3244 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3245 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3247 GetClientRect(hwndLineHeader, &r);
3248 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3249 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3251 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3253 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3255 /* Fill the unoccupied part of the header with color of the
3256 * left-top pixel, but do it only when needed.
3258 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3260 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3261 CopyRect(&r, &rzone);
3262 if (bm.bmWidth < r.right)
3264 r.left = bm.bmWidth;
3265 FillRect(hdc, &r, hbr);
3267 if (bm.bmHeight < r.bottom)
3269 r.left = 0;
3270 r.top = bm.bmHeight;
3271 FillRect(hdc, &r, hbr);
3273 DeleteObject(hbr);
3276 /* Draw the header itself. */
3277 BitBlt(hdc, 0, 0,
3278 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3279 hdcSrc, 0, 0, SRCCOPY);
3281 else
3283 int margin;
3284 hbr = GetSysColorBrush(COLOR_WINDOW);
3285 FillRect(hdc, &rzone, hbr);
3287 /* Draw the header bitmap. It's always centered like a
3288 * common 49 x 49 bitmap. */
3289 margin = (rzone.bottom - 49) / 2;
3290 BitBlt(hdc, rzone.right - 49 - margin, margin,
3291 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3292 hdcSrc, 0, 0, SRCCOPY);
3294 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3295 * if its height is smaller than 49 pixels. Because the reason
3296 * for this bug is unknown the current code doesn't try to
3297 * replicate it. */
3300 clrOld = SetTextColor (hdc, 0x00000000);
3301 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3303 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3304 SetRect(&r, 20, 10, 0, 0);
3305 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3306 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3307 else
3309 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3310 szBuffer, 256);
3311 if (nLength != 0)
3313 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3318 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3319 SelectObject(hdc, psInfo->hFont);
3320 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3321 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3322 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3323 else
3325 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3326 szBuffer, 256);
3327 if (nLength != 0)
3329 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3334 offsety = rzone.bottom + 2;
3336 SetTextColor(hdc, clrOld);
3337 SetBkMode(hdc, oldBkMode);
3338 SelectObject(hdc, hOldFont);
3339 SelectObject(hdcSrc, hbmp);
3342 if ( (ppshpage && (ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3343 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3344 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3346 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3348 GetClientRect(hwndLine, &r);
3349 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3351 rzone.left = 0;
3352 rzone.top = 0;
3353 rzone.right = r.right;
3354 rzone.bottom = r.top - 1;
3356 hbr = GetSysColorBrush(COLOR_WINDOW);
3357 FillRect(hdc, &rzone, hbr);
3359 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3360 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3362 /* The watermark is truncated to a width of 164 pixels */
3363 r.right = min(r.right, 164);
3364 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3365 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3367 /* If the bitmap is not big enough, fill the remaining area
3368 with the color of pixel (0,0) of bitmap - see MSDN */
3369 if (r.top > bm.bmHeight) {
3370 r.bottom = r.top - 1;
3371 r.top = bm.bmHeight;
3372 r.left = 0;
3373 r.right = bm.bmWidth;
3374 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3375 FillRect(hdc, &r, hbr);
3376 DeleteObject(hbr);
3379 SelectObject(hdcSrc, hbmp);
3382 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3383 SelectPalette(hdc, hOldPal, FALSE);
3385 DeleteDC(hdcSrc);
3387 if (!hdcParam) EndPaint(hwnd, &ps);
3389 return 0;
3392 /******************************************************************************
3393 * PROPSHEET_DialogProc
3395 static INT_PTR CALLBACK
3396 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3398 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3399 hwnd, uMsg, wParam, lParam);
3401 switch (uMsg)
3403 case WM_INITDIALOG:
3405 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3406 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3407 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3408 int idx;
3409 LOGFONTW logFont;
3411 /* Using PropSheetInfoStr to store extra data doesn't match the native
3412 * common control: native uses TCM_[GS]ETITEM
3414 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3417 * psInfo->hwnd is not being used by WINE code - it exists
3418 * for compatibility with "real" Windoze. The same about
3419 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3420 * property.
3422 psInfo->hwnd = hwnd;
3423 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3425 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3427 /* set up the Next and Back buttons by default */
3428 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3431 /* Set up fonts */
3432 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3433 psInfo->hFont = CreateFontIndirectW (&logFont);
3434 logFont.lfWeight = FW_BOLD;
3435 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3438 * Small icon in the title bar.
3440 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3441 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3443 HICON hIcon;
3444 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3445 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3447 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3448 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3449 psInfo->ppshheader.u.pszIcon,
3450 IMAGE_ICON,
3451 icon_cx, icon_cy,
3452 LR_DEFAULTCOLOR);
3453 else
3454 hIcon = psInfo->ppshheader.u.hIcon;
3456 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3459 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3460 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3462 psInfo->strPropertiesFor = strCaption;
3464 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3466 PROPSHEET_CreateTabControl(hwnd, psInfo);
3468 PROPSHEET_LoadWizardBitmaps(psInfo);
3470 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3472 ShowWindow(hwndTabCtrl, SW_HIDE);
3473 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3474 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3475 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3477 else
3479 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3481 PROPSHEET_AdjustSize(hwnd, psInfo);
3482 PROPSHEET_AdjustButtons(hwnd, psInfo);
3484 SetFocus(GetDlgItem(hwnd, IDOK));
3487 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3488 psInfo->ppshheader.hInstance)
3490 WCHAR szText[256];
3492 if (LoadStringW(psInfo->ppshheader.hInstance,
3493 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3494 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3496 else
3498 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3499 psInfo->ppshheader.pszCaption);
3503 if (psInfo->useCallback)
3504 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3506 idx = psInfo->active_page;
3507 psInfo->active_page = -1;
3509 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3511 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3512 * as some programs call TCM_GETCURSEL to get the current selection
3513 * from which to switch to the next page */
3514 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3516 PROPSHEET_UnChanged(hwnd, NULL);
3518 /* wizards set their focus during init */
3519 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3520 return FALSE;
3522 return TRUE;
3525 case WM_PRINTCLIENT:
3526 case WM_PAINT:
3527 PROPSHEET_Paint(hwnd, (HDC)wParam);
3528 return TRUE;
3530 case WM_DESTROY:
3531 PROPSHEET_CleanUp(hwnd);
3532 return TRUE;
3534 case WM_CLOSE:
3535 PROPSHEET_Cancel(hwnd, 1);
3536 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3538 case WM_COMMAND:
3539 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3541 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3543 if (!psInfo)
3544 return FALSE;
3546 /* No default handler, forward notification to active page */
3547 if (psInfo->activeValid && psInfo->active_page != -1)
3549 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3550 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3553 return TRUE;
3555 case WM_NOTIFY:
3557 NMHDR* pnmh = (LPNMHDR) lParam;
3559 if (pnmh->code == TCN_SELCHANGE)
3561 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3562 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3565 if(pnmh->code == TCN_SELCHANGING)
3567 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3568 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3569 return TRUE;
3572 return FALSE;
3575 case WM_SYSCOLORCHANGE:
3576 COMCTL32_RefreshSysColors();
3577 return FALSE;
3579 case PSM_GETCURRENTPAGEHWND:
3581 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3582 HWND hwndPage = 0;
3584 if (!psInfo)
3585 return FALSE;
3587 if (psInfo->activeValid && psInfo->active_page != -1)
3588 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3590 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3592 return TRUE;
3595 case PSM_CHANGED:
3596 PROPSHEET_Changed(hwnd, (HWND)wParam);
3597 return TRUE;
3599 case PSM_UNCHANGED:
3600 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3601 return TRUE;
3603 case PSM_GETTABCONTROL:
3605 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3607 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3609 return TRUE;
3612 case PSM_SETCURSEL:
3614 BOOL msgResult;
3616 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3617 if(msgResult != FALSE)
3619 msgResult = PROPSHEET_SetCurSel(hwnd,
3620 (int)wParam,
3622 (HPROPSHEETPAGE)lParam);
3625 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3627 return TRUE;
3630 case PSM_CANCELTOCLOSE:
3632 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3633 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3634 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3636 EnableWindow(hwndCancel, FALSE);
3637 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3638 SetWindowTextW(hwndOK, buf);
3640 return FALSE;
3643 case PSM_RESTARTWINDOWS:
3645 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3647 if (!psInfo)
3648 return FALSE;
3650 /* reboot system takes precedence over restart windows */
3651 if (psInfo->result != ID_PSREBOOTSYSTEM)
3652 psInfo->result = ID_PSRESTARTWINDOWS;
3654 return TRUE;
3657 case PSM_REBOOTSYSTEM:
3659 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3661 if (!psInfo)
3662 return FALSE;
3664 psInfo->result = ID_PSREBOOTSYSTEM;
3666 return TRUE;
3669 case PSM_SETTITLEA:
3670 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3671 return TRUE;
3673 case PSM_SETTITLEW:
3674 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3675 return TRUE;
3677 case PSM_APPLY:
3679 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3681 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3683 return TRUE;
3686 case PSM_QUERYSIBLINGS:
3688 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3690 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3692 return TRUE;
3695 case PSM_ADDPAGE:
3698 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3699 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3700 * on success or FALSE otherwise, as specified on MSDN Online.
3701 * Also see the MFC code for
3702 * CPropertySheet::AddPage(CPropertyPage* pPage).
3705 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3707 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3709 return TRUE;
3712 case PSM_REMOVEPAGE:
3713 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3714 return TRUE;
3716 case PSM_ISDIALOGMESSAGE:
3718 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3719 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3720 return TRUE;
3723 case PSM_PRESSBUTTON:
3724 PROPSHEET_PressButton(hwnd, (int)wParam);
3725 return TRUE;
3727 case PSM_SETFINISHTEXTA:
3728 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3729 return TRUE;
3731 case PSM_SETWIZBUTTONS:
3732 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3733 return TRUE;
3735 case PSM_SETCURSELID:
3736 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3737 return TRUE;
3739 case PSM_SETFINISHTEXTW:
3740 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3741 return FALSE;
3743 case PSM_INSERTPAGE:
3745 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3746 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3747 return TRUE;
3750 case PSM_SETHEADERTITLEW:
3751 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3752 return TRUE;
3754 case PSM_SETHEADERTITLEA:
3755 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3756 return TRUE;
3758 case PSM_SETHEADERSUBTITLEW:
3759 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3760 return TRUE;
3762 case PSM_SETHEADERSUBTITLEA:
3763 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3764 return TRUE;
3766 case PSM_HWNDTOINDEX:
3768 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3769 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3770 return TRUE;
3773 case PSM_INDEXTOHWND:
3775 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3776 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3777 return TRUE;
3780 case PSM_PAGETOINDEX:
3782 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3783 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3784 return TRUE;
3787 case PSM_INDEXTOPAGE:
3789 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3790 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3791 return TRUE;
3794 case PSM_IDTOINDEX:
3796 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3797 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3798 return TRUE;
3801 case PSM_INDEXTOID:
3803 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3804 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3805 return TRUE;
3808 case PSM_GETRESULT:
3810 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3811 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3812 return TRUE;
3815 case PSM_RECALCPAGESIZES:
3817 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3818 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3819 return TRUE;
3822 default:
3823 return FALSE;