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
37 * o PSM_RECALCPAGESIZES
38 * o PSM_SETHEADERSUBTITLE
39 * o PSM_SETHEADERTITLE
44 * o PSN_QUERYINITIALFOCUS
45 * o PSN_TRANSLATEACCELERATOR
48 * o PSH_STRETCHWATERMARK
52 * o PSP_USEFUSIONCONTEXT
59 #define NONAMELESSUNION
60 #define NONAMELESSSTRUCT
71 #include "wine/debug.h"
72 #include "wine/unicode.h"
74 /******************************************************************************
98 } MyDLGITEMTEMPLATEEX;
101 typedef struct tagPropPageInfo
103 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
112 typedef struct tagPropSheetInfo
115 PROPSHEETHEADERW ppshheader;
117 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, 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(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)
281 TRACE("<%s>\n", frstr);
282 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
283 *tostr = Alloc(len * sizeof(WCHAR));
284 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
287 /******************************************************************************
288 * PROPSHEET_CollectSheetInfoA
290 * Collect relevant data.
292 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
293 PropSheetInfo * psInfo)
295 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
296 DWORD dwFlags = lppsh->dwFlags;
298 psInfo->hasHelp = dwFlags & PSH_HASHELP;
299 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
300 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
301 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
302 psInfo->isModeless = dwFlags & PSH_MODELESS;
304 memcpy(&psInfo->ppshheader,lppsh,dwSize);
305 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",
306 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
307 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
309 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
311 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
312 psInfo->ppshheader.pszCaption = NULL;
315 if (HIWORD(lppsh->pszCaption))
317 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
318 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
319 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
322 psInfo->nPages = lppsh->nPages;
324 if (dwFlags & PSH_USEPSTARTPAGE)
326 TRACE("PSH_USEPSTARTPAGE is on\n");
327 psInfo->active_page = 0;
330 psInfo->active_page = lppsh->u2.nStartPage;
332 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
333 psInfo->active_page = 0;
336 psInfo->hImageList = 0;
337 psInfo->activeValid = FALSE;
342 /******************************************************************************
343 * PROPSHEET_CollectSheetInfoW
345 * Collect relevant data.
347 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
348 PropSheetInfo * psInfo)
350 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
351 DWORD dwFlags = lppsh->dwFlags;
353 psInfo->hasHelp = dwFlags & PSH_HASHELP;
354 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
355 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
356 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
357 psInfo->isModeless = dwFlags & PSH_MODELESS;
359 memcpy(&psInfo->ppshheader,lppsh,dwSize);
360 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",
361 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
363 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
365 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
366 psInfo->ppshheader.pszCaption = NULL;
369 if (HIWORD(lppsh->pszCaption))
371 int len = strlenW(lppsh->pszCaption);
372 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
373 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
376 psInfo->nPages = lppsh->nPages;
378 if (dwFlags & PSH_USEPSTARTPAGE)
380 TRACE("PSH_USEPSTARTPAGE is on\n");
381 psInfo->active_page = 0;
384 psInfo->active_page = lppsh->u2.nStartPage;
386 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
387 psInfo->active_page = 0;
390 psInfo->hImageList = 0;
391 psInfo->activeValid = FALSE;
396 /******************************************************************************
397 * PROPSHEET_CollectPageInfo
399 * Collect property sheet data.
400 * With code taken from DIALOG_ParseTemplate32.
402 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
403 PropSheetInfo * psInfo,
406 DLGTEMPLATE* pTemplate;
415 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
416 psInfo->proppage[index].hwndPage = 0;
417 psInfo->proppage[index].isDirty = FALSE;
420 * Process property page flags.
422 dwFlags = lppsp->dwFlags;
423 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
424 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
425 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
427 /* as soon as we have a page with the help flag, set the sheet flag on */
428 if (psInfo->proppage[index].hasHelp)
429 psInfo->hasHelp = TRUE;
432 * Process page template.
434 if (dwFlags & PSP_DLGINDIRECT)
435 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
436 else if(dwFlags & PSP_INTERNAL_UNICODE )
438 HRSRC hResource = FindResourceW(lppsp->hInstance,
439 lppsp->u.pszTemplate,
441 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
443 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
447 HRSRC hResource = FindResourceA(lppsp->hInstance,
448 (LPCSTR)lppsp->u.pszTemplate,
450 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
452 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
456 * Extract the size of the page and the caption.
461 p = (const WORD *)pTemplate;
463 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
465 /* DLGTEMPLATEEX (not defined in any std. header file) */
469 p += 2; /* help ID */
470 p += 2; /* ext style */
478 p += 2; /* ext style */
484 width = (WORD)*p; p++;
485 height = (WORD)*p; p++;
487 /* Special calculation for interior wizard pages so the largest page is
488 * calculated correctly. We need to add all the padding and space occupied
489 * by the header so the width and height sums up to the whole wizard client
491 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
492 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
493 !(dwFlags & PSP_HIDEHEADER))
495 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
496 width += 2 * WIZARD_PADDING;
498 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
500 height += 2 * WIZARD_PADDING;
501 width += 2 * WIZARD_PADDING;
504 /* remember the largest width and height */
505 if (width > psInfo->width)
506 psInfo->width = width;
508 if (height > psInfo->height)
509 psInfo->height = height;
521 p += lstrlenW( (LPCWSTR)p ) + 1;
535 p += lstrlenW( (LPCWSTR)p ) + 1;
539 /* Extract the caption */
540 psInfo->proppage[index].pszText = (LPCWSTR)p;
541 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
542 p += lstrlenW((LPCWSTR)p) + 1;
544 if (dwFlags & PSP_USETITLE)
548 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
551 if ( !HIWORD( lppsp->pszTitle ) )
553 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
556 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
562 pTitle = lppsp->pszTitle;
564 len = strlenW(pTitle);
565 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
566 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
570 * Build the image list for icons
572 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
575 int icon_cx = GetSystemMetrics(SM_CXSMICON);
576 int icon_cy = GetSystemMetrics(SM_CYSMICON);
578 if (dwFlags & PSP_USEICONID)
579 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
580 icon_cx, icon_cy, LR_DEFAULTCOLOR);
582 hIcon = lppsp->u2.hIcon;
586 if (psInfo->hImageList == 0 )
587 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
589 ImageList_AddIcon(psInfo->hImageList, hIcon);
597 /******************************************************************************
598 * PROPSHEET_CreateDialog
600 * Creates the actual property sheet.
602 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
609 WORD resID = IDD_PROPSHEET;
612 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
615 if( psInfo->unicode )
617 if(!(hRes = FindResourceW(COMCTL32_hModule,
618 MAKEINTRESOURCEW(resID),
624 if(!(hRes = FindResourceA(COMCTL32_hModule,
625 MAKEINTRESOURCEA(resID),
630 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
634 * Make a copy of the dialog template.
636 resSize = SizeofResource(COMCTL32_hModule, hRes);
638 temp = Alloc(resSize);
643 memcpy(temp, template, resSize);
645 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
647 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
648 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
650 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
652 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
653 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
655 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
656 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
658 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
661 if (psInfo->useCallback)
662 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
664 /* NOTE: MSDN states "Returns a positive value if successful, or -1
665 * otherwise for modal property sheets.", but this is wrong. The
666 * actual return value is either TRUE (success), FALSE (cancel) or
668 if( psInfo->unicode )
670 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
671 (LPDLGTEMPLATEW) temp,
672 psInfo->ppshheader.hwndParent,
673 PROPSHEET_DialogProc,
675 if ( !ret ) ret = -1;
679 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
680 (LPDLGTEMPLATEA) temp,
681 psInfo->ppshheader.hwndParent,
682 PROPSHEET_DialogProc,
684 if ( !ret ) ret = -1;
692 /******************************************************************************
693 * PROPSHEET_SizeMismatch
695 * Verify that the tab control and the "largest" property sheet page dlg. template
698 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
700 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
701 RECT rcOrigTab, rcPage;
706 GetClientRect(hwndTabCtrl, &rcOrigTab);
707 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
708 rcOrigTab.right, rcOrigTab.bottom);
715 rcPage.right = psInfo->width;
716 rcPage.bottom = psInfo->height;
718 MapDialogRect(hwndDlg, &rcPage);
719 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
720 rcPage.right, rcPage.bottom);
722 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
724 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
730 /******************************************************************************
731 * PROPSHEET_AdjustSize
733 * Resizes the property sheet and the tab control to fit the largest page.
735 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
737 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
738 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
740 int tabOffsetX, tabOffsetY, buttonHeight;
741 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);
784 tabOffsetX = -(rc.left);
785 tabOffsetY = -(rc.top);
789 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
790 hwndTabCtrl, rc.right, rc.bottom);
791 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
792 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
794 GetClientRect(hwndTabCtrl, &rc);
796 TRACE("tab client rc %d %d %d %d\n",
797 rc.left, rc.top, rc.right, rc.bottom);
799 rc.right += ((padding.x * 2) + tabOffsetX);
800 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
803 * Resize the property sheet.
805 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
806 hwndDlg, rc.right, rc.bottom);
807 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
808 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
812 /******************************************************************************
813 * PROPSHEET_AdjustSizeWizard
815 * Resizes the property sheet to fit the largest page.
817 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
819 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
820 RECT rc, lineRect, dialogRect;
822 /* Biggest page size */
825 rc.right = psInfo->width;
826 rc.bottom = psInfo->height;
827 MapDialogRect(hwndDlg, &rc);
829 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
831 /* Add space for the buttons row */
832 GetWindowRect(hwndLine, &lineRect);
833 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
834 GetClientRect(hwndDlg, &dialogRect);
835 rc.bottom += dialogRect.bottom - lineRect.top - 1;
837 /* Convert the client coordinates to window coordinates */
838 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
840 /* Resize the property sheet */
841 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
842 hwndDlg, rc.right, rc.bottom);
843 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
844 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
849 /******************************************************************************
850 * PROPSHEET_AdjustButtons
852 * Adjusts the buttons' positions.
854 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
856 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
860 int buttonWidth, buttonHeight;
861 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
863 if (psInfo->hasApply)
870 * Obtain the size of the buttons.
872 GetClientRect(hwndButton, &rcSheet);
873 buttonWidth = rcSheet.right;
874 buttonHeight = rcSheet.bottom;
877 * Get the size of the property sheet.
879 GetClientRect(hwndParent, &rcSheet);
882 * All buttons will be at this y coordinate.
884 y = rcSheet.bottom - (padding.y + buttonHeight);
887 * Position OK button and make it default.
889 hwndButton = GetDlgItem(hwndParent, IDOK);
891 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
893 SetWindowPos(hwndButton, 0, x, y, 0, 0,
894 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
896 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
900 * Position Cancel button.
902 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
904 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
906 SetWindowPos(hwndButton, 0, x, y, 0, 0,
907 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
910 * Position Apply button.
912 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
914 if (psInfo->hasApply)
917 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
919 x = rcSheet.right - (padding.x + buttonWidth);
921 SetWindowPos(hwndButton, 0, x, y, 0, 0,
922 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
924 EnableWindow(hwndButton, FALSE);
927 ShowWindow(hwndButton, SW_HIDE);
930 * Position Help button.
932 hwndButton = GetDlgItem(hwndParent, IDHELP);
936 x = rcSheet.right - (padding.x + buttonWidth);
938 SetWindowPos(hwndButton, 0, x, y, 0, 0,
939 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
942 ShowWindow(hwndButton, SW_HIDE);
947 /******************************************************************************
948 * PROPSHEET_AdjustButtonsWizard
950 * Adjusts the buttons' positions.
952 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
953 PropSheetInfo* psInfo)
955 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
956 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
957 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
961 int buttonWidth, buttonHeight, lineHeight, lineWidth;
962 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
966 if (psInfo->hasFinish)
970 * Obtain the size of the buttons.
972 GetClientRect(hwndButton, &rcSheet);
973 buttonWidth = rcSheet.right;
974 buttonHeight = rcSheet.bottom;
976 GetClientRect(hwndLine, &rcSheet);
977 lineHeight = rcSheet.bottom;
980 * Get the size of the property sheet.
982 GetClientRect(hwndParent, &rcSheet);
985 * All buttons will be at this y coordinate.
987 y = rcSheet.bottom - (padding.y + buttonHeight);
990 * Position the Back button.
992 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
994 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
996 SetWindowPos(hwndButton, 0, x, y, 0, 0,
997 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1000 * Position the Next button.
1002 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1006 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1007 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1010 * Position the Finish button.
1012 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1014 if (psInfo->hasFinish)
1015 x += padding.x + buttonWidth;
1017 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1018 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1020 if (!psInfo->hasFinish)
1021 ShowWindow(hwndButton, SW_HIDE);
1024 * Position the Cancel button.
1026 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1028 x += padding.x + buttonWidth;
1030 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1031 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1034 * Position Help button.
1036 hwndButton = GetDlgItem(hwndParent, IDHELP);
1038 if (psInfo->hasHelp)
1040 x += padding.x + buttonWidth;
1042 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1043 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1046 ShowWindow(hwndButton, SW_HIDE);
1048 if (psInfo->ppshheader.dwFlags &
1049 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1053 * Position and resize the sunken line.
1056 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1058 lineWidth = rcSheet.right - (padding.x * 2);
1059 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1060 SWP_NOZORDER | SWP_NOACTIVATE);
1063 * Position and resize the header sunken line.
1066 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1067 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1068 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1069 ShowWindow(hwndLineHeader, SW_HIDE);
1074 /******************************************************************************
1075 * PROPSHEET_GetPaddingInfo
1077 * Returns the layout information.
1079 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1081 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1084 PADDING_INFO padding;
1086 GetWindowRect(hwndTab, &rcTab);
1091 ScreenToClient(hwndDlg, &tl);
1099 /******************************************************************************
1100 * PROPSHEET_GetPaddingInfoWizard
1102 * Returns the layout information.
1103 * Vertical spacing is the distance between the line and the buttons.
1104 * Do NOT use the Help button to gather padding information when it isn't mapped
1105 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1106 * for it in this case !
1107 * FIXME: I'm not sure about any other coordinate problems with these evil
1108 * buttons. Fix it in case additional problems appear or maybe calculate
1109 * a padding in a completely different way, as this is somewhat messy.
1111 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1114 PADDING_INFO padding;
1118 POINT ptButton, ptLine;
1121 if (psInfo->hasHelp)
1127 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1129 idButton = IDC_NEXT_BUTTON;
1133 /* hopefully this is ok */
1134 idButton = IDCANCEL;
1138 hwndControl = GetDlgItem(hwndDlg, idButton);
1139 GetWindowRect(hwndControl, &rc);
1141 ptButton.x = rc.left;
1142 ptButton.y = rc.top;
1144 ScreenToClient(hwndDlg, &ptButton);
1147 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1148 GetWindowRect(hwndControl, &rc);
1151 ptLine.y = rc.bottom;
1153 ScreenToClient(hwndDlg, &ptLine);
1155 padding.y = ptButton.y - ptLine.y;
1158 ERR("padding negative ! Please report this !\n");
1160 /* this is most probably not correct, but the best we have now */
1161 padding.x = padding.y;
1165 /******************************************************************************
1166 * PROPSHEET_CreateTabControl
1168 * Insert the tabs in the tab control.
1170 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1171 PropSheetInfo * psInfo)
1173 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1179 item.mask = TCIF_TEXT;
1180 item.cchTextMax = MAX_TABTEXT_LENGTH;
1182 nTabs = psInfo->nPages;
1185 * Set the image list for icons.
1187 if (psInfo->hImageList)
1189 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1192 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1193 for (i = 0; i < nTabs; i++)
1195 if ( psInfo->proppage[i].hasIcon )
1197 item.mask |= TCIF_IMAGE;
1198 item.iImage = iImage++;
1202 item.mask &= ~TCIF_IMAGE;
1205 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1206 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1208 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1213 /******************************************************************************
1214 * PROPSHEET_WizardSubclassProc
1216 * Subclassing window procedure for wizard extrior pages to prevent drawing
1217 * background and so drawing above the watermark.
1219 static LRESULT CALLBACK
1220 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1227 case WM_CTLCOLORSTATIC:
1228 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1229 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1232 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1236 * Get the size of an in-memory Template
1238 *( Based on the code of PROPSHEET_CollectPageInfo)
1239 * See also dialog.c/DIALOG_ParseTemplate32().
1242 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1245 const WORD* p = (const WORD *)pTemplate;
1246 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1252 /* DLGTEMPLATEEX (not defined in any std. header file) */
1254 TRACE("is DLGTEMPLATEEX\n");
1256 p++; /* signature */
1257 p += 2; /* help ID */
1258 p += 2; /* ext style */
1265 TRACE("is DLGTEMPLATE\n");
1267 p += 2; /* ext style */
1270 nrofitems = (WORD)*p; p++; /* nb items */
1286 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1287 p += lstrlenW( (LPCWSTR)p ) + 1;
1298 p += 2; /* 0xffff plus predefined window class ordinal value */
1301 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1302 p += lstrlenW( (LPCWSTR)p ) + 1;
1307 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1308 p += lstrlenW((LPCWSTR)p) + 1;
1310 /* font, if DS_SETFONT set */
1311 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1314 p+=(istemplateex)?3:1;
1315 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1316 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1319 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1320 * that are following the DLGTEMPLATE(EX) data */
1321 TRACE("%d items\n",nrofitems);
1322 while (nrofitems > 0)
1324 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1327 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1336 TRACE("class ordinal 0x%08x\n",*(DWORD*)p);
1340 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1341 p += lstrlenW( (LPCWSTR)p ) + 1;
1345 /* check title text */
1352 TRACE("text ordinal 0x%08x\n",*(DWORD*)p);
1356 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1357 p += lstrlenW( (LPCWSTR)p ) + 1;
1360 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1364 ret = (p - (WORD*)pTemplate) * sizeof(WORD);
1365 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1369 /******************************************************************************
1370 * PROPSHEET_CreatePage
1374 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1376 const PropSheetInfo * psInfo,
1377 LPCPROPSHEETPAGEW ppshpage)
1379 DLGTEMPLATE* pTemplate;
1384 TRACE("index %d\n", index);
1386 if (ppshpage == NULL)
1391 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1393 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1394 resSize = GetTemplateSize(pTemplate);
1396 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1401 hResource = FindResourceW(ppshpage->hInstance,
1402 ppshpage->u.pszTemplate,
1407 resSize = SizeofResource(ppshpage->hInstance, hResource);
1409 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1413 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1415 * Make a copy of the dialog template to make it writable
1423 hResource = FindResourceA(ppshpage->hInstance,
1424 (LPCSTR)ppshpage->u.pszTemplate,
1429 resSize = SizeofResource(ppshpage->hInstance, hResource);
1431 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1435 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1437 * Make a copy of the dialog template to make it writable
1440 temp = Alloc(resSize);
1444 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1445 memcpy(temp, pTemplate, resSize);
1448 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1450 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1451 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1452 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1453 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1454 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1455 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1456 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1457 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1459 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1463 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1464 pTemplate->style &= ~DS_MODALFRAME;
1465 pTemplate->style &= ~WS_CAPTION;
1466 pTemplate->style &= ~WS_SYSMENU;
1467 pTemplate->style &= ~WS_POPUP;
1468 pTemplate->style &= ~WS_DISABLED;
1469 pTemplate->style &= ~WS_VISIBLE;
1470 pTemplate->style &= ~WS_THICKFRAME;
1472 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1475 if (psInfo->proppage[index].useCallback)
1476 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1477 (LPPROPSHEETPAGEW)ppshpage);
1479 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1480 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1483 ppshpage->pfnDlgProc,
1486 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1489 ppshpage->pfnDlgProc,
1491 /* Free a no more needed copy */
1495 psInfo->proppage[index].hwndPage = hwndPage;
1497 /* Subclass exterior wizard pages */
1498 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1499 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1500 (ppshpage->dwFlags & PSP_HIDEHEADER))
1502 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1503 (DWORD_PTR)ppshpage);
1505 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1506 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1511 /******************************************************************************
1512 * PROPSHEET_LoadWizardBitmaps
1514 * Loads the watermark and header bitmaps for a wizard.
1516 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1518 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1520 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1521 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1522 considers hbmWatermark as valid. */
1523 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1524 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1526 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1527 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1530 /* Same behavior as for watermarks */
1531 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1532 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1534 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1535 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1541 /******************************************************************************
1542 * PROPSHEET_ShowPage
1544 * Displays or creates the specified page.
1546 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1549 HWND hwndLineHeader;
1550 LPCPROPSHEETPAGEW ppshpage;
1552 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1553 if (index == psInfo->active_page)
1555 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1556 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1560 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1561 if (psInfo->proppage[index].hwndPage == 0)
1563 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1566 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1568 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1569 psInfo->proppage[index].pszText);
1572 if (psInfo->active_page != -1)
1573 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1575 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1577 /* Synchronize current selection with tab control
1578 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1579 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1580 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1582 psInfo->active_page = index;
1583 psInfo->activeValid = TRUE;
1585 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1587 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1588 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1590 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1591 ShowWindow(hwndLineHeader, SW_HIDE);
1593 ShowWindow(hwndLineHeader, SW_SHOW);
1599 /******************************************************************************
1602 static BOOL PROPSHEET_Back(HWND hwndDlg)
1606 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1611 TRACE("active_page %d\n", psInfo->active_page);
1612 if (psInfo->active_page < 0)
1615 psn.hdr.code = PSN_WIZBACK;
1616 psn.hdr.hwndFrom = hwndDlg;
1620 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1622 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1625 else if (result == 0)
1626 idx = psInfo->active_page - 1;
1628 idx = PROPSHEET_FindPageByResId(psInfo, result);
1630 if (idx >= 0 && idx < psInfo->nPages)
1632 if (PROPSHEET_CanSetCurSel(hwndDlg))
1633 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1638 /******************************************************************************
1641 static BOOL PROPSHEET_Next(HWND hwndDlg)
1645 LRESULT msgResult = 0;
1646 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1650 TRACE("active_page %d\n", psInfo->active_page);
1651 if (psInfo->active_page < 0)
1654 psn.hdr.code = PSN_WIZNEXT;
1655 psn.hdr.hwndFrom = hwndDlg;
1659 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1661 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1662 if (msgResult == -1)
1664 else if (msgResult == 0)
1665 idx = psInfo->active_page + 1;
1667 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1669 if (idx < psInfo->nPages )
1671 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1672 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1678 /******************************************************************************
1681 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1685 LRESULT msgResult = 0;
1686 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1689 TRACE("active_page %d\n", psInfo->active_page);
1690 if (psInfo->active_page < 0)
1693 psn.hdr.code = PSN_WIZFINISH;
1694 psn.hdr.hwndFrom = hwndDlg;
1698 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1700 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1702 TRACE("msg result %ld\n", msgResult);
1707 if (psInfo->isModeless)
1708 psInfo->activeValid = FALSE;
1710 psInfo->ended = TRUE;
1715 /******************************************************************************
1718 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1723 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1726 TRACE("active_page %d\n", psInfo->active_page);
1727 if (psInfo->active_page < 0)
1730 psn.hdr.hwndFrom = hwndDlg;
1736 * Send PSN_KILLACTIVE to the current page.
1738 psn.hdr.code = PSN_KILLACTIVE;
1740 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1742 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1746 * Send PSN_APPLY to all pages.
1748 psn.hdr.code = PSN_APPLY;
1749 psn.lParam = lParam;
1751 for (i = 0; i < psInfo->nPages; i++)
1753 hwndPage = psInfo->proppage[i].hwndPage;
1756 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1758 case PSNRET_INVALID:
1759 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1761 case PSNRET_INVALID_NOCHANGEPAGE:
1769 psInfo->activeValid = FALSE;
1771 else if(psInfo->active_page >= 0)
1773 psn.hdr.code = PSN_SETACTIVE;
1775 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1776 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1782 /******************************************************************************
1785 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1787 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1793 TRACE("active_page %d\n", psInfo->active_page);
1794 if (psInfo->active_page < 0)
1797 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1798 psn.hdr.code = PSN_QUERYCANCEL;
1799 psn.hdr.hwndFrom = hwndDlg;
1803 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1806 psn.hdr.code = PSN_RESET;
1807 psn.lParam = lParam;
1809 for (i = 0; i < psInfo->nPages; i++)
1811 hwndPage = psInfo->proppage[i].hwndPage;
1814 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1817 if (psInfo->isModeless)
1819 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1820 psInfo->activeValid = FALSE;
1823 psInfo->ended = TRUE;
1826 /******************************************************************************
1829 static void PROPSHEET_Help(HWND hwndDlg)
1831 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1836 TRACE("active_page %d\n", psInfo->active_page);
1837 if (psInfo->active_page < 0)
1840 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1841 psn.hdr.code = PSN_HELP;
1842 psn.hdr.hwndFrom = hwndDlg;
1846 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1849 /******************************************************************************
1852 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1855 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
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 = (PropSheetInfo*) GetPropW(hwndDlg,
1892 if ( !psInfo ) return;
1893 for (i = 0; i < psInfo->nPages; i++)
1895 /* set the specified page as clean */
1896 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1897 psInfo->proppage[i].isDirty = FALSE;
1899 /* look to see if there's any dirty pages */
1900 if (psInfo->proppage[i].isDirty)
1901 noPageDirty = FALSE;
1905 * Disable Apply button.
1908 EnableWindow(hwndApplyBtn, FALSE);
1911 /******************************************************************************
1912 * PROPSHEET_PressButton
1914 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1916 TRACE("buttonID %d\n", buttonID);
1919 case PSBTN_APPLYNOW:
1920 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1923 PROPSHEET_Back(hwndDlg);
1926 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1929 PROPSHEET_Finish(hwndDlg);
1932 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1935 PROPSHEET_Next(hwndDlg);
1938 PROPSHEET_DoCommand(hwndDlg, IDOK);
1941 FIXME("Invalid button index %d\n", buttonID);
1946 /*************************************************************************
1947 * BOOL PROPSHEET_CanSetCurSel [Internal]
1949 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1952 * hwndDlg [I] handle to a Dialog hWnd
1955 * TRUE if Current Selection can change
1959 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1961 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1967 TRACE("active_page %d\n", psInfo->active_page);
1974 if (psInfo->active_page < 0)
1981 * Notify the current page.
1983 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1984 psn.hdr.code = PSN_KILLACTIVE;
1985 psn.hdr.hwndFrom = hwndDlg;
1989 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1992 TRACE("<-- %d\n", res);
1996 /******************************************************************************
1997 * PROPSHEET_SetCurSel
1999 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2002 HPROPSHEETPAGE hpage
2005 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2006 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2007 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2009 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2010 /* hpage takes precedence over index */
2012 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2014 if (index < 0 || index >= psInfo->nPages)
2016 TRACE("Could not find page to select!\n");
2024 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2027 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2029 psn.hdr.code = PSN_SETACTIVE;
2030 psn.hdr.hwndFrom = hwndDlg;
2034 if (!psInfo->proppage[index].hwndPage) {
2035 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2038 /* Resize the property sheet page to the fit in the Tab control
2039 * (for regular property sheets) or to fit in the client area (for
2041 * NOTE: The resizing happens every time the page is selected and
2042 * not only when it's created (some applications depend on it). */
2043 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2044 TRACE("setting page %p, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
2045 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2046 rc.right - rc.left, rc.bottom - rc.top);
2047 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2049 rc.right - rc.left, rc.bottom - rc.top, 0);
2051 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2058 WARN("Tried to skip before first property sheet page!\n");
2061 if (index >= psInfo->nPages) {
2062 WARN("Tried to skip after last property sheet page!\n");
2063 index = psInfo->nPages-1;
2067 else if (result != 0)
2069 int old_index = index;
2070 index = PROPSHEET_FindPageByResId(psInfo, result);
2071 if(index >= psInfo->nPages) {
2073 WARN("Tried to skip to nonexistant page by res id\n");
2080 /* Invalidate the header area */
2081 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2082 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2084 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2087 GetClientRect(hwndLineHeader, &r);
2088 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2089 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2091 InvalidateRect(hwndDlg, &r, TRUE);
2095 * Display the new page.
2097 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2099 if (psInfo->proppage[index].hasHelp)
2100 EnableWindow(hwndHelp, TRUE);
2102 EnableWindow(hwndHelp, FALSE);
2107 /******************************************************************************
2108 * PROPSHEET_SetCurSelId
2110 * Selects the page, specified by resource id.
2112 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2115 PropSheetInfo* psInfo =
2116 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2118 idx = PROPSHEET_FindPageByResId(psInfo, id);
2119 if (idx < psInfo->nPages )
2121 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2122 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2126 /******************************************************************************
2127 * PROPSHEET_SetTitleA
2129 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2131 if(HIWORD(lpszText))
2134 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2135 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2136 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2140 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2144 /******************************************************************************
2145 * PROPSHEET_SetTitleW
2147 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2149 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2152 TRACE("'%s' (style %08x)\n", debugstr_w(lpszText), dwStyle);
2153 if (HIWORD(lpszText) == 0) {
2154 if (!LoadStringW(psInfo->ppshheader.hInstance,
2155 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2159 if (dwStyle & PSH_PROPTITLE)
2162 int lentitle = strlenW(lpszText);
2163 int lenprop = strlenW(psInfo->strPropertiesFor);
2165 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2166 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2168 SetWindowTextW(hwndDlg, dest);
2172 SetWindowTextW(hwndDlg, lpszText);
2175 /******************************************************************************
2176 * PROPSHEET_SetFinishTextA
2178 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2180 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2181 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2183 TRACE("'%s'\n", lpszText);
2184 /* Set text, show and enable the Finish button */
2185 SetWindowTextA(hwndButton, lpszText);
2186 ShowWindow(hwndButton, SW_SHOW);
2187 EnableWindow(hwndButton, TRUE);
2189 /* Make it default pushbutton */
2190 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2192 /* Hide Back button */
2193 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2194 ShowWindow(hwndButton, SW_HIDE);
2196 if (!psInfo->hasFinish)
2198 /* Hide Next button */
2199 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2200 ShowWindow(hwndButton, SW_HIDE);
2204 /******************************************************************************
2205 * PROPSHEET_SetFinishTextW
2207 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2209 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2210 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2212 TRACE("'%s'\n", debugstr_w(lpszText));
2213 /* Set text, show and enable the Finish button */
2214 SetWindowTextW(hwndButton, lpszText);
2215 ShowWindow(hwndButton, SW_SHOW);
2216 EnableWindow(hwndButton, TRUE);
2218 /* Make it default pushbutton */
2219 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2221 /* Hide Back button */
2222 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2223 ShowWindow(hwndButton, SW_HIDE);
2225 if (!psInfo->hasFinish)
2227 /* Hide Next button */
2228 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2229 ShowWindow(hwndButton, SW_HIDE);
2233 /******************************************************************************
2234 * PROPSHEET_QuerySiblings
2236 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2237 WPARAM wParam, LPARAM lParam)
2241 LRESULT msgResult = 0;
2242 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2244 while ((i < psInfo->nPages) && (msgResult == 0))
2246 hwndPage = psInfo->proppage[i].hwndPage;
2247 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2255 /******************************************************************************
2258 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2259 HPROPSHEETPAGE hpage)
2262 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2264 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2266 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2268 TRACE("hpage %p\n", hpage);
2270 * Allocate and fill in a new PropPageInfo entry.
2272 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2273 sizeof(PropPageInfo) *
2274 (psInfo->nPages + 1));
2278 psInfo->proppage = ppi;
2279 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2282 psInfo->proppage[psInfo->nPages].hpage = hpage;
2284 if (ppsp->dwFlags & PSP_PREMATURE)
2286 /* Create the page but don't show it */
2287 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2291 * Add a new tab to the tab control.
2293 item.mask = TCIF_TEXT;
2294 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2295 item.cchTextMax = MAX_TABTEXT_LENGTH;
2297 if (psInfo->hImageList)
2299 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2302 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2304 item.mask |= TCIF_IMAGE;
2305 item.iImage = psInfo->nPages;
2308 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2313 /* If it is the only page - show it */
2314 if(psInfo->nPages == 1)
2315 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2319 /******************************************************************************
2320 * PROPSHEET_RemovePage
2322 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2324 HPROPSHEETPAGE hpage)
2326 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2328 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2329 PropPageInfo* oldPages;
2331 TRACE("index %d, hpage %p\n", index, hpage);
2336 * hpage takes precedence over index.
2340 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2343 /* Make sure that index is within range */
2344 if (index < 0 || index >= psInfo->nPages)
2346 TRACE("Could not find page to remove!\n");
2350 TRACE("total pages %d removing page %d active page %d\n",
2351 psInfo->nPages, index, psInfo->active_page);
2353 * Check if we're removing the active page.
2355 if (index == psInfo->active_page)
2357 if (psInfo->nPages > 1)
2361 /* activate previous page */
2362 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2366 /* activate the next page */
2367 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2368 psInfo->active_page = index;
2373 psInfo->active_page = -1;
2374 if (!psInfo->isModeless)
2376 psInfo->ended = TRUE;
2381 else if (index < psInfo->active_page)
2382 psInfo->active_page--;
2384 /* Unsubclass the page dialog window */
2385 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2386 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2387 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2389 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2390 PROPSHEET_WizardSubclassProc, 1);
2393 /* Destroy page dialog window */
2394 DestroyWindow(psInfo->proppage[index].hwndPage);
2396 /* Free page resources */
2397 if(psInfo->proppage[index].hpage)
2399 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2401 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2402 Free ((LPVOID)psInfo->proppage[index].pszText);
2404 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2407 /* Remove the tab */
2408 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2410 oldPages = psInfo->proppage;
2412 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2415 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2417 if (index < psInfo->nPages)
2418 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2419 (psInfo->nPages - index) * sizeof(PropPageInfo));
2426 /******************************************************************************
2427 * PROPSHEET_SetWizButtons
2429 * This code will work if (and assumes that) the Next button is on top of the
2430 * Finish button. ie. Finish comes after Next in the Z order.
2431 * This means make sure the dialog template reflects this.
2434 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2436 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2438 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2439 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2440 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2442 TRACE("%d\n", dwFlags);
2444 EnableWindow(hwndBack, FALSE);
2445 EnableWindow(hwndNext, FALSE);
2446 EnableWindow(hwndFinish, FALSE);
2448 /* set the default pushbutton to an enabled button */
2449 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2450 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2451 else if (dwFlags & PSWIZB_NEXT)
2452 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2453 else if (dwFlags & PSWIZB_BACK)
2454 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2456 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2459 if (dwFlags & PSWIZB_BACK)
2460 EnableWindow(hwndBack, TRUE);
2462 if (dwFlags & PSWIZB_NEXT)
2463 EnableWindow(hwndNext, TRUE);
2465 if (!psInfo->hasFinish)
2467 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2469 /* Hide the Next button */
2470 ShowWindow(hwndNext, SW_HIDE);
2472 /* Show the Finish button */
2473 ShowWindow(hwndFinish, SW_SHOW);
2475 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2476 EnableWindow(hwndFinish, TRUE);
2480 /* Hide the Finish button */
2481 ShowWindow(hwndFinish, SW_HIDE);
2482 /* Show the Next button */
2483 ShowWindow(hwndNext, SW_SHOW);
2486 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2487 EnableWindow(hwndFinish, TRUE);
2490 /******************************************************************************
2491 * PROPSHEET_InsertPage
2493 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2495 if (!HIWORD(hpageInsertAfter))
2496 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2498 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2502 /******************************************************************************
2503 * PROPSHEET_SetHeaderTitleW
2505 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2507 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2510 /******************************************************************************
2511 * PROPSHEET_SetHeaderTitleA
2513 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2515 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2518 /******************************************************************************
2519 * PROPSHEET_SetHeaderSubTitleW
2521 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2523 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2526 /******************************************************************************
2527 * PROPSHEET_SetHeaderSubTitleA
2529 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2531 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2534 /******************************************************************************
2535 * PROPSHEET_HwndToIndex
2537 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2540 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2543 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2545 for (index = 0; index < psInfo->nPages; index++)
2546 if (psInfo->proppage[index].hwndPage == hPageDlg)
2548 WARN("%p not found\n", hPageDlg);
2552 /******************************************************************************
2553 * PROPSHEET_IndexToHwnd
2555 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2557 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2559 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2560 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2561 WARN("%d out of range.\n", iPageIndex);
2564 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2567 /******************************************************************************
2568 * PROPSHEET_PageToIndex
2570 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2573 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2576 TRACE("(%p, %p)\n", hwndDlg, hPage);
2578 for (index = 0; index < psInfo->nPages; index++)
2579 if (psInfo->proppage[index].hpage == hPage)
2581 WARN("%p not found\n", hPage);
2585 /******************************************************************************
2586 * PROPSHEET_IndexToPage
2588 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2590 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2592 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2593 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2594 WARN("%d out of range.\n", iPageIndex);
2597 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2600 /******************************************************************************
2601 * PROPSHEET_IdToIndex
2603 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2606 LPCPROPSHEETPAGEW psp;
2607 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2609 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2610 for (index = 0; index < psInfo->nPages; index++) {
2611 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2612 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2619 /******************************************************************************
2620 * PROPSHEET_IndexToId
2622 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2624 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2626 LPCPROPSHEETPAGEW psp;
2627 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2628 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2629 WARN("%d out of range.\n", iPageIndex);
2632 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2633 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2636 return (LRESULT)psp->u.pszTemplate;
2639 /******************************************************************************
2640 * PROPSHEET_GetResult
2642 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2644 FIXME("(%p): stub\n", hwndDlg);
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);