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_WATERMARK 0x00008000
207 * PSH_USEHBMWATERMARK 0x00010000
208 * PSH_USEHPLWATERMARK 0x00020000
209 * PSH_STRETCHWATERMARK 0x00040000
210 * PSH_HEADER 0x00080000
211 * PSH_USEHBMHEADER 0x00100000
212 * PSH_USEPAGELANG 0x00200000
213 * PSH_WIZARD_LITE 0x00400000 also not in .h
214 * PSH_WIZARD97 0x01000000 (IE 5 and above)
215 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
218 add_flag(PSH_WIZARDHASFINISH);
219 add_flag(PSH_RTLREADING);
220 add_flag(PSH_WIZARDCONTEXTHELP);
221 add_flag(PSH_STRETCHWATERMARK);
222 add_flag(PSH_USEPAGELANG);
223 add_flag(PSH_WIZARD_LITE);
224 add_flag(PSH_NOCONTEXTHELP);
225 if (string[0] != '\0')
226 FIXME("%s\n", string);
230 /******************************************************************************
231 * PROPSHEET_GetPageRect
233 * Retrieve rect from tab control and map into the dialog for SetWindowPos
235 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
237 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
239 GetClientRect(hwndTabCtrl, rc);
240 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
241 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
244 /******************************************************************************
245 * PROPSHEET_FindPageByResId
247 * Find page index corresponding to page resource id.
249 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
253 for (i = 0; i < psInfo->nPages; i++)
255 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
257 /* Fixme: if resource ID is a string shall we use strcmp ??? */
258 if (lppsp->u.pszTemplate == (LPVOID)resId)
265 /******************************************************************************
268 * Convert ASCII to Unicode since all data is saved as Unicode.
270 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
274 TRACE("<%s>\n", frstr);
275 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
276 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
277 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
280 /******************************************************************************
281 * PROPSHEET_CollectSheetInfoA
283 * Collect relevant data.
285 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
286 PropSheetInfo * psInfo)
288 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
289 DWORD dwFlags = lppsh->dwFlags;
291 psInfo->hasHelp = dwFlags & PSH_HASHELP;
292 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
293 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
294 psInfo->isModeless = dwFlags & PSH_MODELESS;
296 memcpy(&psInfo->ppshheader,lppsh,dwSize);
297 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",
298 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
299 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
301 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
303 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
304 psInfo->ppshheader.pszCaption = NULL;
307 if (HIWORD(lppsh->pszCaption))
309 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
310 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
311 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len);
314 psInfo->nPages = lppsh->nPages;
316 if (dwFlags & PSH_USEPSTARTPAGE)
318 TRACE("PSH_USEPSTARTPAGE is on\n");
319 psInfo->active_page = 0;
322 psInfo->active_page = lppsh->u2.nStartPage;
324 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
325 psInfo->active_page = 0;
327 psInfo->restartWindows = FALSE;
328 psInfo->rebootSystem = FALSE;
329 psInfo->hImageList = 0;
330 psInfo->activeValid = FALSE;
335 /******************************************************************************
336 * PROPSHEET_CollectSheetInfoW
338 * Collect relevant data.
340 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
341 PropSheetInfo * psInfo)
343 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
344 DWORD dwFlags = lppsh->dwFlags;
346 psInfo->hasHelp = dwFlags & PSH_HASHELP;
347 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
348 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
349 psInfo->isModeless = dwFlags & PSH_MODELESS;
351 memcpy(&psInfo->ppshheader,lppsh,dwSize);
352 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",
353 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
355 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
357 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
358 psInfo->ppshheader.pszCaption = NULL;
361 if (HIWORD(lppsh->pszCaption))
363 int len = strlenW(lppsh->pszCaption);
364 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
365 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
368 psInfo->nPages = lppsh->nPages;
370 if (dwFlags & PSH_USEPSTARTPAGE)
372 TRACE("PSH_USEPSTARTPAGE is on\n");
373 psInfo->active_page = 0;
376 psInfo->active_page = lppsh->u2.nStartPage;
378 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
379 psInfo->active_page = 0;
381 psInfo->restartWindows = FALSE;
382 psInfo->rebootSystem = FALSE;
383 psInfo->hImageList = 0;
384 psInfo->activeValid = FALSE;
389 /******************************************************************************
390 * PROPSHEET_CollectPageInfo
392 * Collect property sheet data.
393 * With code taken from DIALOG_ParseTemplate32.
395 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
396 PropSheetInfo * psInfo,
399 DLGTEMPLATE* pTemplate;
405 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
406 psInfo->proppage[index].hwndPage = 0;
407 psInfo->proppage[index].isDirty = FALSE;
410 * Process property page flags.
412 dwFlags = lppsp->dwFlags;
413 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
414 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
415 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
417 /* as soon as we have a page with the help flag, set the sheet flag on */
418 if (psInfo->proppage[index].hasHelp)
419 psInfo->hasHelp = TRUE;
422 * Process page template.
424 if (dwFlags & PSP_DLGINDIRECT)
425 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
426 else if(dwFlags & PSP_INTERNAL_UNICODE )
428 HRSRC hResource = FindResourceW(lppsp->hInstance,
429 lppsp->u.pszTemplate,
431 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
433 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
437 HRSRC hResource = FindResourceA(lppsp->hInstance,
438 (LPSTR)lppsp->u.pszTemplate,
440 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
442 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
446 * Extract the size of the page and the caption.
451 p = (const WORD *)pTemplate;
453 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
455 /* DLGTEMPLATEEX (not defined in any std. header file) */
459 p += 2; /* help ID */
460 p += 2; /* ext style */
468 p += 2; /* ext style */
474 width = (WORD)*p; p++;
475 height = (WORD)*p; p++;
477 /* remember the largest width and height */
478 if (width > psInfo->width)
479 psInfo->width = width;
481 if (height > psInfo->height)
482 psInfo->height = height;
494 p += lstrlenW( (LPCWSTR)p ) + 1;
508 p += lstrlenW( (LPCWSTR)p ) + 1;
512 /* Extract the caption */
513 psInfo->proppage[index].pszText = (LPCWSTR)p;
514 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
515 p += lstrlenW((LPCWSTR)p) + 1;
517 if (dwFlags & PSP_USETITLE)
521 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
524 if ( !HIWORD( lppsp->pszTitle ) )
526 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof(szTitle) ))
529 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
535 pTitle = lppsp->pszTitle;
537 len = strlenW(pTitle);
538 psInfo->proppage[index].pszText = Alloc( (len+1)*sizeof (WCHAR) );
539 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
543 * Build the image list for icons
545 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
548 int icon_cx = GetSystemMetrics(SM_CXSMICON);
549 int icon_cy = GetSystemMetrics(SM_CYSMICON);
551 if (dwFlags & PSP_USEICONID)
552 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
553 icon_cx, icon_cy, LR_DEFAULTCOLOR);
555 hIcon = lppsp->u2.hIcon;
559 if (psInfo->hImageList == 0 )
560 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
562 ImageList_AddIcon(psInfo->hImageList, hIcon);
570 /******************************************************************************
571 * PROPSHEET_CreateDialog
573 * Creates the actual property sheet.
575 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
582 WORD resID = IDD_PROPSHEET;
585 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
588 if( psInfo->unicode )
590 if(!(hRes = FindResourceW(COMCTL32_hModule,
591 MAKEINTRESOURCEW(resID),
597 if(!(hRes = FindResourceA(COMCTL32_hModule,
598 MAKEINTRESOURCEA(resID),
603 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
607 * Make a copy of the dialog template.
609 resSize = SizeofResource(COMCTL32_hModule, hRes);
611 temp = Alloc(resSize);
616 memcpy(temp, template, resSize);
618 if (psInfo->useCallback)
619 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
621 if( psInfo->unicode )
623 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
624 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
625 (LPDLGTEMPLATEW) temp,
626 psInfo->ppshheader.hwndParent,
627 PROPSHEET_DialogProc,
631 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
632 (LPDLGTEMPLATEW) temp,
633 psInfo->ppshheader.hwndParent,
634 PROPSHEET_DialogProc,
636 if ( !ret ) ret = -1;
641 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
642 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
643 (LPDLGTEMPLATEA) temp,
644 psInfo->ppshheader.hwndParent,
645 PROPSHEET_DialogProc,
649 ret = (int)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
650 (LPDLGTEMPLATEA) temp,
651 psInfo->ppshheader.hwndParent,
652 PROPSHEET_DialogProc,
654 if ( !ret ) ret = -1;
663 /******************************************************************************
664 * PROPSHEET_SizeMismatch
666 * Verify that the tab control and the "largest" property sheet page dlg. template
669 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
671 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
672 RECT rcOrigTab, rcPage;
677 GetClientRect(hwndTabCtrl, &rcOrigTab);
678 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
679 rcOrigTab.right, rcOrigTab.bottom);
684 rcPage.left = psInfo->x;
685 rcPage.top = psInfo->y;
686 rcPage.right = psInfo->width;
687 rcPage.bottom = psInfo->height;
689 MapDialogRect(hwndDlg, &rcPage);
690 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
691 rcPage.right, rcPage.bottom);
693 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
695 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
701 /******************************************************************************
702 * PROPSHEET_IsTooSmallWizard
704 * Verify that the default property sheet is big enough.
706 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
708 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
709 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
710 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
712 GetClientRect(hwndDlg, &rcSheetClient);
713 GetWindowRect(hwndDlg, &rcSheetRect);
714 GetWindowRect(hwndLine, &rcLine);
716 /* Remove the space below the sunken line */
717 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
719 /* Remove the buffer zone all around the edge */
720 rcSheetClient.bottom -= (padding.y * 2);
721 rcSheetClient.right -= (padding.x * 2);
726 rcPage.left = psInfo->x;
727 rcPage.top = psInfo->y;
728 rcPage.right = psInfo->width;
729 rcPage.bottom = psInfo->height;
731 MapDialogRect(hwndDlg, &rcPage);
732 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
733 rcPage.right, rcPage.bottom);
735 if (rcPage.right > rcSheetClient.right)
738 if (rcPage.bottom > rcSheetClient.bottom)
744 /******************************************************************************
745 * PROPSHEET_AdjustSize
747 * Resizes the property sheet and the tab control to fit the largest page.
749 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
751 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
752 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
754 int tabOffsetX, tabOffsetY, buttonHeight;
755 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
758 /* Get the height of buttons */
759 GetClientRect(hwndButton, &rc);
760 buttonHeight = rc.bottom;
767 rc.right = psInfo->width;
768 rc.bottom = psInfo->height;
770 MapDialogRect(hwndDlg, &rc);
772 /* retrieve the dialog units */
773 units.left = units.right = 4;
774 units.top = units.bottom = 8;
775 MapDialogRect(hwndDlg, &units);
778 * Resize the tab control.
780 GetClientRect(hwndTabCtrl,&tabRect);
782 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
784 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
786 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
787 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
790 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
792 rc.right = rc.left + tabRect.right - tabRect.left;
793 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
796 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
798 tabOffsetX = -(rc.left);
799 tabOffsetY = -(rc.top);
803 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
804 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
805 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
806 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
808 GetClientRect(hwndTabCtrl, &rc);
810 TRACE("tab client rc %ld %ld %ld %ld\n",
811 rc.left, rc.top, rc.right, rc.bottom);
813 rc.right += ((padding.x * 2) + tabOffsetX);
814 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
817 * Resize the property sheet.
819 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
820 (DWORD)hwndDlg, rc.right, rc.bottom);
821 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
822 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
826 /******************************************************************************
827 * PROPSHEET_AdjustSizeWizard
829 * Resizes the property sheet to fit the largest page.
831 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
833 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
834 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
835 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
837 int buttonHeight, lineHeight;
838 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
841 /* Get the height of buttons */
842 GetClientRect(hwndButton, &rc);
843 buttonHeight = rc.bottom;
845 GetClientRect(hwndLine, &rc);
846 lineHeight = rc.bottom;
848 /* retrieve the dialog units */
849 units.left = units.right = 4;
850 units.top = units.bottom = 8;
851 MapDialogRect(hwndDlg, &units);
858 rc.right = psInfo->width;
859 rc.bottom = psInfo->height;
861 MapDialogRect(hwndDlg, &rc);
863 GetClientRect(hwndTabCtrl,&tabRect);
865 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
867 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
868 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
871 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
873 rc.right = rc.left + tabRect.right - tabRect.left;
874 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
877 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
878 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
879 padding.x, padding.y, buttonHeight, lineHeight);
882 rc.right += (padding.x * 2);
883 rc.bottom += (buttonHeight + lineHeight);
884 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW))
885 rc.bottom += (4 * padding.y);
887 rc.bottom += (5 * padding.y);
890 * Resize the property sheet.
892 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
893 (DWORD)hwndDlg, rc.right, rc.bottom);
894 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
895 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
899 /******************************************************************************
900 * PROPSHEET_AdjustButtons
902 * Adjusts the buttons' positions.
904 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
906 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
910 int buttonWidth, buttonHeight;
911 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
913 if (psInfo->hasApply)
920 * Obtain the size of the buttons.
922 GetClientRect(hwndButton, &rcSheet);
923 buttonWidth = rcSheet.right;
924 buttonHeight = rcSheet.bottom;
927 * Get the size of the property sheet.
929 GetClientRect(hwndParent, &rcSheet);
932 * All buttons will be at this y coordinate.
934 y = rcSheet.bottom - (padding.y + buttonHeight);
937 * Position OK button and make it default.
939 hwndButton = GetDlgItem(hwndParent, IDOK);
941 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
943 SetWindowPos(hwndButton, 0, x, y, 0, 0,
944 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
946 SendMessageA(hwndParent, DM_SETDEFID, IDOK, 0);
950 * Position Cancel button.
952 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
954 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
956 SetWindowPos(hwndButton, 0, x, y, 0, 0,
957 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
960 * Position Apply button.
962 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
964 if (psInfo->hasApply)
967 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
969 x = rcSheet.right - (padding.x + buttonWidth);
971 SetWindowPos(hwndButton, 0, x, y, 0, 0,
972 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
974 EnableWindow(hwndButton, FALSE);
977 ShowWindow(hwndButton, SW_HIDE);
980 * Position Help button.
982 hwndButton = GetDlgItem(hwndParent, IDHELP);
986 x = rcSheet.right - (padding.x + buttonWidth);
988 SetWindowPos(hwndButton, 0, x, y, 0, 0,
989 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
992 ShowWindow(hwndButton, SW_HIDE);
997 /******************************************************************************
998 * PROPSHEET_AdjustButtonsWizard
1000 * Adjusts the buttons' positions.
1002 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1003 PropSheetInfo* psInfo)
1005 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1006 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1007 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1010 int num_buttons = 3;
1011 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1012 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1014 if (psInfo->hasHelp)
1018 * Obtain the size of the buttons.
1020 GetClientRect(hwndButton, &rcSheet);
1021 buttonWidth = rcSheet.right;
1022 buttonHeight = rcSheet.bottom;
1024 GetClientRect(hwndLine, &rcSheet);
1025 lineHeight = rcSheet.bottom;
1028 * Get the size of the property sheet.
1030 GetClientRect(hwndParent, &rcSheet);
1033 * All buttons will be at this y coordinate.
1035 y = rcSheet.bottom - (padding.y + buttonHeight);
1038 * Position the Next and the Finish buttons.
1040 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1042 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1044 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1045 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1047 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1049 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1050 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1052 ShowWindow(hwndButton, SW_HIDE);
1055 * Position the Back button.
1057 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1061 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1062 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1065 * Position the Cancel button.
1067 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1069 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1071 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1072 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1075 * Position Help button.
1077 hwndButton = GetDlgItem(hwndParent, IDHELP);
1079 if (psInfo->hasHelp)
1081 x = rcSheet.right - (padding.x + buttonWidth);
1083 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1084 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1087 ShowWindow(hwndButton, SW_HIDE);
1089 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW))
1093 * Position and resize the sunken line.
1096 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1098 lineWidth = rcSheet.right - (padding.x * 2);
1100 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1101 SWP_NOZORDER | SWP_NOACTIVATE);
1104 * Position and resize the header sunken line.
1107 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1108 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1109 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1110 ShowWindow(hwndLineHeader, SW_HIDE);
1115 /******************************************************************************
1116 * PROPSHEET_GetPaddingInfo
1118 * Returns the layout information.
1120 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1122 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1125 PADDING_INFO padding;
1127 GetWindowRect(hwndTab, &rcTab);
1132 ScreenToClient(hwndDlg, &tl);
1140 /******************************************************************************
1141 * PROPSHEET_GetPaddingInfoWizard
1143 * Returns the layout information.
1144 * Vertical spacing is the distance between the line and the buttons.
1145 * Do NOT use the Help button to gather padding information when it isn't mapped
1146 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1147 * for it in this case !
1148 * FIXME: I'm not sure about any other coordinate problems with these evil
1149 * buttons. Fix it in case additional problems appear or maybe calculate
1150 * a padding in a completely different way, as this is somewhat messy.
1152 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1155 PADDING_INFO padding;
1159 POINT ptButton, ptLine;
1162 if (psInfo->hasHelp)
1168 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1170 idButton = IDC_NEXT_BUTTON;
1174 /* hopefully this is ok */
1175 idButton = IDCANCEL;
1179 hwndControl = GetDlgItem(hwndDlg, idButton);
1180 GetWindowRect(hwndControl, &rc);
1182 ptButton.x = rc.left;
1183 ptButton.y = rc.top;
1185 ScreenToClient(hwndDlg, &ptButton);
1188 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1189 GetWindowRect(hwndControl, &rc);
1192 ptLine.y = rc.bottom;
1194 ScreenToClient(hwndDlg, &ptLine);
1196 padding.y = ptButton.y - ptLine.y;
1199 ERR("padding negative ! Please report this !\n");
1201 /* this is most probably not correct, but the best we have now */
1202 padding.x = padding.y;
1206 /******************************************************************************
1207 * PROPSHEET_CreateTabControl
1209 * Insert the tabs in the tab control.
1211 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1212 PropSheetInfo * psInfo)
1214 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1220 item.mask = TCIF_TEXT;
1221 item.cchTextMax = MAX_TABTEXT_LENGTH;
1223 nTabs = psInfo->nPages;
1226 * Set the image list for icons.
1228 if (psInfo->hImageList)
1230 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1233 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1234 for (i = 0; i < nTabs; i++)
1236 if ( psInfo->proppage[i].hasIcon )
1238 item.mask |= TCIF_IMAGE;
1239 item.iImage = iImage++;
1243 item.mask &= ~TCIF_IMAGE;
1246 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1247 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1249 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1254 * Get the size of an in-memory Template
1256 *( Based on the code of PROPSHEET_CollectPageInfo)
1257 * See also dialog.c/DIALOG_ParseTemplate32().
1260 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1263 const WORD* p = (const WORD *)pTemplate;
1264 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1269 /* DLGTEMPLATEEX (not defined in any std. header file) */
1271 TRACE("is DLGTEMPLATEEX\n");
1273 p++; /* signature */
1274 p += 2; /* help ID */
1275 p += 2; /* ext style */
1282 TRACE("is DLGTEMPLATE\n");
1284 p += 2; /* ext style */
1287 nrofitems = (WORD)*p; p++; /* nb items */
1303 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1304 p += lstrlenW( (LPCWSTR)p ) + 1;
1315 p += 2; /* 0xffff plus predefined window class ordinal value */
1318 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1319 p += lstrlenW( (LPCWSTR)p ) + 1;
1324 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1325 p += lstrlenW((LPCWSTR)p) + 1;
1327 /* font, if DS_SETFONT set */
1328 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1331 p+=(istemplateex)?3:1;
1332 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1333 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1336 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1337 * that are following the DLGTEMPLATE(EX) data */
1338 TRACE("%d items\n",nrofitems);
1339 while (nrofitems > 0)
1341 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1344 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1353 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1357 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1358 p += lstrlenW( (LPCWSTR)p ) + 1;
1362 /* check title text */
1369 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1373 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1374 p += lstrlenW( (LPCWSTR)p ) + 1;
1377 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1381 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1382 return (p - (WORD*)pTemplate)*sizeof(WORD);
1386 /******************************************************************************
1387 * PROPSHEET_CreatePage
1391 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1393 const PropSheetInfo * psInfo,
1394 LPCPROPSHEETPAGEW ppshpage)
1396 DLGTEMPLATE* pTemplate;
1399 PADDING_INFO padding;
1400 UINT pageWidth,pageHeight;
1404 TRACE("index %d\n", index);
1406 if (ppshpage == NULL)
1411 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1413 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1414 resSize = GetTemplateSize(pTemplate);
1416 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1421 hResource = FindResourceW(ppshpage->hInstance,
1422 ppshpage->u.pszTemplate,
1427 resSize = SizeofResource(ppshpage->hInstance, hResource);
1429 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1433 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1435 * Make a copy of the dialog template to make it writable
1443 hResource = FindResourceA(ppshpage->hInstance,
1444 (LPSTR)ppshpage->u.pszTemplate,
1449 resSize = SizeofResource(ppshpage->hInstance, hResource);
1451 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1455 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1457 * Make a copy of the dialog template to make it writable
1460 temp = Alloc(resSize);
1464 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1465 memcpy(temp, pTemplate, resSize);
1468 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1470 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1471 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1472 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1473 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1474 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1475 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1476 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1477 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1479 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1483 pTemplate->style |= WS_CHILD | DS_CONTROL;
1484 pTemplate->style &= ~DS_MODALFRAME;
1485 pTemplate->style &= ~WS_CAPTION;
1486 pTemplate->style &= ~WS_SYSMENU;
1487 pTemplate->style &= ~WS_POPUP;
1488 pTemplate->style &= ~WS_DISABLED;
1489 pTemplate->style &= ~WS_VISIBLE;
1490 pTemplate->style &= ~WS_THICKFRAME;
1492 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1495 if (psInfo->proppage[index].useCallback)
1496 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1497 (LPPROPSHEETPAGEW)ppshpage);
1499 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1500 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1503 ppshpage->pfnDlgProc,
1506 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1509 ppshpage->pfnDlgProc,
1511 /* Free a no more needed copy */
1515 psInfo->proppage[index].hwndPage = hwndPage;
1517 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1522 rc.left = psInfo->x;
1524 rc.right = psInfo->width;
1525 rc.bottom = psInfo->height;
1527 MapDialogRect(hwndParent, &rc);
1529 pageWidth = rc.right - rc.left;
1530 pageHeight = rc.bottom - rc.top;
1532 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1533 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d, padx=%d, pady=%d\n",
1534 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1535 pageWidth, pageHeight, padding.x, padding.y);
1537 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
1538 psInfo->ppshheader.dwFlags & PSH_HEADER)
1540 hwndChild = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1542 GetClientRect(hwndChild, &r);
1543 MapWindowPoints(hwndChild, hwndParent, (LPPOINT) &r, 2);
1544 offsety = (ppshpage->dwFlags & PSP_HIDEHEADER)?0:r.bottom + 1;
1547 SetWindowPos(hwndPage, HWND_TOP,
1548 rc.left + padding.x/2,
1549 rc.top + padding.y/2 + offsety,
1550 pageWidth, pageHeight - offsety, 0);
1554 * Ask the Tab control to reduce the client rectangle to that
1557 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1558 pageWidth = rc.right - rc.left;
1559 pageHeight = rc.bottom - rc.top;
1560 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d\n",
1561 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1562 pageWidth, pageHeight);
1563 SetWindowPos(hwndPage, HWND_TOP,
1565 pageWidth, pageHeight, 0);
1571 /******************************************************************************
1572 * PROPSHEET_LoadWizardBitmaps
1574 * Loads the watermark and header bitmaps for a wizard.
1576 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1578 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1580 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1581 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1582 considers hbmWatermark as valid. */
1583 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1584 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1586 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1587 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1590 /* Same behavior as for watermarks */
1591 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1592 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1594 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1595 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1601 /******************************************************************************
1602 * PROPSHEET_ShowPage
1604 * Displays or creates the specified page.
1606 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1609 HWND hwndLineHeader;
1610 LPCPROPSHEETPAGEW ppshpage;
1612 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1613 if (index == psInfo->active_page)
1615 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1616 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1620 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1621 if (psInfo->proppage[index].hwndPage == 0)
1623 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1626 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
1627 (ppshpage->dwFlags & PSP_USETITLE))
1629 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1630 psInfo->proppage[index].pszText);
1633 if (psInfo->active_page != -1)
1634 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1636 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1638 /* Synchronize current selection with tab control
1639 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1640 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1641 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1643 psInfo->active_page = index;
1644 psInfo->activeValid = TRUE;
1646 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1648 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1649 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1651 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1652 ShowWindow(hwndLineHeader, SW_HIDE);
1654 ShowWindow(hwndLineHeader, SW_SHOW);
1657 InvalidateRgn(hwndDlg, NULL, TRUE);
1658 UpdateWindow(hwndDlg);
1663 /******************************************************************************
1666 static BOOL PROPSHEET_Back(HWND hwndDlg)
1670 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1675 TRACE("active_page %d\n", psInfo->active_page);
1676 if (psInfo->active_page < 0)
1679 psn.hdr.code = PSN_WIZBACK;
1680 psn.hdr.hwndFrom = hwndDlg;
1684 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1686 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1689 else if (result == 0)
1690 idx = psInfo->active_page - 1;
1692 idx = PROPSHEET_FindPageByResId(psInfo, result);
1694 if (idx >= 0 && idx < psInfo->nPages)
1696 if (PROPSHEET_CanSetCurSel(hwndDlg))
1697 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1702 /******************************************************************************
1705 static BOOL PROPSHEET_Next(HWND hwndDlg)
1709 LRESULT msgResult = 0;
1710 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1714 TRACE("active_page %d\n", psInfo->active_page);
1715 if (psInfo->active_page < 0)
1718 psn.hdr.code = PSN_WIZNEXT;
1719 psn.hdr.hwndFrom = hwndDlg;
1723 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1725 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1726 if (msgResult == -1)
1728 else if (msgResult == 0)
1729 idx = psInfo->active_page + 1;
1731 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1733 if (idx < psInfo->nPages )
1735 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1736 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1742 /******************************************************************************
1745 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1749 LRESULT msgResult = 0;
1750 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1753 TRACE("active_page %d\n", psInfo->active_page);
1754 if (psInfo->active_page < 0)
1757 psn.hdr.code = PSN_WIZFINISH;
1758 psn.hdr.hwndFrom = hwndDlg;
1762 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1764 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1766 TRACE("msg result %ld\n", msgResult);
1771 if (psInfo->isModeless)
1772 psInfo->activeValid = FALSE;
1774 EndDialog(hwndDlg, TRUE);
1779 /******************************************************************************
1782 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1787 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1790 TRACE("active_page %d\n", psInfo->active_page);
1791 if (psInfo->active_page < 0)
1794 psn.hdr.hwndFrom = hwndDlg;
1800 * Send PSN_KILLACTIVE to the current page.
1802 psn.hdr.code = PSN_KILLACTIVE;
1804 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1806 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1810 * Send PSN_APPLY to all pages.
1812 psn.hdr.code = PSN_APPLY;
1813 psn.lParam = lParam;
1815 for (i = 0; i < psInfo->nPages; i++)
1817 hwndPage = psInfo->proppage[i].hwndPage;
1820 switch (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1822 case PSNRET_INVALID:
1823 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1825 case PSNRET_INVALID_NOCHANGEPAGE:
1833 psInfo->activeValid = FALSE;
1835 else if(psInfo->active_page >= 0)
1837 psn.hdr.code = PSN_SETACTIVE;
1839 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1840 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1846 /******************************************************************************
1849 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1851 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1857 TRACE("active_page %d\n", psInfo->active_page);
1858 if (psInfo->active_page < 0)
1861 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1862 psn.hdr.code = PSN_QUERYCANCEL;
1863 psn.hdr.hwndFrom = hwndDlg;
1867 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1870 psn.hdr.code = PSN_RESET;
1871 psn.lParam = lParam;
1873 for (i = 0; i < psInfo->nPages; i++)
1875 hwndPage = psInfo->proppage[i].hwndPage;
1878 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1881 if (psInfo->isModeless)
1883 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1884 psInfo->activeValid = FALSE;
1887 EndDialog(hwndDlg, FALSE);
1890 /******************************************************************************
1893 static void PROPSHEET_Help(HWND hwndDlg)
1895 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1900 TRACE("active_page %d\n", psInfo->active_page);
1901 if (psInfo->active_page < 0)
1904 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1905 psn.hdr.code = PSN_HELP;
1906 psn.hdr.hwndFrom = hwndDlg;
1910 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1913 /******************************************************************************
1916 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1919 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1923 if (!psInfo) return;
1925 * Set the dirty flag of this page.
1927 for (i = 0; i < psInfo->nPages; i++)
1929 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1930 psInfo->proppage[i].isDirty = TRUE;
1934 * Enable the Apply button.
1936 if (psInfo->hasApply)
1938 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1940 EnableWindow(hwndApplyBtn, TRUE);
1944 /******************************************************************************
1945 * PROPSHEET_UnChanged
1947 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1950 BOOL noPageDirty = TRUE;
1951 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1952 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1956 if ( !psInfo ) return;
1957 for (i = 0; i < psInfo->nPages; i++)
1959 /* set the specified page as clean */
1960 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1961 psInfo->proppage[i].isDirty = FALSE;
1963 /* look to see if there's any dirty pages */
1964 if (psInfo->proppage[i].isDirty)
1965 noPageDirty = FALSE;
1969 * Disable Apply button.
1972 EnableWindow(hwndApplyBtn, FALSE);
1975 /******************************************************************************
1976 * PROPSHEET_PressButton
1978 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1980 TRACE("buttonID %d\n", buttonID);
1983 case PSBTN_APPLYNOW:
1984 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1987 PROPSHEET_Back(hwndDlg);
1990 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1993 PROPSHEET_Finish(hwndDlg);
1996 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1999 PROPSHEET_Next(hwndDlg);
2002 PROPSHEET_DoCommand(hwndDlg, IDOK);
2005 FIXME("Invalid button index %d\n", buttonID);
2010 /*************************************************************************
2011 * BOOL PROPSHEET_CanSetCurSel [Internal]
2013 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
2016 * hwndDlg [I] handle to a Dialog hWnd
2019 * TRUE if Current Selection can change
2023 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2025 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2030 HWND hwndTabControl;
2033 TRACE("active_page %d\n", psInfo->active_page);
2040 if (psInfo->active_page < 0)
2047 * Notify the current page.
2049 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2050 psn.hdr.code = PSN_KILLACTIVE;
2051 psn.hdr.hwndFrom = hwndDlg;
2055 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2058 * Re-adjust the tab control's contents
2060 hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2061 memset( &rect, 0, sizeof rect );
2062 GetClientRect( hwndTabControl, &rect );
2063 SendMessageW( hwndTabControl, TCM_ADJUSTRECT, 0, (LPARAM) &rect );
2064 SetWindowPos( hwndPage, NULL, rect.left, rect.top,
2065 rect.right - rect.left, rect.bottom - rect.top, 0 );
2068 TRACE("<-- %d\n", res);
2072 /******************************************************************************
2073 * PROPSHEET_SetCurSel
2075 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2078 HPROPSHEETPAGE hpage
2081 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2082 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2083 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2085 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2086 /* hpage takes precedence over index */
2088 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2090 if (index < 0 || index >= psInfo->nPages)
2092 TRACE("Could not find page to select!\n");
2101 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2103 psn.hdr.code = PSN_SETACTIVE;
2104 psn.hdr.hwndFrom = hwndDlg;
2108 if (!psInfo->proppage[index].hwndPage) {
2109 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2110 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2113 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2120 WARN("Tried to skip before first property sheet page!\n");
2123 if (index >= psInfo->nPages) {
2124 WARN("Tried to skip after last property sheet page!\n");
2125 index = psInfo->nPages-1;
2129 else if (result != 0)
2131 int old_index = index;
2132 index = PROPSHEET_FindPageByResId(psInfo, result);
2133 if(index >= psInfo->nPages) {
2135 WARN("Tried to skip to nonexistant page by res id\n");
2142 * Display the new page.
2144 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2146 if (psInfo->proppage[index].hasHelp)
2147 EnableWindow(hwndHelp, TRUE);
2149 EnableWindow(hwndHelp, FALSE);
2154 /******************************************************************************
2155 * PROPSHEET_SetCurSelId
2157 * Selects the page, specified by resource id.
2159 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2162 PropSheetInfo* psInfo =
2163 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2165 idx = PROPSHEET_FindPageByResId(psInfo, id);
2166 if (idx < psInfo->nPages )
2168 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2169 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2173 /******************************************************************************
2174 * PROPSHEET_SetTitleA
2176 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2178 if(HIWORD(lpszText))
2181 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2182 szTitle, sizeof(szTitle));
2183 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2187 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2191 /******************************************************************************
2192 * PROPSHEET_SetTitleW
2194 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2196 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2199 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2200 if (HIWORD(lpszText) == 0) {
2201 if (!LoadStringW(psInfo->ppshheader.hInstance,
2202 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2206 if (dwStyle & PSH_PROPTITLE)
2209 int lentitle = strlenW(lpszText);
2210 int lenprop = strlenW(psInfo->strPropertiesFor);
2212 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2213 strcpyW(dest, psInfo->strPropertiesFor);
2214 strcatW(dest, lpszText);
2216 SetWindowTextW(hwndDlg, dest);
2220 SetWindowTextW(hwndDlg, lpszText);
2223 /******************************************************************************
2224 * PROPSHEET_SetFinishTextA
2226 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2228 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2230 TRACE("'%s'\n", lpszText);
2231 /* Set text, show and enable the Finish button */
2232 SetWindowTextA(hwndButton, lpszText);
2233 ShowWindow(hwndButton, SW_SHOW);
2234 EnableWindow(hwndButton, TRUE);
2236 /* Make it default pushbutton */
2237 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2239 /* Hide Back button */
2240 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2241 ShowWindow(hwndButton, SW_HIDE);
2243 /* Hide Next button */
2244 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2245 ShowWindow(hwndButton, SW_HIDE);
2248 /******************************************************************************
2249 * PROPSHEET_SetFinishTextW
2251 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2253 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2255 TRACE("'%s'\n", debugstr_w(lpszText));
2256 /* Set text, show and enable the Finish button */
2257 SetWindowTextW(hwndButton, lpszText);
2258 ShowWindow(hwndButton, SW_SHOW);
2259 EnableWindow(hwndButton, TRUE);
2261 /* Make it default pushbutton */
2262 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2264 /* Hide Back button */
2265 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2266 ShowWindow(hwndButton, SW_HIDE);
2268 /* Hide Next button */
2269 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2270 ShowWindow(hwndButton, SW_HIDE);
2273 /******************************************************************************
2274 * PROPSHEET_QuerySiblings
2276 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2277 WPARAM wParam, LPARAM lParam)
2281 LRESULT msgResult = 0;
2282 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2285 while ((i < psInfo->nPages) && (msgResult == 0))
2287 hwndPage = psInfo->proppage[i].hwndPage;
2288 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2296 /******************************************************************************
2299 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2300 HPROPSHEETPAGE hpage)
2302 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2304 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2306 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2308 TRACE("hpage %p\n", hpage);
2310 * Allocate and fill in a new PropPageInfo entry.
2312 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2313 sizeof(PropPageInfo) *
2314 (psInfo->nPages + 1));
2315 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2318 psInfo->proppage[psInfo->nPages].hpage = hpage;
2320 if (ppsp->dwFlags & PSP_PREMATURE)
2322 /* Create the page but don't show it */
2323 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2327 * Add a new tab to the tab control.
2329 item.mask = TCIF_TEXT;
2330 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2331 item.cchTextMax = MAX_TABTEXT_LENGTH;
2333 if (psInfo->hImageList)
2335 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2338 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2340 item.mask |= TCIF_IMAGE;
2341 item.iImage = psInfo->nPages;
2344 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2349 /* If it is the only page - show it */
2350 if(psInfo->nPages == 1)
2351 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2355 /******************************************************************************
2356 * PROPSHEET_RemovePage
2358 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2360 HPROPSHEETPAGE hpage)
2362 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2364 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2365 PropPageInfo* oldPages;
2367 TRACE("index %d, hpage %p\n", index, hpage);
2372 * hpage takes precedence over index.
2376 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2379 /* Make sure that index is within range */
2380 if (index < 0 || index >= psInfo->nPages)
2382 TRACE("Could not find page to remove!\n");
2386 TRACE("total pages %d removing page %d active page %d\n",
2387 psInfo->nPages, index, psInfo->active_page);
2389 * Check if we're removing the active page.
2391 if (index == psInfo->active_page)
2393 if (psInfo->nPages > 1)
2397 /* activate previous page */
2398 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2402 /* activate the next page */
2403 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2404 psInfo->active_page = index;
2409 psInfo->active_page = -1;
2410 if (!psInfo->isModeless)
2412 EndDialog(hwndDlg, FALSE);
2417 else if (index < psInfo->active_page)
2418 psInfo->active_page--;
2420 /* Destroy page dialog window */
2421 DestroyWindow(psInfo->proppage[index].hwndPage);
2423 /* Free page resources */
2424 if(psInfo->proppage[index].hpage)
2426 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2428 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2429 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2431 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2434 /* Remove the tab */
2435 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2437 oldPages = psInfo->proppage;
2439 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2442 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2444 if (index < psInfo->nPages)
2445 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2446 (psInfo->nPages - index) * sizeof(PropPageInfo));
2453 /******************************************************************************
2454 * PROPSHEET_SetWizButtons
2456 * This code will work if (and assumes that) the Next button is on top of the
2457 * Finish button. ie. Finish comes after Next in the Z order.
2458 * This means make sure the dialog template reflects this.
2461 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2463 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2464 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2465 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2467 TRACE("%ld\n", dwFlags);
2469 EnableWindow(hwndBack, FALSE);
2470 EnableWindow(hwndNext, FALSE);
2471 EnableWindow(hwndFinish, FALSE);
2473 if (dwFlags & PSWIZB_BACK)
2474 EnableWindow(hwndBack, TRUE);
2476 if (dwFlags & PSWIZB_NEXT)
2478 /* Hide the Finish button */
2479 ShowWindow(hwndFinish, SW_HIDE);
2481 /* Show and enable the Next button */
2482 ShowWindow(hwndNext, SW_SHOW);
2483 EnableWindow(hwndNext, TRUE);
2485 /* Set the Next button as the default pushbutton */
2486 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2489 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2491 /* Hide the Next button */
2492 ShowWindow(hwndNext, SW_HIDE);
2494 /* Show the Finish button */
2495 ShowWindow(hwndFinish, SW_SHOW);
2497 if (dwFlags & PSWIZB_FINISH)
2498 EnableWindow(hwndFinish, TRUE);
2500 /* Set the Finish button as the default pushbutton */
2501 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2505 /******************************************************************************
2506 * PROPSHEET_InsertPage
2508 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2510 if (!HIWORD(hpageInsertAfter))
2511 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2513 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2517 /******************************************************************************
2518 * PROPSHEET_SetHeaderTitleW
2520 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2522 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2525 /******************************************************************************
2526 * PROPSHEET_SetHeaderTitleA
2528 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2530 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2533 /******************************************************************************
2534 * PROPSHEET_SetHeaderSubTitleW
2536 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2538 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2541 /******************************************************************************
2542 * PROPSHEET_SetHeaderSubTitleA
2544 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2546 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2549 /******************************************************************************
2550 * PROPSHEET_HwndToIndex
2552 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2555 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2558 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2560 for (index = 0; index < psInfo->nPages; index++)
2561 if (psInfo->proppage[index].hwndPage == hPageDlg)
2563 WARN("%p not found\n", hPageDlg);
2567 /******************************************************************************
2568 * PROPSHEET_IndexToHwnd
2570 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2572 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2574 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2575 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2576 WARN("%d out of range.\n", iPageIndex);
2579 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2582 /******************************************************************************
2583 * PROPSHEET_PageToIndex
2585 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2587 FIXME("(%p, %p): stub\n", hwndDlg, hPage);
2591 /******************************************************************************
2592 * PROPSHEET_IndexToPage
2594 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2596 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2600 /******************************************************************************
2601 * PROPSHEET_IdToIndex
2603 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2605 FIXME("(%p, %d): stub\n", hwndDlg, iPageId);
2609 /******************************************************************************
2610 * PROPSHEET_IndexToId
2612 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2614 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2618 /******************************************************************************
2619 * PROPSHEET_GetResult
2621 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2623 FIXME("(%p): stub\n", hwndDlg);
2627 /******************************************************************************
2628 * PROPSHEET_RecalcPageSizes
2630 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2632 FIXME("(%p): stub\n", hwndDlg);
2636 /******************************************************************************
2637 * PROPSHEET_GetPageIndex
2639 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2640 * the array of PropPageInfo.
2642 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2647 TRACE("hpage %p\n", hpage);
2648 while ((index < psInfo->nPages) && (found == FALSE))
2650 if (psInfo->proppage[index].hpage == hpage)
2662 /******************************************************************************
2665 static void PROPSHEET_CleanUp(HWND hwndDlg)
2668 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2672 if (!psInfo) return;
2673 if (HIWORD(psInfo->ppshheader.pszCaption))
2674 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2676 for (i = 0; i < psInfo->nPages; i++)
2678 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2680 if(psInfo->proppage[i].hwndPage)
2681 DestroyWindow(psInfo->proppage[i].hwndPage);
2685 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2686 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2688 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2692 DeleteObject(psInfo->hFont);
2693 DeleteObject(psInfo->hFontBold);
2694 /* If we created the bitmaps, destroy them */
2695 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2696 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2697 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2698 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2699 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2700 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2702 Free(psInfo->proppage);
2703 Free(psInfo->strPropertiesFor);
2704 ImageList_Destroy(psInfo->hImageList);
2706 GlobalFree((HGLOBAL)psInfo);
2709 /******************************************************************************
2710 * PropertySheet (COMCTL32.@)
2711 * PropertySheetA (COMCTL32.@)
2713 * Creates a property sheet in the specified property sheet header.
2716 * Modal property sheets: Positive if successful or -1 otherwise.
2717 * Modeless property sheets: Property sheet handle.
2719 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2720 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2722 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2725 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2726 sizeof(PropSheetInfo));
2730 TRACE("(%p)\n", lppsh);
2732 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2734 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2736 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2738 for (n = i = 0; i < lppsh->nPages; i++, n++)
2740 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2741 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2744 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2745 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2748 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2751 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2752 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2758 psInfo->unicode = FALSE;
2759 bRet = PROPSHEET_CreateDialog(psInfo);
2764 /******************************************************************************
2765 * PropertySheetW (COMCTL32.@)
2767 * See PropertySheetA.
2769 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2772 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2773 sizeof(PropSheetInfo));
2777 TRACE("(%p)\n", lppsh);
2779 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2781 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2783 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2785 for (n = i = 0; i < lppsh->nPages; i++, n++)
2787 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2788 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2791 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2792 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2795 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2798 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2799 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2805 psInfo->unicode = TRUE;
2806 bRet = PROPSHEET_CreateDialog(psInfo);
2811 /******************************************************************************
2812 * CreatePropertySheetPage (COMCTL32.@)
2813 * CreatePropertySheetPageA (COMCTL32.@)
2815 * Creates a new property sheet page.
2818 * Success: Handle to new property sheet page.
2822 * An application must use the PSM_ADDPAGE message to add the new page to
2823 * an existing property sheet.
2825 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2826 LPCPROPSHEETPAGEA lpPropSheetPage)
2828 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2830 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2832 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2833 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2835 int len = strlen(lpPropSheetPage->u.pszTemplate);
2837 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,len+1 );
2838 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2840 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2842 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2845 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2847 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2849 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2850 ppsp->pszTitle = NULL;
2852 return (HPROPSHEETPAGE)ppsp;
2855 /******************************************************************************
2856 * CreatePropertySheetPageW (COMCTL32.@)
2858 * See CreatePropertySheetA.
2860 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2862 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2864 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2866 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2868 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2870 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2872 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2873 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2875 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2877 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2878 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2879 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2882 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2884 int len = strlenW(lpPropSheetPage->pszTitle);
2885 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2886 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2888 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2889 ppsp->pszTitle = NULL;
2891 return (HPROPSHEETPAGE)ppsp;
2894 /******************************************************************************
2895 * DestroyPropertySheetPage (COMCTL32.@)
2897 * Destroys a property sheet page previously created with
2898 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2905 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2907 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2912 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2913 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2915 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2916 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2918 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2919 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2926 /******************************************************************************
2927 * PROPSHEET_IsDialogMessage
2929 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2931 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2934 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2937 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2940 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2942 if (!(dlgCode & DLGC_WANTMESSAGE))
2944 switch (lpMsg->wParam)
2947 if (GetKeyState(VK_SHIFT) & 0x8000)
2953 case VK_NEXT: new_page = 1; break;
2954 case VK_PRIOR: new_page = -1; break;
2960 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2962 new_page += psInfo->active_page;
2965 new_page = psInfo->nPages - 1;
2966 else if (new_page >= psInfo->nPages)
2969 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2976 return IsDialogMessageA(hwnd, lpMsg);
2979 /******************************************************************************
2980 * PROPSHEET_DoCommand
2982 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2988 case IDC_APPLY_BUTTON:
2990 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2992 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2997 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3001 if (psInfo->restartWindows)
3002 result = ID_PSRESTARTWINDOWS;
3004 /* reboot system takes precedence over restart windows */
3005 if (psInfo->rebootSystem)
3006 result = ID_PSREBOOTSYSTEM;
3008 if (psInfo->isModeless)
3009 psInfo->activeValid = FALSE;
3011 EndDialog(hwnd, result);
3014 EnableWindow(hwndApplyBtn, FALSE);
3019 case IDC_BACK_BUTTON:
3020 PROPSHEET_Back(hwnd);
3023 case IDC_NEXT_BUTTON:
3024 PROPSHEET_Next(hwnd);
3027 case IDC_FINISH_BUTTON:
3028 PROPSHEET_Finish(hwnd);
3032 PROPSHEET_Cancel(hwnd, 0);
3036 PROPSHEET_Help(hwnd);
3046 /******************************************************************************
3049 static LRESULT PROPSHEET_Paint(HWND hwnd)
3051 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3056 HPALETTE hOldPal = 0;
3060 LPCPROPSHEETPAGEW ppshpage;
3061 WCHAR szBuffer[256];
3064 hdc = BeginPaint(hwnd, &ps);
3067 hdcSrc = CreateCompatibleDC(0);
3068 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3070 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3071 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3073 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3074 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3075 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3078 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3080 COLORREF clrOld = 0;
3083 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3084 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3086 GetClientRect(hwndLineHeader, &r);
3087 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3088 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3090 GetObjectA(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3092 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3094 /* Fill the unoccupied part of the header with color of the
3095 * left-top pixel, but do it only when needed.
3097 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3099 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3100 CopyRect(&r, &rzone);
3101 if (bm.bmWidth < r.right)
3103 r.left = bm.bmWidth;
3104 FillRect(hdc, &r, hbr);
3106 if (bm.bmHeight < r.bottom)
3109 r.top = bm.bmHeight;
3110 FillRect(hdc, &r, hbr);
3115 /* Draw the header itself. */
3117 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3118 hdcSrc, 0, 0, SRCCOPY);
3122 hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
3123 FillRect(hdc, &rzone, hbr);
3126 /* Draw the header bitmap. It's always centered like a
3127 * common 49 x 49 bitmap. */
3128 BitBlt(hdc, rzone.right - 49 - ((rzone.bottom - 49) / 2),
3129 (rzone.bottom - 49) / 2,
3130 bm.bmWidth, bm.bmHeight,
3131 hdcSrc, 0, 0, SRCCOPY);
3133 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3134 * if its height is smaller than 49 pixels. Because the reason
3135 * for this bug is unknown the current code doesn't try to
3139 clrOld = SetTextColor (hdc, 0x00000000);
3140 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3142 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3143 SetRect(&r, 20, 10, 0, 0);
3144 if (HIWORD(ppshpage->pszHeaderTitle))
3146 if (psInfo->unicode)
3147 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3148 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3150 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3151 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3155 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderTitle,
3159 DrawTextW(hdc, szBuffer, nLength,
3160 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3165 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3166 SelectObject(hdc, psInfo->hFont);
3167 SetRect(&r, 40, 25, 0, 0);
3168 if (HIWORD(ppshpage->pszHeaderTitle))
3170 if (psInfo->unicode)
3171 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3172 -1, &r, DT_LEFT | DT_SINGLELINE);
3174 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3175 -1, &r, DT_LEFT | DT_SINGLELINE);
3179 nLength = LoadStringW(ppshpage->hInstance, (UINT)ppshpage->pszHeaderSubTitle,
3183 DrawTextW(hdc, szBuffer, nLength,
3184 &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3189 offsety = rzone.bottom + 2;
3191 SetTextColor(hdc, clrOld);
3192 SetBkMode(hdc, oldBkMode);
3193 SelectObject(hdc, hOldFont);
3194 SelectObject(hdcSrc, hbmp);
3197 if ( ((psInfo->active_page == 0) || (psInfo->active_page == psInfo->nPages - 1)) &&
3198 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3199 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3201 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3203 GetClientRect(hwndLine, &r);
3204 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3206 GetObjectA(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3207 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3209 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3210 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3212 /* If the bitmap is not big enough, fill the remaining area
3213 with the color of pixel (0,0) of bitmap - see MSDN */
3214 if (r.top > bm.bmHeight) {
3215 r.bottom = r.top - 1;
3216 r.top = bm.bmHeight;
3218 r.right = bm.bmWidth;
3219 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3220 FillRect(hdc, &r, hbr);
3224 SelectObject(hdcSrc, hbmp);
3227 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3228 SelectPalette(hdc, hOldPal, FALSE);
3232 EndPaint(hwnd, &ps);
3237 /******************************************************************************
3238 * PROPSHEET_DialogProc
3241 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3243 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3244 hwnd, uMsg, wParam, lParam);
3250 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3251 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3252 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3253 LPCPROPSHEETPAGEW ppshpage;
3257 /* Using PropSheetInfoStr to store extra data doesn't match the native
3258 * common control: native uses TCM_[GS]ETITEM
3260 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3263 * psInfo->hwnd is not being used by WINE code - it exists
3264 * for compatibility with "real" Windoze. The same about
3265 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3268 psInfo->hwnd = hwnd;
3269 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3271 /* set up the Next and Back buttons by default */
3272 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3275 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3276 psInfo->hFont = CreateFontIndirectA (&logFont);
3277 logFont.lfWeight = FW_BOLD;
3278 psInfo->hFontBold = CreateFontIndirectA (&logFont);
3281 * Small icon in the title bar.
3283 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3284 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3287 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3288 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3290 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3291 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3292 psInfo->ppshheader.u.pszIcon,
3297 hIcon = psInfo->ppshheader.u.hIcon;
3299 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3302 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3303 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3305 psInfo->strPropertiesFor = strCaption;
3307 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3309 PROPSHEET_CreateTabControl(hwnd, psInfo);
3311 PROPSHEET_LoadWizardBitmaps(psInfo);
3313 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3315 ShowWindow(hwndTabCtrl, SW_HIDE);
3316 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
3318 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3319 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3324 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3326 PROPSHEET_AdjustSize(hwnd, psInfo);
3327 PROPSHEET_AdjustButtons(hwnd, psInfo);
3331 if (psInfo->useCallback)
3332 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3333 PSCB_INITIALIZED, (LPARAM)0);
3335 idx = psInfo->active_page;
3336 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3337 psInfo->active_page = -1;
3339 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3341 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3342 * as some programs call TCM_GETCURSEL to get the current selection
3343 * from which to switch to the next page */
3344 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3346 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3347 psInfo->ppshheader.hInstance)
3351 if (LoadStringW(psInfo->ppshheader.hInstance,
3352 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3353 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3357 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3358 psInfo->ppshheader.pszCaption);
3365 PROPSHEET_Paint(hwnd);
3369 PROPSHEET_CleanUp(hwnd);
3373 PROPSHEET_Cancel(hwnd, 1);
3377 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3379 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3381 /* No default handler, forward notification to active page */
3382 if (psInfo->activeValid && psInfo->active_page != -1)
3384 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3385 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3392 NMHDR* pnmh = (LPNMHDR) lParam;
3394 if (pnmh->code == TCN_SELCHANGE)
3396 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3397 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3400 if(pnmh->code == TCN_SELCHANGING)
3402 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3403 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3410 case PSM_GETCURRENTPAGEHWND:
3412 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3416 if (psInfo->activeValid && psInfo->active_page != -1)
3417 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3419 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3425 PROPSHEET_Changed(hwnd, (HWND)wParam);
3429 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3432 case PSM_GETTABCONTROL:
3434 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3436 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3445 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3446 if(msgResult != FALSE)
3448 msgResult = PROPSHEET_SetCurSel(hwnd,
3451 (HPROPSHEETPAGE)lParam);
3454 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3459 case PSM_CANCELTOCLOSE:
3461 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3462 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3463 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3465 EnableWindow(hwndCancel, FALSE);
3466 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3467 SetWindowTextW(hwndOK, buf);
3472 case PSM_RESTARTWINDOWS:
3474 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3477 psInfo->restartWindows = TRUE;
3481 case PSM_REBOOTSYSTEM:
3483 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3486 psInfo->rebootSystem = TRUE;
3491 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3495 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3500 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3502 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3507 case PSM_QUERYSIBLINGS:
3509 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3511 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3519 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3520 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3521 * on success or FALSE otherwise, as specified on MSDN Online.
3522 * Also see the MFC code for
3523 * CPropertySheet::AddPage(CPropertyPage* pPage).
3526 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3528 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3533 case PSM_REMOVEPAGE:
3534 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3537 case PSM_ISDIALOGMESSAGE:
3539 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3540 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3544 case PSM_PRESSBUTTON:
3545 PROPSHEET_PressButton(hwnd, (int)wParam);
3548 case PSM_SETFINISHTEXTA:
3549 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3552 case PSM_SETWIZBUTTONS:
3553 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3556 case PSM_SETCURSELID:
3557 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3560 case PSM_SETFINISHTEXTW:
3561 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3564 case PSM_INSERTPAGE:
3566 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3567 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3571 case PSM_SETHEADERTITLEW:
3572 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3575 case PSM_SETHEADERTITLEA:
3576 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3579 case PSM_SETHEADERSUBTITLEW:
3580 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3583 case PSM_SETHEADERSUBTITLEA:
3584 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3587 case PSM_HWNDTOINDEX:
3589 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3590 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3594 case PSM_INDEXTOHWND:
3596 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3597 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3601 case PSM_PAGETOINDEX:
3603 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3604 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3608 case PSM_INDEXTOPAGE:
3610 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3611 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3617 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3618 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3624 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3625 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3631 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3632 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);
3636 case PSM_RECALCPAGESIZES:
3638 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3639 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, msgResult);