4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * - Unicode property sheets
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
41 #include "wine/debug.h"
42 #include "wine/unicode.h"
44 /******************************************************************************
68 } MyDLGITEMTEMPLATEEX;
71 typedef struct tagPropPageInfo
73 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
82 typedef struct tagPropSheetInfo
85 PROPSHEETHEADERW ppshheader;
87 LPWSTR strPropertiesFor;
97 PropPageInfo* proppage;
104 HIMAGELIST hImageList;
113 /******************************************************************************
114 * Defines and global variables
117 const WCHAR PropSheetInfoStr[] =
118 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
120 #define PSP_INTERNAL_UNICODE 0x80000000
122 #define MAX_CAPTION_LENGTH 255
123 #define MAX_TABTEXT_LENGTH 255
124 #define MAX_BUTTONTEXT_LENGTH 64
126 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
128 /******************************************************************************
131 static int PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
132 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
133 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
134 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
135 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
136 PropSheetInfo * psInfo);
137 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
138 PropSheetInfo * psInfo);
139 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
140 PropSheetInfo * psInfo,
142 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
143 PropSheetInfo * psInfo);
144 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
145 const PropSheetInfo * psInfo,
146 LPCPROPSHEETPAGEW ppshpage);
147 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
148 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
149 static BOOL PROPSHEET_Back(HWND hwndDlg);
150 static BOOL PROPSHEET_Next(HWND hwndDlg);
151 static BOOL PROPSHEET_Finish(HWND hwndDlg);
152 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
153 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
154 static void PROPSHEET_Help(HWND hwndDlg);
155 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
156 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
157 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
158 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
159 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
160 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
161 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
162 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
163 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
166 HPROPSHEETPAGE hpage);
167 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
168 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
169 WPARAM wParam, LPARAM lParam);
170 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
171 HPROPSHEETPAGE hpage);
173 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
175 HPROPSHEETPAGE hpage);
176 static void PROPSHEET_CleanUp(HWND hwndDlg);
177 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
178 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
179 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
180 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
181 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
184 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
186 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
188 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
189 /******************************************************************************
190 * PROPSHEET_UnImplementedFlags
192 * Document use of flags we don't implement yet.
194 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
201 * unhandled header flags:
202 * PSH_DEFAULT 0x00000000
203 * PSH_WIZARDHASFINISH 0x00000010
204 * PSH_RTLREADING 0x00000800
205 * PSH_WIZARDCONTEXTHELP 0x00001000
206 * PSH_WIZARD97 0x00002000 (pre IE 5)
207 * PSH_WATERMARK 0x00008000
208 * PSH_USEHBMWATERMARK 0x00010000
209 * PSH_USEHPLWATERMARK 0x00020000
210 * PSH_STRETCHWATERMARK 0x00040000
211 * PSH_HEADER 0x00080000
212 * PSH_USEHBMHEADER 0x00100000
213 * PSH_USEPAGELANG 0x00200000
214 * PSH_WIZARD_LITE 0x00400000 also not in .h
215 * PSH_WIZARD97 0x01000000 (IE 5 and above)
216 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
219 add_flag(PSH_WIZARDHASFINISH);
220 add_flag(PSH_RTLREADING);
221 add_flag(PSH_WIZARDCONTEXTHELP);
222 add_flag(PSH_WIZARD97_OLD);
223 add_flag(PSH_STRETCHWATERMARK);
224 add_flag(PSH_USEPAGELANG);
225 add_flag(PSH_WIZARD_LITE);
226 add_flag(PSH_NOCONTEXTHELP);
227 if (string[0] != '\0')
228 FIXME("%s\n", string);
232 /******************************************************************************
233 * PROPSHEET_GetPageRect
235 * Retrieve rect from tab control and map into the dialog for SetWindowPos
237 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
239 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
241 GetClientRect(hwndTabCtrl, rc);
242 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
243 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
246 /******************************************************************************
247 * PROPSHEET_FindPageByResId
249 * Find page index corresponding to page resource id.
251 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
255 for (i = 0; i < psInfo->nPages; i++)
257 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
259 /* Fixme: if resource ID is a string shall we use strcmp ??? */
260 if (lppsp->u.pszTemplate == (LPVOID)resId)
267 /******************************************************************************
270 * Convert ASCII to Unicode since all data is saved as Unicode.
272 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
276 TRACE("<%s>\n", frstr);
277 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
278 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
279 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
282 /******************************************************************************
283 * PROPSHEET_CollectSheetInfoA
285 * Collect relevant data.
287 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
288 PropSheetInfo * psInfo)
290 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
291 DWORD dwFlags = lppsh->dwFlags;
293 psInfo->hasHelp = dwFlags & PSH_HASHELP;
294 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
295 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
296 psInfo->isModeless = dwFlags & PSH_MODELESS;
298 memcpy(&psInfo->ppshheader,lppsh,dwSize);
299 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",
300 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
301 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
303 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
305 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
306 psInfo->ppshheader.pszCaption = NULL;
309 if (HIWORD(lppsh->pszCaption))
311 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
312 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
313 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
316 psInfo->nPages = lppsh->nPages;
318 if (dwFlags & PSH_USEPSTARTPAGE)
320 TRACE("PSH_USEPSTARTPAGE is on\n");
321 psInfo->active_page = 0;
324 psInfo->active_page = lppsh->u2.nStartPage;
326 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
327 psInfo->active_page = 0;
329 psInfo->restartWindows = FALSE;
330 psInfo->rebootSystem = FALSE;
331 psInfo->hImageList = 0;
332 psInfo->activeValid = FALSE;
337 /******************************************************************************
338 * PROPSHEET_CollectSheetInfoW
340 * Collect relevant data.
342 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
343 PropSheetInfo * psInfo)
345 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
346 DWORD dwFlags = lppsh->dwFlags;
348 psInfo->hasHelp = dwFlags & PSH_HASHELP;
349 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
350 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
351 psInfo->isModeless = dwFlags & PSH_MODELESS;
353 memcpy(&psInfo->ppshheader,lppsh,dwSize);
354 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",
355 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
357 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
359 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
360 psInfo->ppshheader.pszCaption = NULL;
363 if (HIWORD(lppsh->pszCaption))
365 int len = strlenW(lppsh->pszCaption);
366 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
367 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
370 psInfo->nPages = lppsh->nPages;
372 if (dwFlags & PSH_USEPSTARTPAGE)
374 TRACE("PSH_USEPSTARTPAGE is on\n");
375 psInfo->active_page = 0;
378 psInfo->active_page = lppsh->u2.nStartPage;
380 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
381 psInfo->active_page = 0;
383 psInfo->restartWindows = FALSE;
384 psInfo->rebootSystem = FALSE;
385 psInfo->hImageList = 0;
386 psInfo->activeValid = FALSE;
391 /******************************************************************************
392 * PROPSHEET_CollectPageInfo
394 * Collect property sheet data.
395 * With code taken from DIALOG_ParseTemplate32.
397 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
398 PropSheetInfo * psInfo,
401 DLGTEMPLATE* pTemplate;
407 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
408 psInfo->proppage[index].hwndPage = 0;
409 psInfo->proppage[index].isDirty = FALSE;
412 * Process property page flags.
414 dwFlags = lppsp->dwFlags;
415 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
416 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
417 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
419 /* as soon as we have a page with the help flag, set the sheet flag on */
420 if (psInfo->proppage[index].hasHelp)
421 psInfo->hasHelp = TRUE;
424 * Process page template.
426 if (dwFlags & PSP_DLGINDIRECT)
427 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
428 else if(dwFlags & PSP_INTERNAL_UNICODE )
430 HRSRC hResource = FindResourceW(lppsp->hInstance,
431 lppsp->u.pszTemplate,
433 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
435 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
439 HRSRC hResource = FindResourceA(lppsp->hInstance,
440 (LPSTR)lppsp->u.pszTemplate,
442 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
444 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
448 * Extract the size of the page and the caption.
453 p = (const WORD *)pTemplate;
455 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
457 /* DLGTEMPLATEEX (not defined in any std. header file) */
461 p += 2; /* help ID */
462 p += 2; /* ext style */
470 p += 2; /* ext style */
476 width = (WORD)*p; p++;
477 height = (WORD)*p; p++;
479 /* remember the largest width and height */
480 if (width > psInfo->width)
481 psInfo->width = width;
483 if (height > psInfo->height)
484 psInfo->height = height;
496 p += lstrlenW( (LPCWSTR)p ) + 1;
510 p += lstrlenW( (LPCWSTR)p ) + 1;
514 /* Extract the caption */
515 psInfo->proppage[index].pszText = (LPCWSTR)p;
516 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
517 p += lstrlenW((LPCWSTR)p) + 1;
519 if (dwFlags & PSP_USETITLE)
523 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
526 if ( !HIWORD( lppsp->pszTitle ) )
528 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
531 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
537 pTitle = lppsp->pszTitle;
539 len = strlenW(pTitle);
540 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
541 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
545 * Build the image list for icons
547 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
550 int icon_cx = GetSystemMetrics(SM_CXSMICON);
551 int icon_cy = GetSystemMetrics(SM_CYSMICON);
553 if (dwFlags & PSP_USEICONID)
554 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
555 icon_cx, icon_cy, LR_DEFAULTCOLOR);
557 hIcon = lppsp->u2.hIcon;
561 if (psInfo->hImageList == 0 )
562 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
564 ImageList_AddIcon(psInfo->hImageList, hIcon);
572 /******************************************************************************
573 * PROPSHEET_CreateDialog
575 * Creates the actual property sheet.
577 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
584 WORD resID = IDD_PROPSHEET;
587 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
590 if( psInfo->unicode )
592 if(!(hRes = FindResourceW(COMCTL32_hModule,
593 MAKEINTRESOURCEW(resID),
599 if(!(hRes = FindResourceA(COMCTL32_hModule,
600 MAKEINTRESOURCEA(resID),
605 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
609 * Make a copy of the dialog template.
611 resSize = SizeofResource(COMCTL32_hModule, hRes);
613 temp = Alloc(resSize);
618 memcpy(temp, template, resSize);
620 if (psInfo->useCallback)
621 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
623 if( psInfo->unicode )
625 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
626 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
627 (LPDLGTEMPLATEW) temp,
628 psInfo->ppshheader.hwndParent,
629 PROPSHEET_DialogProc,
633 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
634 (LPDLGTEMPLATEW) temp,
635 psInfo->ppshheader.hwndParent,
636 PROPSHEET_DialogProc,
638 if ( !ret ) ret = -1;
643 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
644 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
645 (LPDLGTEMPLATEA) temp,
646 psInfo->ppshheader.hwndParent,
647 PROPSHEET_DialogProc,
651 ret = (int)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
652 (LPDLGTEMPLATEA) temp,
653 psInfo->ppshheader.hwndParent,
654 PROPSHEET_DialogProc,
656 if ( !ret ) ret = -1;
665 /******************************************************************************
666 * PROPSHEET_SizeMismatch
668 * Verify that the tab control and the "largest" property sheet page dlg. template
671 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
673 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
674 RECT rcOrigTab, rcPage;
679 GetClientRect(hwndTabCtrl, &rcOrigTab);
680 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
681 rcOrigTab.right, rcOrigTab.bottom);
686 rcPage.left = psInfo->x;
687 rcPage.top = psInfo->y;
688 rcPage.right = psInfo->width;
689 rcPage.bottom = psInfo->height;
691 MapDialogRect(hwndDlg, &rcPage);
692 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
693 rcPage.right, rcPage.bottom);
695 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
697 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
703 /******************************************************************************
704 * PROPSHEET_IsTooSmallWizard
706 * Verify that the default property sheet is big enough.
708 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
710 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
711 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
712 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
714 GetClientRect(hwndDlg, &rcSheetClient);
715 GetWindowRect(hwndDlg, &rcSheetRect);
716 GetWindowRect(hwndLine, &rcLine);
718 /* Remove the space below the sunken line */
719 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
721 /* Remove the buffer zone all around the edge */
722 rcSheetClient.bottom -= (padding.y * 2);
723 rcSheetClient.right -= (padding.x * 2);
728 rcPage.left = psInfo->x;
729 rcPage.top = psInfo->y;
730 rcPage.right = psInfo->width;
731 rcPage.bottom = psInfo->height;
733 MapDialogRect(hwndDlg, &rcPage);
734 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
735 rcPage.right, rcPage.bottom);
737 if (rcPage.right > rcSheetClient.right)
740 if (rcPage.bottom > rcSheetClient.bottom)
746 /******************************************************************************
747 * PROPSHEET_AdjustSize
749 * Resizes the property sheet and the tab control to fit the largest page.
751 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
753 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
754 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
756 int tabOffsetX, tabOffsetY, buttonHeight;
757 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
760 /* Get the height of buttons */
761 GetClientRect(hwndButton, &rc);
762 buttonHeight = rc.bottom;
769 rc.right = psInfo->width;
770 rc.bottom = psInfo->height;
772 MapDialogRect(hwndDlg, &rc);
774 /* retrieve the dialog units */
775 units.left = units.right = 4;
776 units.top = units.bottom = 8;
777 MapDialogRect(hwndDlg, &units);
780 * Resize the tab control.
782 GetClientRect(hwndTabCtrl,&tabRect);
784 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
786 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
788 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
789 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
792 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
794 rc.right = rc.left + tabRect.right - tabRect.left;
795 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
798 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
800 tabOffsetX = -(rc.left);
801 tabOffsetY = -(rc.top);
805 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
806 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
807 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
808 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
810 GetClientRect(hwndTabCtrl, &rc);
812 TRACE("tab client rc %ld %ld %ld %ld\n",
813 rc.left, rc.top, rc.right, rc.bottom);
815 rc.right += ((padding.x * 2) + tabOffsetX);
816 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
819 * Resize the property sheet.
821 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
822 (DWORD)hwndDlg, rc.right, rc.bottom);
823 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
824 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
828 /******************************************************************************
829 * PROPSHEET_AdjustSizeWizard
831 * Resizes the property sheet to fit the largest page.
833 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
835 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
836 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
837 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
839 int buttonHeight, lineHeight;
840 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
843 /* Get the height of buttons */
844 GetClientRect(hwndButton, &rc);
845 buttonHeight = rc.bottom;
847 GetClientRect(hwndLine, &rc);
848 lineHeight = rc.bottom;
850 /* retrieve the dialog units */
851 units.left = units.right = 4;
852 units.top = units.bottom = 8;
853 MapDialogRect(hwndDlg, &units);
860 rc.right = psInfo->width;
861 rc.bottom = psInfo->height;
863 MapDialogRect(hwndDlg, &rc);
865 GetClientRect(hwndTabCtrl,&tabRect);
867 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
869 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
870 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
873 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
875 rc.right = rc.left + tabRect.right - tabRect.left;
876 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
879 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
880 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
881 padding.x, padding.y, buttonHeight, lineHeight);
884 rc.right += (padding.x * 2);
885 rc.bottom += (buttonHeight + lineHeight);
886 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW))
887 rc.bottom += (4 * padding.y);
889 rc.bottom += (5 * padding.y);
892 * Resize the property sheet.
894 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
895 (DWORD)hwndDlg, rc.right, rc.bottom);
896 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
897 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
901 /******************************************************************************
902 * PROPSHEET_AdjustButtons
904 * Adjusts the buttons' positions.
906 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
908 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
912 int buttonWidth, buttonHeight;
913 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
915 if (psInfo->hasApply)
922 * Obtain the size of the buttons.
924 GetClientRect(hwndButton, &rcSheet);
925 buttonWidth = rcSheet.right;
926 buttonHeight = rcSheet.bottom;
929 * Get the size of the property sheet.
931 GetClientRect(hwndParent, &rcSheet);
934 * All buttons will be at this y coordinate.
936 y = rcSheet.bottom - (padding.y + buttonHeight);
939 * Position OK button and make it default.
941 hwndButton = GetDlgItem(hwndParent, IDOK);
943 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
945 SetWindowPos(hwndButton, 0, x, y, 0, 0,
946 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
948 SendMessageA(hwndParent, DM_SETDEFID, IDOK, 0);
952 * Position Cancel button.
954 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
956 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
958 SetWindowPos(hwndButton, 0, x, y, 0, 0,
959 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
962 * Position Apply button.
964 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
966 if (psInfo->hasApply)
969 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
971 x = rcSheet.right - (padding.x + buttonWidth);
973 SetWindowPos(hwndButton, 0, x, y, 0, 0,
974 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
976 EnableWindow(hwndButton, FALSE);
979 ShowWindow(hwndButton, SW_HIDE);
982 * Position Help button.
984 hwndButton = GetDlgItem(hwndParent, IDHELP);
988 x = rcSheet.right - (padding.x + buttonWidth);
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
994 ShowWindow(hwndButton, SW_HIDE);
999 /******************************************************************************
1000 * PROPSHEET_AdjustButtonsWizard
1002 * Adjusts the buttons' positions.
1004 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1005 PropSheetInfo* psInfo)
1007 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1008 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1009 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1012 int num_buttons = 3;
1013 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1014 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1016 if (psInfo->hasHelp)
1020 * Obtain the size of the buttons.
1022 GetClientRect(hwndButton, &rcSheet);
1023 buttonWidth = rcSheet.right;
1024 buttonHeight = rcSheet.bottom;
1026 GetClientRect(hwndLine, &rcSheet);
1027 lineHeight = rcSheet.bottom;
1030 * Get the size of the property sheet.
1032 GetClientRect(hwndParent, &rcSheet);
1035 * All buttons will be at this y coordinate.
1037 y = rcSheet.bottom - (padding.y + buttonHeight);
1040 * Position the Next and the Finish buttons.
1042 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1044 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1046 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1047 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1049 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1051 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1052 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1054 ShowWindow(hwndButton, SW_HIDE);
1057 * Position the Back button.
1059 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1063 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1064 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1067 * Position the Cancel button.
1069 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1071 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1073 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1074 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1077 * Position Help button.
1079 hwndButton = GetDlgItem(hwndParent, IDHELP);
1081 if (psInfo->hasHelp)
1083 x = rcSheet.right - (padding.x + buttonWidth);
1085 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1086 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1089 ShowWindow(hwndButton, SW_HIDE);
1091 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW))
1095 * Position and resize the sunken line.
1098 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1100 lineWidth = rcSheet.right - (padding.x * 2);
1102 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1103 SWP_NOZORDER | SWP_NOACTIVATE);
1106 * Position and resize the header sunken line.
1109 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1110 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1111 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1112 ShowWindow(hwndLineHeader, SW_HIDE);
1117 /******************************************************************************
1118 * PROPSHEET_GetPaddingInfo
1120 * Returns the layout information.
1122 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1124 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1127 PADDING_INFO padding;
1129 GetWindowRect(hwndTab, &rcTab);
1134 ScreenToClient(hwndDlg, &tl);
1142 /******************************************************************************
1143 * PROPSHEET_GetPaddingInfoWizard
1145 * Returns the layout information.
1146 * Vertical spacing is the distance between the line and the buttons.
1147 * Do NOT use the Help button to gather padding information when it isn't mapped
1148 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1149 * for it in this case !
1150 * FIXME: I'm not sure about any other coordinate problems with these evil
1151 * buttons. Fix it in case additional problems appear or maybe calculate
1152 * a padding in a completely different way, as this is somewhat messy.
1154 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1157 PADDING_INFO padding;
1161 POINT ptButton, ptLine;
1164 if (psInfo->hasHelp)
1170 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1172 idButton = IDC_NEXT_BUTTON;
1176 /* hopefully this is ok */
1177 idButton = IDCANCEL;
1181 hwndControl = GetDlgItem(hwndDlg, idButton);
1182 GetWindowRect(hwndControl, &rc);
1184 ptButton.x = rc.left;
1185 ptButton.y = rc.top;
1187 ScreenToClient(hwndDlg, &ptButton);
1190 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1191 GetWindowRect(hwndControl, &rc);
1194 ptLine.y = rc.bottom;
1196 ScreenToClient(hwndDlg, &ptLine);
1198 padding.y = ptButton.y - ptLine.y;
1201 ERR("padding negative ! Please report this !\n");
1203 /* this is most probably not correct, but the best we have now */
1204 padding.x = padding.y;
1208 /******************************************************************************
1209 * PROPSHEET_CreateTabControl
1211 * Insert the tabs in the tab control.
1213 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1214 PropSheetInfo * psInfo)
1216 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1222 item.mask = TCIF_TEXT;
1223 item.cchTextMax = MAX_TABTEXT_LENGTH;
1225 nTabs = psInfo->nPages;
1228 * Set the image list for icons.
1230 if (psInfo->hImageList)
1232 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1235 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1236 for (i = 0; i < nTabs; i++)
1238 if ( psInfo->proppage[i].hasIcon )
1240 item.mask |= TCIF_IMAGE;
1241 item.iImage = iImage++;
1245 item.mask &= ~TCIF_IMAGE;
1248 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1249 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1251 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1256 * Get the size of an in-memory Template
1258 *( Based on the code of PROPSHEET_CollectPageInfo)
1259 * See also dialog.c/DIALOG_ParseTemplate32().
1262 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1265 const WORD* p = (const WORD *)pTemplate;
1266 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1271 /* DLGTEMPLATEEX (not defined in any std. header file) */
1273 TRACE("is DLGTEMPLATEEX\n");
1275 p++; /* signature */
1276 p += 2; /* help ID */
1277 p += 2; /* ext style */
1284 TRACE("is DLGTEMPLATE\n");
1286 p += 2; /* ext style */
1289 nrofitems = (WORD)*p; p++; /* nb items */
1305 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1306 p += lstrlenW( (LPCWSTR)p ) + 1;
1317 p += 2; /* 0xffff plus predefined window class ordinal value */
1320 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1321 p += lstrlenW( (LPCWSTR)p ) + 1;
1326 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1327 p += lstrlenW((LPCWSTR)p) + 1;
1329 /* font, if DS_SETFONT set */
1330 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1333 p+=(istemplateex)?3:1;
1334 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1335 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1338 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1339 * that are following the DLGTEMPLATE(EX) data */
1340 TRACE("%d items\n",nrofitems);
1341 while (nrofitems > 0)
1343 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1346 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1355 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1359 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1360 p += lstrlenW( (LPCWSTR)p ) + 1;
1364 /* check title text */
1371 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1375 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1376 p += lstrlenW( (LPCWSTR)p ) + 1;
1379 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1383 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1384 return (p - (WORD*)pTemplate)*sizeof(WORD);
1388 /******************************************************************************
1389 * PROPSHEET_CreatePage
1393 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1395 const PropSheetInfo * psInfo,
1396 LPCPROPSHEETPAGEW ppshpage)
1398 DLGTEMPLATE* pTemplate;
1401 PADDING_INFO padding;
1402 UINT pageWidth,pageHeight;
1406 TRACE("index %d\n", index);
1408 if (ppshpage == NULL)
1413 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1415 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1416 resSize = GetTemplateSize(pTemplate);
1418 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1423 hResource = FindResourceW(ppshpage->hInstance,
1424 ppshpage->u.pszTemplate,
1429 resSize = SizeofResource(ppshpage->hInstance, hResource);
1431 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1435 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1437 * Make a copy of the dialog template to make it writable
1445 hResource = FindResourceA(ppshpage->hInstance,
1446 (LPSTR)ppshpage->u.pszTemplate,
1451 resSize = SizeofResource(ppshpage->hInstance, hResource);
1453 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1457 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1459 * Make a copy of the dialog template to make it writable
1462 temp = Alloc(resSize);
1466 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1467 memcpy(temp, pTemplate, resSize);
1470 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1472 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1473 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1474 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1475 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1476 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1477 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1478 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1479 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1481 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1485 pTemplate->style |= WS_CHILD | DS_CONTROL;
1486 pTemplate->style &= ~DS_MODALFRAME;
1487 pTemplate->style &= ~WS_CAPTION;
1488 pTemplate->style &= ~WS_SYSMENU;
1489 pTemplate->style &= ~WS_POPUP;
1490 pTemplate->style &= ~WS_DISABLED;
1491 pTemplate->style &= ~WS_VISIBLE;
1492 pTemplate->style &= ~WS_THICKFRAME;
1494 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1497 if (psInfo->proppage[index].useCallback)
1498 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1499 (LPPROPSHEETPAGEW)ppshpage);
1501 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1502 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1505 ppshpage->pfnDlgProc,
1508 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1511 ppshpage->pfnDlgProc,
1513 /* Free a no more needed copy */
1517 psInfo->proppage[index].hwndPage = hwndPage;
1519 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1524 rc.left = psInfo->x;
1526 rc.right = psInfo->width;
1527 rc.bottom = psInfo->height;
1529 MapDialogRect(hwndParent, &rc);
1531 pageWidth = rc.right - rc.left;
1532 pageHeight = rc.bottom - rc.top;
1534 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1535 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d, padx=%d, pady=%d\n",
1536 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1537 pageWidth, pageHeight, padding.x, padding.y);
1539 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
1540 psInfo->ppshheader.dwFlags & PSH_HEADER)
1542 hwndChild = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1544 GetClientRect(hwndChild, &r);
1545 MapWindowPoints(hwndChild, hwndParent, (LPPOINT) &r, 2);
1546 offsety = (ppshpage->dwFlags & PSP_HIDEHEADER)?0:r.bottom + 1;
1549 SetWindowPos(hwndPage, HWND_TOP,
1550 rc.left + padding.x/2,
1551 rc.top + padding.y/2 + offsety,
1552 pageWidth, pageHeight - offsety, 0);
1556 * Ask the Tab control to reduce the client rectangle to that
1559 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1560 pageWidth = rc.right - rc.left;
1561 pageHeight = rc.bottom - rc.top;
1562 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d\n",
1563 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1564 pageWidth, pageHeight);
1565 SetWindowPos(hwndPage, HWND_TOP,
1567 pageWidth, pageHeight, 0);
1573 /******************************************************************************
1574 * PROPSHEET_LoadWizardBitmaps
1576 * Loads the watermark and header bitmaps for a wizard.
1578 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1580 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1582 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1583 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1584 considers hbmWatermark as valid. */
1585 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1586 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1588 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1589 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1592 /* Same behavior as for watermarks */
1593 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1594 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1596 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1597 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1603 /******************************************************************************
1604 * PROPSHEET_ShowPage
1606 * Displays or creates the specified page.
1608 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1611 HWND hwndLineHeader;
1612 LPCPROPSHEETPAGEW ppshpage;
1614 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1615 if (index == psInfo->active_page)
1617 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1618 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1622 if (psInfo->proppage[index].hwndPage == 0)
1624 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1625 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1628 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) == 0)
1630 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1631 psInfo->proppage[index].pszText);
1634 if (psInfo->active_page != -1)
1635 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1637 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1639 /* Synchronize current selection with tab control
1640 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1641 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1642 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1644 psInfo->active_page = index;
1645 psInfo->activeValid = TRUE;
1647 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1649 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1650 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1652 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1653 ShowWindow(hwndLineHeader, SW_HIDE);
1655 ShowWindow(hwndLineHeader, SW_SHOW);
1658 InvalidateRgn(hwndDlg, NULL, TRUE);
1659 UpdateWindow(hwndDlg);
1664 /******************************************************************************
1667 static BOOL PROPSHEET_Back(HWND hwndDlg)
1671 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1676 TRACE("active_page %d\n", psInfo->active_page);
1677 if (psInfo->active_page < 0)
1680 psn.hdr.code = PSN_WIZBACK;
1681 psn.hdr.hwndFrom = hwndDlg;
1685 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1687 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1690 else if (result == 0)
1691 idx = psInfo->active_page - 1;
1693 idx = PROPSHEET_FindPageByResId(psInfo, result);
1695 if (idx >= 0 && idx < psInfo->nPages)
1697 if (PROPSHEET_CanSetCurSel(hwndDlg))
1698 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1703 /******************************************************************************
1706 static BOOL PROPSHEET_Next(HWND hwndDlg)
1710 LRESULT msgResult = 0;
1711 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1715 TRACE("active_page %d\n", psInfo->active_page);
1716 if (psInfo->active_page < 0)
1719 psn.hdr.code = PSN_WIZNEXT;
1720 psn.hdr.hwndFrom = hwndDlg;
1724 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1726 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1727 if (msgResult == -1)
1729 else if (msgResult == 0)
1730 idx = psInfo->active_page + 1;
1732 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1734 if (idx < psInfo->nPages )
1736 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1737 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1743 /******************************************************************************
1746 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1750 LRESULT msgResult = 0;
1751 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1754 TRACE("active_page %d\n", psInfo->active_page);
1755 if (psInfo->active_page < 0)
1758 psn.hdr.code = PSN_WIZFINISH;
1759 psn.hdr.hwndFrom = hwndDlg;
1763 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1765 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1767 TRACE("msg result %ld\n", msgResult);
1772 if (psInfo->isModeless)
1773 psInfo->activeValid = FALSE;
1775 EndDialog(hwndDlg, TRUE);
1780 /******************************************************************************
1783 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1788 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1791 TRACE("active_page %d\n", psInfo->active_page);
1792 if (psInfo->active_page < 0)
1795 psn.hdr.hwndFrom = hwndDlg;
1801 * Send PSN_KILLACTIVE to the current page.
1803 psn.hdr.code = PSN_KILLACTIVE;
1805 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1807 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1811 * Send PSN_APPLY to all pages.
1813 psn.hdr.code = PSN_APPLY;
1814 psn.lParam = lParam;
1816 for (i = 0; i < psInfo->nPages; i++)
1818 hwndPage = psInfo->proppage[i].hwndPage;
1821 switch (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1823 case PSNRET_INVALID:
1824 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1826 case PSNRET_INVALID_NOCHANGEPAGE:
1834 psInfo->activeValid = FALSE;
1836 else if(psInfo->active_page >= 0)
1838 psn.hdr.code = PSN_SETACTIVE;
1840 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1841 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1847 /******************************************************************************
1850 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1852 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1858 TRACE("active_page %d\n", psInfo->active_page);
1859 if (psInfo->active_page < 0)
1862 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1863 psn.hdr.code = PSN_QUERYCANCEL;
1864 psn.hdr.hwndFrom = hwndDlg;
1868 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1871 psn.hdr.code = PSN_RESET;
1872 psn.lParam = lParam;
1874 for (i = 0; i < psInfo->nPages; i++)
1876 hwndPage = psInfo->proppage[i].hwndPage;
1879 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1882 if (psInfo->isModeless)
1884 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1885 psInfo->activeValid = FALSE;
1888 EndDialog(hwndDlg, FALSE);
1891 /******************************************************************************
1894 static void PROPSHEET_Help(HWND hwndDlg)
1896 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1901 TRACE("active_page %d\n", psInfo->active_page);
1902 if (psInfo->active_page < 0)
1905 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1906 psn.hdr.code = PSN_HELP;
1907 psn.hdr.hwndFrom = hwndDlg;
1911 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1914 /******************************************************************************
1917 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1920 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1924 if (!psInfo) return;
1926 * Set the dirty flag of this page.
1928 for (i = 0; i < psInfo->nPages; i++)
1930 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1931 psInfo->proppage[i].isDirty = TRUE;
1935 * Enable the Apply button.
1937 if (psInfo->hasApply)
1939 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1941 EnableWindow(hwndApplyBtn, TRUE);
1945 /******************************************************************************
1946 * PROPSHEET_UnChanged
1948 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1951 BOOL noPageDirty = TRUE;
1952 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1953 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1957 if ( !psInfo ) return;
1958 for (i = 0; i < psInfo->nPages; i++)
1960 /* set the specified page as clean */
1961 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1962 psInfo->proppage[i].isDirty = FALSE;
1964 /* look to see if there's any dirty pages */
1965 if (psInfo->proppage[i].isDirty)
1966 noPageDirty = FALSE;
1970 * Disable Apply button.
1973 EnableWindow(hwndApplyBtn, FALSE);
1976 /******************************************************************************
1977 * PROPSHEET_PressButton
1979 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1981 TRACE("buttonID %d\n", buttonID);
1984 case PSBTN_APPLYNOW:
1985 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1988 PROPSHEET_Back(hwndDlg);
1991 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1994 PROPSHEET_Finish(hwndDlg);
1997 PROPSHEET_DoCommand(hwndDlg, IDHELP);
2000 PROPSHEET_Next(hwndDlg);
2003 PROPSHEET_DoCommand(hwndDlg, IDOK);
2006 FIXME("Invalid button index %d\n", buttonID);
2011 /*************************************************************************
2012 * BOOL PROPSHEET_CanSetCurSel [Internal]
2014 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2017 * hwndDlg [I] handle to a Dialog hWnd
2020 * TRUE if Current Selection can change
2024 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2026 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2031 HWND hwndTabControl;
2034 TRACE("active_page %d\n", psInfo->active_page);
2041 if (psInfo->active_page < 0)
2048 * Notify the current page.
2050 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2051 psn.hdr.code = PSN_KILLACTIVE;
2052 psn.hdr.hwndFrom = hwndDlg;
2056 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2059 * Re-adjust the tab control's contents
2061 hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2062 memset( &rect, 0, sizeof rect );
2063 GetClientRect( hwndTabControl, &rect );
2064 SendMessageW( hwndTabControl, TCM_ADJUSTRECT, 0, (LPARAM) &rect );
2065 SetWindowPos( hwndPage, NULL, rect.left, rect.top,
2066 rect.right - rect.left, rect.bottom - rect.top, 0 );
2069 TRACE("<-- %d\n", res);
2073 /******************************************************************************
2074 * PROPSHEET_SetCurSel
2076 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2079 HPROPSHEETPAGE hpage
2082 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2083 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2084 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2086 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2087 /* hpage takes precedence over index */
2089 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2091 if (index < 0 || index >= psInfo->nPages)
2093 TRACE("Could not find page to select!\n");
2102 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2104 psn.hdr.code = PSN_SETACTIVE;
2105 psn.hdr.hwndFrom = hwndDlg;
2109 if (!psInfo->proppage[index].hwndPage) {
2110 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2111 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2114 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2121 WARN("Tried to skip before first property sheet page!\n");
2124 if (index >= psInfo->nPages) {
2125 WARN("Tried to skip after last property sheet page!\n");
2126 index = psInfo->nPages-1;
2130 else if (result != 0)
2132 int old_index = index;
2133 index = PROPSHEET_FindPageByResId(psInfo, result);
2134 if(index >= psInfo->nPages) {
2136 WARN("Tried to skip to nonexistant page by res id\n");
2143 * Display the new page.
2145 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2147 if (psInfo->proppage[index].hasHelp)
2148 EnableWindow(hwndHelp, TRUE);
2150 EnableWindow(hwndHelp, FALSE);
2155 /******************************************************************************
2156 * PROPSHEET_SetCurSelId
2158 * Selects the page, specified by resource id.
2160 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2163 PropSheetInfo* psInfo =
2164 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2166 idx = PROPSHEET_FindPageByResId(psInfo, id);
2167 if (idx < psInfo->nPages )
2169 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2170 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2174 /******************************************************************************
2175 * PROPSHEET_SetTitleA
2177 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2179 if(HIWORD(lpszText))
2182 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2183 szTitle, sizeof(szTitle));
2184 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2188 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2192 /******************************************************************************
2193 * PROPSHEET_SetTitleW
2195 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2197 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2200 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2201 if (HIWORD(lpszText) == 0) {
2202 if (!LoadStringW(psInfo->ppshheader.hInstance,
2203 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2207 if (dwStyle & PSH_PROPTITLE)
2210 int lentitle = strlenW(lpszText);
2211 int lenprop = strlenW(psInfo->strPropertiesFor);
2213 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2214 strcpyW(dest, psInfo->strPropertiesFor);
2215 strcatW(dest, lpszText);
2217 SetWindowTextW(hwndDlg, dest);
2221 SetWindowTextW(hwndDlg, lpszText);
2224 /******************************************************************************
2225 * PROPSHEET_SetFinishTextA
2227 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2229 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2231 TRACE("'%s'\n", lpszText);
2232 /* Set text, show and enable the Finish button */
2233 SetWindowTextA(hwndButton, lpszText);
2234 ShowWindow(hwndButton, SW_SHOW);
2235 EnableWindow(hwndButton, TRUE);
2237 /* Make it default pushbutton */
2238 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2240 /* Hide Back button */
2241 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2242 ShowWindow(hwndButton, SW_HIDE);
2244 /* Hide Next button */
2245 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2246 ShowWindow(hwndButton, SW_HIDE);
2249 /******************************************************************************
2250 * PROPSHEET_SetFinishTextW
2252 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2254 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2256 TRACE("'%s'\n", debugstr_w(lpszText));
2257 /* Set text, show and enable the Finish button */
2258 SetWindowTextW(hwndButton, lpszText);
2259 ShowWindow(hwndButton, SW_SHOW);
2260 EnableWindow(hwndButton, TRUE);
2262 /* Make it default pushbutton */
2263 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2265 /* Hide Back button */
2266 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2267 ShowWindow(hwndButton, SW_HIDE);
2269 /* Hide Next button */
2270 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2271 ShowWindow(hwndButton, SW_HIDE);
2274 /******************************************************************************
2275 * PROPSHEET_QuerySiblings
2277 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2278 WPARAM wParam, LPARAM lParam)
2282 LRESULT msgResult = 0;
2283 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2286 while ((i < psInfo->nPages) && (msgResult == 0))
2288 hwndPage = psInfo->proppage[i].hwndPage;
2289 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2297 /******************************************************************************
2300 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2301 HPROPSHEETPAGE hpage)
2303 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2305 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2307 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2309 TRACE("hpage %p\n", hpage);
2311 * Allocate and fill in a new PropPageInfo entry.
2313 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2314 sizeof(PropPageInfo) *
2315 (psInfo->nPages + 1));
2316 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2319 psInfo->proppage[psInfo->nPages].hpage = hpage;
2321 if (ppsp->dwFlags & PSP_PREMATURE)
2323 /* Create the page but don't show it */
2324 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2328 * Add a new tab to the tab control.
2330 item.mask = TCIF_TEXT;
2331 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2332 item.cchTextMax = MAX_TABTEXT_LENGTH;
2334 if (psInfo->hImageList)
2336 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2339 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2341 item.mask |= TCIF_IMAGE;
2342 item.iImage = psInfo->nPages;
2345 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2350 /* If it is the only page - show it */
2351 if(psInfo->nPages == 1)
2352 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2356 /******************************************************************************
2357 * PROPSHEET_RemovePage
2359 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2361 HPROPSHEETPAGE hpage)
2363 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2365 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2366 PropPageInfo* oldPages;
2368 TRACE("index %d, hpage %p\n", index, hpage);
2373 * hpage takes precedence over index.
2377 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2380 /* Make sure that index is within range */
2381 if (index < 0 || index >= psInfo->nPages)
2383 TRACE("Could not find page to remove!\n");
2387 TRACE("total pages %d removing page %d active page %d\n",
2388 psInfo->nPages, index, psInfo->active_page);
2390 * Check if we're removing the active page.
2392 if (index == psInfo->active_page)
2394 if (psInfo->nPages > 1)
2398 /* activate previous page */
2399 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2403 /* activate the next page */
2404 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2405 psInfo->active_page = index;
2410 psInfo->active_page = -1;
2411 if (!psInfo->isModeless)
2413 EndDialog(hwndDlg, FALSE);
2418 else if (index < psInfo->active_page)
2419 psInfo->active_page--;
2421 /* Destroy page dialog window */
2422 DestroyWindow(psInfo->proppage[index].hwndPage);
2424 /* Free page resources */
2425 if(psInfo->proppage[index].hpage)
2427 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2429 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2430 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2432 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2435 /* Remove the tab */
2436 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2438 oldPages = psInfo->proppage;
2440 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2443 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2445 if (index < psInfo->nPages)
2446 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2447 (psInfo->nPages - index) * sizeof(PropPageInfo));
2454 /******************************************************************************
2455 * PROPSHEET_SetWizButtons
2457 * This code will work if (and assumes that) the Next button is on top of the
2458 * Finish button. ie. Finish comes after Next in the Z order.
2459 * This means make sure the dialog template reflects this.
2462 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2464 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2465 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2466 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2468 TRACE("%ld\n", dwFlags);
2470 EnableWindow(hwndBack, FALSE);
2471 EnableWindow(hwndNext, FALSE);
2472 EnableWindow(hwndFinish, FALSE);
2474 if (dwFlags & PSWIZB_BACK)
2475 EnableWindow(hwndBack, TRUE);
2477 if (dwFlags & PSWIZB_NEXT)
2479 /* Hide the Finish button */
2480 ShowWindow(hwndFinish, SW_HIDE);
2482 /* Show and enable the Next button */
2483 ShowWindow(hwndNext, SW_SHOW);
2484 EnableWindow(hwndNext, TRUE);
2486 /* Set the Next button as the default pushbutton */
2487 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2490 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2492 /* Hide the Next button */
2493 ShowWindow(hwndNext, SW_HIDE);
2495 /* Show the Finish button */
2496 ShowWindow(hwndFinish, SW_SHOW);
2498 if (dwFlags & PSWIZB_FINISH)
2499 EnableWindow(hwndFinish, TRUE);
2501 /* Set the Finish button as the default pushbutton */
2502 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2506 /******************************************************************************
2507 * PROPSHEET_InsertPage
2509 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2511 if (!HIWORD(hpageInsertAfter))
2512 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2514 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2518 /******************************************************************************
2519 * PROPSHEET_SetHeaderTitleW
2521 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2523 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2526 /******************************************************************************
2527 * PROPSHEET_SetHeaderTitleA
2529 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2531 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2534 /******************************************************************************
2535 * PROPSHEET_SetHeaderSubTitleW
2537 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2539 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2542 /******************************************************************************
2543 * PROPSHEET_SetHeaderSubTitleA
2545 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2547 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2550 /******************************************************************************
2551 * PROPSHEET_HwndToIndex
2553 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2556 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2559 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2561 for (index = 0; index < psInfo->nPages; index++)
2562 if (psInfo->proppage[index].hwndPage == hPageDlg)
2564 WARN("%p not found\n", hPageDlg);
2568 /******************************************************************************
2569 * PROPSHEET_IndexToHwnd
2571 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2573 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2575 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2576 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2577 WARN("%d out of range.\n", iPageIndex);
2580 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2583 /******************************************************************************
2584 * PROPSHEET_PageToIndex
2586 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2588 FIXME("(%p, %p): stub\n", hwndDlg, hPage);
2592 /******************************************************************************
2593 * PROPSHEET_IndexToPage
2595 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2597 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2601 /******************************************************************************
2602 * PROPSHEET_IdToIndex
2604 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2606 FIXME("(%p, %d): stub\n", hwndDlg, iPageId);
2610 /******************************************************************************
2611 * PROPSHEET_IndexToId
2613 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2615 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2619 /******************************************************************************
2620 * PROPSHEET_GetResult
2622 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2624 FIXME("(%p): stub\n", hwndDlg);
2628 /******************************************************************************
2629 * PROPSHEET_RecalcPageSizes
2631 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2633 FIXME("(%p): stub\n", hwndDlg);
2637 /******************************************************************************
2638 * PROPSHEET_GetPageIndex
2640 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2641 * the array of PropPageInfo.
2643 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2648 TRACE("hpage %p\n", hpage);
2649 while ((index < psInfo->nPages) && (found == FALSE))
2651 if (psInfo->proppage[index].hpage == hpage)
2663 /******************************************************************************
2666 static void PROPSHEET_CleanUp(HWND hwndDlg)
2669 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2673 if (!psInfo) return;
2674 if (HIWORD(psInfo->ppshheader.pszCaption))
2675 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2677 for (i = 0; i < psInfo->nPages; i++)
2679 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2681 if(psInfo->proppage[i].hwndPage)
2682 DestroyWindow(psInfo->proppage[i].hwndPage);
2686 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2687 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2689 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2693 DeleteObject(psInfo->hFont);
2694 DeleteObject(psInfo->hFontBold);
2695 /* If we created the bitmaps, destroy them */
2696 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2697 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2698 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2699 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2700 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2701 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2703 Free(psInfo->proppage);
2704 Free(psInfo->strPropertiesFor);
2705 ImageList_Destroy(psInfo->hImageList);
2707 GlobalFree((HGLOBAL)psInfo);
2710 /******************************************************************************
2711 * PropertySheet (COMCTL32.@)
2712 * PropertySheetA (COMCTL32.@)
2714 * Creates a property sheet in the specified property sheet header.
2717 * Modal property sheets: Positive if successful or -1 otherwise.
2718 * Modeless property sheets: Property sheet handle.
2720 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2721 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2723 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2726 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2727 sizeof(PropSheetInfo));
2731 TRACE("(%p)\n", lppsh);
2733 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2735 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2737 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2739 for (n = i = 0; i < lppsh->nPages; i++, n++)
2741 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2742 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2745 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2746 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2749 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2752 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2753 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2759 psInfo->unicode = FALSE;
2760 bRet = PROPSHEET_CreateDialog(psInfo);
2765 /******************************************************************************
2766 * PropertySheetW (COMCTL32.@)
2768 * See PropertySheetA.
2770 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2773 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2774 sizeof(PropSheetInfo));
2778 TRACE("(%p)\n", lppsh);
2780 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2782 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2784 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2786 for (n = i = 0; i < lppsh->nPages; i++, n++)
2788 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2789 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2792 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2793 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2796 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2799 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2800 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2806 psInfo->unicode = TRUE;
2807 bRet = PROPSHEET_CreateDialog(psInfo);
2812 /******************************************************************************
2813 * CreatePropertySheetPage (COMCTL32.@)
2814 * CreatePropertySheetPageA (COMCTL32.@)
2816 * Creates a new property sheet page.
2819 * Success: Handle to new property sheet page.
2823 * An application must use the PSM_ADDPAGE message to add the new page to
2824 * an existing property sheet.
2826 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2827 LPCPROPSHEETPAGEA lpPropSheetPage)
2829 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2831 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2833 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2834 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2836 int len = strlen(lpPropSheetPage->u.pszTemplate);
2838 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,len+1 );
2839 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2841 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2843 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2846 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2848 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2850 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2851 ppsp->pszTitle = NULL;
2853 return (HPROPSHEETPAGE)ppsp;
2856 /******************************************************************************
2857 * CreatePropertySheetPageW (COMCTL32.@)
2859 * See CreatePropertySheetA.
2861 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2863 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2865 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2867 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2869 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2871 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2873 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2874 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2876 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2878 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2879 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2880 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2883 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2885 int len = strlenW(lpPropSheetPage->pszTitle);
2886 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2887 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2889 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2890 ppsp->pszTitle = NULL;
2892 return (HPROPSHEETPAGE)ppsp;
2895 /******************************************************************************
2896 * DestroyPropertySheetPage (COMCTL32.@)
2898 * Destroys a property sheet page previously created with
2899 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2906 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2908 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2913 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2914 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2916 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2917 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2919 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2920 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2927 /******************************************************************************
2928 * PROPSHEET_IsDialogMessage
2930 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2932 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2935 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2938 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2941 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2943 if (!(dlgCode & DLGC_WANTMESSAGE))
2945 switch (lpMsg->wParam)
2948 if (GetKeyState(VK_SHIFT) & 0x8000)
2954 case VK_NEXT: new_page = 1; break;
2955 case VK_PRIOR: new_page = -1; break;
2961 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2963 new_page += psInfo->active_page;
2966 new_page = psInfo->nPages - 1;
2967 else if (new_page >= psInfo->nPages)
2970 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2977 return IsDialogMessageA(hwnd, lpMsg);
2980 /******************************************************************************
2981 * PROPSHEET_DoCommand
2983 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2989 case IDC_APPLY_BUTTON:
2991 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2993 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2998 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3002 if (psInfo->restartWindows)
3003 result = ID_PSRESTARTWINDOWS;
3005 /* reboot system takes precedence over restart windows */
3006 if (psInfo->rebootSystem)
3007 result = ID_PSREBOOTSYSTEM;
3009 if (psInfo->isModeless)
3010 psInfo->activeValid = FALSE;
3012 EndDialog(hwnd, result);
3015 EnableWindow(hwndApplyBtn, FALSE);
3020 case IDC_BACK_BUTTON:
3021 PROPSHEET_Back(hwnd);
3024 case IDC_NEXT_BUTTON:
3025 PROPSHEET_Next(hwnd);
3028 case IDC_FINISH_BUTTON:
3029 PROPSHEET_Finish(hwnd);
3033 PROPSHEET_Cancel(hwnd, 0);
3037 PROPSHEET_Help(hwnd);
3047 /******************************************************************************
3050 static LRESULT PROPSHEET_Paint(HWND hwnd)
3052 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3057 HPALETTE hOldPal = 0;
3061 LPCPROPSHEETPAGEW ppshpage;
3062 WCHAR szBuffer[256];
3065 hdc = BeginPaint(hwnd, &ps);
3068 hdcSrc = CreateCompatibleDC(0);
3069 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3071 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3072 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3074 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3075 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3076 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3079 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3081 COLORREF clrOld = 0;
3084 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3085 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3087 GetClientRect(hwndLineHeader, &r);
3088 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3089 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3091 GetObjectA(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3093 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3095 /* Fill the unoccupied part of the header with color of the
3096 * left-top pixel, but do it only when needed.
3098 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3100 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3101 CopyRect(&r, &rzone);
3102 if (bm.bmWidth < r.right)
3104 r.left = bm.bmWidth;
3105 FillRect(hdc, &r, hbr);
3107 if (bm.bmHeight < r.bottom)
3110 r.top = bm.bmHeight;
3111 FillRect(hdc, &r, hbr);
3118 hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
3119 FillRect(hdc, &rzone, hbr);
3123 clrOld = SetTextColor (hdc, 0x00000000);
3124 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3126 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3127 SetRect(&r, 20, 10, rzone.right - bm.bmWidth, 18);
3128 if (HIWORD(ppshpage->pszHeaderTitle))
3130 if (psInfo->unicode)
3131 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3132 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3134 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3135 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3139 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderTitle,
3143 DrawTextW(hdc, szBuffer, nLength,
3144 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3149 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3150 SelectObject(hdc, psInfo->hFont);
3151 SetRect(&r, 40, 25, rzone.right - bm.bmWidth, 43);
3152 if (HIWORD(ppshpage->pszHeaderTitle))
3154 if (psInfo->unicode)
3155 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3156 -1, &r, DT_LEFT | DT_SINGLELINE);
3158 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3159 -1, &r, DT_LEFT | DT_SINGLELINE);
3163 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderSubTitle,
3167 DrawTextW(hdc, szBuffer, nLength,
3168 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3173 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3176 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3177 hdcSrc, 0, 0, SRCCOPY);
3181 BitBlt(hdc, rzone.right - bm.bmWidth,
3182 (rzone.bottom - bm.bmHeight) / 2,
3183 bm.bmWidth, bm.bmHeight,
3184 hdcSrc, 0, 0, SRCCOPY);
3187 offsety = rzone.bottom + 2;
3189 SetTextColor(hdc, clrOld);
3190 SetBkMode(hdc, oldBkMode);
3191 SelectObject(hdc, hOldFont);
3192 SelectObject(hdcSrc, hbmp);
3195 if ( ((psInfo->active_page == 0) || (psInfo->active_page == psInfo->nPages - 1)) &&
3196 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3197 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3199 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3201 GetClientRect(hwndLine, &r);
3202 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3204 GetObjectA(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3205 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3207 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3208 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3210 /* If the bitmap is not big enough, fill the remaining area
3211 with the color of pixel (0,0) of bitmap - see MSDN */
3212 if (r.top > bm.bmHeight) {
3213 r.bottom = r.top - 1;
3214 r.top = bm.bmHeight;
3216 r.right = bm.bmWidth;
3217 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3218 FillRect(hdc, &r, hbr);
3222 SelectObject(hdcSrc, hbmp);
3225 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3226 SelectPalette(hdc, hOldPal, FALSE);
3230 EndPaint(hwnd, &ps);
3235 /******************************************************************************
3236 * PROPSHEET_DialogProc
3239 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3241 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3242 hwnd, uMsg, wParam, lParam);
3248 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3249 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3250 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3251 LPCPROPSHEETPAGEW ppshpage;
3255 /* Using PropSheetInfoStr to store extra data doesn't match the native
3256 * common control: native uses TCM_[GS]ETITEM
3258 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3261 * psInfo->hwnd is not being used by WINE code - it exists
3262 * for compatibility with "real" Windoze. The same about
3263 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3266 psInfo->hwnd = hwnd;
3267 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3269 /* set up the Next and Back buttons by default */
3270 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3273 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3274 psInfo->hFont = CreateFontIndirectA (&logFont);
3275 logFont.lfWeight = FW_BOLD;
3276 psInfo->hFontBold = CreateFontIndirectA (&logFont);
3279 * Small icon in the title bar.
3281 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3282 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3285 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3286 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3288 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3289 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3290 psInfo->ppshheader.u.pszIcon,
3295 hIcon = psInfo->ppshheader.u.hIcon;
3297 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3300 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3301 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3303 psInfo->strPropertiesFor = strCaption;
3305 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3307 PROPSHEET_CreateTabControl(hwnd, psInfo);
3309 PROPSHEET_LoadWizardBitmaps(psInfo);
3311 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3313 ShowWindow(hwndTabCtrl, SW_HIDE);
3314 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
3316 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3317 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3322 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3324 PROPSHEET_AdjustSize(hwnd, psInfo);
3325 PROPSHEET_AdjustButtons(hwnd, psInfo);
3329 if (psInfo->useCallback)
3330 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3331 PSCB_INITIALIZED, (LPARAM)0);
3333 idx = psInfo->active_page;
3334 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3335 psInfo->active_page = -1;
3337 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3339 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3340 * as some programs call TCM_GETCURSEL to get the current selection
3341 * from which to switch to the next page */
3342 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3344 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3345 psInfo->ppshheader.hInstance)
3349 if (LoadStringW(psInfo->ppshheader.hInstance,
3350 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3351 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3355 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3356 psInfo->ppshheader.pszCaption);
3363 PROPSHEET_Paint(hwnd);
3367 PROPSHEET_CleanUp(hwnd);
3371 PROPSHEET_Cancel(hwnd, 1);
3375 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3377 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3379 /* No default handler, forward notification to active page */
3380 if (psInfo->activeValid && psInfo->active_page != -1)
3382 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3383 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3390 NMHDR* pnmh = (LPNMHDR) lParam;
3392 if (pnmh->code == TCN_SELCHANGE)
3394 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3395 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3398 if(pnmh->code == TCN_SELCHANGING)
3400 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3401 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3408 case PSM_GETCURRENTPAGEHWND:
3410 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3414 if (psInfo->activeValid && psInfo->active_page != -1)
3415 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3417 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3423 PROPSHEET_Changed(hwnd, (HWND)wParam);
3427 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3430 case PSM_GETTABCONTROL:
3432 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3434 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3443 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3444 if(msgResult != FALSE)
3446 msgResult = PROPSHEET_SetCurSel(hwnd,
3449 (HPROPSHEETPAGE)lParam);
3452 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3457 case PSM_CANCELTOCLOSE:
3459 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3460 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3461 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3463 EnableWindow(hwndCancel, FALSE);
3464 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3465 SetWindowTextW(hwndOK, buf);
3470 case PSM_RESTARTWINDOWS:
3472 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3475 psInfo->restartWindows = TRUE;
3479 case PSM_REBOOTSYSTEM:
3481 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3484 psInfo->rebootSystem = TRUE;
3489 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3493 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3498 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3500 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3505 case PSM_QUERYSIBLINGS:
3507 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3509 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3517 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3518 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3519 * on success or FALSE otherwise, as specified on MSDN Online.
3520 * Also see the MFC code for
3521 * CPropertySheet::AddPage(CPropertyPage* pPage).
3524 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3526 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3531 case PSM_REMOVEPAGE:
3532 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3535 case PSM_ISDIALOGMESSAGE:
3537 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3538 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3542 case PSM_PRESSBUTTON:
3543 PROPSHEET_PressButton(hwnd, (int)wParam);
3546 case PSM_SETFINISHTEXTA:
3547 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3550 case PSM_SETWIZBUTTONS:
3551 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3554 case PSM_SETCURSELID:
3555 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3558 case PSM_SETFINISHTEXTW:
3559 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3562 case PSM_INSERTPAGE:
3564 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3565 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3569 case PSM_SETHEADERTITLEW:
3570 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3573 case PSM_SETHEADERTITLEA:
3574 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3577 case PSM_SETHEADERSUBTITLEW:
3578 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3581 case PSM_SETHEADERSUBTITLEA:
3582 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3585 case PSM_HWNDTOINDEX:
3587 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3588 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3592 case PSM_INDEXTOHWND:
3594 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3595 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3599 case PSM_PAGETOINDEX:
3601 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3602 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3606 case PSM_INDEXTOPAGE:
3608 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3609 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3615 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3616 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3622 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3623 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3629 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3630 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3634 case PSM_RECALCPAGESIZES:
3636 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3637 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);