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 LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
142 WPARAM wParam, LPARAM lParam);
143 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
144 HPROPSHEETPAGE hpage);
146 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
148 HPROPSHEETPAGE hpage);
149 static void PROPSHEET_CleanUp();
150 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
151 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
152 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
153 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
154 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
157 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
161 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
162 /******************************************************************************
163 * PROPSHEET_UnImplementedFlags
165 * Document use of flags we don't implement yet.
167 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
174 * unhandled header flags:
175 * PSH_DEFAULT 0x00000000
176 * PSH_WIZARDHASFINISH 0x00000010
177 * PSH_RTLREADING 0x00000800
178 * PSH_WIZARDCONTEXTHELP 0x00001000
179 * PSH_WIZARD97 0x00002000 (pre IE 5)
180 * PSH_WATERMARK 0x00008000
181 * PSH_USEHBMWATERMARK 0x00010000
182 * PSH_USEHPLWATERMARK 0x00020000
183 * PSH_STRETCHWATERMARK 0x00040000
184 * PSH_HEADER 0x00080000
185 * PSH_USEHBMHEADER 0x00100000
186 * PSH_USEPAGELANG 0x00200000
187 * PSH_WIZARD_LITE 0x00400000 also not in .h
188 * PSH_WIZARD97 0x01000000 (IE 5 and above)
189 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
192 add_flag(PSH_WIZARDHASFINISH);
193 add_flag(PSH_RTLREADING);
194 add_flag(PSH_WIZARDCONTEXTHELP);
195 add_flag(PSH_WIZARD97_OLD);
196 add_flag(PSH_WATERMARK);
197 add_flag(PSH_USEHBMWATERMARK);
198 add_flag(PSH_USEHPLWATERMARK);
199 add_flag(PSH_STRETCHWATERMARK);
200 add_flag(PSH_HEADER);
201 add_flag(PSH_USEHBMHEADER);
202 add_flag(PSH_USEPAGELANG);
203 add_flag(PSH_WIZARD_LITE);
204 add_flag(PSH_WIZARD97_NEW);
205 add_flag(PSH_NOCONTEXTHELP);
206 if (string[0] != '\0')
207 FIXME("%s\n", string);
211 /******************************************************************************
212 * PROPSHEET_GetPageRect
214 * Retrieve rect from tab control and map into the dialog for SetWindowPos
216 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg, RECT *rc)
218 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
220 GetClientRect(hwndTabCtrl, rc);
221 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
222 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
225 /******************************************************************************
226 * PROPSHEET_FindPageByResId
228 * Find page index corresponding to page resource id.
230 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
234 for (i = 0; i < psInfo->nPages; i++)
236 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
238 /* Fixme: if resource ID is a string shall we use strcmp ??? */
239 if (lppsp->u.pszTemplate == (LPVOID)resId)
246 /******************************************************************************
249 * Convert ASCII to Unicode since all data is saved as Unicode.
251 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
255 TRACE("<%s>\n", frstr);
256 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
257 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
258 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
261 /******************************************************************************
262 * PROPSHEET_CollectSheetInfoA
264 * Collect relevant data.
266 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
267 PropSheetInfo * psInfo)
269 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
270 DWORD dwFlags = lppsh->dwFlags;
272 psInfo->hasHelp = dwFlags & PSH_HASHELP;
273 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
274 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
275 psInfo->isModeless = dwFlags & PSH_MODELESS;
277 memcpy(&psInfo->ppshheader,lppsh,dwSize);
278 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",
279 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
280 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
282 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
284 if (HIWORD(lppsh->pszCaption))
286 int len = strlen(lppsh->pszCaption);
287 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
288 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
289 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
291 psInfo->nPages = lppsh->nPages;
293 if (dwFlags & PSH_USEPSTARTPAGE)
295 TRACE("PSH_USEPSTARTPAGE is on");
296 psInfo->active_page = 0;
299 psInfo->active_page = lppsh->u2.nStartPage;
301 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
302 psInfo->active_page = 0;
304 psInfo->restartWindows = FALSE;
305 psInfo->rebootSystem = FALSE;
306 psInfo->hImageList = 0;
307 psInfo->activeValid = FALSE;
312 /******************************************************************************
313 * PROPSHEET_CollectSheetInfoW
315 * Collect relevant data.
317 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
318 PropSheetInfo * psInfo)
320 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
321 DWORD dwFlags = lppsh->dwFlags;
323 psInfo->hasHelp = dwFlags & PSH_HASHELP;
324 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
325 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
326 psInfo->isModeless = dwFlags & PSH_MODELESS;
328 memcpy(&psInfo->ppshheader,lppsh,dwSize);
329 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",
330 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
332 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
334 if (HIWORD(lppsh->pszCaption))
336 int len = strlenW(lppsh->pszCaption);
337 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
338 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
340 psInfo->nPages = lppsh->nPages;
342 if (dwFlags & PSH_USEPSTARTPAGE)
344 TRACE("PSH_USEPSTARTPAGE is on");
345 psInfo->active_page = 0;
348 psInfo->active_page = lppsh->u2.nStartPage;
350 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
351 psInfo->active_page = 0;
353 psInfo->restartWindows = FALSE;
354 psInfo->rebootSystem = FALSE;
355 psInfo->hImageList = 0;
356 psInfo->activeValid = FALSE;
361 /******************************************************************************
362 * PROPSHEET_CollectPageInfo
364 * Collect property sheet data.
365 * With code taken from DIALOG_ParseTemplate32.
367 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
368 PropSheetInfo * psInfo,
371 DLGTEMPLATE* pTemplate;
377 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
378 psInfo->proppage[index].hwndPage = 0;
379 psInfo->proppage[index].isDirty = FALSE;
382 * Process property page flags.
384 dwFlags = lppsp->dwFlags;
385 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
386 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
387 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
389 /* as soon as we have a page with the help flag, set the sheet flag on */
390 if (psInfo->proppage[index].hasHelp)
391 psInfo->hasHelp = TRUE;
394 * Process page template.
396 if (dwFlags & PSP_DLGINDIRECT)
397 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
400 HRSRC hResource = FindResourceW(lppsp->hInstance,
401 lppsp->u.pszTemplate,
403 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
405 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
409 * Extract the size of the page and the caption.
414 p = (const WORD *)pTemplate;
416 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
418 /* DIALOGEX template */
422 p += 2; /* help ID */
423 p += 2; /* ext style */
428 /* DIALOG template */
431 p += 2; /* ext style */
437 width = (WORD)*p; p++;
438 height = (WORD)*p; p++;
440 /* remember the largest width and height */
441 if (width > psInfo->width)
442 psInfo->width = width;
444 if (height > psInfo->height)
445 psInfo->height = height;
457 p += lstrlenW( (LPCWSTR)p ) + 1;
471 p += lstrlenW( (LPCWSTR)p ) + 1;
475 /* Extract the caption */
476 psInfo->proppage[index].pszText = (LPCWSTR)p;
477 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
478 p += lstrlenW((LPCWSTR)p) + 1;
480 if (dwFlags & PSP_USETITLE)
484 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
487 if ( !HIWORD( lppsp->pszTitle ) )
489 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
492 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
498 pTitle = lppsp->pszTitle;
500 len = strlenW(pTitle);
501 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
502 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
506 * Build the image list for icons
508 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
511 int icon_cx = GetSystemMetrics(SM_CXSMICON);
512 int icon_cy = GetSystemMetrics(SM_CYSMICON);
514 if (dwFlags & PSP_USEICONID)
515 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
516 icon_cx, icon_cy, LR_DEFAULTCOLOR);
518 hIcon = lppsp->u2.hIcon;
522 if (psInfo->hImageList == 0 )
523 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
525 ImageList_AddIcon(psInfo->hImageList, hIcon);
533 /******************************************************************************
534 * PROPSHEET_CreateDialog
536 * Creates the actual property sheet.
538 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
545 WORD resID = IDD_PROPSHEET;
548 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
551 if(!(hRes = FindResourceW(COMCTL32_hModule,
552 MAKEINTRESOURCEW(resID),
556 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
560 * Make a copy of the dialog template.
562 resSize = SizeofResource(COMCTL32_hModule, hRes);
564 temp = COMCTL32_Alloc(resSize);
569 memcpy(temp, template, resSize);
571 if (psInfo->useCallback)
572 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
574 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
575 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
576 (LPDLGTEMPLATEW) temp,
577 psInfo->ppshheader.hwndParent,
578 (DLGPROC) PROPSHEET_DialogProc,
581 ret = CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
582 (LPDLGTEMPLATEW) temp,
583 psInfo->ppshheader.hwndParent,
584 (DLGPROC) PROPSHEET_DialogProc,
592 /******************************************************************************
593 * PROPSHEET_SizeMismatch
595 * Verify that the tab control and the "largest" property sheet page dlg. template
598 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
600 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
601 RECT rcOrigTab, rcPage;
606 GetClientRect(hwndTabCtrl, &rcOrigTab);
607 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
608 rcOrigTab.right, rcOrigTab.bottom);
613 rcPage.left = psInfo->x;
614 rcPage.top = psInfo->y;
615 rcPage.right = psInfo->width;
616 rcPage.bottom = psInfo->height;
618 MapDialogRect(hwndDlg, &rcPage);
619 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
620 rcPage.right, rcPage.bottom);
622 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
624 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
630 /******************************************************************************
631 * PROPSHEET_IsTooSmallWizard
633 * Verify that the default property sheet is big enough.
635 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
637 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
638 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
639 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
641 GetClientRect(hwndDlg, &rcSheetClient);
642 GetWindowRect(hwndDlg, &rcSheetRect);
643 GetWindowRect(hwndLine, &rcLine);
645 /* Remove the space below the sunken line */
646 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
648 /* Remove the buffer zone all around the edge */
649 rcSheetClient.bottom -= (padding.y * 2);
650 rcSheetClient.right -= (padding.x * 2);
655 rcPage.left = psInfo->x;
656 rcPage.top = psInfo->y;
657 rcPage.right = psInfo->width;
658 rcPage.bottom = psInfo->height;
660 MapDialogRect(hwndDlg, &rcPage);
661 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
662 rcPage.right, rcPage.bottom);
664 if (rcPage.right > rcSheetClient.right)
667 if (rcPage.bottom > rcSheetClient.bottom)
673 /******************************************************************************
674 * PROPSHEET_AdjustSize
676 * Resizes the property sheet and the tab control to fit the largest page.
678 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
680 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
681 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
683 int tabOffsetX, tabOffsetY, buttonHeight;
684 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
687 /* Get the height of buttons */
688 GetClientRect(hwndButton, &rc);
689 buttonHeight = rc.bottom;
696 rc.right = psInfo->width;
697 rc.bottom = psInfo->height;
699 MapDialogRect(hwndDlg, &rc);
701 /* retrieve the dialog units */
702 units.left = units.right = 4;
703 units.top = units.bottom = 8;
704 MapDialogRect(hwndDlg, &units);
707 * Resize the tab control.
709 GetClientRect(hwndTabCtrl,&tabRect);
711 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
713 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
715 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
716 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
719 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
721 rc.right = rc.left + tabRect.right - tabRect.left;
722 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
725 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
727 tabOffsetX = -(rc.left);
728 tabOffsetY = -(rc.top);
732 TRACE("setting tab %08lx, rc (0,0)-(%d,%d)\n",
733 (DWORD)hwndTabCtrl, rc.right, rc.bottom);
734 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
735 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
737 GetClientRect(hwndTabCtrl, &rc);
739 TRACE("tab client rc %d %d %d %d\n",
740 rc.left, rc.top, rc.right, rc.bottom);
742 rc.right += ((padding.x * 2) + tabOffsetX);
743 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
746 * Resize the property sheet.
748 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
749 (DWORD)hwndDlg, rc.right, rc.bottom);
750 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
751 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
755 /******************************************************************************
756 * PROPSHEET_AdjustSizeWizard
758 * Resizes the property sheet to fit the largest page.
760 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
762 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
763 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
764 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
766 int buttonHeight, lineHeight;
767 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
770 /* Get the height of buttons */
771 GetClientRect(hwndButton, &rc);
772 buttonHeight = rc.bottom;
774 GetClientRect(hwndLine, &rc);
775 lineHeight = rc.bottom;
777 /* retrieve the dialog units */
778 units.left = units.right = 4;
779 units.top = units.bottom = 8;
780 MapDialogRect(hwndDlg, &units);
787 rc.right = psInfo->width;
788 rc.bottom = psInfo->height;
790 MapDialogRect(hwndDlg, &rc);
792 GetClientRect(hwndTabCtrl,&tabRect);
794 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
796 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
797 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
800 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
802 rc.right = rc.left + tabRect.right - tabRect.left;
803 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
806 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
807 TRACE(" constants padx=%d, pady=%d, butH=%d, lH=%d\n",
808 padding.x, padding.y, buttonHeight, lineHeight);
811 rc.right += (padding.x * 2);
812 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
815 * Resize the property sheet.
817 TRACE("setting dialog %08lx, rc (0,0)-(%d,%d)\n",
818 (DWORD)hwndDlg, rc.right, rc.bottom);
819 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
820 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
824 /******************************************************************************
825 * PROPSHEET_AdjustButtons
827 * Adjusts the buttons' positions.
829 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
831 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
835 int buttonWidth, buttonHeight;
836 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
838 if (psInfo->hasApply)
845 * Obtain the size of the buttons.
847 GetClientRect(hwndButton, &rcSheet);
848 buttonWidth = rcSheet.right;
849 buttonHeight = rcSheet.bottom;
852 * Get the size of the property sheet.
854 GetClientRect(hwndParent, &rcSheet);
857 * All buttons will be at this y coordinate.
859 y = rcSheet.bottom - (padding.y + buttonHeight);
862 * Position OK button.
864 hwndButton = GetDlgItem(hwndParent, IDOK);
866 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
868 SetWindowPos(hwndButton, 0, x, y, 0, 0,
869 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
872 * Position Cancel button.
874 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
876 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
878 SetWindowPos(hwndButton, 0, x, y, 0, 0,
879 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
882 * Position Apply button.
884 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
886 if (psInfo->hasApply)
889 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
891 x = rcSheet.right - (padding.x + buttonWidth);
893 SetWindowPos(hwndButton, 0, x, y, 0, 0,
894 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
896 EnableWindow(hwndButton, FALSE);
899 ShowWindow(hwndButton, SW_HIDE);
902 * Position Help button.
904 hwndButton = GetDlgItem(hwndParent, IDHELP);
908 x = rcSheet.right - (padding.x + buttonWidth);
910 SetWindowPos(hwndButton, 0, x, y, 0, 0,
911 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
914 ShowWindow(hwndButton, SW_HIDE);
919 /******************************************************************************
920 * PROPSHEET_AdjustButtonsWizard
922 * Adjusts the buttons' positions.
924 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
925 PropSheetInfo* psInfo)
927 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
928 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
932 int buttonWidth, buttonHeight, lineHeight, lineWidth;
933 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
939 * Obtain the size of the buttons.
941 GetClientRect(hwndButton, &rcSheet);
942 buttonWidth = rcSheet.right;
943 buttonHeight = rcSheet.bottom;
945 GetClientRect(hwndLine, &rcSheet);
946 lineHeight = rcSheet.bottom;
949 * Get the size of the property sheet.
951 GetClientRect(hwndParent, &rcSheet);
954 * All buttons will be at this y coordinate.
956 y = rcSheet.bottom - (padding.y + buttonHeight);
959 * Position the Next and the Finish buttons.
961 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
963 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
965 SetWindowPos(hwndButton, 0, x, y, 0, 0,
966 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
968 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
970 SetWindowPos(hwndButton, 0, x, y, 0, 0,
971 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
973 ShowWindow(hwndButton, SW_HIDE);
976 * Position the Back button.
978 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
982 SetWindowPos(hwndButton, 0, x, y, 0, 0,
983 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
986 * Position the Cancel button.
988 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
990 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
992 SetWindowPos(hwndButton, 0, x, y, 0, 0,
993 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
996 * Position Help button.
998 hwndButton = GetDlgItem(hwndParent, IDHELP);
1000 if (psInfo->hasHelp)
1002 x = rcSheet.right - (padding.x + buttonWidth);
1004 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1005 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1008 ShowWindow(hwndButton, SW_HIDE);
1011 * Position and resize the sunken line.
1014 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1016 GetClientRect(hwndParent, &rcSheet);
1017 lineWidth = rcSheet.right - (padding.x * 2);
1019 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1020 SWP_NOZORDER | SWP_NOACTIVATE);
1025 /******************************************************************************
1026 * PROPSHEET_GetPaddingInfo
1028 * Returns the layout information.
1030 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1032 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1035 PADDING_INFO padding;
1037 GetWindowRect(hwndTab, &rcTab);
1042 ScreenToClient(hwndDlg, &tl);
1050 /******************************************************************************
1051 * PROPSHEET_GetPaddingInfoWizard
1053 * Returns the layout information.
1054 * Vertical spacing is the distance between the line and the buttons.
1055 * Do NOT use the Help button to gather padding information when it isn't mapped
1056 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1057 * for it in this case !
1058 * FIXME: I'm not sure about any other coordinate problems with these evil
1059 * buttons. Fix it in case additional problems appear or maybe calculate
1060 * a padding in a completely different way, as this is somewhat messy.
1062 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1065 PADDING_INFO padding;
1069 POINT ptButton, ptLine;
1072 if (psInfo->hasHelp)
1078 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1080 idButton = IDC_NEXT_BUTTON;
1084 /* hopefully this is ok */
1085 idButton = IDCANCEL;
1089 hwndControl = GetDlgItem(hwndDlg, idButton);
1090 GetWindowRect(hwndControl, &rc);
1092 ptButton.x = rc.left;
1093 ptButton.y = rc.top;
1095 ScreenToClient(hwndDlg, &ptButton);
1098 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1099 GetWindowRect(hwndControl, &rc);
1102 ptLine.y = rc.bottom;
1104 ScreenToClient(hwndDlg, &ptLine);
1106 padding.y = ptButton.y - ptLine.y;
1109 ERR("padding negative ! Please report this !\n");
1111 /* this is most probably not correct, but the best we have now */
1112 padding.x = padding.y;
1116 /******************************************************************************
1117 * PROPSHEET_CreateTabControl
1119 * Insert the tabs in the tab control.
1121 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1122 PropSheetInfo * psInfo)
1124 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1130 item.mask = TCIF_TEXT;
1131 item.cchTextMax = MAX_TABTEXT_LENGTH;
1133 nTabs = psInfo->nPages;
1136 * Set the image list for icons.
1138 if (psInfo->hImageList)
1140 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1143 for (i = 0; i < nTabs; i++)
1145 if ( psInfo->proppage[i].hasIcon )
1147 item.mask |= TCIF_IMAGE;
1148 item.iImage = iImage++;
1152 item.mask &= ~TCIF_IMAGE;
1155 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1156 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1162 /******************************************************************************
1163 * PROPSHEET_CreatePage
1167 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1169 const PropSheetInfo * psInfo,
1170 LPCPROPSHEETPAGEW ppshpage)
1172 DLGTEMPLATE* pTemplate;
1175 PropPageInfo* ppInfo = psInfo->proppage;
1176 PADDING_INFO padding;
1177 UINT pageWidth,pageHeight;
1181 TRACE("index %d\n", index);
1183 if (ppshpage == NULL)
1188 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1189 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1195 hResource = FindResourceW(ppshpage->hInstance,
1196 ppshpage->u.pszTemplate,
1201 resSize = SizeofResource(ppshpage->hInstance, hResource);
1203 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1207 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1209 * Make a copy of the dialog template to make it writable
1211 temp = COMCTL32_Alloc(resSize);
1215 memcpy(temp, pTemplate, resSize);
1219 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1221 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1222 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1223 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1224 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1225 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1226 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1227 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1228 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1232 pTemplate->style |= WS_CHILD | DS_CONTROL;
1233 pTemplate->style &= ~DS_MODALFRAME;
1234 pTemplate->style &= ~WS_CAPTION;
1235 pTemplate->style &= ~WS_SYSMENU;
1236 pTemplate->style &= ~WS_POPUP;
1237 pTemplate->style &= ~WS_DISABLED;
1238 pTemplate->style &= ~WS_VISIBLE;
1239 pTemplate->style &= ~WS_THICKFRAME;
1242 if (psInfo->proppage[index].useCallback)
1243 (*(ppshpage->pfnCallback))(hwndParent,
1245 (LPPROPSHEETPAGEW)ppshpage);
1247 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1250 ppshpage->pfnDlgProc,
1252 /* Free a no more needed copy */
1254 COMCTL32_Free(temp);
1256 ppInfo[index].hwndPage = hwndPage;
1258 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
1259 /* FIXME: This code may no longer be correct.
1260 * It was not for the non-wizard path. (GLA 6/02)
1262 rc.left = psInfo->x;
1264 rc.right = psInfo->width;
1265 rc.bottom = psInfo->height;
1267 MapDialogRect(hwndParent, &rc);
1269 pageWidth = rc.right - rc.left;
1270 pageHeight = rc.bottom - rc.top;
1272 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1273 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d, padx=%d, pady=%d\n",
1274 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1275 pageWidth, pageHeight, padding.x, padding.y);
1276 SetWindowPos(hwndPage, HWND_TOP,
1277 rc.left + padding.x/2,
1278 rc.top + padding.y/2,
1279 pageWidth, pageHeight, 0);
1283 * Ask the Tab control to reduce the client rectangle to that
1286 PROPSHEET_GetPageRect(psInfo, hwndParent, &rc);
1287 pageWidth = rc.right - rc.left;
1288 pageHeight = rc.bottom - rc.top;
1289 TRACE("setting page %08lx, rc (%d,%d)-(%d,%d) w=%d, h=%d\n",
1290 (DWORD)hwndPage, rc.left, rc.top, rc.right, rc.bottom,
1291 pageWidth, pageHeight);
1292 SetWindowPos(hwndPage, HWND_TOP,
1294 pageWidth, pageHeight, 0);
1300 /******************************************************************************
1301 * PROPSHEET_ShowPage
1303 * Displays or creates the specified page.
1305 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1309 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1310 if (index == psInfo->active_page)
1312 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1313 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1317 if (psInfo->proppage[index].hwndPage == 0)
1319 LPCPROPSHEETPAGEW ppshpage;
1321 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1322 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1325 if (psInfo->active_page != -1)
1326 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1328 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1330 /* Synchronize current selection with tab control
1331 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1332 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1333 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1335 psInfo->active_page = index;
1336 psInfo->activeValid = TRUE;
1341 /******************************************************************************
1344 static BOOL PROPSHEET_Back(HWND hwndDlg)
1348 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1353 TRACE("active_page %d\n", psInfo->active_page);
1354 if (psInfo->active_page < 0)
1357 psn.hdr.code = PSN_WIZBACK;
1358 psn.hdr.hwndFrom = hwndDlg;
1362 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1364 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1367 else if (result == 0)
1368 idx = psInfo->active_page - 1;
1370 idx = PROPSHEET_FindPageByResId(psInfo, result);
1372 if (idx >= 0 && idx < psInfo->nPages)
1374 if (PROPSHEET_CanSetCurSel(hwndDlg))
1375 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1380 /******************************************************************************
1383 static BOOL PROPSHEET_Next(HWND hwndDlg)
1387 LRESULT msgResult = 0;
1388 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1392 TRACE("active_page %d\n", psInfo->active_page);
1393 if (psInfo->active_page < 0)
1396 psn.hdr.code = PSN_WIZNEXT;
1397 psn.hdr.hwndFrom = hwndDlg;
1401 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1403 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1404 if (msgResult == -1)
1406 else if (msgResult == 0)
1407 idx = psInfo->active_page + 1;
1409 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1411 if (idx < psInfo->nPages )
1413 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1414 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1420 /******************************************************************************
1423 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1427 LRESULT msgResult = 0;
1428 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1431 TRACE("active_page %d\n", psInfo->active_page);
1432 if (psInfo->active_page < 0)
1435 psn.hdr.code = PSN_WIZFINISH;
1436 psn.hdr.hwndFrom = hwndDlg;
1440 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1442 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1444 TRACE("msg result %ld\n", msgResult);
1449 if (psInfo->isModeless)
1450 psInfo->activeValid = FALSE;
1452 EndDialog(hwndDlg, TRUE);
1457 /******************************************************************************
1460 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1466 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1469 TRACE("active_page %d\n", psInfo->active_page);
1470 if (psInfo->active_page < 0)
1473 psn.hdr.hwndFrom = hwndDlg;
1479 * Send PSN_KILLACTIVE to the current page.
1481 psn.hdr.code = PSN_KILLACTIVE;
1483 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1485 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1489 * Send PSN_APPLY to all pages.
1491 psn.hdr.code = PSN_APPLY;
1492 psn.lParam = lParam;
1494 for (i = 0; i < psInfo->nPages; i++)
1496 hwndPage = psInfo->proppage[i].hwndPage;
1499 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1500 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1507 psInfo->activeValid = FALSE;
1509 else if(psInfo->active_page >= 0)
1511 psn.hdr.code = PSN_SETACTIVE;
1513 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1514 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1520 /******************************************************************************
1523 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1525 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1531 TRACE("active_page %d\n", psInfo->active_page);
1532 if (psInfo->active_page < 0)
1535 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1536 psn.hdr.code = PSN_QUERYCANCEL;
1537 psn.hdr.hwndFrom = hwndDlg;
1541 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1544 psn.hdr.code = PSN_RESET;
1545 psn.lParam = lParam;
1547 for (i = 0; i < psInfo->nPages; i++)
1549 hwndPage = psInfo->proppage[i].hwndPage;
1552 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1555 if (psInfo->isModeless)
1557 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1558 psInfo->activeValid = FALSE;
1561 EndDialog(hwndDlg, FALSE);
1564 /******************************************************************************
1567 static void PROPSHEET_Help(HWND hwndDlg)
1569 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1574 TRACE("active_page %d\n", psInfo->active_page);
1575 if (psInfo->active_page < 0)
1578 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1579 psn.hdr.code = PSN_HELP;
1580 psn.hdr.hwndFrom = hwndDlg;
1584 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1587 /******************************************************************************
1590 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1593 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1597 if (!psInfo) return;
1599 * Set the dirty flag of this page.
1601 for (i = 0; i < psInfo->nPages; i++)
1603 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1604 psInfo->proppage[i].isDirty = TRUE;
1608 * Enable the Apply button.
1610 if (psInfo->hasApply)
1612 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1614 EnableWindow(hwndApplyBtn, TRUE);
1618 /******************************************************************************
1619 * PROPSHEET_UnChanged
1621 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1624 BOOL noPageDirty = TRUE;
1625 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1626 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1630 if ( !psInfo ) return;
1631 for (i = 0; i < psInfo->nPages; i++)
1633 /* set the specified page as clean */
1634 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1635 psInfo->proppage[i].isDirty = FALSE;
1637 /* look to see if there's any dirty pages */
1638 if (psInfo->proppage[i].isDirty)
1639 noPageDirty = FALSE;
1643 * Disable Apply button.
1646 EnableWindow(hwndApplyBtn, FALSE);
1649 /******************************************************************************
1650 * PROPSHEET_PressButton
1652 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1654 TRACE("buttonID %d\n", buttonID);
1657 case PSBTN_APPLYNOW:
1658 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1661 PROPSHEET_Back(hwndDlg);
1664 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1667 PROPSHEET_Finish(hwndDlg);
1670 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1673 PROPSHEET_Next(hwndDlg);
1676 PROPSHEET_DoCommand(hwndDlg, IDOK);
1679 FIXME("Invalid button index %d\n", buttonID);
1684 /*************************************************************************
1685 * BOOL PROPSHEET_CanSetCurSel [Internal]
1687 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1690 * hwndDlg [I] handle to a Dialog hWnd
1693 * TRUE if Current Selection can change
1697 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1699 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1705 TRACE("active_page %d\n", psInfo->active_page);
1712 if (psInfo->active_page < 0)
1719 * Notify the current page.
1721 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1722 psn.hdr.code = PSN_KILLACTIVE;
1723 psn.hdr.hwndFrom = hwndDlg;
1727 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1730 TRACE("<-- %d\n", res);
1734 /******************************************************************************
1735 * PROPSHEET_SetCurSel
1737 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1740 HPROPSHEETPAGE hpage
1743 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1744 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1746 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1747 /* hpage takes precedence over index */
1749 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1751 if (index < 0 || index >= psInfo->nPages)
1753 TRACE("Could not find page to select!\n");
1761 psn.hdr.code = PSN_SETACTIVE;
1762 psn.hdr.hwndFrom = hwndDlg;
1766 if (!psInfo->proppage[index].hwndPage) {
1767 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1768 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1771 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1778 FIXME("Tried to skip before first property sheet page!\n");
1781 if (index >= psInfo->nPages) {
1782 FIXME("Tried to skip after last property sheet page!\n");
1783 index = psInfo->nPages-1;
1787 else if (result != 0)
1789 index = PROPSHEET_FindPageByResId(psInfo, result);
1794 * Display the new page.
1796 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1798 if (psInfo->proppage[index].hasHelp)
1799 EnableWindow(hwndHelp, TRUE);
1801 EnableWindow(hwndHelp, FALSE);
1806 /******************************************************************************
1807 * PROPSHEET_SetTitleA
1809 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1811 if(HIWORD(lpszText))
1814 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1815 szTitle, sizeof szTitle);
1816 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
1820 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
1824 /******************************************************************************
1825 * PROPSHEET_SetTitleW
1827 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
1829 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1832 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
1833 if (HIWORD(lpszText) == 0) {
1834 if (!LoadStringW(psInfo->ppshheader.hInstance,
1835 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
1839 if (dwStyle & PSH_PROPTITLE)
1842 int lentitle = strlenW(lpszText);
1843 int lenprop = strlenW(psInfo->strPropertiesFor);
1845 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
1846 strcpyW(dest, psInfo->strPropertiesFor);
1847 strcatW(dest, lpszText);
1849 SetWindowTextW(hwndDlg, dest);
1850 COMCTL32_Free(dest);
1853 SetWindowTextW(hwndDlg, lpszText);
1856 /******************************************************************************
1857 * PROPSHEET_SetFinishTextA
1859 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1861 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1863 TRACE("'%s'\n", lpszText);
1864 /* Set text, show and enable the Finish button */
1865 SetWindowTextA(hwndButton, lpszText);
1866 ShowWindow(hwndButton, SW_SHOW);
1867 EnableWindow(hwndButton, TRUE);
1869 /* Make it default pushbutton */
1870 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1872 /* Hide Back button */
1873 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1874 ShowWindow(hwndButton, SW_HIDE);
1876 /* Hide Next button */
1877 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1878 ShowWindow(hwndButton, SW_HIDE);
1881 /******************************************************************************
1882 * PROPSHEET_SetFinishTextW
1884 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
1886 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1888 TRACE("'%s'\n", debugstr_w(lpszText));
1889 /* Set text, show and enable the Finish button */
1890 SetWindowTextW(hwndButton, lpszText);
1891 ShowWindow(hwndButton, SW_SHOW);
1892 EnableWindow(hwndButton, TRUE);
1894 /* Make it default pushbutton */
1895 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1897 /* Hide Back button */
1898 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1899 ShowWindow(hwndButton, SW_HIDE);
1901 /* Hide Next button */
1902 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1903 ShowWindow(hwndButton, SW_HIDE);
1906 /******************************************************************************
1907 * PROPSHEET_QuerySiblings
1909 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1910 WPARAM wParam, LPARAM lParam)
1914 LRESULT msgResult = 0;
1915 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1918 while ((i < psInfo->nPages) && (msgResult == 0))
1920 hwndPage = psInfo->proppage[i].hwndPage;
1921 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1929 /******************************************************************************
1932 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1933 HPROPSHEETPAGE hpage)
1935 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1937 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1939 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
1941 TRACE("hpage %p\n", hpage);
1943 * Allocate and fill in a new PropPageInfo entry.
1945 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1946 sizeof(PropPageInfo) *
1947 (psInfo->nPages + 1));
1948 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
1951 psInfo->proppage[psInfo->nPages].hpage = hpage;
1953 if (ppsp->dwFlags & PSP_PREMATURE)
1955 /* Create the page but don't show it */
1956 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
1960 * Add a new tab to the tab control.
1962 item.mask = TCIF_TEXT;
1963 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
1964 item.cchTextMax = MAX_TABTEXT_LENGTH;
1966 if (psInfo->hImageList)
1968 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1971 if ( psInfo->proppage[psInfo->nPages].hasIcon )
1973 item.mask |= TCIF_IMAGE;
1974 item.iImage = psInfo->nPages;
1977 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
1982 /* If it is the only page - show it */
1983 if(psInfo->nPages == 1)
1984 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
1988 /******************************************************************************
1989 * PROPSHEET_RemovePage
1991 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
1993 HPROPSHEETPAGE hpage)
1995 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1997 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1998 PropPageInfo* oldPages;
2000 TRACE("index %d, hpage %p\n", index, hpage);
2004 oldPages = psInfo->proppage;
2006 * hpage takes precedence over index.
2010 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2013 /* Make sure that index is within range */
2014 if (index < 0 || index >= psInfo->nPages)
2016 TRACE("Could not find page to remove!\n");
2020 TRACE("total pages %d removing page %d active page %d\n",
2021 psInfo->nPages, index, psInfo->active_page);
2023 * Check if we're removing the active page.
2025 if (index == psInfo->active_page)
2027 if (psInfo->nPages > 1)
2031 /* activate previous page */
2032 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2036 /* activate the next page */
2037 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2038 psInfo->active_page = index;
2043 psInfo->active_page = -1;
2044 if (!psInfo->isModeless)
2046 EndDialog(hwndDlg, FALSE);
2051 else if (index < psInfo->active_page)
2052 psInfo->active_page--;
2054 /* Destroy page dialog window */
2055 DestroyWindow(psInfo->proppage[index].hwndPage);
2057 /* Free page resources */
2058 if(psInfo->proppage[index].hpage)
2060 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2062 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2063 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2065 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2068 /* Remove the tab */
2069 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2072 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2075 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2077 if (index < psInfo->nPages)
2078 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2079 (psInfo->nPages - index) * sizeof(PropPageInfo));
2081 COMCTL32_Free(oldPages);
2086 /******************************************************************************
2087 * PROPSHEET_SetWizButtons
2089 * This code will work if (and assumes that) the Next button is on top of the
2090 * Finish button. ie. Finish comes after Next in the Z order.
2091 * This means make sure the dialog template reflects this.
2094 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2096 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2097 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2098 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2100 TRACE("%ld\n", dwFlags);
2102 EnableWindow(hwndBack, FALSE);
2103 EnableWindow(hwndNext, FALSE);
2104 EnableWindow(hwndFinish, FALSE);
2106 if (dwFlags & PSWIZB_BACK)
2107 EnableWindow(hwndBack, TRUE);
2109 if (dwFlags & PSWIZB_NEXT)
2111 /* Hide the Finish button */
2112 ShowWindow(hwndFinish, SW_HIDE);
2114 /* Show and enable the Next button */
2115 ShowWindow(hwndNext, SW_SHOW);
2116 EnableWindow(hwndNext, TRUE);
2118 /* Set the Next button as the default pushbutton */
2119 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2122 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2124 /* Hide the Next button */
2125 ShowWindow(hwndNext, SW_HIDE);
2127 /* Show the Finish button */
2128 ShowWindow(hwndFinish, SW_SHOW);
2130 if (dwFlags & PSWIZB_FINISH)
2131 EnableWindow(hwndFinish, TRUE);
2133 /* Set the Finish button as the default pushbutton */
2134 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2138 /******************************************************************************
2139 * PROPSHEET_GetPageIndex
2141 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2142 * the array of PropPageInfo.
2144 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2149 TRACE("hpage %p\n", hpage);
2150 while ((index < psInfo->nPages) && (found == FALSE))
2152 if (psInfo->proppage[index].hpage == hpage)
2164 /******************************************************************************
2167 static void PROPSHEET_CleanUp(HWND hwndDlg)
2170 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2174 if (!psInfo) return;
2175 if (HIWORD(psInfo->ppshheader.pszCaption))
2176 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2178 for (i = 0; i < psInfo->nPages; i++)
2180 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2182 if(psInfo->proppage[i].hwndPage)
2183 DestroyWindow(psInfo->proppage[i].hwndPage);
2187 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2188 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2190 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2194 COMCTL32_Free(psInfo->proppage);
2195 COMCTL32_Free(psInfo->strPropertiesFor);
2196 ImageList_Destroy(psInfo->hImageList);
2198 GlobalFree((HGLOBAL)psInfo);
2201 /******************************************************************************
2202 * PropertySheet (COMCTL32.87)
2203 * PropertySheetA (COMCTL32.88)
2205 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2208 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2209 sizeof(PropSheetInfo));
2213 TRACE("(%p)\n", lppsh);
2215 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2217 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2219 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2221 for (n = i = 0; i < lppsh->nPages; i++, n++)
2223 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2224 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2227 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2228 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2231 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2234 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2235 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2241 bRet = PROPSHEET_CreateDialog(psInfo);
2246 /******************************************************************************
2247 * PropertySheetW (COMCTL32.89)
2249 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2252 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2253 sizeof(PropSheetInfo));
2257 TRACE("(%p)\n", lppsh);
2259 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2261 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2263 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2265 for (n = i = 0; i < lppsh->nPages; i++, n++)
2267 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2268 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2271 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2272 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2275 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2278 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2279 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2285 bRet = PROPSHEET_CreateDialog(psInfo);
2290 /******************************************************************************
2291 * CreatePropertySheetPage (COMCTL32.18)
2292 * CreatePropertySheetPageA (COMCTL32.19)
2294 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2295 LPCPROPSHEETPAGEA lpPropSheetPage)
2297 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2299 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2301 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2303 PROPSHEET_AtoW(&ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate);
2305 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2307 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2310 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2312 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2314 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2315 ppsp->pszTitle = NULL;
2317 return (HPROPSHEETPAGE)ppsp;
2320 /******************************************************************************
2321 * CreatePropertySheetPageW (COMCTL32.20)
2323 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2325 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2327 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2329 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2331 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2333 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2334 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2336 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2338 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2339 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2340 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2343 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2345 int len = strlenW(lpPropSheetPage->pszTitle);
2346 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2347 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2349 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2350 ppsp->pszTitle = NULL;
2352 return (HPROPSHEETPAGE)ppsp;
2355 /******************************************************************************
2356 * DestroyPropertySheetPage (COMCTL32.24)
2358 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2360 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2365 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2366 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2368 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2369 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2371 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2372 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2374 COMCTL32_Free(hPropPage);
2379 /******************************************************************************
2380 * PROPSHEET_IsDialogMessage
2382 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2384 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2387 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2390 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2393 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2395 if (!(dlgCode & DLGC_WANTMESSAGE))
2397 switch (lpMsg->wParam)
2400 if (GetKeyState(VK_SHIFT) & 0x8000)
2406 case VK_NEXT: new_page = 1; break;
2407 case VK_PRIOR: new_page = -1; break;
2413 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2415 new_page += psInfo->active_page;
2418 new_page = psInfo->nPages - 1;
2419 else if (new_page >= psInfo->nPages)
2422 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2429 return IsDialogMessageA(hwnd, lpMsg);
2432 /******************************************************************************
2433 * PROPSHEET_DoCommand
2435 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2441 case IDC_APPLY_BUTTON:
2443 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2445 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2450 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2454 if (psInfo->restartWindows)
2455 result = ID_PSRESTARTWINDOWS;
2457 /* reboot system takes precedence over restart windows */
2458 if (psInfo->rebootSystem)
2459 result = ID_PSREBOOTSYSTEM;
2461 if (psInfo->isModeless)
2462 psInfo->activeValid = FALSE;
2464 EndDialog(hwnd, result);
2467 EnableWindow(hwndApplyBtn, FALSE);
2472 case IDC_BACK_BUTTON:
2473 PROPSHEET_Back(hwnd);
2476 case IDC_NEXT_BUTTON:
2477 PROPSHEET_Next(hwnd);
2480 case IDC_FINISH_BUTTON:
2481 PROPSHEET_Finish(hwnd);
2485 PROPSHEET_Cancel(hwnd, 0);
2489 PROPSHEET_Help(hwnd);
2496 /******************************************************************************
2497 * PROPSHEET_DialogProc
2500 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2502 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
2503 hwnd, uMsg, wParam, lParam);
2509 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2510 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2511 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2512 LPCPROPSHEETPAGEW ppshpage;
2515 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2518 * psInfo->hwnd is not being used by WINE code - it exists
2519 * for compatibility with "real" Windoze. The same about
2520 * SetWindowLong - WINE is only using the PropSheetInfoStr
2523 psInfo->hwnd = hwnd;
2524 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2527 * Small icon in the title bar.
2529 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2530 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2533 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2534 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2536 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2537 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2538 psInfo->ppshheader.u.pszIcon,
2543 hIcon = psInfo->ppshheader.u.hIcon;
2545 SendMessageW(hwnd, WM_SETICON, 0, hIcon);
2548 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2549 SendMessageW(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2551 psInfo->strPropertiesFor = strCaption;
2553 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2555 PROPSHEET_CreateTabControl(hwnd, psInfo);
2557 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2559 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2561 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2562 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2567 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2569 PROPSHEET_AdjustSize(hwnd, psInfo);
2570 PROPSHEET_AdjustButtons(hwnd, psInfo);
2574 if (psInfo->useCallback)
2575 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2576 PSCB_INITIALIZED, (LPARAM)0);
2578 idx = psInfo->active_page;
2579 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2580 psInfo->active_page = -1;
2582 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2584 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2585 * as some programs call TCM_GETCURSEL to get the current selection
2586 * from which to switch to the next page */
2587 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2589 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2590 psInfo->ppshheader.hInstance)
2594 if (LoadStringW(psInfo->ppshheader.hInstance,
2595 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2596 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2600 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2601 psInfo->ppshheader.pszCaption);
2608 PROPSHEET_CleanUp(hwnd);
2612 PROPSHEET_Cancel(hwnd, 1);
2616 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2620 NMHDR* pnmh = (LPNMHDR) lParam;
2622 if (pnmh->code == TCN_SELCHANGE)
2624 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2625 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2628 if(pnmh->code == TCN_SELCHANGING)
2630 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2631 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2638 case PSM_GETCURRENTPAGEHWND:
2640 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2644 if (psInfo->activeValid && psInfo->active_page != -1)
2645 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2647 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndPage);
2653 PROPSHEET_Changed(hwnd, (HWND)wParam);
2657 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2660 case PSM_GETTABCONTROL:
2662 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2664 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2673 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2674 if(msgResult != FALSE)
2676 msgResult = PROPSHEET_SetCurSel(hwnd,
2679 (HPROPSHEETPAGE)lParam);
2682 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2687 case PSM_CANCELTOCLOSE:
2689 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2690 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2691 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2693 EnableWindow(hwndCancel, FALSE);
2694 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2695 SetWindowTextW(hwndOK, buf);
2700 case PSM_RESTARTWINDOWS:
2702 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2705 psInfo->restartWindows = TRUE;
2709 case PSM_REBOOTSYSTEM:
2711 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2714 psInfo->rebootSystem = TRUE;
2719 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2723 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2728 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2730 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2735 case PSM_QUERYSIBLINGS:
2737 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2739 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2747 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2748 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2749 * on success or FALSE otherwise, as specified on MSDN Online.
2750 * Also see the MFC code for
2751 * CPropertySheet::AddPage(CPropertyPage* pPage).
2754 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2756 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2761 case PSM_REMOVEPAGE:
2762 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2765 case PSM_ISDIALOGMESSAGE:
2767 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2768 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2772 case PSM_PRESSBUTTON:
2773 PROPSHEET_PressButton(hwnd, (int)wParam);
2776 case PSM_SETFINISHTEXTA:
2777 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2780 case PSM_SETWIZBUTTONS:
2781 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2784 case PSM_SETCURSELID:
2785 FIXME("Unimplemented msg PSM_SETCURSELID\n");
2788 case PSM_SETFINISHTEXTW:
2789 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);