- Center property sheet page during creation (padding)
[wine/testsucceed.git] / dlls / comctl32 / propsheet.c
blobb368194722bc56218c47d72ad3eb4df7d2af67ce
1 /*
2 * Property Sheets
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
21 * TODO:
22 * - Tab order
23 * - Unicode property sheets
26 #include <string.h>
27 #include "winbase.h"
28 #include "commctrl.h"
29 #include "prsht.h"
30 #include "winnls.h"
31 #include "comctl32.h"
32 #include "wine/debug.h"
33 #include "heap.h"
36 /******************************************************************************
37 * Data structures
39 typedef struct
41 WORD dlgVer;
42 WORD signature;
43 DWORD helpID;
44 DWORD exStyle;
45 DWORD style;
46 } MyDLGTEMPLATEEX;
48 typedef struct tagPropPageInfo
50 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
51 HWND hwndPage;
52 BOOL isDirty;
53 LPCWSTR pszText;
54 BOOL hasHelp;
55 BOOL useCallback;
56 BOOL hasIcon;
57 } PropPageInfo;
59 typedef struct tagPropSheetInfo
61 HWND hwnd;
62 PROPSHEETHEADERW ppshheader;
63 LPWSTR strPropertiesFor;
64 int nPages;
65 int active_page;
66 BOOL isModeless;
67 BOOL hasHelp;
68 BOOL hasApply;
69 BOOL useCallback;
70 BOOL restartWindows;
71 BOOL rebootSystem;
72 BOOL activeValid;
73 PropPageInfo* proppage;
74 int x;
75 int y;
76 int width;
77 int height;
78 HIMAGELIST hImageList;
79 } PropSheetInfo;
81 typedef struct
83 int x;
84 int y;
85 } PADDING_INFO;
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 /******************************************************************************
103 * Prototypes
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,
115 int index);
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,
138 int index,
139 int skipdir,
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,
147 int index,
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);
156 BOOL WINAPI
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)
169 CHAR string[256];
171 string[0] = '\0';
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);
209 #undef add_flag
211 /******************************************************************************
212 * PROPSHEET_FindPageByResId
214 * Find page index corresponding to page resource id.
216 INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
218 INT i;
220 for (i = 0; i < psInfo->nPages; i++)
222 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
224 /* Fixme: if resource ID is a string shall we use strcmp ??? */
225 if (lppsp->u.pszTemplate == (LPVOID)resId)
226 break;
229 return i;
232 /******************************************************************************
233 * PROPSHEET_AtoW
235 * Convert ASCII to Unicode since all data is saved as Unicode.
237 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
239 INT len;
241 TRACE("<%s>\n", frstr);
242 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
243 *tostr = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
244 MultiByteToWideChar(CP_ACP, 0, frstr, -1, (LPWSTR)*tostr, len);
247 /******************************************************************************
248 * PROPSHEET_CollectSheetInfoA
250 * Collect relevant data.
252 static BOOL PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
253 PropSheetInfo * psInfo)
255 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
256 DWORD dwFlags = lppsh->dwFlags;
258 psInfo->hasHelp = dwFlags & PSH_HASHELP;
259 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
260 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
261 psInfo->isModeless = dwFlags & PSH_MODELESS;
263 memcpy(&psInfo->ppshheader,lppsh,dwSize);
264 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",
265 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
266 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
268 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
270 if (HIWORD(lppsh->pszCaption))
272 int len = strlen(lppsh->pszCaption);
273 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
274 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, (LPWSTR) psInfo->ppshheader.pszCaption, len+1);
275 /* strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption ); */
277 psInfo->nPages = lppsh->nPages;
279 if (dwFlags & PSH_USEPSTARTPAGE)
281 TRACE("PSH_USEPSTARTPAGE is on");
282 psInfo->active_page = 0;
284 else
285 psInfo->active_page = lppsh->u2.nStartPage;
287 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
288 psInfo->active_page = 0;
290 psInfo->restartWindows = FALSE;
291 psInfo->rebootSystem = FALSE;
292 psInfo->hImageList = 0;
293 psInfo->activeValid = FALSE;
295 return TRUE;
298 /******************************************************************************
299 * PROPSHEET_CollectSheetInfoW
301 * Collect relevant data.
303 static BOOL PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
304 PropSheetInfo * psInfo)
306 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
307 DWORD dwFlags = lppsh->dwFlags;
309 psInfo->hasHelp = dwFlags & PSH_HASHELP;
310 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
311 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
312 psInfo->isModeless = dwFlags & PSH_MODELESS;
314 memcpy(&psInfo->ppshheader,lppsh,dwSize);
315 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",
316 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
318 PROPSHEET_UnImplementedFlags(lppsh->dwFlags);
320 if (HIWORD(lppsh->pszCaption))
322 int len = strlenW(lppsh->pszCaption);
323 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
324 strcpyW( (WCHAR *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
326 psInfo->nPages = lppsh->nPages;
328 if (dwFlags & PSH_USEPSTARTPAGE)
330 TRACE("PSH_USEPSTARTPAGE is on");
331 psInfo->active_page = 0;
333 else
334 psInfo->active_page = lppsh->u2.nStartPage;
336 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
337 psInfo->active_page = 0;
339 psInfo->restartWindows = FALSE;
340 psInfo->rebootSystem = FALSE;
341 psInfo->hImageList = 0;
342 psInfo->activeValid = FALSE;
344 return TRUE;
347 /******************************************************************************
348 * PROPSHEET_CollectPageInfo
350 * Collect property sheet data.
351 * With code taken from DIALOG_ParseTemplate32.
353 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
354 PropSheetInfo * psInfo,
355 int index)
357 DLGTEMPLATE* pTemplate;
358 const WORD* p;
359 DWORD dwFlags;
360 int width, height;
362 TRACE("\n");
363 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
364 psInfo->proppage[index].hwndPage = 0;
365 psInfo->proppage[index].isDirty = FALSE;
368 * Process property page flags.
370 dwFlags = lppsp->dwFlags;
371 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
372 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
373 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
375 /* as soon as we have a page with the help flag, set the sheet flag on */
376 if (psInfo->proppage[index].hasHelp)
377 psInfo->hasHelp = TRUE;
380 * Process page template.
382 if (dwFlags & PSP_DLGINDIRECT)
383 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
384 else
386 HRSRC hResource = FindResourceW(lppsp->hInstance,
387 lppsp->u.pszTemplate,
388 RT_DIALOGW);
389 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
390 hResource);
391 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
395 * Extract the size of the page and the caption.
397 if (!pTemplate)
398 return FALSE;
400 p = (const WORD *)pTemplate;
402 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
404 /* DIALOGEX template */
406 p++; /* dlgVer */
407 p++; /* signature */
408 p += 2; /* help ID */
409 p += 2; /* ext style */
410 p += 2; /* style */
412 else
414 /* DIALOG template */
416 p += 2; /* style */
417 p += 2; /* ext style */
420 p++; /* nb items */
421 p++; /* x */
422 p++; /* y */
423 width = (WORD)*p; p++;
424 height = (WORD)*p; p++;
426 /* remember the largest width and height */
427 if (width > psInfo->width)
428 psInfo->width = width;
430 if (height > psInfo->height)
431 psInfo->height = height;
433 /* menu */
434 switch ((WORD)*p)
436 case 0x0000:
437 p++;
438 break;
439 case 0xffff:
440 p += 2;
441 break;
442 default:
443 p += lstrlenW( (LPCWSTR)p ) + 1;
444 break;
447 /* class */
448 switch ((WORD)*p)
450 case 0x0000:
451 p++;
452 break;
453 case 0xffff:
454 p += 2;
455 break;
456 default:
457 p += lstrlenW( (LPCWSTR)p ) + 1;
458 break;
461 /* Extract the caption */
462 psInfo->proppage[index].pszText = (LPCWSTR)p;
463 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
464 p += lstrlenW((LPCWSTR)p) + 1;
466 if (dwFlags & PSP_USETITLE)
468 WCHAR szTitle[256];
469 const WCHAR *pTitle;
470 static WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
471 int len;
473 if ( !HIWORD( lppsp->pszTitle ) )
475 if (!LoadStringW( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,sizeof szTitle ))
477 pTitle = pszNull;
478 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
480 else
481 pTitle = szTitle;
483 else
484 pTitle = lppsp->pszTitle;
486 len = strlenW(szTitle);
487 psInfo->proppage[index].pszText = COMCTL32_Alloc( (len+1)*sizeof (WCHAR) );
488 strcpyW( (LPWSTR)psInfo->proppage[index].pszText,pTitle);
492 * Build the image list for icons
494 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
496 HICON hIcon;
497 int icon_cx = GetSystemMetrics(SM_CXSMICON);
498 int icon_cy = GetSystemMetrics(SM_CYSMICON);
500 if (dwFlags & PSP_USEICONID)
501 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
502 icon_cx, icon_cy, LR_DEFAULTCOLOR);
503 else
504 hIcon = lppsp->u2.hIcon;
506 if ( hIcon )
508 if (psInfo->hImageList == 0 )
509 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
511 ImageList_AddIcon(psInfo->hImageList, hIcon);
516 return TRUE;
519 /******************************************************************************
520 * PROPSHEET_CreateDialog
522 * Creates the actual property sheet.
524 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
526 LRESULT ret;
527 LPCVOID template;
528 LPVOID temp = 0;
529 HRSRC hRes;
530 DWORD resSize;
531 WORD resID = IDD_PROPSHEET;
533 TRACE("\n");
534 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
535 resID = IDD_WIZARD;
537 if(!(hRes = FindResourceW(COMCTL32_hModule,
538 MAKEINTRESOURCEW(resID),
539 RT_DIALOGW)))
540 return FALSE;
542 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
543 return FALSE;
546 * Make a copy of the dialog template.
548 resSize = SizeofResource(COMCTL32_hModule, hRes);
550 temp = COMCTL32_Alloc(resSize);
552 if (!temp)
553 return FALSE;
555 memcpy(temp, template, resSize);
557 if (psInfo->useCallback)
558 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
560 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
561 ret = DialogBoxIndirectParamW(psInfo->ppshheader.hInstance,
562 (LPDLGTEMPLATEW) temp,
563 psInfo->ppshheader.hwndParent,
564 (DLGPROC) PROPSHEET_DialogProc,
565 (LPARAM)psInfo);
566 else
567 ret = CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
568 (LPDLGTEMPLATEW) temp,
569 psInfo->ppshheader.hwndParent,
570 (DLGPROC) PROPSHEET_DialogProc,
571 (LPARAM)psInfo);
573 COMCTL32_Free(temp);
575 return ret;
578 /******************************************************************************
579 * PROPSHEET_SizeMismatch
581 * Verify that the tab control and the "largest" property sheet page dlg. template
582 * match in size.
584 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
586 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
587 RECT rcOrigTab, rcPage;
590 * Original tab size.
592 GetClientRect(hwndTabCtrl, &rcOrigTab);
593 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
594 rcOrigTab.right, rcOrigTab.bottom);
597 * Biggest page size.
599 rcPage.left = psInfo->x;
600 rcPage.top = psInfo->y;
601 rcPage.right = psInfo->width;
602 rcPage.bottom = psInfo->height;
604 MapDialogRect(hwndDlg, &rcPage);
605 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
606 rcPage.right, rcPage.bottom);
608 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
609 return TRUE;
610 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
611 return TRUE;
613 return FALSE;
616 /******************************************************************************
617 * PROPSHEET_IsTooSmallWizard
619 * Verify that the default property sheet is big enough.
621 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
623 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
624 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
625 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
627 GetClientRect(hwndDlg, &rcSheetClient);
628 GetWindowRect(hwndDlg, &rcSheetRect);
629 GetWindowRect(hwndLine, &rcLine);
631 /* Remove the space below the sunken line */
632 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
634 /* Remove the buffer zone all around the edge */
635 rcSheetClient.bottom -= (padding.y * 2);
636 rcSheetClient.right -= (padding.x * 2);
639 * Biggest page size.
641 rcPage.left = psInfo->x;
642 rcPage.top = psInfo->y;
643 rcPage.right = psInfo->width;
644 rcPage.bottom = psInfo->height;
646 MapDialogRect(hwndDlg, &rcPage);
647 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
648 rcPage.right, rcPage.bottom);
650 if (rcPage.right > rcSheetClient.right)
651 return TRUE;
653 if (rcPage.bottom > rcSheetClient.bottom)
654 return TRUE;
656 return FALSE;
659 /******************************************************************************
660 * PROPSHEET_AdjustSize
662 * Resizes the property sheet and the tab control to fit the largest page.
664 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
666 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
667 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
668 RECT rc,tabRect;
669 int tabOffsetX, tabOffsetY, buttonHeight;
670 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
671 RECT units;
673 /* Get the height of buttons */
674 GetClientRect(hwndButton, &rc);
675 buttonHeight = rc.bottom;
678 * Biggest page size.
680 rc.left = psInfo->x;
681 rc.top = psInfo->y;
682 rc.right = psInfo->width;
683 rc.bottom = psInfo->height;
685 MapDialogRect(hwndDlg, &rc);
687 /* retrieve the dialog units */
688 units.left = units.right = 4;
689 units.top = units.bottom = 8;
690 MapDialogRect(hwndDlg, &units);
693 * Resize the tab control.
695 GetClientRect(hwndTabCtrl,&tabRect);
697 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
699 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
701 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
702 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
705 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
707 rc.right = rc.left + tabRect.right - tabRect.left;
708 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
711 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
713 tabOffsetX = -(rc.left);
714 tabOffsetY = -(rc.top);
716 rc.right -= rc.left;
717 rc.bottom -= rc.top;
718 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
719 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
721 GetClientRect(hwndTabCtrl, &rc);
723 TRACE("tab client rc %d %d %d %d\n",
724 rc.left, rc.top, rc.right, rc.bottom);
726 rc.right += ((padding.x * 2) + tabOffsetX);
727 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
730 * Resize the property sheet.
732 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
733 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
734 return TRUE;
737 /******************************************************************************
738 * PROPSHEET_AdjustSizeWizard
740 * Resizes the property sheet to fit the largest page.
742 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
744 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
745 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
746 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
747 RECT rc,tabRect;
748 int buttonHeight, lineHeight;
749 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
750 RECT units;
752 /* Get the height of buttons */
753 GetClientRect(hwndButton, &rc);
754 buttonHeight = rc.bottom;
756 GetClientRect(hwndLine, &rc);
757 lineHeight = rc.bottom;
759 /* retrieve the dialog units */
760 units.left = units.right = 4;
761 units.top = units.bottom = 8;
762 MapDialogRect(hwndDlg, &units);
765 * Biggest page size.
767 rc.left = psInfo->x;
768 rc.top = psInfo->y;
769 rc.right = psInfo->width;
770 rc.bottom = psInfo->height;
772 MapDialogRect(hwndDlg, &rc);
774 GetClientRect(hwndTabCtrl,&tabRect);
776 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
778 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
779 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
782 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
784 rc.right = rc.left + tabRect.right - tabRect.left;
785 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
788 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
790 /* Make room */
791 rc.right += (padding.x * 2);
792 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
795 * Resize the property sheet.
797 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
798 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
799 return TRUE;
802 /******************************************************************************
803 * PROPSHEET_AdjustButtons
805 * Adjusts the buttons' positions.
807 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
809 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
810 RECT rcSheet;
811 int x, y;
812 int num_buttons = 2;
813 int buttonWidth, buttonHeight;
814 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
816 if (psInfo->hasApply)
817 num_buttons++;
819 if (psInfo->hasHelp)
820 num_buttons++;
823 * Obtain the size of the buttons.
825 GetClientRect(hwndButton, &rcSheet);
826 buttonWidth = rcSheet.right;
827 buttonHeight = rcSheet.bottom;
830 * Get the size of the property sheet.
832 GetClientRect(hwndParent, &rcSheet);
835 * All buttons will be at this y coordinate.
837 y = rcSheet.bottom - (padding.y + buttonHeight);
840 * Position OK button.
842 hwndButton = GetDlgItem(hwndParent, IDOK);
844 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
846 SetWindowPos(hwndButton, 0, x, y, 0, 0,
847 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
850 * Position Cancel button.
852 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
854 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
856 SetWindowPos(hwndButton, 0, x, y, 0, 0,
857 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
860 * Position Apply button.
862 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
864 if (psInfo->hasApply)
866 if (psInfo->hasHelp)
867 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
868 else
869 x = rcSheet.right - (padding.x + buttonWidth);
871 SetWindowPos(hwndButton, 0, x, y, 0, 0,
872 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
874 EnableWindow(hwndButton, FALSE);
876 else
877 ShowWindow(hwndButton, SW_HIDE);
880 * Position Help button.
882 hwndButton = GetDlgItem(hwndParent, IDHELP);
884 if (psInfo->hasHelp)
886 x = rcSheet.right - (padding.x + buttonWidth);
888 SetWindowPos(hwndButton, 0, x, y, 0, 0,
889 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
891 else
892 ShowWindow(hwndButton, SW_HIDE);
894 return TRUE;
897 /******************************************************************************
898 * PROPSHEET_AdjustButtonsWizard
900 * Adjusts the buttons' positions.
902 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
903 PropSheetInfo* psInfo)
905 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
906 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
907 RECT rcSheet;
908 int x, y;
909 int num_buttons = 3;
910 int buttonWidth, buttonHeight, lineHeight, lineWidth;
911 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
913 if (psInfo->hasHelp)
914 num_buttons++;
917 * Obtain the size of the buttons.
919 GetClientRect(hwndButton, &rcSheet);
920 buttonWidth = rcSheet.right;
921 buttonHeight = rcSheet.bottom;
923 GetClientRect(hwndLine, &rcSheet);
924 lineHeight = rcSheet.bottom;
927 * Get the size of the property sheet.
929 GetClientRect(hwndParent, &rcSheet);
932 * All buttons will be at this y coordinate.
934 y = rcSheet.bottom - (padding.y + buttonHeight);
937 * Position the Next and the Finish buttons.
939 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
941 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
943 SetWindowPos(hwndButton, 0, x, y, 0, 0,
944 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
946 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
948 SetWindowPos(hwndButton, 0, x, y, 0, 0,
949 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
951 ShowWindow(hwndButton, SW_HIDE);
954 * Position the Back button.
956 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
958 x -= buttonWidth;
960 SetWindowPos(hwndButton, 0, x, y, 0, 0,
961 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
964 * Position the Cancel button.
966 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
968 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
970 SetWindowPos(hwndButton, 0, x, y, 0, 0,
971 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
974 * Position Help button.
976 hwndButton = GetDlgItem(hwndParent, IDHELP);
978 if (psInfo->hasHelp)
980 x = rcSheet.right - (padding.x + buttonWidth);
982 SetWindowPos(hwndButton, 0, x, y, 0, 0,
983 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
985 else
986 ShowWindow(hwndButton, SW_HIDE);
989 * Position and resize the sunken line.
991 x = padding.x;
992 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
994 GetClientRect(hwndParent, &rcSheet);
995 lineWidth = rcSheet.right - (padding.x * 2);
997 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
998 SWP_NOZORDER | SWP_NOACTIVATE);
1000 return TRUE;
1003 /******************************************************************************
1004 * PROPSHEET_GetPaddingInfo
1006 * Returns the layout information.
1008 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1010 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1011 RECT rcTab;
1012 POINT tl;
1013 PADDING_INFO padding;
1015 GetWindowRect(hwndTab, &rcTab);
1017 tl.x = rcTab.left;
1018 tl.y = rcTab.top;
1020 ScreenToClient(hwndDlg, &tl);
1022 padding.x = tl.x;
1023 padding.y = tl.y;
1025 return padding;
1028 /******************************************************************************
1029 * PROPSHEET_GetPaddingInfoWizard
1031 * Returns the layout information.
1032 * Vertical spacing is the distance between the line and the buttons.
1033 * Do NOT use the Help button to gather padding information when it isn't mapped
1034 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1035 * for it in this case !
1036 * FIXME: I'm not sure about any other coordinate problems with these evil
1037 * buttons. Fix it in case additional problems appear or maybe calculate
1038 * a padding in a completely different way, as this is somewhat messy.
1040 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1041 psInfo)
1043 PADDING_INFO padding;
1044 RECT rc;
1045 HWND hwndControl;
1046 INT idButton;
1047 POINT ptButton, ptLine;
1049 TRACE("\n");
1050 if (psInfo->hasHelp)
1052 idButton = IDHELP;
1054 else
1056 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1058 idButton = IDC_NEXT_BUTTON;
1060 else
1062 /* hopefully this is ok */
1063 idButton = IDCANCEL;
1067 hwndControl = GetDlgItem(hwndDlg, idButton);
1068 GetWindowRect(hwndControl, &rc);
1070 ptButton.x = rc.left;
1071 ptButton.y = rc.top;
1073 ScreenToClient(hwndDlg, &ptButton);
1075 /* Line */
1076 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1077 GetWindowRect(hwndControl, &rc);
1079 ptLine.x = 0;
1080 ptLine.y = rc.bottom;
1082 ScreenToClient(hwndDlg, &ptLine);
1084 padding.y = ptButton.y - ptLine.y;
1086 if (padding.y < 0)
1087 ERR("padding negative ! Please report this !\n");
1089 /* this is most probably not correct, but the best we have now */
1090 padding.x = padding.y;
1091 return padding;
1094 /******************************************************************************
1095 * PROPSHEET_CreateTabControl
1097 * Insert the tabs in the tab control.
1099 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1100 PropSheetInfo * psInfo)
1102 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1103 TCITEMW item;
1104 int i, nTabs;
1105 int iImage = 0;
1107 TRACE("\n");
1108 item.mask = TCIF_TEXT;
1109 item.cchTextMax = MAX_TABTEXT_LENGTH;
1111 nTabs = psInfo->nPages;
1114 * Set the image list for icons.
1116 if (psInfo->hImageList)
1118 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1121 for (i = 0; i < nTabs; i++)
1123 if ( psInfo->proppage[i].hasIcon )
1125 item.mask |= TCIF_IMAGE;
1126 item.iImage = iImage++;
1128 else
1130 item.mask &= ~TCIF_IMAGE;
1133 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1134 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1137 return TRUE;
1140 /******************************************************************************
1141 * PROPSHEET_CreatePage
1143 * Creates a page.
1145 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1146 int index,
1147 const PropSheetInfo * psInfo,
1148 LPCPROPSHEETPAGEW ppshpage)
1150 DLGTEMPLATE* pTemplate;
1151 HWND hwndPage;
1152 RECT rc;
1153 PropPageInfo* ppInfo = psInfo->proppage;
1154 PADDING_INFO padding;
1155 UINT pageWidth,pageHeight;
1156 DWORD resSize;
1157 LPVOID temp = NULL;
1159 TRACE("index %d\n", index);
1161 if (ppshpage == NULL)
1163 return FALSE;
1166 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1167 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1168 else
1170 HRSRC hResource;
1171 HANDLE hTemplate;
1173 hResource = FindResourceW(ppshpage->hInstance,
1174 ppshpage->u.pszTemplate,
1175 RT_DIALOGW);
1176 if(!hResource)
1177 return FALSE;
1179 resSize = SizeofResource(ppshpage->hInstance, hResource);
1181 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1182 if(!hTemplate)
1183 return FALSE;
1185 pTemplate = (LPDLGTEMPLATEW)LockResource(hTemplate);
1187 * Make a copy of the dialog template to make it writable
1189 temp = COMCTL32_Alloc(resSize);
1190 if (!temp)
1191 return FALSE;
1193 memcpy(temp, pTemplate, resSize);
1194 pTemplate = temp;
1197 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1199 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1200 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1201 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1202 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1203 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1204 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1205 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1206 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1208 else
1210 pTemplate->style |= WS_CHILD | DS_CONTROL;
1211 pTemplate->style &= ~DS_MODALFRAME;
1212 pTemplate->style &= ~WS_CAPTION;
1213 pTemplate->style &= ~WS_SYSMENU;
1214 pTemplate->style &= ~WS_POPUP;
1215 pTemplate->style &= ~WS_DISABLED;
1216 pTemplate->style &= ~WS_VISIBLE;
1217 pTemplate->style &= ~WS_THICKFRAME;
1220 if (psInfo->proppage[index].useCallback)
1221 (*(ppshpage->pfnCallback))(hwndParent,
1222 PSPCB_CREATE,
1223 (LPPROPSHEETPAGEW)ppshpage);
1225 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1226 pTemplate,
1227 hwndParent,
1228 ppshpage->pfnDlgProc,
1229 (LPARAM)ppshpage);
1230 /* Free a no more needed copy */
1231 if(temp)
1232 COMCTL32_Free(temp);
1234 ppInfo[index].hwndPage = hwndPage;
1236 rc.left = psInfo->x;
1237 rc.top = psInfo->y;
1238 rc.right = psInfo->width;
1239 rc.bottom = psInfo->height;
1241 MapDialogRect(hwndParent, &rc);
1243 pageWidth = rc.right - rc.left;
1244 pageHeight = rc.bottom - rc.top;
1246 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1247 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1248 else
1251 * Ask the Tab control to fit this page in.
1254 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1255 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1256 padding = PROPSHEET_GetPaddingInfo(hwndParent);
1259 SetWindowPos(hwndPage, HWND_TOP,
1260 rc.left + padding.x/2,
1261 rc.top + padding.y/2,
1262 pageWidth, pageHeight, 0);
1264 return TRUE;
1267 /******************************************************************************
1268 * PROPSHEET_ShowPage
1270 * Displays or creates the specified page.
1272 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1274 HWND hwndTabCtrl;
1276 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1277 if (index == psInfo->active_page)
1279 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1280 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1281 return TRUE;
1284 if (psInfo->proppage[index].hwndPage == 0)
1286 LPCPROPSHEETPAGEW ppshpage;
1288 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1289 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1292 if (psInfo->active_page != -1)
1293 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1295 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1297 /* Synchronize current selection with tab control
1298 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1299 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1300 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1302 psInfo->active_page = index;
1303 psInfo->activeValid = TRUE;
1305 return TRUE;
1308 /******************************************************************************
1309 * PROPSHEET_Back
1311 static BOOL PROPSHEET_Back(HWND hwndDlg)
1313 BOOL res;
1314 PSHNOTIFY psn;
1315 HWND hwndPage;
1316 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1317 PropSheetInfoStr);
1318 LRESULT result;
1319 int idx;
1321 TRACE("active_page %d\n", psInfo->active_page);
1322 if (psInfo->active_page < 0)
1323 return FALSE;
1325 psn.hdr.code = PSN_WIZBACK;
1326 psn.hdr.hwndFrom = hwndDlg;
1327 psn.hdr.idFrom = 0;
1328 psn.lParam = 0;
1330 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1332 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1333 if (result == -1)
1334 return FALSE;
1335 else if (result == 0)
1336 idx = psInfo->active_page - 1;
1337 else
1338 idx = PROPSHEET_FindPageByResId(psInfo, result);
1340 if (idx >= 0 && idx < psInfo->nPages)
1342 if (PROPSHEET_CanSetCurSel(hwndDlg))
1343 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1345 return TRUE;
1348 /******************************************************************************
1349 * PROPSHEET_Next
1351 static BOOL PROPSHEET_Next(HWND hwndDlg)
1353 PSHNOTIFY psn;
1354 HWND hwndPage;
1355 LRESULT msgResult = 0;
1356 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1357 PropSheetInfoStr);
1358 int idx;
1360 TRACE("active_page %d\n", psInfo->active_page);
1361 if (psInfo->active_page < 0)
1362 return FALSE;
1364 psn.hdr.code = PSN_WIZNEXT;
1365 psn.hdr.hwndFrom = hwndDlg;
1366 psn.hdr.idFrom = 0;
1367 psn.lParam = 0;
1369 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1371 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1372 if (msgResult == -1)
1373 return FALSE;
1374 else if (msgResult == 0)
1375 idx = psInfo->active_page + 1;
1376 else
1377 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1379 if (idx < psInfo->nPages )
1381 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1382 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1385 return TRUE;
1388 /******************************************************************************
1389 * PROPSHEET_Finish
1391 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1393 PSHNOTIFY psn;
1394 HWND hwndPage;
1395 LRESULT msgResult = 0;
1396 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1397 PropSheetInfoStr);
1399 TRACE("active_page %d\n", psInfo->active_page);
1400 if (psInfo->active_page < 0)
1401 return FALSE;
1403 psn.hdr.code = PSN_WIZFINISH;
1404 psn.hdr.hwndFrom = hwndDlg;
1405 psn.hdr.idFrom = 0;
1406 psn.lParam = 0;
1408 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1410 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1412 TRACE("msg result %ld\n", msgResult);
1414 if (msgResult != 0)
1415 return FALSE;
1417 if (psInfo->isModeless)
1418 psInfo->activeValid = FALSE;
1419 else
1420 EndDialog(hwndDlg, TRUE);
1422 return TRUE;
1425 /******************************************************************************
1426 * PROPSHEET_Apply
1428 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1430 int i;
1431 HWND hwndPage;
1432 PSHNOTIFY psn;
1433 LRESULT msgResult;
1434 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1435 PropSheetInfoStr);
1437 TRACE("active_page %d\n", psInfo->active_page);
1438 if (psInfo->active_page < 0)
1439 return FALSE;
1441 psn.hdr.hwndFrom = hwndDlg;
1442 psn.hdr.idFrom = 0;
1443 psn.lParam = 0;
1447 * Send PSN_KILLACTIVE to the current page.
1449 psn.hdr.code = PSN_KILLACTIVE;
1451 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1453 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1454 return FALSE;
1457 * Send PSN_APPLY to all pages.
1459 psn.hdr.code = PSN_APPLY;
1460 psn.lParam = lParam;
1462 for (i = 0; i < psInfo->nPages; i++)
1464 hwndPage = psInfo->proppage[i].hwndPage;
1465 if (hwndPage)
1467 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1468 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1469 return FALSE;
1473 if(lParam)
1475 psInfo->activeValid = FALSE;
1477 else if(psInfo->active_page >= 0)
1479 psn.hdr.code = PSN_SETACTIVE;
1480 psn.lParam = 0;
1481 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1482 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1485 return TRUE;
1488 /******************************************************************************
1489 * PROPSHEET_Cancel
1491 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1493 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1494 PropSheetInfoStr);
1495 HWND hwndPage;
1496 PSHNOTIFY psn;
1497 int i;
1499 TRACE("active_page %d\n", psInfo->active_page);
1500 if (psInfo->active_page < 0)
1501 return;
1503 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1504 psn.hdr.code = PSN_QUERYCANCEL;
1505 psn.hdr.hwndFrom = hwndDlg;
1506 psn.hdr.idFrom = 0;
1507 psn.lParam = 0;
1509 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1510 return;
1512 psn.hdr.code = PSN_RESET;
1513 psn.lParam = lParam;
1515 for (i = 0; i < psInfo->nPages; i++)
1517 hwndPage = psInfo->proppage[i].hwndPage;
1519 if (hwndPage)
1520 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1523 if (psInfo->isModeless)
1525 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1526 psInfo->activeValid = FALSE;
1528 else
1529 EndDialog(hwndDlg, FALSE);
1532 /******************************************************************************
1533 * PROPSHEET_Help
1535 static void PROPSHEET_Help(HWND hwndDlg)
1537 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1538 PropSheetInfoStr);
1539 HWND hwndPage;
1540 PSHNOTIFY psn;
1542 TRACE("active_page %d\n", psInfo->active_page);
1543 if (psInfo->active_page < 0)
1544 return;
1546 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1547 psn.hdr.code = PSN_HELP;
1548 psn.hdr.hwndFrom = hwndDlg;
1549 psn.hdr.idFrom = 0;
1550 psn.lParam = 0;
1552 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1555 /******************************************************************************
1556 * PROPSHEET_Changed
1558 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1560 int i;
1561 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1562 PropSheetInfoStr);
1564 TRACE("\n");
1565 if (!psInfo) return;
1567 * Set the dirty flag of this page.
1569 for (i = 0; i < psInfo->nPages; i++)
1571 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1572 psInfo->proppage[i].isDirty = TRUE;
1576 * Enable the Apply button.
1578 if (psInfo->hasApply)
1580 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1582 EnableWindow(hwndApplyBtn, TRUE);
1586 /******************************************************************************
1587 * PROPSHEET_UnChanged
1589 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1591 int i;
1592 BOOL noPageDirty = TRUE;
1593 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1594 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1595 PropSheetInfoStr);
1597 TRACE("\n");
1598 if ( !psInfo ) return;
1599 for (i = 0; i < psInfo->nPages; i++)
1601 /* set the specified page as clean */
1602 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1603 psInfo->proppage[i].isDirty = FALSE;
1605 /* look to see if there's any dirty pages */
1606 if (psInfo->proppage[i].isDirty)
1607 noPageDirty = FALSE;
1611 * Disable Apply button.
1613 if (noPageDirty)
1614 EnableWindow(hwndApplyBtn, FALSE);
1617 /******************************************************************************
1618 * PROPSHEET_PressButton
1620 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1622 TRACE("buttonID %d\n", buttonID);
1623 switch (buttonID)
1625 case PSBTN_APPLYNOW:
1626 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1627 break;
1628 case PSBTN_BACK:
1629 PROPSHEET_Back(hwndDlg);
1630 break;
1631 case PSBTN_CANCEL:
1632 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1633 break;
1634 case PSBTN_FINISH:
1635 PROPSHEET_Finish(hwndDlg);
1636 break;
1637 case PSBTN_HELP:
1638 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1639 break;
1640 case PSBTN_NEXT:
1641 PROPSHEET_Next(hwndDlg);
1642 break;
1643 case PSBTN_OK:
1644 PROPSHEET_DoCommand(hwndDlg, IDOK);
1645 break;
1646 default:
1647 FIXME("Invalid button index %d\n", buttonID);
1652 /*************************************************************************
1653 * BOOL PROPSHEET_CanSetCurSel [Internal]
1655 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1657 * PARAMS
1658 * hwndDlg [I] handle to a Dialog hWnd
1660 * RETURNS
1661 * TRUE if Current Selection can change
1663 * NOTES
1665 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1667 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1668 PropSheetInfoStr);
1669 HWND hwndPage;
1670 PSHNOTIFY psn;
1671 BOOL res = FALSE;
1673 TRACE("active_page %d\n", psInfo->active_page);
1674 if (!psInfo)
1676 res = FALSE;
1677 goto end;
1680 if (psInfo->active_page < 0)
1682 res = TRUE;
1683 goto end;
1687 * Notify the current page.
1689 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1690 psn.hdr.code = PSN_KILLACTIVE;
1691 psn.hdr.hwndFrom = hwndDlg;
1692 psn.hdr.idFrom = 0;
1693 psn.lParam = 0;
1695 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1697 end:
1698 TRACE("<-- %d\n", res);
1699 return res;
1702 /******************************************************************************
1703 * PROPSHEET_SetCurSel
1705 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1706 int index,
1707 int skipdir,
1708 HPROPSHEETPAGE hpage
1711 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1712 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1714 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1715 /* hpage takes precedence over index */
1716 if (hpage != NULL)
1717 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1719 if (index < 0 || index >= psInfo->nPages)
1721 TRACE("Could not find page to select!\n");
1722 return FALSE;
1725 while (1) {
1726 int result;
1727 PSHNOTIFY psn;
1729 psn.hdr.code = PSN_SETACTIVE;
1730 psn.hdr.hwndFrom = hwndDlg;
1731 psn.hdr.idFrom = 0;
1732 psn.lParam = 0;
1734 if (!psInfo->proppage[index].hwndPage) {
1735 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1736 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1739 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1740 if (!result)
1741 break;
1742 if (result == -1) {
1743 index+=skipdir;
1744 if (index < 0) {
1745 index = 0;
1746 FIXME("Tried to skip before first property sheet page!\n");
1747 break;
1749 if (index >= psInfo->nPages) {
1750 FIXME("Tried to skip after last property sheet page!\n");
1751 index = psInfo->nPages-1;
1752 break;
1755 else if (result != 0)
1757 index = PROPSHEET_FindPageByResId(psInfo, result);
1758 continue;
1762 * Display the new page.
1764 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1766 if (psInfo->proppage[index].hasHelp)
1767 EnableWindow(hwndHelp, TRUE);
1768 else
1769 EnableWindow(hwndHelp, FALSE);
1771 return TRUE;
1774 /******************************************************************************
1775 * PROPSHEET_SetTitleA
1777 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1779 if(HIWORD(lpszText))
1781 WCHAR szTitle[256];
1782 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
1783 szTitle, sizeof szTitle);
1784 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
1786 else
1788 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
1792 /******************************************************************************
1793 * PROPSHEET_SetTitleW
1795 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
1797 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg, PropSheetInfoStr);
1798 WCHAR szTitle[256];
1800 TRACE("'%s' (style %08lx)\n", debugstr_w(lpszText), dwStyle);
1801 if (HIWORD(lpszText) == 0) {
1802 if (!LoadStringW(psInfo->ppshheader.hInstance,
1803 LOWORD(lpszText), szTitle, sizeof(szTitle)-sizeof(WCHAR)))
1804 return;
1805 lpszText = szTitle;
1807 if (dwStyle & PSH_PROPTITLE)
1809 WCHAR* dest;
1810 int lentitle = strlenW(lpszText);
1811 int lenprop = strlenW(psInfo->strPropertiesFor);
1813 dest = COMCTL32_Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
1814 strcpyW(dest, psInfo->strPropertiesFor);
1815 strcatW(dest, lpszText);
1817 SetWindowTextW(hwndDlg, dest);
1818 COMCTL32_Free(dest);
1820 else
1821 SetWindowTextW(hwndDlg, lpszText);
1824 /******************************************************************************
1825 * PROPSHEET_SetFinishTextA
1827 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1829 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1831 TRACE("'%s'\n", lpszText);
1832 /* Set text, show and enable the Finish button */
1833 SetWindowTextA(hwndButton, lpszText);
1834 ShowWindow(hwndButton, SW_SHOW);
1835 EnableWindow(hwndButton, TRUE);
1837 /* Make it default pushbutton */
1838 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1840 /* Hide Back button */
1841 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1842 ShowWindow(hwndButton, SW_HIDE);
1844 /* Hide Next button */
1845 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1846 ShowWindow(hwndButton, SW_HIDE);
1849 /******************************************************************************
1850 * PROPSHEET_SetFinishTextW
1852 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
1854 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1856 TRACE("'%s'\n", debugstr_w(lpszText));
1857 /* Set text, show and enable the Finish button */
1858 SetWindowTextW(hwndButton, lpszText);
1859 ShowWindow(hwndButton, SW_SHOW);
1860 EnableWindow(hwndButton, TRUE);
1862 /* Make it default pushbutton */
1863 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1865 /* Hide Back button */
1866 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1867 ShowWindow(hwndButton, SW_HIDE);
1869 /* Hide Next button */
1870 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1871 ShowWindow(hwndButton, SW_HIDE);
1874 /******************************************************************************
1875 * PROPSHEET_QuerySiblings
1877 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1878 WPARAM wParam, LPARAM lParam)
1880 int i = 0;
1881 HWND hwndPage;
1882 LRESULT msgResult = 0;
1883 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1884 PropSheetInfoStr);
1886 while ((i < psInfo->nPages) && (msgResult == 0))
1888 hwndPage = psInfo->proppage[i].hwndPage;
1889 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1890 i++;
1893 return msgResult;
1897 /******************************************************************************
1898 * PROPSHEET_AddPage
1900 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1901 HPROPSHEETPAGE hpage)
1903 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1904 PropSheetInfoStr);
1905 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1906 TCITEMW item;
1907 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
1909 TRACE("hpage %p\n", hpage);
1911 * Allocate and fill in a new PropPageInfo entry.
1913 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1914 sizeof(PropPageInfo) *
1915 (psInfo->nPages + 1));
1916 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
1917 return FALSE;
1919 psInfo->proppage[psInfo->nPages].hpage = hpage;
1921 if (ppsp->dwFlags & PSP_PREMATURE)
1923 /* Create the page but don't show it */
1924 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
1928 * Add a new tab to the tab control.
1930 item.mask = TCIF_TEXT;
1931 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
1932 item.cchTextMax = MAX_TABTEXT_LENGTH;
1934 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
1935 (LPARAM)&item);
1937 psInfo->nPages++;
1939 /* If it is the only page - show it */
1940 if(psInfo->nPages == 1)
1941 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
1942 return TRUE;
1945 /******************************************************************************
1946 * PROPSHEET_RemovePage
1948 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
1949 int index,
1950 HPROPSHEETPAGE hpage)
1952 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropW(hwndDlg,
1953 PropSheetInfoStr);
1954 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1955 PropPageInfo* oldPages;
1957 TRACE("index %d, hpage %p\n", index, hpage);
1958 if (!psInfo) {
1959 return FALSE;
1961 oldPages = psInfo->proppage;
1963 * hpage takes precedence over index.
1965 if (hpage != 0)
1967 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1970 /* Make sure that index is within range */
1971 if (index < 0 || index >= psInfo->nPages)
1973 TRACE("Could not find page to remove!\n");
1974 return FALSE;
1977 TRACE("total pages %d removing page %d active page %d\n",
1978 psInfo->nPages, index, psInfo->active_page);
1980 * Check if we're removing the active page.
1982 if (index == psInfo->active_page)
1984 if (psInfo->nPages > 1)
1986 if (index > 0)
1988 /* activate previous page */
1989 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
1991 else
1993 /* activate the next page */
1994 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
1995 psInfo->active_page = index;
1998 else
2000 psInfo->active_page = -1;
2001 if (!psInfo->isModeless)
2003 EndDialog(hwndDlg, FALSE);
2004 return TRUE;
2008 else if (index < psInfo->active_page)
2009 psInfo->active_page--;
2011 /* Destroy page dialog window */
2012 DestroyWindow(psInfo->proppage[index].hwndPage);
2014 /* Free page resources */
2015 if(psInfo->proppage[index].hpage)
2017 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2019 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
2020 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
2022 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2025 /* Remove the tab */
2026 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2028 psInfo->nPages--;
2029 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2031 if (index > 0)
2032 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2034 if (index < psInfo->nPages)
2035 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2036 (psInfo->nPages - index) * sizeof(PropPageInfo));
2038 COMCTL32_Free(oldPages);
2040 return FALSE;
2043 /******************************************************************************
2044 * PROPSHEET_SetWizButtons
2046 * This code will work if (and assumes that) the Next button is on top of the
2047 * Finish button. ie. Finish comes after Next in the Z order.
2048 * This means make sure the dialog template reflects this.
2051 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2053 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2054 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2055 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2057 TRACE("%ld\n", dwFlags);
2059 EnableWindow(hwndBack, FALSE);
2060 EnableWindow(hwndNext, FALSE);
2061 EnableWindow(hwndFinish, FALSE);
2063 if (dwFlags & PSWIZB_BACK)
2064 EnableWindow(hwndBack, TRUE);
2066 if (dwFlags & PSWIZB_NEXT)
2068 /* Hide the Finish button */
2069 ShowWindow(hwndFinish, SW_HIDE);
2071 /* Show and enable the Next button */
2072 ShowWindow(hwndNext, SW_SHOW);
2073 EnableWindow(hwndNext, TRUE);
2075 /* Set the Next button as the default pushbutton */
2076 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2079 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2081 /* Hide the Next button */
2082 ShowWindow(hwndNext, SW_HIDE);
2084 /* Show the Finish button */
2085 ShowWindow(hwndFinish, SW_SHOW);
2087 if (dwFlags & PSWIZB_FINISH)
2088 EnableWindow(hwndFinish, TRUE);
2090 /* Set the Finish button as the default pushbutton */
2091 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2095 /******************************************************************************
2096 * PROPSHEET_GetPageIndex
2098 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2099 * the array of PropPageInfo.
2101 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2103 BOOL found = FALSE;
2104 int index = 0;
2106 TRACE("hpage %p\n", hpage);
2107 while ((index < psInfo->nPages) && (found == FALSE))
2109 if (psInfo->proppage[index].hpage == hpage)
2110 found = TRUE;
2111 else
2112 index++;
2115 if (found == FALSE)
2116 index = -1;
2118 return index;
2121 /******************************************************************************
2122 * PROPSHEET_CleanUp
2124 static void PROPSHEET_CleanUp(HWND hwndDlg)
2126 int i;
2127 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropW(hwndDlg,
2128 PropSheetInfoStr);
2130 TRACE("\n");
2131 if (!psInfo) return;
2132 if (HIWORD(psInfo->ppshheader.pszCaption))
2133 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
2135 for (i = 0; i < psInfo->nPages; i++)
2137 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2139 if(psInfo->proppage[i].hwndPage)
2140 DestroyWindow(psInfo->proppage[i].hwndPage);
2142 if(psp)
2144 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2145 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2147 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2151 COMCTL32_Free(psInfo->proppage);
2152 COMCTL32_Free(psInfo->strPropertiesFor);
2153 ImageList_Destroy(psInfo->hImageList);
2155 GlobalFree((HGLOBAL)psInfo);
2158 /******************************************************************************
2159 * PropertySheet (COMCTL32.87)
2160 * PropertySheetA (COMCTL32.88)
2162 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2164 int bRet = 0;
2165 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2166 sizeof(PropSheetInfo));
2167 int i, n;
2168 BYTE* pByte;
2170 TRACE("(%p)\n", lppsh);
2172 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2174 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2175 lppsh->nPages);
2176 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2178 for (n = i = 0; i < lppsh->nPages; i++, n++)
2180 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2181 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2182 else
2184 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2185 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2188 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2189 psInfo, n))
2191 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2192 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2193 n--;
2194 psInfo->nPages--;
2198 bRet = PROPSHEET_CreateDialog(psInfo);
2200 return bRet;
2203 /******************************************************************************
2204 * PropertySheetW (COMCTL32.89)
2206 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2208 int bRet = 0;
2209 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2210 sizeof(PropSheetInfo));
2211 int i, n;
2212 BYTE* pByte;
2214 TRACE("(%p)\n", lppsh);
2216 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2218 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2219 lppsh->nPages);
2220 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
2222 for (n = i = 0; i < lppsh->nPages; i++, n++)
2224 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2225 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2226 else
2228 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2229 pByte += ((LPPROPSHEETPAGEW)pByte)->dwSize;
2232 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2233 psInfo, n))
2235 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
2236 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2237 n--;
2238 psInfo->nPages--;
2242 bRet = PROPSHEET_CreateDialog(psInfo);
2244 return bRet;
2247 /******************************************************************************
2248 * CreatePropertySheetPage (COMCTL32.18)
2249 * CreatePropertySheetPageA (COMCTL32.19)
2251 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2252 LPCPROPSHEETPAGEA lpPropSheetPage)
2254 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2256 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2258 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2260 PROPSHEET_AtoW(&ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate);
2262 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2264 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2267 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2269 PROPSHEET_AtoW(&ppsp->pszTitle, lpPropSheetPage->pszTitle);
2271 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2272 ppsp->pszTitle = NULL;
2274 return (HPROPSHEETPAGE)ppsp;
2277 /******************************************************************************
2278 * CreatePropertySheetPageW (COMCTL32.20)
2280 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2282 PROPSHEETPAGEW* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEW));
2284 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
2286 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2288 int len = strlenW(lpPropSheetPage->u.pszTemplate);
2290 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,(len+1)*sizeof (WCHAR) );
2291 strcpyW( (WCHAR *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2293 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2295 int len = strlenW(lpPropSheetPage->u2.pszIcon);
2296 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2297 strcpyW( (WCHAR *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2300 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2302 int len = strlenW(lpPropSheetPage->pszTitle);
2303 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof (WCHAR) );
2304 strcpyW( (WCHAR *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2306 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2307 ppsp->pszTitle = NULL;
2309 return (HPROPSHEETPAGE)ppsp;
2312 /******************************************************************************
2313 * DestroyPropertySheetPage (COMCTL32.24)
2315 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2317 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
2319 if (!psp)
2320 return FALSE;
2322 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2323 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2325 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2326 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2328 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2329 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2331 COMCTL32_Free(hPropPage);
2333 return TRUE;
2336 /******************************************************************************
2337 * PROPSHEET_IsDialogMessage
2339 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2341 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd, PropSheetInfoStr);
2343 TRACE("\n");
2344 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2345 return FALSE;
2347 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2349 int new_page = 0;
2350 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2352 if (!(dlgCode & DLGC_WANTMESSAGE))
2354 switch (lpMsg->wParam)
2356 case VK_TAB:
2357 if (GetKeyState(VK_SHIFT) & 0x8000)
2358 new_page = -1;
2359 else
2360 new_page = 1;
2361 break;
2363 case VK_NEXT: new_page = 1; break;
2364 case VK_PRIOR: new_page = -1; break;
2368 if (new_page)
2370 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2372 new_page += psInfo->active_page;
2374 if (new_page < 0)
2375 new_page = psInfo->nPages - 1;
2376 else if (new_page >= psInfo->nPages)
2377 new_page = 0;
2379 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2382 return TRUE;
2386 return IsDialogMessageA(hwnd, lpMsg);
2389 /******************************************************************************
2390 * PROPSHEET_DoCommand
2392 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
2395 switch (wID) {
2397 case IDOK:
2398 case IDC_APPLY_BUTTON:
2400 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2402 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2403 break;
2405 if (wID == IDOK)
2407 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2408 PropSheetInfoStr);
2409 int result = TRUE;
2411 if (psInfo->restartWindows)
2412 result = ID_PSRESTARTWINDOWS;
2414 /* reboot system takes precedence over restart windows */
2415 if (psInfo->rebootSystem)
2416 result = ID_PSREBOOTSYSTEM;
2418 if (psInfo->isModeless)
2419 psInfo->activeValid = FALSE;
2420 else
2421 EndDialog(hwnd, result);
2423 else
2424 EnableWindow(hwndApplyBtn, FALSE);
2426 break;
2429 case IDC_BACK_BUTTON:
2430 PROPSHEET_Back(hwnd);
2431 break;
2433 case IDC_NEXT_BUTTON:
2434 PROPSHEET_Next(hwnd);
2435 break;
2437 case IDC_FINISH_BUTTON:
2438 PROPSHEET_Finish(hwnd);
2439 break;
2441 case IDCANCEL:
2442 PROPSHEET_Cancel(hwnd, 0);
2443 break;
2445 case IDHELP:
2446 PROPSHEET_Help(hwnd);
2447 break;
2450 return TRUE;
2453 /******************************************************************************
2454 * PROPSHEET_DialogProc
2456 BOOL WINAPI
2457 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2459 TRACE("hwnd=%x msg=%x wparam=%x lparam=%lx\n",
2460 hwnd, uMsg, wParam, lParam);
2462 switch (uMsg)
2464 case WM_INITDIALOG:
2466 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2467 WCHAR* strCaption = (WCHAR*)COMCTL32_Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
2468 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2469 LPCPROPSHEETPAGEW ppshpage;
2470 int idx;
2472 SetPropW(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2475 * psInfo->hwnd is not being used by WINE code - it exists
2476 * for compatibility with "real" Windoze. The same about
2477 * SetWindowLong - WINE is only using the PropSheetInfoStr
2478 * property.
2480 psInfo->hwnd = hwnd;
2481 SetWindowLongW(hwnd,DWL_USER,(LONG)psInfo);
2484 * Small icon in the title bar.
2486 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2487 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2489 HICON hIcon;
2490 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2491 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2493 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2494 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
2495 psInfo->ppshheader.u.pszIcon,
2496 IMAGE_ICON,
2497 icon_cx, icon_cy,
2498 LR_DEFAULTCOLOR);
2499 else
2500 hIcon = psInfo->ppshheader.u.hIcon;
2502 SendMessageW(hwnd, WM_SETICON, 0, hIcon);
2505 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2506 SendMessageW(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2508 psInfo->strPropertiesFor = strCaption;
2510 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2512 PROPSHEET_CreateTabControl(hwnd, psInfo);
2514 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
2516 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2518 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2519 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2522 else
2524 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2526 PROPSHEET_AdjustSize(hwnd, psInfo);
2527 PROPSHEET_AdjustButtons(hwnd, psInfo);
2531 if (psInfo->useCallback)
2532 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2533 PSCB_INITIALIZED, (LPARAM)0);
2535 idx = psInfo->active_page;
2536 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[idx].hpage;
2537 psInfo->active_page = -1;
2539 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2541 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2542 * as some programs call TCM_GETCURSEL to get the current selection
2543 * from which to switch to the next page */
2544 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2546 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2547 psInfo->ppshheader.hInstance)
2549 WCHAR szText[256];
2551 if (LoadStringW(psInfo->ppshheader.hInstance,
2552 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2553 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
2555 else
2557 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
2558 psInfo->ppshheader.pszCaption);
2561 return TRUE;
2564 case WM_DESTROY:
2565 PROPSHEET_CleanUp(hwnd);
2566 return TRUE;
2568 case WM_CLOSE:
2569 PROPSHEET_Cancel(hwnd, 1);
2570 return TRUE;
2572 case WM_COMMAND:
2573 return PROPSHEET_DoCommand(hwnd, LOWORD(wParam));
2575 case WM_NOTIFY:
2577 NMHDR* pnmh = (LPNMHDR) lParam;
2579 if (pnmh->code == TCN_SELCHANGE)
2581 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2582 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2585 if(pnmh->code == TCN_SELCHANGING)
2587 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2588 SetWindowLongW(hwnd, DWL_MSGRESULT, !bRet);
2589 return TRUE;
2592 return FALSE;
2595 case PSM_GETCURRENTPAGEHWND:
2597 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2598 PropSheetInfoStr);
2599 HWND hwndPage = 0;
2601 if (psInfo->activeValid && psInfo->active_page != -1)
2602 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2604 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndPage);
2606 return TRUE;
2609 case PSM_CHANGED:
2610 PROPSHEET_Changed(hwnd, (HWND)wParam);
2611 return TRUE;
2613 case PSM_UNCHANGED:
2614 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2615 return TRUE;
2617 case PSM_GETTABCONTROL:
2619 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2621 SetWindowLongW(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2623 return TRUE;
2626 case PSM_SETCURSEL:
2628 BOOL msgResult;
2630 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2631 if(msgResult != FALSE)
2633 msgResult = PROPSHEET_SetCurSel(hwnd,
2634 (int)wParam,
2636 (HPROPSHEETPAGE)lParam);
2639 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2641 return TRUE;
2644 case PSM_CANCELTOCLOSE:
2646 WCHAR buf[MAX_BUTTONTEXT_LENGTH];
2647 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2648 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2650 EnableWindow(hwndCancel, FALSE);
2651 if (LoadStringW(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2652 SetWindowTextW(hwndOK, buf);
2654 return FALSE;
2657 case PSM_RESTARTWINDOWS:
2659 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2660 PropSheetInfoStr);
2662 psInfo->restartWindows = TRUE;
2663 return TRUE;
2666 case PSM_REBOOTSYSTEM:
2668 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropW(hwnd,
2669 PropSheetInfoStr);
2671 psInfo->rebootSystem = TRUE;
2672 return TRUE;
2675 case PSM_SETTITLEA:
2676 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2677 return TRUE;
2679 case PSM_SETTITLEW:
2680 PROPSHEET_SetTitleW(hwnd, (DWORD) wParam, (LPCWSTR) lParam);
2681 return TRUE;
2683 case PSM_APPLY:
2685 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2687 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2689 return TRUE;
2692 case PSM_QUERYSIBLINGS:
2694 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2696 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2698 return TRUE;
2701 case PSM_ADDPAGE:
2704 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2705 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2706 * on success or FALSE otherwise, as specified on MSDN Online.
2707 * Also see the MFC code for
2708 * CPropertySheet::AddPage(CPropertyPage* pPage).
2711 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2713 SetWindowLongW(hwnd, DWL_MSGRESULT, msgResult);
2715 return TRUE;
2718 case PSM_REMOVEPAGE:
2719 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2720 return TRUE;
2722 case PSM_ISDIALOGMESSAGE:
2724 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2725 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2726 return TRUE;
2729 case PSM_PRESSBUTTON:
2730 PROPSHEET_PressButton(hwnd, (int)wParam);
2731 return TRUE;
2733 case PSM_SETFINISHTEXTA:
2734 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2735 return TRUE;
2737 case PSM_SETWIZBUTTONS:
2738 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2739 return TRUE;
2741 case PSM_SETCURSELID:
2742 FIXME("Unimplemented msg PSM_SETCURSELID\n");
2743 return FALSE;
2745 case PSM_SETFINISHTEXTW:
2746 PROPSHEET_SetFinishTextW(hwnd, (LPCWSTR) lParam);
2747 return FALSE;
2749 default:
2750 return FALSE;
2753 return FALSE;