4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
9 * - Unicode property sheets
18 #include "debugtools.h"
22 /******************************************************************************
34 typedef struct tagPropPageInfo
36 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
45 typedef struct tagPropSheetInfo
48 PROPSHEETHEADERW ppshheader;
49 LPWSTR strPropertiesFor;
59 PropPageInfo* proppage;
64 HIMAGELIST hImageList;
73 /******************************************************************************
74 * Defines and global variables
77 const WCHAR PropSheetInfoStr[] =
78 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
80 #define MAX_CAPTION_LENGTH 255
81 #define MAX_TABTEXT_LENGTH 255
82 #define MAX_BUTTONTEXT_LENGTH 64
84 #define PSH_WIZARD97_OLD 0x00002000
85 #define PSH_WIZARD97_NEW 0x01000000
86 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
88 /******************************************************************************
91 static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
92 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
93 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
94 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
95 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
96 PropSheetInfo * psInfo);
97 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
98 PropSheetInfo * psInfo);
99 static BOOL PROPSHEET_CollectPageInfoA(LPCPROPSHEETPAGEA lppsp,
100 PropSheetInfo * psInfo,
102 static BOOL PROPSHEET_CollectPageInfoW(LPCPROPSHEETPAGEW lppsp,
103 PropSheetInfo * psInfo,
105 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
106 PropSheetInfo * psInfo);
107 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
108 const PropSheetInfo * psInfo,
109 LPCPROPSHEETPAGEW ppshpage);
110 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
111 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
112 static BOOL PROPSHEET_Back(HWND hwndDlg);
113 static BOOL PROPSHEET_Next(HWND hwndDlg);
114 static BOOL PROPSHEET_Finish(HWND hwndDlg);
115 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
116 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
117 static void PROPSHEET_Help(HWND hwndDlg);
118 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
119 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
120 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
121 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
122 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText);
123 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
124 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
125 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
126 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
129 HPROPSHEETPAGE hpage);
130 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
131 WPARAM wParam, LPARAM lParam);
132 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
133 HPROPSHEETPAGE hpage);
135 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
137 HPROPSHEETPAGE hpage);
138 static void PROPSHEET_CleanUp();
139 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
140 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
141 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
142 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
143 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
146 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
148 DEFAULT_DEBUG_CHANNEL(propsheet);
150 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
151 /******************************************************************************
152 * PROPSHEET_UnImplementedFlags
154 * Document use of flags we don't implement yet.
156 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
163 * unhandled header flags:
164 * PSH_DEFAULT 0x00000000
165 * PSH_WIZARDHASFINISH 0x00000010
166 * PSH_RTLREADING 0x00000800
167 * PSH_WIZARDCONTEXTHELP 0x00001000
168 * PSH_WIZARD97 0x00002000 (pre IE 5)
169 * PSH_WATERMARK 0x00008000
170 * PSH_USEHBMWATERMARK 0x00010000
171 * PSH_USEHPLWATERMARK 0x00020000
172 * PSH_STRETCHWATERMARK 0x00040000
173 * PSH_HEADER 0x00080000
174 * PSH_USEHBMHEADER 0x00100000
175 * PSH_USEPAGELANG 0x00200000
176 * PSH_WIZARD_LITE 0x00400000 also not in .h
177 * PSH_WIZARD97 0x01000000 (IE 5 and above)
178 * PSH_NOCONTEXTHELP 0x02000000 also not in .h
181 add_flag(PSH_WIZARDHASFINISH);
182 add_flag(PSH_RTLREADING);
183 add_flag(PSH_WIZARDCONTEXTHELP);
184 add_flag(PSH_WIZARD97_OLD);
185 add_flag(PSH_WATERMARK);
186 add_flag(PSH_USEHBMWATERMARK);
187 add_flag(PSH_USEHPLWATERMARK);
188 add_flag(PSH_STRETCHWATERMARK);
189 add_flag(PSH_HEADER);
190 add_flag(PSH_USEHBMHEADER);
191 add_flag(PSH_USEPAGELANG);
192 add_flag(PSH_WIZARD_LITE);
193 add_flag(PSH_WIZARD97_NEW);
194 add_flag(PSH_NOCONTEXTHELP);
195 if (string[0] != '\0')
196 FIXME("%s\n", string);
200 /******************************************************************************
201 * PROPSHEET_CollectSheetInfoA
203 * Collect relevant data.
205 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
206 PropSheetInfo * psInfo)
208 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
209 DWORD dwFlags = lppsh->dwFlags;
211 psInfo->hasHelp = dwFlags & PSH_HASHELP;
212 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
213 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
214 psInfo->isModeless = dwFlags & PSH_MODELESS;
216 memcpy(&psInfo->ppshheader,lppsh,dwSize);
217 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",
218 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
219 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
221 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
223 if (HIWORD(lppsh->pszCaption))
225 int len = strlen(lppsh->pszCaption);
226 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
227 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
228 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
230 psInfo->nPages = lppsh->nPages;
232 if (dwFlags & PSH_USEPSTARTPAGE)
234 TRACE("PSH_USEPSTARTPAGE is on");
235 psInfo->active_page = 0;
238 psInfo->active_page = lppsh->u2.nStartPage;
240 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
241 psInfo->active_page = 0;
243 psInfo->restartWindows = FALSE;
244 psInfo->rebootSystem = FALSE;
245 psInfo->hImageList = 0;
246 psInfo->activeValid = FALSE;
251 /******************************************************************************
252 * PROPSHEET_CollectSheetInfoW
254 * Collect relevant data.
256 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
257 PropSheetInfo * psInfo)
259 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
260 DWORD dwFlags = lppsh->dwFlags;
262 psInfo->hasHelp = dwFlags & PSH_HASHELP;
263 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
264 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
265 psInfo->isModeless = dwFlags & PSH_MODELESS;
267 memcpy(&psInfo->ppshheader,lppsh,dwSize);
268 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",
269 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
271 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
273 if (HIWORD(lppsh->pszCaption))
275 int len = strlenW(lppsh->pszCaption);
276 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
277 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
279 psInfo->nPages = lppsh->nPages;
281 if (dwFlags & PSH_USEPSTARTPAGE)
283 TRACE("PSH_USEPSTARTPAGE is on");
284 psInfo->active_page = 0;
287 psInfo->active_page = lppsh->u2.nStartPage;
289 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
290 psInfo->active_page = 0;
292 psInfo->restartWindows = FALSE;
293 psInfo->rebootSystem = FALSE;
294 psInfo->hImageList = 0;
295 psInfo->activeValid = FALSE;
300 /******************************************************************************
301 * PROPSHEET_CollectPageInfoA
303 * Collect property sheet data.
304 * With code taken from DIALOG_ParseTemplate32.
306 BOOL PROPSHEET_CollectPageInfoA(LPCPROPSHEETPAGEA lppsp,
307 PropSheetInfo * psInfo,
310 DLGTEMPLATE* pTemplate;
316 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
317 psInfo->proppage[index].hwndPage = 0;
318 psInfo->proppage[index].isDirty = FALSE;
321 * Process property page flags.
323 dwFlags = lppsp->dwFlags;
324 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
325 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
326 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
328 /* as soon as we have a page with the help flag, set the sheet flag on */
329 if (psInfo->proppage[index].hasHelp)
330 psInfo->hasHelp = TRUE;
333 * Process page template.
335 if (dwFlags & PSP_DLGINDIRECT)
336 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
339 HRSRC hResource = FindResourceA(lppsp->hInstance,
340 lppsp->u.pszTemplate,
342 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
344 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
348 * Extract the size of the page and the caption.
353 p = (const WORD *)pTemplate;
355 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
357 /* DIALOGEX template */
361 p += 2; /* help ID */
362 p += 2; /* ext style */
367 /* DIALOG template */
370 p += 2; /* ext style */
376 width = (WORD)*p; p++;
377 height = (WORD)*p; p++;
379 /* remember the largest width and height */
380 if (width > psInfo->width)
381 psInfo->width = width;
383 if (height > psInfo->height)
384 psInfo->height = height;
396 p += lstrlenW( (LPCWSTR)p ) + 1;
410 p += lstrlenW( (LPCWSTR)p ) + 1;
414 /* Extract the caption */
415 psInfo->proppage[index].pszText = (LPCWSTR)p;
416 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
417 p += lstrlenW((LPCWSTR)p) + 1;
419 if (dwFlags & PSP_USETITLE)
421 if ( !HIWORD( lppsp->pszTitle ) )
425 if (LoadStringA( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,256 )) {
426 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(), 0, szTitle );
428 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(), 0, "(null)" );
429 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
433 psInfo->proppage[index].pszText = HEAP_strdupAtoW(GetProcessHeap(),
439 * Build the image list for icons
441 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
444 int icon_cx = GetSystemMetrics(SM_CXSMICON);
445 int icon_cy = GetSystemMetrics(SM_CYSMICON);
447 if (dwFlags & PSP_USEICONID)
448 hIcon = LoadImageA(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
449 icon_cx, icon_cy, LR_DEFAULTCOLOR);
451 hIcon = lppsp->u2.hIcon;
455 if (psInfo->hImageList == 0 )
456 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
458 ImageList_AddIcon(psInfo->hImageList, hIcon);
466 /******************************************************************************
467 * PROPSHEET_CollectPageInfoW
469 * Collect property sheet data.
470 * With code taken from DIALOG_ParseTemplate32.
472 BOOL PROPSHEET_CollectPageInfoW(LPCPROPSHEETPAGEW lppsp,
473 PropSheetInfo * psInfo,
476 DLGTEMPLATE* pTemplate;
482 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
483 psInfo->proppage[index].hwndPage = 0;
484 psInfo->proppage[index].isDirty = FALSE;
487 * Process property page flags.
489 dwFlags = lppsp->dwFlags;
490 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
491 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
492 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
494 /* as soon as we have a page with the help flag, set the sheet flag on */
495 if (psInfo->proppage[index].hasHelp)
496 psInfo->hasHelp = TRUE;
499 * Process page template.
501 if (dwFlags & PSP_DLGINDIRECT)
502 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
505 HRSRC hResource = FindResourceW(lppsp->hInstance,
506 lppsp->u.pszTemplate,
508 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
510 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
514 * Extract the size of the page and the caption.
519 p = (const WORD *)pTemplate;
521 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
523 /* DIALOGEX template */
527 p += 2; /* help ID */
528 p += 2; /* ext style */
533 /* DIALOG template */
536 p += 2; /* ext style */
542 width = (WORD)*p; p++;
543 height = (WORD)*p; p++;
545 /* remember the largest width and height */
546 if (width > psInfo->width)
547 psInfo->width = width;
549 if (height > psInfo->height)
550 psInfo->height = height;
562 p += lstrlenW( (LPCWSTR)p ) + 1;
576 p += lstrlenW( (LPCWSTR)p ) + 1;
580 /* Extract the caption */
581 psInfo->proppage[index].pszText = (LPCWSTR)p;
582 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
583 p += lstrlenW((LPCWSTR)p) + 1;
585 if (dwFlags & PSP_USETITLE)
589 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
592 if ( !HIWORD( lppsp->pszTitle ) )
594 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
597 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
603 pTitle = lppsp->pszTitle;
605 len = strlenW(szTitle);
606 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
607 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
611 * Build the image list for icons
613 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
616 int icon_cx = GetSystemMetrics(SM_CXSMICON);
617 int icon_cy = GetSystemMetrics(SM_CYSMICON);
619 if (dwFlags & PSP_USEICONID)
620 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
621 icon_cx, icon_cy, LR_DEFAULTCOLOR);
623 hIcon = lppsp->u2.hIcon;
627 if (psInfo->hImageList == 0 )
628 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
630 ImageList_AddIcon(psInfo->hImageList, hIcon);
638 /******************************************************************************
639 * PROPSHEET_CreateDialog
641 * Creates the actual property sheet.
643 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
650 WORD resID = IDD_PROPSHEET;
653 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
656 if(!(hRes = FindResourceW(COMCTL32_hModule,
657 MAKEINTRESOURCEW(resID),
661 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
665 * Make a copy of the dialog template.
667 resSize = SizeofResource(COMCTL32_hModule, hRes);
669 temp = COMCTL32_Alloc(resSize);
674 memcpy(temp, template, resSize);
676 if (psInfo->useCallback)
677 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
679 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
680 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
681 (LPDLGTEMPLATEW) temp,
682 psInfo->ppshheader.hwndParent,
683 (DLGPROC) PROPSHEET_DialogProc,
686 ret = CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
687 (LPDLGTEMPLATEW) temp,
688 psInfo->ppshheader.hwndParent,
689 (DLGPROC) PROPSHEET_DialogProc,
697 /******************************************************************************
698 * PROPSHEET_SizeMismatch
700 * Verify that the tab control and the "largest" property sheet page dlg. template
703 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
705 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
706 RECT rcOrigTab, rcPage;
711 GetClientRect(hwndTabCtrl, &rcOrigTab);
712 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
713 rcOrigTab.right, rcOrigTab.bottom);
718 rcPage.left = psInfo->x;
719 rcPage.top = psInfo->y;
720 rcPage.right = psInfo->width;
721 rcPage.bottom = psInfo->height;
723 MapDialogRect(hwndDlg, &rcPage);
724 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
725 rcPage.right, rcPage.bottom);
727 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
729 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
735 /******************************************************************************
736 * PROPSHEET_IsTooSmallWizard
738 * Verify that the default property sheet is big enough.
740 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
742 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
743 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
744 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
746 GetClientRect(hwndDlg, &rcSheetClient);
747 GetWindowRect(hwndDlg, &rcSheetRect);
748 GetWindowRect(hwndLine, &rcLine);
750 /* Remove the space below the sunken line */
751 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
753 /* Remove the buffer zone all around the edge */
754 rcSheetClient.bottom -= (padding.y * 2);
755 rcSheetClient.right -= (padding.x * 2);
760 rcPage.left = psInfo->x;
761 rcPage.top = psInfo->y;
762 rcPage.right = psInfo->width;
763 rcPage.bottom = psInfo->height;
765 MapDialogRect(hwndDlg, &rcPage);
766 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
767 rcPage.right, rcPage.bottom);
769 if (rcPage.right > rcSheetClient.right)
772 if (rcPage.bottom > rcSheetClient.bottom)
778 /******************************************************************************
779 * PROPSHEET_AdjustSize
781 * Resizes the property sheet and the tab control to fit the largest page.
783 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
785 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
786 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
788 int tabOffsetX, tabOffsetY, buttonHeight;
789 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
792 /* Get the height of buttons */
793 GetClientRect(hwndButton, &rc);
794 buttonHeight = rc.bottom;
801 rc.right = psInfo->width;
802 rc.bottom = psInfo->height;
804 MapDialogRect(hwndDlg, &rc);
806 /* retrieve the dialog units */
807 units.left = units.right = 4;
808 units.top = units.bottom = 8;
809 MapDialogRect(hwndDlg, &units);
812 * Resize the tab control.
814 GetClientRect(hwndTabCtrl,&tabRect);
816 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
818 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
820 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
821 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
824 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
826 rc.right = rc.left + tabRect.right - tabRect.left;
827 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
830 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
832 tabOffsetX = -(rc.left);
833 tabOffsetY = -(rc.top);
837 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
838 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
840 GetClientRect(hwndTabCtrl, &rc);
842 TRACE("tab client rc %d %d %d %d\n",
843 rc.left, rc.top, rc.right, rc.bottom);
845 rc.right += ((padding.x * 2) + tabOffsetX);
846 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
849 * Resize the property sheet.
851 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
852 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
856 /******************************************************************************
857 * PROPSHEET_AdjustSizeWizard
859 * Resizes the property sheet to fit the largest page.
861 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
863 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
864 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
865 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
867 int buttonHeight, lineHeight;
868 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
871 /* Get the height of buttons */
872 GetClientRect(hwndButton, &rc);
873 buttonHeight = rc.bottom;
875 GetClientRect(hwndLine, &rc);
876 lineHeight = rc.bottom;
878 /* retrieve the dialog units */
879 units.left = units.right = 4;
880 units.top = units.bottom = 8;
881 MapDialogRect(hwndDlg, &units);
888 rc.right = psInfo->width;
889 rc.bottom = psInfo->height;
891 MapDialogRect(hwndDlg, &rc);
893 GetClientRect(hwndTabCtrl,&tabRect);
895 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
897 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
898 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
901 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
903 rc.right = rc.left + tabRect.right - tabRect.left;
904 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
907 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
910 rc.right += (padding.x * 2);
911 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
914 * Resize the property sheet.
916 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
917 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
921 /******************************************************************************
922 * PROPSHEET_AdjustButtons
924 * Adjusts the buttons' positions.
926 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
928 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
932 int buttonWidth, buttonHeight;
933 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
935 if (psInfo->hasApply)
942 * Obtain the size of the buttons.
944 GetClientRect(hwndButton, &rcSheet);
945 buttonWidth = rcSheet.right;
946 buttonHeight = 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 OK button.
961 hwndButton = GetDlgItem(hwndParent, IDOK);
963 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
965 SetWindowPos(hwndButton, 0, x, y, 0, 0,
966 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
969 * Position Cancel button.
971 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
973 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
975 SetWindowPos(hwndButton, 0, x, y, 0, 0,
976 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
979 * Position Apply button.
981 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
983 if (psInfo->hasApply)
986 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
988 x = rcSheet.right - (padding.x + buttonWidth);
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
993 EnableWindow(hwndButton, FALSE);
996 ShowWindow(hwndButton, SW_HIDE);
999 * Position Help button.
1001 hwndButton = GetDlgItem(hwndParent, IDHELP);
1003 if (psInfo->hasHelp)
1005 x = rcSheet.right - (padding.x + buttonWidth);
1007 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1008 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1011 ShowWindow(hwndButton, SW_HIDE);
1016 /******************************************************************************
1017 * PROPSHEET_AdjustButtonsWizard
1019 * Adjusts the buttons' positions.
1021 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
1022 PropSheetInfo* psInfo)
1024 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1025 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
1028 int num_buttons = 3;
1029 int buttonWidth, buttonHeight, lineHeight, lineWidth;
1030 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1032 if (psInfo->hasHelp)
1036 * Obtain the size of the buttons.
1038 GetClientRect(hwndButton, &rcSheet);
1039 buttonWidth = rcSheet.right;
1040 buttonHeight = rcSheet.bottom;
1042 GetClientRect(hwndLine, &rcSheet);
1043 lineHeight = rcSheet.bottom;
1046 * Get the size of the property sheet.
1048 GetClientRect(hwndParent, &rcSheet);
1051 * All buttons will be at this y coordinate.
1053 y = rcSheet.bottom - (padding.y + buttonHeight);
1056 * Position the Next and the Finish buttons.
1058 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
1060 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
1062 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1063 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1065 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1067 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1068 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1070 ShowWindow(hwndButton, SW_HIDE);
1073 * Position the Back button.
1075 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
1079 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1080 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1083 * Position the Cancel button.
1085 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1087 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
1089 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1090 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1093 * Position Help button.
1095 hwndButton = GetDlgItem(hwndParent, IDHELP);
1097 if (psInfo->hasHelp)
1099 x = rcSheet.right - (padding.x + buttonWidth);
1101 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1102 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1105 ShowWindow(hwndButton, SW_HIDE);
1108 * Position and resize the sunken line.
1111 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1113 GetClientRect(hwndParent, &rcSheet);
1114 lineWidth = rcSheet.right - (padding.x * 2);
1116 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1117 SWP_NOZORDER | SWP_NOACTIVATE);
1122 /******************************************************************************
1123 * PROPSHEET_GetPaddingInfo
1125 * Returns the layout information.
1127 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1129 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1132 PADDING_INFO padding;
1134 GetWindowRect(hwndTab, &rcTab);
1139 ScreenToClient(hwndDlg, &tl);
1147 /******************************************************************************
1148 * PROPSHEET_GetPaddingInfoWizard
1150 * Returns the layout information.
1151 * Vertical spacing is the distance between the line and the buttons.
1152 * Do NOT use the Help button to gather padding information when it isn't mapped
1153 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1154 * for it in this case !
1155 * FIXME: I'm not sure about any other coordinate problems with these evil
1156 * buttons. Fix it in case additional problems appear or maybe calculate
1157 * a padding in a completely different way, as this is somewhat messy.
1159 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1162 PADDING_INFO padding;
1166 POINT ptButton, ptLine;
1169 if (psInfo->hasHelp)
1175 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1177 idButton = IDC_NEXT_BUTTON;
1181 /* hopefully this is ok */
1182 idButton = IDCANCEL;
1186 hwndControl = GetDlgItem(hwndDlg, idButton);
1187 GetWindowRect(hwndControl, &rc);
1189 ptButton.x = rc.left;
1190 ptButton.y = rc.top;
1192 ScreenToClient(hwndDlg, &ptButton);
1195 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1196 GetWindowRect(hwndControl, &rc);
1199 ptLine.y = rc.bottom;
1201 ScreenToClient(hwndDlg, &ptLine);
1203 padding.y = ptButton.y - ptLine.y;
1206 ERR("padding negative ! Please report this !\n");
1208 /* this is most probably not correct, but the best we have now */
1209 padding.x = padding.y;
1213 /******************************************************************************
1214 * PROPSHEET_CreateTabControl
1216 * Insert the tabs in the tab control.
1218 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1219 PropSheetInfo * psInfo)
1221 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1227 item.mask = TCIF_TEXT;
1228 item.cchTextMax = MAX_TABTEXT_LENGTH;
1230 nTabs = psInfo->nPages;
1233 * Set the image list for icons.
1235 if (psInfo->hImageList)
1237 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1240 for (i = 0; i < nTabs; i++)
1242 if ( psInfo->proppage[i].hasIcon )
1244 item.mask |= TCIF_IMAGE;
1245 item.iImage = iImage++;
1249 item.mask &= ~TCIF_IMAGE;
1252 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1253 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1259 /******************************************************************************
1260 * PROPSHEET_CreatePage
1264 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1266 const PropSheetInfo * psInfo,
1267 LPCPROPSHEETPAGEW ppshpage)
1269 DLGTEMPLATE* pTemplate;
1272 PropPageInfo* ppInfo = psInfo->proppage;
1273 PADDING_INFO padding;
1274 UINT pageWidth,pageHeight;
1278 TRACE("index %d\n", index);
1280 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1281 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1287 hResource = FindResourceW(ppshpage->hInstance,
1288 ppshpage->u.pszTemplate,
1293 resSize = SizeofResource(ppshpage->hInstance, hResource);
1295 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1299 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1301 * Make a copy of the dialog template to make it writable
1303 temp = COMCTL32_Alloc(resSize);
1307 memcpy(temp, pTemplate, resSize);
1311 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1313 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1314 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1315 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1316 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1317 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1318 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1319 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1323 pTemplate->style |= WS_CHILD | DS_CONTROL;
1324 pTemplate->style &= ~DS_MODALFRAME;
1325 pTemplate->style &= ~WS_CAPTION;
1326 pTemplate->style &= ~WS_SYSMENU;
1327 pTemplate->style &= ~WS_POPUP;
1328 pTemplate->style &= ~WS_DISABLED;
1329 pTemplate->style &= ~WS_VISIBLE;
1332 if (psInfo->proppage[index].useCallback)
1333 (*(ppshpage->pfnCallback))(hwndParent,
1335 (LPPROPSHEETPAGEW)ppshpage);
1337 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1340 ppshpage->pfnDlgProc,
1342 /* Free a no more needed copy */
1344 COMCTL32_Free(temp);
1346 ppInfo[index].hwndPage = hwndPage;
1348 rc.left = psInfo->x;
1350 rc.right = psInfo->width;
1351 rc.bottom = psInfo->height;
1353 MapDialogRect(hwndParent, &rc);
1355 pageWidth = rc.right - rc.left;
1356 pageHeight = rc.bottom - rc.top;
1358 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1359 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1363 * Ask the Tab control to fit this page in.
1366 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1367 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1368 padding = PROPSHEET_GetPaddingInfo(hwndParent);
1371 SetWindowPos(hwndPage, HWND_TOP,
1372 rc.left + padding.x,
1374 pageWidth, pageHeight, 0);
1379 /******************************************************************************
1380 * PROPSHEET_ShowPage
1382 * Displays or creates the specified page.
1384 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1388 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1389 if (index == psInfo->active_page)
1391 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1392 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1396 if (psInfo->proppage[index].hwndPage == 0)
1398 LPCPROPSHEETPAGEW ppshpage;
1400 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1401 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1404 if (psInfo->active_page != -1)
1405 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1407 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1409 /* Synchronize current selection with tab control
1410 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1411 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1412 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1414 psInfo->active_page = index;
1415 psInfo->activeValid = TRUE;
1420 /******************************************************************************
1423 static BOOL PROPSHEET_Back(HWND hwndDlg)
1428 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_WIZBACK;
1437 psn.hdr.hwndFrom = hwndDlg;
1441 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1443 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1447 if (psInfo->active_page > 0)
1449 res = PROPSHEET_CanSetCurSel(hwndDlg);
1452 res = PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page - 1, -1, 0);
1459 /******************************************************************************
1462 static BOOL PROPSHEET_Next(HWND hwndDlg)
1466 LRESULT msgResult = 0;
1467 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1470 TRACE("active_page %d\n", psInfo->active_page);
1471 if (psInfo->active_page < 0)
1474 psn.hdr.code = PSN_WIZNEXT;
1475 psn.hdr.hwndFrom = hwndDlg;
1479 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1481 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1482 if (msgResult == -1)
1485 if(PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1487 PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page + 1, 1, 0);
1493 /******************************************************************************
1496 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1500 LRESULT msgResult = 0;
1501 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1504 TRACE("active_page %d\n", psInfo->active_page);
1505 if (psInfo->active_page < 0)
1508 psn.hdr.code = PSN_WIZFINISH;
1509 psn.hdr.hwndFrom = hwndDlg;
1513 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1515 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1517 TRACE("msg result %ld\n", msgResult);
1522 if (psInfo->isModeless)
1523 psInfo->activeValid = FALSE;
1525 EndDialog(hwndDlg, TRUE);
1530 /******************************************************************************
1533 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1539 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1542 TRACE("active_page %d\n", psInfo->active_page);
1543 if (psInfo->active_page < 0)
1546 psn.hdr.hwndFrom = hwndDlg;
1552 * Send PSN_KILLACTIVE to the current page.
1554 psn.hdr.code = PSN_KILLACTIVE;
1556 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1558 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1562 * Send PSN_APPLY to all pages.
1564 psn.hdr.code = PSN_APPLY;
1565 psn.lParam = lParam;
1567 for (i = 0; i < psInfo->nPages; i++)
1569 hwndPage = psInfo->proppage[i].hwndPage;
1572 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1573 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1580 psInfo->activeValid = FALSE;
1582 else if(psInfo->active_page >= 0)
1584 psn.hdr.code = PSN_SETACTIVE;
1586 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1587 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1593 /******************************************************************************
1596 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1598 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1604 TRACE("active_page %d\n", psInfo->active_page);
1605 if (psInfo->active_page < 0)
1608 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1609 psn.hdr.code = PSN_QUERYCANCEL;
1610 psn.hdr.hwndFrom = hwndDlg;
1614 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1617 psn.hdr.code = PSN_RESET;
1618 psn.lParam = lParam;
1620 for (i = 0; i < psInfo->nPages; i++)
1622 hwndPage = psInfo->proppage[i].hwndPage;
1625 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1628 if (psInfo->isModeless)
1630 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1631 psInfo->activeValid = FALSE;
1634 EndDialog(hwndDlg, FALSE);
1637 /******************************************************************************
1640 static void PROPSHEET_Help(HWND hwndDlg)
1642 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1647 TRACE("active_page %d\n", psInfo->active_page);
1648 if (psInfo->active_page < 0)
1651 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1652 psn.hdr.code = PSN_HELP;
1653 psn.hdr.hwndFrom = hwndDlg;
1657 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1660 /******************************************************************************
1663 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1666 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1670 if (!psInfo) return;
1672 * Set the dirty flag of this page.
1674 for (i = 0; i < psInfo->nPages; i++)
1676 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1677 psInfo->proppage[i].isDirty = TRUE;
1681 * Enable the Apply button.
1683 if (psInfo->hasApply)
1685 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1687 EnableWindow(hwndApplyBtn, TRUE);
1691 /******************************************************************************
1692 * PROPSHEET_UnChanged
1694 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1697 BOOL noPageDirty = TRUE;
1698 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1699 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1703 if ( !psInfo ) return;
1704 for (i = 0; i < psInfo->nPages; i++)
1706 /* set the specified page as clean */
1707 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1708 psInfo->proppage[i].isDirty = FALSE;
1710 /* look to see if there's any dirty pages */
1711 if (psInfo->proppage[i].isDirty)
1712 noPageDirty = FALSE;
1716 * Disable Apply button.
1719 EnableWindow(hwndApplyBtn, FALSE);
1722 /******************************************************************************
1723 * PROPSHEET_PressButton
1725 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1727 TRACE("buttonID %d\n", buttonID);
1730 case PSBTN_APPLYNOW:
1731 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1734 PROPSHEET_Back(hwndDlg);
1737 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1740 PROPSHEET_Finish(hwndDlg);
1743 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1746 PROPSHEET_Next(hwndDlg);
1749 PROPSHEET_DoCommand(hwndDlg, IDOK);
1752 FIXME("Invalid button index %d\n", buttonID);
1757 /*************************************************************************
1758 * BOOL PROPSHEET_CanSetCurSel [Internal]
1760 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1763 * hwndDlg [I] handle to a Dialog hWnd
1766 * TRUE if Current Selection can change
1770 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1772 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1778 TRACE("active_page %d\n", psInfo->active_page);
1785 if (psInfo->active_page < 0)
1792 * Notify the current page.
1794 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1795 psn.hdr.code = PSN_KILLACTIVE;
1796 psn.hdr.hwndFrom = hwndDlg;
1800 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1803 TRACE("<-- %d\n", res);
1807 /******************************************************************************
1808 * PROPSHEET_SetCurSel
1810 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1813 HPROPSHEETPAGE hpage
1816 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1817 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1819 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1820 /* hpage takes precedence over index */
1822 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1824 if (index < 0 || index >= psInfo->nPages)
1826 TRACE("Could not find page to select!\n");
1834 psn.hdr.code = PSN_SETACTIVE;
1835 psn.hdr.hwndFrom = hwndDlg;
1839 if (!psInfo->proppage[index].hwndPage) {
1840 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1841 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1844 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1851 FIXME("Tried to skip before first property sheet page!\n");
1854 if (index >= psInfo->nPages) {
1855 FIXME("Tried to skip after last property sheet page!\n");
1856 index = psInfo->nPages-1;
1862 * Display the new page.
1864 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1866 if (psInfo->proppage[index].hasHelp)
1867 EnableWindow(hwndHelp, TRUE);
1869 EnableWindow(hwndHelp, FALSE);
1874 /******************************************************************************
1875 * PROPSHEET_SetTitleA
1877 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1879 if(HIWORD(lpszText))
1882 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1883 szTitle, sizeof szTitle);
1884 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
1888 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
1892 /******************************************************************************
1893 * PROPSHEET_SetTitleW
1895 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
1897 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1900 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
1901 if (HIWORD(lpszText) == 0) {
1902 if (!LoadStringW(psInfo->ppshheader.hInstance,
1903 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
1907 if (dwStyle & PSH_PROPTITLE)
1910 int lentitle = strlenW(lpszText);
1911 int lenprop = strlenW(psInfo->strPropertiesFor);
1913 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
1914 strcpyW(dest, psInfo->strPropertiesFor);
1915 strcatW(dest, lpszText);
1917 SetWindowTextW(hwndDlg, dest);
1918 COMCTL32_Free(dest);
1921 SetWindowTextW(hwndDlg, lpszText);
1924 /******************************************************************************
1925 * PROPSHEET_SetFinishTextA
1927 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1929 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1931 TRACE("'%s'\n", lpszText);
1932 /* Set text, show and enable the Finish button */
1933 SetWindowTextA(hwndButton, lpszText);
1934 ShowWindow(hwndButton, SW_SHOW);
1935 EnableWindow(hwndButton, TRUE);
1937 /* Make it default pushbutton */
1938 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1940 /* Hide Back button */
1941 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1942 ShowWindow(hwndButton, SW_HIDE);
1944 /* Hide Next button */
1945 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1946 ShowWindow(hwndButton, SW_HIDE);
1949 /******************************************************************************
1950 * PROPSHEET_SetFinishTextW
1952 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
1954 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1956 TRACE("'%s'\n", debugstr_w(lpszText));
1957 /* Set text, show and enable the Finish button */
1958 SetWindowTextW(hwndButton, lpszText);
1959 ShowWindow(hwndButton, SW_SHOW);
1960 EnableWindow(hwndButton, TRUE);
1962 /* Make it default pushbutton */
1963 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1965 /* Hide Back button */
1966 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1967 ShowWindow(hwndButton, SW_HIDE);
1969 /* Hide Next button */
1970 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1971 ShowWindow(hwndButton, SW_HIDE);
1974 /******************************************************************************
1975 * PROPSHEET_QuerySiblings
1977 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1978 WPARAM wParam, LPARAM lParam)
1982 LRESULT msgResult = 0;
1983 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1986 while ((i < psInfo->nPages) && (msgResult == 0))
1988 hwndPage = psInfo->proppage[i].hwndPage;
1989 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1997 /******************************************************************************
2000 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2001 HPROPSHEETPAGE hpage)
2003 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2005 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2007 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2009 TRACE("hpage %p\n", hpage);
2011 * Allocate and fill in a new PropPageInfo entry.
2013 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
2014 sizeof(PropPageInfo) *
2015 (psInfo->nPages + 1));
2016 if (!PROPSHEET_CollectPageInfoW(ppsp, psInfo, psInfo->nPages))
2019 psInfo->proppage[psInfo->nPages].hpage = hpage;
2021 if (ppsp->dwFlags & PSP_PREMATURE)
2023 /* Create the page but don't show it */
2024 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2028 * Add a new tab to the tab control.
2030 item.mask = TCIF_TEXT;
2031 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2032 item.cchTextMax = MAX_TABTEXT_LENGTH;
2034 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2039 /* If it is the only page - show it */
2040 if(psInfo->nPages == 1)
2041 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2045 /******************************************************************************
2046 * PROPSHEET_RemovePage
2048 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2050 HPROPSHEETPAGE hpage)
2052 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
2054 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2055 PropPageInfo* oldPages;
2057 TRACE("index %d, hpage %p\n", index, hpage);
2061 oldPages = psInfo->proppage;
2063 * hpage takes precedence over index.
2067 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2070 /* Make sure that index is within range */
2071 if (index < 0 || index >= psInfo->nPages)
2073 TRACE("Could not find page to remove!\n");
2077 TRACE("total pages %d removing page %d active page %d\n",
2078 psInfo->nPages, index, psInfo->active_page);
2080 * Check if we're removing the active page.
2082 if (index == psInfo->active_page)
2084 if (psInfo->nPages > 1)
2088 /* activate previous page */
2089 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2093 /* activate the next page */
2094 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2095 psInfo->active_page = index;
2100 psInfo->active_page = -1;
2101 if (!psInfo->isModeless)
2103 EndDialog(hwndDlg, FALSE);
2108 else if (index < psInfo->active_page)
2109 psInfo->active_page--;
2111 /* Destroy page dialog window */
2112 DestroyWindow(psInfo->proppage[index].hwndPage);
2114 /* Free page resources */
2115 if(psInfo->proppage[index].hpage)
2117 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2119 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2120 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2122 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2125 /* Remove the tab */
2126 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2129 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2132 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2134 if (index < psInfo->nPages)
2135 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2136 (psInfo->nPages - index) * sizeof(PropPageInfo));
2138 COMCTL32_Free(oldPages);
2143 /******************************************************************************
2144 * PROPSHEET_SetWizButtons
2146 * This code will work if (and assumes that) the Next button is on top of the
2147 * Finish button. ie. Finish comes after Next in the Z order.
2148 * This means make sure the dialog template reflects this.
2151 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2153 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2154 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2155 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2157 TRACE("%ld\n", dwFlags);
2159 EnableWindow(hwndBack, FALSE);
2160 EnableWindow(hwndNext, FALSE);
2161 EnableWindow(hwndFinish, FALSE);
2163 if (dwFlags & PSWIZB_BACK)
2164 EnableWindow(hwndBack, TRUE);
2166 if (dwFlags & PSWIZB_NEXT)
2168 /* Hide the Finish button */
2169 ShowWindow(hwndFinish, SW_HIDE);
2171 /* Show and enable the Next button */
2172 ShowWindow(hwndNext, SW_SHOW);
2173 EnableWindow(hwndNext, TRUE);
2175 /* Set the Next button as the default pushbutton */
2176 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2179 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2181 /* Hide the Next button */
2182 ShowWindow(hwndNext, SW_HIDE);
2184 /* Show the Finish button */
2185 ShowWindow(hwndFinish, SW_SHOW);
2187 if (dwFlags & PSWIZB_FINISH)
2188 EnableWindow(hwndFinish, TRUE);
2190 /* Set the Finish button as the default pushbutton */
2191 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2195 /******************************************************************************
2196 * PROPSHEET_GetPageIndex
2198 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2199 * the array of PropPageInfo.
2201 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2206 TRACE("hpage %p\n", hpage);
2207 while ((index < psInfo->nPages) && (found == FALSE))
2209 if (psInfo->proppage[index].hpage == hpage)
2221 /******************************************************************************
2224 static void PROPSHEET_CleanUp(HWND hwndDlg)
2227 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2231 if (!psInfo) return;
2232 if (HIWORD(psInfo->ppshheader.pszCaption))
2233 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2235 for (i = 0; i < psInfo->nPages; i++)
2237 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2239 if(psInfo->proppage[i].hwndPage)
2240 DestroyWindow(psInfo->proppage[i].hwndPage);
2244 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2245 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2247 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2251 COMCTL32_Free(psInfo->proppage);
2252 COMCTL32_Free(psInfo->strPropertiesFor);
2253 ImageList_Destroy(psInfo->hImageList);
2255 GlobalFree((HGLOBAL)psInfo);
2258 /******************************************************************************
2259 * PropertySheet (COMCTL32.87)
2260 * PropertySheetA (COMCTL32.88)
2262 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2265 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2266 sizeof(PropSheetInfo));
2270 TRACE("(%p)\n", lppsh);
2272 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2274 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2276 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2278 for (n = i = 0; i < lppsh->nPages; i++, n++)
2280 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2281 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2284 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2285 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2288 if (!PROPSHEET_CollectPageInfoA((LPCPROPSHEETPAGEA)psInfo->proppage[n].hpage,
2291 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2292 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2298 bRet = PROPSHEET_CreateDialog(psInfo);
2303 /******************************************************************************
2304 * PropertySheetW (COMCTL32.89)
2306 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2309 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2310 sizeof(PropSheetInfo));
2314 TRACE("(%p)\n", lppsh);
2316 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2318 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2320 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2322 for (n = i = 0; i < lppsh->nPages; i++, n++)
2324 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2325 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2328 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2329 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2332 if (!PROPSHEET_CollectPageInfoW((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2335 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2336 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2342 bRet = PROPSHEET_CreateDialog(psInfo);
2347 /******************************************************************************
2348 * CreatePropertySheetPage (COMCTL32.18)
2349 * CreatePropertySheetPageA (COMCTL32.19)
2351 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2352 LPCPROPSHEETPAGEA lpPropSheetPage)
2354 PROPSHEETPAGEA* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
2356 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2358 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2360 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,strlen(lpPropSheetPage->u.pszTemplate)+1 );
2361 strcpy( (char *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2363 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2365 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, strlen(lpPropSheetPage->u2.pszIcon)+1 );
2366 strcpy( (char *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2369 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2371 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, strlen(lpPropSheetPage->pszTitle)+1 );
2372 strcpy( (char *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2374 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2375 ppsp->pszTitle = NULL;
2377 return (HPROPSHEETPAGE)ppsp;
2380 /******************************************************************************
2381 * CreatePropertySheetPageW (COMCTL32.20)
2383 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2385 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2387 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2389 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2391 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2393 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2394 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2396 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2398 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2399 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2400 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2403 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2405 int len = strlenW(lpPropSheetPage->pszTitle);
2406 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2407 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2409 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2410 ppsp->pszTitle = NULL;
2412 return (HPROPSHEETPAGE)ppsp;
2415 /******************************************************************************
2416 * DestroyPropertySheetPage (COMCTL32.24)
2418 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2420 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2425 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2426 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2428 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2429 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2431 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2432 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2434 COMCTL32_Free(hPropPage);
2439 /******************************************************************************
2440 * PROPSHEET_IsDialogMessage
2442 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2444 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2447 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2450 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2453 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2455 if (!(dlgCode & DLGC_WANTMESSAGE))
2457 switch (lpMsg->wParam)
2460 if (GetKeyState(VK_SHIFT) & 0x8000)
2466 case VK_NEXT: new_page = 1; break;
2467 case VK_PRIOR: new_page = -1; break;
2473 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2475 new_page += psInfo->active_page;
2478 new_page = psInfo->nPages - 1;
2479 else if (new_page >= psInfo->nPages)
2482 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2489 return IsDialogMessageA(hwnd, lpMsg);
2492 /******************************************************************************
2493 * PROPSHEET_DoCommand
2495 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2501 case IDC_APPLY_BUTTON:
2503 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2505 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2510 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2514 if (psInfo->restartWindows)
2515 result = ID_PSRESTARTWINDOWS;
2517 /* reboot system takes precedence over restart windows */
2518 if (psInfo->rebootSystem)
2519 result = ID_PSREBOOTSYSTEM;
2521 if (psInfo->isModeless)
2522 psInfo->activeValid = FALSE;
2524 EndDialog(hwnd, result);
2527 EnableWindow(hwndApplyBtn, FALSE);
2532 case IDC_BACK_BUTTON:
2533 PROPSHEET_Back(hwnd);
2536 case IDC_NEXT_BUTTON:
2537 PROPSHEET_Next(hwnd);
2540 case IDC_FINISH_BUTTON:
2541 PROPSHEET_Finish(hwnd);
2545 PROPSHEET_Cancel(hwnd, 0);
2549 PROPSHEET_Help(hwnd);
2556 /******************************************************************************
2557 * PROPSHEET_DialogProc
2560 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2562 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
2563 hwnd, uMsg, wParam, lParam);
2569 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2570 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2571 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2572 LPCPROPSHEETPAGEW ppshpage;
2575 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2578 * psInfo->hwnd is not being used by WINE code - it exists
2579 * for compatibility with "real" Windoze. The same about
2580 * SetWindowLong - WINE is only using the PropSheetInfoStr
2583 psInfo->hwnd = hwnd;
2584 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2587 * Small icon in the title bar.
2589 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2590 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2593 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2594 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2596 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2597 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2598 psInfo->ppshheader.u.pszIcon,
2603 hIcon = psInfo->ppshheader.u.hIcon;
2605 SendMessageW(hwnd, WM_SETICON, 0, hIcon);
2608 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2609 SendMessageW(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2611 psInfo->strPropertiesFor = strCaption;
2613 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2615 PROPSHEET_CreateTabControl(hwnd, psInfo);
2617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2619 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2621 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2622 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2627 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2629 PROPSHEET_AdjustSize(hwnd, psInfo);
2630 PROPSHEET_AdjustButtons(hwnd, psInfo);
2634 if (psInfo->useCallback)
2635 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2636 PSCB_INITIALIZED, (LPARAM)0);
2638 idx = psInfo->active_page;
2639 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2640 psInfo->active_page = -1;
2642 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2644 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2645 * as some programs call TCM_GETCURSEL to get the current selection
2646 * from which to switch to the next page */
2647 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2649 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2650 psInfo->ppshheader.hInstance)
2654 if (LoadStringW(psInfo->ppshheader.hInstance,
2655 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2656 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2660 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2661 psInfo->ppshheader.pszCaption);
2668 PROPSHEET_CleanUp(hwnd);
2672 PROPSHEET_Cancel(hwnd, 1);
2676 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2680 NMHDR* pnmh = (LPNMHDR) lParam;
2682 if (pnmh->code == TCN_SELCHANGE)
2684 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2685 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2688 if(pnmh->code == TCN_SELCHANGING)
2690 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2691 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2698 case PSM_GETCURRENTPAGEHWND:
2700 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2704 if (psInfo->activeValid && psInfo->active_page != -1)
2705 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2707 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndPage);
2713 PROPSHEET_Changed(hwnd, (HWND)wParam);
2717 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2720 case PSM_GETTABCONTROL:
2722 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2724 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2733 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2734 if(msgResult != FALSE)
2736 msgResult = PROPSHEET_SetCurSel(hwnd,
2739 (HPROPSHEETPAGE)lParam);
2742 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2747 case PSM_CANCELTOCLOSE:
2749 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2750 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2751 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2753 EnableWindow(hwndCancel, FALSE);
2754 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2755 SetWindowTextW(hwndOK, buf);
2760 case PSM_RESTARTWINDOWS:
2762 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2765 psInfo->restartWindows = TRUE;
2769 case PSM_REBOOTSYSTEM:
2771 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2774 psInfo->rebootSystem = TRUE;
2779 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2783 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2788 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2790 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2795 case PSM_QUERYSIBLINGS:
2797 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2799 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2807 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2808 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2809 * on success or FALSE otherwise, as specified on MSDN Online.
2810 * Also see the MFC code for
2811 * CPropertySheet::AddPage(CPropertyPage* pPage).
2814 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2816 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2821 case PSM_REMOVEPAGE:
2822 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2825 case PSM_ISDIALOGMESSAGE:
2827 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2828 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2832 case PSM_PRESSBUTTON:
2833 PROPSHEET_PressButton(hwnd, (int)wParam);
2836 case PSM_SETFINISHTEXTA:
2837 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2840 case PSM_SETWIZBUTTONS:
2841 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2844 case PSM_SETCURSELID:
2845 FIXME("Unimplemented msg PSM_SETCURSELID\n");
2848 case PSM_SETFINISHTEXTW:
2849 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);