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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
128 PropPageInfo* proppage;
133 HIMAGELIST hImageList;
143 /******************************************************************************
144 * Defines and global variables
147 const WCHAR PropSheetInfoStr[] =
148 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
150 #define PSP_INTERNAL_UNICODE 0x80000000
152 #define MAX_CAPTION_LENGTH 255
153 #define MAX_TABTEXT_LENGTH 255
154 #define MAX_BUTTONTEXT_LENGTH 64
156 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
158 /* Wizard metrics specified in DLUs */
159 #define WIZARD_PADDING 7
160 #define WIZARD_HEADER_HEIGHT 36
162 /******************************************************************************
165 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
166 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
167 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
169 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
170 PropSheetInfo * psInfo);
171 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
172 PropSheetInfo * psInfo);
173 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
174 PropSheetInfo * psInfo,
176 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
177 PropSheetInfo * psInfo);
178 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
179 const PropSheetInfo * psInfo,
180 LPCPROPSHEETPAGEW ppshpage);
181 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
182 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
183 static BOOL PROPSHEET_Back(HWND hwndDlg);
184 static BOOL PROPSHEET_Next(HWND hwndDlg);
185 static BOOL PROPSHEET_Finish(HWND hwndDlg);
186 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
187 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
188 static void PROPSHEET_Help(HWND hwndDlg);
189 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
190 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
191 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
192 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
193 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
194 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
195 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
196 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
197 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
200 HPROPSHEETPAGE hpage);
201 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
202 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
203 WPARAM wParam, LPARAM lParam);
204 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
205 HPROPSHEETPAGE hpage);
207 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
209 HPROPSHEETPAGE hpage);
210 static void PROPSHEET_CleanUp(HWND hwndDlg);
211 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
212 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
213 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
214 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
215 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
218 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
220 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
222 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
223 /******************************************************************************
224 * PROPSHEET_UnImplementedFlags
226 * Document use of flags we don't implement yet.
228 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
235 * unhandled header flags:
236 * PSH_RTLREADING 0x00000800
237 * PSH_STRETCHWATERMARK 0x00040000
238 * PSH_USEPAGELANG 0x00200000
241 add_flag(PSH_RTLREADING);
242 add_flag(PSH_STRETCHWATERMARK);
243 add_flag(PSH_USEPAGELANG);
244 if (string[0] != '\0')
245 FIXME("%s\n", string);
249 /******************************************************************************
250 * PROPSHEET_GetPageRect
252 * Retrieve rect from tab control and map into the dialog for SetWindowPos
254 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
255 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
257 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
261 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
262 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
263 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
264 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
266 rc->left = rc->top = WIZARD_PADDING;
270 rc->left = rc->top = 0;
272 rc->right = psInfo->width - rc->left;
273 rc->bottom = psInfo->height - rc->top;
274 MapDialogRect(hwndDlg, rc);
276 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
277 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
278 !(ppshpage->dwFlags & PSP_HIDEHEADER))
280 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
281 GetClientRect(hwndChild, &r);
282 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
283 rc->top += r.bottom + 1;
286 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
287 GetClientRect(hwndTabCtrl, rc);
288 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
289 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
293 /******************************************************************************
294 * PROPSHEET_FindPageByResId
296 * Find page index corresponding to page resource id.
298 static INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
302 for (i = 0; i < psInfo->nPages; i++)
304 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
306 /* Fixme: if resource ID is a string shall we use strcmp ??? */
307 if (lppsp->u.pszTemplate == (LPVOID)resId)
314 /******************************************************************************
317 * Convert ASCII to Unicode since all data is saved as Unicode.
319 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
323 TRACE("<%s>\n", frstr);
324 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
325 *tostr = Alloc(len * sizeof(WCHAR));
326 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
329 /******************************************************************************
330 * PROPSHEET_CollectSheetInfoA
332 * Collect relevant data.
334 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
335 PropSheetInfo * psInfo)
337 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
338 DWORD dwFlags = lppsh->dwFlags;
340 psInfo->hasHelp = dwFlags & PSH_HASHELP;
341 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
342 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
343 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
344 psInfo->isModeless = dwFlags & PSH_MODELESS;
346 memcpy(&psInfo->ppshheader,lppsh,dwSize);
347 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
348 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
349 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
351 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
353 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
354 psInfo->ppshheader.pszCaption = NULL;
357 if (HIWORD(lppsh->pszCaption))
359 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
360 psInfo->ppshheader.pszCaption = Alloc( len*sizeof (WCHAR) );
361 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
364 psInfo->nPages = lppsh->nPages;
366 if (dwFlags & PSH_USEPSTARTPAGE)
368 TRACE("PSH_USEPSTARTPAGE is on\n");
369 psInfo->active_page = 0;
372 psInfo->active_page = lppsh->u2.nStartPage;
374 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
375 psInfo->active_page = 0;
377 psInfo->restartWindows = FALSE;
378 psInfo->rebootSystem = FALSE;
379 psInfo->hImageList = 0;
380 psInfo->activeValid = FALSE;
385 /******************************************************************************
386 * PROPSHEET_CollectSheetInfoW
388 * Collect relevant data.
390 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
391 PropSheetInfo * psInfo)
393 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
394 DWORD dwFlags = lppsh->dwFlags;
396 psInfo->hasHelp = dwFlags & PSH_HASHELP;
397 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
398 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
399 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
400 psInfo->isModeless = dwFlags & PSH_MODELESS;
402 memcpy(&psInfo->ppshheader,lppsh,dwSize);
403 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
404 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
406 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
408 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
409 psInfo->ppshheader.pszCaption = NULL;
412 if (HIWORD(lppsh->pszCaption))
414 int len = strlenW(lppsh->pszCaption);
415 psInfo->ppshheader.pszCaption = Alloc( (len+1)*sizeof(WCHAR) );
416 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
419 psInfo->nPages = lppsh->nPages;
421 if (dwFlags & PSH_USEPSTARTPAGE)
423 TRACE("PSH_USEPSTARTPAGE is on\n");
424 psInfo->active_page = 0;
427 psInfo->active_page = lppsh->u2.nStartPage;
429 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
430 psInfo->active_page = 0;
432 psInfo->restartWindows = FALSE;
433 psInfo->rebootSystem = FALSE;
434 psInfo->hImageList = 0;
435 psInfo->activeValid = FALSE;
440 /******************************************************************************
441 * PROPSHEET_CollectPageInfo
443 * Collect property sheet data.
444 * With code taken from DIALOG_ParseTemplate32.
446 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
447 PropSheetInfo * psInfo,
450 DLGTEMPLATE* pTemplate;
459 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
460 psInfo->proppage[index].hwndPage = 0;
461 psInfo->proppage[index].isDirty = FALSE;
464 * Process property page flags.
466 dwFlags = lppsp->dwFlags;
467 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
468 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
469 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
471 /* as soon as we have a page with the help flag, set the sheet flag on */
472 if (psInfo->proppage[index].hasHelp)
473 psInfo->hasHelp = TRUE;
476 * Process page template.
478 if (dwFlags & PSP_DLGINDIRECT)
479 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
480 else if(dwFlags & PSP_INTERNAL_UNICODE )
482 HRSRC hResource = FindResourceW(lppsp->hInstance,
483 lppsp->u.pszTemplate,
485 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
487 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
491 HRSRC hResource = FindResourceA(lppsp->hInstance,
492 (LPSTR)lppsp->u.pszTemplate,
494 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
496 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
500 * Extract the size of the page and the caption.
505 p = (const WORD *)pTemplate;
507 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
509 /* DLGTEMPLATEEX (not defined in any std. header file) */
513 p += 2; /* help ID */
514 p += 2; /* ext style */
522 p += 2; /* ext style */
528 width = (WORD)*p; p++;
529 height = (WORD)*p; p++;
531 /* Special calculation for interior wizard pages so the largest page is
532 * calculated correctly. We need to add all the padding and space occupied
533 * by the header so the width and height sums up to the whole wizard client
535 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
536 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
537 !(dwFlags & PSP_HIDEHEADER))
539 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
540 width += 2 * WIZARD_PADDING;
542 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
544 height += 2 * WIZARD_PADDING;
545 width += 2 * WIZARD_PADDING;
548 /* remember the largest width and height */
549 if (width > psInfo->width)
550 psInfo->width = width;
552 if (height > psInfo->height)
553 psInfo->height = height;
565 p += lstrlenW( (LPCWSTR)p ) + 1;
579 p += lstrlenW( (LPCWSTR)p ) + 1;
583 /* Extract the caption */
584 psInfo->proppage[index].pszText = (LPCWSTR)p;
585 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
586 p += lstrlenW((LPCWSTR)p) + 1;
588 if (dwFlags & PSP_USETITLE)
592 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
595 if ( !HIWORD( lppsp->pszTitle ) )
597 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
600 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
606 pTitle = lppsp->pszTitle;
608 len = strlenW(pTitle);
609 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
610 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
614 * Build the image list for icons
616 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
619 int icon_cx = GetSystemMetrics(SM_CXSMICON);
620 int icon_cy = GetSystemMetrics(SM_CYSMICON);
622 if (dwFlags & PSP_USEICONID)
623 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
624 icon_cx, icon_cy, LR_DEFAULTCOLOR);
626 hIcon = lppsp->u2.hIcon;
630 if (psInfo->hImageList == 0 )
631 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
633 ImageList_AddIcon(psInfo->hImageList, hIcon);
641 /******************************************************************************
642 * PROPSHEET_CreateDialog
644 * Creates the actual property sheet.
646 INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
653 WORD resID = IDD_PROPSHEET;
656 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
659 if( psInfo->unicode )
661 if(!(hRes = FindResourceW(COMCTL32_hModule,
662 MAKEINTRESOURCEW(resID),
668 if(!(hRes = FindResourceA(COMCTL32_hModule,
669 MAKEINTRESOURCEA(resID),
674 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
678 * Make a copy of the dialog template.
680 resSize = SizeofResource(COMCTL32_hModule, hRes);
682 temp = Alloc(resSize);
687 memcpy(temp, template, resSize);
689 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
691 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
692 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
694 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
696 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
697 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
699 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
700 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
702 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
705 if (psInfo->useCallback)
706 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
708 /* NOTE: MSDN states "Returns a positive value if successful, or -1
709 * otherwise for modal property sheets.", but this is wrong. The
710 * actual return value is either TRUE (success), FALSE (cancel) or
712 if( psInfo->unicode )
714 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
715 (LPDLGTEMPLATEW) temp,
716 psInfo->ppshheader.hwndParent,
717 PROPSHEET_DialogProc,
719 if ( !ret ) ret = -1;
723 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
724 (LPDLGTEMPLATEA) temp,
725 psInfo->ppshheader.hwndParent,
726 PROPSHEET_DialogProc,
728 if ( !ret ) ret = -1;
736 /******************************************************************************
737 * PROPSHEET_SizeMismatch
739 * Verify that the tab control and the "largest" property sheet page dlg. template
742 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
744 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
745 RECT rcOrigTab, rcPage;
750 GetClientRect(hwndTabCtrl, &rcOrigTab);
751 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
752 rcOrigTab.right, rcOrigTab.bottom);
759 rcPage.right = psInfo->width;
760 rcPage.bottom = psInfo->height;
762 MapDialogRect(hwndDlg, &rcPage);
763 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
764 rcPage.right, rcPage.bottom);
766 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
768 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
774 /******************************************************************************
775 * PROPSHEET_AdjustSize
777 * Resizes the property sheet and the tab control to fit the largest page.
779 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
781 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
782 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
784 int tabOffsetX, tabOffsetY, buttonHeight;
785 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
788 /* Get the height of buttons */
789 GetClientRect(hwndButton, &rc);
790 buttonHeight = rc.bottom;
797 rc.right = psInfo->width;
798 rc.bottom = psInfo->height;
800 MapDialogRect(hwndDlg, &rc);
802 /* retrieve the dialog units */
803 units.left = units.right = 4;
804 units.top = units.bottom = 8;
805 MapDialogRect(hwndDlg, &units);
808 * Resize the tab control.
810 GetClientRect(hwndTabCtrl,&tabRect);
812 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
814 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
816 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
817 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
820 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
822 rc.right = rc.left + tabRect.right - tabRect.left;
823 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
826 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
828 tabOffsetX = -(rc.left);
829 tabOffsetY = -(rc.top);
833 TRACE("setting tab %p, rc (0,0)-(%ld,%ld)\n",
834 hwndTabCtrl, rc.right, rc.bottom);
835 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
836 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
838 GetClientRect(hwndTabCtrl, &rc);
840 TRACE("tab client rc %ld %ld %ld %ld\n",
841 rc.left, rc.top, rc.right, rc.bottom);
843 rc.right += ((padding.x * 2) + tabOffsetX);
844 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
847 * Resize the property sheet.
849 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
850 hwndDlg, rc.right, rc.bottom);
851 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
852 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
856 /******************************************************************************
857 * PROPSHEET_AdjustSizeWizard
859 * Resizes the property sheet to fit the largest page.
861 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
863 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
864 RECT rc, lineRect, dialogRect;
866 /* Biggest page size */
869 rc.right = psInfo->width;
870 rc.bottom = psInfo->height;
871 MapDialogRect(hwndDlg, &rc);
873 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
875 /* Add space for the buttons row */
876 GetWindowRect(hwndLine, &lineRect);
877 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
878 GetClientRect(hwndDlg, &dialogRect);
879 rc.bottom += dialogRect.bottom - lineRect.top - 1;
881 /* Convert the client coordinates to window coordinates */
882 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
884 /* Resize the property sheet */
885 TRACE("setting dialog %p, rc (0,0)-(%ld,%ld)\n",
886 hwndDlg, rc.right, rc.bottom);
887 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
888 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
893 /******************************************************************************
894 * PROPSHEET_AdjustButtons
896 * Adjusts the buttons' positions.
898 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
900 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
904 int buttonWidth, buttonHeight;
905 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
907 if (psInfo->hasApply)
914 * Obtain the size of the buttons.
916 GetClientRect(hwndButton, &rcSheet);
917 buttonWidth = rcSheet.right;
918 buttonHeight = rcSheet.bottom;
921 * Get the size of the property sheet.
923 GetClientRect(hwndParent, &rcSheet);
926 * All buttons will be at this y coordinate.
928 y = rcSheet.bottom - (padding.y + buttonHeight);
931 * Position OK button and make it default.
933 hwndButton = GetDlgItem(hwndParent, IDOK);
935 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
937 SetWindowPos(hwndButton, 0, x, y, 0, 0,
938 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
940 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
944 * Position Cancel button.
946 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
948 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
950 SetWindowPos(hwndButton, 0, x, y, 0, 0,
951 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
954 * Position Apply button.
956 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
958 if (psInfo->hasApply)
961 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
963 x = rcSheet.right - (padding.x + buttonWidth);
965 SetWindowPos(hwndButton, 0, x, y, 0, 0,
966 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968 EnableWindow(hwndButton, FALSE);
971 ShowWindow(hwndButton, SW_HIDE);
974 * Position Help button.
976 hwndButton = GetDlgItem(hwndParent, IDHELP);
980 x = rcSheet.right - (padding.x + buttonWidth);
982 SetWindowPos(hwndButton, 0, x, y, 0, 0,
983 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
986 ShowWindow(hwndButton, SW_HIDE);
991 /******************************************************************************
992 * PROPSHEET_AdjustButtonsWizard
994 * Adjusts the buttons' positions.
996 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
997 PropSheetInfo* psInfo)
999 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1000 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1001 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1004 int num_buttons = 3;
1005 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1006 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1008 if (psInfo->hasHelp)
1010 if (psInfo->hasFinish)
1014 * Obtain the size of the buttons.
1016 GetClientRect(hwndButton, &rcSheet);
1017 buttonWidth = rcSheet.right;
1018 buttonHeight = rcSheet.bottom;
1020 GetClientRect(hwndLine, &rcSheet);
1021 lineHeight = rcSheet.bottom;
1024 * Get the size of the property sheet.
1026 GetClientRect(hwndParent, &rcSheet);
1029 * All buttons will be at this y coordinate.
1031 y = rcSheet.bottom - (padding.y + buttonHeight);
1034 * Position the Back button.
1036 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1038 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1040 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1041 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1044 * Position the Next button.
1046 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1050 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1051 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1054 * Position the Finish button.
1056 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1058 if (psInfo->hasFinish)
1059 x += padding.x + buttonWidth;
1061 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1062 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1064 if (!psInfo->hasFinish)
1065 ShowWindow(hwndButton, SW_HIDE);
1068 * Position the Cancel button.
1070 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1072 x += padding.x + buttonWidth;
1074 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1075 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1078 * Position Help button.
1080 hwndButton = GetDlgItem(hwndParent, IDHELP);
1082 if (psInfo->hasHelp)
1084 x += padding.x + buttonWidth;
1086 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1087 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1090 ShowWindow(hwndButton, SW_HIDE);
1092 if (psInfo->ppshheader.dwFlags &
1093 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1097 * Position and resize the sunken line.
1100 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1102 lineWidth = rcSheet.right - (padding.x * 2);
1103 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1104 SWP_NOZORDER | SWP_NOACTIVATE);
1107 * Position and resize the header sunken line.
1110 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1111 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1112 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1113 ShowWindow(hwndLineHeader, SW_HIDE);
1118 /******************************************************************************
1119 * PROPSHEET_GetPaddingInfo
1121 * Returns the layout information.
1123 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1125 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1128 PADDING_INFO padding;
1130 GetWindowRect(hwndTab, &rcTab);
1135 ScreenToClient(hwndDlg, &tl);
1143 /******************************************************************************
1144 * PROPSHEET_GetPaddingInfoWizard
1146 * Returns the layout information.
1147 * Vertical spacing is the distance between the line and the buttons.
1148 * Do NOT use the Help button to gather padding information when it isn't mapped
1149 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1150 * for it in this case !
1151 * FIXME: I'm not sure about any other coordinate problems with these evil
1152 * buttons. Fix it in case additional problems appear or maybe calculate
1153 * a padding in a completely different way, as this is somewhat messy.
1155 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1158 PADDING_INFO padding;
1162 POINT ptButton, ptLine;
1165 if (psInfo->hasHelp)
1171 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1173 idButton = IDC_NEXT_BUTTON;
1177 /* hopefully this is ok */
1178 idButton = IDCANCEL;
1182 hwndControl = GetDlgItem(hwndDlg, idButton);
1183 GetWindowRect(hwndControl, &rc);
1185 ptButton.x = rc.left;
1186 ptButton.y = rc.top;
1188 ScreenToClient(hwndDlg, &ptButton);
1191 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1192 GetWindowRect(hwndControl, &rc);
1195 ptLine.y = rc.bottom;
1197 ScreenToClient(hwndDlg, &ptLine);
1199 padding.y = ptButton.y - ptLine.y;
1202 ERR("padding negative ! Please report this !\n");
1204 /* this is most probably not correct, but the best we have now */
1205 padding.x = padding.y;
1209 /******************************************************************************
1210 * PROPSHEET_CreateTabControl
1212 * Insert the tabs in the tab control.
1214 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1215 PropSheetInfo * psInfo)
1217 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1223 item.mask = TCIF_TEXT;
1224 item.cchTextMax = MAX_TABTEXT_LENGTH;
1226 nTabs = psInfo->nPages;
1229 * Set the image list for icons.
1231 if (psInfo->hImageList)
1233 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1236 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1237 for (i = 0; i < nTabs; i++)
1239 if ( psInfo->proppage[i].hasIcon )
1241 item.mask |= TCIF_IMAGE;
1242 item.iImage = iImage++;
1246 item.mask &= ~TCIF_IMAGE;
1249 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1250 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1252 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1257 /******************************************************************************
1258 * PROPSHEET_WizardSubclassProc
1260 * Subclassing window procedure for wizard extrior pages to prevent drawing
1261 * background and so drawing above the watermark.
1263 static LRESULT CALLBACK
1264 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1271 case WM_CTLCOLORSTATIC:
1272 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1273 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1276 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1280 * Get the size of an in-memory Template
1282 *( Based on the code of PROPSHEET_CollectPageInfo)
1283 * See also dialog.c/DIALOG_ParseTemplate32().
1286 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1289 const WORD* p = (const WORD *)pTemplate;
1290 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1295 /* DLGTEMPLATEEX (not defined in any std. header file) */
1297 TRACE("is DLGTEMPLATEEX\n");
1299 p++; /* signature */
1300 p += 2; /* help ID */
1301 p += 2; /* ext style */
1308 TRACE("is DLGTEMPLATE\n");
1310 p += 2; /* ext style */
1313 nrofitems = (WORD)*p; p++; /* nb items */
1329 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1330 p += lstrlenW( (LPCWSTR)p ) + 1;
1341 p += 2; /* 0xffff plus predefined window class ordinal value */
1344 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1345 p += lstrlenW( (LPCWSTR)p ) + 1;
1350 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1351 p += lstrlenW((LPCWSTR)p) + 1;
1353 /* font, if DS_SETFONT set */
1354 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1357 p+=(istemplateex)?3:1;
1358 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1359 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1362 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1363 * that are following the DLGTEMPLATE(EX) data */
1364 TRACE("%d items\n",nrofitems);
1365 while (nrofitems > 0)
1367 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1370 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1379 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1383 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1384 p += lstrlenW( (LPCWSTR)p ) + 1;
1388 /* check title text */
1395 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1399 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1400 p += lstrlenW( (LPCWSTR)p ) + 1;
1403 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1407 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1408 return (p - (WORD*)pTemplate)*sizeof(WORD);
1412 /******************************************************************************
1413 * PROPSHEET_CreatePage
1417 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1419 const PropSheetInfo * psInfo,
1420 LPCPROPSHEETPAGEW ppshpage)
1422 DLGTEMPLATE* pTemplate;
1427 TRACE("index %d\n", index);
1429 if (ppshpage == NULL)
1434 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1436 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1437 resSize = GetTemplateSize(pTemplate);
1439 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1444 hResource = FindResourceW(ppshpage->hInstance,
1445 ppshpage->u.pszTemplate,
1450 resSize = SizeofResource(ppshpage->hInstance, hResource);
1452 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1456 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1458 * Make a copy of the dialog template to make it writable
1466 hResource = FindResourceA(ppshpage->hInstance,
1467 (LPSTR)ppshpage->u.pszTemplate,
1472 resSize = SizeofResource(ppshpage->hInstance, hResource);
1474 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1478 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1480 * Make a copy of the dialog template to make it writable
1483 temp = Alloc(resSize);
1487 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1488 memcpy(temp, pTemplate, resSize);
1491 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1493 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1494 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1495 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1496 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1497 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1498 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1500 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1502 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1506 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1507 pTemplate->style &= ~DS_MODALFRAME;
1508 pTemplate->style &= ~WS_CAPTION;
1509 pTemplate->style &= ~WS_SYSMENU;
1510 pTemplate->style &= ~WS_POPUP;
1511 pTemplate->style &= ~WS_DISABLED;
1512 pTemplate->style &= ~WS_VISIBLE;
1513 pTemplate->style &= ~WS_THICKFRAME;
1515 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1518 if (psInfo->proppage[index].useCallback)
1519 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1520 (LPPROPSHEETPAGEW)ppshpage);
1522 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1523 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1526 ppshpage->pfnDlgProc,
1529 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1532 ppshpage->pfnDlgProc,
1534 /* Free a no more needed copy */
1538 psInfo->proppage[index].hwndPage = hwndPage;
1540 /* Subclass exterior wizard pages */
1541 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1542 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1543 (ppshpage->dwFlags & PSP_HIDEHEADER))
1545 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1546 (DWORD_PTR)ppshpage);
1548 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1549 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1554 /******************************************************************************
1555 * PROPSHEET_LoadWizardBitmaps
1557 * Loads the watermark and header bitmaps for a wizard.
1559 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1561 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1563 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1564 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1565 considers hbmWatermark as valid. */
1566 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1567 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1569 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1570 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1573 /* Same behavior as for watermarks */
1574 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1575 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1577 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1578 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1584 /******************************************************************************
1585 * PROPSHEET_ShowPage
1587 * Displays or creates the specified page.
1589 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1592 HWND hwndLineHeader;
1593 LPCPROPSHEETPAGEW ppshpage;
1595 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1596 if (index == psInfo->active_page)
1598 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1599 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1603 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1604 if (psInfo->proppage[index].hwndPage == 0)
1606 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1609 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1610 (ppshpage->dwFlags & PSP_USETITLE))
1612 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1613 psInfo->proppage[index].pszText);
1616 if (psInfo->active_page != -1)
1617 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1619 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1621 /* Synchronize current selection with tab control
1622 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1623 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1624 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1626 psInfo->active_page = index;
1627 psInfo->activeValid = TRUE;
1629 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1631 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1632 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1634 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1635 ShowWindow(hwndLineHeader, SW_HIDE);
1637 ShowWindow(hwndLineHeader, SW_SHOW);
1643 /******************************************************************************
1646 static BOOL PROPSHEET_Back(HWND hwndDlg)
1650 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1655 TRACE("active_page %d\n", psInfo->active_page);
1656 if (psInfo->active_page < 0)
1659 psn.hdr.code = PSN_WIZBACK;
1660 psn.hdr.hwndFrom = hwndDlg;
1664 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1666 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1669 else if (result == 0)
1670 idx = psInfo->active_page - 1;
1672 idx = PROPSHEET_FindPageByResId(psInfo, result);
1674 if (idx >= 0 && idx < psInfo->nPages)
1676 if (PROPSHEET_CanSetCurSel(hwndDlg))
1677 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1682 /******************************************************************************
1685 static BOOL PROPSHEET_Next(HWND hwndDlg)
1689 LRESULT msgResult = 0;
1690 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1694 TRACE("active_page %d\n", psInfo->active_page);
1695 if (psInfo->active_page < 0)
1698 psn.hdr.code = PSN_WIZNEXT;
1699 psn.hdr.hwndFrom = hwndDlg;
1703 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1705 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1706 if (msgResult == -1)
1708 else if (msgResult == 0)
1709 idx = psInfo->active_page + 1;
1711 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1713 if (idx < psInfo->nPages )
1715 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1716 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1722 /******************************************************************************
1725 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1729 LRESULT msgResult = 0;
1730 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1733 TRACE("active_page %d\n", psInfo->active_page);
1734 if (psInfo->active_page < 0)
1737 psn.hdr.code = PSN_WIZFINISH;
1738 psn.hdr.hwndFrom = hwndDlg;
1742 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1744 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1746 TRACE("msg result %ld\n", msgResult);
1751 if (psInfo->isModeless)
1752 psInfo->activeValid = FALSE;
1754 psInfo->ended = TRUE;
1759 /******************************************************************************
1762 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1767 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1770 TRACE("active_page %d\n", psInfo->active_page);
1771 if (psInfo->active_page < 0)
1774 psn.hdr.hwndFrom = hwndDlg;
1780 * Send PSN_KILLACTIVE to the current page.
1782 psn.hdr.code = PSN_KILLACTIVE;
1784 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1786 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1790 * Send PSN_APPLY to all pages.
1792 psn.hdr.code = PSN_APPLY;
1793 psn.lParam = lParam;
1795 for (i = 0; i < psInfo->nPages; i++)
1797 hwndPage = psInfo->proppage[i].hwndPage;
1800 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1802 case PSNRET_INVALID:
1803 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1805 case PSNRET_INVALID_NOCHANGEPAGE:
1813 psInfo->activeValid = FALSE;
1815 else if(psInfo->active_page >= 0)
1817 psn.hdr.code = PSN_SETACTIVE;
1819 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1820 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1826 /******************************************************************************
1829 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1831 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
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_QUERYCANCEL;
1843 psn.hdr.hwndFrom = hwndDlg;
1847 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1850 psn.hdr.code = PSN_RESET;
1851 psn.lParam = lParam;
1853 for (i = 0; i < psInfo->nPages; i++)
1855 hwndPage = psInfo->proppage[i].hwndPage;
1858 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1861 if (psInfo->isModeless)
1863 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1864 psInfo->activeValid = FALSE;
1867 psInfo->ended = TRUE;
1870 /******************************************************************************
1873 static void PROPSHEET_Help(HWND hwndDlg)
1875 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1880 TRACE("active_page %d\n", psInfo->active_page);
1881 if (psInfo->active_page < 0)
1884 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1885 psn.hdr.code = PSN_HELP;
1886 psn.hdr.hwndFrom = hwndDlg;
1890 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1893 /******************************************************************************
1896 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1899 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1903 if (!psInfo) return;
1905 * Set the dirty flag of this page.
1907 for (i = 0; i < psInfo->nPages; i++)
1909 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1910 psInfo->proppage[i].isDirty = TRUE;
1914 * Enable the Apply button.
1916 if (psInfo->hasApply)
1918 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1920 EnableWindow(hwndApplyBtn, TRUE);
1924 /******************************************************************************
1925 * PROPSHEET_UnChanged
1927 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1930 BOOL noPageDirty = TRUE;
1931 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1932 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1936 if ( !psInfo ) return;
1937 for (i = 0; i < psInfo->nPages; i++)
1939 /* set the specified page as clean */
1940 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1941 psInfo->proppage[i].isDirty = FALSE;
1943 /* look to see if there's any dirty pages */
1944 if (psInfo->proppage[i].isDirty)
1945 noPageDirty = FALSE;
1949 * Disable Apply button.
1952 EnableWindow(hwndApplyBtn, FALSE);
1955 /******************************************************************************
1956 * PROPSHEET_PressButton
1958 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1960 TRACE("buttonID %d\n", buttonID);
1963 case PSBTN_APPLYNOW:
1964 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1967 PROPSHEET_Back(hwndDlg);
1970 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1973 PROPSHEET_Finish(hwndDlg);
1976 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1979 PROPSHEET_Next(hwndDlg);
1982 PROPSHEET_DoCommand(hwndDlg, IDOK);
1985 FIXME("Invalid button index %d\n", buttonID);
1990 /*************************************************************************
1991 * BOOL PROPSHEET_CanSetCurSel [Internal]
1993 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1996 * hwndDlg [I] handle to a Dialog hWnd
1999 * TRUE if Current Selection can change
2003 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2005 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2011 TRACE("active_page %d\n", psInfo->active_page);
2018 if (psInfo->active_page < 0)
2025 * Notify the current page.
2027 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2028 psn.hdr.code = PSN_KILLACTIVE;
2029 psn.hdr.hwndFrom = hwndDlg;
2033 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2036 TRACE("<-- %d\n", res);
2040 /******************************************************************************
2041 * PROPSHEET_SetCurSel
2043 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2046 HPROPSHEETPAGE hpage
2049 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2050 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2051 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2053 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2054 /* hpage takes precedence over index */
2056 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2058 if (index < 0 || index >= psInfo->nPages)
2060 TRACE("Could not find page to select!\n");
2068 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2071 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2073 psn.hdr.code = PSN_SETACTIVE;
2074 psn.hdr.hwndFrom = hwndDlg;
2078 if (!psInfo->proppage[index].hwndPage) {
2079 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2082 /* Resize the property sheet page to the fit in the Tab control
2083 * (for regular property sheets) or to fit in the client area (for
2085 * NOTE: The resizing happens every time the page is selected and
2086 * not only when it's created (some applications depend on it). */
2087 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2088 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2089 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2090 rc.right - rc.left, rc.bottom - rc.top);
2091 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2093 rc.right - rc.left, rc.bottom - rc.top, 0);
2095 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2102 WARN("Tried to skip before first property sheet page!\n");
2105 if (index >= psInfo->nPages) {
2106 WARN("Tried to skip after last property sheet page!\n");
2107 index = psInfo->nPages-1;
2111 else if (result != 0)
2113 int old_index = index;
2114 index = PROPSHEET_FindPageByResId(psInfo, result);
2115 if(index >= psInfo->nPages) {
2117 WARN("Tried to skip to nonexistant page by res id\n");
2124 * Display the new page.
2126 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2128 if (psInfo->proppage[index].hasHelp)
2129 EnableWindow(hwndHelp, TRUE);
2131 EnableWindow(hwndHelp, FALSE);
2136 /******************************************************************************
2137 * PROPSHEET_SetCurSelId
2139 * Selects the page, specified by resource id.
2141 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2144 PropSheetInfo* psInfo =
2145 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2147 idx = PROPSHEET_FindPageByResId(psInfo, id);
2148 if (idx < psInfo->nPages )
2150 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2151 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2155 /******************************************************************************
2156 * PROPSHEET_SetTitleA
2158 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2160 if(HIWORD(lpszText))
2163 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2164 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2165 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2169 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2173 /******************************************************************************
2174 * PROPSHEET_SetTitleW
2176 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2178 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2181 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2182 if (HIWORD(lpszText) == 0) {
2183 if (!LoadStringW(psInfo->ppshheader.hInstance,
2184 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2188 if (dwStyle & PSH_PROPTITLE)
2191 int lentitle = strlenW(lpszText);
2192 int lenprop = strlenW(psInfo->strPropertiesFor);
2194 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2195 strcpyW(dest, psInfo->strPropertiesFor);
2196 strcatW(dest, lpszText);
2198 SetWindowTextW(hwndDlg, dest);
2202 SetWindowTextW(hwndDlg, lpszText);
2205 /******************************************************************************
2206 * PROPSHEET_SetFinishTextA
2208 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2210 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2211 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2213 TRACE("'%s'\n", lpszText);
2214 /* Set text, show and enable the Finish button */
2215 SetWindowTextA(hwndButton, lpszText);
2216 ShowWindow(hwndButton, SW_SHOW);
2217 EnableWindow(hwndButton, TRUE);
2219 /* Make it default pushbutton */
2220 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2222 /* Hide Back button */
2223 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2224 ShowWindow(hwndButton, SW_HIDE);
2226 if (!psInfo->hasFinish)
2228 /* Hide Next button */
2229 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2230 ShowWindow(hwndButton, SW_HIDE);
2234 /******************************************************************************
2235 * PROPSHEET_SetFinishTextW
2237 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2239 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2240 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2242 TRACE("'%s'\n", debugstr_w(lpszText));
2243 /* Set text, show and enable the Finish button */
2244 SetWindowTextW(hwndButton, lpszText);
2245 ShowWindow(hwndButton, SW_SHOW);
2246 EnableWindow(hwndButton, TRUE);
2248 /* Make it default pushbutton */
2249 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2251 /* Hide Back button */
2252 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2253 ShowWindow(hwndButton, SW_HIDE);
2255 if (!psInfo->hasFinish)
2257 /* Hide Next button */
2258 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2259 ShowWindow(hwndButton, SW_HIDE);
2263 /******************************************************************************
2264 * PROPSHEET_QuerySiblings
2266 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2267 WPARAM wParam, LPARAM lParam)
2271 LRESULT msgResult = 0;
2272 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2274 while ((i < psInfo->nPages) && (msgResult == 0))
2276 hwndPage = psInfo->proppage[i].hwndPage;
2277 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2285 /******************************************************************************
2288 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2289 HPROPSHEETPAGE hpage)
2292 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2294 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2296 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2298 TRACE("hpage %p\n", hpage);
2300 * Allocate and fill in a new PropPageInfo entry.
2302 ppi = (PropPageInfo*) ReAlloc(psInfo->proppage,
2303 sizeof(PropPageInfo) *
2304 (psInfo->nPages + 1));
2308 psInfo->proppage = ppi;
2309 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2312 psInfo->proppage[psInfo->nPages].hpage = hpage;
2314 if (ppsp->dwFlags & PSP_PREMATURE)
2316 /* Create the page but don't show it */
2317 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2321 * Add a new tab to the tab control.
2323 item.mask = TCIF_TEXT;
2324 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2325 item.cchTextMax = MAX_TABTEXT_LENGTH;
2327 if (psInfo->hImageList)
2329 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2332 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2334 item.mask |= TCIF_IMAGE;
2335 item.iImage = psInfo->nPages;
2338 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2343 /* If it is the only page - show it */
2344 if(psInfo->nPages == 1)
2345 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2349 /******************************************************************************
2350 * PROPSHEET_RemovePage
2352 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2354 HPROPSHEETPAGE hpage)
2356 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2358 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2359 PropPageInfo* oldPages;
2361 TRACE("index %d, hpage %p\n", index, hpage);
2366 * hpage takes precedence over index.
2370 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2373 /* Make sure that index is within range */
2374 if (index < 0 || index >= psInfo->nPages)
2376 TRACE("Could not find page to remove!\n");
2380 TRACE("total pages %d removing page %d active page %d\n",
2381 psInfo->nPages, index, psInfo->active_page);
2383 * Check if we're removing the active page.
2385 if (index == psInfo->active_page)
2387 if (psInfo->nPages > 1)
2391 /* activate previous page */
2392 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2396 /* activate the next page */
2397 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2398 psInfo->active_page = index;
2403 psInfo->active_page = -1;
2404 if (!psInfo->isModeless)
2406 psInfo->ended = TRUE;
2411 else if (index < psInfo->active_page)
2412 psInfo->active_page--;
2414 /* Unsubclass the page dialog window */
2415 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2416 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2417 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2419 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2420 PROPSHEET_WizardSubclassProc, 1);
2423 /* Destroy page dialog window */
2424 DestroyWindow(psInfo->proppage[index].hwndPage);
2426 /* Free page resources */
2427 if(psInfo->proppage[index].hpage)
2429 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2431 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2432 Free ((LPVOID)psInfo->proppage[index].pszText);
2434 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2437 /* Remove the tab */
2438 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2440 oldPages = psInfo->proppage;
2442 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2445 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2447 if (index < psInfo->nPages)
2448 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2449 (psInfo->nPages - index) * sizeof(PropPageInfo));
2456 /******************************************************************************
2457 * PROPSHEET_SetWizButtons
2459 * This code will work if (and assumes that) the Next button is on top of the
2460 * Finish button. ie. Finish comes after Next in the Z order.
2461 * This means make sure the dialog template reflects this.
2464 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2466 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2468 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2469 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2470 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2472 TRACE("%ld\n", dwFlags);
2474 EnableWindow(hwndBack, FALSE);
2475 EnableWindow(hwndNext, FALSE);
2476 EnableWindow(hwndFinish, FALSE);
2478 if (dwFlags & PSWIZB_BACK)
2479 EnableWindow(hwndBack, TRUE);
2481 if (dwFlags & PSWIZB_NEXT)
2483 if (!psInfo->hasFinish)
2485 /* Hide the Finish button */
2486 ShowWindow(hwndFinish, SW_HIDE);
2489 /* Show and enable the Next button */
2490 ShowWindow(hwndNext, SW_SHOW);
2491 EnableWindow(hwndNext, TRUE);
2493 /* Set the Next button as the default pushbutton */
2494 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2497 if (!psInfo->hasFinish)
2499 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2501 /* Hide the Next button */
2502 ShowWindow(hwndNext, SW_HIDE);
2504 /* Show the Finish button */
2505 ShowWindow(hwndFinish, SW_SHOW);
2507 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2509 EnableWindow(hwndFinish, TRUE);
2511 /* Set the Finish button as the default pushbutton */
2512 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2516 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2517 EnableWindow(hwndFinish, TRUE);
2520 /******************************************************************************
2521 * PROPSHEET_InsertPage
2523 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2525 if (!HIWORD(hpageInsertAfter))
2526 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2528 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2532 /******************************************************************************
2533 * PROPSHEET_SetHeaderTitleW
2535 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2537 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2540 /******************************************************************************
2541 * PROPSHEET_SetHeaderTitleA
2543 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2545 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2548 /******************************************************************************
2549 * PROPSHEET_SetHeaderSubTitleW
2551 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2553 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2556 /******************************************************************************
2557 * PROPSHEET_SetHeaderSubTitleA
2559 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2561 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2564 /******************************************************************************
2565 * PROPSHEET_HwndToIndex
2567 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2570 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2573 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2575 for (index = 0; index < psInfo->nPages; index++)
2576 if (psInfo->proppage[index].hwndPage == hPageDlg)
2578 WARN("%p not found\n", hPageDlg);
2582 /******************************************************************************
2583 * PROPSHEET_IndexToHwnd
2585 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2587 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2589 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2590 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2591 WARN("%d out of range.\n", iPageIndex);
2594 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2597 /******************************************************************************
2598 * PROPSHEET_PageToIndex
2600 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2603 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2606 TRACE("(%p, %p)\n", hwndDlg, hPage);
2608 for (index = 0; index < psInfo->nPages; index++)
2609 if (psInfo->proppage[index].hpage == hPage)
2611 WARN("%p not found\n", hPage);
2615 /******************************************************************************
2616 * PROPSHEET_IndexToPage
2618 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2620 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2622 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2623 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2624 WARN("%d out of range.\n", iPageIndex);
2627 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2630 /******************************************************************************
2631 * PROPSHEET_IdToIndex
2633 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2636 LPCPROPSHEETPAGEW psp;
2637 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2639 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2640 for (index = 0; index < psInfo->nPages; index++) {
2641 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2642 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2649 /******************************************************************************
2650 * PROPSHEET_IndexToId
2652 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2654 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2656 LPCPROPSHEETPAGEW psp;
2657 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2658 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2659 WARN("%d out of range.\n", iPageIndex);
2662 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2663 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2666 return (LRESULT)psp->u.pszTemplate;
2669 /******************************************************************************
2670 * PROPSHEET_GetResult
2672 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2674 FIXME("(%p): stub\n", hwndDlg);
2678 /******************************************************************************
2679 * PROPSHEET_RecalcPageSizes
2681 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2683 FIXME("(%p): stub\n", hwndDlg);
2687 /******************************************************************************
2688 * PROPSHEET_GetPageIndex
2690 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2691 * the array of PropPageInfo.
2693 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2698 TRACE("hpage %p\n", hpage);
2699 while ((index < psInfo->nPages) && (found == FALSE))
2701 if (psInfo->proppage[index].hpage == hpage)
2713 /******************************************************************************
2716 static void PROPSHEET_CleanUp(HWND hwndDlg)
2719 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2723 if (!psInfo) return;
2724 if (HIWORD(psInfo->ppshheader.pszCaption))
2725 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2727 for (i = 0; i < psInfo->nPages; i++)
2729 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2731 /* Unsubclass the page dialog window */
2732 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2733 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2734 (psp->dwFlags & PSP_HIDEHEADER))
2736 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2737 PROPSHEET_WizardSubclassProc, 1);
2740 if(psInfo->proppage[i].hwndPage)
2741 DestroyWindow(psInfo->proppage[i].hwndPage);
2745 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2746 Free ((LPVOID)psInfo->proppage[i].pszText);
2748 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2752 DeleteObject(psInfo->hFont);
2753 DeleteObject(psInfo->hFontBold);
2754 /* If we created the bitmaps, destroy them */
2755 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2756 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2757 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2758 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2759 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2760 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2762 Free(psInfo->proppage);
2763 Free(psInfo->strPropertiesFor);
2764 ImageList_Destroy(psInfo->hImageList);
2766 GlobalFree((HGLOBAL)psInfo);
2769 static INT do_loop(PropSheetInfo *psInfo)
2773 HWND hwnd = psInfo->hwnd;
2775 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2780 if(!IsDialogMessageW(hwnd, &msg))
2782 TranslateMessage(&msg);
2783 DispatchMessageW(&msg);
2789 PostQuitMessage(msg.wParam);
2793 DestroyWindow(hwnd);
2797 /******************************************************************************
2798 * PropertySheet (COMCTL32.@)
2799 * PropertySheetA (COMCTL32.@)
2801 * Creates a property sheet in the specified property sheet header.
2804 * Modal property sheets: Positive if successful or -1 otherwise.
2805 * Modeless property sheets: Property sheet handle.
2807 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2808 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2810 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2813 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2814 sizeof(PropSheetInfo));
2818 TRACE("(%p)\n", lppsh);
2820 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2822 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2824 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2826 for (n = i = 0; i < lppsh->nPages; i++, n++)
2828 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2829 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2832 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2833 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2836 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2839 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2840 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2846 psInfo->unicode = FALSE;
2847 psInfo->ended = FALSE;
2849 bRet = PROPSHEET_CreateDialog(psInfo);
2850 if(!psInfo->isModeless)
2851 bRet = do_loop(psInfo);
2856 /******************************************************************************
2857 * PropertySheetW (COMCTL32.@)
2859 * See PropertySheetA.
2861 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2864 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2865 sizeof(PropSheetInfo));
2869 TRACE("(%p)\n", lppsh);
2871 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2873 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2875 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2877 for (n = i = 0; i < lppsh->nPages; i++, n++)
2879 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2880 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2883 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2884 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2887 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2890 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2891 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2897 psInfo->unicode = TRUE;
2898 psInfo->ended = FALSE;
2900 bRet = PROPSHEET_CreateDialog(psInfo);
2901 if(!psInfo->isModeless)
2902 bRet = do_loop(psInfo);
2907 /******************************************************************************
2908 * CreatePropertySheetPage (COMCTL32.@)
2909 * CreatePropertySheetPageA (COMCTL32.@)
2911 * Creates a new property sheet page.
2914 * Success: Handle to new property sheet page.
2918 * An application must use the PSM_ADDPAGE message to add the new page to
2919 * an existing property sheet.
2921 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2922 LPCPROPSHEETPAGEA lpPropSheetPage)
2924 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2926 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2928 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2929 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2931 int len = strlen(lpPropSheetPage->u.pszTemplate);
2933 ppsp->u.pszTemplate = Alloc( len+1 );
2934 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2936 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2938 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2941 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2943 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2945 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2946 ppsp->pszTitle = NULL;
2948 return (HPROPSHEETPAGE)ppsp;
2951 /******************************************************************************
2952 * CreatePropertySheetPageW (COMCTL32.@)
2954 * See CreatePropertySheetA.
2956 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2958 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2960 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2962 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2964 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2966 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2968 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2969 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2971 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2973 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2974 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2975 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2978 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2980 int len = strlenW(lpPropSheetPage->pszTitle);
2981 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2982 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2984 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2985 ppsp->pszTitle = NULL;
2987 return (HPROPSHEETPAGE)ppsp;
2990 /******************************************************************************
2991 * DestroyPropertySheetPage (COMCTL32.@)
2993 * Destroys a property sheet page previously created with
2994 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3001 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3003 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3008 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3009 Free ((LPVOID)psp->u.pszTemplate);
3011 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3012 Free ((LPVOID)psp->u2.pszIcon);
3014 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3015 Free ((LPVOID)psp->pszTitle);
3022 /******************************************************************************
3023 * PROPSHEET_IsDialogMessage
3025 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3027 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3030 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3033 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3036 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3038 if (!(dlgCode & DLGC_WANTMESSAGE))
3040 switch (lpMsg->wParam)
3043 if (GetKeyState(VK_SHIFT) & 0x8000)
3049 case VK_NEXT: new_page = 1; break;
3050 case VK_PRIOR: new_page = -1; break;
3056 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3058 new_page += psInfo->active_page;
3061 new_page = psInfo->nPages - 1;
3062 else if (new_page >= psInfo->nPages)
3065 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3072 return IsDialogMessageW(hwnd, lpMsg);
3075 /******************************************************************************
3076 * PROPSHEET_DoCommand
3078 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3084 case IDC_APPLY_BUTTON:
3086 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3088 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3093 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3097 if (psInfo->restartWindows)
3098 result = ID_PSRESTARTWINDOWS;
3100 /* reboot system takes precedence over restart windows */
3101 if (psInfo->rebootSystem)
3102 result = ID_PSREBOOTSYSTEM;
3104 if (psInfo->isModeless)
3105 psInfo->activeValid = FALSE;
3107 psInfo->ended = TRUE;
3110 EnableWindow(hwndApplyBtn, FALSE);
3115 case IDC_BACK_BUTTON:
3116 PROPSHEET_Back(hwnd);
3119 case IDC_NEXT_BUTTON:
3120 PROPSHEET_Next(hwnd);
3123 case IDC_FINISH_BUTTON:
3124 PROPSHEET_Finish(hwnd);
3128 PROPSHEET_Cancel(hwnd, 0);
3132 PROPSHEET_Help(hwnd);
3142 /******************************************************************************
3145 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3147 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3152 HPALETTE hOldPal = 0;
3156 LPCPROPSHEETPAGEW ppshpage;
3157 WCHAR szBuffer[256];
3160 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3163 hdcSrc = CreateCompatibleDC(0);
3164 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3166 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3167 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3169 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3170 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3171 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3173 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3175 COLORREF clrOld = 0;
3178 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3179 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3181 GetClientRect(hwndLineHeader, &r);
3182 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3183 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3185 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3187 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3189 /* Fill the unoccupied part of the header with color of the
3190 * left-top pixel, but do it only when needed.
3192 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3194 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3195 CopyRect(&r, &rzone);
3196 if (bm.bmWidth < r.right)
3198 r.left = bm.bmWidth;
3199 FillRect(hdc, &r, hbr);
3201 if (bm.bmHeight < r.bottom)
3204 r.top = bm.bmHeight;
3205 FillRect(hdc, &r, hbr);
3210 /* Draw the header itself. */
3212 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3213 hdcSrc, 0, 0, SRCCOPY);
3217 hbr = GetSysColorBrush(COLOR_WINDOW);
3218 FillRect(hdc, &rzone, hbr);
3220 /* Draw the header bitmap. It's always centered like a
3221 * common 49 x 49 bitmap. */
3222 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3223 (rzone.bottom - 49) / 2,
3224 bm.bmWidth, bm.bmHeight,
3225 hdcSrc, 0, 0, SRCCOPY);
3227 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3228 * if its height is smaller than 49 pixels. Because the reason
3229 * for this bug is unknown the current code doesn't try to
3233 clrOld = SetTextColor (hdc, 0x00000000);
3234 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3236 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3237 SetRect(&r, 20, 10, 0, 0);
3238 if (HIWORD(ppshpage->pszHeaderTitle))
3240 if (psInfo->unicode)
3241 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3242 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3244 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3245 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3249 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3253 DrawTextW(hdc, szBuffer, nLength,
3254 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3259 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3260 SelectObject(hdc, psInfo->hFont);
3261 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3262 if (HIWORD(ppshpage->pszHeaderTitle))
3264 if (psInfo->unicode)
3265 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3266 -1, &r, DT_LEFT | DT_SINGLELINE);
3268 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3269 -1, &r, DT_LEFT | DT_SINGLELINE);
3273 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3277 DrawTextW(hdc, szBuffer, nLength,
3278 &r, DT_LEFT | DT_SINGLELINE);
3283 offsety = rzone.bottom + 2;
3285 SetTextColor(hdc, clrOld);
3286 SetBkMode(hdc, oldBkMode);
3287 SelectObject(hdc, hOldFont);
3288 SelectObject(hdcSrc, hbmp);
3291 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3292 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3293 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3295 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3297 GetClientRect(hwndLine, &r);
3298 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3302 rzone.right = r.right;
3303 rzone.bottom = r.top - 1;
3305 hbr = GetSysColorBrush(COLOR_WINDOW);
3306 FillRect(hdc, &rzone, hbr);
3308 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3309 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3311 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3312 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3314 /* If the bitmap is not big enough, fill the remaining area
3315 with the color of pixel (0,0) of bitmap - see MSDN */
3316 if (r.top > bm.bmHeight) {
3317 r.bottom = r.top - 1;
3318 r.top = bm.bmHeight;
3320 r.right = bm.bmWidth;
3321 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3322 FillRect(hdc, &r, hbr);
3326 SelectObject(hdcSrc, hbmp);
3329 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3330 SelectPalette(hdc, hOldPal, FALSE);
3334 if (!hdcParam) EndPaint(hwnd, &ps);
3339 /******************************************************************************
3340 * PROPSHEET_DialogProc
3343 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3345 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3346 hwnd, uMsg, wParam, lParam);
3352 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3353 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3354 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3355 LPCPROPSHEETPAGEW ppshpage;
3359 /* Using PropSheetInfoStr to store extra data doesn't match the native
3360 * common control: native uses TCM_[GS]ETITEM
3362 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3365 * psInfo->hwnd is not being used by WINE code - it exists
3366 * for compatibility with "real" Windoze. The same about
3367 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3370 psInfo->hwnd = hwnd;
3371 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3373 /* set up the Next and Back buttons by default */
3374 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3377 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3378 psInfo->hFont = CreateFontIndirectW (&logFont);
3379 logFont.lfWeight = FW_BOLD;
3380 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3383 * Small icon in the title bar.
3385 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3386 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3389 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3390 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3392 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3393 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3394 psInfo->ppshheader.u.pszIcon,
3399 hIcon = psInfo->ppshheader.u.hIcon;
3401 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3404 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3405 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3407 psInfo->strPropertiesFor = strCaption;
3409 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3411 PROPSHEET_CreateTabControl(hwnd, psInfo);
3413 PROPSHEET_LoadWizardBitmaps(psInfo);
3415 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3417 ShowWindow(hwndTabCtrl, SW_HIDE);
3418 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3419 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3423 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3425 PROPSHEET_AdjustSize(hwnd, psInfo);
3426 PROPSHEET_AdjustButtons(hwnd, psInfo);
3430 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3431 psInfo->ppshheader.hInstance)
3435 if (LoadStringW(psInfo->ppshheader.hInstance,
3436 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3437 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3441 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3442 psInfo->ppshheader.pszCaption);
3446 if (psInfo->useCallback)
3447 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3448 PSCB_INITIALIZED, (LPARAM)0);
3450 idx = psInfo->active_page;
3451 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3452 psInfo->active_page = -1;
3454 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3456 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3457 * as some programs call TCM_GETCURSEL to get the current selection
3458 * from which to switch to the next page */
3459 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3464 case WM_PRINTCLIENT:
3466 PROPSHEET_Paint(hwnd, (HDC)wParam);
3470 PROPSHEET_CleanUp(hwnd);
3474 PROPSHEET_Cancel(hwnd, 1);
3478 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3480 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3485 /* No default handler, forward notification to active page */
3486 if (psInfo->activeValid && psInfo->active_page != -1)
3488 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3489 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3495 switch(wParam & 0xfff0)
3498 PROPSHEET_Cancel(hwnd, 1);
3507 NMHDR* pnmh = (LPNMHDR) lParam;
3509 if (pnmh->code == TCN_SELCHANGE)
3511 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3512 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3515 if(pnmh->code == TCN_SELCHANGING)
3517 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3518 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3525 case WM_SYSCOLORCHANGE:
3526 COMCTL32_RefreshSysColors();
3529 case PSM_GETCURRENTPAGEHWND:
3531 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3538 if (psInfo->activeValid && psInfo->active_page != -1)
3539 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3541 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3547 PROPSHEET_Changed(hwnd, (HWND)wParam);
3551 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3554 case PSM_GETTABCONTROL:
3556 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3558 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3567 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3568 if(msgResult != FALSE)
3570 msgResult = PROPSHEET_SetCurSel(hwnd,
3573 (HPROPSHEETPAGE)lParam);
3576 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3581 case PSM_CANCELTOCLOSE:
3583 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3584 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3585 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3587 EnableWindow(hwndCancel, FALSE);
3588 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3589 SetWindowTextW(hwndOK, buf);
3594 case PSM_RESTARTWINDOWS:
3596 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3602 psInfo->restartWindows = TRUE;
3606 case PSM_REBOOTSYSTEM:
3608 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3614 psInfo->rebootSystem = TRUE;
3619 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3623 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3628 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3630 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3635 case PSM_QUERYSIBLINGS:
3637 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3647 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3648 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3649 * on success or FALSE otherwise, as specified on MSDN Online.
3650 * Also see the MFC code for
3651 * CPropertySheet::AddPage(CPropertyPage* pPage).
3654 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3656 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3661 case PSM_REMOVEPAGE:
3662 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3665 case PSM_ISDIALOGMESSAGE:
3667 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3668 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3672 case PSM_PRESSBUTTON:
3673 PROPSHEET_PressButton(hwnd, (int)wParam);
3676 case PSM_SETFINISHTEXTA:
3677 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3680 case PSM_SETWIZBUTTONS:
3681 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3684 case PSM_SETCURSELID:
3685 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3688 case PSM_SETFINISHTEXTW:
3689 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3692 case PSM_INSERTPAGE:
3694 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3695 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3699 case PSM_SETHEADERTITLEW:
3700 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3703 case PSM_SETHEADERTITLEA:
3704 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3707 case PSM_SETHEADERSUBTITLEW:
3708 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3711 case PSM_SETHEADERSUBTITLEA:
3712 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3715 case PSM_HWNDTOINDEX:
3717 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3718 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3722 case PSM_INDEXTOHWND:
3724 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3725 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3729 case PSM_PAGETOINDEX:
3731 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3732 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3736 case PSM_INDEXTOPAGE:
3738 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3739 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3745 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3746 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3752 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3753 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3759 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3760 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3764 case PSM_RECALCPAGESIZES:
3766 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3767 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);