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.
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
36 * o PSM_RECALCPAGESIZES
37 * o PSM_SETHEADERSUBTITLE
38 * o PSM_SETHEADERTITLE
43 * o PSN_QUERYINITIALFOCUS
44 * o PSN_TRANSLATEACCELERATOR
47 * o PSH_STRETCHWATERMARK
51 * o PSP_USEFUSIONCONTEXT
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
73 /******************************************************************************
97 } MyDLGITEMTEMPLATEEX;
100 typedef struct tagPropPageInfo
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
111 typedef struct tagPropSheetInfo
114 PROPSHEETHEADERW ppshheader;
116 LPWSTR strPropertiesFor;
125 PropPageInfo* proppage;
130 HIMAGELIST hImageList;
141 /******************************************************************************
142 * Defines and global variables
145 static const WCHAR PropSheetInfoStr[] =
146 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
148 #define PSP_INTERNAL_UNICODE 0x80000000
150 #define MAX_CAPTION_LENGTH 255
151 #define MAX_TABTEXT_LENGTH 255
152 #define MAX_BUTTONTEXT_LENGTH 64
154 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
156 /* Wizard metrics specified in DLUs */
157 #define WIZARD_PADDING 7
158 #define WIZARD_HEADER_HEIGHT 36
160 /******************************************************************************
163 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
164 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
165 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
166 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
169 HPROPSHEETPAGE hpage);
170 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
171 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
172 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 static INT_PTR CALLBACK
175 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
179 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
180 /******************************************************************************
181 * PROPSHEET_UnImplementedFlags
183 * Document use of flags we don't implement yet.
185 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
192 * unhandled header flags:
193 * PSH_RTLREADING 0x00000800
194 * PSH_STRETCHWATERMARK 0x00040000
195 * PSH_USEPAGELANG 0x00200000
198 add_flag(PSH_RTLREADING);
199 add_flag(PSH_STRETCHWATERMARK);
200 add_flag(PSH_USEPAGELANG);
201 if (string[0] != '\0')
202 FIXME("%s\n", string);
206 /******************************************************************************
207 * PROPSHEET_GetPageRect
209 * Retrieve rect from tab control and map into the dialog for SetWindowPos
211 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
212 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
214 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
218 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
219 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
220 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
221 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
223 rc->left = rc->top = WIZARD_PADDING;
227 rc->left = rc->top = 0;
229 rc->right = psInfo->width - rc->left;
230 rc->bottom = psInfo->height - rc->top;
231 MapDialogRect(hwndDlg, rc);
233 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
234 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
235 !(ppshpage->dwFlags & PSP_HIDEHEADER))
237 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
238 GetClientRect(hwndChild, &r);
239 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
240 rc->top += r.bottom + 1;
243 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
244 GetClientRect(hwndTabCtrl, rc);
245 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
246 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
250 /******************************************************************************
251 * PROPSHEET_FindPageByResId
253 * Find page index corresponding to page resource id.
255 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
259 for (i = 0; i < psInfo->nPages; i++)
261 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
263 /* Fixme: if resource ID is a string shall we use strcmp ??? */
264 if (lppsp->u.pszTemplate == (LPVOID)resId)
271 /******************************************************************************
274 * Convert ASCII to Unicode since all data is saved as Unicode.
276 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
280 TRACE("<%s>\n", frstr);
281 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
282 *tostr = Alloc(len * sizeof(WCHAR));
283 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
286 /******************************************************************************
287 * PROPSHEET_CollectSheetInfoA
289 * Collect relevant data.
291 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
292 PropSheetInfo * psInfo)
294 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
295 DWORD dwFlags = lppsh->dwFlags;
297 psInfo->hasHelp = dwFlags & PSH_HASHELP;
298 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
299 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
300 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
303 memcpy(&psInfo->ppshheader,lppsh,dwSize);
304 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",
305 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
306 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
308 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
310 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
311 psInfo->ppshheader.pszCaption = NULL;
314 if (HIWORD(lppsh->pszCaption))
316 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
317 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
318 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
321 psInfo->nPages = lppsh->nPages;
323 if (dwFlags & PSH_USEPSTARTPAGE)
325 TRACE("PSH_USEPSTARTPAGE is on\n");
326 psInfo->active_page = 0;
329 psInfo->active_page = lppsh->u2.nStartPage;
331 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
332 psInfo->active_page = 0;
335 psInfo->hImageList = 0;
336 psInfo->activeValid = FALSE;
341 /******************************************************************************
342 * PROPSHEET_CollectSheetInfoW
344 * Collect relevant data.
346 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
347 PropSheetInfo * psInfo)
349 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
350 DWORD dwFlags = lppsh->dwFlags;
352 psInfo->hasHelp = dwFlags & PSH_HASHELP;
353 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
354 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
355 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
356 psInfo->isModeless = dwFlags & PSH_MODELESS;
358 memcpy(&psInfo->ppshheader,lppsh,dwSize);
359 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",
360 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
362 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
364 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
365 psInfo->ppshheader.pszCaption = NULL;
368 if (HIWORD(lppsh->pszCaption))
370 int len = strlenW(lppsh->pszCaption);
371 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
372 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
375 psInfo->nPages = lppsh->nPages;
377 if (dwFlags & PSH_USEPSTARTPAGE)
379 TRACE("PSH_USEPSTARTPAGE is on\n");
380 psInfo->active_page = 0;
383 psInfo->active_page = lppsh->u2.nStartPage;
385 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
386 psInfo->active_page = 0;
389 psInfo->hImageList = 0;
390 psInfo->activeValid = FALSE;
395 /******************************************************************************
396 * PROPSHEET_CollectPageInfo
398 * Collect property sheet data.
399 * With code taken from DIALOG_ParseTemplate32.
401 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
402 PropSheetInfo * psInfo,
405 DLGTEMPLATE* pTemplate;
414 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
415 psInfo->proppage[index].hwndPage = 0;
416 psInfo->proppage[index].isDirty = FALSE;
419 * Process property page flags.
421 dwFlags = lppsp->dwFlags;
422 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
423 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
424 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
426 /* as soon as we have a page with the help flag, set the sheet flag on */
427 if (psInfo->proppage[index].hasHelp)
428 psInfo->hasHelp = TRUE;
431 * Process page template.
433 if (dwFlags & PSP_DLGINDIRECT)
434 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
435 else if(dwFlags & PSP_INTERNAL_UNICODE )
437 HRSRC hResource = FindResourceW(lppsp->hInstance,
438 lppsp->u.pszTemplate,
440 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
442 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
446 HRSRC hResource = FindResourceA(lppsp->hInstance,
447 (LPCSTR)lppsp->u.pszTemplate,
449 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
451 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
455 * Extract the size of the page and the caption.
460 p = (const WORD *)pTemplate;
462 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
464 /* DLGTEMPLATEEX (not defined in any std. header file) */
468 p += 2; /* help ID */
469 p += 2; /* ext style */
477 p += 2; /* ext style */
483 width = (WORD)*p; p++;
484 height = (WORD)*p; p++;
486 /* Special calculation for interior wizard pages so the largest page is
487 * calculated correctly. We need to add all the padding and space occupied
488 * by the header so the width and height sums up to the whole wizard client
490 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
491 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
492 !(dwFlags & PSP_HIDEHEADER))
494 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
495 width += 2 * WIZARD_PADDING;
497 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
499 height += 2 * WIZARD_PADDING;
500 width += 2 * WIZARD_PADDING;
503 /* remember the largest width and height */
504 if (width > psInfo->width)
505 psInfo->width = width;
507 if (height > psInfo->height)
508 psInfo->height = height;
520 p += lstrlenW( (LPCWSTR)p ) + 1;
534 p += lstrlenW( (LPCWSTR)p ) + 1;
538 /* Extract the caption */
539 psInfo->proppage[index].pszText = (LPCWSTR)p;
540 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
541 p += lstrlenW((LPCWSTR)p) + 1;
543 if (dwFlags & PSP_USETITLE)
547 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
550 if ( !HIWORD( lppsp->pszTitle ) )
552 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
555 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
561 pTitle = lppsp->pszTitle;
563 len = strlenW(pTitle);
564 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
565 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
569 * Build the image list for icons
571 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
574 int icon_cx = GetSystemMetrics(SM_CXSMICON);
575 int icon_cy = GetSystemMetrics(SM_CYSMICON);
577 if (dwFlags & PSP_USEICONID)
578 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
579 icon_cx, icon_cy, LR_DEFAULTCOLOR);
581 hIcon = lppsp->u2.hIcon;
585 if (psInfo->hImageList == 0 )
586 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
588 ImageList_AddIcon(psInfo->hImageList, hIcon);
596 /******************************************************************************
597 * PROPSHEET_CreateDialog
599 * Creates the actual property sheet.
601 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
608 WORD resID = IDD_PROPSHEET;
611 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
614 if( psInfo->unicode )
616 if(!(hRes = FindResourceW(COMCTL32_hModule,
617 MAKEINTRESOURCEW(resID),
623 if(!(hRes = FindResourceA(COMCTL32_hModule,
624 MAKEINTRESOURCEA(resID),
629 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
633 * Make a copy of the dialog template.
635 resSize = SizeofResource(COMCTL32_hModule, hRes);
637 temp = Alloc(resSize);
642 memcpy(temp, template, resSize);
644 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
646 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
647 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
649 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
651 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
652 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
654 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
655 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
657 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
660 if (psInfo->useCallback)
661 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
663 /* NOTE: MSDN states "Returns a positive value if successful, or -1
664 * otherwise for modal property sheets.", but this is wrong. The
665 * actual return value is either TRUE (success), FALSE (cancel) or
667 if( psInfo->unicode )
669 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
670 (LPDLGTEMPLATEW) temp,
671 psInfo->ppshheader.hwndParent,
672 PROPSHEET_DialogProc,
674 if ( !ret ) ret = -1;
678 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
679 (LPDLGTEMPLATEA) temp,
680 psInfo->ppshheader.hwndParent,
681 PROPSHEET_DialogProc,
683 if ( !ret ) ret = -1;
691 /******************************************************************************
692 * PROPSHEET_SizeMismatch
694 * Verify that the tab control and the "largest" property sheet page dlg. template
697 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
699 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
700 RECT rcOrigTab, rcPage;
705 GetClientRect(hwndTabCtrl, &rcOrigTab);
706 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
707 rcOrigTab.right, rcOrigTab.bottom);
714 rcPage.right = psInfo->width;
715 rcPage.bottom = psInfo->height;
717 MapDialogRect(hwndDlg, &rcPage);
718 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
719 rcPage.right, rcPage.bottom);
721 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
723 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
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);
739 int tabOffsetX, tabOffsetY, buttonHeight;
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
743 /* Get the height of buttons */
744 GetClientRect(hwndButton, &rc);
745 buttonHeight = rc.bottom;
752 rc.right = psInfo->width;
753 rc.bottom = psInfo->height;
755 MapDialogRect(hwndDlg, &rc);
757 /* retrieve the dialog units */
758 units.left = units.right = 4;
759 units.top = units.bottom = 8;
760 MapDialogRect(hwndDlg, &units);
763 * Resize the tab control.
765 GetClientRect(hwndTabCtrl,&tabRect);
767 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
769 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
771 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
772 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
775 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
777 rc.right = rc.left + tabRect.right - tabRect.left;
778 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
781 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
783 tabOffsetX = -(rc.left);
784 tabOffsetY = -(rc.top);
788 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
789 hwndTabCtrl, rc.right, rc.bottom);
790 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
791 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
793 GetClientRect(hwndTabCtrl, &rc);
795 TRACE("tab client rc %d %d %d %d\n",
796 rc.left, rc.top, rc.right, rc.bottom);
798 rc.right += ((padding.x * 2) + tabOffsetX);
799 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
802 * Resize the property sheet.
804 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
805 hwndDlg, rc.right, rc.bottom);
806 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
807 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
811 /******************************************************************************
812 * PROPSHEET_AdjustSizeWizard
814 * Resizes the property sheet to fit the largest page.
816 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
818 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
819 RECT rc, lineRect, dialogRect;
821 /* Biggest page size */
824 rc.right = psInfo->width;
825 rc.bottom = psInfo->height;
826 MapDialogRect(hwndDlg, &rc);
828 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
830 /* Add space for the buttons row */
831 GetWindowRect(hwndLine, &lineRect);
832 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
833 GetClientRect(hwndDlg, &dialogRect);
834 rc.bottom += dialogRect.bottom - lineRect.top - 1;
836 /* Convert the client coordinates to window coordinates */
837 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
839 /* Resize the property sheet */
840 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
841 hwndDlg, rc.right, rc.bottom);
842 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
843 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
848 /******************************************************************************
849 * PROPSHEET_AdjustButtons
851 * Adjusts the buttons' positions.
853 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
855 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
859 int buttonWidth, buttonHeight;
860 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
862 if (psInfo->hasApply)
869 * Obtain the size of the buttons.
871 GetClientRect(hwndButton, &rcSheet);
872 buttonWidth = rcSheet.right;
873 buttonHeight = rcSheet.bottom;
876 * Get the size of the property sheet.
878 GetClientRect(hwndParent, &rcSheet);
881 * All buttons will be at this y coordinate.
883 y = rcSheet.bottom - (padding.y + buttonHeight);
886 * Position OK button and make it default.
888 hwndButton = GetDlgItem(hwndParent, IDOK);
890 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
892 SetWindowPos(hwndButton, 0, x, y, 0, 0,
893 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
895 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
899 * Position Cancel button.
901 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
903 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
905 SetWindowPos(hwndButton, 0, x, y, 0, 0,
906 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
909 * Position Apply button.
911 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
913 if (psInfo->hasApply)
916 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
918 x = rcSheet.right - (padding.x + buttonWidth);
920 SetWindowPos(hwndButton, 0, x, y, 0, 0,
921 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
923 EnableWindow(hwndButton, FALSE);
926 ShowWindow(hwndButton, SW_HIDE);
929 * Position Help button.
931 hwndButton = GetDlgItem(hwndParent, IDHELP);
935 x = rcSheet.right - (padding.x + buttonWidth);
937 SetWindowPos(hwndButton, 0, x, y, 0, 0,
938 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
941 ShowWindow(hwndButton, SW_HIDE);
946 /******************************************************************************
947 * PROPSHEET_AdjustButtonsWizard
949 * Adjusts the buttons' positions.
951 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
952 PropSheetInfo* psInfo)
954 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
955 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
956 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
960 int buttonWidth, buttonHeight, lineHeight, lineWidth;
961 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
965 if (psInfo->hasFinish)
969 * Obtain the size of the buttons.
971 GetClientRect(hwndButton, &rcSheet);
972 buttonWidth = rcSheet.right;
973 buttonHeight = rcSheet.bottom;
975 GetClientRect(hwndLine, &rcSheet);
976 lineHeight = rcSheet.bottom;
979 * Get the size of the property sheet.
981 GetClientRect(hwndParent, &rcSheet);
984 * All buttons will be at this y coordinate.
986 y = rcSheet.bottom - (padding.y + buttonHeight);
989 * Position the Back button.
991 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
993 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
995 SetWindowPos(hwndButton, 0, x, y, 0, 0,
996 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
999 * Position the Next button.
1001 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1005 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1006 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1009 * Position the Finish button.
1011 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1013 if (psInfo->hasFinish)
1014 x += padding.x + buttonWidth;
1016 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1017 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1019 if (!psInfo->hasFinish)
1020 ShowWindow(hwndButton, SW_HIDE);
1023 * Position the Cancel button.
1025 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1027 x += padding.x + buttonWidth;
1029 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1030 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1033 * Position Help button.
1035 hwndButton = GetDlgItem(hwndParent, IDHELP);
1037 if (psInfo->hasHelp)
1039 x += padding.x + buttonWidth;
1041 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1042 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1045 ShowWindow(hwndButton, SW_HIDE);
1047 if (psInfo->ppshheader.dwFlags &
1048 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1052 * Position and resize the sunken line.
1055 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1057 lineWidth = rcSheet.right - (padding.x * 2);
1058 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1059 SWP_NOZORDER | SWP_NOACTIVATE);
1062 * Position and resize the header sunken line.
1065 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1066 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1067 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1068 ShowWindow(hwndLineHeader, SW_HIDE);
1073 /******************************************************************************
1074 * PROPSHEET_GetPaddingInfo
1076 * Returns the layout information.
1078 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1080 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1083 PADDING_INFO padding;
1085 GetWindowRect(hwndTab, &rcTab);
1090 ScreenToClient(hwndDlg, &tl);
1098 /******************************************************************************
1099 * PROPSHEET_GetPaddingInfoWizard
1101 * Returns the layout information.
1102 * Vertical spacing is the distance between the line and the buttons.
1103 * Do NOT use the Help button to gather padding information when it isn't mapped
1104 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1105 * for it in this case !
1106 * FIXME: I'm not sure about any other coordinate problems with these evil
1107 * buttons. Fix it in case additional problems appear or maybe calculate
1108 * a padding in a completely different way, as this is somewhat messy.
1110 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1113 PADDING_INFO padding;
1117 POINT ptButton, ptLine;
1120 if (psInfo->hasHelp)
1126 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1128 idButton = IDC_NEXT_BUTTON;
1132 /* hopefully this is ok */
1133 idButton = IDCANCEL;
1137 hwndControl = GetDlgItem(hwndDlg, idButton);
1138 GetWindowRect(hwndControl, &rc);
1140 ptButton.x = rc.left;
1141 ptButton.y = rc.top;
1143 ScreenToClient(hwndDlg, &ptButton);
1146 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1147 GetWindowRect(hwndControl, &rc);
1150 ptLine.y = rc.bottom;
1152 ScreenToClient(hwndDlg, &ptLine);
1154 padding.y = ptButton.y - ptLine.y;
1157 ERR("padding negative ! Please report this !\n");
1159 /* this is most probably not correct, but the best we have now */
1160 padding.x = padding.y;
1164 /******************************************************************************
1165 * PROPSHEET_CreateTabControl
1167 * Insert the tabs in the tab control.
1169 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1170 PropSheetInfo * psInfo)
1172 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1178 item.mask = TCIF_TEXT;
1179 item.cchTextMax = MAX_TABTEXT_LENGTH;
1181 nTabs = psInfo->nPages;
1184 * Set the image list for icons.
1186 if (psInfo->hImageList)
1188 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1191 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1192 for (i = 0; i < nTabs; i++)
1194 if ( psInfo->proppage[i].hasIcon )
1196 item.mask |= TCIF_IMAGE;
1197 item.iImage = iImage++;
1201 item.mask &= ~TCIF_IMAGE;
1204 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1205 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1207 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1212 /******************************************************************************
1213 * PROPSHEET_WizardSubclassProc
1215 * Subclassing window procedure for wizard extrior pages to prevent drawing
1216 * background and so drawing above the watermark.
1218 static LRESULT CALLBACK
1219 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1226 case WM_CTLCOLORSTATIC:
1227 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1228 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1231 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1235 * Get the size of an in-memory Template
1237 *( Based on the code of PROPSHEET_CollectPageInfo)
1238 * See also dialog.c/DIALOG_ParseTemplate32().
1241 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1244 const WORD* p = (const WORD *)pTemplate;
1245 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1251 /* DLGTEMPLATEEX (not defined in any std. header file) */
1253 TRACE("is DLGTEMPLATEEX\n");
1255 p++; /* signature */
1256 p += 2; /* help ID */
1257 p += 2; /* ext style */
1264 TRACE("is DLGTEMPLATE\n");
1266 p += 2; /* ext style */
1269 nrofitems = (WORD)*p; p++; /* nb items */
1285 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1286 p += lstrlenW( (LPCWSTR)p ) + 1;
1297 p += 2; /* 0xffff plus predefined window class ordinal value */
1300 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1301 p += lstrlenW( (LPCWSTR)p ) + 1;
1306 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1307 p += lstrlenW((LPCWSTR)p) + 1;
1309 /* font, if DS_SETFONT set */
1310 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1313 p+=(istemplateex)?3:1;
1314 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1315 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1318 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1319 * that are following the DLGTEMPLATE(EX) data */
1320 TRACE("%d items\n",nrofitems);
1321 while (nrofitems > 0)
1323 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1326 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1335 TRACE("class ordinal 0x%08x\n",*(DWORD*)p);
1339 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1340 p += lstrlenW( (LPCWSTR)p ) + 1;
1344 /* check title text */
1351 TRACE("text ordinal 0x%08x\n",*(DWORD*)p);
1355 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1356 p += lstrlenW( (LPCWSTR)p ) + 1;
1359 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1363 ret = (p - (WORD*)pTemplate) * sizeof(WORD);
1364 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1368 /******************************************************************************
1369 * PROPSHEET_CreatePage
1373 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1375 const PropSheetInfo * psInfo,
1376 LPCPROPSHEETPAGEW ppshpage)
1378 DLGTEMPLATE* pTemplate;
1383 TRACE("index %d\n", index);
1385 if (ppshpage == NULL)
1390 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1392 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1393 resSize = GetTemplateSize(pTemplate);
1395 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1400 hResource = FindResourceW(ppshpage->hInstance,
1401 ppshpage->u.pszTemplate,
1406 resSize = SizeofResource(ppshpage->hInstance, hResource);
1408 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1412 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1414 * Make a copy of the dialog template to make it writable
1422 hResource = FindResourceA(ppshpage->hInstance,
1423 (LPCSTR)ppshpage->u.pszTemplate,
1428 resSize = SizeofResource(ppshpage->hInstance, hResource);
1430 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1434 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1436 * Make a copy of the dialog template to make it writable
1439 temp = Alloc(resSize);
1443 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1444 memcpy(temp, pTemplate, resSize);
1447 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1449 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1450 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1451 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1452 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1453 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1454 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1458 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1462 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1463 pTemplate->style &= ~DS_MODALFRAME;
1464 pTemplate->style &= ~WS_CAPTION;
1465 pTemplate->style &= ~WS_SYSMENU;
1466 pTemplate->style &= ~WS_POPUP;
1467 pTemplate->style &= ~WS_DISABLED;
1468 pTemplate->style &= ~WS_VISIBLE;
1469 pTemplate->style &= ~WS_THICKFRAME;
1471 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1474 if (psInfo->proppage[index].useCallback)
1475 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1476 (LPPROPSHEETPAGEW)ppshpage);
1478 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1479 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1482 ppshpage->pfnDlgProc,
1485 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1488 ppshpage->pfnDlgProc,
1490 /* Free a no more needed copy */
1494 psInfo->proppage[index].hwndPage = hwndPage;
1496 /* Subclass exterior wizard pages */
1497 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1498 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1499 (ppshpage->dwFlags & PSP_HIDEHEADER))
1501 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1502 (DWORD_PTR)ppshpage);
1504 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1505 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1510 /******************************************************************************
1511 * PROPSHEET_LoadWizardBitmaps
1513 * Loads the watermark and header bitmaps for a wizard.
1515 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1517 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1519 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1520 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1521 considers hbmWatermark as valid. */
1522 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1523 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1525 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1526 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1529 /* Same behavior as for watermarks */
1530 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1531 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1533 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1534 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1540 /******************************************************************************
1541 * PROPSHEET_ShowPage
1543 * Displays or creates the specified page.
1545 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1548 HWND hwndLineHeader;
1549 LPCPROPSHEETPAGEW ppshpage;
1551 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1552 if (index == psInfo->active_page)
1554 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1555 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1559 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1560 if (psInfo->proppage[index].hwndPage == 0)
1562 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1565 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1567 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1568 psInfo->proppage[index].pszText);
1571 if (psInfo->active_page != -1)
1572 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1574 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1576 /* Synchronize current selection with tab control
1577 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1578 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1579 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1581 psInfo->active_page = index;
1582 psInfo->activeValid = TRUE;
1584 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1586 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1587 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1589 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1590 ShowWindow(hwndLineHeader, SW_HIDE);
1592 ShowWindow(hwndLineHeader, SW_SHOW);
1598 /******************************************************************************
1601 static BOOL PROPSHEET_Back(HWND hwndDlg)
1605 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1610 TRACE("active_page %d\n", psInfo->active_page);
1611 if (psInfo->active_page < 0)
1614 psn.hdr.code = PSN_WIZBACK;
1615 psn.hdr.hwndFrom = hwndDlg;
1619 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1621 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1624 else if (result == 0)
1625 idx = psInfo->active_page - 1;
1627 idx = PROPSHEET_FindPageByResId(psInfo, result);
1629 if (idx >= 0 && idx < psInfo->nPages)
1631 if (PROPSHEET_CanSetCurSel(hwndDlg))
1632 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1637 /******************************************************************************
1640 static BOOL PROPSHEET_Next(HWND hwndDlg)
1644 LRESULT msgResult = 0;
1645 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1649 TRACE("active_page %d\n", psInfo->active_page);
1650 if (psInfo->active_page < 0)
1653 psn.hdr.code = PSN_WIZNEXT;
1654 psn.hdr.hwndFrom = hwndDlg;
1658 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1660 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1661 if (msgResult == -1)
1663 else if (msgResult == 0)
1664 idx = psInfo->active_page + 1;
1666 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1668 if (idx < psInfo->nPages )
1670 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1671 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1677 /******************************************************************************
1680 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1684 LRESULT msgResult = 0;
1685 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1688 TRACE("active_page %d\n", psInfo->active_page);
1689 if (psInfo->active_page < 0)
1692 psn.hdr.code = PSN_WIZFINISH;
1693 psn.hdr.hwndFrom = hwndDlg;
1697 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1699 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1701 TRACE("msg result %ld\n", msgResult);
1706 if (psInfo->isModeless)
1707 psInfo->activeValid = FALSE;
1709 psInfo->ended = TRUE;
1714 /******************************************************************************
1717 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1722 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1725 TRACE("active_page %d\n", psInfo->active_page);
1726 if (psInfo->active_page < 0)
1729 psn.hdr.hwndFrom = hwndDlg;
1735 * Send PSN_KILLACTIVE to the current page.
1737 psn.hdr.code = PSN_KILLACTIVE;
1739 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1741 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1745 * Send PSN_APPLY to all pages.
1747 psn.hdr.code = PSN_APPLY;
1748 psn.lParam = lParam;
1750 for (i = 0; i < psInfo->nPages; i++)
1752 hwndPage = psInfo->proppage[i].hwndPage;
1755 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1757 case PSNRET_INVALID:
1758 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1760 case PSNRET_INVALID_NOCHANGEPAGE:
1768 psInfo->activeValid = FALSE;
1770 else if(psInfo->active_page >= 0)
1772 psn.hdr.code = PSN_SETACTIVE;
1774 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1775 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1781 /******************************************************************************
1784 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1786 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1792 TRACE("active_page %d\n", psInfo->active_page);
1793 if (psInfo->active_page < 0)
1796 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1797 psn.hdr.code = PSN_QUERYCANCEL;
1798 psn.hdr.hwndFrom = hwndDlg;
1802 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1805 psn.hdr.code = PSN_RESET;
1806 psn.lParam = lParam;
1808 for (i = 0; i < psInfo->nPages; i++)
1810 hwndPage = psInfo->proppage[i].hwndPage;
1813 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1816 if (psInfo->isModeless)
1818 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1819 psInfo->activeValid = FALSE;
1822 psInfo->ended = TRUE;
1825 /******************************************************************************
1828 static void PROPSHEET_Help(HWND hwndDlg)
1830 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1835 TRACE("active_page %d\n", psInfo->active_page);
1836 if (psInfo->active_page < 0)
1839 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1840 psn.hdr.code = PSN_HELP;
1841 psn.hdr.hwndFrom = hwndDlg;
1845 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1848 /******************************************************************************
1851 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1854 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1858 if (!psInfo) return;
1860 * Set the dirty flag of this page.
1862 for (i = 0; i < psInfo->nPages; i++)
1864 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1865 psInfo->proppage[i].isDirty = TRUE;
1869 * Enable the Apply button.
1871 if (psInfo->hasApply)
1873 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1875 EnableWindow(hwndApplyBtn, TRUE);
1879 /******************************************************************************
1880 * PROPSHEET_UnChanged
1882 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1885 BOOL noPageDirty = TRUE;
1886 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1887 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1891 if ( !psInfo ) return;
1892 for (i = 0; i < psInfo->nPages; i++)
1894 /* set the specified page as clean */
1895 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1896 psInfo->proppage[i].isDirty = FALSE;
1898 /* look to see if there's any dirty pages */
1899 if (psInfo->proppage[i].isDirty)
1900 noPageDirty = FALSE;
1904 * Disable Apply button.
1907 EnableWindow(hwndApplyBtn, FALSE);
1910 /******************************************************************************
1911 * PROPSHEET_PressButton
1913 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1915 TRACE("buttonID %d\n", buttonID);
1918 case PSBTN_APPLYNOW:
1919 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1922 PROPSHEET_Back(hwndDlg);
1925 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1928 PROPSHEET_Finish(hwndDlg);
1931 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1934 PROPSHEET_Next(hwndDlg);
1937 PROPSHEET_DoCommand(hwndDlg, IDOK);
1940 FIXME("Invalid button index %d\n", buttonID);
1945 /*************************************************************************
1946 * BOOL PROPSHEET_CanSetCurSel [Internal]
1948 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1951 * hwndDlg [I] handle to a Dialog hWnd
1954 * TRUE if Current Selection can change
1958 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1960 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1966 TRACE("active_page %d\n", psInfo->active_page);
1973 if (psInfo->active_page < 0)
1980 * Notify the current page.
1982 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1983 psn.hdr.code = PSN_KILLACTIVE;
1984 psn.hdr.hwndFrom = hwndDlg;
1988 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1991 TRACE("<-- %d\n", res);
1995 /******************************************************************************
1996 * PROPSHEET_SetCurSel
1998 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2001 HPROPSHEETPAGE hpage
2004 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2005 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2006 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2008 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2009 /* hpage takes precedence over index */
2011 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2013 if (index < 0 || index >= psInfo->nPages)
2015 TRACE("Could not find page to select!\n");
2023 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2026 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2028 psn.hdr.code = PSN_SETACTIVE;
2029 psn.hdr.hwndFrom = hwndDlg;
2033 if (!psInfo->proppage[index].hwndPage) {
2034 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2037 /* Resize the property sheet page to the fit in the Tab control
2038 * (for regular property sheets) or to fit in the client area (for
2040 * NOTE: The resizing happens every time the page is selected and
2041 * not only when it's created (some applications depend on it). */
2042 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2043 TRACE("setting page %p, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
2044 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2045 rc.right - rc.left, rc.bottom - rc.top);
2046 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2048 rc.right - rc.left, rc.bottom - rc.top, 0);
2050 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2057 WARN("Tried to skip before first property sheet page!\n");
2060 if (index >= psInfo->nPages) {
2061 WARN("Tried to skip after last property sheet page!\n");
2062 index = psInfo->nPages-1;
2066 else if (result != 0)
2068 int old_index = index;
2069 index = PROPSHEET_FindPageByResId(psInfo, result);
2070 if(index >= psInfo->nPages) {
2072 WARN("Tried to skip to nonexistant page by res id\n");
2079 /* Invalidate the header area */
2080 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2081 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2083 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2086 GetClientRect(hwndLineHeader, &r);
2087 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2088 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2090 InvalidateRect(hwndDlg, &r, TRUE);
2094 * Display the new page.
2096 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2098 if (psInfo->proppage[index].hasHelp)
2099 EnableWindow(hwndHelp, TRUE);
2101 EnableWindow(hwndHelp, FALSE);
2106 /******************************************************************************
2107 * PROPSHEET_SetCurSelId
2109 * Selects the page, specified by resource id.
2111 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2114 PropSheetInfo* psInfo =
2115 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2117 idx = PROPSHEET_FindPageByResId(psInfo, id);
2118 if (idx < psInfo->nPages )
2120 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2121 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2125 /******************************************************************************
2126 * PROPSHEET_SetTitleA
2128 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2130 if(HIWORD(lpszText))
2133 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2134 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2135 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2139 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2143 /******************************************************************************
2144 * PROPSHEET_SetTitleW
2146 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2148 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2151 TRACE("'%s' (style %08x)\n", debugstr_w(lpszText), dwStyle);
2152 if (HIWORD(lpszText) == 0) {
2153 if (!LoadStringW(psInfo->ppshheader.hInstance,
2154 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2158 if (dwStyle & PSH_PROPTITLE)
2161 int lentitle = strlenW(lpszText);
2162 int lenprop = strlenW(psInfo->strPropertiesFor);
2164 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2165 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2167 SetWindowTextW(hwndDlg, dest);
2171 SetWindowTextW(hwndDlg, lpszText);
2174 /******************************************************************************
2175 * PROPSHEET_SetFinishTextA
2177 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2179 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2180 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2182 TRACE("'%s'\n", lpszText);
2183 /* Set text, show and enable the Finish button */
2184 SetWindowTextA(hwndButton, lpszText);
2185 ShowWindow(hwndButton, SW_SHOW);
2186 EnableWindow(hwndButton, TRUE);
2188 /* Make it default pushbutton */
2189 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2191 /* Hide Back button */
2192 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2193 ShowWindow(hwndButton, SW_HIDE);
2195 if (!psInfo->hasFinish)
2197 /* Hide Next button */
2198 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2199 ShowWindow(hwndButton, SW_HIDE);
2203 /******************************************************************************
2204 * PROPSHEET_SetFinishTextW
2206 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2208 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2209 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2211 TRACE("'%s'\n", debugstr_w(lpszText));
2212 /* Set text, show and enable the Finish button */
2213 SetWindowTextW(hwndButton, lpszText);
2214 ShowWindow(hwndButton, SW_SHOW);
2215 EnableWindow(hwndButton, TRUE);
2217 /* Make it default pushbutton */
2218 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2220 /* Hide Back button */
2221 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2222 ShowWindow(hwndButton, SW_HIDE);
2224 if (!psInfo->hasFinish)
2226 /* Hide Next button */
2227 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2228 ShowWindow(hwndButton, SW_HIDE);
2232 /******************************************************************************
2233 * PROPSHEET_QuerySiblings
2235 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2236 WPARAM wParam, LPARAM lParam)
2240 LRESULT msgResult = 0;
2241 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2243 while ((i < psInfo->nPages) && (msgResult == 0))
2245 hwndPage = psInfo->proppage[i].hwndPage;
2246 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2254 /******************************************************************************
2257 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2258 HPROPSHEETPAGE hpage)
2261 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2263 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2265 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2267 TRACE("hpage %p\n", hpage);
2269 * Allocate and fill in a new PropPageInfo entry.
2271 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2272 sizeof(PropPageInfo) *
2273 (psInfo->nPages + 1));
2277 psInfo->proppage = ppi;
2278 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2281 psInfo->proppage[psInfo->nPages].hpage = hpage;
2283 if (ppsp->dwFlags & PSP_PREMATURE)
2285 /* Create the page but don't show it */
2286 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2290 * Add a new tab to the tab control.
2292 item.mask = TCIF_TEXT;
2293 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2294 item.cchTextMax = MAX_TABTEXT_LENGTH;
2296 if (psInfo->hImageList)
2298 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2301 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2303 item.mask |= TCIF_IMAGE;
2304 item.iImage = psInfo->nPages;
2307 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2312 /* If it is the only page - show it */
2313 if(psInfo->nPages == 1)
2314 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2318 /******************************************************************************
2319 * PROPSHEET_RemovePage
2321 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2323 HPROPSHEETPAGE hpage)
2325 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2327 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2328 PropPageInfo* oldPages;
2330 TRACE("index %d, hpage %p\n", index, hpage);
2335 * hpage takes precedence over index.
2339 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2342 /* Make sure that index is within range */
2343 if (index < 0 || index >= psInfo->nPages)
2345 TRACE("Could not find page to remove!\n");
2349 TRACE("total pages %d removing page %d active page %d\n",
2350 psInfo->nPages, index, psInfo->active_page);
2352 * Check if we're removing the active page.
2354 if (index == psInfo->active_page)
2356 if (psInfo->nPages > 1)
2360 /* activate previous page */
2361 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2365 /* activate the next page */
2366 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2367 psInfo->active_page = index;
2372 psInfo->active_page = -1;
2373 if (!psInfo->isModeless)
2375 psInfo->ended = TRUE;
2380 else if (index < psInfo->active_page)
2381 psInfo->active_page--;
2383 /* Unsubclass the page dialog window */
2384 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2385 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2386 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2388 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2389 PROPSHEET_WizardSubclassProc, 1);
2392 /* Destroy page dialog window */
2393 DestroyWindow(psInfo->proppage[index].hwndPage);
2395 /* Free page resources */
2396 if(psInfo->proppage[index].hpage)
2398 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2400 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2401 Free ((LPVOID)psInfo->proppage[index].pszText);
2403 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2406 /* Remove the tab */
2407 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2409 oldPages = psInfo->proppage;
2411 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2414 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2416 if (index < psInfo->nPages)
2417 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2418 (psInfo->nPages - index) * sizeof(PropPageInfo));
2425 /******************************************************************************
2426 * PROPSHEET_SetWizButtons
2428 * This code will work if (and assumes that) the Next button is on top of the
2429 * Finish button. ie. Finish comes after Next in the Z order.
2430 * This means make sure the dialog template reflects this.
2433 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2435 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
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);
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);
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 (!HIWORD(hpageInsertAfter))
2495 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2497 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
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)
2539 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2542 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2544 for (index = 0; index < psInfo->nPages; index++)
2545 if (psInfo->proppage[index].hwndPage == hPageDlg)
2547 WARN("%p not found\n", hPageDlg);
2551 /******************************************************************************
2552 * PROPSHEET_IndexToHwnd
2554 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2556 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2558 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2559 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2560 WARN("%d out of range.\n", iPageIndex);
2563 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2566 /******************************************************************************
2567 * PROPSHEET_PageToIndex
2569 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2572 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2575 TRACE("(%p, %p)\n", hwndDlg, hPage);
2577 for (index = 0; index < psInfo->nPages; index++)
2578 if (psInfo->proppage[index].hpage == hPage)
2580 WARN("%p not found\n", hPage);
2584 /******************************************************************************
2585 * PROPSHEET_IndexToPage
2587 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2589 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2591 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2592 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2593 WARN("%d out of range.\n", iPageIndex);
2596 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2599 /******************************************************************************
2600 * PROPSHEET_IdToIndex
2602 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2605 LPCPROPSHEETPAGEW psp;
2606 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2608 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2609 for (index = 0; index < psInfo->nPages; index++) {
2610 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2611 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2618 /******************************************************************************
2619 * PROPSHEET_IndexToId
2621 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2623 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2625 LPCPROPSHEETPAGEW psp;
2626 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2627 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2628 WARN("%d out of range.\n", iPageIndex);
2631 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2632 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2635 return (LRESULT)psp->u.pszTemplate;
2638 /******************************************************************************
2639 * PROPSHEET_GetResult
2641 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2643 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2645 return psInfo->result;
2648 /******************************************************************************
2649 * PROPSHEET_RecalcPageSizes
2651 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2653 FIXME("(%p): stub\n", hwndDlg);
2657 /******************************************************************************
2658 * PROPSHEET_GetPageIndex
2660 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2661 * the array of PropPageInfo.
2663 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2668 TRACE("hpage %p\n", hpage);
2669 while ((index < psInfo->nPages) && (found == FALSE))
2671 if (psInfo->proppage[index].hpage == hpage)
2683 /******************************************************************************
2686 static void PROPSHEET_CleanUp(HWND hwndDlg)
2689 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2693 if (!psInfo) return;
2694 if (HIWORD(psInfo->ppshheader.pszCaption))
2695 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2697 for (i = 0; i < psInfo->nPages; i++)
2699 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2701 /* Unsubclass the page dialog window */
2702 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2703 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2704 (psp->dwFlags & PSP_HIDEHEADER))
2706 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2707 PROPSHEET_WizardSubclassProc, 1);
2710 if(psInfo->proppage[i].hwndPage)
2711 DestroyWindow(psInfo->proppage[i].hwndPage);
2715 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2716 Free ((LPVOID)psInfo->proppage[i].pszText);
2718 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2722 DeleteObject(psInfo->hFont);
2723 DeleteObject(psInfo->hFontBold);
2724 /* If we created the bitmaps, destroy them */
2725 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2726 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2727 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2728 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2729 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2730 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2732 Free(psInfo->proppage);
2733 Free(psInfo->strPropertiesFor);
2734 ImageList_Destroy(psInfo->hImageList);
2736 GlobalFree((HGLOBAL)psInfo);
2739 static INT do_loop(PropSheetInfo *psInfo)
2743 HWND hwnd = psInfo->hwnd;
2745 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2750 if(!IsDialogMessageW(hwnd, &msg))
2752 TranslateMessage(&msg);
2753 DispatchMessageW(&msg);
2759 PostQuitMessage(msg.wParam);
2764 ret = psInfo->result;
2766 DestroyWindow(hwnd);
2770 /******************************************************************************
2771 * PropertySheet (COMCTL32.@)
2772 * PropertySheetA (COMCTL32.@)
2774 * Creates a property sheet in the specified property sheet header.
2777 * Modal property sheets: Positive if successful or -1 otherwise.
2778 * Modeless property sheets: Property sheet handle.
2780 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2781 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2783 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2786 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2787 sizeof(PropSheetInfo));
2791 TRACE("(%p)\n", lppsh);
2793 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2795 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2797 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2799 for (n = i = 0; i < lppsh->nPages; i++, n++)
2801 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2802 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2805 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2806 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2809 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2812 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2813 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2819 psInfo->unicode = FALSE;
2820 psInfo->ended = FALSE;
2822 bRet = PROPSHEET_CreateDialog(psInfo);
2823 if(!psInfo->isModeless)
2824 bRet = do_loop(psInfo);
2829 /******************************************************************************
2830 * PropertySheetW (COMCTL32.@)
2832 * See PropertySheetA.
2834 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2837 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2838 sizeof(PropSheetInfo));
2842 TRACE("(%p)\n", lppsh);
2844 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2846 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2848 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2850 for (n = i = 0; i < lppsh->nPages; i++, n++)
2852 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2853 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2856 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2857 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2860 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2863 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2864 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2870 psInfo->unicode = TRUE;
2871 psInfo->ended = FALSE;
2873 bRet = PROPSHEET_CreateDialog(psInfo);
2874 if(!psInfo->isModeless)
2875 bRet = do_loop(psInfo);
2880 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2885 if (IS_INTRESOURCE(str))
2890 WORD i, id = LOWORD(str);
2892 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2894 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2895 if (!(ptr = LockResource( hmem ))) return NULL;
2896 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2898 if (!len) return NULL;
2899 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2902 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2908 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2910 if (ret) memcpy( ret, str, len );
2916 /******************************************************************************
2917 * CreatePropertySheetPage (COMCTL32.@)
2918 * CreatePropertySheetPageA (COMCTL32.@)
2920 * Creates a new property sheet page.
2923 * Success: Handle to new property sheet page.
2927 * An application must use the PSM_ADDPAGE message to add the new page to
2928 * an existing property sheet.
2930 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2931 LPCPROPSHEETPAGEA lpPropSheetPage)
2933 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2935 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2937 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2939 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2941 if (HIWORD( ppsp->u.pszTemplate ))
2943 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2944 ppsp->u.pszTemplate = Alloc( len );
2945 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2949 if (ppsp->dwFlags & PSP_USEICONID)
2951 if (HIWORD( ppsp->u2.pszIcon ))
2952 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2955 if (ppsp->dwFlags & PSP_USETITLE)
2957 if (HIWORD( ppsp->pszTitle ))
2958 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2960 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2963 ppsp->pszTitle = NULL;
2965 if (ppsp->dwFlags & PSP_HIDEHEADER)
2966 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2968 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2970 if (HIWORD( ppsp->pszHeaderTitle ))
2971 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2973 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2976 ppsp->pszHeaderTitle = NULL;
2978 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2980 if (HIWORD( ppsp->pszHeaderSubTitle ))
2981 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2983 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2986 ppsp->pszHeaderSubTitle = NULL;
2988 return (HPROPSHEETPAGE)ppsp;
2991 /******************************************************************************
2992 * CreatePropertySheetPageW (COMCTL32.@)
2994 * See CreatePropertySheetA.
2996 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2998 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3000 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3002 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3004 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3006 if (HIWORD( ppsp->u.pszTemplate ))
3008 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3009 ppsp->u.pszTemplate = Alloc( len * sizeof (WCHAR) );
3010 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
3014 if ( ppsp->dwFlags & PSP_USEICONID )
3016 if (HIWORD( ppsp->u2.pszIcon ))
3018 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3019 ppsp->u2.pszIcon = Alloc( len * sizeof (WCHAR) );
3020 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
3024 if (ppsp->dwFlags & PSP_USETITLE)
3025 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3027 ppsp->pszTitle = NULL;
3029 if (ppsp->dwFlags & PSP_HIDEHEADER)
3030 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3032 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3033 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3035 ppsp->pszHeaderTitle = NULL;
3037 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3038 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3040 ppsp->pszHeaderSubTitle = NULL;
3042 return (HPROPSHEETPAGE)ppsp;
3045 /******************************************************************************
3046 * DestroyPropertySheetPage (COMCTL32.@)
3048 * Destroys a property sheet page previously created with
3049 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3056 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3058 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3063 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3064 Free ((LPVOID)psp->u.pszTemplate);
3066 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3067 Free ((LPVOID)psp->u2.pszIcon);
3069 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3070 Free ((LPVOID)psp->pszTitle);
3077 /******************************************************************************
3078 * PROPSHEET_IsDialogMessage
3080 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3082 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3085 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3088 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3091 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3093 if (!(dlgCode & DLGC_WANTMESSAGE))
3095 switch (lpMsg->wParam)
3098 if (GetKeyState(VK_SHIFT) & 0x8000)
3104 case VK_NEXT: new_page = 1; break;
3105 case VK_PRIOR: new_page = -1; break;
3111 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3113 new_page += psInfo->active_page;
3116 new_page = psInfo->nPages - 1;
3117 else if (new_page >= psInfo->nPages)
3120 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3127 return IsDialogMessageW(hwnd, lpMsg);
3130 /******************************************************************************
3131 * PROPSHEET_DoCommand
3133 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3139 case IDC_APPLY_BUTTON:
3141 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3143 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3148 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3151 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3152 if (psInfo->result == 0)
3153 psInfo->result = IDOK;
3155 if (psInfo->isModeless)
3156 psInfo->activeValid = FALSE;
3158 psInfo->ended = TRUE;
3161 EnableWindow(hwndApplyBtn, FALSE);
3166 case IDC_BACK_BUTTON:
3167 PROPSHEET_Back(hwnd);
3170 case IDC_NEXT_BUTTON:
3171 PROPSHEET_Next(hwnd);
3174 case IDC_FINISH_BUTTON:
3175 PROPSHEET_Finish(hwnd);
3179 PROPSHEET_Cancel(hwnd, 0);
3183 PROPSHEET_Help(hwnd);
3193 /******************************************************************************
3196 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3198 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3203 HPALETTE hOldPal = 0;
3207 LPCPROPSHEETPAGEW ppshpage;
3208 WCHAR szBuffer[256];
3211 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3214 hdcSrc = CreateCompatibleDC(0);
3215 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3217 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3218 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3220 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3221 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3222 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3224 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3226 COLORREF clrOld = 0;
3229 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3230 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3232 GetClientRect(hwndLineHeader, &r);
3233 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3234 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3236 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3238 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3240 /* Fill the unoccupied part of the header with color of the
3241 * left-top pixel, but do it only when needed.
3243 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3245 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3246 CopyRect(&r, &rzone);
3247 if (bm.bmWidth < r.right)
3249 r.left = bm.bmWidth;
3250 FillRect(hdc, &r, hbr);
3252 if (bm.bmHeight < r.bottom)
3255 r.top = bm.bmHeight;
3256 FillRect(hdc, &r, hbr);
3261 /* Draw the header itself. */
3263 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3264 hdcSrc, 0, 0, SRCCOPY);
3269 hbr = GetSysColorBrush(COLOR_WINDOW);
3270 FillRect(hdc, &rzone, hbr);
3272 /* Draw the header bitmap. It's always centered like a
3273 * common 49 x 49 bitmap. */
3274 margin = (rzone.bottom - 49) / 2;
3275 BitBlt(hdc, rzone.right - 49 - margin, margin,
3276 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3277 hdcSrc, 0, 0, SRCCOPY);
3279 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3280 * if its height is smaller than 49 pixels. Because the reason
3281 * for this bug is unknown the current code doesn't try to
3285 clrOld = SetTextColor (hdc, 0x00000000);
3286 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3288 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3289 SetRect(&r, 20, 10, 0, 0);
3290 if (HIWORD(ppshpage->pszHeaderTitle))
3291 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3294 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3298 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3303 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3304 SelectObject(hdc, psInfo->hFont);
3305 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3306 if (HIWORD(ppshpage->pszHeaderTitle))
3307 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3310 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3314 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3319 offsety = rzone.bottom + 2;
3321 SetTextColor(hdc, clrOld);
3322 SetBkMode(hdc, oldBkMode);
3323 SelectObject(hdc, hOldFont);
3324 SelectObject(hdcSrc, hbmp);
3327 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3328 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3329 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3331 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3333 GetClientRect(hwndLine, &r);
3334 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3338 rzone.right = r.right;
3339 rzone.bottom = r.top - 1;
3341 hbr = GetSysColorBrush(COLOR_WINDOW);
3342 FillRect(hdc, &rzone, hbr);
3344 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3345 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3347 /* The watermark is truncated to a width of 164 pixels */
3348 r.right = min(r.right, 164);
3349 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3350 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3352 /* If the bitmap is not big enough, fill the remaining area
3353 with the color of pixel (0,0) of bitmap - see MSDN */
3354 if (r.top > bm.bmHeight) {
3355 r.bottom = r.top - 1;
3356 r.top = bm.bmHeight;
3358 r.right = bm.bmWidth;
3359 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3360 FillRect(hdc, &r, hbr);
3364 SelectObject(hdcSrc, hbmp);
3367 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3368 SelectPalette(hdc, hOldPal, FALSE);
3372 if (!hdcParam) EndPaint(hwnd, &ps);
3377 /******************************************************************************
3378 * PROPSHEET_DialogProc
3380 static INT_PTR CALLBACK
3381 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3383 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3384 hwnd, uMsg, wParam, lParam);
3390 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3391 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3392 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3393 LPCPROPSHEETPAGEW ppshpage;
3397 /* Using PropSheetInfoStr to store extra data doesn't match the native
3398 * common control: native uses TCM_[GS]ETITEM
3400 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3403 * psInfo->hwnd is not being used by WINE code - it exists
3404 * for compatibility with "real" Windoze. The same about
3405 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3408 psInfo->hwnd = hwnd;
3409 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3411 /* set up the Next and Back buttons by default */
3412 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3415 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3416 psInfo->hFont = CreateFontIndirectW (&logFont);
3417 logFont.lfWeight = FW_BOLD;
3418 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3421 * Small icon in the title bar.
3423 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3424 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3427 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3428 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3430 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3431 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3432 psInfo->ppshheader.u.pszIcon,
3437 hIcon = psInfo->ppshheader.u.hIcon;
3439 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3442 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3443 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3445 psInfo->strPropertiesFor = strCaption;
3447 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3449 PROPSHEET_CreateTabControl(hwnd, psInfo);
3451 PROPSHEET_LoadWizardBitmaps(psInfo);
3453 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3455 ShowWindow(hwndTabCtrl, SW_HIDE);
3456 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3457 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3461 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3463 PROPSHEET_AdjustSize(hwnd, psInfo);
3464 PROPSHEET_AdjustButtons(hwnd, psInfo);
3468 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3469 psInfo->ppshheader.hInstance)
3473 if (LoadStringW(psInfo->ppshheader.hInstance,
3474 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3475 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3479 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3480 psInfo->ppshheader.pszCaption);
3484 if (psInfo->useCallback)
3485 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3486 PSCB_INITIALIZED, (LPARAM)0);
3488 idx = psInfo->active_page;
3489 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3490 psInfo->active_page = -1;
3492 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3494 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3495 * as some programs call TCM_GETCURSEL to get the current selection
3496 * from which to switch to the next page */
3497 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3502 case WM_PRINTCLIENT:
3504 PROPSHEET_Paint(hwnd, (HDC)wParam);
3508 PROPSHEET_CleanUp(hwnd);
3512 PROPSHEET_Cancel(hwnd, 1);
3513 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3516 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3518 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3523 /* No default handler, forward notification to active page */
3524 if (psInfo->activeValid && psInfo->active_page != -1)
3526 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3527 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3534 NMHDR* pnmh = (LPNMHDR) lParam;
3536 if (pnmh->code == TCN_SELCHANGE)
3538 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3539 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3542 if(pnmh->code == TCN_SELCHANGING)
3544 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3545 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3552 case WM_SYSCOLORCHANGE:
3553 COMCTL32_RefreshSysColors();
3556 case PSM_GETCURRENTPAGEHWND:
3558 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3565 if (psInfo->activeValid && psInfo->active_page != -1)
3566 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3568 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3574 PROPSHEET_Changed(hwnd, (HWND)wParam);
3578 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3581 case PSM_GETTABCONTROL:
3583 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3585 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3594 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3595 if(msgResult != FALSE)
3597 msgResult = PROPSHEET_SetCurSel(hwnd,
3600 (HPROPSHEETPAGE)lParam);
3603 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3608 case PSM_CANCELTOCLOSE:
3610 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3611 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3612 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3614 EnableWindow(hwndCancel, FALSE);
3615 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3616 SetWindowTextW(hwndOK, buf);
3621 case PSM_RESTARTWINDOWS:
3623 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3629 /* reboot system takes precedence over restart windows */
3630 if (psInfo->result != ID_PSREBOOTSYSTEM)
3631 psInfo->result = ID_PSRESTARTWINDOWS;
3636 case PSM_REBOOTSYSTEM:
3638 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3644 psInfo->result = ID_PSREBOOTSYSTEM;
3650 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3654 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3659 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3661 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3666 case PSM_QUERYSIBLINGS:
3668 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3670 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3678 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3679 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3680 * on success or FALSE otherwise, as specified on MSDN Online.
3681 * Also see the MFC code for
3682 * CPropertySheet::AddPage(CPropertyPage* pPage).
3685 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3687 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3692 case PSM_REMOVEPAGE:
3693 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3696 case PSM_ISDIALOGMESSAGE:
3698 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3699 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3703 case PSM_PRESSBUTTON:
3704 PROPSHEET_PressButton(hwnd, (int)wParam);
3707 case PSM_SETFINISHTEXTA:
3708 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3711 case PSM_SETWIZBUTTONS:
3712 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3715 case PSM_SETCURSELID:
3716 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3719 case PSM_SETFINISHTEXTW:
3720 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3723 case PSM_INSERTPAGE:
3725 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3726 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3730 case PSM_SETHEADERTITLEW:
3731 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3734 case PSM_SETHEADERTITLEA:
3735 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3738 case PSM_SETHEADERSUBTITLEW:
3739 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3742 case PSM_SETHEADERSUBTITLEA:
3743 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3746 case PSM_HWNDTOINDEX:
3748 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3749 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3753 case PSM_INDEXTOHWND:
3755 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3756 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3760 case PSM_PAGETOINDEX:
3762 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3763 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3767 case PSM_INDEXTOPAGE:
3769 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3770 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3776 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3777 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3783 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3784 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3790 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3791 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3795 case PSM_RECALCPAGESIZES:
3797 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3798 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);