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
32 #include "wine/debug.h"
36 /******************************************************************************
59 } MyDLGITEMTEMPLATEEX;
62 typedef struct tagPropPageInfo
64 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
73 typedef struct tagPropSheetInfo
76 PROPSHEETHEADERW ppshheader;
77 LPWSTR strPropertiesFor;
87 PropPageInfo* proppage;
92 HIMAGELIST hImageList;
101 /******************************************************************************
102 * Defines and global variables
105 const WCHAR PropSheetInfoStr[] =
106 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
108 #define MAX_CAPTION_LENGTH 255
109 #define MAX_TABTEXT_LENGTH 255
110 #define MAX_BUTTONTEXT_LENGTH 64
112 #define PSH_WIZARD97_OLD 0x00002000
113 #define PSH_WIZARD97_NEW 0x01000000
114 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
116 /******************************************************************************
119 static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
120 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
121 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
122 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
123 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
124 PropSheetInfo * psInfo);
125 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
126 PropSheetInfo * psInfo);
127 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
128 PropSheetInfo * psInfo,
130 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
131 PropSheetInfo * psInfo);
132 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
133 const PropSheetInfo * psInfo,
134 LPCPROPSHEETPAGEW ppshpage);
135 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
136 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
137 static BOOL PROPSHEET_Back(HWND hwndDlg);
138 static BOOL PROPSHEET_Next(HWND hwndDlg);
139 static BOOL PROPSHEET_Finish(HWND hwndDlg);
140 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
141 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
142 static void PROPSHEET_Help(HWND hwndDlg);
143 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
144 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
145 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
146 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
147 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
148 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
149 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
150 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
151 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
154 HPROPSHEETPAGE hpage);
155 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
156 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
157 WPARAM wParam, LPARAM lParam);
158 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
159 HPROPSHEETPAGE hpage);
161 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
163 HPROPSHEETPAGE hpage);
164 static void PROPSHEET_CleanUp();
165 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
166 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
167 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
168 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
169 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
172 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
174 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
176 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
177 /******************************************************************************
178 * PROPSHEET_UnImplementedFlags
180 * Document use of flags we don't implement yet.
182 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
189 * unhandled header flags:
190 * PSH_DEFAULT 0x00000000
191 * PSH_WIZARDHASFINISH 0x00000010
192 * PSH_RTLREADING 0x00000800
193 * PSH_WIZARDCONTEXTHELP 0x00001000
194 * PSH_WIZARD97 0x00002000 (pre IE 5)
195 * PSH_WATERMARK 0x00008000
196 * PSH_USEHBMWATERMARK 0x00010000
197 * PSH_USEHPLWATERMARK 0x00020000
198 * PSH_STRETCHWATERMARK 0x00040000
199 * PSH_HEADER 0x00080000
200 * PSH_USEHBMHEADER 0x00100000
201 * PSH_USEPAGELANG 0x00200000
202 * PSH_WIZARD_LITE 0x00400000 also not in .h
203 * PSH_WIZARD97 0x01000000 (IE 5 and above)
204 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
207 add_flag(PSH_WIZARDHASFINISH);
208 add_flag(PSH_RTLREADING);
209 add_flag(PSH_WIZARDCONTEXTHELP);
210 add_flag(PSH_WIZARD97_OLD);
211 add_flag(PSH_WATERMARK);
212 add_flag(PSH_USEHBMWATERMARK);
213 add_flag(PSH_USEHPLWATERMARK);
214 add_flag(PSH_STRETCHWATERMARK);
215 add_flag(PSH_HEADER);
216 add_flag(PSH_USEHBMHEADER);
217 add_flag(PSH_USEPAGELANG);
218 add_flag(PSH_WIZARD_LITE);
219 add_flag(PSH_WIZARD97_NEW);
220 add_flag(PSH_NOCONTEXTHELP);
221 if (string[0] != '\0')
222 FIXME("%s\n", string);
226 /******************************************************************************
227 * PROPSHEET_GetPageRect
229 * Retrieve rect from tab control and map into the dialog for SetWindowPos
231 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
233 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
235 GetClientRect(hwndTabCtrl, rc);
236 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
237 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
240 /******************************************************************************
241 * PROPSHEET_FindPageByResId
243 * Find page index corresponding to page resource id.
245 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
249 for (i = 0; i < psInfo->nPages; i++)
251 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
253 /* Fixme: if resource ID is a string shall we use strcmp ??? */
254 if (lppsp->u.pszTemplate == (LPVOID)resId)
261 /******************************************************************************
264 * Convert ASCII to Unicode since all data is saved as Unicode.
266 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
270 TRACE("<%s>\n", frstr);
271 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
272 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
273 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
276 /******************************************************************************
277 * PROPSHEET_CollectSheetInfoA
279 * Collect relevant data.
281 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
282 PropSheetInfo * psInfo)
284 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
285 DWORD dwFlags = lppsh->dwFlags;
287 psInfo->hasHelp = dwFlags & PSH_HASHELP;
288 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
289 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
290 psInfo->isModeless = dwFlags & PSH_MODELESS;
292 memcpy(&psInfo->ppshheader,lppsh,dwSize);
293 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%04x\nhInstance\t%08x\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
294 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
295 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
297 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
299 if (HIWORD(lppsh->pszCaption))
301 int len = strlen(lppsh->pszCaption);
302 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
303 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
304 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
306 psInfo->nPages = lppsh->nPages;
308 if (dwFlags & PSH_USEPSTARTPAGE)
310 TRACE("PSH_USEPSTARTPAGE is on");
311 psInfo->active_page = 0;
314 psInfo->active_page = lppsh->u2.nStartPage;
316 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
317 psInfo->active_page = 0;
319 psInfo->restartWindows = FALSE;
320 psInfo->rebootSystem = FALSE;
321 psInfo->hImageList = 0;
322 psInfo->activeValid = FALSE;
327 /******************************************************************************
328 * PROPSHEET_CollectSheetInfoW
330 * Collect relevant data.
332 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
333 PropSheetInfo * psInfo)
335 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
336 DWORD dwFlags = lppsh->dwFlags;
338 psInfo->hasHelp = dwFlags & PSH_HASHELP;
339 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
340 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
341 psInfo->isModeless = dwFlags & PSH_MODELESS;
343 memcpy(&psInfo->ppshheader,lppsh,dwSize);
344 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%04x\nhInstance\t%08x\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
345 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
347 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
349 if (HIWORD(lppsh->pszCaption))
351 int len = strlenW(lppsh->pszCaption);
352 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
353 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
355 psInfo->nPages = lppsh->nPages;
357 if (dwFlags & PSH_USEPSTARTPAGE)
359 TRACE("PSH_USEPSTARTPAGE is on");
360 psInfo->active_page = 0;
363 psInfo->active_page = lppsh->u2.nStartPage;
365 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
366 psInfo->active_page = 0;
368 psInfo->restartWindows = FALSE;
369 psInfo->rebootSystem = FALSE;
370 psInfo->hImageList = 0;
371 psInfo->activeValid = FALSE;
376 /******************************************************************************
377 * PROPSHEET_CollectPageInfo
379 * Collect property sheet data.
380 * With code taken from DIALOG_ParseTemplate32.
382 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
383 PropSheetInfo * psInfo,
386 DLGTEMPLATE* pTemplate;
392 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
393 psInfo->proppage[index].hwndPage = 0;
394 psInfo->proppage[index].isDirty = FALSE;
397 * Process property page flags.
399 dwFlags = lppsp->dwFlags;
400 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
401 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
402 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
404 /* as soon as we have a page with the help flag, set the sheet flag on */
405 if (psInfo->proppage[index].hasHelp)
406 psInfo->hasHelp = TRUE;
409 * Process page template.
411 if (dwFlags & PSP_DLGINDIRECT)
412 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
415 HRSRC hResource = FindResourceW(lppsp->hInstance,
416 lppsp->u.pszTemplate,
418 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
420 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
424 * Extract the size of the page and the caption.
429 p = (const WORD *)pTemplate;
431 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
433 /* DIALOGEX template */
437 p += 2; /* help ID */
438 p += 2; /* ext style */
443 /* DIALOG template */
446 p += 2; /* ext style */
452 width = (WORD)*p; p++;
453 height = (WORD)*p; p++;
455 /* remember the largest width and height */
456 if (width > psInfo->width)
457 psInfo->width = width;
459 if (height > psInfo->height)
460 psInfo->height = height;
472 p += lstrlenW( (LPCWSTR)p ) + 1;
486 p += lstrlenW( (LPCWSTR)p ) + 1;
490 /* Extract the caption */
491 psInfo->proppage[index].pszText = (LPCWSTR)p;
492 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
493 p += lstrlenW((LPCWSTR)p) + 1;
495 if (dwFlags & PSP_USETITLE)
499 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
502 if ( !HIWORD( lppsp->pszTitle ) )
504 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
507 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
513 pTitle = lppsp->pszTitle;
515 len = strlenW(pTitle);
516 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
517 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
521 * Build the image list for icons
523 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
526 int icon_cx = GetSystemMetrics(SM_CXSMICON);
527 int icon_cy = GetSystemMetrics(SM_CYSMICON);
529 if (dwFlags & PSP_USEICONID)
530 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
531 icon_cx, icon_cy, LR_DEFAULTCOLOR);
533 hIcon = lppsp->u2.hIcon;
537 if (psInfo->hImageList == 0 )
538 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
540 ImageList_AddIcon(psInfo->hImageList, hIcon);
548 /******************************************************************************
549 * PROPSHEET_CreateDialog
551 * Creates the actual property sheet.
553 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
560 WORD resID = IDD_PROPSHEET;
563 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
566 if(!(hRes = FindResourceW(COMCTL32_hModule,
567 MAKEINTRESOURCEW(resID),
571 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
575 * Make a copy of the dialog template.
577 resSize = SizeofResource(COMCTL32_hModule, hRes);
579 temp = COMCTL32_Alloc(resSize);
584 memcpy(temp, template, resSize);
586 if (psInfo->useCallback)
587 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
589 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
590 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
591 (LPDLGTEMPLATEW) temp,
592 psInfo->ppshheader.hwndParent,
593 (DLGPROC) PROPSHEET_DialogProc,
596 ret = CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
597 (LPDLGTEMPLATEW) temp,
598 psInfo->ppshheader.hwndParent,
599 (DLGPROC) PROPSHEET_DialogProc,
600 (LPARAM)psInfo) ? TRUE : FALSE;
607 /******************************************************************************
608 * PROPSHEET_SizeMismatch
610 * Verify that the tab control and the "largest" property sheet page dlg. template
613 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
615 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
616 RECT rcOrigTab, rcPage;
621 GetClientRect(hwndTabCtrl, &rcOrigTab);
622 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
623 rcOrigTab.right, rcOrigTab.bottom);
628 rcPage.left = psInfo->x;
629 rcPage.top = psInfo->y;
630 rcPage.right = psInfo->width;
631 rcPage.bottom = psInfo->height;
633 MapDialogRect(hwndDlg, &rcPage);
634 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
635 rcPage.right, rcPage.bottom);
637 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
639 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
645 /******************************************************************************
646 * PROPSHEET_IsTooSmallWizard
648 * Verify that the default property sheet is big enough.
650 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
652 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
653 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
654 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
656 GetClientRect(hwndDlg, &rcSheetClient);
657 GetWindowRect(hwndDlg, &rcSheetRect);
658 GetWindowRect(hwndLine, &rcLine);
660 /* Remove the space below the sunken line */
661 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
663 /* Remove the buffer zone all around the edge */
664 rcSheetClient.bottom -= (padding.y * 2);
665 rcSheetClient.right -= (padding.x * 2);
670 rcPage.left = psInfo->x;
671 rcPage.top = psInfo->y;
672 rcPage.right = psInfo->width;
673 rcPage.bottom = psInfo->height;
675 MapDialogRect(hwndDlg, &rcPage);
676 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
677 rcPage.right, rcPage.bottom);
679 if (rcPage.right > rcSheetClient.right)
682 if (rcPage.bottom > rcSheetClient.bottom)
688 /******************************************************************************
689 * PROPSHEET_AdjustSize
691 * Resizes the property sheet and the tab control to fit the largest page.
693 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
695 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
696 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
698 int tabOffsetX, tabOffsetY, buttonHeight;
699 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
702 /* Get the height of buttons */
703 GetClientRect(hwndButton, &rc);
704 buttonHeight = rc.bottom;
711 rc.right = psInfo->width;
712 rc.bottom = psInfo->height;
714 MapDialogRect(hwndDlg, &rc);
716 /* retrieve the dialog units */
717 units.left = units.right = 4;
718 units.top = units.bottom = 8;
719 MapDialogRect(hwndDlg, &units);
722 * Resize the tab control.
724 GetClientRect(hwndTabCtrl,&tabRect);
726 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
728 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
730 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
731 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
734 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
736 rc.right = rc.left + tabRect.right - tabRect.left;
737 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
740 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
742 tabOffsetX = -(rc.left);
743 tabOffsetY = -(rc.top);
747 TRACE("setting tab %08lx, rc (0,0)-(%d,%d)\n",
748 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
749 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
750 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
752 GetClientRect(hwndTabCtrl, &rc);
754 TRACE("tab client rc %d %d %d %d\n",
755 rc.left, rc.top, rc.right, rc.bottom);
757 rc.right += ((padding.x * 2) + tabOffsetX);
758 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
761 * Resize the property sheet.
763 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
764 (DWORD)hwndDlg, rc.right, rc.bottom);
765 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
766 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
770 /******************************************************************************
771 * PROPSHEET_AdjustSizeWizard
773 * Resizes the property sheet to fit the largest page.
775 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
777 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
778 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
779 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
781 int buttonHeight, lineHeight;
782 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
785 /* Get the height of buttons */
786 GetClientRect(hwndButton, &rc);
787 buttonHeight = rc.bottom;
789 GetClientRect(hwndLine, &rc);
790 lineHeight = rc.bottom;
792 /* retrieve the dialog units */
793 units.left = units.right = 4;
794 units.top = units.bottom = 8;
795 MapDialogRect(hwndDlg, &units);
802 rc.right = psInfo->width;
803 rc.bottom = psInfo->height;
805 MapDialogRect(hwndDlg, &rc);
807 GetClientRect(hwndTabCtrl,&tabRect);
809 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
811 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
812 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
815 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
817 rc.right = rc.left + tabRect.right - tabRect.left;
818 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
821 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
822 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
823 padding.x, padding.y, buttonHeight, lineHeight);
826 rc.right += (padding.x * 2);
827 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
830 * Resize the property sheet.
832 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
833 (DWORD)hwndDlg, rc.right, rc.bottom);
834 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
835 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
839 /******************************************************************************
840 * PROPSHEET_AdjustButtons
842 * Adjusts the buttons' positions.
844 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
846 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
850 int buttonWidth, buttonHeight;
851 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
853 if (psInfo->hasApply)
860 * Obtain the size of the buttons.
862 GetClientRect(hwndButton, &rcSheet);
863 buttonWidth = rcSheet.right;
864 buttonHeight = rcSheet.bottom;
867 * Get the size of the property sheet.
869 GetClientRect(hwndParent, &rcSheet);
872 * All buttons will be at this y coordinate.
874 y = rcSheet.bottom - (padding.y + buttonHeight);
877 * Position OK button.
879 hwndButton = GetDlgItem(hwndParent, IDOK);
881 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
883 SetWindowPos(hwndButton, 0, x, y, 0, 0,
884 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
887 * Position Cancel button.
889 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
891 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
893 SetWindowPos(hwndButton, 0, x, y, 0, 0,
894 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
897 * Position Apply button.
899 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
901 if (psInfo->hasApply)
904 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
906 x = rcSheet.right - (padding.x + buttonWidth);
908 SetWindowPos(hwndButton, 0, x, y, 0, 0,
909 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
911 EnableWindow(hwndButton, FALSE);
914 ShowWindow(hwndButton, SW_HIDE);
917 * Position Help button.
919 hwndButton = GetDlgItem(hwndParent, IDHELP);
923 x = rcSheet.right - (padding.x + buttonWidth);
925 SetWindowPos(hwndButton, 0, x, y, 0, 0,
926 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
929 ShowWindow(hwndButton, SW_HIDE);
934 /******************************************************************************
935 * PROPSHEET_AdjustButtonsWizard
937 * Adjusts the buttons' positions.
939 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
940 PropSheetInfo* psInfo)
942 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
943 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
947 int buttonWidth, buttonHeight, lineHeight, lineWidth;
948 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
954 * Obtain the size of the buttons.
956 GetClientRect(hwndButton, &rcSheet);
957 buttonWidth = rcSheet.right;
958 buttonHeight = rcSheet.bottom;
960 GetClientRect(hwndLine, &rcSheet);
961 lineHeight = rcSheet.bottom;
964 * Get the size of the property sheet.
966 GetClientRect(hwndParent, &rcSheet);
969 * All buttons will be at this y coordinate.
971 y = rcSheet.bottom - (padding.y + buttonHeight);
974 * Position the Next and the Finish buttons.
976 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
978 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
980 SetWindowPos(hwndButton, 0, x, y, 0, 0,
981 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
983 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
985 SetWindowPos(hwndButton, 0, x, y, 0, 0,
986 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
988 ShowWindow(hwndButton, SW_HIDE);
991 * Position the Back button.
993 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
997 SetWindowPos(hwndButton, 0, x, y, 0, 0,
998 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1001 * Position the Cancel button.
1003 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1005 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1007 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1008 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1011 * Position Help button.
1013 hwndButton = GetDlgItem(hwndParent, IDHELP);
1015 if (psInfo->hasHelp)
1017 x = rcSheet.right - (padding.x + buttonWidth);
1019 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1020 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1023 ShowWindow(hwndButton, SW_HIDE);
1026 * Position and resize the sunken line.
1029 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1031 GetClientRect(hwndParent, &rcSheet);
1032 lineWidth = rcSheet.right - (padding.x * 2);
1034 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1035 SWP_NOZORDER | SWP_NOACTIVATE);
1040 /******************************************************************************
1041 * PROPSHEET_GetPaddingInfo
1043 * Returns the layout information.
1045 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1047 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1050 PADDING_INFO padding;
1052 GetWindowRect(hwndTab, &rcTab);
1057 ScreenToClient(hwndDlg, &tl);
1065 /******************************************************************************
1066 * PROPSHEET_GetPaddingInfoWizard
1068 * Returns the layout information.
1069 * Vertical spacing is the distance between the line and the buttons.
1070 * Do NOT use the Help button to gather padding information when it isn't mapped
1071 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1072 * for it in this case !
1073 * FIXME: I'm not sure about any other coordinate problems with these evil
1074 * buttons. Fix it in case additional problems appear or maybe calculate
1075 * a padding in a completely different way, as this is somewhat messy.
1077 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1080 PADDING_INFO padding;
1084 POINT ptButton, ptLine;
1087 if (psInfo->hasHelp)
1093 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1095 idButton = IDC_NEXT_BUTTON;
1099 /* hopefully this is ok */
1100 idButton = IDCANCEL;
1104 hwndControl = GetDlgItem(hwndDlg, idButton);
1105 GetWindowRect(hwndControl, &rc);
1107 ptButton.x = rc.left;
1108 ptButton.y = rc.top;
1110 ScreenToClient(hwndDlg, &ptButton);
1113 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1114 GetWindowRect(hwndControl, &rc);
1117 ptLine.y = rc.bottom;
1119 ScreenToClient(hwndDlg, &ptLine);
1121 padding.y = ptButton.y - ptLine.y;
1124 ERR("padding negative ! Please report this !\n");
1126 /* this is most probably not correct, but the best we have now */
1127 padding.x = padding.y;
1131 /******************************************************************************
1132 * PROPSHEET_CreateTabControl
1134 * Insert the tabs in the tab control.
1136 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1137 PropSheetInfo * psInfo)
1139 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1145 item.mask = TCIF_TEXT;
1146 item.cchTextMax = MAX_TABTEXT_LENGTH;
1148 nTabs = psInfo->nPages;
1151 * Set the image list for icons.
1153 if (psInfo->hImageList)
1155 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1158 for (i = 0; i < nTabs; i++)
1160 if ( psInfo->proppage[i].hasIcon )
1162 item.mask |= TCIF_IMAGE;
1163 item.iImage = iImage++;
1167 item.mask &= ~TCIF_IMAGE;
1170 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1171 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1177 * Get the size of an in-memory Template
1179 *( Based on the code of PROPSHEET_CollectPageInfo)
1182 static UINT GetTemplateSize(DLGTEMPLATE* pTemplate)
1185 const WORD* p = (const WORD *)pTemplate;
1186 BOOL istemplateex = (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1191 /* DIALOGEX template */
1194 p++; /* signature */
1195 p += 2; /* help ID */
1196 p += 2; /* ext style */
1201 /* DIALOG template */
1204 p += 2; /* ext style */
1207 nrofitems = (WORD)*p; p++; /* nb items */
1223 TRACE("menu %s\n",debugstr_w((LPCWSTR)p));
1224 p += lstrlenW( (LPCWSTR)p ) + 1;
1238 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1239 p += lstrlenW( (LPCWSTR)p ) + 1;
1244 TRACE("title %s\n",debugstr_w((LPCWSTR)p));
1245 p += lstrlenW((LPCWSTR)p) + 1;
1247 /* font, if DS_FONT set */
1248 if ((DS_SETFONT & ((istemplateex)? ((MyDLGTEMPLATEEX*)pTemplate)->style :
1251 p+=(istemplateex)?3:1;
1252 TRACE("font %s\n",debugstr_w((LPCWSTR)p));
1253 p += lstrlenW( (LPCWSTR)p ) + 1; /* the font name*/
1256 TRACE("%d items\n",nrofitems);
1257 while (nrofitems > 0)
1259 p = (WORD*)(((DWORD)p + 3) & ~3); /* DWORD align */
1261 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1269 TRACE("class ordinal 0x%08lx\n",*(DWORD*)p);
1273 TRACE("class %s\n",debugstr_w((LPCWSTR)p));
1274 p += lstrlenW( (LPCWSTR)p ) + 1;
1283 TRACE("text ordinal 0x%08lx\n",*(DWORD*)p);
1287 TRACE("text %s\n",debugstr_w((LPCWSTR)p));
1288 p += lstrlenW( (LPCWSTR)p ) + 1;
1291 p += *p + 1; /* Skip extra data */
1295 TRACE("%p %p size 0x%08x\n",p, (WORD*)pTemplate,sizeof(WORD)*(p - (WORD*)pTemplate));
1296 return (p - (WORD*)pTemplate)*sizeof(WORD);
1300 /******************************************************************************
1301 * PROPSHEET_CreatePage
1305 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1307 const PropSheetInfo * psInfo,
1308 LPCPROPSHEETPAGEW ppshpage)
1310 DLGTEMPLATE* pTemplate;
1313 PropPageInfo* ppInfo = psInfo->proppage;
1314 PADDING_INFO padding;
1315 UINT pageWidth,pageHeight;
1319 TRACE("index %d\n", index);
1321 if (ppshpage == NULL)
1326 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1328 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1329 resSize = GetTemplateSize(pTemplate);
1336 hResource = FindResourceW(ppshpage->hInstance,
1337 ppshpage->u.pszTemplate,
1342 resSize = SizeofResource(ppshpage->hInstance, hResource);
1344 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1348 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1350 * Make a copy of the dialog template to make it writable
1353 temp = COMCTL32_Alloc(resSize);
1357 memcpy(temp, pTemplate, resSize);
1360 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1362 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1363 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1364 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1365 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1366 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1367 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1368 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1369 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1373 pTemplate->style |= WS_CHILD | DS_CONTROL;
1374 pTemplate->style &= ~DS_MODALFRAME;
1375 pTemplate->style &= ~WS_CAPTION;
1376 pTemplate->style &= ~WS_SYSMENU;
1377 pTemplate->style &= ~WS_POPUP;
1378 pTemplate->style &= ~WS_DISABLED;
1379 pTemplate->style &= ~WS_VISIBLE;
1380 pTemplate->style &= ~WS_THICKFRAME;
1383 if (psInfo->proppage[index].useCallback)
1384 (*(ppshpage->pfnCallback))(hwndParent,
1386 (LPPROPSHEETPAGEW)ppshpage);
1388 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1391 ppshpage->pfnDlgProc,
1393 /* Free a no more needed copy */
1395 COMCTL32_Free(temp);
1397 ppInfo[index].hwndPage = hwndPage;
1399 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1400 /* FIXME: This code may no longer be correct.
1401 * It was not for the non-wizard path. (GLA 6/02)
1403 rc.left = psInfo->x;
1405 rc.right = psInfo->width;
1406 rc.bottom = psInfo->height;
1408 MapDialogRect(hwndParent, &rc);
1410 pageWidth = rc.right - rc.left;
1411 pageHeight = rc.bottom - rc.top;
1413 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1414 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d, padx=%d, pady=%d\n",
1415 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1416 pageWidth, pageHeight, padding.x, padding.y);
1417 SetWindowPos(hwndPage, HWND_TOP,
1418 rc.left + padding.x/2,
1419 rc.top + padding.y/2,
1420 pageWidth, pageHeight, 0);
1424 * Ask the Tab control to reduce the client rectangle to that
1427 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1428 pageWidth = rc.right - rc.left;
1429 pageHeight = rc.bottom - rc.top;
1430 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
1431 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1432 pageWidth, pageHeight);
1433 SetWindowPos(hwndPage, HWND_TOP,
1435 pageWidth, pageHeight, 0);
1441 /******************************************************************************
1442 * PROPSHEET_ShowPage
1444 * Displays or creates the specified page.
1446 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1450 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1451 if (index == psInfo->active_page)
1453 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1454 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1458 if (psInfo->proppage[index].hwndPage == 0)
1460 LPCPROPSHEETPAGEW ppshpage;
1462 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1463 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1466 if (psInfo->active_page != -1)
1467 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1469 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1471 /* Synchronize current selection with tab control
1472 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1473 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1474 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1476 psInfo->active_page = index;
1477 psInfo->activeValid = TRUE;
1482 /******************************************************************************
1485 static BOOL PROPSHEET_Back(HWND hwndDlg)
1489 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1494 TRACE("active_page %d\n", psInfo->active_page);
1495 if (psInfo->active_page < 0)
1498 psn.hdr.code = PSN_WIZBACK;
1499 psn.hdr.hwndFrom = hwndDlg;
1503 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1505 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1508 else if (result == 0)
1509 idx = psInfo->active_page - 1;
1511 idx = PROPSHEET_FindPageByResId(psInfo, result);
1513 if (idx >= 0 && idx < psInfo->nPages)
1515 if (PROPSHEET_CanSetCurSel(hwndDlg))
1516 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1521 /******************************************************************************
1524 static BOOL PROPSHEET_Next(HWND hwndDlg)
1528 LRESULT msgResult = 0;
1529 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1533 TRACE("active_page %d\n", psInfo->active_page);
1534 if (psInfo->active_page < 0)
1537 psn.hdr.code = PSN_WIZNEXT;
1538 psn.hdr.hwndFrom = hwndDlg;
1542 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1544 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1545 if (msgResult == -1)
1547 else if (msgResult == 0)
1548 idx = psInfo->active_page + 1;
1550 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1552 if (idx < psInfo->nPages )
1554 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1555 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1561 /******************************************************************************
1564 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1568 LRESULT msgResult = 0;
1569 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1572 TRACE("active_page %d\n", psInfo->active_page);
1573 if (psInfo->active_page < 0)
1576 psn.hdr.code = PSN_WIZFINISH;
1577 psn.hdr.hwndFrom = hwndDlg;
1581 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1583 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1585 TRACE("msg result %ld\n", msgResult);
1590 if (psInfo->isModeless)
1591 psInfo->activeValid = FALSE;
1593 EndDialog(hwndDlg, TRUE);
1598 /******************************************************************************
1601 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1607 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1610 TRACE("active_page %d\n", psInfo->active_page);
1611 if (psInfo->active_page < 0)
1614 psn.hdr.hwndFrom = hwndDlg;
1620 * Send PSN_KILLACTIVE to the current page.
1622 psn.hdr.code = PSN_KILLACTIVE;
1624 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1626 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1630 * Send PSN_APPLY to all pages.
1632 psn.hdr.code = PSN_APPLY;
1633 psn.lParam = lParam;
1635 for (i = 0; i < psInfo->nPages; i++)
1637 hwndPage = psInfo->proppage[i].hwndPage;
1640 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1641 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1648 psInfo->activeValid = FALSE;
1650 else if(psInfo->active_page >= 0)
1652 psn.hdr.code = PSN_SETACTIVE;
1654 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1655 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1661 /******************************************************************************
1664 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1666 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1672 TRACE("active_page %d\n", psInfo->active_page);
1673 if (psInfo->active_page < 0)
1676 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1677 psn.hdr.code = PSN_QUERYCANCEL;
1678 psn.hdr.hwndFrom = hwndDlg;
1682 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1685 psn.hdr.code = PSN_RESET;
1686 psn.lParam = lParam;
1688 for (i = 0; i < psInfo->nPages; i++)
1690 hwndPage = psInfo->proppage[i].hwndPage;
1693 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1696 if (psInfo->isModeless)
1698 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1699 psInfo->activeValid = FALSE;
1702 EndDialog(hwndDlg, FALSE);
1705 /******************************************************************************
1708 static void PROPSHEET_Help(HWND hwndDlg)
1710 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1715 TRACE("active_page %d\n", psInfo->active_page);
1716 if (psInfo->active_page < 0)
1719 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1720 psn.hdr.code = PSN_HELP;
1721 psn.hdr.hwndFrom = hwndDlg;
1725 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1728 /******************************************************************************
1731 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1734 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1738 if (!psInfo) return;
1740 * Set the dirty flag of this page.
1742 for (i = 0; i < psInfo->nPages; i++)
1744 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1745 psInfo->proppage[i].isDirty = TRUE;
1749 * Enable the Apply button.
1751 if (psInfo->hasApply)
1753 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1755 EnableWindow(hwndApplyBtn, TRUE);
1759 /******************************************************************************
1760 * PROPSHEET_UnChanged
1762 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1765 BOOL noPageDirty = TRUE;
1766 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1767 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1771 if ( !psInfo ) return;
1772 for (i = 0; i < psInfo->nPages; i++)
1774 /* set the specified page as clean */
1775 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1776 psInfo->proppage[i].isDirty = FALSE;
1778 /* look to see if there's any dirty pages */
1779 if (psInfo->proppage[i].isDirty)
1780 noPageDirty = FALSE;
1784 * Disable Apply button.
1787 EnableWindow(hwndApplyBtn, FALSE);
1790 /******************************************************************************
1791 * PROPSHEET_PressButton
1793 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1795 TRACE("buttonID %d\n", buttonID);
1798 case PSBTN_APPLYNOW:
1799 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1802 PROPSHEET_Back(hwndDlg);
1805 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1808 PROPSHEET_Finish(hwndDlg);
1811 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1814 PROPSHEET_Next(hwndDlg);
1817 PROPSHEET_DoCommand(hwndDlg, IDOK);
1820 FIXME("Invalid button index %d\n", buttonID);
1825 /*************************************************************************
1826 * BOOL PROPSHEET_CanSetCurSel [Internal]
1828 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1831 * hwndDlg [I] handle to a Dialog hWnd
1834 * TRUE if Current Selection can change
1838 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1840 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1846 TRACE("active_page %d\n", psInfo->active_page);
1853 if (psInfo->active_page < 0)
1860 * Notify the current page.
1862 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1863 psn.hdr.code = PSN_KILLACTIVE;
1864 psn.hdr.hwndFrom = hwndDlg;
1868 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1871 TRACE("<-- %d\n", res);
1875 /******************************************************************************
1876 * PROPSHEET_SetCurSel
1878 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1881 HPROPSHEETPAGE hpage
1884 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1885 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1886 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1888 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1889 /* hpage takes precedence over index */
1891 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1893 if (index < 0 || index >= psInfo->nPages)
1895 TRACE("Could not find page to select!\n");
1904 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
1906 psn.hdr.code = PSN_SETACTIVE;
1907 psn.hdr.hwndFrom = hwndDlg;
1911 if (!psInfo->proppage[index].hwndPage) {
1912 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1913 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1916 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1923 FIXME("Tried to skip before first property sheet page!\n");
1926 if (index >= psInfo->nPages) {
1927 FIXME("Tried to skip after last property sheet page!\n");
1928 index = psInfo->nPages-1;
1932 else if (result != 0)
1934 index = PROPSHEET_FindPageByResId(psInfo, result);
1939 * Display the new page.
1941 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1943 if (psInfo->proppage[index].hasHelp)
1944 EnableWindow(hwndHelp, TRUE);
1946 EnableWindow(hwndHelp, FALSE);
1951 /******************************************************************************
1952 * PROPSHEET_SetCurSelId
1954 * Selects the page, specified by resource id.
1956 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
1959 PropSheetInfo* psInfo =
1960 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1962 idx = PROPSHEET_FindPageByResId(psInfo, id);
1963 if (idx < psInfo->nPages )
1965 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1966 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1970 /******************************************************************************
1971 * PROPSHEET_SetTitleA
1973 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1975 if(HIWORD(lpszText))
1978 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1979 szTitle, sizeof szTitle);
1980 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
1984 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
1988 /******************************************************************************
1989 * PROPSHEET_SetTitleW
1991 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
1993 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1996 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
1997 if (HIWORD(lpszText) == 0) {
1998 if (!LoadStringW(psInfo->ppshheader.hInstance,
1999 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
2003 if (dwStyle & PSH_PROPTITLE)
2006 int lentitle = strlenW(lpszText);
2007 int lenprop = strlenW(psInfo->strPropertiesFor);
2009 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2010 strcpyW(dest, psInfo->strPropertiesFor);
2011 strcatW(dest, lpszText);
2013 SetWindowTextW(hwndDlg, dest);
2014 COMCTL32_Free(dest);
2017 SetWindowTextW(hwndDlg, lpszText);
2020 /******************************************************************************
2021 * PROPSHEET_SetFinishTextA
2023 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2025 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2027 TRACE("'%s'\n", lpszText);
2028 /* Set text, show and enable the Finish button */
2029 SetWindowTextA(hwndButton, lpszText);
2030 ShowWindow(hwndButton, SW_SHOW);
2031 EnableWindow(hwndButton, TRUE);
2033 /* Make it default pushbutton */
2034 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2036 /* Hide Back button */
2037 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2038 ShowWindow(hwndButton, SW_HIDE);
2040 /* Hide Next button */
2041 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2042 ShowWindow(hwndButton, SW_HIDE);
2045 /******************************************************************************
2046 * PROPSHEET_SetFinishTextW
2048 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2050 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2052 TRACE("'%s'\n", debugstr_w(lpszText));
2053 /* Set text, show and enable the Finish button */
2054 SetWindowTextW(hwndButton, lpszText);
2055 ShowWindow(hwndButton, SW_SHOW);
2056 EnableWindow(hwndButton, TRUE);
2058 /* Make it default pushbutton */
2059 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2061 /* Hide Back button */
2062 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2063 ShowWindow(hwndButton, SW_HIDE);
2065 /* Hide Next button */
2066 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2067 ShowWindow(hwndButton, SW_HIDE);
2070 /******************************************************************************
2071 * PROPSHEET_QuerySiblings
2073 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2074 WPARAM wParam, LPARAM lParam)
2078 LRESULT msgResult = 0;
2079 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2082 while ((i < psInfo->nPages) && (msgResult == 0))
2084 hwndPage = psInfo->proppage[i].hwndPage;
2085 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2093 /******************************************************************************
2096 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2097 HPROPSHEETPAGE hpage)
2099 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2101 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2103 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2105 TRACE("hpage %p\n", hpage);
2107 * Allocate and fill in a new PropPageInfo entry.
2109 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
2110 sizeof(PropPageInfo) *
2111 (psInfo->nPages + 1));
2112 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
2115 psInfo->proppage[psInfo->nPages].hpage = hpage;
2117 if (ppsp->dwFlags & PSP_PREMATURE)
2119 /* Create the page but don't show it */
2120 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2124 * Add a new tab to the tab control.
2126 item.mask = TCIF_TEXT;
2127 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2128 item.cchTextMax = MAX_TABTEXT_LENGTH;
2130 if (psInfo->hImageList)
2132 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2135 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2137 item.mask |= TCIF_IMAGE;
2138 item.iImage = psInfo->nPages;
2141 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2146 /* If it is the only page - show it */
2147 if(psInfo->nPages == 1)
2148 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2152 /******************************************************************************
2153 * PROPSHEET_RemovePage
2155 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2157 HPROPSHEETPAGE hpage)
2159 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2161 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2162 PropPageInfo* oldPages;
2164 TRACE("index %d, hpage %p\n", index, hpage);
2168 oldPages = psInfo->proppage;
2170 * hpage takes precedence over index.
2174 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2177 /* Make sure that index is within range */
2178 if (index < 0 || index >= psInfo->nPages)
2180 TRACE("Could not find page to remove!\n");
2184 TRACE("total pages %d removing page %d active page %d\n",
2185 psInfo->nPages, index, psInfo->active_page);
2187 * Check if we're removing the active page.
2189 if (index == psInfo->active_page)
2191 if (psInfo->nPages > 1)
2195 /* activate previous page */
2196 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2200 /* activate the next page */
2201 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2202 psInfo->active_page = index;
2207 psInfo->active_page = -1;
2208 if (!psInfo->isModeless)
2210 EndDialog(hwndDlg, FALSE);
2215 else if (index < psInfo->active_page)
2216 psInfo->active_page--;
2218 /* Destroy page dialog window */
2219 DestroyWindow(psInfo->proppage[index].hwndPage);
2221 /* Free page resources */
2222 if(psInfo->proppage[index].hpage)
2224 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2226 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2227 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2229 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2232 /* Remove the tab */
2233 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2236 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2239 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2241 if (index < psInfo->nPages)
2242 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2243 (psInfo->nPages - index) * sizeof(PropPageInfo));
2245 COMCTL32_Free(oldPages);
2250 /******************************************************************************
2251 * PROPSHEET_SetWizButtons
2253 * This code will work if (and assumes that) the Next button is on top of the
2254 * Finish button. ie. Finish comes after Next in the Z order.
2255 * This means make sure the dialog template reflects this.
2258 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2260 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2261 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2262 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2264 TRACE("%ld\n", dwFlags);
2266 EnableWindow(hwndBack, FALSE);
2267 EnableWindow(hwndNext, FALSE);
2268 EnableWindow(hwndFinish, FALSE);
2270 if (dwFlags & PSWIZB_BACK)
2271 EnableWindow(hwndBack, TRUE);
2273 if (dwFlags & PSWIZB_NEXT)
2275 /* Hide the Finish button */
2276 ShowWindow(hwndFinish, SW_HIDE);
2278 /* Show and enable the Next button */
2279 ShowWindow(hwndNext, SW_SHOW);
2280 EnableWindow(hwndNext, TRUE);
2282 /* Set the Next button as the default pushbutton */
2283 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2286 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2288 /* Hide the Next button */
2289 ShowWindow(hwndNext, SW_HIDE);
2291 /* Show the Finish button */
2292 ShowWindow(hwndFinish, SW_SHOW);
2294 if (dwFlags & PSWIZB_FINISH)
2295 EnableWindow(hwndFinish, TRUE);
2297 /* Set the Finish button as the default pushbutton */
2298 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2302 /******************************************************************************
2303 * PROPSHEET_GetPageIndex
2305 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2306 * the array of PropPageInfo.
2308 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2313 TRACE("hpage %p\n", hpage);
2314 while ((index < psInfo->nPages) && (found == FALSE))
2316 if (psInfo->proppage[index].hpage == hpage)
2328 /******************************************************************************
2331 static void PROPSHEET_CleanUp(HWND hwndDlg)
2334 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2338 if (!psInfo) return;
2339 if (HIWORD(psInfo->ppshheader.pszCaption))
2340 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2342 for (i = 0; i < psInfo->nPages; i++)
2344 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2346 if(psInfo->proppage[i].hwndPage)
2347 DestroyWindow(psInfo->proppage[i].hwndPage);
2351 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2352 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2354 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2358 COMCTL32_Free(psInfo->proppage);
2359 COMCTL32_Free(psInfo->strPropertiesFor);
2360 ImageList_Destroy(psInfo->hImageList);
2362 GlobalFree((HGLOBAL)psInfo);
2365 /******************************************************************************
2366 * PropertySheet (COMCTL32.@)
2367 * PropertySheetA (COMCTL32.@)
2369 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2372 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2373 sizeof(PropSheetInfo));
2377 TRACE("(%p)\n", lppsh);
2379 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2381 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2383 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2385 for (n = i = 0; i < lppsh->nPages; i++, n++)
2387 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2388 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2391 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2392 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2395 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2398 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2399 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2405 bRet = PROPSHEET_CreateDialog(psInfo);
2410 /******************************************************************************
2411 * PropertySheetW (COMCTL32.@)
2413 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2416 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2417 sizeof(PropSheetInfo));
2421 TRACE("(%p)\n", lppsh);
2423 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2425 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2427 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2429 for (n = i = 0; i < lppsh->nPages; i++, n++)
2431 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2432 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2435 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2436 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2439 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2442 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2443 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2449 bRet = PROPSHEET_CreateDialog(psInfo);
2454 /******************************************************************************
2455 * CreatePropertySheetPage (COMCTL32.@)
2456 * CreatePropertySheetPageA (COMCTL32.@)
2458 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2459 LPCPROPSHEETPAGEA lpPropSheetPage)
2461 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2463 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2465 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2467 PROPSHEET_AtoW(&ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate);
2469 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2471 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2474 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2476 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2478 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2479 ppsp->pszTitle = NULL;
2481 return (HPROPSHEETPAGE)ppsp;
2484 /******************************************************************************
2485 * CreatePropertySheetPageW (COMCTL32.@)
2487 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2489 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2491 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2493 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2495 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2497 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2498 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2500 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2502 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2503 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2504 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2507 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2509 int len = strlenW(lpPropSheetPage->pszTitle);
2510 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2511 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2513 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2514 ppsp->pszTitle = NULL;
2516 return (HPROPSHEETPAGE)ppsp;
2519 /******************************************************************************
2520 * DestroyPropertySheetPage (COMCTL32.@)
2522 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2524 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2529 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2530 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2532 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2533 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2535 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2536 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2538 COMCTL32_Free(hPropPage);
2543 /******************************************************************************
2544 * PROPSHEET_IsDialogMessage
2546 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2548 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2551 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2554 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2557 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2559 if (!(dlgCode & DLGC_WANTMESSAGE))
2561 switch (lpMsg->wParam)
2564 if (GetKeyState(VK_SHIFT) & 0x8000)
2570 case VK_NEXT: new_page = 1; break;
2571 case VK_PRIOR: new_page = -1; break;
2577 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2579 new_page += psInfo->active_page;
2582 new_page = psInfo->nPages - 1;
2583 else if (new_page >= psInfo->nPages)
2586 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2593 return IsDialogMessageA(hwnd, lpMsg);
2596 /******************************************************************************
2597 * PROPSHEET_DoCommand
2599 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2605 case IDC_APPLY_BUTTON:
2607 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2609 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2614 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2618 if (psInfo->restartWindows)
2619 result = ID_PSRESTARTWINDOWS;
2621 /* reboot system takes precedence over restart windows */
2622 if (psInfo->rebootSystem)
2623 result = ID_PSREBOOTSYSTEM;
2625 if (psInfo->isModeless)
2626 psInfo->activeValid = FALSE;
2628 EndDialog(hwnd, result);
2631 EnableWindow(hwndApplyBtn, FALSE);
2636 case IDC_BACK_BUTTON:
2637 PROPSHEET_Back(hwnd);
2640 case IDC_NEXT_BUTTON:
2641 PROPSHEET_Next(hwnd);
2644 case IDC_FINISH_BUTTON:
2645 PROPSHEET_Finish(hwnd);
2649 PROPSHEET_Cancel(hwnd, 0);
2653 PROPSHEET_Help(hwnd);
2660 /******************************************************************************
2661 * PROPSHEET_DialogProc
2664 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2666 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
2667 hwnd, uMsg, wParam, lParam);
2673 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2674 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2675 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2676 LPCPROPSHEETPAGEW ppshpage;
2679 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2682 * psInfo->hwnd is not being used by WINE code - it exists
2683 * for compatibility with "real" Windoze. The same about
2684 * SetWindowLong - WINE is only using the PropSheetInfoStr
2687 psInfo->hwnd = hwnd;
2688 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2691 * Small icon in the title bar.
2693 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2694 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2697 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2698 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2700 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2701 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2702 psInfo->ppshheader.u.pszIcon,
2707 hIcon = psInfo->ppshheader.u.hIcon;
2709 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
2712 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2713 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
2715 psInfo->strPropertiesFor = strCaption;
2717 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2719 PROPSHEET_CreateTabControl(hwnd, psInfo);
2721 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2723 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2725 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2726 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2731 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2733 PROPSHEET_AdjustSize(hwnd, psInfo);
2734 PROPSHEET_AdjustButtons(hwnd, psInfo);
2738 if (psInfo->useCallback)
2739 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2740 PSCB_INITIALIZED, (LPARAM)0);
2742 idx = psInfo->active_page;
2743 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2744 psInfo->active_page = -1;
2746 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2748 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2749 * as some programs call TCM_GETCURSEL to get the current selection
2750 * from which to switch to the next page */
2751 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2753 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2754 psInfo->ppshheader.hInstance)
2758 if (LoadStringW(psInfo->ppshheader.hInstance,
2759 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2760 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2764 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2765 psInfo->ppshheader.pszCaption);
2772 PROPSHEET_CleanUp(hwnd);
2776 PROPSHEET_Cancel(hwnd, 1);
2780 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2784 NMHDR* pnmh = (LPNMHDR) lParam;
2786 if (pnmh->code == TCN_SELCHANGE)
2788 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2789 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2792 if(pnmh->code == TCN_SELCHANGING)
2794 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2795 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2802 case PSM_GETCURRENTPAGEHWND:
2804 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2808 if (psInfo->activeValid && psInfo->active_page != -1)
2809 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2811 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndPage);
2817 PROPSHEET_Changed(hwnd, (HWND)wParam);
2821 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2824 case PSM_GETTABCONTROL:
2826 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2828 SetWindowLongW(hwnd, DWL_MSGRESULT, (LONG)hwndTabCtrl);
2837 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2838 if(msgResult != FALSE)
2840 msgResult = PROPSHEET_SetCurSel(hwnd,
2843 (HPROPSHEETPAGE)lParam);
2846 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2851 case PSM_CANCELTOCLOSE:
2853 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2854 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2855 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2857 EnableWindow(hwndCancel, FALSE);
2858 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2859 SetWindowTextW(hwndOK, buf);
2864 case PSM_RESTARTWINDOWS:
2866 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2869 psInfo->restartWindows = TRUE;
2873 case PSM_REBOOTSYSTEM:
2875 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2878 psInfo->rebootSystem = TRUE;
2883 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2887 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2892 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2894 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2899 case PSM_QUERYSIBLINGS:
2901 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2903 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2911 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2912 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2913 * on success or FALSE otherwise, as specified on MSDN Online.
2914 * Also see the MFC code for
2915 * CPropertySheet::AddPage(CPropertyPage* pPage).
2918 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2920 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2925 case PSM_REMOVEPAGE:
2926 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2929 case PSM_ISDIALOGMESSAGE:
2931 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2932 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2936 case PSM_PRESSBUTTON:
2937 PROPSHEET_PressButton(hwnd, (int)wParam);
2940 case PSM_SETFINISHTEXTA:
2941 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2944 case PSM_SETWIZBUTTONS:
2945 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2948 case PSM_SETCURSELID:
2949 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
2952 case PSM_SETFINISHTEXTW:
2953 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);