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.
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);
949 * Position Cancel button.
951 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
953 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
955 SetWindowPos(hwndButton, 0, x, y, 0, 0,
956 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
959 * Position Apply button.
961 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
963 if (psInfo->hasApply)
966 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
968 x = rcSheet.right - (padding.x + buttonWidth);
970 SetWindowPos(hwndButton, 0, x, y, 0, 0,
971 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
973 EnableWindow(hwndButton, FALSE);
976 ShowWindow(hwndButton, SW_HIDE);
979 * Position Help button.
981 hwndButton = GetDlgItem(hwndParent, IDHELP);
985 x = rcSheet.right - (padding.x + buttonWidth);
987 SetWindowPos(hwndButton, 0, x, y, 0, 0,
988 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
991 ShowWindow(hwndButton, SW_HIDE);
996 /******************************************************************************
997 * PROPSHEET_AdjustButtonsWizard
999 * Adjusts the buttons' positions.
1001 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1002 PropSheetInfo* psInfo)
1004 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1005 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1006 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1009 int num_buttons = 3;
1010 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1011 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1013 if (psInfo->hasHelp)
1017 * Obtain the size of the buttons.
1019 GetClientRect(hwndButton, &rcSheet);
1020 buttonWidth = rcSheet.right;
1021 buttonHeight = rcSheet.bottom;
1023 GetClientRect(hwndLine, &rcSheet);
1024 lineHeight = rcSheet.bottom;
1027 * Get the size of the property sheet.
1029 GetClientRect(hwndParent, &rcSheet);
1032 * All buttons will be at this y coordinate.
1034 y = rcSheet.bottom - (padding.y + buttonHeight);
1037 * Position the Next and the Finish buttons.
1039 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1041 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1043 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1044 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1046 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1048 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1049 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1051 ShowWindow(hwndButton, SW_HIDE);
1054 * Position the Back button.
1056 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1060 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1061 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1064 * Position the Cancel button.
1066 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1068 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1070 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1071 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1074 * Position Help button.
1076 hwndButton = GetDlgItem(hwndParent, IDHELP);
1078 if (psInfo->hasHelp)
1080 x = rcSheet.right - (padding.x + buttonWidth);
1082 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1083 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1086 ShowWindow(hwndButton, SW_HIDE);
1088 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW))
1092 * Position and resize the sunken line.
1095 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1097 lineWidth = rcSheet.right - (padding.x * 2);
1099 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1100 SWP_NOZORDER | SWP_NOACTIVATE);
1103 * Position and resize the header sunken line.
1106 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1107 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1108 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1109 ShowWindow(hwndLineHeader, SW_HIDE);
1114 /******************************************************************************
1115 * PROPSHEET_GetPaddingInfo
1117 * Returns the layout information.
1119 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1121 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1124 PADDING_INFO padding;
1126 GetWindowRect(hwndTab, &rcTab);
1131 ScreenToClient(hwndDlg, &tl);
1139 /******************************************************************************
1140 * PROPSHEET_GetPaddingInfoWizard
1142 * Returns the layout information.
1143 * Vertical spacing is the distance between the line and the buttons.
1144 * Do NOT use the Help button to gather padding information when it isn't mapped
1145 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1146 * for it in this case !
1147 * FIXME: I'm not sure about any other coordinate problems with these evil
1148 * buttons. Fix it in case additional problems appear or maybe calculate
1149 * a padding in a completely different way, as this is somewhat messy.
1151 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1154 PADDING_INFO padding;
1158 POINT ptButton, ptLine;
1161 if (psInfo->hasHelp)
1167 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1169 idButton = IDC_NEXT_BUTTON;
1173 /* hopefully this is ok */
1174 idButton = IDCANCEL;
1178 hwndControl = GetDlgItem(hwndDlg, idButton);
1179 GetWindowRect(hwndControl, &rc);
1181 ptButton.x = rc.left;
1182 ptButton.y = rc.top;
1184 ScreenToClient(hwndDlg, &ptButton);
1187 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1188 GetWindowRect(hwndControl, &rc);
1191 ptLine.y = rc.bottom;
1193 ScreenToClient(hwndDlg, &ptLine);
1195 padding.y = ptButton.y - ptLine.y;
1198 ERR("padding negative ! Please report this !\n");
1200 /* this is most probably not correct, but the best we have now */
1201 padding.x = padding.y;
1205 /******************************************************************************
1206 * PROPSHEET_CreateTabControl
1208 * Insert the tabs in the tab control.
1210 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1211 PropSheetInfo * psInfo)
1213 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1219 item.mask = TCIF_TEXT;
1220 item.cchTextMax = MAX_TABTEXT_LENGTH;
1222 nTabs = psInfo->nPages;
1225 * Set the image list for icons.
1227 if (psInfo->hImageList)
1229 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1232 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1233 for (i = 0; i < nTabs; i++)
1235 if ( psInfo->proppage[i].hasIcon )
1237 item.mask |= TCIF_IMAGE;
1238 item.iImage = iImage++;
1242 item.mask &= ~TCIF_IMAGE;
1245 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1246 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1248 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1253 * Get the size of an in-memory Template
1255 *( Based on the code of PROPSHEET_CollectPageInfo)
1256 * See also dialog.c/DIALOG_ParseTemplate32().
1259 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1262 const WORD* p = (const WORD *)pTemplate;
1263 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1268 /* DLGTEMPLATEEX (not defined in any std. header file) */
1270 TRACE("is DLGTEMPLATEEX\n");
1272 p++; /* signature */
1273 p += 2; /* help ID */
1274 p += 2; /* ext style */
1281 TRACE("is DLGTEMPLATE\n");
1283 p += 2; /* ext style */
1286 nrofitems = (WORD)*p; p++; /* nb items */
1302 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1303 p += lstrlenW( (LPCWSTR)p ) + 1;
1314 p += 2; /* 0xffff plus predefined window class ordinal value */
1317 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1318 p += lstrlenW( (LPCWSTR)p ) + 1;
1323 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1324 p += lstrlenW((LPCWSTR)p) + 1;
1326 /* font, if DS_SETFONT set */
1327 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1330 p+=(istemplateex)?3:1;
1331 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1332 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1335 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1336 * that are following the DLGTEMPLATE(EX) data */
1337 TRACE("%d items\n",nrofitems);
1338 while (nrofitems > 0)
1340 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1343 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1352 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1356 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1357 p += lstrlenW( (LPCWSTR)p ) + 1;
1361 /* check title text */
1368 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1372 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1373 p += lstrlenW( (LPCWSTR)p ) + 1;
1376 p += *p + 1; /* Skip extra data */
1380 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1381 return (p - (WORD*)pTemplate)*sizeof(WORD);
1385 /******************************************************************************
1386 * PROPSHEET_CreatePage
1390 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1392 const PropSheetInfo * psInfo,
1393 LPCPROPSHEETPAGEW ppshpage)
1395 DLGTEMPLATE* pTemplate;
1398 PADDING_INFO padding;
1399 UINT pageWidth,pageHeight;
1403 TRACE("index %d\n", index);
1405 if (ppshpage == NULL)
1410 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1412 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1413 resSize = GetTemplateSize(pTemplate);
1415 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1420 hResource = FindResourceW(ppshpage->hInstance,
1421 ppshpage->u.pszTemplate,
1426 resSize = SizeofResource(ppshpage->hInstance, hResource);
1428 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1432 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1434 * Make a copy of the dialog template to make it writable
1442 hResource = FindResourceA(ppshpage->hInstance,
1443 (LPSTR)ppshpage->u.pszTemplate,
1448 resSize = SizeofResource(ppshpage->hInstance, hResource);
1450 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1454 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1456 * Make a copy of the dialog template to make it writable
1459 temp = Alloc(resSize);
1463 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1464 memcpy(temp, pTemplate, resSize);
1467 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1469 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1470 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1471 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1472 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1473 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1474 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1475 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1476 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1480 pTemplate->style |= WS_CHILD | DS_CONTROL;
1481 pTemplate->style &= ~DS_MODALFRAME;
1482 pTemplate->style &= ~WS_CAPTION;
1483 pTemplate->style &= ~WS_SYSMENU;
1484 pTemplate->style &= ~WS_POPUP;
1485 pTemplate->style &= ~WS_DISABLED;
1486 pTemplate->style &= ~WS_VISIBLE;
1487 pTemplate->style &= ~WS_THICKFRAME;
1490 if (psInfo->proppage[index].useCallback)
1491 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1492 (LPPROPSHEETPAGEW)ppshpage);
1494 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1495 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1498 ppshpage->pfnDlgProc,
1501 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1504 ppshpage->pfnDlgProc,
1506 /* Free a no more needed copy */
1510 psInfo->proppage[index].hwndPage = hwndPage;
1512 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1517 rc.left = psInfo->x;
1519 rc.right = psInfo->width;
1520 rc.bottom = psInfo->height;
1522 MapDialogRect(hwndParent, &rc);
1524 pageWidth = rc.right - rc.left;
1525 pageHeight = rc.bottom - rc.top;
1527 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1528 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d, padx=%d, pady=%d\n",
1529 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1530 pageWidth, pageHeight, padding.x, padding.y);
1532 /* If there is a watermark, offset the dialog items */
1533 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1534 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1535 ((index == 0) || (index == psInfo->nPages - 1)) )
1537 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1538 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1539 considers hbmWatermark as valid. */
1540 if (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1542 ((PropSheetInfo *)psInfo)->ppshheader.u4.hbmWatermark =
1543 CreateMappedBitmap(ppshpage->hInstance, (INT)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1547 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
1548 psInfo->ppshheader.dwFlags & PSH_HEADER)
1550 /* Same behavior as for watermarks */
1551 if (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1553 ((PropSheetInfo *)psInfo)->ppshheader.u5.hbmHeader =
1554 CreateMappedBitmap(ppshpage->hInstance, (INT)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1557 hwndChild = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
1559 GetClientRect(hwndChild, &r);
1560 MapWindowPoints(hwndChild, hwndParent, (LPPOINT) &r, 2);
1561 offsety = (ppshpage->dwFlags & PSP_HIDEHEADER)?0:r.bottom + 1;
1564 SetWindowPos(hwndPage, HWND_TOP,
1565 rc.left + padding.x/2,
1566 rc.top + padding.y/2 + offsety,
1567 pageWidth, pageHeight - offsety, 0);
1571 * Ask the Tab control to reduce the client rectangle to that
1574 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1575 pageWidth = rc.right - rc.left;
1576 pageHeight = rc.bottom - rc.top;
1577 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d\n",
1578 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1579 pageWidth, pageHeight);
1580 SetWindowPos(hwndPage, HWND_TOP,
1582 pageWidth, pageHeight, 0);
1588 /******************************************************************************
1589 * PROPSHEET_ShowPage
1591 * Displays or creates the specified page.
1593 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1596 HWND hwndLineHeader;
1597 LPCPROPSHEETPAGEW ppshpage;
1599 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1600 if (index == psInfo->active_page)
1602 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1603 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1607 if (psInfo->proppage[index].hwndPage == 0)
1609 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1610 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1613 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1614 psInfo->proppage[index].pszText);
1616 if (psInfo->active_page != -1)
1617 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1619 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1621 /* Synchronize current selection with tab control
1622 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1623 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1624 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1626 psInfo->active_page = index;
1627 psInfo->activeValid = TRUE;
1629 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1631 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1632 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1634 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1635 ShowWindow(hwndLineHeader, SW_HIDE);
1637 ShowWindow(hwndLineHeader, SW_SHOW);
1639 InvalidateRgn(hwndDlg, NULL, TRUE);
1640 UpdateWindow(hwndDlg);
1646 /******************************************************************************
1649 static BOOL PROPSHEET_Back(HWND hwndDlg)
1653 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1658 TRACE("active_page %d\n", psInfo->active_page);
1659 if (psInfo->active_page < 0)
1662 psn.hdr.code = PSN_WIZBACK;
1663 psn.hdr.hwndFrom = hwndDlg;
1667 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1669 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1672 else if (result == 0)
1673 idx = psInfo->active_page - 1;
1675 idx = PROPSHEET_FindPageByResId(psInfo, result);
1677 if (idx >= 0 && idx < psInfo->nPages)
1679 if (PROPSHEET_CanSetCurSel(hwndDlg))
1680 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1685 /******************************************************************************
1688 static BOOL PROPSHEET_Next(HWND hwndDlg)
1692 LRESULT msgResult = 0;
1693 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1697 TRACE("active_page %d\n", psInfo->active_page);
1698 if (psInfo->active_page < 0)
1701 psn.hdr.code = PSN_WIZNEXT;
1702 psn.hdr.hwndFrom = hwndDlg;
1706 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1708 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1709 if (msgResult == -1)
1711 else if (msgResult == 0)
1712 idx = psInfo->active_page + 1;
1714 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1716 if (idx < psInfo->nPages )
1718 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1719 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1725 /******************************************************************************
1728 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1732 LRESULT msgResult = 0;
1733 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1736 TRACE("active_page %d\n", psInfo->active_page);
1737 if (psInfo->active_page < 0)
1740 psn.hdr.code = PSN_WIZFINISH;
1741 psn.hdr.hwndFrom = hwndDlg;
1745 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1747 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1749 TRACE("msg result %ld\n", msgResult);
1754 if (psInfo->isModeless)
1755 psInfo->activeValid = FALSE;
1757 EndDialog(hwndDlg, TRUE);
1762 /******************************************************************************
1765 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1770 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1773 TRACE("active_page %d\n", psInfo->active_page);
1774 if (psInfo->active_page < 0)
1777 psn.hdr.hwndFrom = hwndDlg;
1783 * Send PSN_KILLACTIVE to the current page.
1785 psn.hdr.code = PSN_KILLACTIVE;
1787 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1789 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1793 * Send PSN_APPLY to all pages.
1795 psn.hdr.code = PSN_APPLY;
1796 psn.lParam = lParam;
1798 for (i = 0; i < psInfo->nPages; i++)
1800 hwndPage = psInfo->proppage[i].hwndPage;
1803 switch (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1805 case PSNRET_INVALID:
1806 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1808 case PSNRET_INVALID_NOCHANGEPAGE:
1816 psInfo->activeValid = FALSE;
1818 else if(psInfo->active_page >= 0)
1820 psn.hdr.code = PSN_SETACTIVE;
1822 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1823 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1829 /******************************************************************************
1832 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1834 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1840 TRACE("active_page %d\n", psInfo->active_page);
1841 if (psInfo->active_page < 0)
1844 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1845 psn.hdr.code = PSN_QUERYCANCEL;
1846 psn.hdr.hwndFrom = hwndDlg;
1850 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1853 psn.hdr.code = PSN_RESET;
1854 psn.lParam = lParam;
1856 for (i = 0; i < psInfo->nPages; i++)
1858 hwndPage = psInfo->proppage[i].hwndPage;
1861 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1864 if (psInfo->isModeless)
1866 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1867 psInfo->activeValid = FALSE;
1870 EndDialog(hwndDlg, FALSE);
1873 /******************************************************************************
1876 static void PROPSHEET_Help(HWND hwndDlg)
1878 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1883 TRACE("active_page %d\n", psInfo->active_page);
1884 if (psInfo->active_page < 0)
1887 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1888 psn.hdr.code = PSN_HELP;
1889 psn.hdr.hwndFrom = hwndDlg;
1893 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1896 /******************************************************************************
1899 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1902 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1906 if (!psInfo) return;
1908 * Set the dirty flag of this page.
1910 for (i = 0; i < psInfo->nPages; i++)
1912 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1913 psInfo->proppage[i].isDirty = TRUE;
1917 * Enable the Apply button.
1919 if (psInfo->hasApply)
1921 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1923 EnableWindow(hwndApplyBtn, TRUE);
1927 /******************************************************************************
1928 * PROPSHEET_UnChanged
1930 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1933 BOOL noPageDirty = TRUE;
1934 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1935 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1939 if ( !psInfo ) return;
1940 for (i = 0; i < psInfo->nPages; i++)
1942 /* set the specified page as clean */
1943 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1944 psInfo->proppage[i].isDirty = FALSE;
1946 /* look to see if there's any dirty pages */
1947 if (psInfo->proppage[i].isDirty)
1948 noPageDirty = FALSE;
1952 * Disable Apply button.
1955 EnableWindow(hwndApplyBtn, FALSE);
1958 /******************************************************************************
1959 * PROPSHEET_PressButton
1961 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1963 TRACE("buttonID %d\n", buttonID);
1966 case PSBTN_APPLYNOW:
1967 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1970 PROPSHEET_Back(hwndDlg);
1973 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1976 PROPSHEET_Finish(hwndDlg);
1979 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1982 PROPSHEET_Next(hwndDlg);
1985 PROPSHEET_DoCommand(hwndDlg, IDOK);
1988 FIXME("Invalid button index %d\n", buttonID);
1993 /*************************************************************************
1994 * BOOL PROPSHEET_CanSetCurSel [Internal]
1996 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1999 * hwndDlg [I] handle to a Dialog hWnd
2002 * TRUE if Current Selection can change
2006 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
2008 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2014 TRACE("active_page %d\n", psInfo->active_page);
2021 if (psInfo->active_page < 0)
2028 * Notify the current page.
2030 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2031 psn.hdr.code = PSN_KILLACTIVE;
2032 psn.hdr.hwndFrom = hwndDlg;
2036 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2039 TRACE("<-- %d\n", res);
2043 /******************************************************************************
2044 * PROPSHEET_SetCurSel
2046 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
2049 HPROPSHEETPAGE hpage
2052 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2053 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2054 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2056 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2057 /* hpage takes precedence over index */
2059 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2061 if (index < 0 || index >= psInfo->nPages)
2063 TRACE("Could not find page to select!\n");
2072 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2074 psn.hdr.code = PSN_SETACTIVE;
2075 psn.hdr.hwndFrom = hwndDlg;
2079 if (!psInfo->proppage[index].hwndPage) {
2080 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2081 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2084 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2091 WARN("Tried to skip before first property sheet page!\n");
2094 if (index >= psInfo->nPages) {
2095 WARN("Tried to skip after last property sheet page!\n");
2096 index = psInfo->nPages-1;
2100 else if (result != 0)
2102 int old_index = index;
2103 index = PROPSHEET_FindPageByResId(psInfo, result);
2104 if(index >= psInfo->nPages) {
2106 WARN("Tried to skip to nonexistant page by res id\n");
2113 * Display the new page.
2115 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2117 if (psInfo->proppage[index].hasHelp)
2118 EnableWindow(hwndHelp, TRUE);
2120 EnableWindow(hwndHelp, FALSE);
2125 /******************************************************************************
2126 * PROPSHEET_SetCurSelId
2128 * Selects the page, specified by resource id.
2130 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2133 PropSheetInfo* psInfo =
2134 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2136 idx = PROPSHEET_FindPageByResId(psInfo, id);
2137 if (idx < psInfo->nPages )
2139 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2140 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2144 /******************************************************************************
2145 * PROPSHEET_SetTitleA
2147 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2149 if(HIWORD(lpszText))
2152 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2153 szTitle, sizeof(szTitle));
2154 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2158 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2162 /******************************************************************************
2163 * PROPSHEET_SetTitleW
2165 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2167 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2170 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2171 if (HIWORD(lpszText) == 0) {
2172 if (!LoadStringW(psInfo->ppshheader.hInstance,
2173 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2177 if (dwStyle & PSH_PROPTITLE)
2180 int lentitle = strlenW(lpszText);
2181 int lenprop = strlenW(psInfo->strPropertiesFor);
2183 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2184 strcpyW(dest, psInfo->strPropertiesFor);
2185 strcatW(dest, lpszText);
2187 SetWindowTextW(hwndDlg, dest);
2191 SetWindowTextW(hwndDlg, lpszText);
2194 /******************************************************************************
2195 * PROPSHEET_SetFinishTextA
2197 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2199 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2201 TRACE("'%s'\n", lpszText);
2202 /* Set text, show and enable the Finish button */
2203 SetWindowTextA(hwndButton, lpszText);
2204 ShowWindow(hwndButton, SW_SHOW);
2205 EnableWindow(hwndButton, TRUE);
2207 /* Make it default pushbutton */
2208 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2210 /* Hide Back button */
2211 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2212 ShowWindow(hwndButton, SW_HIDE);
2214 /* Hide Next button */
2215 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2216 ShowWindow(hwndButton, SW_HIDE);
2219 /******************************************************************************
2220 * PROPSHEET_SetFinishTextW
2222 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2224 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2226 TRACE("'%s'\n", debugstr_w(lpszText));
2227 /* Set text, show and enable the Finish button */
2228 SetWindowTextW(hwndButton, lpszText);
2229 ShowWindow(hwndButton, SW_SHOW);
2230 EnableWindow(hwndButton, TRUE);
2232 /* Make it default pushbutton */
2233 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2235 /* Hide Back button */
2236 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2237 ShowWindow(hwndButton, SW_HIDE);
2239 /* Hide Next button */
2240 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2241 ShowWindow(hwndButton, SW_HIDE);
2244 /******************************************************************************
2245 * PROPSHEET_QuerySiblings
2247 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2248 WPARAM wParam, LPARAM lParam)
2252 LRESULT msgResult = 0;
2253 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2256 while ((i < psInfo->nPages) && (msgResult == 0))
2258 hwndPage = psInfo->proppage[i].hwndPage;
2259 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2267 /******************************************************************************
2270 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2271 HPROPSHEETPAGE hpage)
2273 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2275 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2277 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2279 TRACE("hpage %p\n", hpage);
2281 * Allocate and fill in a new PropPageInfo entry.
2283 psInfo->proppage = (PropPageInfo*) ReAlloc(psInfo->proppage,
2284 sizeof(PropPageInfo) *
2285 (psInfo->nPages + 1));
2286 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2289 psInfo->proppage[psInfo->nPages].hpage = hpage;
2291 if (ppsp->dwFlags & PSP_PREMATURE)
2293 /* Create the page but don't show it */
2294 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2298 * Add a new tab to the tab control.
2300 item.mask = TCIF_TEXT;
2301 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2302 item.cchTextMax = MAX_TABTEXT_LENGTH;
2304 if (psInfo->hImageList)
2306 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2309 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2311 item.mask |= TCIF_IMAGE;
2312 item.iImage = psInfo->nPages;
2315 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2320 /* If it is the only page - show it */
2321 if(psInfo->nPages == 1)
2322 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2326 /******************************************************************************
2327 * PROPSHEET_RemovePage
2329 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2331 HPROPSHEETPAGE hpage)
2333 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2335 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2336 PropPageInfo* oldPages;
2338 TRACE("index %d, hpage %p\n", index, hpage);
2343 * hpage takes precedence over index.
2347 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2350 /* Make sure that index is within range */
2351 if (index < 0 || index >= psInfo->nPages)
2353 TRACE("Could not find page to remove!\n");
2357 TRACE("total pages %d removing page %d active page %d\n",
2358 psInfo->nPages, index, psInfo->active_page);
2360 * Check if we're removing the active page.
2362 if (index == psInfo->active_page)
2364 if (psInfo->nPages > 1)
2368 /* activate previous page */
2369 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2373 /* activate the next page */
2374 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2375 psInfo->active_page = index;
2380 psInfo->active_page = -1;
2381 if (!psInfo->isModeless)
2383 EndDialog(hwndDlg, FALSE);
2388 else if (index < psInfo->active_page)
2389 psInfo->active_page--;
2391 /* Destroy page dialog window */
2392 DestroyWindow(psInfo->proppage[index].hwndPage);
2394 /* Free page resources */
2395 if(psInfo->proppage[index].hpage)
2397 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2399 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2400 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2402 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2405 /* Remove the tab */
2406 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2408 oldPages = psInfo->proppage;
2410 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2413 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2415 if (index < psInfo->nPages)
2416 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2417 (psInfo->nPages - index) * sizeof(PropPageInfo));
2424 /******************************************************************************
2425 * PROPSHEET_SetWizButtons
2427 * This code will work if (and assumes that) the Next button is on top of the
2428 * Finish button. ie. Finish comes after Next in the Z order.
2429 * This means make sure the dialog template reflects this.
2432 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2434 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2435 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2436 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2438 TRACE("%ld\n", dwFlags);
2440 EnableWindow(hwndBack, FALSE);
2441 EnableWindow(hwndNext, FALSE);
2442 EnableWindow(hwndFinish, FALSE);
2444 if (dwFlags & PSWIZB_BACK)
2445 EnableWindow(hwndBack, TRUE);
2447 if (dwFlags & PSWIZB_NEXT)
2449 /* Hide the Finish button */
2450 ShowWindow(hwndFinish, SW_HIDE);
2452 /* Show and enable the Next button */
2453 ShowWindow(hwndNext, SW_SHOW);
2454 EnableWindow(hwndNext, TRUE);
2456 /* Set the Next button as the default pushbutton */
2457 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2460 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2462 /* Hide the Next button */
2463 ShowWindow(hwndNext, SW_HIDE);
2465 /* Show the Finish button */
2466 ShowWindow(hwndFinish, SW_SHOW);
2468 if (dwFlags & PSWIZB_FINISH)
2469 EnableWindow(hwndFinish, TRUE);
2471 /* Set the Finish button as the default pushbutton */
2472 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2476 /******************************************************************************
2477 * PROPSHEET_InsertPage
2479 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2481 if (!HIWORD(hpageInsertAfter))
2482 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2484 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2488 /******************************************************************************
2489 * PROPSHEET_SetHeaderTitleW
2491 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2493 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2496 /******************************************************************************
2497 * PROPSHEET_SetHeaderTitleA
2499 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2501 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2504 /******************************************************************************
2505 * PROPSHEET_SetHeaderSubTitleW
2507 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2509 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2512 /******************************************************************************
2513 * PROPSHEET_SetHeaderSubTitleA
2515 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2517 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2520 /******************************************************************************
2521 * PROPSHEET_HwndToIndex
2523 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2526 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2529 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2531 for (index = 0; index < psInfo->nPages; index++)
2532 if (psInfo->proppage[index].hwndPage == hPageDlg)
2534 WARN("%p not found\n", hPageDlg);
2538 /******************************************************************************
2539 * PROPSHEET_IndexToHwnd
2541 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2543 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2545 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2546 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2547 WARN("%d out of range.\n", iPageIndex);
2550 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2553 /******************************************************************************
2554 * PROPSHEET_PageToIndex
2556 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2558 FIXME("(%p, %p): stub\n", hwndDlg, hPage);
2562 /******************************************************************************
2563 * PROPSHEET_IndexToPage
2565 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2567 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2571 /******************************************************************************
2572 * PROPSHEET_IdToIndex
2574 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2576 FIXME("(%p, %d): stub\n", hwndDlg, iPageId);
2580 /******************************************************************************
2581 * PROPSHEET_IndexToId
2583 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2585 FIXME("(%p, %d): stub\n", hwndDlg, iPageIndex);
2589 /******************************************************************************
2590 * PROPSHEET_GetResult
2592 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2594 FIXME("(%p): stub\n", hwndDlg);
2598 /******************************************************************************
2599 * PROPSHEET_RecalcPageSizes
2601 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2603 FIXME("(%p): stub\n", hwndDlg);
2607 /******************************************************************************
2608 * PROPSHEET_GetPageIndex
2610 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2611 * the array of PropPageInfo.
2613 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2618 TRACE("hpage %p\n", hpage);
2619 while ((index < psInfo->nPages) && (found == FALSE))
2621 if (psInfo->proppage[index].hpage == hpage)
2633 /******************************************************************************
2636 static void PROPSHEET_CleanUp(HWND hwndDlg)
2639 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2643 if (!psInfo) return;
2644 if (HIWORD(psInfo->ppshheader.pszCaption))
2645 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2647 for (i = 0; i < psInfo->nPages; i++)
2649 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2651 if(psInfo->proppage[i].hwndPage)
2652 DestroyWindow(psInfo->proppage[i].hwndPage);
2656 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2657 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2659 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2663 DeleteObject(psInfo->hFont);
2664 DeleteObject(psInfo->hFontBold);
2665 /* If we created the bitmaps, destroy them */
2666 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2667 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2668 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2669 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2670 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2671 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2673 Free(psInfo->proppage);
2674 Free(psInfo->strPropertiesFor);
2675 ImageList_Destroy(psInfo->hImageList);
2677 GlobalFree((HGLOBAL)psInfo);
2680 /******************************************************************************
2681 * PropertySheet (COMCTL32.@)
2682 * PropertySheetA (COMCTL32.@)
2684 * Creates a property sheet in the specified property sheet header.
2687 * Modal property sheets: Positive if successful or -1 otherwise.
2688 * Modeless property sheets: Property sheet handle.
2690 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2691 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2693 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2696 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2697 sizeof(PropSheetInfo));
2701 TRACE("(%p)\n", lppsh);
2703 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2705 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2707 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2709 for (n = i = 0; i < lppsh->nPages; i++, n++)
2711 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2712 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2715 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2716 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2719 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2722 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2723 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2729 psInfo->unicode = FALSE;
2730 bRet = PROPSHEET_CreateDialog(psInfo);
2735 /******************************************************************************
2736 * PropertySheetW (COMCTL32.@)
2738 * See PropertySheetA.
2740 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2743 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2744 sizeof(PropSheetInfo));
2748 TRACE("(%p)\n", lppsh);
2750 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2752 psInfo->proppage = (PropPageInfo*) Alloc(sizeof(PropPageInfo) *
2754 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2756 for (n = i = 0; i < lppsh->nPages; i++, n++)
2758 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2759 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2762 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2763 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2766 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2769 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2770 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2776 psInfo->unicode = TRUE;
2777 bRet = PROPSHEET_CreateDialog(psInfo);
2782 /******************************************************************************
2783 * CreatePropertySheetPage (COMCTL32.@)
2784 * CreatePropertySheetPageA (COMCTL32.@)
2786 * Creates a new property sheet page.
2789 * Success: Handle to new property sheet page.
2793 * An application must use the PSM_ADDPAGE message to add the new page to
2794 * an existing property sheet.
2796 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2797 LPCPROPSHEETPAGEA lpPropSheetPage)
2799 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2801 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2803 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2804 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2806 int len = strlen(lpPropSheetPage->u.pszTemplate);
2808 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,len+1 );
2809 strcpy( (LPSTR)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2811 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2813 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2816 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2818 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2820 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2821 ppsp->pszTitle = NULL;
2823 return (HPROPSHEETPAGE)ppsp;
2826 /******************************************************************************
2827 * CreatePropertySheetPageW (COMCTL32.@)
2829 * See CreatePropertySheetA.
2831 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2833 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2835 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2837 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
2839 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2841 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2843 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2844 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2846 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2848 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2849 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2850 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2853 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2855 int len = strlenW(lpPropSheetPage->pszTitle);
2856 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2857 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2859 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2860 ppsp->pszTitle = NULL;
2862 return (HPROPSHEETPAGE)ppsp;
2865 /******************************************************************************
2866 * DestroyPropertySheetPage (COMCTL32.@)
2868 * Destroys a property sheet page previously created with
2869 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
2876 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2878 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2883 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2884 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2886 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2887 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2889 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2890 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2897 /******************************************************************************
2898 * PROPSHEET_IsDialogMessage
2900 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2902 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2905 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2908 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2911 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2913 if (!(dlgCode & DLGC_WANTMESSAGE))
2915 switch (lpMsg->wParam)
2918 if (GetKeyState(VK_SHIFT) & 0x8000)
2924 case VK_NEXT: new_page = 1; break;
2925 case VK_PRIOR: new_page = -1; break;
2931 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2933 new_page += psInfo->active_page;
2936 new_page = psInfo->nPages - 1;
2937 else if (new_page >= psInfo->nPages)
2940 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2947 return IsDialogMessageA(hwnd, lpMsg);
2950 /******************************************************************************
2951 * PROPSHEET_DoCommand
2953 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2959 case IDC_APPLY_BUTTON:
2961 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2963 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2968 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2972 if (psInfo->restartWindows)
2973 result = ID_PSRESTARTWINDOWS;
2975 /* reboot system takes precedence over restart windows */
2976 if (psInfo->rebootSystem)
2977 result = ID_PSREBOOTSYSTEM;
2979 if (psInfo->isModeless)
2980 psInfo->activeValid = FALSE;
2982 EndDialog(hwnd, result);
2985 EnableWindow(hwndApplyBtn, FALSE);
2990 case IDC_BACK_BUTTON:
2991 PROPSHEET_Back(hwnd);
2994 case IDC_NEXT_BUTTON:
2995 PROPSHEET_Next(hwnd);
2998 case IDC_FINISH_BUTTON:
2999 PROPSHEET_Finish(hwnd);
3003 PROPSHEET_Cancel(hwnd, 0);
3007 PROPSHEET_Help(hwnd);
3017 /******************************************************************************
3020 static LRESULT PROPSHEET_Paint(HWND hwnd)
3022 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3027 HPALETTE hOldPal = 0;
3031 LPCPROPSHEETPAGEW ppshpage;
3033 hdc = BeginPaint(hwnd, &ps);
3036 hdcSrc = CreateCompatibleDC(0);
3037 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3039 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3040 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3042 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3043 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3044 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3047 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3049 COLORREF clrOld = 0;
3052 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3053 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3055 GetClientRect(hwndLineHeader, &r);
3056 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3057 SetRect(&rzone, 0, 0, r.right, r.top - 1);
3058 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3059 FillRect(hdc, &rzone, hbr);
3062 GetObjectA(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), (LPVOID)&bm);
3064 clrOld = SetTextColor (hdc, 0x00000000);
3065 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3067 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3068 SetRect(&r, 20, 10, rzone.right - bm.bmWidth, 18);
3069 if (psInfo->unicode)
3070 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderTitle,
3071 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3073 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderTitle,
3074 -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3077 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3078 SelectObject(hdc, psInfo->hFont);
3079 SetRect(&r, 40, 25, rzone.right - bm.bmWidth, 43);
3080 if (psInfo->unicode)
3081 DrawTextW(hdc, (LPWSTR)ppshpage->pszHeaderSubTitle,
3082 -1, &r, DT_LEFT | DT_SINGLELINE);
3084 DrawTextA(hdc, (LPCSTR)ppshpage->pszHeaderSubTitle,
3085 -1, &r, DT_LEFT | DT_SINGLELINE);
3088 BitBlt(hdc, rzone.right - bm.bmWidth, (rzone.bottom - bm.bmHeight)/2,
3089 bm.bmWidth, bm.bmHeight,
3090 hdcSrc, 0, 0, SRCCOPY);
3091 offsety = rzone.bottom + 2;
3093 SetTextColor(hdc, clrOld);
3094 SetBkMode(hdc, oldBkMode);
3095 SelectObject(hdc, hOldFont);
3096 SelectObject(hdcSrc, hbmp);
3099 if ( ((psInfo->active_page == 0) || (psInfo->active_page == psInfo->nPages - 1)) &&
3100 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3101 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3103 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3105 GetClientRect(hwndLine, &r);
3106 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3108 GetObjectA(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), (LPVOID)&bm);
3109 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3111 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3112 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3114 /* If the bitmap is not big enough, fill the remaining area
3115 with the color of pixel (0,0) of bitmap - see MSDN */
3116 if (r.top > bm.bmHeight) {
3117 r.bottom = r.top - 1;
3118 r.top = bm.bmHeight;
3120 r.right = bm.bmWidth;
3121 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3122 FillRect(hdc, &r, hbr);
3126 SelectObject(hdcSrc, hbmp);
3129 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3130 SelectPalette(hdc, hOldPal, FALSE);
3134 EndPaint(hwnd, &ps);
3139 /******************************************************************************
3140 * PROPSHEET_DialogProc
3143 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3145 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
3146 hwnd, uMsg, wParam, lParam);
3152 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3153 WCHAR* strCaption = (WCHAR*)Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3154 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3155 LPCPROPSHEETPAGEW ppshpage;
3159 /* Using PropSheetInfoStr to store extra data doesn't match the native
3160 * common control: native uses TCM_[GS]ETITEM
3162 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
3165 * psInfo->hwnd is not being used by WINE code - it exists
3166 * for compatibility with "real" Windoze. The same about
3167 * SetWindowLong - WINE is only using the PropSheetInfoStr
3170 psInfo->hwnd = hwnd;
3171 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
3173 /* set up the Next and Back buttons by default */
3174 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3177 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3178 psInfo->hFont = CreateFontIndirectA (&logFont);
3179 logFont.lfWeight = FW_BOLD;
3180 psInfo->hFontBold = CreateFontIndirectA (&logFont);
3183 * Small icon in the title bar.
3185 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3186 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3189 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3190 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3192 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3193 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3194 psInfo->ppshheader.u.pszIcon,
3199 hIcon = psInfo->ppshheader.u.hIcon;
3201 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3204 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3205 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3207 psInfo->strPropertiesFor = strCaption;
3209 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3211 PROPSHEET_CreateTabControl(hwnd, psInfo);
3213 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3215 ShowWindow(hwndTabCtrl, SW_HIDE);
3216 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
3218 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3219 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3224 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3226 PROPSHEET_AdjustSize(hwnd, psInfo);
3227 PROPSHEET_AdjustButtons(hwnd, psInfo);
3231 if (psInfo->useCallback)
3232 (*(psInfo->ppshheader.pfnCallback))(hwnd,
3233 PSCB_INITIALIZED, (LPARAM)0);
3235 idx = psInfo->active_page;
3236 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
3237 psInfo->active_page = -1;
3239 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3241 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3242 * as some programs call TCM_GETCURSEL to get the current selection
3243 * from which to switch to the next page */
3244 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3246 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3247 psInfo->ppshheader.hInstance)
3251 if (LoadStringW(psInfo->ppshheader.hInstance,
3252 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
3253 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3257 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3258 psInfo->ppshheader.pszCaption);
3265 PROPSHEET_Paint(hwnd);
3269 PROPSHEET_CleanUp(hwnd);
3273 PROPSHEET_Cancel(hwnd, 1);
3277 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3279 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
3281 /* No default handler, forward notification to active page */
3282 if (psInfo->activeValid && psInfo->active_page != -1)
3284 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3285 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3292 NMHDR* pnmh = (LPNMHDR) lParam;
3294 if (pnmh->code == TCN_SELCHANGE)
3296 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3297 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3300 if(pnmh->code == TCN_SELCHANGING)
3302 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3303 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
3310 case PSM_GETCURRENTPAGEHWND:
3312 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3316 if (psInfo->activeValid && psInfo->active_page != -1)
3317 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3319 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndPage);
3325 PROPSHEET_Changed(hwnd, (HWND)wParam);
3329 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3332 case PSM_GETTABCONTROL:
3334 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3336 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndTabCtrl);
3345 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3346 if(msgResult != FALSE)
3348 msgResult = PROPSHEET_SetCurSel(hwnd,
3351 (HPROPSHEETPAGE)lParam);
3354 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3359 case PSM_CANCELTOCLOSE:
3361 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
3362 HWND hwndOK = GetDlgItem(hwnd, IDOK);
3363 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
3365 EnableWindow(hwndCancel, FALSE);
3366 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
3367 SetWindowTextW(hwndOK, buf);
3372 case PSM_RESTARTWINDOWS:
3374 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3377 psInfo->restartWindows = TRUE;
3381 case PSM_REBOOTSYSTEM:
3383 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
3386 psInfo->rebootSystem = TRUE;
3391 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
3395 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
3400 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
3402 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3407 case PSM_QUERYSIBLINGS:
3409 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
3411 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3419 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
3420 * a return value. This is not true. PSM_ADDPAGE returns TRUE
3421 * on success or FALSE otherwise, as specified on MSDN Online.
3422 * Also see the MFC code for
3423 * CPropertySheet::AddPage(CPropertyPage* pPage).
3426 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
3428 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3433 case PSM_REMOVEPAGE:
3434 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
3437 case PSM_ISDIALOGMESSAGE:
3439 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
3440 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
3444 case PSM_PRESSBUTTON:
3445 PROPSHEET_PressButton(hwnd, (int)wParam);
3448 case PSM_SETFINISHTEXTA:
3449 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
3452 case PSM_SETWIZBUTTONS:
3453 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
3456 case PSM_SETCURSELID:
3457 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
3460 case PSM_SETFINISHTEXTW:
3461 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
3464 case PSM_INSERTPAGE:
3466 BOOL msgResult = PROPSHEET_InsertPage(hwnd, (HPROPSHEETPAGE)wParam, (HPROPSHEETPAGE)lParam);
3467 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3471 case PSM_SETHEADERTITLEW:
3472 PROPSHEET_SetHeaderTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3475 case PSM_SETHEADERTITLEA:
3476 PROPSHEET_SetHeaderTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3479 case PSM_SETHEADERSUBTITLEW:
3480 PROPSHEET_SetHeaderSubTitleW(hwnd, (int)wParam, (LPCWSTR)lParam);
3483 case PSM_SETHEADERSUBTITLEA:
3484 PROPSHEET_SetHeaderSubTitleA(hwnd, (int)wParam, (LPCSTR)lParam);
3487 case PSM_HWNDTOINDEX:
3489 LRESULT msgResult = PROPSHEET_HwndToIndex(hwnd, (HWND)wParam);
3490 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3494 case PSM_INDEXTOHWND:
3496 LRESULT msgResult = PROPSHEET_IndexToHwnd(hwnd, (int)wParam);
3497 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3501 case PSM_PAGETOINDEX:
3503 LRESULT msgResult = PROPSHEET_PageToIndex(hwnd, (HPROPSHEETPAGE)wParam);
3504 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3508 case PSM_INDEXTOPAGE:
3510 LRESULT msgResult = PROPSHEET_IndexToPage(hwnd, (int)wParam);
3511 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3517 LRESULT msgResult = PROPSHEET_IdToIndex(hwnd, (int)lParam);
3518 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3524 LRESULT msgResult = PROPSHEET_IndexToId(hwnd, (int)wParam);
3525 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3531 LRESULT msgResult = PROPSHEET_GetResult(hwnd);
3532 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
3536 case PSM_RECALCPAGESIZES:
3538 LRESULT msgResult = PROPSHEET_RecalcPageSizes(hwnd);
3539 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);