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;
126 PropPageInfo* proppage;
131 HIMAGELIST hImageList;
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 /******************************************************************************
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,
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);
175 static INT_PTR CALLBACK
176 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
178 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
180 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
181 /******************************************************************************
182 * PROPSHEET_UnImplementedFlags
184 * Document use of flags we don't implement yet.
186 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
193 * unhandled header flags:
194 * PSH_RTLREADING 0x00000800
195 * PSH_STRETCHWATERMARK 0x00040000
196 * PSH_USEPAGELANG 0x00200000
199 add_flag(PSH_RTLREADING);
200 add_flag(PSH_STRETCHWATERMARK);
201 add_flag(PSH_USEPAGELANG);
202 if (string[0] != '\0')
203 FIXME("%s\n", string);
207 /******************************************************************************
208 * PROPSHEET_GetPageRect
210 * Retrieve rect from tab control and map into the dialog for SetWindowPos
212 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
213 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
215 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
219 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
220 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
221 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
222 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
224 rc->left = rc->top = WIZARD_PADDING;
228 rc->left = rc->top = 0;
230 rc->right = psInfo->width - rc->left;
231 rc->bottom = psInfo->height - rc->top;
232 MapDialogRect(hwndDlg, rc);
234 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
235 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
236 !(ppshpage->dwFlags & PSP_HIDEHEADER))
238 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
239 GetClientRect(hwndChild, &r);
240 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
241 rc->top += r.bottom + 1;
244 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
245 GetClientRect(hwndTabCtrl, rc);
246 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
247 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
251 /******************************************************************************
252 * PROPSHEET_FindPageByResId
254 * Find page index corresponding to page resource id.
256 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
260 for (i = 0; i < psInfo->nPages; i++)
262 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
264 /* Fixme: if resource ID is a string shall we use strcmp ??? */
265 if (lppsp->u.pszTemplate == (LPVOID)resId)
272 /******************************************************************************
275 * Convert ASCII to Unicode since all data is saved as Unicode.
277 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
282 TRACE("<%s>\n", frstr);
283 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
284 to = Alloc(len * sizeof(WCHAR));
285 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
289 /******************************************************************************
290 * PROPSHEET_CollectSheetInfoCommon
292 * Common code for PROPSHEET_CollectSheetInfoA/W
294 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
296 PROPSHEET_UnImplementedFlags(dwFlags);
298 psInfo->hasHelp = dwFlags & PSH_HASHELP;
299 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
300 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
302 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
303 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
304 psInfo->active_page = 0;
307 psInfo->hImageList = 0;
308 psInfo->activeValid = FALSE;
311 /******************************************************************************
312 * PROPSHEET_CollectSheetInfoA
314 * Collect relevant data.
316 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
317 PropSheetInfo * psInfo)
319 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
320 DWORD dwFlags = lppsh->dwFlags;
322 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
324 memcpy(&psInfo->ppshheader,lppsh,dwSize);
325 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
326 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
327 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
329 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
330 psInfo->ppshheader.pszCaption = NULL;
333 if (!IS_INTRESOURCE(lppsh->pszCaption))
335 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
336 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
338 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
339 psInfo->ppshheader.pszCaption = caption;
342 psInfo->nPages = lppsh->nPages;
344 if (dwFlags & PSH_USEPSTARTPAGE)
346 TRACE("PSH_USEPSTARTPAGE is on\n");
347 psInfo->active_page = 0;
350 psInfo->active_page = lppsh->u2.nStartPage;
352 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
355 /******************************************************************************
356 * PROPSHEET_CollectSheetInfoW
358 * Collect relevant data.
360 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
361 PropSheetInfo * psInfo)
363 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
364 DWORD dwFlags = lppsh->dwFlags;
366 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
368 memcpy(&psInfo->ppshheader,lppsh,dwSize);
369 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
370 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
372 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
373 psInfo->ppshheader.pszCaption = NULL;
376 if (!IS_INTRESOURCE(lppsh->pszCaption))
378 int len = strlenW(lppsh->pszCaption);
379 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
381 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
384 psInfo->nPages = lppsh->nPages;
386 if (dwFlags & PSH_USEPSTARTPAGE)
388 TRACE("PSH_USEPSTARTPAGE is on\n");
389 psInfo->active_page = 0;
392 psInfo->active_page = lppsh->u2.nStartPage;
394 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
397 /******************************************************************************
398 * PROPSHEET_CollectPageInfo
400 * Collect property sheet data.
401 * With code taken from DIALOG_ParseTemplate32.
403 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
404 PropSheetInfo * psInfo,
405 int index, BOOL resize)
407 const DLGTEMPLATE* pTemplate;
416 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
417 psInfo->proppage[index].hwndPage = 0;
418 psInfo->proppage[index].isDirty = FALSE;
421 * Process property page flags.
423 dwFlags = lppsp->dwFlags;
424 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
425 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
426 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
428 /* as soon as we have a page with the help flag, set the sheet flag on */
429 if (psInfo->proppage[index].hasHelp)
430 psInfo->hasHelp = TRUE;
433 * Process page template.
435 if (dwFlags & PSP_DLGINDIRECT)
436 pTemplate = lppsp->u.pResource;
437 else if(dwFlags & PSP_INTERNAL_UNICODE )
439 HRSRC hResource = FindResourceW(lppsp->hInstance,
440 lppsp->u.pszTemplate,
442 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
444 pTemplate = LockResource(hTemplate);
448 HRSRC hResource = FindResourceA(lppsp->hInstance,
449 (LPCSTR)lppsp->u.pszTemplate,
451 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
453 pTemplate = LockResource(hTemplate);
457 * Extract the size of the page and the caption.
462 p = (const WORD *)pTemplate;
464 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
466 /* DLGTEMPLATEEX (not defined in any std. header file) */
470 p += 2; /* help ID */
471 p += 2; /* ext style */
479 p += 2; /* ext style */
485 width = (WORD)*p; p++;
486 height = (WORD)*p; p++;
488 /* Special calculation for interior wizard pages so the largest page is
489 * calculated correctly. We need to add all the padding and space occupied
490 * by the header so the width and height sums up to the whole wizard client
492 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
493 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
494 !(dwFlags & PSP_HIDEHEADER))
496 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
497 width += 2 * WIZARD_PADDING;
499 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
501 height += 2 * WIZARD_PADDING;
502 width += 2 * WIZARD_PADDING;
505 /* remember the largest width and height */
508 if (width > psInfo->width)
509 psInfo->width = width;
511 if (height > psInfo->height)
512 psInfo->height = height;
525 p += lstrlenW( p ) + 1;
539 p += lstrlenW( p ) + 1;
543 /* Extract the caption */
544 psInfo->proppage[index].pszText = p;
545 TRACE("Tab %d %s\n",index,debugstr_w( p ));
546 p += lstrlenW( p ) + 1;
548 if (dwFlags & PSP_USETITLE)
552 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
556 if (IS_INTRESOURCE( lppsp->pszTitle ))
558 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle)/sizeof(szTitle[0]) ))
561 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
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))
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);
587 hIcon = lppsp->u2.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);
602 /******************************************************************************
603 * PROPSHEET_CreateDialog
605 * Creates the actual property sheet.
607 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
614 WORD resID = IDD_PROPSHEET;
617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
620 if( psInfo->unicode )
622 if(!(hRes = FindResourceW(COMCTL32_hModule,
623 MAKEINTRESOURCEW(resID),
629 if(!(hRes = FindResourceA(COMCTL32_hModule,
630 MAKEINTRESOURCEA(resID),
635 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
639 * Make a copy of the dialog template.
641 resSize = SizeofResource(COMCTL32_hModule, hRes);
643 temp = Alloc(resSize);
648 memcpy(temp, template, resSize);
650 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
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;
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
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;
682 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
683 temp, psInfo->ppshheader.hwndParent,
684 PROPSHEET_DialogProc, (LPARAM)psInfo);
685 if ( !ret ) ret = -1;
693 /******************************************************************************
694 * PROPSHEET_SizeMismatch
696 * Verify that the tab control and the "largest" property sheet page dlg. template
699 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
701 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
702 RECT rcOrigTab, rcPage;
707 GetClientRect(hwndTabCtrl, &rcOrigTab);
708 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
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) )
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);
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
744 /* Get the height of buttons */
745 GetClientRect(hwndButton, &rc);
746 buttonHeight = rc.bottom;
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);
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);
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);
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 */
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);
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);
863 int buttonWidth, buttonHeight;
864 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
866 if (psInfo->hasApply)
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);
918 x += padding.x + buttonWidth;
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);
936 ShowWindow(hwndButton, SW_HIDE);
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);
955 int buttonWidth, buttonHeight, lineHeight, lineWidth;
956 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
960 if (psInfo->hasFinish)
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);
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);
1040 ShowWindow(hwndButton, SW_HIDE);
1042 if (psInfo->ppshheader.dwFlags &
1043 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1047 * Position and resize the sunken line.
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);
1068 /******************************************************************************
1069 * PROPSHEET_GetPaddingInfo
1071 * Returns the layout information.
1073 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1075 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1078 PADDING_INFO padding;
1080 GetWindowRect(hwndTab, &rcTab);
1085 ScreenToClient(hwndDlg, &tl);
1093 /******************************************************************************
1094 * PROPSHEET_GetPaddingInfoWizard
1096 * Returns the layout information.
1097 * Vertical spacing is the distance between the line and the buttons.
1098 * Do NOT use the Help button to gather padding information when it isn't mapped
1099 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1100 * for it in this case !
1101 * FIXME: I'm not sure about any other coordinate problems with these evil
1102 * buttons. Fix it in case additional problems appear or maybe calculate
1103 * a padding in a completely different way, as this is somewhat messy.
1105 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1108 PADDING_INFO padding;
1112 POINT ptButton, ptLine;
1115 if (psInfo->hasHelp)
1121 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1123 idButton = IDC_NEXT_BUTTON;
1127 /* hopefully this is ok */
1128 idButton = IDCANCEL;
1132 hwndControl = GetDlgItem(hwndDlg, idButton);
1133 GetWindowRect(hwndControl, &rc);
1135 ptButton.x = rc.left;
1136 ptButton.y = rc.top;
1138 ScreenToClient(hwndDlg, &ptButton);
1141 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1142 GetWindowRect(hwndControl, &rc);
1145 ptLine.y = rc.bottom;
1147 ScreenToClient(hwndDlg, &ptLine);
1149 padding.y = ptButton.y - ptLine.y;
1152 ERR("padding negative ! Please report this !\n");
1154 /* this is most probably not correct, but the best we have now */
1155 padding.x = padding.y;
1159 /******************************************************************************
1160 * PROPSHEET_CreateTabControl
1162 * Insert the tabs in the tab control.
1164 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1165 const PropSheetInfo * psInfo)
1167 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1173 item.mask = TCIF_TEXT;
1174 item.cchTextMax = MAX_TABTEXT_LENGTH;
1176 nTabs = psInfo->nPages;
1179 * Set the image list for icons.
1181 if (psInfo->hImageList)
1183 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1186 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1187 for (i = 0; i < nTabs; i++)
1189 if ( psInfo->proppage[i].hasIcon )
1191 item.mask |= TCIF_IMAGE;
1192 item.iImage = iImage++;
1196 item.mask &= ~TCIF_IMAGE;
1199 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1200 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, i, (LPARAM)&item);
1202 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1207 /******************************************************************************
1208 * PROPSHEET_WizardSubclassProc
1210 * Subclassing window procedure for wizard exterior pages to prevent drawing
1211 * background and so drawing above the watermark.
1213 static LRESULT CALLBACK
1214 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1221 case WM_CTLCOLORSTATIC:
1222 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1223 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1226 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1230 * Get the size of an in-memory Template
1232 *( Based on the code of PROPSHEET_CollectPageInfo)
1233 * See also dialog.c/DIALOG_ParseTemplate32().
1236 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1239 const WORD* p = (const WORD *)pTemplate;
1240 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1246 /* DLGTEMPLATEEX (not defined in any std. header file) */
1248 TRACE("is DLGTEMPLATEEX\n");
1250 p++; /* signature */
1251 p += 2; /* help ID */
1252 p += 2; /* ext style */
1259 TRACE("is DLGTEMPLATE\n");
1261 p += 2; /* ext style */
1264 nrofitems = (WORD)*p; p++; /* nb items */
1280 TRACE("menu %s\n",debugstr_w( p ));
1281 p += lstrlenW( p ) + 1;
1292 p += 2; /* 0xffff plus predefined window class ordinal value */
1295 TRACE("class %s\n",debugstr_w( p ));
1296 p += lstrlenW( p ) + 1;
1301 TRACE("title %s\n",debugstr_w( p ));
1302 p += lstrlenW( p ) + 1;
1304 /* font, if DS_SETFONT set */
1305 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1308 p+=(istemplateex)?3:1;
1309 TRACE("font %s\n",debugstr_w( p ));
1310 p += lstrlenW( p ) + 1; /* the font name */
1313 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1314 * that are following the DLGTEMPLATE(EX) data */
1315 TRACE("%d items\n",nrofitems);
1316 while (nrofitems > 0)
1318 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1321 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1330 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1334 TRACE("class %s\n",debugstr_w( p ));
1335 p += lstrlenW( p ) + 1;
1339 /* check title text */
1346 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1350 TRACE("text %s\n",debugstr_w( p ));
1351 p += lstrlenW( p ) + 1;
1354 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1358 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1359 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1363 /******************************************************************************
1364 * PROPSHEET_CreatePage
1368 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1370 const PropSheetInfo * psInfo,
1371 LPCPROPSHEETPAGEW ppshpage)
1373 const DLGTEMPLATE* pTemplate;
1376 DLGTEMPLATE* pTemplateCopy = NULL;
1378 TRACE("index %d\n", index);
1380 if (ppshpage == NULL)
1385 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1387 pTemplate = ppshpage->u.pResource;
1388 resSize = GetTemplateSize(pTemplate);
1390 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1395 hResource = FindResourceW(ppshpage->hInstance,
1396 ppshpage->u.pszTemplate,
1401 resSize = SizeofResource(ppshpage->hInstance, hResource);
1403 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1407 pTemplate = LockResource(hTemplate);
1409 * Make a copy of the dialog template to make it writable
1417 hResource = FindResourceA(ppshpage->hInstance,
1418 (LPCSTR)ppshpage->u.pszTemplate,
1423 resSize = SizeofResource(ppshpage->hInstance, hResource);
1425 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1429 pTemplate = LockResource(hTemplate);
1431 * Make a copy of the dialog template to make it writable
1434 pTemplateCopy = Alloc(resSize);
1438 TRACE("copying pTemplate %p into pTemplateCopy %p (%d)\n", pTemplate, pTemplateCopy, resSize);
1439 memcpy(pTemplateCopy, pTemplate, resSize);
1441 if (((MyDLGTEMPLATEEX*)pTemplateCopy)->signature == 0xFFFF)
1443 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1444 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~DS_MODALFRAME;
1445 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_CAPTION;
1446 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_SYSMENU;
1447 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_POPUP;
1448 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_DISABLED;
1449 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_VISIBLE;
1450 ((MyDLGTEMPLATEEX*)pTemplateCopy)->style &= ~WS_THICKFRAME;
1452 ((MyDLGTEMPLATEEX*)pTemplateCopy)->exStyle |= WS_EX_CONTROLPARENT;
1456 pTemplateCopy->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1457 pTemplateCopy->style &= ~DS_MODALFRAME;
1458 pTemplateCopy->style &= ~WS_CAPTION;
1459 pTemplateCopy->style &= ~WS_SYSMENU;
1460 pTemplateCopy->style &= ~WS_POPUP;
1461 pTemplateCopy->style &= ~WS_DISABLED;
1462 pTemplateCopy->style &= ~WS_VISIBLE;
1463 pTemplateCopy->style &= ~WS_THICKFRAME;
1465 pTemplateCopy->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1468 if (psInfo->proppage[index].useCallback)
1469 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1470 (LPPROPSHEETPAGEW)ppshpage);
1472 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1473 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1476 ppshpage->pfnDlgProc,
1479 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1482 ppshpage->pfnDlgProc,
1484 /* Free a no more needed copy */
1485 Free(pTemplateCopy);
1487 psInfo->proppage[index].hwndPage = hwndPage;
1489 /* Subclass exterior wizard pages */
1490 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1491 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1492 (ppshpage->dwFlags & PSP_HIDEHEADER))
1494 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1495 (DWORD_PTR)ppshpage);
1497 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1498 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1503 /******************************************************************************
1504 * PROPSHEET_LoadWizardBitmaps
1506 * Loads the watermark and header bitmaps for a wizard.
1508 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1510 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1512 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1513 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1514 considers hbmWatermark as valid. */
1515 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1516 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1518 psInfo->ppshheader.u4.hbmWatermark =
1519 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1522 /* Same behavior as for watermarks */
1523 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1524 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1526 psInfo->ppshheader.u5.hbmHeader =
1527 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1533 /******************************************************************************
1534 * PROPSHEET_ShowPage
1536 * Displays or creates the specified page.
1538 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1541 HWND hwndLineHeader;
1543 LPCPROPSHEETPAGEW ppshpage;
1545 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1546 if (index == psInfo->active_page)
1548 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1549 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1553 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1554 if (psInfo->proppage[index].hwndPage == 0)
1556 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1559 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1561 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1562 psInfo->proppage[index].pszText);
1564 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1569 if (psInfo->active_page != -1)
1570 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1572 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1574 /* Synchronize current selection with tab control
1575 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1576 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1577 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1579 psInfo->active_page = index;
1580 psInfo->activeValid = TRUE;
1582 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1584 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1585 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1587 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1588 ShowWindow(hwndLineHeader, SW_HIDE);
1590 ShowWindow(hwndLineHeader, SW_SHOW);
1596 /******************************************************************************
1599 static BOOL PROPSHEET_Back(HWND hwndDlg)
1603 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1607 TRACE("active_page %d\n", psInfo->active_page);
1608 if (psInfo->active_page < 0)
1611 psn.hdr.code = PSN_WIZBACK;
1612 psn.hdr.hwndFrom = hwndDlg;
1616 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1618 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1621 else if (result == 0)
1622 idx = psInfo->active_page - 1;
1624 idx = PROPSHEET_FindPageByResId(psInfo, result);
1626 if (idx >= 0 && idx < psInfo->nPages)
1628 if (PROPSHEET_CanSetCurSel(hwndDlg))
1630 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1631 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1632 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1638 /******************************************************************************
1641 static BOOL PROPSHEET_Next(HWND hwndDlg)
1645 LRESULT msgResult = 0;
1646 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
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)
1672 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1673 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1674 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1681 /******************************************************************************
1684 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1688 LRESULT msgResult = 0;
1689 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1691 TRACE("active_page %d\n", psInfo->active_page);
1692 if (psInfo->active_page < 0)
1695 psn.hdr.code = PSN_WIZFINISH;
1696 psn.hdr.hwndFrom = hwndDlg;
1700 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1702 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1704 TRACE("msg result %ld\n", msgResult);
1709 if (psInfo->result == 0)
1710 psInfo->result = IDOK;
1711 if (psInfo->isModeless)
1712 psInfo->activeValid = FALSE;
1714 psInfo->ended = TRUE;
1719 /******************************************************************************
1722 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1727 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1729 TRACE("active_page %d\n", psInfo->active_page);
1730 if (psInfo->active_page < 0)
1733 psn.hdr.hwndFrom = hwndDlg;
1739 * Send PSN_KILLACTIVE to the current page.
1741 psn.hdr.code = PSN_KILLACTIVE;
1743 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1745 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1749 * Send PSN_APPLY to all pages.
1751 psn.hdr.code = PSN_APPLY;
1752 psn.lParam = lParam;
1754 for (i = 0; i < psInfo->nPages; i++)
1756 hwndPage = psInfo->proppage[i].hwndPage;
1759 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1761 case PSNRET_INVALID:
1762 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1764 case PSNRET_INVALID_NOCHANGEPAGE:
1772 psInfo->activeValid = FALSE;
1774 else if(psInfo->active_page >= 0)
1776 psn.hdr.code = PSN_SETACTIVE;
1778 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1779 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1785 /******************************************************************************
1788 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1790 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1795 TRACE("active_page %d\n", psInfo->active_page);
1796 if (psInfo->active_page < 0)
1799 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1800 psn.hdr.code = PSN_QUERYCANCEL;
1801 psn.hdr.hwndFrom = hwndDlg;
1805 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1808 psn.hdr.code = PSN_RESET;
1809 psn.lParam = lParam;
1811 for (i = 0; i < psInfo->nPages; i++)
1813 hwndPage = psInfo->proppage[i].hwndPage;
1816 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1819 if (psInfo->isModeless)
1821 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1822 psInfo->activeValid = FALSE;
1825 psInfo->ended = TRUE;
1828 /******************************************************************************
1831 static void PROPSHEET_Help(HWND hwndDlg)
1833 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1837 TRACE("active_page %d\n", psInfo->active_page);
1838 if (psInfo->active_page < 0)
1841 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1842 psn.hdr.code = PSN_HELP;
1843 psn.hdr.hwndFrom = hwndDlg;
1847 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1850 /******************************************************************************
1853 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1856 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1859 if (!psInfo) return;
1861 * Set the dirty flag of this page.
1863 for (i = 0; i < psInfo->nPages; i++)
1865 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1866 psInfo->proppage[i].isDirty = TRUE;
1870 * Enable the Apply button.
1872 if (psInfo->hasApply)
1874 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1876 EnableWindow(hwndApplyBtn, TRUE);
1880 /******************************************************************************
1881 * PROPSHEET_UnChanged
1883 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1886 BOOL noPageDirty = TRUE;
1887 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1888 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
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 = GetPropW(hwndDlg, PropSheetInfoStr);
1971 TRACE("active_page %d\n", psInfo->active_page);
1972 if (psInfo->active_page < 0)
1979 * Notify the current page.
1981 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1982 psn.hdr.code = PSN_KILLACTIVE;
1983 psn.hdr.hwndFrom = hwndDlg;
1987 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1990 TRACE("<-- %d\n", res);
1994 /******************************************************************************
1995 * PROPSHEET_SetCurSel
1997 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2000 HPROPSHEETPAGE hpage
2003 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2004 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2005 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2007 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2008 /* hpage takes precedence over index */
2010 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2012 if (index < 0 || index >= psInfo->nPages)
2014 TRACE("Could not find page to select!\n");
2018 /* unset active page while doing this transition. */
2019 if (psInfo->active_page != -1)
2020 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2021 psInfo->active_page = -1;
2027 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2030 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2032 psn.hdr.code = PSN_SETACTIVE;
2033 psn.hdr.hwndFrom = hwndDlg;
2037 if (!psInfo->proppage[index].hwndPage) {
2038 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2041 /* Resize the property sheet page to the fit in the Tab control
2042 * (for regular property sheets) or to fit in the client area (for
2044 * NOTE: The resizing happens every time the page is selected and
2045 * not only when it's created (some applications depend on it). */
2046 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2047 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2048 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2049 rc.right - rc.left, rc.bottom - rc.top);
2050 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2052 rc.right - rc.left, rc.bottom - rc.top, 0);
2054 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2061 WARN("Tried to skip before first property sheet page!\n");
2064 if (index >= psInfo->nPages) {
2065 WARN("Tried to skip after last property sheet page!\n");
2066 index = psInfo->nPages-1;
2070 else if (result != 0)
2072 int old_index = index;
2073 index = PROPSHEET_FindPageByResId(psInfo, result);
2074 if(index >= psInfo->nPages) {
2076 WARN("Tried to skip to nonexistent page by res id\n");
2083 /* Invalidate the header area */
2084 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2085 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2087 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2090 GetClientRect(hwndLineHeader, &r);
2091 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2092 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2094 InvalidateRect(hwndDlg, &r, TRUE);
2098 * Display the new page.
2100 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2102 if (psInfo->proppage[index].hasHelp)
2103 EnableWindow(hwndHelp, TRUE);
2105 EnableWindow(hwndHelp, FALSE);
2110 /******************************************************************************
2111 * PROPSHEET_SetCurSelId
2113 * Selects the page, specified by resource id.
2115 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2118 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2120 idx = PROPSHEET_FindPageByResId(psInfo, id);
2121 if (idx < psInfo->nPages )
2123 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2124 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2128 /******************************************************************************
2129 * PROPSHEET_SetTitleA
2131 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2133 if(!IS_INTRESOURCE(lpszText))
2136 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2137 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2138 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2142 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2146 /******************************************************************************
2147 * PROPSHEET_SetTitleW
2149 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2151 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2154 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2155 if (IS_INTRESOURCE(lpszText)) {
2156 if (!LoadStringW(psInfo->ppshheader.hInstance,
2157 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2161 if (dwStyle & PSH_PROPTITLE)
2164 int lentitle = strlenW(lpszText);
2165 int lenprop = strlenW(psInfo->strPropertiesFor);
2167 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2168 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2170 SetWindowTextW(hwndDlg, dest);
2174 SetWindowTextW(hwndDlg, lpszText);
2177 /******************************************************************************
2178 * PROPSHEET_SetFinishTextA
2180 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2182 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2183 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2185 TRACE("'%s'\n", lpszText);
2186 /* Set text, show and enable the Finish button */
2187 SetWindowTextA(hwndButton, lpszText);
2188 ShowWindow(hwndButton, SW_SHOW);
2189 EnableWindow(hwndButton, TRUE);
2191 /* Make it default pushbutton */
2192 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2194 /* Hide Back button */
2195 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2196 ShowWindow(hwndButton, SW_HIDE);
2198 if (!psInfo->hasFinish)
2200 /* Hide Next button */
2201 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2202 ShowWindow(hwndButton, SW_HIDE);
2206 /******************************************************************************
2207 * PROPSHEET_SetFinishTextW
2209 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2211 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2212 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2214 TRACE("%s\n", debugstr_w(lpszText));
2215 /* Set text, show and enable the Finish button */
2216 SetWindowTextW(hwndButton, lpszText);
2217 ShowWindow(hwndButton, SW_SHOW);
2218 EnableWindow(hwndButton, TRUE);
2220 /* Make it default pushbutton */
2221 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2223 /* Hide Back button */
2224 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2225 ShowWindow(hwndButton, SW_HIDE);
2227 if (!psInfo->hasFinish)
2229 /* Hide Next button */
2230 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2231 ShowWindow(hwndButton, SW_HIDE);
2235 /******************************************************************************
2236 * PROPSHEET_QuerySiblings
2238 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2239 WPARAM wParam, LPARAM lParam)
2243 LRESULT msgResult = 0;
2244 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2246 while ((i < psInfo->nPages) && (msgResult == 0))
2248 hwndPage = psInfo->proppage[i].hwndPage;
2249 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2257 /******************************************************************************
2260 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2261 HPROPSHEETPAGE hpage)
2264 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2265 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2267 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2269 TRACE("hpage %p\n", hpage);
2271 * Allocate and fill in a new PropPageInfo entry.
2273 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2277 psInfo->proppage = ppi;
2278 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
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 = GetPropW(hwndDlg, PropSheetInfoStr);
2326 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2327 PropPageInfo* oldPages;
2329 TRACE("index %d, hpage %p\n", index, hpage);
2334 * hpage takes precedence over index.
2338 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2341 /* Make sure that index is within range */
2342 if (index < 0 || index >= psInfo->nPages)
2344 TRACE("Could not find page to remove!\n");
2348 TRACE("total pages %d removing page %d active page %d\n",
2349 psInfo->nPages, index, psInfo->active_page);
2351 * Check if we're removing the active page.
2353 if (index == psInfo->active_page)
2355 if (psInfo->nPages > 1)
2359 /* activate previous page */
2360 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2364 /* activate the next page */
2365 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2366 psInfo->active_page = index;
2371 psInfo->active_page = -1;
2372 if (!psInfo->isModeless)
2374 psInfo->ended = TRUE;
2379 else if (index < psInfo->active_page)
2380 psInfo->active_page--;
2382 /* Unsubclass the page dialog window */
2383 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2384 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2385 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2387 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2388 PROPSHEET_WizardSubclassProc, 1);
2391 /* Destroy page dialog window */
2392 DestroyWindow(psInfo->proppage[index].hwndPage);
2394 /* Free page resources */
2395 if(psInfo->proppage[index].hpage)
2397 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2399 if (psp->dwFlags & PSP_USETITLE)
2400 Free ((LPVOID)psInfo->proppage[index].pszText);
2402 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2405 /* Remove the tab */
2406 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2408 oldPages = psInfo->proppage;
2410 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2413 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2415 if (index < psInfo->nPages)
2416 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2417 (psInfo->nPages - index) * sizeof(PropPageInfo));
2424 /******************************************************************************
2425 * PROPSHEET_SetWizButtons
2427 * This code will work if (and assumes that) the Next button is on top of the
2428 * Finish button. ie. Finish comes after Next in the Z order.
2429 * This means make sure the dialog template reflects this.
2432 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2434 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2435 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2436 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2437 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2439 TRACE("%d\n", dwFlags);
2441 EnableWindow(hwndBack, FALSE);
2442 EnableWindow(hwndNext, FALSE);
2443 EnableWindow(hwndFinish, FALSE);
2445 /* set the default pushbutton to an enabled button */
2446 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2447 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2448 else if (dwFlags & PSWIZB_NEXT)
2449 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2450 else if (dwFlags & PSWIZB_BACK)
2451 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2453 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2456 if (dwFlags & PSWIZB_BACK)
2457 EnableWindow(hwndBack, TRUE);
2459 if (dwFlags & PSWIZB_NEXT)
2460 EnableWindow(hwndNext, TRUE);
2462 if (!psInfo->hasFinish)
2464 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2466 /* Hide the Next button */
2467 ShowWindow(hwndNext, SW_HIDE);
2469 /* Show the Finish button */
2470 ShowWindow(hwndFinish, SW_SHOW);
2472 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2473 EnableWindow(hwndFinish, TRUE);
2477 /* Hide the Finish button */
2478 ShowWindow(hwndFinish, SW_HIDE);
2479 /* Show the Next button */
2480 ShowWindow(hwndNext, SW_SHOW);
2483 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2484 EnableWindow(hwndFinish, TRUE);
2487 /******************************************************************************
2488 * PROPSHEET_InsertPage
2490 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2492 if (IS_INTRESOURCE(hpageInsertAfter))
2493 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2495 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2499 /******************************************************************************
2500 * PROPSHEET_SetHeaderTitleW
2502 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2504 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2507 /******************************************************************************
2508 * PROPSHEET_SetHeaderTitleA
2510 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2512 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2515 /******************************************************************************
2516 * PROPSHEET_SetHeaderSubTitleW
2518 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2520 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2523 /******************************************************************************
2524 * PROPSHEET_SetHeaderSubTitleA
2526 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2528 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2531 /******************************************************************************
2532 * PROPSHEET_HwndToIndex
2534 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2537 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2539 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2541 for (index = 0; index < psInfo->nPages; index++)
2542 if (psInfo->proppage[index].hwndPage == hPageDlg)
2544 WARN("%p not found\n", hPageDlg);
2548 /******************************************************************************
2549 * PROPSHEET_IndexToHwnd
2551 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2553 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2554 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2557 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2558 WARN("%d out of range.\n", iPageIndex);
2561 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2564 /******************************************************************************
2565 * PROPSHEET_PageToIndex
2567 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2570 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2572 TRACE("(%p, %p)\n", hwndDlg, hPage);
2574 for (index = 0; index < psInfo->nPages; index++)
2575 if (psInfo->proppage[index].hpage == hPage)
2577 WARN("%p not found\n", hPage);
2581 /******************************************************************************
2582 * PROPSHEET_IndexToPage
2584 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2586 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2587 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2588 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2589 WARN("%d out of range.\n", iPageIndex);
2592 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2595 /******************************************************************************
2596 * PROPSHEET_IdToIndex
2598 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2601 LPCPROPSHEETPAGEW psp;
2602 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2603 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2604 for (index = 0; index < psInfo->nPages; index++) {
2605 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2606 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2613 /******************************************************************************
2614 * PROPSHEET_IndexToId
2616 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2618 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2619 LPCPROPSHEETPAGEW psp;
2620 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2621 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2622 WARN("%d out of range.\n", iPageIndex);
2625 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2626 if (psp->dwFlags & PSP_DLGINDIRECT || !IS_INTRESOURCE(psp->u.pszTemplate)) {
2629 return (LRESULT)psp->u.pszTemplate;
2632 /******************************************************************************
2633 * PROPSHEET_GetResult
2635 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2637 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2638 return psInfo->result;
2641 /******************************************************************************
2642 * PROPSHEET_RecalcPageSizes
2644 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2646 FIXME("(%p): stub\n", hwndDlg);
2650 /******************************************************************************
2651 * PROPSHEET_GetPageIndex
2653 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2654 * the array of PropPageInfo.
2656 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2661 TRACE("hpage %p\n", hpage);
2662 while ((index < psInfo->nPages) && (found == FALSE))
2664 if (psInfo->proppage[index].hpage == hpage)
2676 /******************************************************************************
2679 static void PROPSHEET_CleanUp(HWND hwndDlg)
2682 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2685 if (!psInfo) return;
2686 if (!IS_INTRESOURCE(psInfo->ppshheader.pszCaption))
2687 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2689 for (i = 0; i < psInfo->nPages; i++)
2691 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2693 /* Unsubclass the page dialog window */
2694 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2695 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2696 (psp->dwFlags & PSP_HIDEHEADER))
2698 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2699 PROPSHEET_WizardSubclassProc, 1);
2702 if(psInfo->proppage[i].hwndPage)
2703 DestroyWindow(psInfo->proppage[i].hwndPage);
2707 if (psp->dwFlags & PSP_USETITLE)
2708 Free ((LPVOID)psInfo->proppage[i].pszText);
2710 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2714 DeleteObject(psInfo->hFont);
2715 DeleteObject(psInfo->hFontBold);
2716 /* If we created the bitmaps, destroy them */
2717 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2718 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2719 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2720 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2721 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2722 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2724 Free(psInfo->proppage);
2725 Free(psInfo->strPropertiesFor);
2726 ImageList_Destroy(psInfo->hImageList);
2731 static INT do_loop(const PropSheetInfo *psInfo)
2735 HWND hwnd = psInfo->hwnd;
2737 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2742 if(!IsDialogMessageW(hwnd, &msg))
2744 TranslateMessage(&msg);
2745 DispatchMessageW(&msg);
2751 PostQuitMessage(msg.wParam);
2756 ret = psInfo->result;
2758 DestroyWindow(hwnd);
2762 /******************************************************************************
2763 * PROPSHEET_PropertySheet
2765 * Common code between PropertySheetA/W
2767 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2771 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2772 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2774 psInfo->unicode = unicode;
2775 psInfo->ended = FALSE;
2777 if(!psInfo->isModeless)
2779 parent = psInfo->ppshheader.hwndParent;
2780 if (parent) EnableWindow(parent, FALSE);
2782 bRet = PROPSHEET_CreateDialog(psInfo);
2783 if(!psInfo->isModeless)
2785 bRet = do_loop(psInfo);
2786 if (parent) EnableWindow(parent, TRUE);
2791 /******************************************************************************
2792 * PropertySheet (COMCTL32.@)
2793 * PropertySheetA (COMCTL32.@)
2795 * Creates a property sheet in the specified property sheet header.
2798 * Modal property sheets: Positive if successful or -1 otherwise.
2799 * Modeless property sheets: Property sheet handle.
2801 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2802 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2804 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2806 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2810 TRACE("(%p)\n", lppsh);
2812 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2814 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2815 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2817 for (n = i = 0; i < lppsh->nPages; i++, n++)
2819 if (!psInfo->usePropPage)
2820 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2823 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2824 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2827 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2830 if (psInfo->usePropPage)
2831 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2837 return PROPSHEET_PropertySheet(psInfo, FALSE);
2840 /******************************************************************************
2841 * PropertySheetW (COMCTL32.@)
2843 * See PropertySheetA.
2845 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2847 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2851 TRACE("(%p)\n", lppsh);
2853 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2855 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2856 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2858 for (n = i = 0; i < lppsh->nPages; i++, n++)
2860 if (!psInfo->usePropPage)
2861 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2864 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2865 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2868 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2871 if (psInfo->usePropPage)
2872 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2878 return PROPSHEET_PropertySheet(psInfo, TRUE);
2881 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2885 if (IS_INTRESOURCE(str))
2890 WORD i, id = LOWORD(str);
2893 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2895 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2896 if (!(ptr = LockResource( hmem ))) return NULL;
2897 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2899 if (!len) return NULL;
2900 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2903 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2909 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2911 if (ret) memcpy( ret, str, len );
2917 /******************************************************************************
2918 * CreatePropertySheetPage (COMCTL32.@)
2919 * CreatePropertySheetPageA (COMCTL32.@)
2921 * Creates a new property sheet page.
2924 * Success: Handle to new property sheet page.
2928 * An application must use the PSM_ADDPAGE message to add the new page to
2929 * an existing property sheet.
2931 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2932 LPCPROPSHEETPAGEA lpPropSheetPage)
2934 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2936 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2938 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2940 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2942 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
2944 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2945 char *template = Alloc( len );
2947 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2951 if (ppsp->dwFlags & PSP_USEICONID)
2953 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
2954 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2957 if (ppsp->dwFlags & PSP_USETITLE)
2959 if (!IS_INTRESOURCE( ppsp->pszTitle ))
2960 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2962 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2965 ppsp->pszTitle = NULL;
2967 if (ppsp->dwFlags & PSP_HIDEHEADER)
2968 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
2970 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
2972 if (!IS_INTRESOURCE( ppsp->pszHeaderTitle ))
2973 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
2975 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
2978 ppsp->pszHeaderTitle = NULL;
2980 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
2982 if (!IS_INTRESOURCE( ppsp->pszHeaderSubTitle ))
2983 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
2985 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
2988 ppsp->pszHeaderSubTitle = NULL;
2990 return (HPROPSHEETPAGE)ppsp;
2993 /******************************************************************************
2994 * CreatePropertySheetPageW (COMCTL32.@)
2996 * See CreatePropertySheetA.
2998 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3000 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3002 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3004 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3006 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3008 if (!IS_INTRESOURCE( ppsp->u.pszTemplate ))
3010 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3011 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3013 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3017 if ( ppsp->dwFlags & PSP_USEICONID )
3019 if (!IS_INTRESOURCE( ppsp->u2.pszIcon ))
3021 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3022 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3024 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3028 if (ppsp->dwFlags & PSP_USETITLE)
3029 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3031 ppsp->pszTitle = NULL;
3033 if (ppsp->dwFlags & PSP_HIDEHEADER)
3034 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3036 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3037 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3039 ppsp->pszHeaderTitle = NULL;
3041 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3042 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3044 ppsp->pszHeaderSubTitle = NULL;
3046 return (HPROPSHEETPAGE)ppsp;
3049 /******************************************************************************
3050 * DestroyPropertySheetPage (COMCTL32.@)
3052 * Destroys a property sheet page previously created with
3053 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3060 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3062 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3067 if (!(psp->dwFlags & PSP_DLGINDIRECT) && !IS_INTRESOURCE( psp->u.pszTemplate ))
3068 Free ((LPVOID)psp->u.pszTemplate);
3070 if ((psp->dwFlags & PSP_USEICONID) && !IS_INTRESOURCE( psp->u2.pszIcon ))
3071 Free ((LPVOID)psp->u2.pszIcon);
3073 if ((psp->dwFlags & PSP_USETITLE) && !IS_INTRESOURCE( psp->pszTitle ))
3074 Free ((LPVOID)psp->pszTitle);
3081 /******************************************************************************
3082 * PROPSHEET_IsDialogMessage
3084 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3086 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3089 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3092 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3095 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3097 if (!(dlgCode & DLGC_WANTMESSAGE))
3099 switch (lpMsg->wParam)
3102 if (GetKeyState(VK_SHIFT) & 0x8000)
3108 case VK_NEXT: new_page = 1; break;
3109 case VK_PRIOR: new_page = -1; break;
3115 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3117 new_page += psInfo->active_page;
3120 new_page = psInfo->nPages - 1;
3121 else if (new_page >= psInfo->nPages)
3124 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3131 return IsDialogMessageW(hwnd, lpMsg);
3134 /******************************************************************************
3135 * PROPSHEET_DoCommand
3137 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3143 case IDC_APPLY_BUTTON:
3145 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3147 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3152 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3154 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3155 if (psInfo->result == 0)
3156 psInfo->result = IDOK;
3158 if (psInfo->isModeless)
3159 psInfo->activeValid = FALSE;
3161 psInfo->ended = TRUE;
3164 EnableWindow(hwndApplyBtn, FALSE);
3169 case IDC_BACK_BUTTON:
3170 PROPSHEET_Back(hwnd);
3173 case IDC_NEXT_BUTTON:
3174 PROPSHEET_Next(hwnd);
3177 case IDC_FINISH_BUTTON:
3178 PROPSHEET_Finish(hwnd);
3182 PROPSHEET_Cancel(hwnd, 0);
3186 PROPSHEET_Help(hwnd);
3196 /******************************************************************************
3199 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3201 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3206 HPALETTE hOldPal = 0;
3210 LPCPROPSHEETPAGEW ppshpage;
3211 WCHAR szBuffer[256];
3214 if (psInfo->active_page < 0) return 1;
3215 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3218 hdcSrc = CreateCompatibleDC(0);
3219 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3221 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3222 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3224 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3225 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3226 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3228 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3230 COLORREF clrOld = 0;
3233 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3234 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3236 GetClientRect(hwndLineHeader, &r);
3237 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3238 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3240 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3242 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3244 /* Fill the unoccupied part of the header with color of the
3245 * left-top pixel, but do it only when needed.
3247 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3249 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3250 CopyRect(&r, &rzone);
3251 if (bm.bmWidth < r.right)
3253 r.left = bm.bmWidth;
3254 FillRect(hdc, &r, hbr);
3256 if (bm.bmHeight < r.bottom)
3259 r.top = bm.bmHeight;
3260 FillRect(hdc, &r, hbr);
3265 /* Draw the header itself. */
3267 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3268 hdcSrc, 0, 0, SRCCOPY);
3273 hbr = GetSysColorBrush(COLOR_WINDOW);
3274 FillRect(hdc, &rzone, hbr);
3276 /* Draw the header bitmap. It's always centered like a
3277 * common 49 x 49 bitmap. */
3278 margin = (rzone.bottom - 49) / 2;
3279 BitBlt(hdc, rzone.right - 49 - margin, margin,
3280 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3281 hdcSrc, 0, 0, SRCCOPY);
3283 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3284 * if its height is smaller than 49 pixels. Because the reason
3285 * for this bug is unknown the current code doesn't try to
3289 clrOld = SetTextColor (hdc, 0x00000000);
3290 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3292 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3293 SetRect(&r, 20, 10, 0, 0);
3294 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3295 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3298 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3302 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3307 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3308 SelectObject(hdc, psInfo->hFont);
3309 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3310 if (!IS_INTRESOURCE(ppshpage->pszHeaderTitle))
3311 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3314 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3318 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3323 offsety = rzone.bottom + 2;
3325 SetTextColor(hdc, clrOld);
3326 SetBkMode(hdc, oldBkMode);
3327 SelectObject(hdc, hOldFont);
3328 SelectObject(hdcSrc, hbmp);
3331 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3332 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3333 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3335 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3337 GetClientRect(hwndLine, &r);
3338 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3342 rzone.right = r.right;
3343 rzone.bottom = r.top - 1;
3345 hbr = GetSysColorBrush(COLOR_WINDOW);
3346 FillRect(hdc, &rzone, hbr);
3348 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3349 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3351 /* The watermark is truncated to a width of 164 pixels */
3352 r.right = min(r.right, 164);
3353 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3354 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3356 /* If the bitmap is not big enough, fill the remaining area
3357 with the color of pixel (0,0) of bitmap - see MSDN */
3358 if (r.top > bm.bmHeight) {
3359 r.bottom = r.top - 1;
3360 r.top = bm.bmHeight;
3362 r.right = bm.bmWidth;
3363 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3364 FillRect(hdc, &r, hbr);
3368 SelectObject(hdcSrc, hbmp);
3371 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3372 SelectPalette(hdc, hOldPal, FALSE);
3376 if (!hdcParam) EndPaint(hwnd, &ps);
3381 /******************************************************************************
3382 * PROPSHEET_DialogProc
3384 static INT_PTR CALLBACK
3385 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3387 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3388 hwnd, uMsg, wParam, lParam);
3394 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3395 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3396 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3400 /* Using PropSheetInfoStr to store extra data doesn't match the native
3401 * common control: native uses TCM_[GS]ETITEM
3403 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3406 * psInfo->hwnd is not being used by WINE code - it exists
3407 * for compatibility with "real" Windoze. The same about
3408 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3411 psInfo->hwnd = hwnd;
3412 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3414 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3416 /* set up the Next and Back buttons by default */
3417 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3418 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3421 SetFocus(GetDlgItem(hwnd, IDOK));
3424 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3425 psInfo->hFont = CreateFontIndirectW (&logFont);
3426 logFont.lfWeight = FW_BOLD;
3427 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3430 * Small icon in the title bar.
3432 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3433 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3436 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3437 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3439 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3440 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3441 psInfo->ppshheader.u.pszIcon,
3446 hIcon = psInfo->ppshheader.u.hIcon;
3448 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3451 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3452 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3454 psInfo->strPropertiesFor = strCaption;
3456 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3458 PROPSHEET_CreateTabControl(hwnd, psInfo);
3460 PROPSHEET_LoadWizardBitmaps(psInfo);
3462 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3464 ShowWindow(hwndTabCtrl, SW_HIDE);
3465 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3466 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3470 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3472 PROPSHEET_AdjustSize(hwnd, psInfo);
3473 PROPSHEET_AdjustButtons(hwnd, psInfo);
3477 if (IS_INTRESOURCE(psInfo->ppshheader.pszCaption) &&
3478 psInfo->ppshheader.hInstance)
3482 if (LoadStringW(psInfo->ppshheader.hInstance,
3483 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3484 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3488 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3489 psInfo->ppshheader.pszCaption);
3493 if (psInfo->useCallback)
3494 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3496 idx = psInfo->active_page;
3497 psInfo->active_page = -1;
3499 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3501 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3502 * as some programs call TCM_GETCURSEL to get the current selection
3503 * from which to switch to the next page */
3504 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3506 PROPSHEET_UnChanged(hwnd, NULL);
3508 /* wizards set their focus during init */
3509 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3515 case WM_PRINTCLIENT:
3517 PROPSHEET_Paint(hwnd, (HDC)wParam);
3521 PROPSHEET_CleanUp(hwnd);
3525 PROPSHEET_Cancel(hwnd, 1);
3526 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3529 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3531 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3536 /* No default handler, forward notification to active page */
3537 if (psInfo->activeValid && psInfo->active_page != -1)
3539 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3540 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3547 NMHDR* pnmh = (LPNMHDR) lParam;
3549 if (pnmh->code == TCN_SELCHANGE)
3551 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3552 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3555 if(pnmh->code == TCN_SELCHANGING)
3557 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3558 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3565 case WM_SYSCOLORCHANGE:
3566 COMCTL32_RefreshSysColors();
3569 case PSM_GETCURRENTPAGEHWND:
3571 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3577 if (psInfo->activeValid && psInfo->active_page != -1)
3578 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3580 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3586 PROPSHEET_Changed(hwnd, (HWND)wParam);
3590 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3593 case PSM_GETTABCONTROL:
3595 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3597 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3606 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3607 if(msgResult != FALSE)
3609 msgResult = PROPSHEET_SetCurSel(hwnd,
3612 (HPROPSHEETPAGE)lParam);
3615 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3620 case PSM_CANCELTOCLOSE:
3622 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3623 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3624 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3626 EnableWindow(hwndCancel, FALSE);
3627 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)/sizeof(buf[0])))
3628 SetWindowTextW(hwndOK, buf);
3633 case PSM_RESTARTWINDOWS:
3635 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3640 /* reboot system takes precedence over restart windows */
3641 if (psInfo->result != ID_PSREBOOTSYSTEM)
3642 psInfo->result = ID_PSRESTARTWINDOWS;
3647 case PSM_REBOOTSYSTEM:
3649 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3654 psInfo->result = ID_PSREBOOTSYSTEM;
3660 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3664 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3669 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3671 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3676 case PSM_QUERYSIBLINGS:
3678 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3680 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3688 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3689 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3690 * on success or FALSE otherwise, as specified on MSDN Online.
3691 * Also see the MFC code for
3692 * CPropertySheet::AddPage(CPropertyPage* pPage).
3695 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3697 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3702 case PSM_REMOVEPAGE:
3703 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3706 case PSM_ISDIALOGMESSAGE:
3708 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3709 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3713 case PSM_PRESSBUTTON:
3714 PROPSHEET_PressButton(hwnd, (int)wParam);
3717 case PSM_SETFINISHTEXTA:
3718 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3721 case PSM_SETWIZBUTTONS:
3722 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3725 case PSM_SETCURSELID:
3726 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3729 case PSM_SETFINISHTEXTW:
3730 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3733 case PSM_INSERTPAGE:
3735 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3736 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3740 case PSM_SETHEADERTITLEW:
3741 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3744 case PSM_SETHEADERTITLEA:
3745 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3748 case PSM_SETHEADERSUBTITLEW:
3749 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3752 case PSM_SETHEADERSUBTITLEA:
3753 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3756 case PSM_HWNDTOINDEX:
3758 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3759 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3763 case PSM_INDEXTOHWND:
3765 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3766 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3770 case PSM_PAGETOINDEX:
3772 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3773 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3777 case PSM_INDEXTOPAGE:
3779 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3780 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3786 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3787 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3793 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3794 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3800 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3801 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3805 case PSM_RECALCPAGESIZES:
3807 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3808 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);