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
38 * o PSM_RECALCPAGESIZES
39 * o PSM_SETHEADERSUBTITLE
40 * o PSM_SETHEADERTITLE
45 * o PSN_QUERYINITIALFOCUS
46 * o PSN_TRANSLATEACCELERATOR
48 * o PSH_WIZARDHASFINISH
50 * o PSH_STRETCHWATERMARK
54 * o PSP_USEFUSIONCONTEXT
61 #define NONAMELESSUNION
62 #define NONAMELESSSTRUCT
72 #include "wine/debug.h"
73 #include "wine/unicode.h"
75 /******************************************************************************
99 } MyDLGITEMTEMPLATEEX;
102 typedef struct tagPropPageInfo
104 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
113 typedef struct tagPropSheetInfo
116 PROPSHEETHEADERW ppshheader;
118 LPWSTR strPropertiesFor;
128 PropPageInfo* proppage;
133 HIMAGELIST hImageList;
142 /******************************************************************************
143 * Defines and global variables
146 const WCHAR PropSheetInfoStr[] =
147 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
149 #define PSP_INTERNAL_UNICODE 0x80000000
151 #define MAX_CAPTION_LENGTH 255
152 #define MAX_TABTEXT_LENGTH 255
153 #define MAX_BUTTONTEXT_LENGTH 64
155 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
157 /* Wizard metrics specified in DLUs */
158 #define WIZARD_PADDING 7
159 #define WIZARD_HEADER_HEIGHT 36
161 /******************************************************************************
164 static int PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
165 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
166 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
167 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
169 PropSheetInfo * psInfo);
170 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
171 PropSheetInfo * psInfo);
172 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
173 PropSheetInfo * psInfo,
175 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
176 PropSheetInfo * psInfo);
177 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
178 const PropSheetInfo * psInfo,
179 LPCPROPSHEETPAGEW ppshpage);
180 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
181 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
182 static BOOL PROPSHEET_Back(HWND hwndDlg);
183 static BOOL PROPSHEET_Next(HWND hwndDlg);
184 static BOOL PROPSHEET_Finish(HWND hwndDlg);
185 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
186 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
187 static void PROPSHEET_Help(HWND hwndDlg);
188 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
189 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
190 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
191 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
192 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
193 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
194 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
195 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
196 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
199 HPROPSHEETPAGE hpage);
200 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
201 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
202 WPARAM wParam, LPARAM lParam);
203 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
204 HPROPSHEETPAGE hpage);
206 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
208 HPROPSHEETPAGE hpage);
209 static void PROPSHEET_CleanUp(HWND hwndDlg);
210 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
211 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
212 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
213 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
214 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
217 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
219 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
221 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
222 /******************************************************************************
223 * PROPSHEET_UnImplementedFlags
225 * Document use of flags we don't implement yet.
227 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
234 * unhandled header flags:
235 * PSH_WIZARDHASFINISH 0x00000010
236 * PSH_RTLREADING 0x00000800
237 * PSH_STRETCHWATERMARK 0x00040000
238 * PSH_USEPAGELANG 0x00200000
241 add_flag(PSH_WIZARDHASFINISH);
242 add_flag(PSH_RTLREADING);
243 add_flag(PSH_STRETCHWATERMARK);
244 add_flag(PSH_USEPAGELANG);
245 if (string[0] != '\0')
246 FIXME("%s\n", string);
250 /******************************************************************************
251 * PROPSHEET_GetPageRect
253 * Retrieve rect from tab control and map into the dialog for SetWindowPos
255 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
256 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
258 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
262 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
263 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
264 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
265 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
267 rc->left = rc->top = WIZARD_PADDING;
271 rc->left = rc->top = 0;
273 rc->right = psInfo->width - rc->left;
274 rc->bottom = psInfo->height - rc->top;
275 MapDialogRect(hwndDlg, rc);
277 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
278 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
279 !(ppshpage->dwFlags & PSP_HIDEHEADER))
281 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
282 GetClientRect(hwndChild, &r);
283 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
284 rc->top += r.bottom + 1;
287 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
288 GetClientRect(hwndTabCtrl, rc);
289 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
290 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
294 /******************************************************************************
295 * PROPSHEET_FindPageByResId
297 * Find page index corresponding to page resource id.
299 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
303 for (i = 0; i < psInfo->nPages; i++)
305 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
307 /* Fixme: if resource ID is a string shall we use strcmp ??? */
308 if (lppsp->u.pszTemplate == (LPVOID)resId)
315 /******************************************************************************
318 * Convert ASCII to Unicode since all data is saved as Unicode.
320 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
324 TRACE("<%s>\n", frstr);
325 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
326 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
327 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
330 /******************************************************************************
331 * PROPSHEET_CollectSheetInfoA
333 * Collect relevant data.
335 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
336 PropSheetInfo * psInfo)
338 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
339 DWORD dwFlags = lppsh->dwFlags;
341 psInfo->hasHelp = dwFlags & PSH_HASHELP;
342 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
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 = HeapAlloc( GetProcessHeap(), 0, 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->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
399 psInfo->isModeless = dwFlags & PSH_MODELESS;
401 memcpy(&psInfo->ppshheader,lppsh,dwSize);
402 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",
403 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
405 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
407 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
408 psInfo->ppshheader.pszCaption = NULL;
411 if (HIWORD(lppsh->pszCaption))
413 int len = strlenW(lppsh->pszCaption);
414 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
415 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
418 psInfo->nPages = lppsh->nPages;
420 if (dwFlags & PSH_USEPSTARTPAGE)
422 TRACE("PSH_USEPSTARTPAGE is on\n");
423 psInfo->active_page = 0;
426 psInfo->active_page = lppsh->u2.nStartPage;
428 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
429 psInfo->active_page = 0;
431 psInfo->restartWindows = FALSE;
432 psInfo->rebootSystem = FALSE;
433 psInfo->hImageList = 0;
434 psInfo->activeValid = FALSE;
439 /******************************************************************************
440 * PROPSHEET_CollectPageInfo
442 * Collect property sheet data.
443 * With code taken from DIALOG_ParseTemplate32.
445 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
446 PropSheetInfo * psInfo,
449 DLGTEMPLATE* pTemplate;
455 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
456 psInfo->proppage[index].hwndPage = 0;
457 psInfo->proppage[index].isDirty = FALSE;
460 * Process property page flags.
462 dwFlags = lppsp->dwFlags;
463 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
464 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
465 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
467 /* as soon as we have a page with the help flag, set the sheet flag on */
468 if (psInfo->proppage[index].hasHelp)
469 psInfo->hasHelp = TRUE;
472 * Process page template.
474 if (dwFlags & PSP_DLGINDIRECT)
475 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
476 else if(dwFlags & PSP_INTERNAL_UNICODE )
478 HRSRC hResource = FindResourceW(lppsp->hInstance,
479 lppsp->u.pszTemplate,
481 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
483 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
487 HRSRC hResource = FindResourceA(lppsp->hInstance,
488 (LPSTR)lppsp->u.pszTemplate,
490 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
492 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
496 * Extract the size of the page and the caption.
501 p = (const WORD *)pTemplate;
503 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
505 /* DLGTEMPLATEEX (not defined in any std. header file) */
509 p += 2; /* help ID */
510 p += 2; /* ext style */
518 p += 2; /* ext style */
524 width = (WORD)*p; p++;
525 height = (WORD)*p; p++;
527 /* Special calculation for interior wizard pages so the largest page is
528 * calculated correctly. We need to add all the padding and space occupied
529 * by the header so the width and height sums up to the whole wizard client
531 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
532 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
533 !(dwFlags & PSP_HIDEHEADER))
535 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
536 width += 2 * WIZARD_PADDING;
538 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
540 height += 2 * WIZARD_PADDING;
541 width += 2 * WIZARD_PADDING;
544 /* remember the largest width and height */
545 if (width > psInfo->width)
546 psInfo->width = width;
548 if (height > psInfo->height)
549 psInfo->height = height;
561 p += lstrlenW( (LPCWSTR)p ) + 1;
575 p += lstrlenW( (LPCWSTR)p ) + 1;
579 /* Extract the caption */
580 psInfo->proppage[index].pszText = (LPCWSTR)p;
581 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
582 p += lstrlenW((LPCWSTR)p) + 1;
584 if (dwFlags & PSP_USETITLE)
588 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
591 if ( !HIWORD( lppsp->pszTitle ) )
593 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
596 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
602 pTitle = lppsp->pszTitle;
604 len = strlenW(pTitle);
605 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
606 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
610 * Build the image list for icons
612 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
615 int icon_cx = GetSystemMetrics(SM_CXSMICON);
616 int icon_cy = GetSystemMetrics(SM_CYSMICON);
618 if (dwFlags & PSP_USEICONID)
619 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
620 icon_cx, icon_cy, LR_DEFAULTCOLOR);
622 hIcon = lppsp->u2.hIcon;
626 if (psInfo->hImageList == 0 )
627 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
629 ImageList_AddIcon(psInfo->hImageList, hIcon);
637 /******************************************************************************
638 * PROPSHEET_CreateDialog
640 * Creates the actual property sheet.
642 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
649 WORD resID = IDD_PROPSHEET;
652 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
655 if( psInfo->unicode )
657 if(!(hRes = FindResourceW(COMCTL32_hModule,
658 MAKEINTRESOURCEW(resID),
664 if(!(hRes = FindResourceA(COMCTL32_hModule,
665 MAKEINTRESOURCEA(resID),
670 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
674 * Make a copy of the dialog template.
676 resSize = SizeofResource(COMCTL32_hModule, hRes);
678 temp = Alloc(resSize);
683 memcpy(temp, template, resSize);
685 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
687 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
688 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
690 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
692 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
693 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
695 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
696 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
698 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
701 if (psInfo->useCallback)
702 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
704 /* NOTE: MSDN states "Returns a positive value if successful, or -1
705 * otherwise for modal property sheets.", but this is wrong. The
706 * actual return value is either TRUE (success), FALSE (cancel) or
708 if( psInfo->unicode )
710 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
711 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
712 (LPDLGTEMPLATEW) temp,
713 psInfo->ppshheader.hwndParent,
714 PROPSHEET_DialogProc,
718 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
719 (LPDLGTEMPLATEW) temp,
720 psInfo->ppshheader.hwndParent,
721 PROPSHEET_DialogProc,
723 if ( !ret ) ret = -1;
728 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
729 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
730 (LPDLGTEMPLATEA) temp,
731 psInfo->ppshheader.hwndParent,
732 PROPSHEET_DialogProc,
736 ret = (int)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
737 (LPDLGTEMPLATEA) temp,
738 psInfo->ppshheader.hwndParent,
739 PROPSHEET_DialogProc,
741 if ( !ret ) ret = -1;
750 /******************************************************************************
751 * PROPSHEET_SizeMismatch
753 * Verify that the tab control and the "largest" property sheet page dlg. template
756 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
758 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
759 RECT rcOrigTab, rcPage;
764 GetClientRect(hwndTabCtrl, &rcOrigTab);
765 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
766 rcOrigTab.right, rcOrigTab.bottom);
773 rcPage.right = psInfo->width;
774 rcPage.bottom = psInfo->height;
776 MapDialogRect(hwndDlg, &rcPage);
777 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
778 rcPage.right, rcPage.bottom);
780 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
782 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
788 /******************************************************************************
789 * PROPSHEET_AdjustSize
791 * Resizes the property sheet and the tab control to fit the largest page.
793 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
795 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
796 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
798 int tabOffsetX, tabOffsetY, buttonHeight;
799 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
802 /* Get the height of buttons */
803 GetClientRect(hwndButton, &rc);
804 buttonHeight = rc.bottom;
811 rc.right = psInfo->width;
812 rc.bottom = psInfo->height;
814 MapDialogRect(hwndDlg, &rc);
816 /* retrieve the dialog units */
817 units.left = units.right = 4;
818 units.top = units.bottom = 8;
819 MapDialogRect(hwndDlg, &units);
822 * Resize the tab control.
824 GetClientRect(hwndTabCtrl,&tabRect);
826 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
828 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
830 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
831 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
834 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
836 rc.right = rc.left + tabRect.right - tabRect.left;
837 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
840 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
842 tabOffsetX = -(rc.left);
843 tabOffsetY = -(rc.top);
847 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
848 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
849 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
850 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
852 GetClientRect(hwndTabCtrl, &rc);
854 TRACE("tab client rc %ld %ld %ld %ld\n",
855 rc.left, rc.top, rc.right, rc.bottom);
857 rc.right += ((padding.x * 2) + tabOffsetX);
858 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
861 * Resize the property sheet.
863 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
864 (DWORD)hwndDlg, rc.right, rc.bottom);
865 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
866 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
870 /******************************************************************************
871 * PROPSHEET_AdjustSizeWizard
873 * Resizes the property sheet to fit the largest page.
875 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
877 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
878 RECT rc, lineRect, dialogRect;
880 /* Biggest page size */
883 rc.right = psInfo->width;
884 rc.bottom = psInfo->height;
885 MapDialogRect(hwndDlg, &rc);
887 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
889 /* Add space for the buttons row */
890 GetWindowRect(hwndLine, &lineRect);
891 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
892 GetClientRect(hwndDlg, &dialogRect);
893 rc.bottom += dialogRect.bottom - lineRect.top - 1;
895 /* Convert the client coordinates to window coordinates */
896 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
898 /* Resize the property sheet */
899 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
900 (DWORD)hwndDlg, rc.right, rc.bottom);
901 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
902 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
907 /******************************************************************************
908 * PROPSHEET_AdjustButtons
910 * Adjusts the buttons' positions.
912 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
914 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
918 int buttonWidth, buttonHeight;
919 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
921 if (psInfo->hasApply)
928 * Obtain the size of the buttons.
930 GetClientRect(hwndButton, &rcSheet);
931 buttonWidth = rcSheet.right;
932 buttonHeight = rcSheet.bottom;
935 * Get the size of the property sheet.
937 GetClientRect(hwndParent, &rcSheet);
940 * All buttons will be at this y coordinate.
942 y = rcSheet.bottom - (padding.y + buttonHeight);
945 * Position OK button and make it default.
947 hwndButton = GetDlgItem(hwndParent, IDOK);
949 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
951 SetWindowPos(hwndButton, 0, x, y, 0, 0,
952 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
954 SendMessageA(hwndParent, DM_SETDEFID, IDOK, 0);
958 * Position Cancel button.
960 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
962 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
964 SetWindowPos(hwndButton, 0, x, y, 0, 0,
965 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968 * Position Apply button.
970 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
972 if (psInfo->hasApply)
975 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
977 x = rcSheet.right - (padding.x + buttonWidth);
979 SetWindowPos(hwndButton, 0, x, y, 0, 0,
980 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
982 EnableWindow(hwndButton, FALSE);
985 ShowWindow(hwndButton, SW_HIDE);
988 * Position Help button.
990 hwndButton = GetDlgItem(hwndParent, IDHELP);
994 x = rcSheet.right - (padding.x + buttonWidth);
996 SetWindowPos(hwndButton, 0, x, y, 0, 0,
997 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1000 ShowWindow(hwndButton, SW_HIDE);
1005 /******************************************************************************
1006 * PROPSHEET_AdjustButtonsWizard
1008 * Adjusts the buttons' positions.
1010 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1011 PropSheetInfo* psInfo)
1013 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1014 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1015 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1018 int num_buttons = 3;
1019 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1020 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1022 if (psInfo->hasHelp)
1026 * Obtain the size of the buttons.
1028 GetClientRect(hwndButton, &rcSheet);
1029 buttonWidth = rcSheet.right;
1030 buttonHeight = rcSheet.bottom;
1032 GetClientRect(hwndLine, &rcSheet);
1033 lineHeight = rcSheet.bottom;
1036 * Get the size of the property sheet.
1038 GetClientRect(hwndParent, &rcSheet);
1041 * All buttons will be at this y coordinate.
1043 y = rcSheet.bottom - (padding.y + buttonHeight);
1046 * Position the Next and the Finish buttons.
1048 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1050 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1052 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1053 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1055 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1057 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1058 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1060 ShowWindow(hwndButton, SW_HIDE);
1063 * Position the Back button.
1065 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1069 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1070 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1073 * Position the Cancel button.
1075 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1077 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1079 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1080 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1083 * Position Help button.
1085 hwndButton = GetDlgItem(hwndParent, IDHELP);
1087 if (psInfo->hasHelp)
1089 x = rcSheet.right - (padding.x + buttonWidth);
1091 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1092 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1095 ShowWindow(hwndButton, SW_HIDE);
1097 if (psInfo->ppshheader.dwFlags &
1098 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1102 * Position and resize the sunken line.
1105 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1107 lineWidth = rcSheet.right - (padding.x * 2);
1108 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1109 SWP_NOZORDER | SWP_NOACTIVATE);
1112 * Position and resize the header sunken line.
1115 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1116 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1117 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1118 ShowWindow(hwndLineHeader, SW_HIDE);
1123 /******************************************************************************
1124 * PROPSHEET_GetPaddingInfo
1126 * Returns the layout information.
1128 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1130 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1133 PADDING_INFO padding;
1135 GetWindowRect(hwndTab, &rcTab);
1140 ScreenToClient(hwndDlg, &tl);
1148 /******************************************************************************
1149 * PROPSHEET_GetPaddingInfoWizard
1151 * Returns the layout information.
1152 * Vertical spacing is the distance between the line and the buttons.
1153 * Do NOT use the Help button to gather padding information when it isn't mapped
1154 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1155 * for it in this case !
1156 * FIXME: I'm not sure about any other coordinate problems with these evil
1157 * buttons. Fix it in case additional problems appear or maybe calculate
1158 * a padding in a completely different way, as this is somewhat messy.
1160 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1163 PADDING_INFO padding;
1167 POINT ptButton, ptLine;
1170 if (psInfo->hasHelp)
1176 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1178 idButton = IDC_NEXT_BUTTON;
1182 /* hopefully this is ok */
1183 idButton = IDCANCEL;
1187 hwndControl = GetDlgItem(hwndDlg, idButton);
1188 GetWindowRect(hwndControl, &rc);
1190 ptButton.x = rc.left;
1191 ptButton.y = rc.top;
1193 ScreenToClient(hwndDlg, &ptButton);
1196 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1197 GetWindowRect(hwndControl, &rc);
1200 ptLine.y = rc.bottom;
1202 ScreenToClient(hwndDlg, &ptLine);
1204 padding.y = ptButton.y - ptLine.y;
1207 ERR("padding negative ! Please report this !\n");
1209 /* this is most probably not correct, but the best we have now */
1210 padding.x = padding.y;
1214 /******************************************************************************
1215 * PROPSHEET_CreateTabControl
1217 * Insert the tabs in the tab control.
1219 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1220 PropSheetInfo * psInfo)
1222 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1228 item.mask = TCIF_TEXT;
1229 item.cchTextMax = MAX_TABTEXT_LENGTH;
1231 nTabs = psInfo->nPages;
1234 * Set the image list for icons.
1236 if (psInfo->hImageList)
1238 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1241 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1242 for (i = 0; i < nTabs; i++)
1244 if ( psInfo->proppage[i].hasIcon )
1246 item.mask |= TCIF_IMAGE;
1247 item.iImage = iImage++;
1251 item.mask &= ~TCIF_IMAGE;
1254 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1255 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1257 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1262 /******************************************************************************
1263 * PROPSHEET_WizardSubclassProc
1265 * Subclassing window procedure for wizard extrior pages to prevent drawing
1266 * background and so drawing above the watermark.
1269 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1276 case WM_CTLCOLORSTATIC:
1277 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1278 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1281 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1285 * Get the size of an in-memory Template
1287 *( Based on the code of PROPSHEET_CollectPageInfo)
1288 * See also dialog.c/DIALOG_ParseTemplate32().
1291 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1294 const WORD* p = (const WORD *)pTemplate;
1295 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1300 /* DLGTEMPLATEEX (not defined in any std. header file) */
1302 TRACE("is DLGTEMPLATEEX\n");
1304 p++; /* signature */
1305 p += 2; /* help ID */
1306 p += 2; /* ext style */
1313 TRACE("is DLGTEMPLATE\n");
1315 p += 2; /* ext style */
1318 nrofitems = (WORD)*p; p++; /* nb items */
1334 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1335 p += lstrlenW( (LPCWSTR)p ) + 1;
1346 p += 2; /* 0xffff plus predefined window class ordinal value */
1349 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1350 p += lstrlenW( (LPCWSTR)p ) + 1;
1355 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1356 p += lstrlenW((LPCWSTR)p) + 1;
1358 /* font, if DS_SETFONT set */
1359 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1362 p+=(istemplateex)?3:1;
1363 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1364 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1367 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1368 * that are following the DLGTEMPLATE(EX) data */
1369 TRACE("%d items\n",nrofitems);
1370 while (nrofitems > 0)
1372 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1375 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1384 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1388 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1389 p += lstrlenW( (LPCWSTR)p ) + 1;
1393 /* check title text */
1400 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1404 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1405 p += lstrlenW( (LPCWSTR)p ) + 1;
1408 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1412 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1413 return (p - (WORD*)pTemplate)*sizeof(WORD);
1417 /******************************************************************************
1418 * PROPSHEET_CreatePage
1422 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1424 const PropSheetInfo * psInfo,
1425 LPCPROPSHEETPAGEW ppshpage)
1427 DLGTEMPLATE* pTemplate;
1432 TRACE("index %d\n", index);
1434 if (ppshpage == NULL)
1439 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1441 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1442 resSize = GetTemplateSize(pTemplate);
1444 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1449 hResource = FindResourceW(ppshpage->hInstance,
1450 ppshpage->u.pszTemplate,
1455 resSize = SizeofResource(ppshpage->hInstance, hResource);
1457 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1461 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1463 * Make a copy of the dialog template to make it writable
1471 hResource = FindResourceA(ppshpage->hInstance,
1472 (LPSTR)ppshpage->u.pszTemplate,
1477 resSize = SizeofResource(ppshpage->hInstance, hResource);
1479 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1483 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1485 * Make a copy of the dialog template to make it writable
1488 temp = Alloc(resSize);
1492 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1493 memcpy(temp, pTemplate, resSize);
1496 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1498 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1499 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1500 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1501 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1502 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1503 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1504 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1505 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1507 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1511 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1512 pTemplate->style &= ~DS_MODALFRAME;
1513 pTemplate->style &= ~WS_CAPTION;
1514 pTemplate->style &= ~WS_SYSMENU;
1515 pTemplate->style &= ~WS_POPUP;
1516 pTemplate->style &= ~WS_DISABLED;
1517 pTemplate->style &= ~WS_VISIBLE;
1518 pTemplate->style &= ~WS_THICKFRAME;
1520 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1523 if (psInfo->proppage[index].useCallback)
1524 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1525 (LPPROPSHEETPAGEW)ppshpage);
1527 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1528 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1531 ppshpage->pfnDlgProc,
1534 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1537 ppshpage->pfnDlgProc,
1539 /* Free a no more needed copy */
1543 psInfo->proppage[index].hwndPage = hwndPage;
1545 /* Subclass exterior wizard pages */
1546 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1547 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1548 (ppshpage->dwFlags & PSP_HIDEHEADER))
1550 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1551 (DWORD_PTR)ppshpage);
1557 /******************************************************************************
1558 * PROPSHEET_LoadWizardBitmaps
1560 * Loads the watermark and header bitmaps for a wizard.
1562 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1564 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1566 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1567 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1568 considers hbmWatermark as valid. */
1569 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1570 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1572 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1573 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1576 /* Same behavior as for watermarks */
1577 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1578 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1580 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1581 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1587 /******************************************************************************
1588 * PROPSHEET_ShowPage
1590 * Displays or creates the specified page.
1592 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1595 HWND hwndLineHeader;
1596 LPCPROPSHEETPAGEW ppshpage;
1598 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1599 if (index == psInfo->active_page)
1601 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1602 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1606 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1607 if (psInfo->proppage[index].hwndPage == 0)
1609 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1612 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1613 (ppshpage->dwFlags & PSP_USETITLE))
1615 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1616 psInfo->proppage[index].pszText);
1619 if (psInfo->active_page != -1)
1620 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1622 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1624 /* Synchronize current selection with tab control
1625 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1626 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1627 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1629 psInfo->active_page = index;
1630 psInfo->activeValid = TRUE;
1632 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1634 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1635 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1637 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1638 ShowWindow(hwndLineHeader, SW_HIDE);
1640 ShowWindow(hwndLineHeader, SW_SHOW);
1643 InvalidateRgn(hwndDlg, NULL, TRUE);
1644 UpdateWindow(hwndDlg);
1649 /******************************************************************************
1652 static BOOL PROPSHEET_Back(HWND hwndDlg)
1656 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1661 TRACE("active_page %d\n", psInfo->active_page);
1662 if (psInfo->active_page < 0)
1665 psn.hdr.code = PSN_WIZBACK;
1666 psn.hdr.hwndFrom = hwndDlg;
1670 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1672 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1675 else if (result == 0)
1676 idx = psInfo->active_page - 1;
1678 idx = PROPSHEET_FindPageByResId(psInfo, result);
1680 if (idx >= 0 && idx < psInfo->nPages)
1682 if (PROPSHEET_CanSetCurSel(hwndDlg))
1683 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1688 /******************************************************************************
1691 static BOOL PROPSHEET_Next(HWND hwndDlg)
1695 LRESULT msgResult = 0;
1696 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1700 TRACE("active_page %d\n", psInfo->active_page);
1701 if (psInfo->active_page < 0)
1704 psn.hdr.code = PSN_WIZNEXT;
1705 psn.hdr.hwndFrom = hwndDlg;
1709 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1711 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1712 if (msgResult == -1)
1714 else if (msgResult == 0)
1715 idx = psInfo->active_page + 1;
1717 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1719 if (idx < psInfo->nPages )
1721 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1722 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1728 /******************************************************************************
1731 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1735 LRESULT msgResult = 0;
1736 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1739 TRACE("active_page %d\n", psInfo->active_page);
1740 if (psInfo->active_page < 0)
1743 psn.hdr.code = PSN_WIZFINISH;
1744 psn.hdr.hwndFrom = hwndDlg;
1748 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1750 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1752 TRACE("msg result %ld\n", msgResult);
1757 if (psInfo->isModeless)
1758 psInfo->activeValid = FALSE;
1760 EndDialog(hwndDlg, TRUE);
1765 /******************************************************************************
1768 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1773 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1776 TRACE("active_page %d\n", psInfo->active_page);
1777 if (psInfo->active_page < 0)
1780 psn.hdr.hwndFrom = hwndDlg;
1786 * Send PSN_KILLACTIVE to the current page.
1788 psn.hdr.code = PSN_KILLACTIVE;
1790 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1792 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1796 * Send PSN_APPLY to all pages.
1798 psn.hdr.code = PSN_APPLY;
1799 psn.lParam = lParam;
1801 for (i = 0; i < psInfo->nPages; i++)
1803 hwndPage = psInfo->proppage[i].hwndPage;
1806 switch (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1808 case PSNRET_INVALID:
1809 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1811 case PSNRET_INVALID_NOCHANGEPAGE:
1819 psInfo->activeValid = FALSE;
1821 else if(psInfo->active_page >= 0)
1823 psn.hdr.code = PSN_SETACTIVE;
1825 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1826 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1832 /******************************************************************************
1835 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1837 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1843 TRACE("active_page %d\n", psInfo->active_page);
1844 if (psInfo->active_page < 0)
1847 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1848 psn.hdr.code = PSN_QUERYCANCEL;
1849 psn.hdr.hwndFrom = hwndDlg;
1853 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1856 psn.hdr.code = PSN_RESET;
1857 psn.lParam = lParam;
1859 for (i = 0; i < psInfo->nPages; i++)
1861 hwndPage = psInfo->proppage[i].hwndPage;
1864 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1867 if (psInfo->isModeless)
1869 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1870 psInfo->activeValid = FALSE;
1873 EndDialog(hwndDlg, FALSE);
1876 /******************************************************************************
1879 static void PROPSHEET_Help(HWND hwndDlg)
1881 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1886 TRACE("active_page %d\n", psInfo->active_page);
1887 if (psInfo->active_page < 0)
1890 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1891 psn.hdr.code = PSN_HELP;
1892 psn.hdr.hwndFrom = hwndDlg;
1896 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1899 /******************************************************************************
1902 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1905 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1909 if (!psInfo) return;
1911 * Set the dirty flag of this page.
1913 for (i = 0; i < psInfo->nPages; i++)
1915 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1916 psInfo->proppage[i].isDirty = TRUE;
1920 * Enable the Apply button.
1922 if (psInfo->hasApply)
1924 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1926 EnableWindow(hwndApplyBtn, TRUE);
1930 /******************************************************************************
1931 * PROPSHEET_UnChanged
1933 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1936 BOOL noPageDirty = TRUE;
1937 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1938 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1942 if ( !psInfo ) return;
1943 for (i = 0; i < psInfo->nPages; i++)
1945 /* set the specified page as clean */
1946 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1947 psInfo->proppage[i].isDirty = FALSE;
1949 /* look to see if there's any dirty pages */
1950 if (psInfo->proppage[i].isDirty)
1951 noPageDirty = FALSE;
1955 * Disable Apply button.
1958 EnableWindow(hwndApplyBtn, FALSE);
1961 /******************************************************************************
1962 * PROPSHEET_PressButton
1964 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1966 TRACE("buttonID %d\n", buttonID);
1969 case PSBTN_APPLYNOW:
1970 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1973 PROPSHEET_Back(hwndDlg);
1976 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1979 PROPSHEET_Finish(hwndDlg);
1982 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1985 PROPSHEET_Next(hwndDlg);
1988 PROPSHEET_DoCommand(hwndDlg, IDOK);
1991 FIXME("Invalid button index %d\n", buttonID);
1996 /*************************************************************************
1997 * BOOL PROPSHEET_CanSetCurSel [Internal]
1999 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2002 * hwndDlg [I] handle to a Dialog hWnd
2005 * TRUE if Current Selection can change
2009 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2011 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2017 TRACE("active_page %d\n", psInfo->active_page);
2024 if (psInfo->active_page < 0)
2031 * Notify the current page.
2033 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2034 psn.hdr.code = PSN_KILLACTIVE;
2035 psn.hdr.hwndFrom = hwndDlg;
2039 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2042 TRACE("<-- %d\n", res);
2046 /******************************************************************************
2047 * PROPSHEET_SetCurSel
2049 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2052 HPROPSHEETPAGE hpage
2055 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2056 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2057 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2059 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2060 /* hpage takes precedence over index */
2062 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2064 if (index < 0 || index >= psInfo->nPages)
2066 TRACE("Could not find page to select!\n");
2074 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2077 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2079 psn.hdr.code = PSN_SETACTIVE;
2080 psn.hdr.hwndFrom = hwndDlg;
2084 if (!psInfo->proppage[index].hwndPage) {
2085 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2088 /* Resize the property sheet page to the fit in the Tab control
2089 * (for regular property sheets) or to fit in the client area (for
2091 * NOTE: The resizing happens every time the page is selected and
2092 * not only when it's created (some applications depend on it). */
2093 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2094 TRACE("setting page %p, rc (%ld,%ld)-(%ld,%ld) w=%ld, h=%ld\n",
2095 psInfo->proppage[index].hwndPage, rc.left, rc.top, rc.right, rc.bottom,
2096 rc.right - rc.left, rc.bottom - rc.top);
2097 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2099 rc.right - rc.left, rc.bottom - rc.top, 0);
2101 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2108 WARN("Tried to skip before first property sheet page!\n");
2111 if (index >= psInfo->nPages) {
2112 WARN("Tried to skip after last property sheet page!\n");
2113 index = psInfo->nPages-1;
2117 else if (result != 0)
2119 int old_index = index;
2120 index = PROPSHEET_FindPageByResId(psInfo, result);
2121 if(index >= psInfo->nPages) {
2123 WARN("Tried to skip to nonexistant page by res id\n");
2130 * Display the new page.
2132 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2134 if (psInfo->proppage[index].hasHelp)
2135 EnableWindow(hwndHelp, TRUE);
2137 EnableWindow(hwndHelp, FALSE);
2142 /******************************************************************************
2143 * PROPSHEET_SetCurSelId
2145 * Selects the page, specified by resource id.
2147 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2150 PropSheetInfo* psInfo =
2151 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2153 idx = PROPSHEET_FindPageByResId(psInfo, id);
2154 if (idx < psInfo->nPages )
2156 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2157 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2161 /******************************************************************************
2162 * PROPSHEET_SetTitleA
2164 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2166 if(HIWORD(lpszText))
2169 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2170 szTitle, sizeof(szTitle));
2171 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2175 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2179 /******************************************************************************
2180 * PROPSHEET_SetTitleW
2182 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2184 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2187 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2188 if (HIWORD(lpszText) == 0) {
2189 if (!LoadStringW(psInfo->ppshheader.hInstance,
2190 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2194 if (dwStyle & PSH_PROPTITLE)
2197 int lentitle = strlenW(lpszText);
2198 int lenprop = strlenW(psInfo->strPropertiesFor);
2200 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2201 strcpyW(dest, psInfo->strPropertiesFor);
2202 strcatW(dest, lpszText);
2204 SetWindowTextW(hwndDlg, dest);
2208 SetWindowTextW(hwndDlg, lpszText);
2211 /******************************************************************************
2212 * PROPSHEET_SetFinishTextA
2214 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2216 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2218 TRACE("'%s'\n", lpszText);
2219 /* Set text, show and enable the Finish button */
2220 SetWindowTextA(hwndButton, lpszText);
2221 ShowWindow(hwndButton, SW_SHOW);
2222 EnableWindow(hwndButton, TRUE);
2224 /* Make it default pushbutton */
2225 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2227 /* Hide Back button */
2228 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2229 ShowWindow(hwndButton, SW_HIDE);
2231 /* Hide Next button */
2232 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2233 ShowWindow(hwndButton, SW_HIDE);
2236 /******************************************************************************
2237 * PROPSHEET_SetFinishTextW
2239 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2241 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2243 TRACE("'%s'\n", debugstr_w(lpszText));
2244 /* Set text, show and enable the Finish button */
2245 SetWindowTextW(hwndButton, lpszText);
2246 ShowWindow(hwndButton, SW_SHOW);
2247 EnableWindow(hwndButton, TRUE);
2249 /* Make it default pushbutton */
2250 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2252 /* Hide Back button */
2253 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2254 ShowWindow(hwndButton, SW_HIDE);
2256 /* Hide Next button */
2257 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2258 ShowWindow(hwndButton, SW_HIDE);
2261 /******************************************************************************
2262 * PROPSHEET_QuerySiblings
2264 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2265 WPARAM wParam, LPARAM lParam)
2269 LRESULT msgResult = 0;
2270 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2273 while ((i < psInfo->nPages) && (msgResult == 0))
2275 hwndPage = psInfo->proppage[i].hwndPage;
2276 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2284 /******************************************************************************
2287 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2288 HPROPSHEETPAGE hpage)
2290 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2292 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2294 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2296 TRACE("hpage %p\n", hpage);
2298 * Allocate and fill in a new PropPageInfo entry.
2300 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2301 sizeof(PropPageInfo) *
2302 (psInfo->nPages + 1));
2303 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2306 psInfo->proppage[psInfo->nPages].hpage = hpage;
2308 if (ppsp->dwFlags & PSP_PREMATURE)
2310 /* Create the page but don't show it */
2311 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2315 * Add a new tab to the tab control.
2317 item.mask = TCIF_TEXT;
2318 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2319 item.cchTextMax = MAX_TABTEXT_LENGTH;
2321 if (psInfo->hImageList)
2323 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2326 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2328 item.mask |= TCIF_IMAGE;
2329 item.iImage = psInfo->nPages;
2332 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2337 /* If it is the only page - show it */
2338 if(psInfo->nPages == 1)
2339 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2343 /******************************************************************************
2344 * PROPSHEET_RemovePage
2346 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2348 HPROPSHEETPAGE hpage)
2350 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2352 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2353 PropPageInfo* oldPages;
2355 TRACE("index %d, hpage %p\n", index, hpage);
2360 * hpage takes precedence over index.
2364 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2367 /* Make sure that index is within range */
2368 if (index < 0 || index >= psInfo->nPages)
2370 TRACE("Could not find page to remove!\n");
2374 TRACE("total pages %d removing page %d active page %d\n",
2375 psInfo->nPages, index, psInfo->active_page);
2377 * Check if we're removing the active page.
2379 if (index == psInfo->active_page)
2381 if (psInfo->nPages > 1)
2385 /* activate previous page */
2386 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2390 /* activate the next page */
2391 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2392 psInfo->active_page = index;
2397 psInfo->active_page = -1;
2398 if (!psInfo->isModeless)
2400 EndDialog(hwndDlg, FALSE);
2405 else if (index < psInfo->active_page)
2406 psInfo->active_page--;
2408 /* Unsubclass the page dialog window */
2409 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2410 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2411 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2413 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2414 PROPSHEET_WizardSubclassProc, 1);
2417 /* Destroy page dialog window */
2418 DestroyWindow(psInfo->proppage[index].hwndPage);
2420 /* Free page resources */
2421 if(psInfo->proppage[index].hpage)
2423 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2425 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2426 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2428 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2431 /* Remove the tab */
2432 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2434 oldPages = psInfo->proppage;
2436 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2439 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2441 if (index < psInfo->nPages)
2442 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2443 (psInfo->nPages - index) * sizeof(PropPageInfo));
2450 /******************************************************************************
2451 * PROPSHEET_SetWizButtons
2453 * This code will work if (and assumes that) the Next button is on top of the
2454 * Finish button. ie. Finish comes after Next in the Z order.
2455 * This means make sure the dialog template reflects this.
2458 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
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 /* Hide the Finish button */
2476 ShowWindow(hwndFinish, SW_HIDE);
2478 /* Show and enable the Next button */
2479 ShowWindow(hwndNext, SW_SHOW);
2480 EnableWindow(hwndNext, TRUE);
2482 /* Set the Next button as the default pushbutton */
2483 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2486 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2488 /* Hide the Next button */
2489 ShowWindow(hwndNext, SW_HIDE);
2491 /* Show the Finish button */
2492 ShowWindow(hwndFinish, SW_SHOW);
2494 if (dwFlags & PSWIZB_FINISH)
2495 EnableWindow(hwndFinish, TRUE);
2497 /* Set the Finish button as the default pushbutton */
2498 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2502 /******************************************************************************
2503 * PROPSHEET_InsertPage
2505 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2507 if (!HIWORD(hpageInsertAfter))
2508 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2510 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2514 /******************************************************************************
2515 * PROPSHEET_SetHeaderTitleW
2517 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2519 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2522 /******************************************************************************
2523 * PROPSHEET_SetHeaderTitleA
2525 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2527 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2530 /******************************************************************************
2531 * PROPSHEET_SetHeaderSubTitleW
2533 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2535 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2538 /******************************************************************************
2539 * PROPSHEET_SetHeaderSubTitleA
2541 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2543 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2546 /******************************************************************************
2547 * PROPSHEET_HwndToIndex
2549 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2552 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2555 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2557 for (index = 0; index < psInfo->nPages; index++)
2558 if (psInfo->proppage[index].hwndPage == hPageDlg)
2560 WARN("%p not found\n", hPageDlg);
2564 /******************************************************************************
2565 * PROPSHEET_IndexToHwnd
2567 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2569 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2571 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2572 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2573 WARN("%d out of range.\n", iPageIndex);
2576 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2579 /******************************************************************************
2580 * PROPSHEET_PageToIndex
2582 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2585 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2588 TRACE("(%p, %p)\n", hwndDlg, hPage);
2590 for (index = 0; index < psInfo->nPages; index++)
2591 if (psInfo->proppage[index].hpage == hPage)
2593 WARN("%p not found\n", hPage);
2597 /******************************************************************************
2598 * PROPSHEET_IndexToPage
2600 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2602 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2604 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2605 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2606 WARN("%d out of range.\n", iPageIndex);
2609 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2612 /******************************************************************************
2613 * PROPSHEET_IdToIndex
2615 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2617 FIXME("(%p, %d): stub\n", hwndDlg, iPageId);
2621 /******************************************************************************
2622 * PROPSHEET_IndexToId
2624 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2626 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2628 LPCPROPSHEETPAGEW psp;
2629 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2630 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2631 WARN("%d out of range.\n", iPageIndex);
2634 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2635 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2638 return (LRESULT)psp->u.pszTemplate;
2641 /******************************************************************************
2642 * PROPSHEET_GetResult
2644 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2646 FIXME("(%p): stub\n", hwndDlg);
2650 /******************************************************************************
2651 * PROPSHEET_RecalcPageSizes
2653 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2655 FIXME("(%p): stub\n", hwndDlg);
2659 /******************************************************************************
2660 * PROPSHEET_GetPageIndex
2662 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2663 * the array of PropPageInfo.
2665 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2670 TRACE("hpage %p\n", hpage);
2671 while ((index < psInfo->nPages) && (found == FALSE))
2673 if (psInfo->proppage[index].hpage == hpage)
2685 /******************************************************************************
2688 static void PROPSHEET_CleanUp(HWND hwndDlg)
2691 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2695 if (!psInfo) return;
2696 if (HIWORD(psInfo->ppshheader.pszCaption))
2697 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2699 for (i = 0; i < psInfo->nPages; i++)
2701 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2703 /* Unsubclass the page dialog window */
2704 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2705 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2706 (psp->dwFlags & PSP_HIDEHEADER))
2708 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2709 PROPSHEET_WizardSubclassProc, 1);
2712 if(psInfo->proppage[i].hwndPage)
2713 DestroyWindow(psInfo->proppage[i].hwndPage);
2717 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2718 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2720 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2724 DeleteObject(psInfo->hFont);
2725 DeleteObject(psInfo->hFontBold);
2726 /* If we created the bitmaps, destroy them */
2727 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2728 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2729 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2730 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2731 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2732 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2734 Free(psInfo->proppage);
2735 Free(psInfo->strPropertiesFor);
2736 ImageList_Destroy(psInfo->hImageList);
2738 GlobalFree((HGLOBAL)psInfo);
2741 /******************************************************************************
2742 * PropertySheet (COMCTL32.@)
2743 * PropertySheetA (COMCTL32.@)
2745 * Creates a property sheet in the specified property sheet header.
2748 * Modal property sheets: Positive if successful or -1 otherwise.
2749 * Modeless property sheets: Property sheet handle.
2751 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2752 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2754 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2757 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2758 sizeof(PropSheetInfo));
2762 TRACE("(%p)\n", lppsh);
2764 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2766 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2768 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2770 for (n = i = 0; i < lppsh->nPages; i++, n++)
2772 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2773 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2776 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2777 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2780 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2783 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2784 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2790 psInfo->unicode = FALSE;
2791 bRet = PROPSHEET_CreateDialog(psInfo);
2796 /******************************************************************************
2797 * PropertySheetW (COMCTL32.@)
2799 * See PropertySheetA.
2801 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2804 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2805 sizeof(PropSheetInfo));
2809 TRACE("(%p)\n", lppsh);
2811 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2813 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2815 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2817 for (n = i = 0; i < lppsh->nPages; i++, n++)
2819 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2820 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2823 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2824 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2827 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2830 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2831 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2837 psInfo->unicode = TRUE;
2838 bRet = PROPSHEET_CreateDialog(psInfo);
2843 /******************************************************************************
2844 * CreatePropertySheetPage (COMCTL32.@)
2845 * CreatePropertySheetPageA (COMCTL32.@)
2847 * Creates a new property sheet page.
2850 * Success: Handle to new property sheet page.
2854 * An application must use the PSM_ADDPAGE message to add the new page to
2855 * an existing property sheet.
2857 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2858 LPCPROPSHEETPAGEA lpPropSheetPage)
2860 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2862 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2864 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2865 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2867 int len = strlen(lpPropSheetPage->u.pszTemplate);
2869 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,len+1 );
2870 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2872 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2874 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2877 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2879 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2881 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2882 ppsp->pszTitle = NULL;
2884 return (HPROPSHEETPAGE)ppsp;
2887 /******************************************************************************
2888 * CreatePropertySheetPageW (COMCTL32.@)
2890 * See CreatePropertySheetA.
2892 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2894 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2896 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2898 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2900 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2902 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2904 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2905 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2907 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2909 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2910 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2911 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2914 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2916 int len = strlenW(lpPropSheetPage->pszTitle);
2917 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2918 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2920 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2921 ppsp->pszTitle = NULL;
2923 return (HPROPSHEETPAGE)ppsp;
2926 /******************************************************************************
2927 * DestroyPropertySheetPage (COMCTL32.@)
2929 * Destroys a property sheet page previously created with
2930 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2937 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2939 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2944 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2945 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2947 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2948 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2950 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2951 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2958 /******************************************************************************
2959 * PROPSHEET_IsDialogMessage
2961 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2963 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2966 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2969 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2972 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2974 if (!(dlgCode & DLGC_WANTMESSAGE))
2976 switch (lpMsg->wParam)
2979 if (GetKeyState(VK_SHIFT) & 0x8000)
2985 case VK_NEXT: new_page = 1; break;
2986 case VK_PRIOR: new_page = -1; break;
2992 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2994 new_page += psInfo->active_page;
2997 new_page = psInfo->nPages - 1;
2998 else if (new_page >= psInfo->nPages)
3001 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3008 return IsDialogMessageA(hwnd, lpMsg);
3011 /******************************************************************************
3012 * PROPSHEET_DoCommand
3014 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3020 case IDC_APPLY_BUTTON:
3022 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3024 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3029 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3033 if (psInfo->restartWindows)
3034 result = ID_PSRESTARTWINDOWS;
3036 /* reboot system takes precedence over restart windows */
3037 if (psInfo->rebootSystem)
3038 result = ID_PSREBOOTSYSTEM;
3040 if (psInfo->isModeless)
3041 psInfo->activeValid = FALSE;
3043 EndDialog(hwnd, result);
3046 EnableWindow(hwndApplyBtn, FALSE);
3051 case IDC_BACK_BUTTON:
3052 PROPSHEET_Back(hwnd);
3055 case IDC_NEXT_BUTTON:
3056 PROPSHEET_Next(hwnd);
3059 case IDC_FINISH_BUTTON:
3060 PROPSHEET_Finish(hwnd);
3064 PROPSHEET_Cancel(hwnd, 0);
3068 PROPSHEET_Help(hwnd);
3078 /******************************************************************************
3081 static LRESULT PROPSHEET_Paint(HWND hwnd)
3083 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3088 HPALETTE hOldPal = 0;
3092 LPCPROPSHEETPAGEW ppshpage;
3093 WCHAR szBuffer[256];
3096 hdc = BeginPaint(hwnd, &ps);
3099 hdcSrc = CreateCompatibleDC(0);
3100 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3102 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3103 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3105 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3106 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3107 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3109 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3111 COLORREF clrOld = 0;
3114 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3115 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3117 GetClientRect(hwndLineHeader, &r);
3118 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3119 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3121 GetObjectA(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3123 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3125 /* Fill the unoccupied part of the header with color of the
3126 * left-top pixel, but do it only when needed.
3128 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3130 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3131 CopyRect(&r, &rzone);
3132 if (bm.bmWidth < r.right)
3134 r.left = bm.bmWidth;
3135 FillRect(hdc, &r, hbr);
3137 if (bm.bmHeight < r.bottom)
3140 r.top = bm.bmHeight;
3141 FillRect(hdc, &r, hbr);
3146 /* Draw the header itself. */
3148 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3149 hdcSrc, 0, 0, SRCCOPY);
3153 hbr = GetSysColorBrush(COLOR_WINDOW);
3154 FillRect(hdc, &rzone, hbr);
3156 /* Draw the header bitmap. It's always centered like a
3157 * common 49 x 49 bitmap. */
3158 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3159 (rzone.bottom - 49) / 2,
3160 bm.bmWidth, bm.bmHeight,
3161 hdcSrc, 0, 0, SRCCOPY);
3163 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3164 * if its height is smaller than 49 pixels. Because the reason
3165 * for this bug is unknown the current code doesn't try to
3169 clrOld = SetTextColor (hdc, 0x00000000);
3170 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3172 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3173 SetRect(&r, 20, 10, 0, 0);
3174 if (HIWORD(ppshpage->pszHeaderTitle))
3176 if (psInfo->unicode)
3177 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3178 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3180 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3181 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3185 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderTitle,
3189 DrawTextW(hdc, szBuffer, nLength,
3190 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3195 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3196 SelectObject(hdc, psInfo->hFont);
3197 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3198 if (HIWORD(ppshpage->pszHeaderTitle))
3200 if (psInfo->unicode)
3201 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3202 -1, &r, DT_LEFT | DT_SINGLELINE);
3204 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3205 -1, &r, DT_LEFT | DT_SINGLELINE);
3209 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderSubTitle,
3213 DrawTextW(hdc, szBuffer, nLength,
3214 &r, DT_LEFT | DT_SINGLELINE);
3219 offsety = rzone.bottom + 2;
3221 SetTextColor(hdc, clrOld);
3222 SetBkMode(hdc, oldBkMode);
3223 SelectObject(hdc, hOldFont);
3224 SelectObject(hdcSrc, hbmp);
3227 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3228 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3229 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3231 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3233 GetClientRect(hwndLine, &r);
3234 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3238 rzone.right = r.right;
3239 rzone.bottom = r.top - 1;
3241 hbr = GetSysColorBrush(COLOR_WINDOW);
3242 FillRect(hdc, &rzone, hbr);
3244 GetObjectA(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3245 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3247 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3248 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3250 /* If the bitmap is not big enough, fill the remaining area
3251 with the color of pixel (0,0) of bitmap - see MSDN */
3252 if (r.top > bm.bmHeight) {
3253 r.bottom = r.top - 1;
3254 r.top = bm.bmHeight;
3256 r.right = bm.bmWidth;
3257 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3258 FillRect(hdc, &r, hbr);
3262 SelectObject(hdcSrc, hbmp);
3265 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3266 SelectPalette(hdc, hOldPal, FALSE);
3270 EndPaint(hwnd, &ps);
3275 /******************************************************************************
3276 * PROPSHEET_DialogProc
3279 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3281 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3282 hwnd, uMsg, wParam, lParam);
3288 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3289 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3290 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3291 LPCPROPSHEETPAGEW ppshpage;
3295 /* Using PropSheetInfoStr to store extra data doesn't match the native
3296 * common control: native uses TCM_[GS]ETITEM
3298 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3301 * psInfo->hwnd is not being used by WINE code - it exists
3302 * for compatibility with "real" Windoze. The same about
3303 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3306 psInfo->hwnd = hwnd;
3307 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3309 /* set up the Next and Back buttons by default */
3310 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3313 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3314 psInfo->hFont = CreateFontIndirectA (&logFont);
3315 logFont.lfWeight = FW_BOLD;
3316 psInfo->hFontBold = CreateFontIndirectA (&logFont);
3319 * Small icon in the title bar.
3321 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3322 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3325 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3326 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3328 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3329 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3330 psInfo->ppshheader.u.pszIcon,
3335 hIcon = psInfo->ppshheader.u.hIcon;
3337 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3340 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3341 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3343 psInfo->strPropertiesFor = strCaption;
3345 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3347 PROPSHEET_CreateTabControl(hwnd, psInfo);
3349 PROPSHEET_LoadWizardBitmaps(psInfo);
3351 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3353 ShowWindow(hwndTabCtrl, SW_HIDE);
3354 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3355 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3359 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3361 PROPSHEET_AdjustSize(hwnd, psInfo);
3362 PROPSHEET_AdjustButtons(hwnd, psInfo);
3366 if (psInfo->useCallback)
3367 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3368 PSCB_INITIALIZED, (LPARAM)0);
3370 idx = psInfo->active_page;
3371 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3372 psInfo->active_page = -1;
3374 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3376 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3377 * as some programs call TCM_GETCURSEL to get the current selection
3378 * from which to switch to the next page */
3379 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3381 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3382 psInfo->ppshheader.hInstance)
3386 if (LoadStringW(psInfo->ppshheader.hInstance,
3387 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3388 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3392 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3393 psInfo->ppshheader.pszCaption);
3400 PROPSHEET_Paint(hwnd);
3404 PROPSHEET_CleanUp(hwnd);
3408 PROPSHEET_Cancel(hwnd, 1);
3412 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3414 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3419 /* No default handler, forward notification to active page */
3420 if (psInfo->activeValid && psInfo->active_page != -1)
3422 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3423 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3430 NMHDR* pnmh = (LPNMHDR) lParam;
3432 if (pnmh->code == TCN_SELCHANGE)
3434 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3435 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3438 if(pnmh->code == TCN_SELCHANGING)
3440 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3441 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3448 case PSM_GETCURRENTPAGEHWND:
3450 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3457 if (psInfo->activeValid && psInfo->active_page != -1)
3458 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3460 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3466 PROPSHEET_Changed(hwnd, (HWND)wParam);
3470 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3473 case PSM_GETTABCONTROL:
3475 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3477 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3486 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3487 if(msgResult != FALSE)
3489 msgResult = PROPSHEET_SetCurSel(hwnd,
3492 (HPROPSHEETPAGE)lParam);
3495 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3500 case PSM_CANCELTOCLOSE:
3502 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3503 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3504 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3506 EnableWindow(hwndCancel, FALSE);
3507 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3508 SetWindowTextW(hwndOK, buf);
3513 case PSM_RESTARTWINDOWS:
3515 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3521 psInfo->restartWindows = TRUE;
3525 case PSM_REBOOTSYSTEM:
3527 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3533 psInfo->rebootSystem = TRUE;
3538 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3542 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3547 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3549 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3554 case PSM_QUERYSIBLINGS:
3556 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3558 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3566 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3567 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3568 * on success or FALSE otherwise, as specified on MSDN Online.
3569 * Also see the MFC code for
3570 * CPropertySheet::AddPage(CPropertyPage* pPage).
3573 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3575 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3580 case PSM_REMOVEPAGE:
3581 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3584 case PSM_ISDIALOGMESSAGE:
3586 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3587 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3591 case PSM_PRESSBUTTON:
3592 PROPSHEET_PressButton(hwnd, (int)wParam);
3595 case PSM_SETFINISHTEXTA:
3596 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3599 case PSM_SETWIZBUTTONS:
3600 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3603 case PSM_SETCURSELID:
3604 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3607 case PSM_SETFINISHTEXTW:
3608 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3611 case PSM_INSERTPAGE:
3613 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3614 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3618 case PSM_SETHEADERTITLEW:
3619 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3622 case PSM_SETHEADERTITLEA:
3623 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3626 case PSM_SETHEADERSUBTITLEW:
3627 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3630 case PSM_SETHEADERSUBTITLEA:
3631 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3634 case PSM_HWNDTOINDEX:
3636 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3637 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3641 case PSM_INDEXTOHWND:
3643 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3644 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3648 case PSM_PAGETOINDEX:
3650 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3651 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3655 case PSM_INDEXTOPAGE:
3657 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3658 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3664 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3665 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3671 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3672 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3678 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3679 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3683 case PSM_RECALCPAGESIZES:
3685 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3686 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);