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 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;
456 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
457 psInfo->proppage[index].hwndPage = 0;
458 psInfo->proppage[index].isDirty = FALSE;
461 * Process property page flags.
463 dwFlags = lppsp->dwFlags;
464 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
465 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
466 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
468 /* as soon as we have a page with the help flag, set the sheet flag on */
469 if (psInfo->proppage[index].hasHelp)
470 psInfo->hasHelp = TRUE;
473 * Process page template.
475 if (dwFlags & PSP_DLGINDIRECT)
476 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
477 else if(dwFlags & PSP_INTERNAL_UNICODE )
479 HRSRC hResource = FindResourceW(lppsp->hInstance,
480 lppsp->u.pszTemplate,
482 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
484 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
488 HRSRC hResource = FindResourceA(lppsp->hInstance,
489 (LPSTR)lppsp->u.pszTemplate,
491 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
493 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
497 * Extract the size of the page and the caption.
502 p = (const WORD *)pTemplate;
504 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
506 /* DLGTEMPLATEEX (not defined in any std. header file) */
510 p += 2; /* help ID */
511 p += 2; /* ext style */
519 p += 2; /* ext style */
525 width = (WORD)*p; p++;
526 height = (WORD)*p; p++;
528 /* Special calculation for interior wizard pages so the largest page is
529 * calculated correctly. We need to add all the padding and space occupied
530 * by the header so the width and height sums up to the whole wizard client
532 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
533 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
534 !(dwFlags & PSP_HIDEHEADER))
536 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
537 width += 2 * WIZARD_PADDING;
539 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
541 height += 2 * WIZARD_PADDING;
542 width += 2 * WIZARD_PADDING;
545 /* remember the largest width and height */
546 if (width > psInfo->width)
547 psInfo->width = width;
549 if (height > psInfo->height)
550 psInfo->height = height;
562 p += lstrlenW( (LPCWSTR)p ) + 1;
576 p += lstrlenW( (LPCWSTR)p ) + 1;
580 /* Extract the caption */
581 psInfo->proppage[index].pszText = (LPCWSTR)p;
582 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
583 p += lstrlenW((LPCWSTR)p) + 1;
585 if (dwFlags & PSP_USETITLE)
589 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
592 if ( !HIWORD( lppsp->pszTitle ) )
594 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
597 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
603 pTitle = lppsp->pszTitle;
605 len = strlenW(pTitle);
606 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
607 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
611 * Build the image list for icons
613 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
616 int icon_cx = GetSystemMetrics(SM_CXSMICON);
617 int icon_cy = GetSystemMetrics(SM_CYSMICON);
619 if (dwFlags & PSP_USEICONID)
620 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
621 icon_cx, icon_cy, LR_DEFAULTCOLOR);
623 hIcon = lppsp->u2.hIcon;
627 if (psInfo->hImageList == 0 )
628 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
630 ImageList_AddIcon(psInfo->hImageList, hIcon);
638 /******************************************************************************
639 * PROPSHEET_CreateDialog
641 * Creates the actual property sheet.
643 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
650 WORD resID = IDD_PROPSHEET;
653 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
656 if( psInfo->unicode )
658 if(!(hRes = FindResourceW(COMCTL32_hModule,
659 MAKEINTRESOURCEW(resID),
665 if(!(hRes = FindResourceA(COMCTL32_hModule,
666 MAKEINTRESOURCEA(resID),
671 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
675 * Make a copy of the dialog template.
677 resSize = SizeofResource(COMCTL32_hModule, hRes);
679 temp = Alloc(resSize);
684 memcpy(temp, template, resSize);
686 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
688 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
689 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
691 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
693 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
694 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
696 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
697 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
699 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
702 if (psInfo->useCallback)
703 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
705 /* NOTE: MSDN states "Returns a positive value if successful, or -1
706 * otherwise for modal property sheets.", but this is wrong. The
707 * actual return value is either TRUE (success), FALSE (cancel) or
709 if( psInfo->unicode )
711 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
712 (LPDLGTEMPLATEW) temp,
713 psInfo->ppshheader.hwndParent,
714 PROPSHEET_DialogProc,
716 if ( !ret ) ret = -1;
720 ret = (int)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
721 (LPDLGTEMPLATEA) temp,
722 psInfo->ppshheader.hwndParent,
723 PROPSHEET_DialogProc,
725 if ( !ret ) ret = -1;
733 /******************************************************************************
734 * PROPSHEET_SizeMismatch
736 * Verify that the tab control and the "largest" property sheet page dlg. template
739 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
741 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
742 RECT rcOrigTab, rcPage;
747 GetClientRect(hwndTabCtrl, &rcOrigTab);
748 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
749 rcOrigTab.right, rcOrigTab.bottom);
756 rcPage.right = psInfo->width;
757 rcPage.bottom = psInfo->height;
759 MapDialogRect(hwndDlg, &rcPage);
760 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
761 rcPage.right, rcPage.bottom);
763 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
765 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
771 /******************************************************************************
772 * PROPSHEET_AdjustSize
774 * Resizes the property sheet and the tab control to fit the largest page.
776 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
778 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
779 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
781 int tabOffsetX, tabOffsetY, buttonHeight;
782 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
785 /* Get the height of buttons */
786 GetClientRect(hwndButton, &rc);
787 buttonHeight = rc.bottom;
794 rc.right = psInfo->width;
795 rc.bottom = psInfo->height;
797 MapDialogRect(hwndDlg, &rc);
799 /* retrieve the dialog units */
800 units.left = units.right = 4;
801 units.top = units.bottom = 8;
802 MapDialogRect(hwndDlg, &units);
805 * Resize the tab control.
807 GetClientRect(hwndTabCtrl,&tabRect);
809 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
811 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
813 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
814 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
817 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
819 rc.right = rc.left + tabRect.right - tabRect.left;
820 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
823 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
825 tabOffsetX = -(rc.left);
826 tabOffsetY = -(rc.top);
830 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
831 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
832 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
833 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
835 GetClientRect(hwndTabCtrl, &rc);
837 TRACE("tab client rc %ld %ld %ld %ld\n",
838 rc.left, rc.top, rc.right, rc.bottom);
840 rc.right += ((padding.x * 2) + tabOffsetX);
841 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
844 * Resize the property sheet.
846 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
847 (DWORD)hwndDlg, rc.right, rc.bottom);
848 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
849 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
853 /******************************************************************************
854 * PROPSHEET_AdjustSizeWizard
856 * Resizes the property sheet to fit the largest page.
858 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
860 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
861 RECT rc, lineRect, dialogRect;
863 /* Biggest page size */
866 rc.right = psInfo->width;
867 rc.bottom = psInfo->height;
868 MapDialogRect(hwndDlg, &rc);
870 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
872 /* Add space for the buttons row */
873 GetWindowRect(hwndLine, &lineRect);
874 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
875 GetClientRect(hwndDlg, &dialogRect);
876 rc.bottom += dialogRect.bottom - lineRect.top - 1;
878 /* Convert the client coordinates to window coordinates */
879 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
881 /* Resize the property sheet */
882 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
883 (DWORD)hwndDlg, rc.right, rc.bottom);
884 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
885 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
890 /******************************************************************************
891 * PROPSHEET_AdjustButtons
893 * Adjusts the buttons' positions.
895 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
897 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
901 int buttonWidth, buttonHeight;
902 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
904 if (psInfo->hasApply)
911 * Obtain the size of the buttons.
913 GetClientRect(hwndButton, &rcSheet);
914 buttonWidth = rcSheet.right;
915 buttonHeight = rcSheet.bottom;
918 * Get the size of the property sheet.
920 GetClientRect(hwndParent, &rcSheet);
923 * All buttons will be at this y coordinate.
925 y = rcSheet.bottom - (padding.y + buttonHeight);
928 * Position OK button and make it default.
930 hwndButton = GetDlgItem(hwndParent, IDOK);
932 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
934 SetWindowPos(hwndButton, 0, x, y, 0, 0,
935 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
937 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
941 * Position Cancel button.
943 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
945 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
947 SetWindowPos(hwndButton, 0, x, y, 0, 0,
948 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
951 * Position Apply button.
953 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
955 if (psInfo->hasApply)
958 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
960 x = rcSheet.right - (padding.x + buttonWidth);
962 SetWindowPos(hwndButton, 0, x, y, 0, 0,
963 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
965 EnableWindow(hwndButton, FALSE);
968 ShowWindow(hwndButton, SW_HIDE);
971 * Position Help button.
973 hwndButton = GetDlgItem(hwndParent, IDHELP);
977 x = rcSheet.right - (padding.x + buttonWidth);
979 SetWindowPos(hwndButton, 0, x, y, 0, 0,
980 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
983 ShowWindow(hwndButton, SW_HIDE);
988 /******************************************************************************
989 * PROPSHEET_AdjustButtonsWizard
991 * Adjusts the buttons' positions.
993 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
994 PropSheetInfo* psInfo)
996 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
997 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
998 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1001 int num_buttons = 3;
1002 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1003 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1005 if (psInfo->hasHelp)
1007 if (psInfo->hasFinish)
1011 * Obtain the size of the buttons.
1013 GetClientRect(hwndButton, &rcSheet);
1014 buttonWidth = rcSheet.right;
1015 buttonHeight = rcSheet.bottom;
1017 GetClientRect(hwndLine, &rcSheet);
1018 lineHeight = rcSheet.bottom;
1021 * Get the size of the property sheet.
1023 GetClientRect(hwndParent, &rcSheet);
1026 * All buttons will be at this y coordinate.
1028 y = rcSheet.bottom - (padding.y + buttonHeight);
1031 * Position the Back button.
1033 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1035 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
1037 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1038 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1041 * Position the Next button.
1043 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1047 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1048 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1051 * Position the Finish button.
1053 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1055 if (psInfo->hasFinish)
1056 x += padding.x + buttonWidth;
1058 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1059 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1061 if (!psInfo->hasFinish)
1062 ShowWindow(hwndButton, SW_HIDE);
1065 * Position the Cancel button.
1067 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1069 x += padding.x + buttonWidth;
1071 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1072 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1075 * Position Help button.
1077 hwndButton = GetDlgItem(hwndParent, IDHELP);
1079 if (psInfo->hasHelp)
1081 x += padding.x + buttonWidth;
1083 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1084 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1087 ShowWindow(hwndButton, SW_HIDE);
1089 if (psInfo->ppshheader.dwFlags &
1090 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1094 * Position and resize the sunken line.
1097 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1099 lineWidth = rcSheet.right - (padding.x * 2);
1100 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1101 SWP_NOZORDER | SWP_NOACTIVATE);
1104 * Position and resize the header sunken line.
1107 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1108 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1109 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1110 ShowWindow(hwndLineHeader, SW_HIDE);
1115 /******************************************************************************
1116 * PROPSHEET_GetPaddingInfo
1118 * Returns the layout information.
1120 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1122 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1125 PADDING_INFO padding;
1127 GetWindowRect(hwndTab, &rcTab);
1132 ScreenToClient(hwndDlg, &tl);
1140 /******************************************************************************
1141 * PROPSHEET_GetPaddingInfoWizard
1143 * Returns the layout information.
1144 * Vertical spacing is the distance between the line and the buttons.
1145 * Do NOT use the Help button to gather padding information when it isn't mapped
1146 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1147 * for it in this case !
1148 * FIXME: I'm not sure about any other coordinate problems with these evil
1149 * buttons. Fix it in case additional problems appear or maybe calculate
1150 * a padding in a completely different way, as this is somewhat messy.
1152 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1155 PADDING_INFO padding;
1159 POINT ptButton, ptLine;
1162 if (psInfo->hasHelp)
1168 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1170 idButton = IDC_NEXT_BUTTON;
1174 /* hopefully this is ok */
1175 idButton = IDCANCEL;
1179 hwndControl = GetDlgItem(hwndDlg, idButton);
1180 GetWindowRect(hwndControl, &rc);
1182 ptButton.x = rc.left;
1183 ptButton.y = rc.top;
1185 ScreenToClient(hwndDlg, &ptButton);
1188 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1189 GetWindowRect(hwndControl, &rc);
1192 ptLine.y = rc.bottom;
1194 ScreenToClient(hwndDlg, &ptLine);
1196 padding.y = ptButton.y - ptLine.y;
1199 ERR("padding negative ! Please report this !\n");
1201 /* this is most probably not correct, but the best we have now */
1202 padding.x = padding.y;
1206 /******************************************************************************
1207 * PROPSHEET_CreateTabControl
1209 * Insert the tabs in the tab control.
1211 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1212 PropSheetInfo * psInfo)
1214 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1220 item.mask = TCIF_TEXT;
1221 item.cchTextMax = MAX_TABTEXT_LENGTH;
1223 nTabs = psInfo->nPages;
1226 * Set the image list for icons.
1228 if (psInfo->hImageList)
1230 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1233 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1234 for (i = 0; i < nTabs; i++)
1236 if ( psInfo->proppage[i].hasIcon )
1238 item.mask |= TCIF_IMAGE;
1239 item.iImage = iImage++;
1243 item.mask &= ~TCIF_IMAGE;
1246 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1247 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1249 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1254 /******************************************************************************
1255 * PROPSHEET_WizardSubclassProc
1257 * Subclassing window procedure for wizard extrior pages to prevent drawing
1258 * background and so drawing above the watermark.
1260 static LRESULT CALLBACK
1261 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1268 case WM_CTLCOLORSTATIC:
1269 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1270 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1273 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1277 * Get the size of an in-memory Template
1279 *( Based on the code of PROPSHEET_CollectPageInfo)
1280 * See also dialog.c/DIALOG_ParseTemplate32().
1283 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1286 const WORD* p = (const WORD *)pTemplate;
1287 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1292 /* DLGTEMPLATEEX (not defined in any std. header file) */
1294 TRACE("is DLGTEMPLATEEX\n");
1296 p++; /* signature */
1297 p += 2; /* help ID */
1298 p += 2; /* ext style */
1305 TRACE("is DLGTEMPLATE\n");
1307 p += 2; /* ext style */
1310 nrofitems = (WORD)*p; p++; /* nb items */
1326 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1327 p += lstrlenW( (LPCWSTR)p ) + 1;
1338 p += 2; /* 0xffff plus predefined window class ordinal value */
1341 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1342 p += lstrlenW( (LPCWSTR)p ) + 1;
1347 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1348 p += lstrlenW((LPCWSTR)p) + 1;
1350 /* font, if DS_SETFONT set */
1351 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1354 p+=(istemplateex)?3:1;
1355 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1356 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1359 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1360 * that are following the DLGTEMPLATE(EX) data */
1361 TRACE("%d items\n",nrofitems);
1362 while (nrofitems > 0)
1364 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1367 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1376 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1380 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1381 p += lstrlenW( (LPCWSTR)p ) + 1;
1385 /* check title text */
1392 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1396 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1397 p += lstrlenW( (LPCWSTR)p ) + 1;
1400 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1404 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1405 return (p - (WORD*)pTemplate)*sizeof(WORD);
1409 /******************************************************************************
1410 * PROPSHEET_CreatePage
1414 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1416 const PropSheetInfo * psInfo,
1417 LPCPROPSHEETPAGEW ppshpage)
1419 DLGTEMPLATE* pTemplate;
1424 TRACE("index %d\n", index);
1426 if (ppshpage == NULL)
1431 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1433 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1434 resSize = GetTemplateSize(pTemplate);
1436 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1441 hResource = FindResourceW(ppshpage->hInstance,
1442 ppshpage->u.pszTemplate,
1447 resSize = SizeofResource(ppshpage->hInstance, hResource);
1449 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1453 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1455 * Make a copy of the dialog template to make it writable
1463 hResource = FindResourceA(ppshpage->hInstance,
1464 (LPSTR)ppshpage->u.pszTemplate,
1469 resSize = SizeofResource(ppshpage->hInstance, hResource);
1471 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1475 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1477 * Make a copy of the dialog template to make it writable
1480 temp = Alloc(resSize);
1484 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1485 memcpy(temp, pTemplate, resSize);
1488 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1490 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1491 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1492 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1493 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1494 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1495 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1496 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1497 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1503 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1504 pTemplate->style &= ~DS_MODALFRAME;
1505 pTemplate->style &= ~WS_CAPTION;
1506 pTemplate->style &= ~WS_SYSMENU;
1507 pTemplate->style &= ~WS_POPUP;
1508 pTemplate->style &= ~WS_DISABLED;
1509 pTemplate->style &= ~WS_VISIBLE;
1510 pTemplate->style &= ~WS_THICKFRAME;
1512 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1515 if (psInfo->proppage[index].useCallback)
1516 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1517 (LPPROPSHEETPAGEW)ppshpage);
1519 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1520 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1523 ppshpage->pfnDlgProc,
1526 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1529 ppshpage->pfnDlgProc,
1531 /* Free a no more needed copy */
1535 psInfo->proppage[index].hwndPage = hwndPage;
1537 /* Subclass exterior wizard pages */
1538 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1539 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1540 (ppshpage->dwFlags & PSP_HIDEHEADER))
1542 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1543 (DWORD_PTR)ppshpage);
1545 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1546 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1551 /******************************************************************************
1552 * PROPSHEET_LoadWizardBitmaps
1554 * Loads the watermark and header bitmaps for a wizard.
1556 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1558 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1560 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1561 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1562 considers hbmWatermark as valid. */
1563 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1564 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1566 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1567 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1570 /* Same behavior as for watermarks */
1571 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1572 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1574 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1575 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1581 /******************************************************************************
1582 * PROPSHEET_ShowPage
1584 * Displays or creates the specified page.
1586 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1589 HWND hwndLineHeader;
1590 LPCPROPSHEETPAGEW ppshpage;
1592 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1593 if (index == psInfo->active_page)
1595 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1596 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1600 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1601 if (psInfo->proppage[index].hwndPage == 0)
1603 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1606 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1607 (ppshpage->dwFlags & PSP_USETITLE))
1609 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1610 psInfo->proppage[index].pszText);
1613 if (psInfo->active_page != -1)
1614 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1616 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1618 /* Synchronize current selection with tab control
1619 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1620 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1621 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1623 psInfo->active_page = index;
1624 psInfo->activeValid = TRUE;
1626 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1628 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1629 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1631 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1632 ShowWindow(hwndLineHeader, SW_HIDE);
1634 ShowWindow(hwndLineHeader, SW_SHOW);
1640 /******************************************************************************
1643 static BOOL PROPSHEET_Back(HWND hwndDlg)
1647 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1652 TRACE("active_page %d\n", psInfo->active_page);
1653 if (psInfo->active_page < 0)
1656 psn.hdr.code = PSN_WIZBACK;
1657 psn.hdr.hwndFrom = hwndDlg;
1661 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1663 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1666 else if (result == 0)
1667 idx = psInfo->active_page - 1;
1669 idx = PROPSHEET_FindPageByResId(psInfo, result);
1671 if (idx >= 0 && idx < psInfo->nPages)
1673 if (PROPSHEET_CanSetCurSel(hwndDlg))
1674 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1679 /******************************************************************************
1682 static BOOL PROPSHEET_Next(HWND hwndDlg)
1686 LRESULT msgResult = 0;
1687 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1691 TRACE("active_page %d\n", psInfo->active_page);
1692 if (psInfo->active_page < 0)
1695 psn.hdr.code = PSN_WIZNEXT;
1696 psn.hdr.hwndFrom = hwndDlg;
1700 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1702 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1703 if (msgResult == -1)
1705 else if (msgResult == 0)
1706 idx = psInfo->active_page + 1;
1708 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1710 if (idx < psInfo->nPages )
1712 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1713 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1719 /******************************************************************************
1722 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1726 LRESULT msgResult = 0;
1727 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1730 TRACE("active_page %d\n", psInfo->active_page);
1731 if (psInfo->active_page < 0)
1734 psn.hdr.code = PSN_WIZFINISH;
1735 psn.hdr.hwndFrom = hwndDlg;
1739 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1741 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1743 TRACE("msg result %ld\n", msgResult);
1748 if (psInfo->isModeless)
1749 psInfo->activeValid = FALSE;
1751 psInfo->ended = TRUE;
1756 /******************************************************************************
1759 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1764 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1767 TRACE("active_page %d\n", psInfo->active_page);
1768 if (psInfo->active_page < 0)
1771 psn.hdr.hwndFrom = hwndDlg;
1777 * Send PSN_KILLACTIVE to the current page.
1779 psn.hdr.code = PSN_KILLACTIVE;
1781 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1783 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1787 * Send PSN_APPLY to all pages.
1789 psn.hdr.code = PSN_APPLY;
1790 psn.lParam = lParam;
1792 for (i = 0; i < psInfo->nPages; i++)
1794 hwndPage = psInfo->proppage[i].hwndPage;
1797 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1799 case PSNRET_INVALID:
1800 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1802 case PSNRET_INVALID_NOCHANGEPAGE:
1810 psInfo->activeValid = FALSE;
1812 else if(psInfo->active_page >= 0)
1814 psn.hdr.code = PSN_SETACTIVE;
1816 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1817 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1823 /******************************************************************************
1826 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1828 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1834 TRACE("active_page %d\n", psInfo->active_page);
1835 if (psInfo->active_page < 0)
1838 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1839 psn.hdr.code = PSN_QUERYCANCEL;
1840 psn.hdr.hwndFrom = hwndDlg;
1844 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1847 psn.hdr.code = PSN_RESET;
1848 psn.lParam = lParam;
1850 for (i = 0; i < psInfo->nPages; i++)
1852 hwndPage = psInfo->proppage[i].hwndPage;
1855 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1858 if (psInfo->isModeless)
1860 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1861 psInfo->activeValid = FALSE;
1864 psInfo->ended = TRUE;
1867 /******************************************************************************
1870 static void PROPSHEET_Help(HWND hwndDlg)
1872 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1877 TRACE("active_page %d\n", psInfo->active_page);
1878 if (psInfo->active_page < 0)
1881 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1882 psn.hdr.code = PSN_HELP;
1883 psn.hdr.hwndFrom = hwndDlg;
1887 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1890 /******************************************************************************
1893 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1896 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1900 if (!psInfo) return;
1902 * Set the dirty flag of this page.
1904 for (i = 0; i < psInfo->nPages; i++)
1906 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1907 psInfo->proppage[i].isDirty = TRUE;
1911 * Enable the Apply button.
1913 if (psInfo->hasApply)
1915 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1917 EnableWindow(hwndApplyBtn, TRUE);
1921 /******************************************************************************
1922 * PROPSHEET_UnChanged
1924 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1927 BOOL noPageDirty = TRUE;
1928 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1929 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1933 if ( !psInfo ) return;
1934 for (i = 0; i < psInfo->nPages; i++)
1936 /* set the specified page as clean */
1937 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1938 psInfo->proppage[i].isDirty = FALSE;
1940 /* look to see if there's any dirty pages */
1941 if (psInfo->proppage[i].isDirty)
1942 noPageDirty = FALSE;
1946 * Disable Apply button.
1949 EnableWindow(hwndApplyBtn, FALSE);
1952 /******************************************************************************
1953 * PROPSHEET_PressButton
1955 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1957 TRACE("buttonID %d\n", buttonID);
1960 case PSBTN_APPLYNOW:
1961 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1964 PROPSHEET_Back(hwndDlg);
1967 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1970 PROPSHEET_Finish(hwndDlg);
1973 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1976 PROPSHEET_Next(hwndDlg);
1979 PROPSHEET_DoCommand(hwndDlg, IDOK);
1982 FIXME("Invalid button index %d\n", buttonID);
1987 /*************************************************************************
1988 * BOOL PROPSHEET_CanSetCurSel [Internal]
1990 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1993 * hwndDlg [I] handle to a Dialog hWnd
1996 * TRUE if Current Selection can change
2000 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2002 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2008 TRACE("active_page %d\n", psInfo->active_page);
2015 if (psInfo->active_page < 0)
2022 * Notify the current page.
2024 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2025 psn.hdr.code = PSN_KILLACTIVE;
2026 psn.hdr.hwndFrom = hwndDlg;
2030 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2033 TRACE("<-- %d\n", res);
2037 /******************************************************************************
2038 * PROPSHEET_SetCurSel
2040 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2043 HPROPSHEETPAGE hpage
2046 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2047 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2048 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2050 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2051 /* hpage takes precedence over index */
2053 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2055 if (index < 0 || index >= psInfo->nPages)
2057 TRACE("Could not find page to select!\n");
2065 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2068 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2070 psn.hdr.code = PSN_SETACTIVE;
2071 psn.hdr.hwndFrom = hwndDlg;
2075 if (!psInfo->proppage[index].hwndPage) {
2076 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2079 /* Resize the property sheet page to the fit in the Tab control
2080 * (for regular property sheets) or to fit in the client area (for
2082 * NOTE: The resizing happens every time the page is selected and
2083 * not only when it's created (some applications depend on it). */
2084 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2085 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2086 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2087 rc.right - rc.left, rc.bottom - rc.top);
2088 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2090 rc.right - rc.left, rc.bottom - rc.top, 0);
2092 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2099 WARN("Tried to skip before first property sheet page!\n");
2102 if (index >= psInfo->nPages) {
2103 WARN("Tried to skip after last property sheet page!\n");
2104 index = psInfo->nPages-1;
2108 else if (result != 0)
2110 int old_index = index;
2111 index = PROPSHEET_FindPageByResId(psInfo, result);
2112 if(index >= psInfo->nPages) {
2114 WARN("Tried to skip to nonexistant page by res id\n");
2121 * Display the new page.
2123 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2125 if (psInfo->proppage[index].hasHelp)
2126 EnableWindow(hwndHelp, TRUE);
2128 EnableWindow(hwndHelp, FALSE);
2133 /******************************************************************************
2134 * PROPSHEET_SetCurSelId
2136 * Selects the page, specified by resource id.
2138 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2141 PropSheetInfo* psInfo =
2142 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2144 idx = PROPSHEET_FindPageByResId(psInfo, id);
2145 if (idx < psInfo->nPages )
2147 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2148 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2152 /******************************************************************************
2153 * PROPSHEET_SetTitleA
2155 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2157 if(HIWORD(lpszText))
2160 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2161 szTitle, sizeof(szTitle));
2162 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2166 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2170 /******************************************************************************
2171 * PROPSHEET_SetTitleW
2173 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2175 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2178 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2179 if (HIWORD(lpszText) == 0) {
2180 if (!LoadStringW(psInfo->ppshheader.hInstance,
2181 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2185 if (dwStyle & PSH_PROPTITLE)
2188 int lentitle = strlenW(lpszText);
2189 int lenprop = strlenW(psInfo->strPropertiesFor);
2191 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2192 strcpyW(dest, psInfo->strPropertiesFor);
2193 strcatW(dest, lpszText);
2195 SetWindowTextW(hwndDlg, dest);
2199 SetWindowTextW(hwndDlg, lpszText);
2202 /******************************************************************************
2203 * PROPSHEET_SetFinishTextA
2205 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2207 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2208 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2210 TRACE("'%s'\n", lpszText);
2211 /* Set text, show and enable the Finish button */
2212 SetWindowTextA(hwndButton, lpszText);
2213 ShowWindow(hwndButton, SW_SHOW);
2214 EnableWindow(hwndButton, TRUE);
2216 /* Make it default pushbutton */
2217 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2219 /* Hide Back button */
2220 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2221 ShowWindow(hwndButton, SW_HIDE);
2223 if (!psInfo->hasFinish)
2225 /* Hide Next button */
2226 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2227 ShowWindow(hwndButton, SW_HIDE);
2231 /******************************************************************************
2232 * PROPSHEET_SetFinishTextW
2234 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2236 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2237 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2239 TRACE("'%s'\n", debugstr_w(lpszText));
2240 /* Set text, show and enable the Finish button */
2241 SetWindowTextW(hwndButton, lpszText);
2242 ShowWindow(hwndButton, SW_SHOW);
2243 EnableWindow(hwndButton, TRUE);
2245 /* Make it default pushbutton */
2246 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2248 /* Hide Back button */
2249 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2250 ShowWindow(hwndButton, SW_HIDE);
2252 if (!psInfo->hasFinish)
2254 /* Hide Next button */
2255 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2256 ShowWindow(hwndButton, SW_HIDE);
2260 /******************************************************************************
2261 * PROPSHEET_QuerySiblings
2263 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2264 WPARAM wParam, LPARAM lParam)
2268 LRESULT msgResult = 0;
2269 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2271 while ((i < psInfo->nPages) && (msgResult == 0))
2273 hwndPage = psInfo->proppage[i].hwndPage;
2274 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2282 /******************************************************************************
2285 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2286 HPROPSHEETPAGE hpage)
2288 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2290 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2292 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2294 TRACE("hpage %p\n", hpage);
2296 * Allocate and fill in a new PropPageInfo entry.
2298 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2299 sizeof(PropPageInfo) *
2300 (psInfo->nPages + 1));
2301 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2304 psInfo->proppage[psInfo->nPages].hpage = hpage;
2306 if (ppsp->dwFlags & PSP_PREMATURE)
2308 /* Create the page but don't show it */
2309 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2313 * Add a new tab to the tab control.
2315 item.mask = TCIF_TEXT;
2316 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2317 item.cchTextMax = MAX_TABTEXT_LENGTH;
2319 if (psInfo->hImageList)
2321 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2324 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2326 item.mask |= TCIF_IMAGE;
2327 item.iImage = psInfo->nPages;
2330 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2335 /* If it is the only page - show it */
2336 if(psInfo->nPages == 1)
2337 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2341 /******************************************************************************
2342 * PROPSHEET_RemovePage
2344 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2346 HPROPSHEETPAGE hpage)
2348 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2350 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2351 PropPageInfo* oldPages;
2353 TRACE("index %d, hpage %p\n", index, hpage);
2358 * hpage takes precedence over index.
2362 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2365 /* Make sure that index is within range */
2366 if (index < 0 || index >= psInfo->nPages)
2368 TRACE("Could not find page to remove!\n");
2372 TRACE("total pages %d removing page %d active page %d\n",
2373 psInfo->nPages, index, psInfo->active_page);
2375 * Check if we're removing the active page.
2377 if (index == psInfo->active_page)
2379 if (psInfo->nPages > 1)
2383 /* activate previous page */
2384 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2388 /* activate the next page */
2389 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2390 psInfo->active_page = index;
2395 psInfo->active_page = -1;
2396 if (!psInfo->isModeless)
2398 psInfo->ended = TRUE;
2403 else if (index < psInfo->active_page)
2404 psInfo->active_page--;
2406 /* Unsubclass the page dialog window */
2407 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2408 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2409 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2411 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2412 PROPSHEET_WizardSubclassProc, 1);
2415 /* Destroy page dialog window */
2416 DestroyWindow(psInfo->proppage[index].hwndPage);
2418 /* Free page resources */
2419 if(psInfo->proppage[index].hpage)
2421 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2423 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2424 Free ((LPVOID)psInfo->proppage[index].pszText);
2426 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2429 /* Remove the tab */
2430 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2432 oldPages = psInfo->proppage;
2434 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2437 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2439 if (index < psInfo->nPages)
2440 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2441 (psInfo->nPages - index) * sizeof(PropPageInfo));
2448 /******************************************************************************
2449 * PROPSHEET_SetWizButtons
2451 * This code will work if (and assumes that) the Next button is on top of the
2452 * Finish button. ie. Finish comes after Next in the Z order.
2453 * This means make sure the dialog template reflects this.
2456 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2458 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2460 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2461 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2462 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2464 TRACE("%ld\n", dwFlags);
2466 EnableWindow(hwndBack, FALSE);
2467 EnableWindow(hwndNext, FALSE);
2468 EnableWindow(hwndFinish, FALSE);
2470 if (dwFlags & PSWIZB_BACK)
2471 EnableWindow(hwndBack, TRUE);
2473 if (dwFlags & PSWIZB_NEXT)
2475 if (!psInfo->hasFinish)
2477 /* Hide the Finish button */
2478 ShowWindow(hwndFinish, SW_HIDE);
2481 /* Show and enable the Next button */
2482 ShowWindow(hwndNext, SW_SHOW);
2483 EnableWindow(hwndNext, TRUE);
2485 /* Set the Next button as the default pushbutton */
2486 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2489 if (!psInfo->hasFinish)
2491 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2493 /* Hide the Next button */
2494 ShowWindow(hwndNext, SW_HIDE);
2496 /* Show the Finish button */
2497 ShowWindow(hwndFinish, SW_SHOW);
2499 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2501 EnableWindow(hwndFinish, TRUE);
2503 /* Set the Finish button as the default pushbutton */
2504 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2508 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2509 EnableWindow(hwndFinish, TRUE);
2512 /******************************************************************************
2513 * PROPSHEET_InsertPage
2515 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2517 if (!HIWORD(hpageInsertAfter))
2518 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2520 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2524 /******************************************************************************
2525 * PROPSHEET_SetHeaderTitleW
2527 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2529 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2532 /******************************************************************************
2533 * PROPSHEET_SetHeaderTitleA
2535 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2537 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2540 /******************************************************************************
2541 * PROPSHEET_SetHeaderSubTitleW
2543 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2545 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2548 /******************************************************************************
2549 * PROPSHEET_SetHeaderSubTitleA
2551 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2553 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2556 /******************************************************************************
2557 * PROPSHEET_HwndToIndex
2559 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2562 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2565 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2567 for (index = 0; index < psInfo->nPages; index++)
2568 if (psInfo->proppage[index].hwndPage == hPageDlg)
2570 WARN("%p not found\n", hPageDlg);
2574 /******************************************************************************
2575 * PROPSHEET_IndexToHwnd
2577 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2579 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2581 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2582 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2583 WARN("%d out of range.\n", iPageIndex);
2586 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2589 /******************************************************************************
2590 * PROPSHEET_PageToIndex
2592 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2595 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2598 TRACE("(%p, %p)\n", hwndDlg, hPage);
2600 for (index = 0; index < psInfo->nPages; index++)
2601 if (psInfo->proppage[index].hpage == hPage)
2603 WARN("%p not found\n", hPage);
2607 /******************************************************************************
2608 * PROPSHEET_IndexToPage
2610 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2612 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2614 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2615 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2616 WARN("%d out of range.\n", iPageIndex);
2619 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2622 /******************************************************************************
2623 * PROPSHEET_IdToIndex
2625 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2628 LPCPROPSHEETPAGEW psp;
2629 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2631 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2632 for (index = 0; index < psInfo->nPages; index++) {
2633 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2634 if (psp->u.pszTemplate == (LPCWSTR)iPageId)
2641 /******************************************************************************
2642 * PROPSHEET_IndexToId
2644 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2646 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2648 LPCPROPSHEETPAGEW psp;
2649 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2650 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2651 WARN("%d out of range.\n", iPageIndex);
2654 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2655 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2658 return (LRESULT)psp->u.pszTemplate;
2661 /******************************************************************************
2662 * PROPSHEET_GetResult
2664 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2666 FIXME("(%p): stub\n", hwndDlg);
2670 /******************************************************************************
2671 * PROPSHEET_RecalcPageSizes
2673 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2675 FIXME("(%p): stub\n", hwndDlg);
2679 /******************************************************************************
2680 * PROPSHEET_GetPageIndex
2682 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2683 * the array of PropPageInfo.
2685 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2690 TRACE("hpage %p\n", hpage);
2691 while ((index < psInfo->nPages) && (found == FALSE))
2693 if (psInfo->proppage[index].hpage == hpage)
2705 /******************************************************************************
2708 static void PROPSHEET_CleanUp(HWND hwndDlg)
2711 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2715 if (!psInfo) return;
2716 if (HIWORD(psInfo->ppshheader.pszCaption))
2717 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2719 for (i = 0; i < psInfo->nPages; i++)
2721 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2723 /* Unsubclass the page dialog window */
2724 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2725 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2726 (psp->dwFlags & PSP_HIDEHEADER))
2728 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2729 PROPSHEET_WizardSubclassProc, 1);
2732 if(psInfo->proppage[i].hwndPage)
2733 DestroyWindow(psInfo->proppage[i].hwndPage);
2737 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2738 Free ((LPVOID)psInfo->proppage[i].pszText);
2740 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2744 DeleteObject(psInfo->hFont);
2745 DeleteObject(psInfo->hFontBold);
2746 /* If we created the bitmaps, destroy them */
2747 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2748 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2749 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2750 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2751 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2752 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2754 Free(psInfo->proppage);
2755 Free(psInfo->strPropertiesFor);
2756 ImageList_Destroy(psInfo->hImageList);
2758 GlobalFree((HGLOBAL)psInfo);
2761 static INT do_loop(PropSheetInfo *psInfo)
2765 HWND hwnd = psInfo->hwnd;
2767 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2772 if(!IsDialogMessageW(hwnd, &msg))
2774 TranslateMessage(&msg);
2775 DispatchMessageW(&msg);
2781 PostQuitMessage(msg.wParam);
2785 DestroyWindow(hwnd);
2789 /******************************************************************************
2790 * PropertySheet (COMCTL32.@)
2791 * PropertySheetA (COMCTL32.@)
2793 * Creates a property sheet in the specified property sheet header.
2796 * Modal property sheets: Positive if successful or -1 otherwise.
2797 * Modeless property sheets: Property sheet handle.
2799 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2800 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2802 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2805 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2806 sizeof(PropSheetInfo));
2810 TRACE("(%p)\n", lppsh);
2812 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2814 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2816 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2818 for (n = i = 0; i < lppsh->nPages; i++, n++)
2820 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2821 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2824 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2825 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2828 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2831 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2832 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2838 psInfo->unicode = FALSE;
2839 psInfo->ended = FALSE;
2841 bRet = PROPSHEET_CreateDialog(psInfo);
2842 if(!psInfo->isModeless)
2843 bRet = do_loop(psInfo);
2848 /******************************************************************************
2849 * PropertySheetW (COMCTL32.@)
2851 * See PropertySheetA.
2853 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2856 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2857 sizeof(PropSheetInfo));
2861 TRACE("(%p)\n", lppsh);
2863 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2865 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2867 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2869 for (n = i = 0; i < lppsh->nPages; i++, n++)
2871 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2872 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2875 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2876 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2879 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2882 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2883 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2889 psInfo->unicode = TRUE;
2890 psInfo->ended = FALSE;
2892 bRet = PROPSHEET_CreateDialog(psInfo);
2893 if(!psInfo->isModeless)
2894 bRet = do_loop(psInfo);
2899 /******************************************************************************
2900 * CreatePropertySheetPage (COMCTL32.@)
2901 * CreatePropertySheetPageA (COMCTL32.@)
2903 * Creates a new property sheet page.
2906 * Success: Handle to new property sheet page.
2910 * An application must use the PSM_ADDPAGE message to add the new page to
2911 * an existing property sheet.
2913 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2914 LPCPROPSHEETPAGEA lpPropSheetPage)
2916 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2918 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2920 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2921 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2923 int len = strlen(lpPropSheetPage->u.pszTemplate);
2925 ppsp->u.pszTemplate = Alloc( len+1 );
2926 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2928 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2930 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2933 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2935 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2937 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2938 ppsp->pszTitle = NULL;
2940 return (HPROPSHEETPAGE)ppsp;
2943 /******************************************************************************
2944 * CreatePropertySheetPageW (COMCTL32.@)
2946 * See CreatePropertySheetA.
2948 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2950 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2952 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2954 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2956 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2958 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2960 ppsp->u.pszTemplate = Alloc( (len+1)*sizeof (WCHAR) );
2961 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2963 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2965 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2966 ppsp->u2.pszIcon = Alloc( (len+1)*sizeof (WCHAR) );
2967 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2970 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2972 int len = strlenW(lpPropSheetPage->pszTitle);
2973 ppsp->pszTitle = Alloc( (len+1)*sizeof (WCHAR) );
2974 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2976 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2977 ppsp->pszTitle = NULL;
2979 return (HPROPSHEETPAGE)ppsp;
2982 /******************************************************************************
2983 * DestroyPropertySheetPage (COMCTL32.@)
2985 * Destroys a property sheet page previously created with
2986 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2993 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2995 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3000 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3001 Free ((LPVOID)psp->u.pszTemplate);
3003 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3004 Free ((LPVOID)psp->u2.pszIcon);
3006 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3007 Free ((LPVOID)psp->pszTitle);
3014 /******************************************************************************
3015 * PROPSHEET_IsDialogMessage
3017 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3019 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3022 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3025 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3028 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3030 if (!(dlgCode & DLGC_WANTMESSAGE))
3032 switch (lpMsg->wParam)
3035 if (GetKeyState(VK_SHIFT) & 0x8000)
3041 case VK_NEXT: new_page = 1; break;
3042 case VK_PRIOR: new_page = -1; break;
3048 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3050 new_page += psInfo->active_page;
3053 new_page = psInfo->nPages - 1;
3054 else if (new_page >= psInfo->nPages)
3057 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3064 return IsDialogMessageW(hwnd, lpMsg);
3067 /******************************************************************************
3068 * PROPSHEET_DoCommand
3070 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3076 case IDC_APPLY_BUTTON:
3078 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3080 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3085 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3089 if (psInfo->restartWindows)
3090 result = ID_PSRESTARTWINDOWS;
3092 /* reboot system takes precedence over restart windows */
3093 if (psInfo->rebootSystem)
3094 result = ID_PSREBOOTSYSTEM;
3096 if (psInfo->isModeless)
3097 psInfo->activeValid = FALSE;
3099 psInfo->ended = TRUE;
3102 EnableWindow(hwndApplyBtn, FALSE);
3107 case IDC_BACK_BUTTON:
3108 PROPSHEET_Back(hwnd);
3111 case IDC_NEXT_BUTTON:
3112 PROPSHEET_Next(hwnd);
3115 case IDC_FINISH_BUTTON:
3116 PROPSHEET_Finish(hwnd);
3120 PROPSHEET_Cancel(hwnd, 0);
3124 PROPSHEET_Help(hwnd);
3134 /******************************************************************************
3137 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3139 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3144 HPALETTE hOldPal = 0;
3148 LPCPROPSHEETPAGEW ppshpage;
3149 WCHAR szBuffer[256];
3152 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3155 hdcSrc = CreateCompatibleDC(0);
3156 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3158 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3159 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3161 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3162 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3163 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3165 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3167 COLORREF clrOld = 0;
3170 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3171 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3173 GetClientRect(hwndLineHeader, &r);
3174 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3175 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3177 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3179 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3181 /* Fill the unoccupied part of the header with color of the
3182 * left-top pixel, but do it only when needed.
3184 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3186 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3187 CopyRect(&r, &rzone);
3188 if (bm.bmWidth < r.right)
3190 r.left = bm.bmWidth;
3191 FillRect(hdc, &r, hbr);
3193 if (bm.bmHeight < r.bottom)
3196 r.top = bm.bmHeight;
3197 FillRect(hdc, &r, hbr);
3202 /* Draw the header itself. */
3204 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3205 hdcSrc, 0, 0, SRCCOPY);
3209 hbr = GetSysColorBrush(COLOR_WINDOW);
3210 FillRect(hdc, &rzone, hbr);
3212 /* Draw the header bitmap. It's always centered like a
3213 * common 49 x 49 bitmap. */
3214 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3215 (rzone.bottom - 49) / 2,
3216 bm.bmWidth, bm.bmHeight,
3217 hdcSrc, 0, 0, SRCCOPY);
3219 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3220 * if its height is smaller than 49 pixels. Because the reason
3221 * for this bug is unknown the current code doesn't try to
3225 clrOld = SetTextColor (hdc, 0x00000000);
3226 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3228 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3229 SetRect(&r, 20, 10, 0, 0);
3230 if (HIWORD(ppshpage->pszHeaderTitle))
3232 if (psInfo->unicode)
3233 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3234 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3236 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3237 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3241 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderTitle,
3245 DrawTextW(hdc, szBuffer, nLength,
3246 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3251 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3252 SelectObject(hdc, psInfo->hFont);
3253 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3254 if (HIWORD(ppshpage->pszHeaderTitle))
3256 if (psInfo->unicode)
3257 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3258 -1, &r, DT_LEFT | DT_SINGLELINE);
3260 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3261 -1, &r, DT_LEFT | DT_SINGLELINE);
3265 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderSubTitle,
3269 DrawTextW(hdc, szBuffer, nLength,
3270 &r, DT_LEFT | DT_SINGLELINE);
3275 offsety = rzone.bottom + 2;
3277 SetTextColor(hdc, clrOld);
3278 SetBkMode(hdc, oldBkMode);
3279 SelectObject(hdc, hOldFont);
3280 SelectObject(hdcSrc, hbmp);
3283 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3284 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3285 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3287 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3289 GetClientRect(hwndLine, &r);
3290 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3294 rzone.right = r.right;
3295 rzone.bottom = r.top - 1;
3297 hbr = GetSysColorBrush(COLOR_WINDOW);
3298 FillRect(hdc, &rzone, hbr);
3300 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3301 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3303 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3304 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3306 /* If the bitmap is not big enough, fill the remaining area
3307 with the color of pixel (0,0) of bitmap - see MSDN */
3308 if (r.top > bm.bmHeight) {
3309 r.bottom = r.top - 1;
3310 r.top = bm.bmHeight;
3312 r.right = bm.bmWidth;
3313 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3314 FillRect(hdc, &r, hbr);
3318 SelectObject(hdcSrc, hbmp);
3321 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3322 SelectPalette(hdc, hOldPal, FALSE);
3326 if (!hdcParam) EndPaint(hwnd, &ps);
3331 /******************************************************************************
3332 * PROPSHEET_DialogProc
3335 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3337 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3338 hwnd, uMsg, wParam, lParam);
3344 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3345 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3346 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3347 LPCPROPSHEETPAGEW ppshpage;
3351 /* Using PropSheetInfoStr to store extra data doesn't match the native
3352 * common control: native uses TCM_[GS]ETITEM
3354 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3357 * psInfo->hwnd is not being used by WINE code - it exists
3358 * for compatibility with "real" Windoze. The same about
3359 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3362 psInfo->hwnd = hwnd;
3363 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3365 /* set up the Next and Back buttons by default */
3366 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3369 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3370 psInfo->hFont = CreateFontIndirectW (&logFont);
3371 logFont.lfWeight = FW_BOLD;
3372 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3375 * Small icon in the title bar.
3377 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3378 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3381 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3382 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3384 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3385 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3386 psInfo->ppshheader.u.pszIcon,
3391 hIcon = psInfo->ppshheader.u.hIcon;
3393 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3396 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3397 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3399 psInfo->strPropertiesFor = strCaption;
3401 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3403 PROPSHEET_CreateTabControl(hwnd, psInfo);
3405 PROPSHEET_LoadWizardBitmaps(psInfo);
3407 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3409 ShowWindow(hwndTabCtrl, SW_HIDE);
3410 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3411 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3415 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3417 PROPSHEET_AdjustSize(hwnd, psInfo);
3418 PROPSHEET_AdjustButtons(hwnd, psInfo);
3422 if (psInfo->useCallback)
3423 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3424 PSCB_INITIALIZED, (LPARAM)0);
3426 idx = psInfo->active_page;
3427 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3428 psInfo->active_page = -1;
3430 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3432 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3433 * as some programs call TCM_GETCURSEL to get the current selection
3434 * from which to switch to the next page */
3435 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3437 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3438 psInfo->ppshheader.hInstance)
3442 if (LoadStringW(psInfo->ppshheader.hInstance,
3443 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3444 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3448 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3449 psInfo->ppshheader.pszCaption);
3456 PROPSHEET_Paint(hwnd, (HDC)wParam);
3460 PROPSHEET_CleanUp(hwnd);
3464 PROPSHEET_Cancel(hwnd, 1);
3468 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3470 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3475 /* No default handler, forward notification to active page */
3476 if (psInfo->activeValid && psInfo->active_page != -1)
3478 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3479 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3485 switch(wParam & 0xfff0)
3488 PROPSHEET_Cancel(hwnd, 1);
3497 NMHDR* pnmh = (LPNMHDR) lParam;
3499 if (pnmh->code == TCN_SELCHANGE)
3501 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3502 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3505 if(pnmh->code == TCN_SELCHANGING)
3507 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3508 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3515 case WM_SYSCOLORCHANGE:
3516 COMCTL32_RefreshSysColors();
3519 case PSM_GETCURRENTPAGEHWND:
3521 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3528 if (psInfo->activeValid && psInfo->active_page != -1)
3529 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3531 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3537 PROPSHEET_Changed(hwnd, (HWND)wParam);
3541 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3544 case PSM_GETTABCONTROL:
3546 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3548 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3557 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3558 if(msgResult != FALSE)
3560 msgResult = PROPSHEET_SetCurSel(hwnd,
3563 (HPROPSHEETPAGE)lParam);
3566 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3571 case PSM_CANCELTOCLOSE:
3573 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3574 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3575 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3577 EnableWindow(hwndCancel, FALSE);
3578 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3579 SetWindowTextW(hwndOK, buf);
3584 case PSM_RESTARTWINDOWS:
3586 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3592 psInfo->restartWindows = TRUE;
3596 case PSM_REBOOTSYSTEM:
3598 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3604 psInfo->rebootSystem = TRUE;
3609 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3613 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3618 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3620 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3625 case PSM_QUERYSIBLINGS:
3627 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3629 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3637 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3638 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3639 * on success or FALSE otherwise, as specified on MSDN Online.
3640 * Also see the MFC code for
3641 * CPropertySheet::AddPage(CPropertyPage* pPage).
3644 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3646 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3651 case PSM_REMOVEPAGE:
3652 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3655 case PSM_ISDIALOGMESSAGE:
3657 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3658 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3662 case PSM_PRESSBUTTON:
3663 PROPSHEET_PressButton(hwnd, (int)wParam);
3666 case PSM_SETFINISHTEXTA:
3667 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3670 case PSM_SETWIZBUTTONS:
3671 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3674 case PSM_SETCURSELID:
3675 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3678 case PSM_SETFINISHTEXTW:
3679 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3682 case PSM_INSERTPAGE:
3684 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3685 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3689 case PSM_SETHEADERTITLEW:
3690 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3693 case PSM_SETHEADERTITLEA:
3694 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3697 case PSM_SETHEADERSUBTITLEW:
3698 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3701 case PSM_SETHEADERSUBTITLEA:
3702 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3705 case PSM_HWNDTOINDEX:
3707 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3708 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3712 case PSM_INDEXTOHWND:
3714 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3715 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3719 case PSM_PAGETOINDEX:
3721 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3722 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3726 case PSM_INDEXTOPAGE:
3728 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3729 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3735 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3736 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3742 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3743 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3749 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3750 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3754 case PSM_RECALCPAGESIZES:
3756 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3757 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);