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 /******************************************************************************
48 typedef struct tagPropPageInfo
50 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
59 typedef struct tagPropSheetInfo
62 PROPSHEETHEADERW ppshheader;
63 LPWSTR strPropertiesFor;
73 PropPageInfo* proppage;
78 HIMAGELIST hImageList;
87 /******************************************************************************
88 * Defines and global variables
91 const WCHAR PropSheetInfoStr[] =
92 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
94 #define MAX_CAPTION_LENGTH 255
95 #define MAX_TABTEXT_LENGTH 255
96 #define MAX_BUTTONTEXT_LENGTH 64
98 #define PSH_WIZARD97_OLD 0x00002000
99 #define PSH_WIZARD97_NEW 0x01000000
100 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
102 /******************************************************************************
105 static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
106 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
107 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
108 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
109 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
110 PropSheetInfo * psInfo);
111 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
112 PropSheetInfo * psInfo);
113 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
114 PropSheetInfo * psInfo,
116 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
117 PropSheetInfo * psInfo);
118 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
119 const PropSheetInfo * psInfo,
120 LPCPROPSHEETPAGEW ppshpage);
121 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
122 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
123 static BOOL PROPSHEET_Back(HWND hwndDlg);
124 static BOOL PROPSHEET_Next(HWND hwndDlg);
125 static BOOL PROPSHEET_Finish(HWND hwndDlg);
126 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
127 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
128 static void PROPSHEET_Help(HWND hwndDlg);
129 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
130 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
131 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
132 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
133 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
134 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
135 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
136 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
137 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
140 HPROPSHEETPAGE hpage);
141 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id);
142 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
143 WPARAM wParam, LPARAM lParam);
144 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
145 HPROPSHEETPAGE hpage);
147 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
149 HPROPSHEETPAGE hpage);
150 static void PROPSHEET_CleanUp();
151 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
152 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
153 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
154 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
155 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
158 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
160 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
162 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
163 /******************************************************************************
164 * PROPSHEET_UnImplementedFlags
166 * Document use of flags we don't implement yet.
168 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
175 * unhandled header flags:
176 * PSH_DEFAULT 0x00000000
177 * PSH_WIZARDHASFINISH 0x00000010
178 * PSH_RTLREADING 0x00000800
179 * PSH_WIZARDCONTEXTHELP 0x00001000
180 * PSH_WIZARD97 0x00002000 (pre IE 5)
181 * PSH_WATERMARK 0x00008000
182 * PSH_USEHBMWATERMARK 0x00010000
183 * PSH_USEHPLWATERMARK 0x00020000
184 * PSH_STRETCHWATERMARK 0x00040000
185 * PSH_HEADER 0x00080000
186 * PSH_USEHBMHEADER 0x00100000
187 * PSH_USEPAGELANG 0x00200000
188 * PSH_WIZARD_LITE 0x00400000 also not in .h
189 * PSH_WIZARD97 0x01000000 (IE 5 and above)
190 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
193 add_flag(PSH_WIZARDHASFINISH);
194 add_flag(PSH_RTLREADING);
195 add_flag(PSH_WIZARDCONTEXTHELP);
196 add_flag(PSH_WIZARD97_OLD);
197 add_flag(PSH_WATERMARK);
198 add_flag(PSH_USEHBMWATERMARK);
199 add_flag(PSH_USEHPLWATERMARK);
200 add_flag(PSH_STRETCHWATERMARK);
201 add_flag(PSH_HEADER);
202 add_flag(PSH_USEHBMHEADER);
203 add_flag(PSH_USEPAGELANG);
204 add_flag(PSH_WIZARD_LITE);
205 add_flag(PSH_WIZARD97_NEW);
206 add_flag(PSH_NOCONTEXTHELP);
207 if (string[0] != '\0')
208 FIXME("%s\n", string);
212 /******************************************************************************
213 * PROPSHEET_GetPageRect
215 * Retrieve rect from tab control and map into the dialog for SetWindowPos
217 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
219 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
221 GetClientRect(hwndTabCtrl, rc);
222 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
223 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
226 /******************************************************************************
227 * PROPSHEET_FindPageByResId
229 * Find page index corresponding to page resource id.
231 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
235 for (i = 0; i < psInfo->nPages; i++)
237 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
239 /* Fixme: if resource ID is a string shall we use strcmp ??? */
240 if (lppsp->u.pszTemplate == (LPVOID)resId)
247 /******************************************************************************
250 * Convert ASCII to Unicode since all data is saved as Unicode.
252 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
256 TRACE("<%s>\n", frstr);
257 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
258 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
259 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
262 /******************************************************************************
263 * PROPSHEET_CollectSheetInfoA
265 * Collect relevant data.
267 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
268 PropSheetInfo * psInfo)
270 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
271 DWORD dwFlags = lppsh->dwFlags;
273 psInfo->hasHelp = dwFlags & PSH_HASHELP;
274 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
275 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
276 psInfo->isModeless = dwFlags & PSH_MODELESS;
278 memcpy(&psInfo->ppshheader,lppsh,dwSize);
279 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",
280 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
281 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
283 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
285 if (HIWORD(lppsh->pszCaption))
287 int len = strlen(lppsh->pszCaption);
288 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
289 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
290 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
292 psInfo->nPages = lppsh->nPages;
294 if (dwFlags & PSH_USEPSTARTPAGE)
296 TRACE("PSH_USEPSTARTPAGE is on");
297 psInfo->active_page = 0;
300 psInfo->active_page = lppsh->u2.nStartPage;
302 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
303 psInfo->active_page = 0;
305 psInfo->restartWindows = FALSE;
306 psInfo->rebootSystem = FALSE;
307 psInfo->hImageList = 0;
308 psInfo->activeValid = FALSE;
313 /******************************************************************************
314 * PROPSHEET_CollectSheetInfoW
316 * Collect relevant data.
318 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
319 PropSheetInfo * psInfo)
321 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
322 DWORD dwFlags = lppsh->dwFlags;
324 psInfo->hasHelp = dwFlags & PSH_HASHELP;
325 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
326 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
327 psInfo->isModeless = dwFlags & PSH_MODELESS;
329 memcpy(&psInfo->ppshheader,lppsh,dwSize);
330 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",
331 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
333 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
335 if (HIWORD(lppsh->pszCaption))
337 int len = strlenW(lppsh->pszCaption);
338 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
339 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
341 psInfo->nPages = lppsh->nPages;
343 if (dwFlags & PSH_USEPSTARTPAGE)
345 TRACE("PSH_USEPSTARTPAGE is on");
346 psInfo->active_page = 0;
349 psInfo->active_page = lppsh->u2.nStartPage;
351 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
352 psInfo->active_page = 0;
354 psInfo->restartWindows = FALSE;
355 psInfo->rebootSystem = FALSE;
356 psInfo->hImageList = 0;
357 psInfo->activeValid = FALSE;
362 /******************************************************************************
363 * PROPSHEET_CollectPageInfo
365 * Collect property sheet data.
366 * With code taken from DIALOG_ParseTemplate32.
368 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
369 PropSheetInfo * psInfo,
372 DLGTEMPLATE* pTemplate;
378 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
379 psInfo->proppage[index].hwndPage = 0;
380 psInfo->proppage[index].isDirty = FALSE;
383 * Process property page flags.
385 dwFlags = lppsp->dwFlags;
386 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
387 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
388 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
390 /* as soon as we have a page with the help flag, set the sheet flag on */
391 if (psInfo->proppage[index].hasHelp)
392 psInfo->hasHelp = TRUE;
395 * Process page template.
397 if (dwFlags & PSP_DLGINDIRECT)
398 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
401 HRSRC hResource = FindResourceW(lppsp->hInstance,
402 lppsp->u.pszTemplate,
404 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
406 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
410 * Extract the size of the page and the caption.
415 p = (const WORD *)pTemplate;
417 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
419 /* DIALOGEX template */
423 p += 2; /* help ID */
424 p += 2; /* ext style */
429 /* DIALOG template */
432 p += 2; /* ext style */
438 width = (WORD)*p; p++;
439 height = (WORD)*p; p++;
441 /* remember the largest width and height */
442 if (width > psInfo->width)
443 psInfo->width = width;
445 if (height > psInfo->height)
446 psInfo->height = height;
458 p += lstrlenW( (LPCWSTR)p ) + 1;
472 p += lstrlenW( (LPCWSTR)p ) + 1;
476 /* Extract the caption */
477 psInfo->proppage[index].pszText = (LPCWSTR)p;
478 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
479 p += lstrlenW((LPCWSTR)p) + 1;
481 if (dwFlags & PSP_USETITLE)
485 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
488 if ( !HIWORD( lppsp->pszTitle ) )
490 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
493 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
499 pTitle = lppsp->pszTitle;
501 len = strlenW(pTitle);
502 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
503 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
507 * Build the image list for icons
509 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
512 int icon_cx = GetSystemMetrics(SM_CXSMICON);
513 int icon_cy = GetSystemMetrics(SM_CYSMICON);
515 if (dwFlags & PSP_USEICONID)
516 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
517 icon_cx, icon_cy, LR_DEFAULTCOLOR);
519 hIcon = lppsp->u2.hIcon;
523 if (psInfo->hImageList == 0 )
524 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
526 ImageList_AddIcon(psInfo->hImageList, hIcon);
534 /******************************************************************************
535 * PROPSHEET_CreateDialog
537 * Creates the actual property sheet.
539 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
546 WORD resID = IDD_PROPSHEET;
549 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
552 if(!(hRes = FindResourceW(COMCTL32_hModule,
553 MAKEINTRESOURCEW(resID),
557 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
561 * Make a copy of the dialog template.
563 resSize = SizeofResource(COMCTL32_hModule, hRes);
565 temp = COMCTL32_Alloc(resSize);
570 memcpy(temp, template, resSize);
572 if (psInfo->useCallback)
573 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
575 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
576 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
577 (LPDLGTEMPLATEW) temp,
578 psInfo->ppshheader.hwndParent,
579 (DLGPROC) PROPSHEET_DialogProc,
582 ret = CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
583 (LPDLGTEMPLATEW) temp,
584 psInfo->ppshheader.hwndParent,
585 (DLGPROC) PROPSHEET_DialogProc,
593 /******************************************************************************
594 * PROPSHEET_SizeMismatch
596 * Verify that the tab control and the "largest" property sheet page dlg. template
599 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
601 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
602 RECT rcOrigTab, rcPage;
607 GetClientRect(hwndTabCtrl, &rcOrigTab);
608 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
609 rcOrigTab.right, rcOrigTab.bottom);
614 rcPage.left = psInfo->x;
615 rcPage.top = psInfo->y;
616 rcPage.right = psInfo->width;
617 rcPage.bottom = psInfo->height;
619 MapDialogRect(hwndDlg, &rcPage);
620 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
621 rcPage.right, rcPage.bottom);
623 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
625 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
631 /******************************************************************************
632 * PROPSHEET_IsTooSmallWizard
634 * Verify that the default property sheet is big enough.
636 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
638 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
639 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
640 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
642 GetClientRect(hwndDlg, &rcSheetClient);
643 GetWindowRect(hwndDlg, &rcSheetRect);
644 GetWindowRect(hwndLine, &rcLine);
646 /* Remove the space below the sunken line */
647 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
649 /* Remove the buffer zone all around the edge */
650 rcSheetClient.bottom -= (padding.y * 2);
651 rcSheetClient.right -= (padding.x * 2);
656 rcPage.left = psInfo->x;
657 rcPage.top = psInfo->y;
658 rcPage.right = psInfo->width;
659 rcPage.bottom = psInfo->height;
661 MapDialogRect(hwndDlg, &rcPage);
662 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
663 rcPage.right, rcPage.bottom);
665 if (rcPage.right > rcSheetClient.right)
668 if (rcPage.bottom > rcSheetClient.bottom)
674 /******************************************************************************
675 * PROPSHEET_AdjustSize
677 * Resizes the property sheet and the tab control to fit the largest page.
679 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
681 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
682 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
684 int tabOffsetX, tabOffsetY, buttonHeight;
685 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
688 /* Get the height of buttons */
689 GetClientRect(hwndButton, &rc);
690 buttonHeight = rc.bottom;
697 rc.right = psInfo->width;
698 rc.bottom = psInfo->height;
700 MapDialogRect(hwndDlg, &rc);
702 /* retrieve the dialog units */
703 units.left = units.right = 4;
704 units.top = units.bottom = 8;
705 MapDialogRect(hwndDlg, &units);
708 * Resize the tab control.
710 GetClientRect(hwndTabCtrl,&tabRect);
712 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
714 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
716 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
717 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
720 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
722 rc.right = rc.left + tabRect.right - tabRect.left;
723 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
726 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
728 tabOffsetX = -(rc.left);
729 tabOffsetY = -(rc.top);
733 TRACE("setting tab %08lx, rc (0,0)-(%d,%d)\n",
734 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
735 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
736 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
738 GetClientRect(hwndTabCtrl, &rc);
740 TRACE("tab client rc %d %d %d %d\n",
741 rc.left, rc.top, rc.right, rc.bottom);
743 rc.right += ((padding.x * 2) + tabOffsetX);
744 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
747 * Resize the property sheet.
749 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
750 (DWORD)hwndDlg, rc.right, rc.bottom);
751 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
752 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
756 /******************************************************************************
757 * PROPSHEET_AdjustSizeWizard
759 * Resizes the property sheet to fit the largest page.
761 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
763 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
764 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
765 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
767 int buttonHeight, lineHeight;
768 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
771 /* Get the height of buttons */
772 GetClientRect(hwndButton, &rc);
773 buttonHeight = rc.bottom;
775 GetClientRect(hwndLine, &rc);
776 lineHeight = rc.bottom;
778 /* retrieve the dialog units */
779 units.left = units.right = 4;
780 units.top = units.bottom = 8;
781 MapDialogRect(hwndDlg, &units);
788 rc.right = psInfo->width;
789 rc.bottom = psInfo->height;
791 MapDialogRect(hwndDlg, &rc);
793 GetClientRect(hwndTabCtrl,&tabRect);
795 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
797 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
798 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
801 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
803 rc.right = rc.left + tabRect.right - tabRect.left;
804 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
807 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
808 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
809 padding.x, padding.y, buttonHeight, lineHeight);
812 rc.right += (padding.x * 2);
813 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
816 * Resize the property sheet.
818 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
819 (DWORD)hwndDlg, rc.right, rc.bottom);
820 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
821 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
825 /******************************************************************************
826 * PROPSHEET_AdjustButtons
828 * Adjusts the buttons' positions.
830 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
832 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
836 int buttonWidth, buttonHeight;
837 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
839 if (psInfo->hasApply)
846 * Obtain the size of the buttons.
848 GetClientRect(hwndButton, &rcSheet);
849 buttonWidth = rcSheet.right;
850 buttonHeight = rcSheet.bottom;
853 * Get the size of the property sheet.
855 GetClientRect(hwndParent, &rcSheet);
858 * All buttons will be at this y coordinate.
860 y = rcSheet.bottom - (padding.y + buttonHeight);
863 * Position OK button.
865 hwndButton = GetDlgItem(hwndParent, IDOK);
867 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
869 SetWindowPos(hwndButton, 0, x, y, 0, 0,
870 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
873 * Position Cancel button.
875 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
877 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
879 SetWindowPos(hwndButton, 0, x, y, 0, 0,
880 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
883 * Position Apply button.
885 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
887 if (psInfo->hasApply)
890 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
892 x = rcSheet.right - (padding.x + buttonWidth);
894 SetWindowPos(hwndButton, 0, x, y, 0, 0,
895 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
897 EnableWindow(hwndButton, FALSE);
900 ShowWindow(hwndButton, SW_HIDE);
903 * Position Help button.
905 hwndButton = GetDlgItem(hwndParent, IDHELP);
909 x = rcSheet.right - (padding.x + buttonWidth);
911 SetWindowPos(hwndButton, 0, x, y, 0, 0,
912 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
915 ShowWindow(hwndButton, SW_HIDE);
920 /******************************************************************************
921 * PROPSHEET_AdjustButtonsWizard
923 * Adjusts the buttons' positions.
925 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
926 PropSheetInfo* psInfo)
928 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
929 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
933 int buttonWidth, buttonHeight, lineHeight, lineWidth;
934 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
940 * Obtain the size of the buttons.
942 GetClientRect(hwndButton, &rcSheet);
943 buttonWidth = rcSheet.right;
944 buttonHeight = rcSheet.bottom;
946 GetClientRect(hwndLine, &rcSheet);
947 lineHeight = rcSheet.bottom;
950 * Get the size of the property sheet.
952 GetClientRect(hwndParent, &rcSheet);
955 * All buttons will be at this y coordinate.
957 y = rcSheet.bottom - (padding.y + buttonHeight);
960 * Position the Next and the Finish buttons.
962 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
964 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
966 SetWindowPos(hwndButton, 0, x, y, 0, 0,
967 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
969 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
971 SetWindowPos(hwndButton, 0, x, y, 0, 0,
972 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
974 ShowWindow(hwndButton, SW_HIDE);
977 * Position the Back button.
979 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
983 SetWindowPos(hwndButton, 0, x, y, 0, 0,
984 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
987 * Position the Cancel button.
989 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
991 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
993 SetWindowPos(hwndButton, 0, x, y, 0, 0,
994 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
997 * Position Help button.
999 hwndButton = GetDlgItem(hwndParent, IDHELP);
1001 if (psInfo->hasHelp)
1003 x = rcSheet.right - (padding.x + buttonWidth);
1005 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1006 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1009 ShowWindow(hwndButton, SW_HIDE);
1012 * Position and resize the sunken line.
1015 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1017 GetClientRect(hwndParent, &rcSheet);
1018 lineWidth = rcSheet.right - (padding.x * 2);
1020 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1021 SWP_NOZORDER | SWP_NOACTIVATE);
1026 /******************************************************************************
1027 * PROPSHEET_GetPaddingInfo
1029 * Returns the layout information.
1031 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1033 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1036 PADDING_INFO padding;
1038 GetWindowRect(hwndTab, &rcTab);
1043 ScreenToClient(hwndDlg, &tl);
1051 /******************************************************************************
1052 * PROPSHEET_GetPaddingInfoWizard
1054 * Returns the layout information.
1055 * Vertical spacing is the distance between the line and the buttons.
1056 * Do NOT use the Help button to gather padding information when it isn't mapped
1057 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1058 * for it in this case !
1059 * FIXME: I'm not sure about any other coordinate problems with these evil
1060 * buttons. Fix it in case additional problems appear or maybe calculate
1061 * a padding in a completely different way, as this is somewhat messy.
1063 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1066 PADDING_INFO padding;
1070 POINT ptButton, ptLine;
1073 if (psInfo->hasHelp)
1079 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1081 idButton = IDC_NEXT_BUTTON;
1085 /* hopefully this is ok */
1086 idButton = IDCANCEL;
1090 hwndControl = GetDlgItem(hwndDlg, idButton);
1091 GetWindowRect(hwndControl, &rc);
1093 ptButton.x = rc.left;
1094 ptButton.y = rc.top;
1096 ScreenToClient(hwndDlg, &ptButton);
1099 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1100 GetWindowRect(hwndControl, &rc);
1103 ptLine.y = rc.bottom;
1105 ScreenToClient(hwndDlg, &ptLine);
1107 padding.y = ptButton.y - ptLine.y;
1110 ERR("padding negative ! Please report this !\n");
1112 /* this is most probably not correct, but the best we have now */
1113 padding.x = padding.y;
1117 /******************************************************************************
1118 * PROPSHEET_CreateTabControl
1120 * Insert the tabs in the tab control.
1122 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1123 PropSheetInfo * psInfo)
1125 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1131 item.mask = TCIF_TEXT;
1132 item.cchTextMax = MAX_TABTEXT_LENGTH;
1134 nTabs = psInfo->nPages;
1137 * Set the image list for icons.
1139 if (psInfo->hImageList)
1141 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1144 for (i = 0; i < nTabs; i++)
1146 if ( psInfo->proppage[i].hasIcon )
1148 item.mask |= TCIF_IMAGE;
1149 item.iImage = iImage++;
1153 item.mask &= ~TCIF_IMAGE;
1156 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1157 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1163 /******************************************************************************
1164 * PROPSHEET_CreatePage
1168 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1170 const PropSheetInfo * psInfo,
1171 LPCPROPSHEETPAGEW ppshpage)
1173 DLGTEMPLATE* pTemplate;
1176 PropPageInfo* ppInfo = psInfo->proppage;
1177 PADDING_INFO padding;
1178 UINT pageWidth,pageHeight;
1182 TRACE("index %d\n", index);
1184 if (ppshpage == NULL)
1189 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1190 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1196 hResource = FindResourceW(ppshpage->hInstance,
1197 ppshpage->u.pszTemplate,
1202 resSize = SizeofResource(ppshpage->hInstance, hResource);
1204 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1208 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1210 * Make a copy of the dialog template to make it writable
1212 temp = COMCTL32_Alloc(resSize);
1216 memcpy(temp, pTemplate, resSize);
1220 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1222 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1223 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1224 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1225 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1226 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1227 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1228 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1229 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1233 pTemplate->style |= WS_CHILD | DS_CONTROL;
1234 pTemplate->style &= ~DS_MODALFRAME;
1235 pTemplate->style &= ~WS_CAPTION;
1236 pTemplate->style &= ~WS_SYSMENU;
1237 pTemplate->style &= ~WS_POPUP;
1238 pTemplate->style &= ~WS_DISABLED;
1239 pTemplate->style &= ~WS_VISIBLE;
1240 pTemplate->style &= ~WS_THICKFRAME;
1243 if (psInfo->proppage[index].useCallback)
1244 (*(ppshpage->pfnCallback))(hwndParent,
1246 (LPPROPSHEETPAGEW)ppshpage);
1248 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1251 ppshpage->pfnDlgProc,
1253 /* Free a no more needed copy */
1255 COMCTL32_Free(temp);
1257 ppInfo[index].hwndPage = hwndPage;
1259 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1260 /* FIXME: This code may no longer be correct.
1261 * It was not for the non-wizard path. (GLA 6/02)
1263 rc.left = psInfo->x;
1265 rc.right = psInfo->width;
1266 rc.bottom = psInfo->height;
1268 MapDialogRect(hwndParent, &rc);
1270 pageWidth = rc.right - rc.left;
1271 pageHeight = rc.bottom - rc.top;
1273 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1274 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d, padx=%d, pady=%d\n",
1275 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1276 pageWidth, pageHeight, padding.x, padding.y);
1277 SetWindowPos(hwndPage, HWND_TOP,
1278 rc.left + padding.x/2,
1279 rc.top + padding.y/2,
1280 pageWidth, pageHeight, 0);
1284 * Ask the Tab control to reduce the client rectangle to that
1287 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1288 pageWidth = rc.right - rc.left;
1289 pageHeight = rc.bottom - rc.top;
1290 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
1291 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1292 pageWidth, pageHeight);
1293 SetWindowPos(hwndPage, HWND_TOP,
1295 pageWidth, pageHeight, 0);
1301 /******************************************************************************
1302 * PROPSHEET_ShowPage
1304 * Displays or creates the specified page.
1306 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1310 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1311 if (index == psInfo->active_page)
1313 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1314 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1318 if (psInfo->proppage[index].hwndPage == 0)
1320 LPCPROPSHEETPAGEW ppshpage;
1322 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1323 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1326 if (psInfo->active_page != -1)
1327 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1329 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1331 /* Synchronize current selection with tab control
1332 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1333 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1334 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1336 psInfo->active_page = index;
1337 psInfo->activeValid = TRUE;
1342 /******************************************************************************
1345 static BOOL PROPSHEET_Back(HWND hwndDlg)
1349 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1354 TRACE("active_page %d\n", psInfo->active_page);
1355 if (psInfo->active_page < 0)
1358 psn.hdr.code = PSN_WIZBACK;
1359 psn.hdr.hwndFrom = hwndDlg;
1363 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1365 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1368 else if (result == 0)
1369 idx = psInfo->active_page - 1;
1371 idx = PROPSHEET_FindPageByResId(psInfo, result);
1373 if (idx >= 0 && idx < psInfo->nPages)
1375 if (PROPSHEET_CanSetCurSel(hwndDlg))
1376 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1381 /******************************************************************************
1384 static BOOL PROPSHEET_Next(HWND hwndDlg)
1388 LRESULT msgResult = 0;
1389 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1393 TRACE("active_page %d\n", psInfo->active_page);
1394 if (psInfo->active_page < 0)
1397 psn.hdr.code = PSN_WIZNEXT;
1398 psn.hdr.hwndFrom = hwndDlg;
1402 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1404 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1405 if (msgResult == -1)
1407 else if (msgResult == 0)
1408 idx = psInfo->active_page + 1;
1410 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1412 if (idx < psInfo->nPages )
1414 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1415 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1421 /******************************************************************************
1424 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1428 LRESULT msgResult = 0;
1429 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1432 TRACE("active_page %d\n", psInfo->active_page);
1433 if (psInfo->active_page < 0)
1436 psn.hdr.code = PSN_WIZFINISH;
1437 psn.hdr.hwndFrom = hwndDlg;
1441 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1443 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1445 TRACE("msg result %ld\n", msgResult);
1450 if (psInfo->isModeless)
1451 psInfo->activeValid = FALSE;
1453 EndDialog(hwndDlg, TRUE);
1458 /******************************************************************************
1461 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1467 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1470 TRACE("active_page %d\n", psInfo->active_page);
1471 if (psInfo->active_page < 0)
1474 psn.hdr.hwndFrom = hwndDlg;
1480 * Send PSN_KILLACTIVE to the current page.
1482 psn.hdr.code = PSN_KILLACTIVE;
1484 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1486 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1490 * Send PSN_APPLY to all pages.
1492 psn.hdr.code = PSN_APPLY;
1493 psn.lParam = lParam;
1495 for (i = 0; i < psInfo->nPages; i++)
1497 hwndPage = psInfo->proppage[i].hwndPage;
1500 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1501 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1508 psInfo->activeValid = FALSE;
1510 else if(psInfo->active_page >= 0)
1512 psn.hdr.code = PSN_SETACTIVE;
1514 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1515 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1521 /******************************************************************************
1524 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1526 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1532 TRACE("active_page %d\n", psInfo->active_page);
1533 if (psInfo->active_page < 0)
1536 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1537 psn.hdr.code = PSN_QUERYCANCEL;
1538 psn.hdr.hwndFrom = hwndDlg;
1542 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1545 psn.hdr.code = PSN_RESET;
1546 psn.lParam = lParam;
1548 for (i = 0; i < psInfo->nPages; i++)
1550 hwndPage = psInfo->proppage[i].hwndPage;
1553 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1556 if (psInfo->isModeless)
1558 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1559 psInfo->activeValid = FALSE;
1562 EndDialog(hwndDlg, FALSE);
1565 /******************************************************************************
1568 static void PROPSHEET_Help(HWND hwndDlg)
1570 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1575 TRACE("active_page %d\n", psInfo->active_page);
1576 if (psInfo->active_page < 0)
1579 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1580 psn.hdr.code = PSN_HELP;
1581 psn.hdr.hwndFrom = hwndDlg;
1585 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1588 /******************************************************************************
1591 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1594 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1598 if (!psInfo) return;
1600 * Set the dirty flag of this page.
1602 for (i = 0; i < psInfo->nPages; i++)
1604 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1605 psInfo->proppage[i].isDirty = TRUE;
1609 * Enable the Apply button.
1611 if (psInfo->hasApply)
1613 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1615 EnableWindow(hwndApplyBtn, TRUE);
1619 /******************************************************************************
1620 * PROPSHEET_UnChanged
1622 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1625 BOOL noPageDirty = TRUE;
1626 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1627 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1631 if ( !psInfo ) return;
1632 for (i = 0; i < psInfo->nPages; i++)
1634 /* set the specified page as clean */
1635 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1636 psInfo->proppage[i].isDirty = FALSE;
1638 /* look to see if there's any dirty pages */
1639 if (psInfo->proppage[i].isDirty)
1640 noPageDirty = FALSE;
1644 * Disable Apply button.
1647 EnableWindow(hwndApplyBtn, FALSE);
1650 /******************************************************************************
1651 * PROPSHEET_PressButton
1653 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1655 TRACE("buttonID %d\n", buttonID);
1658 case PSBTN_APPLYNOW:
1659 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1662 PROPSHEET_Back(hwndDlg);
1665 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1668 PROPSHEET_Finish(hwndDlg);
1671 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1674 PROPSHEET_Next(hwndDlg);
1677 PROPSHEET_DoCommand(hwndDlg, IDOK);
1680 FIXME("Invalid button index %d\n", buttonID);
1685 /*************************************************************************
1686 * BOOL PROPSHEET_CanSetCurSel [Internal]
1688 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1691 * hwndDlg [I] handle to a Dialog hWnd
1694 * TRUE if Current Selection can change
1698 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1700 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1706 TRACE("active_page %d\n", psInfo->active_page);
1713 if (psInfo->active_page < 0)
1720 * Notify the current page.
1722 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1723 psn.hdr.code = PSN_KILLACTIVE;
1724 psn.hdr.hwndFrom = hwndDlg;
1728 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1731 TRACE("<-- %d\n", res);
1735 /******************************************************************************
1736 * PROPSHEET_SetCurSel
1738 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1741 HPROPSHEETPAGE hpage
1744 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1745 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1746 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1748 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1749 /* hpage takes precedence over index */
1751 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1753 if (index < 0 || index >= psInfo->nPages)
1755 TRACE("Could not find page to select!\n");
1764 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
1766 psn.hdr.code = PSN_SETACTIVE;
1767 psn.hdr.hwndFrom = hwndDlg;
1771 if (!psInfo->proppage[index].hwndPage) {
1772 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1773 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1776 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1783 FIXME("Tried to skip before first property sheet page!\n");
1786 if (index >= psInfo->nPages) {
1787 FIXME("Tried to skip after last property sheet page!\n");
1788 index = psInfo->nPages-1;
1792 else if (result != 0)
1794 index = PROPSHEET_FindPageByResId(psInfo, result);
1799 * Display the new page.
1801 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1803 if (psInfo->proppage[index].hasHelp)
1804 EnableWindow(hwndHelp, TRUE);
1806 EnableWindow(hwndHelp, FALSE);
1811 /******************************************************************************
1812 * PROPSHEET_SetCurSelId
1814 * Selects the page, specified by resource id.
1816 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
1819 PropSheetInfo* psInfo =
1820 (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1822 idx = PROPSHEET_FindPageByResId(psInfo, id);
1823 if (idx < psInfo->nPages )
1825 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1826 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1830 /******************************************************************************
1831 * PROPSHEET_SetTitleA
1833 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1835 if(HIWORD(lpszText))
1838 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1839 szTitle, sizeof szTitle);
1840 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
1844 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
1848 /******************************************************************************
1849 * PROPSHEET_SetTitleW
1851 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
1853 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1856 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
1857 if (HIWORD(lpszText) == 0) {
1858 if (!LoadStringW(psInfo->ppshheader.hInstance,
1859 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
1863 if (dwStyle & PSH_PROPTITLE)
1866 int lentitle = strlenW(lpszText);
1867 int lenprop = strlenW(psInfo->strPropertiesFor);
1869 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
1870 strcpyW(dest, psInfo->strPropertiesFor);
1871 strcatW(dest, lpszText);
1873 SetWindowTextW(hwndDlg, dest);
1874 COMCTL32_Free(dest);
1877 SetWindowTextW(hwndDlg, lpszText);
1880 /******************************************************************************
1881 * PROPSHEET_SetFinishTextA
1883 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1885 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1887 TRACE("'%s'\n", lpszText);
1888 /* Set text, show and enable the Finish button */
1889 SetWindowTextA(hwndButton, lpszText);
1890 ShowWindow(hwndButton, SW_SHOW);
1891 EnableWindow(hwndButton, TRUE);
1893 /* Make it default pushbutton */
1894 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1896 /* Hide Back button */
1897 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1898 ShowWindow(hwndButton, SW_HIDE);
1900 /* Hide Next button */
1901 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1902 ShowWindow(hwndButton, SW_HIDE);
1905 /******************************************************************************
1906 * PROPSHEET_SetFinishTextW
1908 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
1910 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1912 TRACE("'%s'\n", debugstr_w(lpszText));
1913 /* Set text, show and enable the Finish button */
1914 SetWindowTextW(hwndButton, lpszText);
1915 ShowWindow(hwndButton, SW_SHOW);
1916 EnableWindow(hwndButton, TRUE);
1918 /* Make it default pushbutton */
1919 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1921 /* Hide Back button */
1922 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1923 ShowWindow(hwndButton, SW_HIDE);
1925 /* Hide Next button */
1926 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1927 ShowWindow(hwndButton, SW_HIDE);
1930 /******************************************************************************
1931 * PROPSHEET_QuerySiblings
1933 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1934 WPARAM wParam, LPARAM lParam)
1938 LRESULT msgResult = 0;
1939 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1942 while ((i < psInfo->nPages) && (msgResult == 0))
1944 hwndPage = psInfo->proppage[i].hwndPage;
1945 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1953 /******************************************************************************
1956 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1957 HPROPSHEETPAGE hpage)
1959 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1961 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1963 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
1965 TRACE("hpage %p\n", hpage);
1967 * Allocate and fill in a new PropPageInfo entry.
1969 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1970 sizeof(PropPageInfo) *
1971 (psInfo->nPages + 1));
1972 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
1975 psInfo->proppage[psInfo->nPages].hpage = hpage;
1977 if (ppsp->dwFlags & PSP_PREMATURE)
1979 /* Create the page but don't show it */
1980 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
1984 * Add a new tab to the tab control.
1986 item.mask = TCIF_TEXT;
1987 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
1988 item.cchTextMax = MAX_TABTEXT_LENGTH;
1990 if (psInfo->hImageList)
1992 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1995 if ( psInfo->proppage[psInfo->nPages].hasIcon )
1997 item.mask |= TCIF_IMAGE;
1998 item.iImage = psInfo->nPages;
2001 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2006 /* If it is the only page - show it */
2007 if(psInfo->nPages == 1)
2008 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2012 /******************************************************************************
2013 * PROPSHEET_RemovePage
2015 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2017 HPROPSHEETPAGE hpage)
2019 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2021 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2022 PropPageInfo* oldPages;
2024 TRACE("index %d, hpage %p\n", index, hpage);
2028 oldPages = psInfo->proppage;
2030 * hpage takes precedence over index.
2034 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2037 /* Make sure that index is within range */
2038 if (index < 0 || index >= psInfo->nPages)
2040 TRACE("Could not find page to remove!\n");
2044 TRACE("total pages %d removing page %d active page %d\n",
2045 psInfo->nPages, index, psInfo->active_page);
2047 * Check if we're removing the active page.
2049 if (index == psInfo->active_page)
2051 if (psInfo->nPages > 1)
2055 /* activate previous page */
2056 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2060 /* activate the next page */
2061 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2062 psInfo->active_page = index;
2067 psInfo->active_page = -1;
2068 if (!psInfo->isModeless)
2070 EndDialog(hwndDlg, FALSE);
2075 else if (index < psInfo->active_page)
2076 psInfo->active_page--;
2078 /* Destroy page dialog window */
2079 DestroyWindow(psInfo->proppage[index].hwndPage);
2081 /* Free page resources */
2082 if(psInfo->proppage[index].hpage)
2084 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2086 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2087 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2089 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2092 /* Remove the tab */
2093 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2096 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2099 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2101 if (index < psInfo->nPages)
2102 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2103 (psInfo->nPages - index) * sizeof(PropPageInfo));
2105 COMCTL32_Free(oldPages);
2110 /******************************************************************************
2111 * PROPSHEET_SetWizButtons
2113 * This code will work if (and assumes that) the Next button is on top of the
2114 * Finish button. ie. Finish comes after Next in the Z order.
2115 * This means make sure the dialog template reflects this.
2118 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2120 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2121 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2122 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2124 TRACE("%ld\n", dwFlags);
2126 EnableWindow(hwndBack, FALSE);
2127 EnableWindow(hwndNext, FALSE);
2128 EnableWindow(hwndFinish, FALSE);
2130 if (dwFlags & PSWIZB_BACK)
2131 EnableWindow(hwndBack, TRUE);
2133 if (dwFlags & PSWIZB_NEXT)
2135 /* Hide the Finish button */
2136 ShowWindow(hwndFinish, SW_HIDE);
2138 /* Show and enable the Next button */
2139 ShowWindow(hwndNext, SW_SHOW);
2140 EnableWindow(hwndNext, TRUE);
2142 /* Set the Next button as the default pushbutton */
2143 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2146 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2148 /* Hide the Next button */
2149 ShowWindow(hwndNext, SW_HIDE);
2151 /* Show the Finish button */
2152 ShowWindow(hwndFinish, SW_SHOW);
2154 if (dwFlags & PSWIZB_FINISH)
2155 EnableWindow(hwndFinish, TRUE);
2157 /* Set the Finish button as the default pushbutton */
2158 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2162 /******************************************************************************
2163 * PROPSHEET_GetPageIndex
2165 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2166 * the array of PropPageInfo.
2168 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2173 TRACE("hpage %p\n", hpage);
2174 while ((index < psInfo->nPages) && (found == FALSE))
2176 if (psInfo->proppage[index].hpage == hpage)
2188 /******************************************************************************
2191 static void PROPSHEET_CleanUp(HWND hwndDlg)
2194 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2198 if (!psInfo) return;
2199 if (HIWORD(psInfo->ppshheader.pszCaption))
2200 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2202 for (i = 0; i < psInfo->nPages; i++)
2204 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2206 if(psInfo->proppage[i].hwndPage)
2207 DestroyWindow(psInfo->proppage[i].hwndPage);
2211 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2212 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2214 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2218 COMCTL32_Free(psInfo->proppage);
2219 COMCTL32_Free(psInfo->strPropertiesFor);
2220 ImageList_Destroy(psInfo->hImageList);
2222 GlobalFree((HGLOBAL)psInfo);
2225 /******************************************************************************
2226 * PropertySheet (COMCTL32.@)
2227 * PropertySheetA (COMCTL32.@)
2229 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2232 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2233 sizeof(PropSheetInfo));
2237 TRACE("(%p)\n", lppsh);
2239 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2241 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2243 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2245 for (n = i = 0; i < lppsh->nPages; i++, n++)
2247 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2248 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2251 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2252 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2255 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2258 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2259 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2265 bRet = PROPSHEET_CreateDialog(psInfo);
2270 /******************************************************************************
2271 * PropertySheetW (COMCTL32.@)
2273 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2276 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2277 sizeof(PropSheetInfo));
2281 TRACE("(%p)\n", lppsh);
2283 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2285 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2287 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2289 for (n = i = 0; i < lppsh->nPages; i++, n++)
2291 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2292 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2295 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2296 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2299 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2302 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2303 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2309 bRet = PROPSHEET_CreateDialog(psInfo);
2314 /******************************************************************************
2315 * CreatePropertySheetPage (COMCTL32.@)
2316 * CreatePropertySheetPageA (COMCTL32.@)
2318 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2319 LPCPROPSHEETPAGEA lpPropSheetPage)
2321 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2323 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2325 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2327 PROPSHEET_AtoW(&ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate);
2329 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2331 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2334 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2336 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2338 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2339 ppsp->pszTitle = NULL;
2341 return (HPROPSHEETPAGE)ppsp;
2344 /******************************************************************************
2345 * CreatePropertySheetPageW (COMCTL32.@)
2347 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2349 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2351 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2353 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2355 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2357 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2358 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2360 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2362 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2363 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2364 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2367 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2369 int len = strlenW(lpPropSheetPage->pszTitle);
2370 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2371 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2373 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2374 ppsp->pszTitle = NULL;
2376 return (HPROPSHEETPAGE)ppsp;
2379 /******************************************************************************
2380 * DestroyPropertySheetPage (COMCTL32.@)
2382 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2384 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2389 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2390 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2392 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2393 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2395 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2396 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2398 COMCTL32_Free(hPropPage);
2403 /******************************************************************************
2404 * PROPSHEET_IsDialogMessage
2406 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2408 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2411 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2414 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2417 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2419 if (!(dlgCode & DLGC_WANTMESSAGE))
2421 switch (lpMsg->wParam)
2424 if (GetKeyState(VK_SHIFT) & 0x8000)
2430 case VK_NEXT: new_page = 1; break;
2431 case VK_PRIOR: new_page = -1; break;
2437 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2439 new_page += psInfo->active_page;
2442 new_page = psInfo->nPages - 1;
2443 else if (new_page >= psInfo->nPages)
2446 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2453 return IsDialogMessageA(hwnd, lpMsg);
2456 /******************************************************************************
2457 * PROPSHEET_DoCommand
2459 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2465 case IDC_APPLY_BUTTON:
2467 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2469 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2474 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2478 if (psInfo->restartWindows)
2479 result = ID_PSRESTARTWINDOWS;
2481 /* reboot system takes precedence over restart windows */
2482 if (psInfo->rebootSystem)
2483 result = ID_PSREBOOTSYSTEM;
2485 if (psInfo->isModeless)
2486 psInfo->activeValid = FALSE;
2488 EndDialog(hwnd, result);
2491 EnableWindow(hwndApplyBtn, FALSE);
2496 case IDC_BACK_BUTTON:
2497 PROPSHEET_Back(hwnd);
2500 case IDC_NEXT_BUTTON:
2501 PROPSHEET_Next(hwnd);
2504 case IDC_FINISH_BUTTON:
2505 PROPSHEET_Finish(hwnd);
2509 PROPSHEET_Cancel(hwnd, 0);
2513 PROPSHEET_Help(hwnd);
2520 /******************************************************************************
2521 * PROPSHEET_DialogProc
2524 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2526 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
2527 hwnd, uMsg, wParam, lParam);
2533 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2534 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2535 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2536 LPCPROPSHEETPAGEW ppshpage;
2539 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2542 * psInfo->hwnd is not being used by WINE code - it exists
2543 * for compatibility with "real" Windoze. The same about
2544 * SetWindowLong - WINE is only using the PropSheetInfoStr
2547 psInfo->hwnd = hwnd;
2548 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2551 * Small icon in the title bar.
2553 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2554 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2557 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2558 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2560 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2561 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2562 psInfo->ppshheader.u.pszIcon,
2567 hIcon = psInfo->ppshheader.u.hIcon;
2569 SendMessageW(hwnd, WM_SETICON, 0, hIcon);
2572 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2573 SendMessageW(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2575 psInfo->strPropertiesFor = strCaption;
2577 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2579 PROPSHEET_CreateTabControl(hwnd, psInfo);
2581 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2583 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2585 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2586 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2591 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2593 PROPSHEET_AdjustSize(hwnd, psInfo);
2594 PROPSHEET_AdjustButtons(hwnd, psInfo);
2598 if (psInfo->useCallback)
2599 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2600 PSCB_INITIALIZED, (LPARAM)0);
2602 idx = psInfo->active_page;
2603 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2604 psInfo->active_page = -1;
2606 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2608 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2609 * as some programs call TCM_GETCURSEL to get the current selection
2610 * from which to switch to the next page */
2611 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2613 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2614 psInfo->ppshheader.hInstance)
2618 if (LoadStringW(psInfo->ppshheader.hInstance,
2619 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2620 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2624 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2625 psInfo->ppshheader.pszCaption);
2632 PROPSHEET_CleanUp(hwnd);
2636 PROPSHEET_Cancel(hwnd, 1);
2640 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2644 NMHDR* pnmh = (LPNMHDR) lParam;
2646 if (pnmh->code == TCN_SELCHANGE)
2648 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2649 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2652 if(pnmh->code == TCN_SELCHANGING)
2654 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2655 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2662 case PSM_GETCURRENTPAGEHWND:
2664 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2668 if (psInfo->activeValid && psInfo->active_page != -1)
2669 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2671 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndPage);
2677 PROPSHEET_Changed(hwnd, (HWND)wParam);
2681 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2684 case PSM_GETTABCONTROL:
2686 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2688 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2697 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2698 if(msgResult != FALSE)
2700 msgResult = PROPSHEET_SetCurSel(hwnd,
2703 (HPROPSHEETPAGE)lParam);
2706 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2711 case PSM_CANCELTOCLOSE:
2713 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2714 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2715 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2717 EnableWindow(hwndCancel, FALSE);
2718 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2719 SetWindowTextW(hwndOK, buf);
2724 case PSM_RESTARTWINDOWS:
2726 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2729 psInfo->restartWindows = TRUE;
2733 case PSM_REBOOTSYSTEM:
2735 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2738 psInfo->rebootSystem = TRUE;
2743 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2747 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2752 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2754 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2759 case PSM_QUERYSIBLINGS:
2761 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2763 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2771 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2772 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2773 * on success or FALSE otherwise, as specified on MSDN Online.
2774 * Also see the MFC code for
2775 * CPropertySheet::AddPage(CPropertyPage* pPage).
2778 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2780 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2785 case PSM_REMOVEPAGE:
2786 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2789 case PSM_ISDIALOGMESSAGE:
2791 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2792 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2796 case PSM_PRESSBUTTON:
2797 PROPSHEET_PressButton(hwnd, (int)wParam);
2800 case PSM_SETFINISHTEXTA:
2801 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2804 case PSM_SETWIZBUTTONS:
2805 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2808 case PSM_SETCURSELID:
2809 PROPSHEET_SetCurSelId(hwnd, (int)lParam);
2812 case PSM_SETFINISHTEXTW:
2813 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);