4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * - Unicode property sheets
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
39 /******************************************************************************
63 } MyDLGITEMTEMPLATEEX;
66 typedef struct tagPropPageInfo
68 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
77 typedef struct tagPropSheetInfo
80 PROPSHEETHEADERW ppshheader;
81 LPWSTR strPropertiesFor;
91 PropPageInfo* proppage;
96 HIMAGELIST hImageList;
105 /******************************************************************************
106 * Defines and global variables
109 const WCHAR PropSheetInfoStr[] =
110 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
112 #define MAX_CAPTION_LENGTH 255
113 #define MAX_TABTEXT_LENGTH 255
114 #define MAX_BUTTONTEXT_LENGTH 64
116 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
118 /******************************************************************************
121 static int PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
122 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
123 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
124 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
125 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
126 PropSheetInfo * psInfo);
127 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
128 PropSheetInfo * psInfo);
129 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
130 PropSheetInfo * psInfo,
132 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
133 PropSheetInfo * psInfo);
134 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
135 const PropSheetInfo * psInfo,
136 LPCPROPSHEETPAGEW ppshpage);
137 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
138 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
139 static BOOL PROPSHEET_Back(HWND hwndDlg);
140 static BOOL PROPSHEET_Next(HWND hwndDlg);
141 static BOOL PROPSHEET_Finish(HWND hwndDlg);
142 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
143 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
144 static void PROPSHEET_Help(HWND hwndDlg);
145 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
146 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
147 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
148 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
149 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
150 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
151 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
152 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
153 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
156 HPROPSHEETPAGE hpage);
157 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
158 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
159 WPARAM wParam, LPARAM lParam);
160 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
161 HPROPSHEETPAGE hpage);
163 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
165 HPROPSHEETPAGE hpage);
166 static void PROPSHEET_CleanUp();
167 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
168 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
169 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
170 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
171 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
176 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
178 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
179 /******************************************************************************
180 * PROPSHEET_UnImplementedFlags
182 * Document use of flags we don't implement yet.
184 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
191 * unhandled header flags:
192 * PSH_DEFAULT 0x00000000
193 * PSH_WIZARDHASFINISH 0x00000010
194 * PSH_RTLREADING 0x00000800
195 * PSH_WIZARDCONTEXTHELP 0x00001000
196 * PSH_WIZARD97 0x00002000 (pre IE 5)
197 * PSH_WATERMARK 0x00008000
198 * PSH_USEHBMWATERMARK 0x00010000
199 * PSH_USEHPLWATERMARK 0x00020000
200 * PSH_STRETCHWATERMARK 0x00040000
201 * PSH_HEADER 0x00080000
202 * PSH_USEHBMHEADER 0x00100000
203 * PSH_USEPAGELANG 0x00200000
204 * PSH_WIZARD_LITE 0x00400000 also not in .h
205 * PSH_WIZARD97 0x01000000 (IE 5 and above)
206 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
209 add_flag(PSH_WIZARDHASFINISH);
210 add_flag(PSH_RTLREADING);
211 add_flag(PSH_WIZARDCONTEXTHELP);
212 add_flag(PSH_WIZARD97_OLD);
213 add_flag(PSH_WATERMARK);
214 add_flag(PSH_USEHBMWATERMARK);
215 add_flag(PSH_USEHPLWATERMARK);
216 add_flag(PSH_STRETCHWATERMARK);
217 add_flag(PSH_HEADER);
218 add_flag(PSH_USEHBMHEADER);
219 add_flag(PSH_USEPAGELANG);
220 add_flag(PSH_WIZARD_LITE);
221 add_flag(PSH_WIZARD97_NEW);
222 add_flag(PSH_NOCONTEXTHELP);
223 if (string[0] != '\0')
224 FIXME("%s\n", string);
228 /******************************************************************************
229 * PROPSHEET_GetPageRect
231 * Retrieve rect from tab control and map into the dialog for SetWindowPos
233 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
235 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
237 GetClientRect(hwndTabCtrl, rc);
238 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
239 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
242 /******************************************************************************
243 * PROPSHEET_FindPageByResId
245 * Find page index corresponding to page resource id.
247 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
251 for (i = 0; i < psInfo->nPages; i++)
253 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
255 /* Fixme: if resource ID is a string shall we use strcmp ??? */
256 if (lppsp->u.pszTemplate == (LPVOID)resId)
263 /******************************************************************************
266 * Convert ASCII to Unicode since all data is saved as Unicode.
268 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
272 TRACE("<%s>\n", frstr);
273 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
274 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
275 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
278 /******************************************************************************
279 * PROPSHEET_CollectSheetInfoA
281 * Collect relevant data.
283 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
284 PropSheetInfo * psInfo)
286 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
287 DWORD dwFlags = lppsh->dwFlags;
289 psInfo->hasHelp = dwFlags & PSH_HASHELP;
290 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
291 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
292 psInfo->isModeless = dwFlags & PSH_MODELESS;
294 memcpy(&psInfo->ppshheader,lppsh,dwSize);
295 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",
296 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
297 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
299 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
301 if (HIWORD(lppsh->pszCaption))
303 int len = strlen(lppsh->pszCaption);
304 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
305 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
306 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
308 psInfo->nPages = lppsh->nPages;
310 if (dwFlags & PSH_USEPSTARTPAGE)
312 TRACE("PSH_USEPSTARTPAGE is on");
313 psInfo->active_page = 0;
316 psInfo->active_page = lppsh->u2.nStartPage;
318 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
319 psInfo->active_page = 0;
321 psInfo->restartWindows = FALSE;
322 psInfo->rebootSystem = FALSE;
323 psInfo->hImageList = 0;
324 psInfo->activeValid = FALSE;
329 /******************************************************************************
330 * PROPSHEET_CollectSheetInfoW
332 * Collect relevant data.
334 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
335 PropSheetInfo * psInfo)
337 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
338 DWORD dwFlags = lppsh->dwFlags;
340 psInfo->hasHelp = dwFlags & PSH_HASHELP;
341 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
342 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
343 psInfo->isModeless = dwFlags & PSH_MODELESS;
345 memcpy(&psInfo->ppshheader,lppsh,dwSize);
346 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",
347 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
349 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
351 if (HIWORD(lppsh->pszCaption))
353 int len = strlenW(lppsh->pszCaption);
354 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
355 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
357 psInfo->nPages = lppsh->nPages;
359 if (dwFlags & PSH_USEPSTARTPAGE)
361 TRACE("PSH_USEPSTARTPAGE is on");
362 psInfo->active_page = 0;
365 psInfo->active_page = lppsh->u2.nStartPage;
367 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
368 psInfo->active_page = 0;
370 psInfo->restartWindows = FALSE;
371 psInfo->rebootSystem = FALSE;
372 psInfo->hImageList = 0;
373 psInfo->activeValid = FALSE;
378 /******************************************************************************
379 * PROPSHEET_CollectPageInfo
381 * Collect property sheet data.
382 * With code taken from DIALOG_ParseTemplate32.
384 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
385 PropSheetInfo * psInfo,
388 DLGTEMPLATE* pTemplate;
394 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
395 psInfo->proppage[index].hwndPage = 0;
396 psInfo->proppage[index].isDirty = FALSE;
399 * Process property page flags.
401 dwFlags = lppsp->dwFlags;
402 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
403 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
404 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
406 /* as soon as we have a page with the help flag, set the sheet flag on */
407 if (psInfo->proppage[index].hasHelp)
408 psInfo->hasHelp = TRUE;
411 * Process page template.
413 if (dwFlags & PSP_DLGINDIRECT)
414 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
417 HRSRC hResource = FindResourceW(lppsp->hInstance,
418 lppsp->u.pszTemplate,
420 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
422 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
426 * Extract the size of the page and the caption.
431 p = (const WORD *)pTemplate;
433 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
435 /* DLGTEMPLATEEX (not defined in any std. header file) */
439 p += 2; /* help ID */
440 p += 2; /* ext style */
448 p += 2; /* ext style */
454 width = (WORD)*p; p++;
455 height = (WORD)*p; p++;
457 /* remember the largest width and height */
458 if (width > psInfo->width)
459 psInfo->width = width;
461 if (height > psInfo->height)
462 psInfo->height = height;
474 p += lstrlenW( (LPCWSTR)p ) + 1;
488 p += lstrlenW( (LPCWSTR)p ) + 1;
492 /* Extract the caption */
493 psInfo->proppage[index].pszText = (LPCWSTR)p;
494 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
495 p += lstrlenW((LPCWSTR)p) + 1;
497 if (dwFlags & PSP_USETITLE)
501 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
504 if ( !HIWORD( lppsp->pszTitle ) )
506 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
509 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
515 pTitle = lppsp->pszTitle;
517 len = strlenW(pTitle);
518 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
519 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
523 * Build the image list for icons
525 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
528 int icon_cx = GetSystemMetrics(SM_CXSMICON);
529 int icon_cy = GetSystemMetrics(SM_CYSMICON);
531 if (dwFlags & PSP_USEICONID)
532 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
533 icon_cx, icon_cy, LR_DEFAULTCOLOR);
535 hIcon = lppsp->u2.hIcon;
539 if (psInfo->hImageList == 0 )
540 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
542 ImageList_AddIcon(psInfo->hImageList, hIcon);
550 /******************************************************************************
551 * PROPSHEET_CreateDialog
553 * Creates the actual property sheet.
555 int PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
562 WORD resID = IDD_PROPSHEET;
565 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
568 if(!(hRes = FindResourceW(COMCTL32_hModule,
569 MAKEINTRESOURCEW(resID),
573 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
577 * Make a copy of the dialog template.
579 resSize = SizeofResource(COMCTL32_hModule, hRes);
581 temp = COMCTL32_Alloc(resSize);
586 memcpy(temp, template, resSize);
588 if (psInfo->useCallback)
589 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
591 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
592 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
593 (LPDLGTEMPLATEW) temp,
594 psInfo->ppshheader.hwndParent,
595 PROPSHEET_DialogProc,
599 ret = (int)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
600 (LPDLGTEMPLATEW) temp,
601 psInfo->ppshheader.hwndParent,
602 PROPSHEET_DialogProc,
604 if ( !ret ) ret = -1;
612 /******************************************************************************
613 * PROPSHEET_SizeMismatch
615 * Verify that the tab control and the "largest" property sheet page dlg. template
618 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
620 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
621 RECT rcOrigTab, rcPage;
626 GetClientRect(hwndTabCtrl, &rcOrigTab);
627 TRACE("orig tab %ld %ld %ld %ld\n", rcOrigTab.left, rcOrigTab.top,
628 rcOrigTab.right, rcOrigTab.bottom);
633 rcPage.left = psInfo->x;
634 rcPage.top = psInfo->y;
635 rcPage.right = psInfo->width;
636 rcPage.bottom = psInfo->height;
638 MapDialogRect(hwndDlg, &rcPage);
639 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
640 rcPage.right, rcPage.bottom);
642 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
644 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
650 /******************************************************************************
651 * PROPSHEET_IsTooSmallWizard
653 * Verify that the default property sheet is big enough.
655 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
657 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
658 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
659 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
661 GetClientRect(hwndDlg, &rcSheetClient);
662 GetWindowRect(hwndDlg, &rcSheetRect);
663 GetWindowRect(hwndLine, &rcLine);
665 /* Remove the space below the sunken line */
666 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
668 /* Remove the buffer zone all around the edge */
669 rcSheetClient.bottom -= (padding.y * 2);
670 rcSheetClient.right -= (padding.x * 2);
675 rcPage.left = psInfo->x;
676 rcPage.top = psInfo->y;
677 rcPage.right = psInfo->width;
678 rcPage.bottom = psInfo->height;
680 MapDialogRect(hwndDlg, &rcPage);
681 TRACE("biggest page %ld %ld %ld %ld\n", rcPage.left, rcPage.top,
682 rcPage.right, rcPage.bottom);
684 if (rcPage.right > rcSheetClient.right)
687 if (rcPage.bottom > rcSheetClient.bottom)
693 /******************************************************************************
694 * PROPSHEET_AdjustSize
696 * Resizes the property sheet and the tab control to fit the largest page.
698 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
700 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
701 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
703 int tabOffsetX, tabOffsetY, buttonHeight;
704 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
707 /* Get the height of buttons */
708 GetClientRect(hwndButton, &rc);
709 buttonHeight = rc.bottom;
716 rc.right = psInfo->width;
717 rc.bottom = psInfo->height;
719 MapDialogRect(hwndDlg, &rc);
721 /* retrieve the dialog units */
722 units.left = units.right = 4;
723 units.top = units.bottom = 8;
724 MapDialogRect(hwndDlg, &units);
727 * Resize the tab control.
729 GetClientRect(hwndTabCtrl,&tabRect);
731 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
733 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
735 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
736 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
739 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
741 rc.right = rc.left + tabRect.right - tabRect.left;
742 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
745 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
747 tabOffsetX = -(rc.left);
748 tabOffsetY = -(rc.top);
752 TRACE("setting tab %08lx, rc (0,0)-(%ld,%ld)\n",
753 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
754 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
755 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
757 GetClientRect(hwndTabCtrl, &rc);
759 TRACE("tab client rc %ld %ld %ld %ld\n",
760 rc.left, rc.top, rc.right, rc.bottom);
762 rc.right += ((padding.x * 2) + tabOffsetX);
763 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
766 * Resize the property sheet.
768 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
769 (DWORD)hwndDlg, rc.right, rc.bottom);
770 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
771 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
775 /******************************************************************************
776 * PROPSHEET_AdjustSizeWizard
778 * Resizes the property sheet to fit the largest page.
780 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
782 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
783 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
784 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
786 int buttonHeight, lineHeight;
787 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
790 /* Get the height of buttons */
791 GetClientRect(hwndButton, &rc);
792 buttonHeight = rc.bottom;
794 GetClientRect(hwndLine, &rc);
795 lineHeight = rc.bottom;
797 /* retrieve the dialog units */
798 units.left = units.right = 4;
799 units.top = units.bottom = 8;
800 MapDialogRect(hwndDlg, &units);
807 rc.right = psInfo->width;
808 rc.bottom = psInfo->height;
810 MapDialogRect(hwndDlg, &rc);
812 GetClientRect(hwndTabCtrl,&tabRect);
814 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
816 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
817 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
820 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
822 rc.right = rc.left + tabRect.right - tabRect.left;
823 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
826 TRACE("Biggest page %ld %ld %ld %ld\n", rc.left, rc.top, rc.right, rc.bottom);
827 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
828 padding.x, padding.y, buttonHeight, lineHeight);
831 rc.right += (padding.x * 2);
832 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
835 * Resize the property sheet.
837 TRACE("setting dialog %08lx, rc (0,0)-(%ld,%ld)\n",
838 (DWORD)hwndDlg, rc.right, rc.bottom);
839 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
840 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
844 /******************************************************************************
845 * PROPSHEET_AdjustButtons
847 * Adjusts the buttons' positions.
849 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
851 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
855 int buttonWidth, buttonHeight;
856 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
858 if (psInfo->hasApply)
865 * Obtain the size of the buttons.
867 GetClientRect(hwndButton, &rcSheet);
868 buttonWidth = rcSheet.right;
869 buttonHeight = rcSheet.bottom;
872 * Get the size of the property sheet.
874 GetClientRect(hwndParent, &rcSheet);
877 * All buttons will be at this y coordinate.
879 y = rcSheet.bottom - (padding.y + buttonHeight);
882 * Position OK button.
884 hwndButton = GetDlgItem(hwndParent, IDOK);
886 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
888 SetWindowPos(hwndButton, 0, x, y, 0, 0,
889 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
892 * Position Cancel button.
894 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
896 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
898 SetWindowPos(hwndButton, 0, x, y, 0, 0,
899 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
902 * Position Apply button.
904 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
906 if (psInfo->hasApply)
909 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
911 x = rcSheet.right - (padding.x + buttonWidth);
913 SetWindowPos(hwndButton, 0, x, y, 0, 0,
914 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
916 EnableWindow(hwndButton, FALSE);
919 ShowWindow(hwndButton, SW_HIDE);
922 * Position Help button.
924 hwndButton = GetDlgItem(hwndParent, IDHELP);
928 x = rcSheet.right - (padding.x + buttonWidth);
930 SetWindowPos(hwndButton, 0, x, y, 0, 0,
931 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
934 ShowWindow(hwndButton, SW_HIDE);
939 /******************************************************************************
940 * PROPSHEET_AdjustButtonsWizard
942 * Adjusts the buttons' positions.
944 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
945 PropSheetInfo* psInfo)
947 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
948 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
952 int buttonWidth, buttonHeight, lineHeight, lineWidth;
953 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
959 * Obtain the size of the buttons.
961 GetClientRect(hwndButton, &rcSheet);
962 buttonWidth = rcSheet.right;
963 buttonHeight = rcSheet.bottom;
965 GetClientRect(hwndLine, &rcSheet);
966 lineHeight = rcSheet.bottom;
969 * Get the size of the property sheet.
971 GetClientRect(hwndParent, &rcSheet);
974 * All buttons will be at this y coordinate.
976 y = rcSheet.bottom - (padding.y + buttonHeight);
979 * Position the Next and the Finish buttons.
981 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
983 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
985 SetWindowPos(hwndButton, 0, x, y, 0, 0,
986 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
988 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
993 ShowWindow(hwndButton, SW_HIDE);
996 * Position the Back button.
998 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1002 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1003 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1006 * Position the Cancel button.
1008 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1010 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1012 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1013 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1016 * Position Help button.
1018 hwndButton = GetDlgItem(hwndParent, IDHELP);
1020 if (psInfo->hasHelp)
1022 x = rcSheet.right - (padding.x + buttonWidth);
1024 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1025 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1028 ShowWindow(hwndButton, SW_HIDE);
1031 * Position and resize the sunken line.
1034 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1036 GetClientRect(hwndParent, &rcSheet);
1037 lineWidth = rcSheet.right - (padding.x * 2);
1039 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1040 SWP_NOZORDER | SWP_NOACTIVATE);
1045 /******************************************************************************
1046 * PROPSHEET_GetPaddingInfo
1048 * Returns the layout information.
1050 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1052 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1055 PADDING_INFO padding;
1057 GetWindowRect(hwndTab, &rcTab);
1062 ScreenToClient(hwndDlg, &tl);
1070 /******************************************************************************
1071 * PROPSHEET_GetPaddingInfoWizard
1073 * Returns the layout information.
1074 * Vertical spacing is the distance between the line and the buttons.
1075 * Do NOT use the Help button to gather padding information when it isn't mapped
1076 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1077 * for it in this case !
1078 * FIXME: I'm not sure about any other coordinate problems with these evil
1079 * buttons. Fix it in case additional problems appear or maybe calculate
1080 * a padding in a completely different way, as this is somewhat messy.
1082 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1085 PADDING_INFO padding;
1089 POINT ptButton, ptLine;
1092 if (psInfo->hasHelp)
1098 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1100 idButton = IDC_NEXT_BUTTON;
1104 /* hopefully this is ok */
1105 idButton = IDCANCEL;
1109 hwndControl = GetDlgItem(hwndDlg, idButton);
1110 GetWindowRect(hwndControl, &rc);
1112 ptButton.x = rc.left;
1113 ptButton.y = rc.top;
1115 ScreenToClient(hwndDlg, &ptButton);
1118 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1119 GetWindowRect(hwndControl, &rc);
1122 ptLine.y = rc.bottom;
1124 ScreenToClient(hwndDlg, &ptLine);
1126 padding.y = ptButton.y - ptLine.y;
1129 ERR("padding negative ! Please report this !\n");
1131 /* this is most probably not correct, but the best we have now */
1132 padding.x = padding.y;
1136 /******************************************************************************
1137 * PROPSHEET_CreateTabControl
1139 * Insert the tabs in the tab control.
1141 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1142 PropSheetInfo * psInfo)
1144 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1150 item.mask = TCIF_TEXT;
1151 item.cchTextMax = MAX_TABTEXT_LENGTH;
1153 nTabs = psInfo->nPages;
1156 * Set the image list for icons.
1158 if (psInfo->hImageList)
1160 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1163 for (i = 0; i < nTabs; i++)
1165 if ( psInfo->proppage[i].hasIcon )
1167 item.mask |= TCIF_IMAGE;
1168 item.iImage = iImage++;
1172 item.mask &= ~TCIF_IMAGE;
1175 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1176 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1182 * Get the size of an in-memory Template
1184 *( Based on the code of PROPSHEET_CollectPageInfo)
1185 * See also dialog.c/DIALOG_ParseTemplate32().
1188 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1191 const WORD* p = (const WORD *)pTemplate;
1192 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1197 /* DLGTEMPLATEEX (not defined in any std. header file) */
1199 TRACE("is DLGTEMPLATEEX\n");
1201 p++; /* signature */
1202 p += 2; /* help ID */
1203 p += 2; /* ext style */
1210 TRACE("is DLGTEMPLATE\n");
1212 p += 2; /* ext style */
1215 nrofitems = (WORD)*p; p++; /* nb items */
1231 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1232 p += lstrlenW( (LPCWSTR)p ) + 1;
1243 p += 2; /* 0xffff plus predefined window class ordinal value */
1246 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1247 p += lstrlenW( (LPCWSTR)p ) + 1;
1252 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1253 p += lstrlenW((LPCWSTR)p) + 1;
1255 /* font, if DS_SETFONT set */
1256 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1259 p+=(istemplateex)?3:1;
1260 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1261 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name */
1264 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1265 * that are following the DLGTEMPLATE(EX) data */
1266 TRACE("%d items\n",nrofitems);
1267 while (nrofitems > 0)
1269 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1272 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1281 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1285 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1286 p += lstrlenW( (LPCWSTR)p ) + 1;
1290 /* check title text */
1297 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1301 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1302 p += lstrlenW( (LPCWSTR)p ) + 1;
1305 p += *p + 1; /* Skip extra data */
1309 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1310 return (p - (WORD*)pTemplate)*sizeof(WORD);
1314 /******************************************************************************
1315 * PROPSHEET_CreatePage
1319 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1321 const PropSheetInfo * psInfo,
1322 LPCPROPSHEETPAGEW ppshpage)
1324 DLGTEMPLATE* pTemplate;
1327 PropPageInfo* ppInfo = psInfo->proppage;
1328 PADDING_INFO padding;
1329 UINT pageWidth,pageHeight;
1333 TRACE("index %d\n", index);
1335 if (ppshpage == NULL)
1340 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1342 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1343 resSize = GetTemplateSize(pTemplate);
1350 hResource = FindResourceW(ppshpage->hInstance,
1351 ppshpage->u.pszTemplate,
1356 resSize = SizeofResource(ppshpage->hInstance, hResource);
1358 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1362 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1364 * Make a copy of the dialog template to make it writable
1367 temp = COMCTL32_Alloc(resSize);
1371 TRACE("copying pTemplate %p into temp %p (%ld)\n", pTemplate, temp, resSize);
1372 memcpy(temp, pTemplate, resSize);
1375 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1377 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1378 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1379 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1380 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1381 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1382 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1383 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1384 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1388 pTemplate->style |= WS_CHILD | DS_CONTROL;
1389 pTemplate->style &= ~DS_MODALFRAME;
1390 pTemplate->style &= ~WS_CAPTION;
1391 pTemplate->style &= ~WS_SYSMENU;
1392 pTemplate->style &= ~WS_POPUP;
1393 pTemplate->style &= ~WS_DISABLED;
1394 pTemplate->style &= ~WS_VISIBLE;
1395 pTemplate->style &= ~WS_THICKFRAME;
1398 if (psInfo->proppage[index].useCallback)
1399 (*(ppshpage->pfnCallback))(hwndParent,
1401 (LPPROPSHEETPAGEW)ppshpage);
1403 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1406 ppshpage->pfnDlgProc,
1408 /* Free a no more needed copy */
1410 COMCTL32_Free(temp);
1412 ppInfo[index].hwndPage = hwndPage;
1414 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1415 /* FIXME: This code may no longer be correct.
1416 * It was not for the non-wizard path. (GLA 6/02)
1418 rc.left = psInfo->x;
1420 rc.right = psInfo->width;
1421 rc.bottom = psInfo->height;
1423 MapDialogRect(hwndParent, &rc);
1425 pageWidth = rc.right - rc.left;
1426 pageHeight = rc.bottom - rc.top;
1428 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1429 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d, padx=%d, pady=%d\n",
1430 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1431 pageWidth, pageHeight, padding.x, padding.y);
1432 SetWindowPos(hwndPage, HWND_TOP,
1433 rc.left + padding.x/2,
1434 rc.top + padding.y/2,
1435 pageWidth, pageHeight, 0);
1439 * Ask the Tab control to reduce the client rectangle to that
1442 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1443 pageWidth = rc.right - rc.left;
1444 pageHeight = rc.bottom - rc.top;
1445 TRACE("setting page %08lx, rc (%ld,%ld)-(%ld,%ld) w=%d, h=%d\n",
1446 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1447 pageWidth, pageHeight);
1448 SetWindowPos(hwndPage, HWND_TOP,
1450 pageWidth, pageHeight, 0);
1456 /******************************************************************************
1457 * PROPSHEET_ShowPage
1459 * Displays or creates the specified page.
1461 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1465 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1466 if (index == psInfo->active_page)
1468 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1469 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1473 if (psInfo->proppage[index].hwndPage == 0)
1475 LPCPROPSHEETPAGEW ppshpage;
1477 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1478 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1481 if (psInfo->active_page != -1)
1482 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1484 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1486 /* Synchronize current selection with tab control
1487 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1488 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1489 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1491 psInfo->active_page = index;
1492 psInfo->activeValid = TRUE;
1497 /******************************************************************************
1500 static BOOL PROPSHEET_Back(HWND hwndDlg)
1504 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1509 TRACE("active_page %d\n", psInfo->active_page);
1510 if (psInfo->active_page < 0)
1513 psn.hdr.code = PSN_WIZBACK;
1514 psn.hdr.hwndFrom = hwndDlg;
1518 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1520 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1523 else if (result == 0)
1524 idx = psInfo->active_page - 1;
1526 idx = PROPSHEET_FindPageByResId(psInfo, result);
1528 if (idx >= 0 && idx < psInfo->nPages)
1530 if (PROPSHEET_CanSetCurSel(hwndDlg))
1531 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1536 /******************************************************************************
1539 static BOOL PROPSHEET_Next(HWND hwndDlg)
1543 LRESULT msgResult = 0;
1544 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1548 TRACE("active_page %d\n", psInfo->active_page);
1549 if (psInfo->active_page < 0)
1552 psn.hdr.code = PSN_WIZNEXT;
1553 psn.hdr.hwndFrom = hwndDlg;
1557 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1559 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1560 if (msgResult == -1)
1562 else if (msgResult == 0)
1563 idx = psInfo->active_page + 1;
1565 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1567 if (idx < psInfo->nPages )
1569 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1570 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1576 /******************************************************************************
1579 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1583 LRESULT msgResult = 0;
1584 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1587 TRACE("active_page %d\n", psInfo->active_page);
1588 if (psInfo->active_page < 0)
1591 psn.hdr.code = PSN_WIZFINISH;
1592 psn.hdr.hwndFrom = hwndDlg;
1596 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1598 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1600 TRACE("msg result %ld\n", msgResult);
1605 if (psInfo->isModeless)
1606 psInfo->activeValid = FALSE;
1608 EndDialog(hwndDlg, TRUE);
1613 /******************************************************************************
1616 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1621 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1624 TRACE("active_page %d\n", psInfo->active_page);
1625 if (psInfo->active_page < 0)
1628 psn.hdr.hwndFrom = hwndDlg;
1634 * Send PSN_KILLACTIVE to the current page.
1636 psn.hdr.code = PSN_KILLACTIVE;
1638 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1640 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1644 * Send PSN_APPLY to all pages.
1646 psn.hdr.code = PSN_APPLY;
1647 psn.lParam = lParam;
1649 for (i = 0; i < psInfo->nPages; i++)
1651 hwndPage = psInfo->proppage[i].hwndPage;
1654 switch (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1656 case PSNRET_INVALID:
1657 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1659 case PSNRET_INVALID_NOCHANGEPAGE:
1667 psInfo->activeValid = FALSE;
1669 else if(psInfo->active_page >= 0)
1671 psn.hdr.code = PSN_SETACTIVE;
1673 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1674 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1680 /******************************************************************************
1683 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1685 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1691 TRACE("active_page %d\n", psInfo->active_page);
1692 if (psInfo->active_page < 0)
1695 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1696 psn.hdr.code = PSN_QUERYCANCEL;
1697 psn.hdr.hwndFrom = hwndDlg;
1701 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1704 psn.hdr.code = PSN_RESET;
1705 psn.lParam = lParam;
1707 for (i = 0; i < psInfo->nPages; i++)
1709 hwndPage = psInfo->proppage[i].hwndPage;
1712 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1715 if (psInfo->isModeless)
1717 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1718 psInfo->activeValid = FALSE;
1721 EndDialog(hwndDlg, FALSE);
1724 /******************************************************************************
1727 static void PROPSHEET_Help(HWND hwndDlg)
1729 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1734 TRACE("active_page %d\n", psInfo->active_page);
1735 if (psInfo->active_page < 0)
1738 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1739 psn.hdr.code = PSN_HELP;
1740 psn.hdr.hwndFrom = hwndDlg;
1744 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1747 /******************************************************************************
1750 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1753 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1757 if (!psInfo) return;
1759 * Set the dirty flag of this page.
1761 for (i = 0; i < psInfo->nPages; i++)
1763 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1764 psInfo->proppage[i].isDirty = TRUE;
1768 * Enable the Apply button.
1770 if (psInfo->hasApply)
1772 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1774 EnableWindow(hwndApplyBtn, TRUE);
1778 /******************************************************************************
1779 * PROPSHEET_UnChanged
1781 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1784 BOOL noPageDirty = TRUE;
1785 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1786 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1790 if ( !psInfo ) return;
1791 for (i = 0; i < psInfo->nPages; i++)
1793 /* set the specified page as clean */
1794 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1795 psInfo->proppage[i].isDirty = FALSE;
1797 /* look to see if there's any dirty pages */
1798 if (psInfo->proppage[i].isDirty)
1799 noPageDirty = FALSE;
1803 * Disable Apply button.
1806 EnableWindow(hwndApplyBtn, FALSE);
1809 /******************************************************************************
1810 * PROPSHEET_PressButton
1812 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1814 TRACE("buttonID %d\n", buttonID);
1817 case PSBTN_APPLYNOW:
1818 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1821 PROPSHEET_Back(hwndDlg);
1824 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1827 PROPSHEET_Finish(hwndDlg);
1830 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1833 PROPSHEET_Next(hwndDlg);
1836 PROPSHEET_DoCommand(hwndDlg, IDOK);
1839 FIXME("Invalid button index %d\n", buttonID);
1844 /*************************************************************************
1845 * BOOL PROPSHEET_CanSetCurSel [Internal]
1847 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1850 * hwndDlg [I] handle to a Dialog hWnd
1853 * TRUE if Current Selection can change
1857 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1859 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1865 TRACE("active_page %d\n", psInfo->active_page);
1872 if (psInfo->active_page < 0)
1879 * Notify the current page.
1881 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1882 psn.hdr.code = PSN_KILLACTIVE;
1883 psn.hdr.hwndFrom = hwndDlg;
1887 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1890 TRACE("<-- %d\n", res);
1894 /******************************************************************************
1895 * PROPSHEET_SetCurSel
1897 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1900 HPROPSHEETPAGE hpage
1903 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1904 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1905 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1907 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1908 /* hpage takes precedence over index */
1910 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1912 if (index < 0 || index >= psInfo->nPages)
1914 TRACE("Could not find page to select!\n");
1923 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
1925 psn.hdr.code = PSN_SETACTIVE;
1926 psn.hdr.hwndFrom = hwndDlg;
1930 if (!psInfo->proppage[index].hwndPage) {
1931 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1932 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1935 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1942 FIXME("Tried to skip before first property sheet page!\n");
1945 if (index >= psInfo->nPages) {
1946 FIXME("Tried to skip after last property sheet page!\n");
1947 index = psInfo->nPages-1;
1951 else if (result != 0)
1953 index = PROPSHEET_FindPageByResId(psInfo, result);
1958 * Display the new page.
1960 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1962 if (psInfo->proppage[index].hasHelp)
1963 EnableWindow(hwndHelp, TRUE);
1965 EnableWindow(hwndHelp, FALSE);
1970 /******************************************************************************
1971 * PROPSHEET_SetCurSelId
1973 * Selects the page, specified by resource id.
1975 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
1978 PropSheetInfo* psInfo =
1979 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1981 idx = PROPSHEET_FindPageByResId(psInfo, id);
1982 if (idx < psInfo->nPages )
1984 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1985 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1989 /******************************************************************************
1990 * PROPSHEET_SetTitleA
1992 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1994 if(HIWORD(lpszText))
1997 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1998 szTitle, sizeof szTitle);
1999 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2003 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2007 /******************************************************************************
2008 * PROPSHEET_SetTitleW
2010 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2012 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
2015 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
2016 if (HIWORD(lpszText) == 0) {
2017 if (!LoadStringW(psInfo->ppshheader.hInstance,
2018 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2022 if (dwStyle & PSH_PROPTITLE)
2025 int lentitle = strlenW(lpszText);
2026 int lenprop = strlenW(psInfo->strPropertiesFor);
2028 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2029 strcpyW(dest, psInfo->strPropertiesFor);
2030 strcatW(dest, lpszText);
2032 SetWindowTextW(hwndDlg, dest);
2033 COMCTL32_Free(dest);
2036 SetWindowTextW(hwndDlg, lpszText);
2039 /******************************************************************************
2040 * PROPSHEET_SetFinishTextA
2042 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2044 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2046 TRACE("'%s'\n", lpszText);
2047 /* Set text, show and enable the Finish button */
2048 SetWindowTextA(hwndButton, lpszText);
2049 ShowWindow(hwndButton, SW_SHOW);
2050 EnableWindow(hwndButton, TRUE);
2052 /* Make it default pushbutton */
2053 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2055 /* Hide Back button */
2056 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2057 ShowWindow(hwndButton, SW_HIDE);
2059 /* Hide Next button */
2060 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2061 ShowWindow(hwndButton, SW_HIDE);
2064 /******************************************************************************
2065 * PROPSHEET_SetFinishTextW
2067 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2069 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2071 TRACE("'%s'\n", debugstr_w(lpszText));
2072 /* Set text, show and enable the Finish button */
2073 SetWindowTextW(hwndButton, lpszText);
2074 ShowWindow(hwndButton, SW_SHOW);
2075 EnableWindow(hwndButton, TRUE);
2077 /* Make it default pushbutton */
2078 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2080 /* Hide Back button */
2081 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2082 ShowWindow(hwndButton, SW_HIDE);
2084 /* Hide Next button */
2085 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2086 ShowWindow(hwndButton, SW_HIDE);
2089 /******************************************************************************
2090 * PROPSHEET_QuerySiblings
2092 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2093 WPARAM wParam, LPARAM lParam)
2097 LRESULT msgResult = 0;
2098 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2101 while ((i < psInfo->nPages) && (msgResult == 0))
2103 hwndPage = psInfo->proppage[i].hwndPage;
2104 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2112 /******************************************************************************
2115 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2116 HPROPSHEETPAGE hpage)
2118 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2120 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2122 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2124 TRACE("hpage %p\n", hpage);
2126 * Allocate and fill in a new PropPageInfo entry.
2128 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
2129 sizeof(PropPageInfo) *
2130 (psInfo->nPages + 1));
2131 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2134 psInfo->proppage[psInfo->nPages].hpage = hpage;
2136 if (ppsp->dwFlags & PSP_PREMATURE)
2138 /* Create the page but don't show it */
2139 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2143 * Add a new tab to the tab control.
2145 item.mask = TCIF_TEXT;
2146 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2147 item.cchTextMax = MAX_TABTEXT_LENGTH;
2149 if (psInfo->hImageList)
2151 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2154 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2156 item.mask |= TCIF_IMAGE;
2157 item.iImage = psInfo->nPages;
2160 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2165 /* If it is the only page - show it */
2166 if(psInfo->nPages == 1)
2167 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2171 /******************************************************************************
2172 * PROPSHEET_RemovePage
2174 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2176 HPROPSHEETPAGE hpage)
2178 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2180 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2181 PropPageInfo* oldPages;
2183 TRACE("index %d, hpage %p\n", index, hpage);
2187 oldPages = psInfo->proppage;
2189 * hpage takes precedence over index.
2193 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2196 /* Make sure that index is within range */
2197 if (index < 0 || index >= psInfo->nPages)
2199 TRACE("Could not find page to remove!\n");
2203 TRACE("total pages %d removing page %d active page %d\n",
2204 psInfo->nPages, index, psInfo->active_page);
2206 * Check if we're removing the active page.
2208 if (index == psInfo->active_page)
2210 if (psInfo->nPages > 1)
2214 /* activate previous page */
2215 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2219 /* activate the next page */
2220 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2221 psInfo->active_page = index;
2226 psInfo->active_page = -1;
2227 if (!psInfo->isModeless)
2229 EndDialog(hwndDlg, FALSE);
2234 else if (index < psInfo->active_page)
2235 psInfo->active_page--;
2237 /* Destroy page dialog window */
2238 DestroyWindow(psInfo->proppage[index].hwndPage);
2240 /* Free page resources */
2241 if(psInfo->proppage[index].hpage)
2243 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2245 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2246 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2248 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2251 /* Remove the tab */
2252 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2255 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2258 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2260 if (index < psInfo->nPages)
2261 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2262 (psInfo->nPages - index) * sizeof(PropPageInfo));
2264 COMCTL32_Free(oldPages);
2269 /******************************************************************************
2270 * PROPSHEET_SetWizButtons
2272 * This code will work if (and assumes that) the Next button is on top of the
2273 * Finish button. ie. Finish comes after Next in the Z order.
2274 * This means make sure the dialog template reflects this.
2277 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2279 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2280 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2281 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2283 TRACE("%ld\n", dwFlags);
2285 EnableWindow(hwndBack, FALSE);
2286 EnableWindow(hwndNext, FALSE);
2287 EnableWindow(hwndFinish, FALSE);
2289 if (dwFlags & PSWIZB_BACK)
2290 EnableWindow(hwndBack, TRUE);
2292 if (dwFlags & PSWIZB_NEXT)
2294 /* Hide the Finish button */
2295 ShowWindow(hwndFinish, SW_HIDE);
2297 /* Show and enable the Next button */
2298 ShowWindow(hwndNext, SW_SHOW);
2299 EnableWindow(hwndNext, TRUE);
2301 /* Set the Next button as the default pushbutton */
2302 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2305 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2307 /* Hide the Next button */
2308 ShowWindow(hwndNext, SW_HIDE);
2310 /* Show the Finish button */
2311 ShowWindow(hwndFinish, SW_SHOW);
2313 if (dwFlags & PSWIZB_FINISH)
2314 EnableWindow(hwndFinish, TRUE);
2316 /* Set the Finish button as the default pushbutton */
2317 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2321 /******************************************************************************
2322 * PROPSHEET_GetPageIndex
2324 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2325 * the array of PropPageInfo.
2327 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2332 TRACE("hpage %p\n", hpage);
2333 while ((index < psInfo->nPages) && (found == FALSE))
2335 if (psInfo->proppage[index].hpage == hpage)
2347 /******************************************************************************
2350 static void PROPSHEET_CleanUp(HWND hwndDlg)
2353 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2357 if (!psInfo) return;
2358 if (HIWORD(psInfo->ppshheader.pszCaption))
2359 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2361 for (i = 0; i < psInfo->nPages; i++)
2363 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2365 if(psInfo->proppage[i].hwndPage)
2366 DestroyWindow(psInfo->proppage[i].hwndPage);
2370 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2371 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2373 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2377 COMCTL32_Free(psInfo->proppage);
2378 COMCTL32_Free(psInfo->strPropertiesFor);
2379 ImageList_Destroy(psInfo->hImageList);
2381 GlobalFree((HGLOBAL)psInfo);
2384 /******************************************************************************
2385 * PropertySheet (COMCTL32.@)
2386 * PropertySheetA (COMCTL32.@)
2388 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2391 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2392 sizeof(PropSheetInfo));
2396 TRACE("(%p)\n", lppsh);
2398 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2400 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2402 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2404 for (n = i = 0; i < lppsh->nPages; i++, n++)
2406 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2407 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2410 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2411 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2414 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2417 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2418 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2424 bRet = PROPSHEET_CreateDialog(psInfo);
2429 /******************************************************************************
2430 * PropertySheetW (COMCTL32.@)
2432 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2435 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2436 sizeof(PropSheetInfo));
2440 TRACE("(%p)\n", lppsh);
2442 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2444 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2446 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2448 for (n = i = 0; i < lppsh->nPages; i++, n++)
2450 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2451 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2454 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2455 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2458 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2461 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2462 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2468 bRet = PROPSHEET_CreateDialog(psInfo);
2473 /******************************************************************************
2474 * CreatePropertySheetPage (COMCTL32.@)
2475 * CreatePropertySheetPageA (COMCTL32.@)
2477 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2478 LPCPROPSHEETPAGEA lpPropSheetPage)
2480 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2482 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2484 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2486 PROPSHEET_AtoW(&ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate);
2488 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2490 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2493 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2495 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2497 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2498 ppsp->pszTitle = NULL;
2500 return (HPROPSHEETPAGE)ppsp;
2503 /******************************************************************************
2504 * CreatePropertySheetPageW (COMCTL32.@)
2506 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2508 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2510 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2512 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2514 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2516 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2517 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2519 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2521 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2522 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2523 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2526 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2528 int len = strlenW(lpPropSheetPage->pszTitle);
2529 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2530 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2532 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2533 ppsp->pszTitle = NULL;
2535 return (HPROPSHEETPAGE)ppsp;
2538 /******************************************************************************
2539 * DestroyPropertySheetPage (COMCTL32.@)
2541 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2543 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2548 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2549 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2551 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2552 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2554 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2555 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2557 COMCTL32_Free(hPropPage);
2562 /******************************************************************************
2563 * PROPSHEET_IsDialogMessage
2565 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2567 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2570 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2573 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2576 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2578 if (!(dlgCode & DLGC_WANTMESSAGE))
2580 switch (lpMsg->wParam)
2583 if (GetKeyState(VK_SHIFT) & 0x8000)
2589 case VK_NEXT: new_page = 1; break;
2590 case VK_PRIOR: new_page = -1; break;
2596 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2598 new_page += psInfo->active_page;
2601 new_page = psInfo->nPages - 1;
2602 else if (new_page >= psInfo->nPages)
2605 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2612 return IsDialogMessageA(hwnd, lpMsg);
2615 /******************************************************************************
2616 * PROPSHEET_DoCommand
2618 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2624 case IDC_APPLY_BUTTON:
2626 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2628 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2633 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2637 if (psInfo->restartWindows)
2638 result = ID_PSRESTARTWINDOWS;
2640 /* reboot system takes precedence over restart windows */
2641 if (psInfo->rebootSystem)
2642 result = ID_PSREBOOTSYSTEM;
2644 if (psInfo->isModeless)
2645 psInfo->activeValid = FALSE;
2647 EndDialog(hwnd, result);
2650 EnableWindow(hwndApplyBtn, FALSE);
2655 case IDC_BACK_BUTTON:
2656 PROPSHEET_Back(hwnd);
2659 case IDC_NEXT_BUTTON:
2660 PROPSHEET_Next(hwnd);
2663 case IDC_FINISH_BUTTON:
2664 PROPSHEET_Finish(hwnd);
2668 PROPSHEET_Cancel(hwnd, 0);
2672 PROPSHEET_Help(hwnd);
2679 /******************************************************************************
2680 * PROPSHEET_DialogProc
2683 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2685 TRACE("hwnd=%p msg=0x%04x wparam=%x lparam=%lx\n",
2686 hwnd, uMsg, wParam, lParam);
2692 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2693 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2694 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2695 LPCPROPSHEETPAGEW ppshpage;
2698 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2701 * psInfo->hwnd is not being used by WINE code - it exists
2702 * for compatibility with "real" Windoze. The same about
2703 * SetWindowLong - WINE is only using the PropSheetInfoStr
2706 psInfo->hwnd = hwnd;
2707 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2710 * Small icon in the title bar.
2712 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2713 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2716 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2717 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2719 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2720 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2721 psInfo->ppshheader.u.pszIcon,
2726 hIcon = psInfo->ppshheader.u.hIcon;
2728 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
2731 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2732 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
2734 psInfo->strPropertiesFor = strCaption;
2736 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2738 PROPSHEET_CreateTabControl(hwnd, psInfo);
2740 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2742 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2744 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2745 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2750 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2752 PROPSHEET_AdjustSize(hwnd, psInfo);
2753 PROPSHEET_AdjustButtons(hwnd, psInfo);
2757 if (psInfo->useCallback)
2758 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2759 PSCB_INITIALIZED, (LPARAM)0);
2761 idx = psInfo->active_page;
2762 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2763 psInfo->active_page = -1;
2765 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2767 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2768 * as some programs call TCM_GETCURSEL to get the current selection
2769 * from which to switch to the next page */
2770 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2772 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2773 psInfo->ppshheader.hInstance)
2777 if (LoadStringW(psInfo->ppshheader.hInstance,
2778 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2779 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2783 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2784 psInfo->ppshheader.pszCaption);
2791 PROPSHEET_CleanUp(hwnd);
2795 PROPSHEET_Cancel(hwnd, 1);
2799 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2803 NMHDR* pnmh = (LPNMHDR) lParam;
2805 if (pnmh->code == TCN_SELCHANGE)
2807 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2808 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2811 if(pnmh->code == TCN_SELCHANGING)
2813 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2814 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2821 case PSM_GETCURRENTPAGEHWND:
2823 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2827 if (psInfo->activeValid && psInfo->active_page != -1)
2828 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2830 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndPage);
2836 PROPSHEET_Changed(hwnd, (HWND)wParam);
2840 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2843 case PSM_GETTABCONTROL:
2845 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2847 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndTabCtrl);
2856 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2857 if(msgResult != FALSE)
2859 msgResult = PROPSHEET_SetCurSel(hwnd,
2862 (HPROPSHEETPAGE)lParam);
2865 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2870 case PSM_CANCELTOCLOSE:
2872 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2873 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2874 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2876 EnableWindow(hwndCancel, FALSE);
2877 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2878 SetWindowTextW(hwndOK, buf);
2883 case PSM_RESTARTWINDOWS:
2885 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2888 psInfo->restartWindows = TRUE;
2892 case PSM_REBOOTSYSTEM:
2894 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2897 psInfo->rebootSystem = TRUE;
2902 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2906 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2911 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2913 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2918 case PSM_QUERYSIBLINGS:
2920 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2922 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2930 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2931 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2932 * on success or FALSE otherwise, as specified on MSDN Online.
2933 * Also see the MFC code for
2934 * CPropertySheet::AddPage(CPropertyPage* pPage).
2937 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2939 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2944 case PSM_REMOVEPAGE:
2945 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2948 case PSM_ISDIALOGMESSAGE:
2950 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2951 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2955 case PSM_PRESSBUTTON:
2956 PROPSHEET_PressButton(hwnd, (int)wParam);
2959 case PSM_SETFINISHTEXTA:
2960 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2963 case PSM_SETWIZBUTTONS:
2964 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2967 case PSM_SETCURSELID:
2968 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
2971 case PSM_SETFINISHTEXTW:
2972 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);