6264923e8ecef03f6b24efadceaf87503f954012
[reactos.git] / reactos / dll / win32 / comctl32 / propsheet.c
1 /*
2 * Property Sheets
3 *
4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
6 * Copyright 2004 Maxime Bellenge
7 * Copyright 2004 Filip Navara
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 *
23 * This code was audited for completeness against the documented features
24 * of Comctl32.dll version 6.0 on Sep. 12, 2004, by Filip Navara.
25 *
26 * Unless otherwise noted, we believe this code to be complete, as per
27 * the specification mentioned above.
28 * If you discover missing features, or bugs, please note them below.
29 *
30 * TODO:
31 * - Tab order
32 * - Wizard 97 header resizing
33 * - Enforcing of minimal wizard size
34 * - Messages:
35 * o PSM_INSERTPAGE
36 * o PSM_RECALCPAGESIZES
37 * o PSM_SETHEADERSUBTITLE
38 * o PSM_SETHEADERTITLE
39 * o WM_HELP
40 * o WM_CONTEXTMENU
41 * - Notifications:
42 * o PSN_GETOBJECT
43 * o PSN_QUERYINITIALFOCUS
44 * o PSN_TRANSLATEACCELERATOR
45 * - Styles:
46 * o PSH_RTLREADING
47 * o PSH_STRETCHWATERMARK
48 * o PSH_USEPAGELANG
49 * o PSH_USEPSTARTPAGE
50 * - Page styles:
51 * o PSP_USEFUSIONCONTEXT
52 * o PSP_USEREFPARENT
53 */
54
55 #include <stdarg.h>
56 #include <string.h>
57
58 #define NONAMELESSUNION
59 #define NONAMELESSSTRUCT
60 #include "windef.h"
61 #include "winbase.h"
62 #include "wingdi.h"
63 #include "winuser.h"
64 #include "winnls.h"
65 #include "commctrl.h"
66 #include "prsht.h"
67 #include "comctl32.h"
68 #include "uxtheme.h"
69
70 #include "wine/debug.h"
71 #include "wine/unicode.h"
72
73 /******************************************************************************
74 * Data structures
75 */
76 #include "pshpack2.h"
77
78 typedef struct
79 {
80 WORD dlgVer;
81 WORD signature;
82 DWORD helpID;
83 DWORD exStyle;
84 DWORD style;
85 } MyDLGTEMPLATEEX;
86
87 typedef struct
88 {
89 DWORD helpid;
90 DWORD exStyle;
91 DWORD style;
92 short x;
93 short y;
94 short cx;
95 short cy;
96 DWORD id;
97 } MyDLGITEMTEMPLATEEX;
98 #include "poppack.h"
99
100 typedef struct tagPropPageInfo
101 {
102 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
103 HWND hwndPage;
104 BOOL isDirty;
105 LPCWSTR pszText;
106 BOOL hasHelp;
107 BOOL useCallback;
108 BOOL hasIcon;
109 } PropPageInfo;
110
111 typedef struct tagPropSheetInfo
112 {
113 HWND hwnd;
114 PROPSHEETHEADERW ppshheader;
115 BOOL unicode;
116 LPWSTR strPropertiesFor;
117 int nPages;
118 int active_page;
119 BOOL isModeless;
120 BOOL hasHelp;
121 BOOL hasApply;
122 BOOL hasFinish;
123 BOOL usePropPage;
124 BOOL useCallback;
125 BOOL activeValid;
126 PropPageInfo* proppage;
127 HFONT hFont;
128 HFONT hFontBold;
129 int width;
130 int height;
131 HIMAGELIST hImageList;
132 BOOL ended;
133 INT result;
134 } PropSheetInfo;
135
136 typedef struct
137 {
138 int x;
139 int y;
140 } PADDING_INFO;
141
142 /******************************************************************************
143 * Defines and global variables
144 */
145
146 static const WCHAR PropSheetInfoStr[] =
147 {'P','r','o','p','e','r','t','y','S','h','e','e','t','I','n','f','o',0 };
148
149 #define PSP_INTERNAL_UNICODE 0x80000000
150
151 #define MAX_CAPTION_LENGTH 255
152 #define MAX_TABTEXT_LENGTH 255
153 #define MAX_BUTTONTEXT_LENGTH 64
154
155 #define INTRNL_ANY_WIZARD (PSH_WIZARD | PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE)
156
157 /* Wizard metrics specified in DLUs */
158 #define WIZARD_PADDING 7
159 #define WIZARD_HEADER_HEIGHT 36
160
161 /******************************************************************************
162 * Prototypes
163 */
164 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
165 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText);
166 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
167 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
168 int index,
169 int skipdir,
170 HPROPSHEETPAGE hpage);
171 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo);
172 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
173 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID);
174
175 static INT_PTR CALLBACK
176 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
177
178 WINE_DEFAULT_DEBUG_CHANNEL(propsheet);
179
180 #define add_flag(a) if (dwFlags & a) {strcat(string, #a );strcat(string," ");}
181 /******************************************************************************
182 * PROPSHEET_UnImplementedFlags
183 *
184 * Document use of flags we don't implement yet.
185 */
186 static VOID PROPSHEET_UnImplementedFlags(DWORD dwFlags)
187 {
188 CHAR string[256];
189
190 string[0] = '\0';
191
192 /*
193 * unhandled header flags:
194 * PSH_RTLREADING 0x00000800
195 * PSH_STRETCHWATERMARK 0x00040000
196 * PSH_USEPAGELANG 0x00200000
197 */
198
199 add_flag(PSH_RTLREADING);
200 add_flag(PSH_STRETCHWATERMARK);
201 add_flag(PSH_USEPAGELANG);
202 if (string[0] != '\0')
203 FIXME("%s\n", string);
204 }
205 #undef add_flag
206
207 /******************************************************************************
208 * PROPSHEET_GetPageRect
209 *
210 * Retrieve rect from tab control and map into the dialog for SetWindowPos
211 */
212 static void PROPSHEET_GetPageRect(const PropSheetInfo * psInfo, HWND hwndDlg,
213 RECT *rc, LPCPROPSHEETPAGEW ppshpage)
214 {
215 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) {
216 HWND hwndChild;
217 RECT r;
218
219 if (((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
220 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
221 !(ppshpage->dwFlags & PSP_HIDEHEADER)) ||
222 (psInfo->ppshheader.dwFlags & PSH_WIZARD))
223 {
224 rc->left = rc->top = WIZARD_PADDING;
225 }
226 else
227 {
228 rc->left = rc->top = 0;
229 }
230 rc->right = psInfo->width - rc->left;
231 rc->bottom = psInfo->height - rc->top;
232 MapDialogRect(hwndDlg, rc);
233
234 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
235 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
236 !(ppshpage->dwFlags & PSP_HIDEHEADER))
237 {
238 hwndChild = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
239 GetClientRect(hwndChild, &r);
240 MapWindowPoints(hwndChild, hwndDlg, (LPPOINT) &r, 2);
241 rc->top += r.bottom + 1;
242 }
243 } else {
244 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
245 GetClientRect(hwndTabCtrl, rc);
246 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)rc);
247 MapWindowPoints(hwndTabCtrl, hwndDlg, (LPPOINT)rc, 2);
248 }
249 }
250
251 /******************************************************************************
252 * PROPSHEET_FindPageByResId
253 *
254 * Find page index corresponding to page resource id.
255 */
256 static INT PROPSHEET_FindPageByResId(const PropSheetInfo * psInfo, LRESULT resId)
257 {
258 INT i;
259
260 for (i = 0; i < psInfo->nPages; i++)
261 {
262 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
263
264 /* Fixme: if resource ID is a string shall we use strcmp ??? */
265 if (lppsp->u.pszTemplate == (LPVOID)resId)
266 break;
267 }
268
269 return i;
270 }
271
272 /******************************************************************************
273 * PROPSHEET_AtoW
274 *
275 * Convert ASCII to Unicode since all data is saved as Unicode.
276 */
277 static void PROPSHEET_AtoW(LPCWSTR *tostr, LPCSTR frstr)
278 {
279 INT len;
280 WCHAR *to;
281
282 TRACE("<%s>\n", frstr);
283 len = MultiByteToWideChar(CP_ACP, 0, frstr, -1, 0, 0);
284 to = Alloc(len * sizeof(WCHAR));
285 MultiByteToWideChar(CP_ACP, 0, frstr, -1, to, len);
286 *tostr = to;
287 }
288
289 /******************************************************************************
290 * PROPSHEET_CollectSheetInfoCommon
291 *
292 * Common code for PROPSHEET_CollectSheetInfoA/W
293 */
294 static void PROPSHEET_CollectSheetInfoCommon(PropSheetInfo * psInfo, DWORD dwFlags)
295 {
296 PROPSHEET_UnImplementedFlags(dwFlags);
297
298 psInfo->hasHelp = dwFlags & PSH_HASHELP;
299 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
300 psInfo->hasFinish = dwFlags & PSH_WIZARDHASFINISH;
301 psInfo->isModeless = dwFlags & PSH_MODELESS;
302 psInfo->usePropPage = dwFlags & PSH_PROPSHEETPAGE;
303 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
304 psInfo->active_page = 0;
305
306 psInfo->result = 0;
307 psInfo->hImageList = 0;
308 psInfo->activeValid = FALSE;
309 }
310
311 /******************************************************************************
312 * PROPSHEET_CollectSheetInfoA
313 *
314 * Collect relevant data.
315 */
316 static void PROPSHEET_CollectSheetInfoA(LPCPROPSHEETHEADERA lppsh,
317 PropSheetInfo * psInfo)
318 {
319 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
320 DWORD dwFlags = lppsh->dwFlags;
321
322 psInfo->useCallback = (dwFlags & PSH_USECALLBACK )&& (lppsh->pfnCallback);
323
324 memcpy(&psInfo->ppshheader,lppsh,dwSize);
325 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
326 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance,
327 debugstr_a(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
328
329 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
330 psInfo->ppshheader.pszCaption = NULL;
331 else
332 {
333 if (HIWORD(lppsh->pszCaption))
334 {
335 int len = MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, NULL, 0);
336 WCHAR *caption = Alloc( len*sizeof (WCHAR) );
337
338 MultiByteToWideChar(CP_ACP, 0, lppsh->pszCaption, -1, caption, len);
339 psInfo->ppshheader.pszCaption = caption;
340 }
341 }
342 psInfo->nPages = lppsh->nPages;
343
344 if (dwFlags & PSH_USEPSTARTPAGE)
345 {
346 TRACE("PSH_USEPSTARTPAGE is on\n");
347 psInfo->active_page = 0;
348 }
349 else
350 psInfo->active_page = lppsh->u2.nStartPage;
351
352 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
353 }
354
355 /******************************************************************************
356 * PROPSHEET_CollectSheetInfoW
357 *
358 * Collect relevant data.
359 */
360 static void PROPSHEET_CollectSheetInfoW(LPCPROPSHEETHEADERW lppsh,
361 PropSheetInfo * psInfo)
362 {
363 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERW));
364 DWORD dwFlags = lppsh->dwFlags;
365
366 psInfo->useCallback = (dwFlags & PSH_USECALLBACK) && (lppsh->pfnCallback);
367
368 memcpy(&psInfo->ppshheader,lppsh,dwSize);
369 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%d\ndwFlags\t\t%08x\nhwndParent\t%p\nhInstance\t%p\npszCaption\t%s\nnPages\t\t%d\npfnCallback\t%p\n",
370 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, debugstr_w(lppsh->pszCaption), lppsh->nPages, lppsh->pfnCallback);
371
372 if (lppsh->dwFlags & INTRNL_ANY_WIZARD)
373 psInfo->ppshheader.pszCaption = NULL;
374 else
375 {
376 if (HIWORD(lppsh->pszCaption))
377 {
378 int len = strlenW(lppsh->pszCaption);
379 WCHAR *caption = Alloc( (len+1)*sizeof(WCHAR) );
380
381 psInfo->ppshheader.pszCaption = strcpyW( caption, lppsh->pszCaption );
382 }
383 }
384 psInfo->nPages = lppsh->nPages;
385
386 if (dwFlags & PSH_USEPSTARTPAGE)
387 {
388 TRACE("PSH_USEPSTARTPAGE is on\n");
389 psInfo->active_page = 0;
390 }
391 else
392 psInfo->active_page = lppsh->u2.nStartPage;
393
394 PROPSHEET_CollectSheetInfoCommon(psInfo, dwFlags);
395 }
396
397 /******************************************************************************
398 * PROPSHEET_CollectPageInfo
399 *
400 * Collect property sheet data.
401 * With code taken from DIALOG_ParseTemplate32.
402 */
403 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEW lppsp,
404 PropSheetInfo * psInfo,
405 int index, BOOL resize)
406 {
407 const DLGTEMPLATE* pTemplate;
408 const WORD* p;
409 DWORD dwFlags;
410 int width, height;
411
412 if (!lppsp)
413 return FALSE;
414
415 TRACE("\n");
416 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
417 psInfo->proppage[index].hwndPage = 0;
418 psInfo->proppage[index].isDirty = FALSE;
419
420 /*
421 * Process property page flags.
422 */
423 dwFlags = lppsp->dwFlags;
424 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
425 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
426 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
427
428 /* as soon as we have a page with the help flag, set the sheet flag on */
429 if (psInfo->proppage[index].hasHelp)
430 psInfo->hasHelp = TRUE;
431
432 /*
433 * Process page template.
434 */
435 if (dwFlags & PSP_DLGINDIRECT)
436 pTemplate = lppsp->u.pResource;
437 else if(dwFlags & PSP_INTERNAL_UNICODE )
438 {
439 HRSRC hResource = FindResourceW(lppsp->hInstance,
440 lppsp->u.pszTemplate,
441 (LPWSTR)RT_DIALOG);
442 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
443 hResource);
444 pTemplate = LockResource(hTemplate);
445 }
446 else
447 {
448 HRSRC hResource = FindResourceA(lppsp->hInstance,
449 (LPCSTR)lppsp->u.pszTemplate,
450 (LPSTR)RT_DIALOG);
451 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
452 hResource);
453 pTemplate = LockResource(hTemplate);
454 }
455
456 /*
457 * Extract the size of the page and the caption.
458 */
459 if (!pTemplate)
460 return FALSE;
461
462 p = (const WORD *)pTemplate;
463
464 if (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
465 {
466 /* DLGTEMPLATEEX (not defined in any std. header file) */
467
468 p++; /* dlgVer */
469 p++; /* signature */
470 p += 2; /* help ID */
471 p += 2; /* ext style */
472 p += 2; /* style */
473 }
474 else
475 {
476 /* DLGTEMPLATE */
477
478 p += 2; /* style */
479 p += 2; /* ext style */
480 }
481
482 p++; /* nb items */
483 p++; /* x */
484 p++; /* y */
485 width = (WORD)*p; p++;
486 height = (WORD)*p; p++;
487
488 /* Special calculation for interior wizard pages so the largest page is
489 * calculated correctly. We need to add all the padding and space occupied
490 * by the header so the width and height sums up to the whole wizard client
491 * area. */
492 if ((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
493 (psInfo->ppshheader.dwFlags & PSH_HEADER) &&
494 !(dwFlags & PSP_HIDEHEADER))
495 {
496 height += 2 * WIZARD_PADDING + WIZARD_HEADER_HEIGHT;
497 width += 2 * WIZARD_PADDING;
498 }
499 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
500 {
501 height += 2 * WIZARD_PADDING;
502 width += 2 * WIZARD_PADDING;
503 }
504
505 /* remember the largest width and height */
506 if (resize)
507 {
508 if (width > psInfo->width)
509 psInfo->width = width;
510
511 if (height > psInfo->height)
512 psInfo->height = height;
513 }
514
515 /* menu */
516 switch ((WORD)*p)
517 {
518 case 0x0000:
519 p++;
520 break;
521 case 0xffff:
522 p += 2;
523 break;
524 default:
525 p += lstrlenW( p ) + 1;
526 break;
527 }
528
529 /* class */
530 switch ((WORD)*p)
531 {
532 case 0x0000:
533 p++;
534 break;
535 case 0xffff:
536 p += 2;
537 break;
538 default:
539 p += lstrlenW( p ) + 1;
540 break;
541 }
542
543 /* Extract the caption */
544 psInfo->proppage[index].pszText = p;
545 TRACE("Tab %d %s\n",index,debugstr_w( p ));
546 p += lstrlenW( p ) + 1;
547
548 if (dwFlags & PSP_USETITLE)
549 {
550 WCHAR szTitle[256];
551 const WCHAR *pTitle;
552 static const WCHAR pszNull[] = { '(','n','u','l','l',')',0 };
553 WCHAR *text;
554 int len;
555
556 if ( !HIWORD( lppsp->pszTitle ) )
557 {
558 if (!LoadStringW( lppsp->hInstance, (DWORD_PTR)lppsp->pszTitle,szTitle,sizeof(szTitle)/sizeof(szTitle[0]) ))
559 {
560 pTitle = pszNull;
561 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
562 }
563 else
564 pTitle = szTitle;
565 }
566 else
567 pTitle = lppsp->pszTitle;
568
569 len = strlenW(pTitle);
570 text = Alloc( (len+1)*sizeof (WCHAR) );
571 psInfo->proppage[index].pszText = strcpyW( text, pTitle);
572 }
573
574 /*
575 * Build the image list for icons
576 */
577 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
578 {
579 HICON hIcon;
580 int icon_cx = GetSystemMetrics(SM_CXSMICON);
581 int icon_cy = GetSystemMetrics(SM_CYSMICON);
582
583 if (dwFlags & PSP_USEICONID)
584 hIcon = LoadImageW(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
585 icon_cx, icon_cy, LR_DEFAULTCOLOR);
586 else
587 hIcon = lppsp->u2.hIcon;
588
589 if ( hIcon )
590 {
591 if (psInfo->hImageList == 0 )
592 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
593
594 ImageList_AddIcon(psInfo->hImageList, hIcon);
595 }
596
597 }
598
599 return TRUE;
600 }
601
602 /******************************************************************************
603 * PROPSHEET_CreateDialog
604 *
605 * Creates the actual property sheet.
606 */
607 static INT_PTR PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
608 {
609 LRESULT ret;
610 LPCVOID template;
611 LPVOID temp = 0;
612 HRSRC hRes;
613 DWORD resSize;
614 WORD resID = IDD_PROPSHEET;
615
616 TRACE("\n");
617 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
618 resID = IDD_WIZARD;
619
620 if( psInfo->unicode )
621 {
622 if(!(hRes = FindResourceW(COMCTL32_hModule,
623 MAKEINTRESOURCEW(resID),
624 (LPWSTR)RT_DIALOG)))
625 return -1;
626 }
627 else
628 {
629 if(!(hRes = FindResourceA(COMCTL32_hModule,
630 MAKEINTRESOURCEA(resID),
631 (LPSTR)RT_DIALOG)))
632 return -1;
633 }
634
635 if(!(template = LoadResource(COMCTL32_hModule, hRes)))
636 return -1;
637
638 /*
639 * Make a copy of the dialog template.
640 */
641 resSize = SizeofResource(COMCTL32_hModule, hRes);
642
643 temp = Alloc(resSize);
644
645 if (!temp)
646 return -1;
647
648 memcpy(temp, template, resSize);
649
650 if (psInfo->ppshheader.dwFlags & PSH_NOCONTEXTHELP)
651 {
652 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
653 ((MyDLGTEMPLATEEX*)temp)->style &= ~DS_CONTEXTHELP;
654 else
655 ((DLGTEMPLATE*)temp)->style &= ~DS_CONTEXTHELP;
656 }
657 if ((psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD) &&
658 (psInfo->ppshheader.dwFlags & PSH_WIZARDCONTEXTHELP))
659 {
660 if (((MyDLGTEMPLATEEX*)temp)->signature == 0xFFFF)
661 ((MyDLGTEMPLATEEX*)temp)->style |= DS_CONTEXTHELP;
662 else
663 ((DLGTEMPLATE*)temp)->style |= DS_CONTEXTHELP;
664 }
665
666 if (psInfo->useCallback)
667 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
668
669 /* NOTE: MSDN states "Returns a positive value if successful, or -1
670 * otherwise for modal property sheets.", but this is wrong. The
671 * actual return value is either TRUE (success), FALSE (cancel) or
672 * -1 (error). */
673 if( psInfo->unicode )
674 {
675 ret = (INT_PTR)CreateDialogIndirectParamW(psInfo->ppshheader.hInstance,
676 temp, psInfo->ppshheader.hwndParent,
677 PROPSHEET_DialogProc, (LPARAM)psInfo);
678 if ( !ret ) ret = -1;
679 }
680 else
681 {
682 ret = (INT_PTR)CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
683 temp, psInfo->ppshheader.hwndParent,
684 PROPSHEET_DialogProc, (LPARAM)psInfo);
685 if ( !ret ) ret = -1;
686 }
687
688 Free(temp);
689
690 return ret;
691 }
692
693 /******************************************************************************
694 * PROPSHEET_SizeMismatch
695 *
696 * Verify that the tab control and the "largest" property sheet page dlg. template
697 * match in size.
698 */
699 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, const PropSheetInfo* psInfo)
700 {
701 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
702 RECT rcOrigTab, rcPage;
703
704 /*
705 * Original tab size.
706 */
707 GetClientRect(hwndTabCtrl, &rcOrigTab);
708 TRACE("orig tab %s\n", wine_dbgstr_rect(&rcOrigTab));
709
710 /*
711 * Biggest page size.
712 */
713 rcPage.left = 0;
714 rcPage.top = 0;
715 rcPage.right = psInfo->width;
716 rcPage.bottom = psInfo->height;
717
718 MapDialogRect(hwndDlg, &rcPage);
719 TRACE("biggest page %s\n", wine_dbgstr_rect(&rcPage));
720
721 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
722 return TRUE;
723 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
724 return TRUE;
725
726 return FALSE;
727 }
728
729 /******************************************************************************
730 * PROPSHEET_AdjustSize
731 *
732 * Resizes the property sheet and the tab control to fit the largest page.
733 */
734 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
735 {
736 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
737 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
738 RECT rc,tabRect;
739 int buttonHeight;
740 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
741 RECT units;
742 LONG style;
743
744 /* Get the height of buttons */
745 GetClientRect(hwndButton, &rc);
746 buttonHeight = rc.bottom;
747
748 /*
749 * Biggest page size.
750 */
751 rc.left = 0;
752 rc.top = 0;
753 rc.right = psInfo->width;
754 rc.bottom = psInfo->height;
755
756 MapDialogRect(hwndDlg, &rc);
757
758 /* retrieve the dialog units */
759 units.left = units.right = 4;
760 units.top = units.bottom = 8;
761 MapDialogRect(hwndDlg, &units);
762
763 /*
764 * Resize the tab control.
765 */
766 GetClientRect(hwndTabCtrl,&tabRect);
767
768 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
769
770 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
771 {
772 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
773 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
774 }
775
776 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
777 {
778 rc.right = rc.left + tabRect.right - tabRect.left;
779 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
780 }
781
782 SendMessageW(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
783
784 rc.right -= rc.left;
785 rc.bottom -= rc.top;
786 TRACE("setting tab %p, rc (0,0)-(%d,%d)\n",
787 hwndTabCtrl, rc.right, rc.bottom);
788 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
789 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
790
791 GetClientRect(hwndTabCtrl, &rc);
792
793 TRACE("tab client rc %s\n", wine_dbgstr_rect(&rc));
794
795 rc.right += (padding.x * 2);
796 rc.bottom += buttonHeight + (3 * padding.y);
797
798 style = GetWindowLongW(hwndDlg, GWL_STYLE);
799 if (!(style & WS_CHILD))
800 AdjustWindowRect(&rc, style, FALSE);
801
802 rc.right -= rc.left;
803 rc.bottom -= rc.top;
804
805 /*
806 * Resize the property sheet.
807 */
808 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
809 hwndDlg, rc.right, rc.bottom);
810 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
811 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
812 return TRUE;
813 }
814
815 /******************************************************************************
816 * PROPSHEET_AdjustSizeWizard
817 *
818 * Resizes the property sheet to fit the largest page.
819 */
820 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, const PropSheetInfo* psInfo)
821 {
822 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
823 RECT rc, lineRect, dialogRect;
824
825 /* Biggest page size */
826 rc.left = 0;
827 rc.top = 0;
828 rc.right = psInfo->width;
829 rc.bottom = psInfo->height;
830 MapDialogRect(hwndDlg, &rc);
831
832 TRACE("Biggest page %s\n", wine_dbgstr_rect(&rc));
833
834 /* Add space for the buttons row */
835 GetWindowRect(hwndLine, &lineRect);
836 MapWindowPoints(NULL, hwndDlg, (LPPOINT)&lineRect, 2);
837 GetClientRect(hwndDlg, &dialogRect);
838 rc.bottom += dialogRect.bottom - lineRect.top - 1;
839
840 /* Convert the client coordinates to window coordinates */
841 AdjustWindowRect(&rc, GetWindowLongW(hwndDlg, GWL_STYLE), FALSE);
842
843 /* Resize the property sheet */
844 TRACE("setting dialog %p, rc (0,0)-(%d,%d)\n",
845 hwndDlg, rc.right, rc.bottom);
846 SetWindowPos(hwndDlg, 0, 0, 0, rc.right - rc.left, rc.bottom - rc.top,
847 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
848
849 return TRUE;
850 }
851
852 /******************************************************************************
853 * PROPSHEET_AdjustButtons
854 *
855 * Adjusts the buttons' positions.
856 */
857 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, const PropSheetInfo* psInfo)
858 {
859 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
860 RECT rcSheet;
861 int x, y;
862 int num_buttons = 2;
863 int buttonWidth, buttonHeight;
864 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
865
866 if (psInfo->hasApply)
867 num_buttons++;
868
869 if (psInfo->hasHelp)
870 num_buttons++;
871
872 /*
873 * Obtain the size of the buttons.
874 */
875 GetClientRect(hwndButton, &rcSheet);
876 buttonWidth = rcSheet.right;
877 buttonHeight = rcSheet.bottom;
878
879 /*
880 * Get the size of the property sheet.
881 */
882 GetClientRect(hwndParent, &rcSheet);
883
884 /*
885 * All buttons will be at this y coordinate.
886 */
887 y = rcSheet.bottom - (padding.y + buttonHeight);
888
889 /*
890 * Position OK button and make it default.
891 */
892 hwndButton = GetDlgItem(hwndParent, IDOK);
893
894 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
895
896 SetWindowPos(hwndButton, 0, x, y, 0, 0,
897 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
898
899 SendMessageW(hwndParent, DM_SETDEFID, IDOK, 0);
900
901
902 /*
903 * Position Cancel button.
904 */
905 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
906
907 x += padding.x + buttonWidth;
908
909 SetWindowPos(hwndButton, 0, x, y, 0, 0,
910 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
911
912 /*
913 * Position Apply button.
914 */
915 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
916
917 if(psInfo->hasApply)
918 x += padding.x + buttonWidth;
919 else
920 ShowWindow(hwndButton, SW_HIDE);
921
922 SetWindowPos(hwndButton, 0, x, y, 0, 0,
923 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
924 EnableWindow(hwndButton, FALSE);
925
926 /*
927 * Position Help button.
928 */
929 hwndButton = GetDlgItem(hwndParent, IDHELP);
930
931 x += padding.x + buttonWidth;
932 SetWindowPos(hwndButton, 0, x, y, 0, 0,
933 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
934
935 if(!psInfo->hasHelp)
936 ShowWindow(hwndButton, SW_HIDE);
937
938 return TRUE;
939 }
940
941 /******************************************************************************
942 * PROPSHEET_AdjustButtonsWizard
943 *
944 * Adjusts the buttons' positions.
945 */
946 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
947 const PropSheetInfo* psInfo)
948 {
949 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
950 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
951 HWND hwndLineHeader = GetDlgItem(hwndParent, IDC_SUNKEN_LINEHEADER);
952 RECT rcSheet;
953 int x, y;
954 int num_buttons = 3;
955 int buttonWidth, buttonHeight, lineHeight, lineWidth;
956 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
957
958 if (psInfo->hasHelp)
959 num_buttons++;
960 if (psInfo->hasFinish)
961 num_buttons++;
962
963 /*
964 * Obtain the size of the buttons.
965 */
966 GetClientRect(hwndButton, &rcSheet);
967 buttonWidth = rcSheet.right;
968 buttonHeight = rcSheet.bottom;
969
970 GetClientRect(hwndLine, &rcSheet);
971 lineHeight = rcSheet.bottom;
972
973 /*
974 * Get the size of the property sheet.
975 */
976 GetClientRect(hwndParent, &rcSheet);
977
978 /*
979 * All buttons will be at this y coordinate.
980 */
981 y = rcSheet.bottom - (padding.y + buttonHeight);
982
983 /*
984 * Position the Back button.
985 */
986 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
987
988 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1)) - buttonWidth;
989
990 SetWindowPos(hwndButton, 0, x, y, 0, 0,
991 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
992
993 /*
994 * Position the Next button.
995 */
996 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
997
998 x += buttonWidth;
999
1000 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1001 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1002
1003 /*
1004 * Position the Finish button.
1005 */
1006 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
1007
1008 if (psInfo->hasFinish)
1009 x += padding.x + buttonWidth;
1010
1011 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1012 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1013
1014 if (!psInfo->hasFinish)
1015 ShowWindow(hwndButton, SW_HIDE);
1016
1017 /*
1018 * Position the Cancel button.
1019 */
1020 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
1021
1022 x += padding.x + buttonWidth;
1023
1024 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1025 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1026
1027 /*
1028 * Position Help button.
1029 */
1030 hwndButton = GetDlgItem(hwndParent, IDHELP);
1031
1032 if (psInfo->hasHelp)
1033 {
1034 x += padding.x + buttonWidth;
1035
1036 SetWindowPos(hwndButton, 0, x, y, 0, 0,
1037 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1038 }
1039 else
1040 ShowWindow(hwndButton, SW_HIDE);
1041
1042 if (psInfo->ppshheader.dwFlags &
1043 (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW | PSH_WIZARD_LITE))
1044 padding.x = 0;
1045
1046 /*
1047 * Position and resize the sunken line.
1048 */
1049 x = padding.x;
1050 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
1051
1052 lineWidth = rcSheet.right - (padding.x * 2);
1053 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
1054 SWP_NOZORDER | SWP_NOACTIVATE);
1055
1056 /*
1057 * Position and resize the header sunken line.
1058 */
1059
1060 SetWindowPos(hwndLineHeader, 0, 0, 0, rcSheet.right, 2,
1061 SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
1062 if (!(psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)))
1063 ShowWindow(hwndLineHeader, SW_HIDE);
1064
1065 return TRUE;
1066 }
1067
1068 /******************************************************************************
1069 * PROPSHEET_GetPaddingInfo
1070 *
1071 * Returns the layout information.
1072 */
1073 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
1074 {
1075 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1076 RECT rcTab;
1077 POINT tl;
1078 PADDING_INFO padding;
1079
1080 GetWindowRect(hwndTab, &rcTab);
1081
1082 tl.x = rcTab.left;
1083 tl.y = rcTab.top;
1084
1085 ScreenToClient(hwndDlg, &tl);
1086
1087 padding.x = tl.x;
1088 padding.y = tl.y;
1089
1090 return padding;
1091 }
1092
1093 /******************************************************************************
1094 * PROPSHEET_GetPaddingInfoWizard
1095 *
1096 * Returns the layout information.
1097 * Vertical spacing is the distance between the line and the buttons.
1098 * Do NOT use the Help button to gather padding information when it isn't mapped
1099 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
1100 * for it in this case !
1101 * FIXME: I'm not sure about any other coordinate problems with these evil
1102 * buttons. Fix it in case additional problems appear or maybe calculate
1103 * a padding in a completely different way, as this is somewhat messy.
1104 */
1105 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
1106 psInfo)
1107 {
1108 PADDING_INFO padding;
1109 RECT rc;
1110 HWND hwndControl;
1111 INT idButton;
1112 POINT ptButton, ptLine;
1113
1114 TRACE("\n");
1115 if (psInfo->hasHelp)
1116 {
1117 idButton = IDHELP;
1118 }
1119 else
1120 {
1121 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1122 {
1123 idButton = IDC_NEXT_BUTTON;
1124 }
1125 else
1126 {
1127 /* hopefully this is ok */
1128 idButton = IDCANCEL;
1129 }
1130 }
1131
1132 hwndControl = GetDlgItem(hwndDlg, idButton);
1133 GetWindowRect(hwndControl, &rc);
1134
1135 ptButton.x = rc.left;
1136 ptButton.y = rc.top;
1137
1138 ScreenToClient(hwndDlg, &ptButton);
1139
1140 /* Line */
1141 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
1142 GetWindowRect(hwndControl, &rc);
1143
1144 ptLine.x = rc.left;
1145 ptLine.y = rc.bottom;
1146
1147 ScreenToClient(hwndDlg, &ptLine);
1148
1149 padding.y = ptButton.y - ptLine.y;
1150
1151 if (padding.y < 0)
1152 ERR("padding negative ! Please report this !\n");
1153
1154 /* this is most probably not correct, but the best we have now */
1155 padding.x = padding.y;
1156 return padding;
1157 }
1158
1159 /******************************************************************************
1160 * PROPSHEET_CreateTabControl
1161 *
1162 * Insert the tabs in the tab control.
1163 */
1164 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
1165 const PropSheetInfo * psInfo)
1166 {
1167 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1168 TCITEMW item;
1169 int i, nTabs;
1170 int iImage = 0;
1171
1172 TRACE("\n");
1173 item.mask = TCIF_TEXT;
1174 item.cchTextMax = MAX_TABTEXT_LENGTH;
1175
1176 nTabs = psInfo->nPages;
1177
1178 /*
1179 * Set the image list for icons.
1180 */
1181 if (psInfo->hImageList)
1182 {
1183 SendMessageW(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1184 }
1185
1186 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 0, 0);
1187 for (i = 0; i < nTabs; i++)
1188 {
1189 if ( psInfo->proppage[i].hasIcon )
1190 {
1191 item.mask |= TCIF_IMAGE;
1192 item.iImage = iImage++;
1193 }
1194 else
1195 {
1196 item.mask &= ~TCIF_IMAGE;
1197 }
1198
1199 item.pszText = (LPWSTR) psInfo->proppage[i].pszText;
1200 SendMessageW(hwndTabCtrl, TCM_INSERTITEMW, (WPARAM)i, (LPARAM)&item);
1201 }
1202 SendMessageW(GetDlgItem(hwndTabCtrl, IDC_TABCONTROL), WM_SETREDRAW, 1, 0);
1203
1204 return TRUE;
1205 }
1206
1207 /******************************************************************************
1208 * PROPSHEET_WizardSubclassProc
1209 *
1210 * Subclassing window procedure for wizard exterior pages to prevent drawing
1211 * background and so drawing above the watermark.
1212 */
1213 static LRESULT CALLBACK
1214 PROPSHEET_WizardSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, DWORD_PTR dwRef)
1215 {
1216 switch (uMsg)
1217 {
1218 case WM_ERASEBKGND:
1219 return TRUE;
1220
1221 case WM_CTLCOLORSTATIC:
1222 SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW));
1223 return (INT_PTR)GetSysColorBrush(COLOR_WINDOW);
1224 }
1225
1226 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
1227 }
1228
1229 /*
1230 * Get the size of an in-memory Template
1231 *
1232 *( Based on the code of PROPSHEET_CollectPageInfo)
1233 * See also dialog.c/DIALOG_ParseTemplate32().
1234 */
1235
1236 static UINT GetTemplateSize(const DLGTEMPLATE* pTemplate)
1237
1238 {
1239 const WORD* p = (const WORD *)pTemplate;
1240 BOOL istemplateex = (((const MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF);
1241 WORD nrofitems;
1242 UINT ret;
1243
1244 if (istemplateex)
1245 {
1246 /* DLGTEMPLATEEX (not defined in any std. header file) */
1247
1248 TRACE("is DLGTEMPLATEEX\n");
1249 p++; /* dlgVer */
1250 p++; /* signature */
1251 p += 2; /* help ID */
1252 p += 2; /* ext style */
1253 p += 2; /* style */
1254 }
1255 else
1256 {
1257 /* DLGTEMPLATE */
1258
1259 TRACE("is DLGTEMPLATE\n");
1260 p += 2; /* style */
1261 p += 2; /* ext style */
1262 }
1263
1264 nrofitems = (WORD)*p; p++; /* nb items */
1265 p++; /* x */
1266 p++; /* y */
1267 p++; /* width */
1268 p++; /* height */
1269
1270 /* menu */
1271 switch ((WORD)*p)
1272 {
1273 case 0x0000:
1274 p++;
1275 break;
1276 case 0xffff:
1277 p += 2;
1278 break;
1279 default:
1280 TRACE("menu %s\n",debugstr_w( p ));
1281 p += lstrlenW( p ) + 1;
1282 break;
1283 }
1284
1285 /* class */
1286 switch ((WORD)*p)
1287 {
1288 case 0x0000:
1289 p++;
1290 break;
1291 case 0xffff:
1292 p += 2; /* 0xffff plus predefined window class ordinal value */
1293 break;
1294 default:
1295 TRACE("class %s\n",debugstr_w( p ));
1296 p += lstrlenW( p ) + 1;
1297 break;
1298 }
1299
1300 /* title */
1301 TRACE("title %s\n",debugstr_w( p ));
1302 p += lstrlenW( p ) + 1;
1303
1304 /* font, if DS_SETFONT set */
1305 if ((DS_SETFONT & ((istemplateex)? ((const MyDLGTEMPLATEEX*)pTemplate)->style :
1306 pTemplate->style)))
1307 {
1308 p+=(istemplateex)?3:1;
1309 TRACE("font %s\n",debugstr_w( p ));
1310 p += lstrlenW( p ) + 1; /* the font name */
1311 }
1312
1313 /* now process the DLGITEMTEMPLATE(EX) structs (plus custom data)
1314 * that are following the DLGTEMPLATE(EX) data */
1315 TRACE("%d items\n",nrofitems);
1316 while (nrofitems > 0)
1317 {
1318 p = (WORD*)(((DWORD_PTR)p + 3) & ~3); /* DWORD align */
1319
1320 /* skip header */
1321 p += (istemplateex ? sizeof(MyDLGITEMTEMPLATEEX) : sizeof(DLGITEMTEMPLATE))/sizeof(WORD);
1322
1323 /* check class */
1324 switch ((WORD)*p)
1325 {
1326 case 0x0000:
1327 p++;
1328 break;
1329 case 0xffff:
1330 TRACE("class ordinal 0x%08x\n",*(const DWORD*)p);
1331 p += 2;
1332 break;
1333 default:
1334 TRACE("class %s\n",debugstr_w( p ));
1335 p += lstrlenW( p ) + 1;
1336 break;
1337 }
1338
1339 /* check title text */
1340 switch ((WORD)*p)
1341 {
1342 case 0x0000:
1343 p++;
1344 break;
1345 case 0xffff:
1346 TRACE("text ordinal 0x%08x\n",*(const DWORD*)p);
1347 p += 2;
1348 break;
1349 default:
1350 TRACE("text %s\n",debugstr_w( p ));
1351 p += lstrlenW( p ) + 1;
1352 break;
1353 }
1354 p += *p / sizeof(WORD) + 1; /* Skip extra data */
1355 --nrofitems;
1356 }
1357
1358 ret = (p - (const WORD*)pTemplate) * sizeof(WORD);
1359 TRACE("%p %p size 0x%08x\n", p, pTemplate, ret);
1360 return ret;
1361 }
1362
1363 /******************************************************************************
1364 * PROPSHEET_CreatePage
1365 *
1366 * Creates a page.
1367 */
1368 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
1369 int index,
1370 const PropSheetInfo * psInfo,
1371 LPCPROPSHEETPAGEW ppshpage)
1372 {
1373 DLGTEMPLATE* pTemplate;
1374 HWND hwndPage;
1375 DWORD resSize;
1376 LPVOID temp = NULL;
1377
1378 TRACE("index %d\n", index);
1379
1380 if (ppshpage == NULL)
1381 {
1382 return FALSE;
1383 }
1384
1385 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1386 {
1387 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1388 resSize = GetTemplateSize(pTemplate);
1389 }
1390 else if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1391 {
1392 HRSRC hResource;
1393 HANDLE hTemplate;
1394
1395 hResource = FindResourceW(ppshpage->hInstance,
1396 ppshpage->u.pszTemplate,
1397 (LPWSTR)RT_DIALOG);
1398 if(!hResource)
1399 return FALSE;
1400
1401 resSize = SizeofResource(ppshpage->hInstance, hResource);
1402
1403 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1404 if(!hTemplate)
1405 return FALSE;
1406
1407 pTemplate = LockResource(hTemplate);
1408 /*
1409 * Make a copy of the dialog template to make it writable
1410 */
1411 }
1412 else
1413 {
1414 HRSRC hResource;
1415 HANDLE hTemplate;
1416
1417 hResource = FindResourceA(ppshpage->hInstance,
1418 (LPCSTR)ppshpage->u.pszTemplate,
1419 (LPSTR)RT_DIALOG);
1420 if(!hResource)
1421 return FALSE;
1422
1423 resSize = SizeofResource(ppshpage->hInstance, hResource);
1424
1425 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1426 if(!hTemplate)
1427 return FALSE;
1428
1429 pTemplate = LockResource(hTemplate);
1430 /*
1431 * Make a copy of the dialog template to make it writable
1432 */
1433 }
1434 temp = Alloc(resSize);
1435 if (!temp)
1436 return FALSE;
1437
1438 TRACE("copying pTemplate %p into temp %p (%d)\n", pTemplate, temp, resSize);
1439 memcpy(temp, pTemplate, resSize);
1440 pTemplate = temp;
1441
1442 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1443 {
1444 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1445 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1446 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1447 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1448 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1449 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1450 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1451 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1452
1453 ((MyDLGTEMPLATEEX*)pTemplate)->exStyle |= WS_EX_CONTROLPARENT;
1454 }
1455 else
1456 {
1457 pTemplate->style |= WS_CHILD | WS_TABSTOP | DS_CONTROL;
1458 pTemplate->style &= ~DS_MODALFRAME;
1459 pTemplate->style &= ~WS_CAPTION;
1460 pTemplate->style &= ~WS_SYSMENU;
1461 pTemplate->style &= ~WS_POPUP;
1462 pTemplate->style &= ~WS_DISABLED;
1463 pTemplate->style &= ~WS_VISIBLE;
1464 pTemplate->style &= ~WS_THICKFRAME;
1465
1466 pTemplate->dwExtendedStyle |= WS_EX_CONTROLPARENT;
1467 }
1468
1469 if (psInfo->proppage[index].useCallback)
1470 (*(ppshpage->pfnCallback))(0, PSPCB_CREATE,
1471 (LPPROPSHEETPAGEW)ppshpage);
1472
1473 if(ppshpage->dwFlags & PSP_INTERNAL_UNICODE)
1474 hwndPage = CreateDialogIndirectParamW(ppshpage->hInstance,
1475 pTemplate,
1476 hwndParent,
1477 ppshpage->pfnDlgProc,
1478 (LPARAM)ppshpage);
1479 else
1480 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1481 pTemplate,
1482 hwndParent,
1483 ppshpage->pfnDlgProc,
1484 (LPARAM)ppshpage);
1485 /* Free a no more needed copy */
1486 Free(temp);
1487
1488 psInfo->proppage[index].hwndPage = hwndPage;
1489
1490 /* Subclass exterior wizard pages */
1491 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
1492 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1493 (ppshpage->dwFlags & PSP_HIDEHEADER))
1494 {
1495 SetWindowSubclass(hwndPage, PROPSHEET_WizardSubclassProc, 1,
1496 (DWORD_PTR)ppshpage);
1497 }
1498 if (!(psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD))
1499 EnableThemeDialogTexture (hwndPage, ETDT_ENABLETAB);
1500
1501 return TRUE;
1502 }
1503
1504 /******************************************************************************
1505 * PROPSHEET_LoadWizardBitmaps
1506 *
1507 * Loads the watermark and header bitmaps for a wizard.
1508 */
1509 static VOID PROPSHEET_LoadWizardBitmaps(PropSheetInfo *psInfo)
1510 {
1511 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD))
1512 {
1513 /* if PSH_USEHBMWATERMARK is not set, load the resource from pszbmWatermark
1514 and put the HBITMAP in hbmWatermark. Thus all the rest of the code always
1515 considers hbmWatermark as valid. */
1516 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
1517 !(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK))
1518 {
1519 psInfo->ppshheader.u4.hbmWatermark =
1520 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u4.pszbmWatermark, 0, NULL, 0);
1521 }
1522
1523 /* Same behavior as for watermarks */
1524 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
1525 !(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER))
1526 {
1527 psInfo->ppshheader.u5.hbmHeader =
1528 CreateMappedBitmap(psInfo->ppshheader.hInstance, (INT_PTR)psInfo->ppshheader.u5.pszbmHeader, 0, NULL, 0);
1529 }
1530 }
1531 }
1532
1533
1534 /******************************************************************************
1535 * PROPSHEET_ShowPage
1536 *
1537 * Displays or creates the specified page.
1538 */
1539 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1540 {
1541 HWND hwndTabCtrl;
1542 HWND hwndLineHeader;
1543 HWND control;
1544 LPCPROPSHEETPAGEW ppshpage;
1545
1546 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1547 if (index == psInfo->active_page)
1548 {
1549 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1550 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1551 return TRUE;
1552 }
1553
1554 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1555 if (psInfo->proppage[index].hwndPage == 0)
1556 {
1557 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1558 }
1559
1560 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
1561 {
1562 PROPSHEET_SetTitleW(hwndDlg, psInfo->ppshheader.dwFlags,
1563 psInfo->proppage[index].pszText);
1564
1565 control = GetNextDlgTabItem(psInfo->proppage[index].hwndPage, NULL, FALSE);
1566 if(control != NULL)
1567 SetFocus(control);
1568 }
1569
1570 if (psInfo->active_page != -1)
1571 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1572
1573 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1574
1575 /* Synchronize current selection with tab control
1576 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1577 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1578 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1579
1580 psInfo->active_page = index;
1581 psInfo->activeValid = TRUE;
1582
1583 if (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW) )
1584 {
1585 hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
1586 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
1587
1588 if ((ppshpage->dwFlags & PSP_HIDEHEADER) || (!(psInfo->ppshheader.dwFlags & PSH_HEADER)) )
1589 ShowWindow(hwndLineHeader, SW_HIDE);
1590 else
1591 ShowWindow(hwndLineHeader, SW_SHOW);
1592 }
1593
1594 return TRUE;
1595 }
1596
1597 /******************************************************************************
1598 * PROPSHEET_Back
1599 */
1600 static BOOL PROPSHEET_Back(HWND hwndDlg)
1601 {
1602 PSHNOTIFY psn;
1603 HWND hwndPage;
1604 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1605 LRESULT result;
1606 int idx;
1607
1608 TRACE("active_page %d\n", psInfo->active_page);
1609 if (psInfo->active_page < 0)
1610 return FALSE;
1611
1612 psn.hdr.code = PSN_WIZBACK;
1613 psn.hdr.hwndFrom = hwndDlg;
1614 psn.hdr.idFrom = 0;
1615 psn.lParam = 0;
1616
1617 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1618
1619 result = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1620 if (result == -1)
1621 return FALSE;
1622 else if (result == 0)
1623 idx = psInfo->active_page - 1;
1624 else
1625 idx = PROPSHEET_FindPageByResId(psInfo, result);
1626
1627 if (idx >= 0 && idx < psInfo->nPages)
1628 {
1629 if (PROPSHEET_CanSetCurSel(hwndDlg))
1630 {
1631 SetFocus(GetDlgItem(hwndDlg, IDC_BACK_BUTTON));
1632 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
1633 PROPSHEET_SetCurSel(hwndDlg, idx, -1, 0);
1634 }
1635 }
1636 return TRUE;
1637 }
1638
1639 /******************************************************************************
1640 * PROPSHEET_Next
1641 */
1642 static BOOL PROPSHEET_Next(HWND hwndDlg)
1643 {
1644 PSHNOTIFY psn;
1645 HWND hwndPage;
1646 LRESULT msgResult = 0;
1647 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1648 int idx;
1649
1650 TRACE("active_page %d\n", psInfo->active_page);
1651 if (psInfo->active_page < 0)
1652 return FALSE;
1653
1654 psn.hdr.code = PSN_WIZNEXT;
1655 psn.hdr.hwndFrom = hwndDlg;
1656 psn.hdr.idFrom = 0;
1657 psn.lParam = 0;
1658
1659 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1660
1661 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1662 if (msgResult == -1)
1663 return FALSE;
1664 else if (msgResult == 0)
1665 idx = psInfo->active_page + 1;
1666 else
1667 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1668
1669 if (idx < psInfo->nPages )
1670 {
1671 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1672 {
1673 SetFocus(GetDlgItem(hwndDlg, IDC_NEXT_BUTTON));
1674 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1675 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
1676 }
1677 }
1678
1679 return TRUE;
1680 }
1681
1682 /******************************************************************************
1683 * PROPSHEET_Finish
1684 */
1685 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1686 {
1687 PSHNOTIFY psn;
1688 HWND hwndPage;
1689 LRESULT msgResult = 0;
1690 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1691
1692 TRACE("active_page %d\n", psInfo->active_page);
1693 if (psInfo->active_page < 0)
1694 return FALSE;
1695
1696 psn.hdr.code = PSN_WIZFINISH;
1697 psn.hdr.hwndFrom = hwndDlg;
1698 psn.hdr.idFrom = 0;
1699 psn.lParam = 0;
1700
1701 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1702
1703 msgResult = SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1704
1705 TRACE("msg result %ld\n", msgResult);
1706
1707 if (msgResult != 0)
1708 return FALSE;
1709
1710 if (psInfo->result == 0)
1711 psInfo->result = IDOK;
1712 if (psInfo->isModeless)
1713 psInfo->activeValid = FALSE;
1714 else
1715 psInfo->ended = TRUE;
1716
1717 return TRUE;
1718 }
1719
1720 /******************************************************************************
1721 * PROPSHEET_Apply
1722 */
1723 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1724 {
1725 int i;
1726 HWND hwndPage;
1727 PSHNOTIFY psn;
1728 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1729
1730 TRACE("active_page %d\n", psInfo->active_page);
1731 if (psInfo->active_page < 0)
1732 return FALSE;
1733
1734 psn.hdr.hwndFrom = hwndDlg;
1735 psn.hdr.idFrom = 0;
1736 psn.lParam = 0;
1737
1738
1739 /*
1740 * Send PSN_KILLACTIVE to the current page.
1741 */
1742 psn.hdr.code = PSN_KILLACTIVE;
1743
1744 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1745
1746 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1747 return FALSE;
1748
1749 /*
1750 * Send PSN_APPLY to all pages.
1751 */
1752 psn.hdr.code = PSN_APPLY;
1753 psn.lParam = lParam;
1754
1755 for (i = 0; i < psInfo->nPages; i++)
1756 {
1757 hwndPage = psInfo->proppage[i].hwndPage;
1758 if (hwndPage)
1759 {
1760 switch (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1761 {
1762 case PSNRET_INVALID:
1763 PROPSHEET_ShowPage(hwndDlg, i, psInfo);
1764 /* fall through */
1765 case PSNRET_INVALID_NOCHANGEPAGE:
1766 return FALSE;
1767 }
1768 }
1769 }
1770
1771 if(lParam)
1772 {
1773 psInfo->activeValid = FALSE;
1774 }
1775 else if(psInfo->active_page >= 0)
1776 {
1777 psn.hdr.code = PSN_SETACTIVE;
1778 psn.lParam = 0;
1779 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1780 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1781 }
1782
1783 return TRUE;
1784 }
1785
1786 /******************************************************************************
1787 * PROPSHEET_Cancel
1788 */
1789 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1790 {
1791 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1792 HWND hwndPage;
1793 PSHNOTIFY psn;
1794 int i;
1795
1796 TRACE("active_page %d\n", psInfo->active_page);
1797 if (psInfo->active_page < 0)
1798 return;
1799
1800 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1801 psn.hdr.code = PSN_QUERYCANCEL;
1802 psn.hdr.hwndFrom = hwndDlg;
1803 psn.hdr.idFrom = 0;
1804 psn.lParam = 0;
1805
1806 if (SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1807 return;
1808
1809 psn.hdr.code = PSN_RESET;
1810 psn.lParam = lParam;
1811
1812 for (i = 0; i < psInfo->nPages; i++)
1813 {
1814 hwndPage = psInfo->proppage[i].hwndPage;
1815
1816 if (hwndPage)
1817 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1818 }
1819
1820 if (psInfo->isModeless)
1821 {
1822 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1823 psInfo->activeValid = FALSE;
1824 }
1825 else
1826 psInfo->ended = TRUE;
1827 }
1828
1829 /******************************************************************************
1830 * PROPSHEET_Help
1831 */
1832 static void PROPSHEET_Help(HWND hwndDlg)
1833 {
1834 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1835 HWND hwndPage;
1836 PSHNOTIFY psn;
1837
1838 TRACE("active_page %d\n", psInfo->active_page);
1839 if (psInfo->active_page < 0)
1840 return;
1841
1842 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1843 psn.hdr.code = PSN_HELP;
1844 psn.hdr.hwndFrom = hwndDlg;
1845 psn.hdr.idFrom = 0;
1846 psn.lParam = 0;
1847
1848 SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1849 }
1850
1851 /******************************************************************************
1852 * PROPSHEET_Changed
1853 */
1854 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1855 {
1856 int i;
1857 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1858
1859 TRACE("\n");
1860 if (!psInfo) return;
1861 /*
1862 * Set the dirty flag of this page.
1863 */
1864 for (i = 0; i < psInfo->nPages; i++)
1865 {
1866 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1867 psInfo->proppage[i].isDirty = TRUE;
1868 }
1869
1870 /*
1871 * Enable the Apply button.
1872 */
1873 if (psInfo->hasApply)
1874 {
1875 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1876
1877 EnableWindow(hwndApplyBtn, TRUE);
1878 }
1879 }
1880
1881 /******************************************************************************
1882 * PROPSHEET_UnChanged
1883 */
1884 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1885 {
1886 int i;
1887 BOOL noPageDirty = TRUE;
1888 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1889 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1890
1891 TRACE("\n");
1892 if ( !psInfo ) return;
1893 for (i = 0; i < psInfo->nPages; i++)
1894 {
1895 /* set the specified page as clean */
1896 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1897 psInfo->proppage[i].isDirty = FALSE;
1898
1899 /* look to see if there's any dirty pages */
1900 if (psInfo->proppage[i].isDirty)
1901 noPageDirty = FALSE;
1902 }
1903
1904 /*
1905 * Disable Apply button.
1906 */
1907 if (noPageDirty)
1908 EnableWindow(hwndApplyBtn, FALSE);
1909 }
1910
1911 /******************************************************************************
1912 * PROPSHEET_PressButton
1913 */
1914 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1915 {
1916 TRACE("buttonID %d\n", buttonID);
1917 switch (buttonID)
1918 {
1919 case PSBTN_APPLYNOW:
1920 PROPSHEET_DoCommand(hwndDlg, IDC_APPLY_BUTTON);
1921 break;
1922 case PSBTN_BACK:
1923 PROPSHEET_Back(hwndDlg);
1924 break;
1925 case PSBTN_CANCEL:
1926 PROPSHEET_DoCommand(hwndDlg, IDCANCEL);
1927 break;
1928 case PSBTN_FINISH:
1929 PROPSHEET_Finish(hwndDlg);
1930 break;
1931 case PSBTN_HELP:
1932 PROPSHEET_DoCommand(hwndDlg, IDHELP);
1933 break;
1934 case PSBTN_NEXT:
1935 PROPSHEET_Next(hwndDlg);
1936 break;
1937 case PSBTN_OK:
1938 PROPSHEET_DoCommand(hwndDlg, IDOK);
1939 break;
1940 default:
1941 FIXME("Invalid button index %d\n", buttonID);
1942 }
1943 }
1944
1945
1946 /*************************************************************************
1947 * BOOL PROPSHEET_CanSetCurSel [Internal]
1948 *
1949 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1950 *
1951 * PARAMS
1952 * hwndDlg [I] handle to a Dialog hWnd
1953 *
1954 * RETURNS
1955 * TRUE if Current Selection can change
1956 *
1957 * NOTES
1958 */
1959 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1960 {
1961 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
1962 HWND hwndPage;
1963 PSHNOTIFY psn;
1964 BOOL res = FALSE;
1965
1966 TRACE("active_page %d\n", psInfo->active_page);
1967 if (!psInfo)
1968 {
1969 res = FALSE;
1970 goto end;
1971 }
1972
1973 if (psInfo->active_page < 0)
1974 {
1975 res = TRUE;
1976 goto end;
1977 }
1978
1979 /*
1980 * Notify the current page.
1981 */
1982 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1983 psn.hdr.code = PSN_KILLACTIVE;
1984 psn.hdr.hwndFrom = hwndDlg;
1985 psn.hdr.idFrom = 0;
1986 psn.lParam = 0;
1987
1988 res = !SendMessageW(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1989
1990 end:
1991 TRACE("<-- %d\n", res);
1992 return res;
1993 }
1994
1995 /******************************************************************************
1996 * PROPSHEET_SetCurSel
1997 */
1998 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1999 int index,
2000 int skipdir,
2001 HPROPSHEETPAGE hpage
2002 )
2003 {
2004 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2005 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
2006 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2007
2008 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
2009 /* hpage takes precedence over index */
2010 if (hpage != NULL)
2011 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2012
2013 if (index < 0 || index >= psInfo->nPages)
2014 {
2015 TRACE("Could not find page to select!\n");
2016 return FALSE;
2017 }
2018
2019 /* unset active page while doing this transition. */
2020 if (psInfo->active_page != -1)
2021 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
2022 psInfo->active_page = -1;
2023
2024 while (1) {
2025 int result;
2026 PSHNOTIFY psn;
2027 RECT rc;
2028 LPCPROPSHEETPAGEW ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2029
2030 if (hwndTabControl)
2031 SendMessageW(hwndTabControl, TCM_SETCURSEL, index, 0);
2032
2033 psn.hdr.code = PSN_SETACTIVE;
2034 psn.hdr.hwndFrom = hwndDlg;
2035 psn.hdr.idFrom = 0;
2036 psn.lParam = 0;
2037
2038 if (!psInfo->proppage[index].hwndPage) {
2039 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
2040 }
2041
2042 /* Resize the property sheet page to the fit in the Tab control
2043 * (for regular property sheets) or to fit in the client area (for
2044 * wizards).
2045 * NOTE: The resizing happens every time the page is selected and
2046 * not only when it's created (some applications depend on it). */
2047 PROPSHEET_GetPageRect(psInfo, hwndDlg, &rc, ppshpage);
2048 TRACE("setting page %p, rc (%s) w=%d, h=%d\n",
2049 psInfo->proppage[index].hwndPage, wine_dbgstr_rect(&rc),
2050 rc.right - rc.left, rc.bottom - rc.top);
2051 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP,
2052 rc.left, rc.top,
2053 rc.right - rc.left, rc.bottom - rc.top, 0);
2054
2055 result = SendMessageW(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
2056 if (!result)
2057 break;
2058 if (result == -1) {
2059 index+=skipdir;
2060 if (index < 0) {
2061 index = 0;
2062 WARN("Tried to skip before first property sheet page!\n");
2063 break;
2064 }
2065 if (index >= psInfo->nPages) {
2066 WARN("Tried to skip after last property sheet page!\n");
2067 index = psInfo->nPages-1;
2068 break;
2069 }
2070 }
2071 else if (result != 0)
2072 {
2073 int old_index = index;
2074 index = PROPSHEET_FindPageByResId(psInfo, result);
2075 if(index >= psInfo->nPages) {
2076 index = old_index;
2077 WARN("Tried to skip to nonexistent page by res id\n");
2078 break;
2079 }
2080 continue;
2081 }
2082 }
2083
2084 /* Invalidate the header area */
2085 if ( (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
2086 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
2087 {
2088 HWND hwndLineHeader = GetDlgItem(hwndDlg, IDC_SUNKEN_LINEHEADER);
2089 RECT r;
2090
2091 GetClientRect(hwndLineHeader, &r);
2092 MapWindowPoints(hwndLineHeader, hwndDlg, (LPPOINT) &r, 2);
2093 SetRect(&r, 0, 0, r.right + 1, r.top - 1);
2094
2095 InvalidateRect(hwndDlg, &r, TRUE);
2096 }
2097
2098 /*
2099 * Display the new page.
2100 */
2101 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
2102
2103 if (psInfo->proppage[index].hasHelp)
2104 EnableWindow(hwndHelp, TRUE);
2105 else
2106 EnableWindow(hwndHelp, FALSE);
2107
2108 return TRUE;
2109 }
2110
2111 /******************************************************************************
2112 * PROPSHEET_SetCurSelId
2113 *
2114 * Selects the page, specified by resource id.
2115 */
2116 static void PROPSHEET_SetCurSelId(HWND hwndDlg, int id)
2117 {
2118 int idx;
2119 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2120
2121 idx = PROPSHEET_FindPageByResId(psInfo, id);
2122 if (idx < psInfo->nPages )
2123 {
2124 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
2125 PROPSHEET_SetCurSel(hwndDlg, idx, 1, 0);
2126 }
2127 }
2128
2129 /******************************************************************************
2130 * PROPSHEET_SetTitleA
2131 */
2132 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
2133 {
2134 if(HIWORD(lpszText))
2135 {
2136 WCHAR szTitle[256];
2137 MultiByteToWideChar(CP_ACP, 0, lpszText, -1,
2138 szTitle, sizeof(szTitle)/sizeof(WCHAR));
2139 PROPSHEET_SetTitleW(hwndDlg, dwStyle, szTitle);
2140 }
2141 else
2142 {
2143 PROPSHEET_SetTitleW(hwndDlg, dwStyle, (LPCWSTR)lpszText);
2144 }
2145 }
2146
2147 /******************************************************************************
2148 * PROPSHEET_SetTitleW
2149 */
2150 static void PROPSHEET_SetTitleW(HWND hwndDlg, DWORD dwStyle, LPCWSTR lpszText)
2151 {
2152 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2153 WCHAR szTitle[256];
2154
2155 TRACE("%s (style %08x)\n", debugstr_w(lpszText), dwStyle);
2156 if (HIWORD(lpszText) == 0) {
2157 if (!LoadStringW(psInfo->ppshheader.hInstance,
2158 LOWORD(lpszText), szTitle, sizeof(szTitle)/sizeof(szTitle[0])))
2159 return;
2160 lpszText = szTitle;
2161 }
2162 if (dwStyle & PSH_PROPTITLE)
2163 {
2164 WCHAR* dest;
2165 int lentitle = strlenW(lpszText);
2166 int lenprop = strlenW(psInfo->strPropertiesFor);
2167
2168 dest = Alloc( (lentitle + lenprop + 1)*sizeof (WCHAR));
2169 wsprintfW(dest, psInfo->strPropertiesFor, lpszText);
2170
2171 SetWindowTextW(hwndDlg, dest);
2172 Free(dest);
2173 }
2174 else
2175 SetWindowTextW(hwndDlg, lpszText);
2176 }
2177
2178 /******************************************************************************
2179 * PROPSHEET_SetFinishTextA
2180 */
2181 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
2182 {
2183 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2184 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2185
2186 TRACE("'%s'\n", lpszText);
2187 /* Set text, show and enable the Finish button */
2188 SetWindowTextA(hwndButton, lpszText);
2189 ShowWindow(hwndButton, SW_SHOW);
2190 EnableWindow(hwndButton, TRUE);
2191
2192 /* Make it default pushbutton */
2193 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2194
2195 /* Hide Back button */
2196 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2197 ShowWindow(hwndButton, SW_HIDE);
2198
2199 if (!psInfo->hasFinish)
2200 {
2201 /* Hide Next button */
2202 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2203 ShowWindow(hwndButton, SW_HIDE);
2204 }
2205 }
2206
2207 /******************************************************************************
2208 * PROPSHEET_SetFinishTextW
2209 */
2210 static void PROPSHEET_SetFinishTextW(HWND hwndDlg, LPCWSTR lpszText)
2211 {
2212 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2213 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2214
2215 TRACE("%s\n", debugstr_w(lpszText));
2216 /* Set text, show and enable the Finish button */
2217 SetWindowTextW(hwndButton, lpszText);
2218 ShowWindow(hwndButton, SW_SHOW);
2219 EnableWindow(hwndButton, TRUE);
2220
2221 /* Make it default pushbutton */
2222 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2223
2224 /* Hide Back button */
2225 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2226 ShowWindow(hwndButton, SW_HIDE);
2227
2228 if (!psInfo->hasFinish)
2229 {
2230 /* Hide Next button */
2231 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2232 ShowWindow(hwndButton, SW_HIDE);
2233 }
2234 }
2235
2236 /******************************************************************************
2237 * PROPSHEET_QuerySiblings
2238 */
2239 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
2240 WPARAM wParam, LPARAM lParam)
2241 {
2242 int i = 0;
2243 HWND hwndPage;
2244 LRESULT msgResult = 0;
2245 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2246
2247 while ((i < psInfo->nPages) && (msgResult == 0))
2248 {
2249 hwndPage = psInfo->proppage[i].hwndPage;
2250 msgResult = SendMessageW(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
2251 i++;
2252 }
2253
2254 return msgResult;
2255 }
2256
2257
2258 /******************************************************************************
2259 * PROPSHEET_AddPage
2260 */
2261 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
2262 HPROPSHEETPAGE hpage)
2263 {
2264 PropPageInfo * ppi;
2265 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2266 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2267 TCITEMW item;
2268 LPCPROPSHEETPAGEW ppsp = (LPCPROPSHEETPAGEW)hpage;
2269
2270 TRACE("hpage %p\n", hpage);
2271 /*
2272 * Allocate and fill in a new PropPageInfo entry.
2273 */
2274 ppi = ReAlloc(psInfo->proppage, sizeof(PropPageInfo) * (psInfo->nPages + 1));
2275 if (!ppi)
2276 return FALSE;
2277
2278 psInfo->proppage = ppi;
2279 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages, FALSE))
2280 return FALSE;
2281
2282 psInfo->proppage[psInfo->nPages].hpage = hpage;
2283
2284 if (ppsp->dwFlags & PSP_PREMATURE)
2285 {
2286 /* Create the page but don't show it */
2287 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
2288 }
2289
2290 /*
2291 * Add a new tab to the tab control.
2292 */
2293 item.mask = TCIF_TEXT;
2294 item.pszText = (LPWSTR) psInfo->proppage[psInfo->nPages].pszText;
2295 item.cchTextMax = MAX_TABTEXT_LENGTH;
2296
2297 if (psInfo->hImageList)
2298 {
2299 SendMessageW(hwndTabControl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
2300 }
2301
2302 if ( psInfo->proppage[psInfo->nPages].hasIcon )
2303 {
2304 item.mask |= TCIF_IMAGE;
2305 item.iImage = psInfo->nPages;
2306 }
2307
2308 SendMessageW(hwndTabControl, TCM_INSERTITEMW, psInfo->nPages + 1,
2309 (LPARAM)&item);
2310
2311 psInfo->nPages++;
2312
2313 /* If it is the only page - show it */
2314 if(psInfo->nPages == 1)
2315 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
2316 return TRUE;
2317 }
2318
2319 /******************************************************************************
2320 * PROPSHEET_RemovePage
2321 */
2322 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
2323 int index,
2324 HPROPSHEETPAGE hpage)
2325 {
2326 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2327 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
2328 PropPageInfo* oldPages;
2329
2330 TRACE("index %d, hpage %p\n", index, hpage);
2331 if (!psInfo) {
2332 return FALSE;
2333 }
2334 /*
2335 * hpage takes precedence over index.
2336 */
2337 if (hpage != 0)
2338 {
2339 index = PROPSHEET_GetPageIndex(hpage, psInfo);
2340 }
2341
2342 /* Make sure that index is within range */
2343 if (index < 0 || index >= psInfo->nPages)
2344 {
2345 TRACE("Could not find page to remove!\n");
2346 return FALSE;
2347 }
2348
2349 TRACE("total pages %d removing page %d active page %d\n",
2350 psInfo->nPages, index, psInfo->active_page);
2351 /*
2352 * Check if we're removing the active page.
2353 */
2354 if (index == psInfo->active_page)
2355 {
2356 if (psInfo->nPages > 1)
2357 {
2358 if (index > 0)
2359 {
2360 /* activate previous page */
2361 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
2362 }
2363 else
2364 {
2365 /* activate the next page */
2366 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
2367 psInfo->active_page = index;
2368 }
2369 }
2370 else
2371 {
2372 psInfo->active_page = -1;
2373 if (!psInfo->isModeless)
2374 {
2375 psInfo->ended = TRUE;
2376 return TRUE;
2377 }
2378 }
2379 }
2380 else if (index < psInfo->active_page)
2381 psInfo->active_page--;
2382
2383 /* Unsubclass the page dialog window */
2384 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD) &&
2385 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2386 ((PROPSHEETPAGEW*)psInfo->proppage[index].hpage)->dwFlags & PSP_HIDEHEADER))
2387 {
2388 RemoveWindowSubclass(psInfo->proppage[index].hwndPage,
2389 PROPSHEET_WizardSubclassProc, 1);
2390 }
2391
2392 /* Destroy page dialog window */
2393 DestroyWindow(psInfo->proppage[index].hwndPage);
2394
2395 /* Free page resources */
2396 if(psInfo->proppage[index].hpage)
2397 {
2398 PROPSHEETPAGEW* psp = (PROPSHEETPAGEW*)psInfo->proppage[index].hpage;
2399
2400 if (psp->dwFlags & PSP_USETITLE)
2401 Free ((LPVOID)psInfo->proppage[index].pszText);
2402
2403 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2404 }
2405
2406 /* Remove the tab */
2407 SendMessageW(hwndTabControl, TCM_DELETEITEM, index, 0);
2408
2409 oldPages = psInfo->proppage;
2410 psInfo->nPages--;
2411 psInfo->proppage = Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2412
2413 if (index > 0)
2414 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2415
2416 if (index < psInfo->nPages)
2417 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2418 (psInfo->nPages - index) * sizeof(PropPageInfo));
2419
2420 Free(oldPages);
2421
2422 return FALSE;
2423 }
2424
2425 BOOL CALLBACK
2426 EnumChildProc(HWND hwnd, LPARAM lParam)
2427 {
2428 WCHAR szType[20];
2429 RealGetWindowClassW(hwnd, szType, 20);
2430
2431 if (strcmpW(szType, WC_EDITW) == 0)
2432 {
2433 if (IsWindowEnabled(hwnd) && IsWindowVisible(hwnd))
2434 {
2435 SetFocus(hwnd);
2436 return FALSE;
2437 }
2438 }
2439 else
2440 {
2441 EnumChildWindows(hwnd, EnumChildProc, 0);
2442 }
2443
2444 return TRUE;
2445 }
2446
2447 /******************************************************************************
2448 * PROPSHEET_SetWizButtons
2449 *
2450 * This code will work if (and assumes that) the Next button is on top of the
2451 * Finish button. ie. Finish comes after Next in the Z order.
2452 * This means make sure the dialog template reflects this.
2453 *
2454 */
2455 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2456 {
2457 PropSheetInfo* psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2458 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2459 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2460 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2461
2462 TRACE("%d\n", dwFlags);
2463
2464 EnableWindow(hwndBack, FALSE);
2465 EnableWindow(hwndNext, FALSE);
2466 EnableWindow(hwndFinish, FALSE);
2467
2468 if (dwFlags & PSWIZB_BACK)
2469 EnableWindow(hwndBack, TRUE);
2470
2471 if (dwFlags & PSWIZB_NEXT)
2472 EnableWindow(hwndNext, TRUE);
2473
2474 if (!psInfo->hasFinish)
2475 {
2476 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2477 {
2478 /* Hide the Next button */
2479 ShowWindow(hwndNext, SW_HIDE);
2480
2481 /* Show the Finish button */
2482 ShowWindow(hwndFinish, SW_SHOW);
2483
2484 if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2485 EnableWindow(hwndFinish, TRUE);
2486 }
2487 else
2488 {
2489 /* Hide the Finish button */
2490 ShowWindow(hwndFinish, SW_HIDE);
2491 /* Show the Next button */
2492 ShowWindow(hwndNext, SW_SHOW);
2493 }
2494 }
2495 else if (!(dwFlags & PSWIZB_DISABLEDFINISH))
2496 EnableWindow(hwndFinish, TRUE);
2497
2498 /* set the default pushbutton to an enabled button and give it focus */
2499 if (((dwFlags & PSWIZB_FINISH) || psInfo->hasFinish) && !(dwFlags & PSWIZB_DISABLEDFINISH))
2500 {
2501 SendMessageW(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2502 SetFocus(hwndFinish);
2503 }
2504 else if (dwFlags & PSWIZB_NEXT)
2505 {
2506 SendMessageW(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2507 SetFocus(hwndNext);
2508 }
2509 else if (dwFlags & PSWIZB_BACK)
2510 {
2511 SendMessageW(hwndDlg, DM_SETDEFID, IDC_BACK_BUTTON, 0);
2512 SetFocus(hwndBack);
2513 }
2514 else
2515 {
2516 SendMessageW(hwndDlg, DM_SETDEFID, IDCANCEL, 0);
2517 SetFocus(GetDlgItem(hwndDlg, IDCANCEL));
2518 }
2519
2520 /* Now try to find an edit control that deserves focus */
2521 EnumChildWindows(PropSheet_GetCurrentPageHwnd(hwndDlg), EnumChildProc, 0);
2522 }
2523
2524 /******************************************************************************
2525 * PROPSHEET_InsertPage
2526 */
2527 static BOOL PROPSHEET_InsertPage(HWND hwndDlg, HPROPSHEETPAGE hpageInsertAfter, HPROPSHEETPAGE hpage)
2528 {
2529 if (!HIWORD(hpageInsertAfter))
2530 FIXME("(%p, %d, %p): stub\n", hwndDlg, LOWORD(hpageInsertAfter), hpage);
2531 else
2532 FIXME("(%p, %p, %p): stub\n", hwndDlg, hpageInsertAfter, hpage);
2533 return FALSE;
2534 }
2535
2536 /******************************************************************************
2537 * PROPSHEET_SetHeaderTitleW
2538 */
2539 static void PROPSHEET_SetHeaderTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderTitle)
2540 {
2541 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderTitle));
2542 }
2543
2544 /******************************************************************************
2545 * PROPSHEET_SetHeaderTitleA
2546 */
2547 static void PROPSHEET_SetHeaderTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderTitle)
2548 {
2549 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderTitle));
2550 }
2551
2552 /******************************************************************************
2553 * PROPSHEET_SetHeaderSubTitleW
2554 */
2555 static void PROPSHEET_SetHeaderSubTitleW(HWND hwndDlg, int iPageIndex, LPCWSTR pszHeaderSubTitle)
2556 {
2557 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_w(pszHeaderSubTitle));
2558 }
2559
2560 /******************************************************************************
2561 * PROPSHEET_SetHeaderSubTitleA
2562 */
2563 static void PROPSHEET_SetHeaderSubTitleA(HWND hwndDlg, int iPageIndex, LPCSTR pszHeaderSubTitle)
2564 {
2565 FIXME("(%p, %d, %s): stub\n", hwndDlg, iPageIndex, debugstr_a(pszHeaderSubTitle));
2566 }
2567
2568 /******************************************************************************
2569 * PROPSHEET_HwndToIndex
2570 */
2571 static LRESULT PROPSHEET_HwndToIndex(HWND hwndDlg, HWND hPageDlg)
2572 {
2573 int index;
2574 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2575
2576 TRACE("(%p, %p)\n", hwndDlg, hPageDlg);
2577
2578 for (index = 0; index < psInfo->nPages; index++)
2579 if (psInfo->proppage[index].hwndPage == hPageDlg)
2580 return index;
2581 WARN("%p not found\n", hPageDlg);
2582 return -1;
2583 }
2584
2585 /******************************************************************************
2586 * PROPSHEET_IndexToHwnd
2587 */
2588 static LRESULT PROPSHEET_IndexToHwnd(HWND hwndDlg, int iPageIndex)
2589 {
2590 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2591 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2592 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2593 WARN("%d out of range.\n", iPageIndex);
2594 return 0;
2595 }
2596 return (LRESULT)psInfo->proppage[iPageIndex].hwndPage;
2597 }
2598
2599 /******************************************************************************
2600 * PROPSHEET_PageToIndex
2601 */
2602 static LRESULT PROPSHEET_PageToIndex(HWND hwndDlg, HPROPSHEETPAGE hPage)
2603 {
2604 int index;
2605 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2606
2607 TRACE("(%p, %p)\n", hwndDlg, hPage);
2608
2609 for (index = 0; index < psInfo->nPages; index++)
2610 if (psInfo->proppage[index].hpage == hPage)
2611 return index;
2612 WARN("%p not found\n", hPage);
2613 return -1;
2614 }
2615
2616 /******************************************************************************
2617 * PROPSHEET_IndexToPage
2618 */
2619 static LRESULT PROPSHEET_IndexToPage(HWND hwndDlg, int iPageIndex)
2620 {
2621 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2622 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2623 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2624 WARN("%d out of range.\n", iPageIndex);
2625 return 0;
2626 }
2627 return (LRESULT)psInfo->proppage[iPageIndex].hpage;
2628 }
2629
2630 /******************************************************************************
2631 * PROPSHEET_IdToIndex
2632 */
2633 static LRESULT PROPSHEET_IdToIndex(HWND hwndDlg, int iPageId)
2634 {
2635 int index;
2636 LPCPROPSHEETPAGEW psp;
2637 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2638 TRACE("(%p, %d)\n", hwndDlg, iPageId);
2639 for (index = 0; index < psInfo->nPages; index++) {
2640 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[index].hpage;
2641 if (psp->u.pszTemplate == MAKEINTRESOURCEW(iPageId))
2642 return index;
2643 }
2644
2645 return -1;
2646 }
2647
2648 /******************************************************************************
2649 * PROPSHEET_IndexToId
2650 */
2651 static LRESULT PROPSHEET_IndexToId(HWND hwndDlg, int iPageIndex)
2652 {
2653 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2654 LPCPROPSHEETPAGEW psp;
2655 TRACE("(%p, %d)\n", hwndDlg, iPageIndex);
2656 if (iPageIndex<0 || iPageIndex>=psInfo->nPages) {
2657 WARN("%d out of range.\n", iPageIndex);
2658 return 0;
2659 }
2660 psp = (LPCPROPSHEETPAGEW)psInfo->proppage[iPageIndex].hpage;
2661 if (psp->dwFlags & PSP_DLGINDIRECT || HIWORD(psp->u.pszTemplate)) {
2662 return 0;
2663 }
2664 return (LRESULT)psp->u.pszTemplate;
2665 }
2666
2667 /******************************************************************************
2668 * PROPSHEET_GetResult
2669 */
2670 static LRESULT PROPSHEET_GetResult(HWND hwndDlg)
2671 {
2672 PropSheetInfo * psInfo = GetPropW(hwndDlg, PropSheetInfoStr);
2673 return psInfo->result;
2674 }
2675
2676 /******************************************************************************
2677 * PROPSHEET_RecalcPageSizes
2678 */
2679 static BOOL PROPSHEET_RecalcPageSizes(HWND hwndDlg)
2680 {
2681 FIXME("(%p): stub\n", hwndDlg);
2682 return FALSE;
2683 }
2684
2685 /******************************************************************************
2686 * PROPSHEET_GetPageIndex
2687 *
2688 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2689 * the array of PropPageInfo.
2690 */
2691 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, const PropSheetInfo* psInfo)
2692 {
2693 BOOL found = FALSE;
2694 int index = 0;
2695
2696 TRACE("hpage %p\n", hpage);
2697 while ((index < psInfo->nPages) && (found == FALSE))
2698 {
2699 if (psInfo->proppage[index].hpage == hpage)
2700 found = TRUE;
2701 else
2702 index++;
2703 }
2704
2705 if (found == FALSE)
2706 index = -1;
2707
2708 return index;
2709 }
2710
2711 /******************************************************************************
2712 * PROPSHEET_CleanUp
2713 */
2714 static void PROPSHEET_CleanUp(HWND hwndDlg)
2715 {
2716 int i;
2717 PropSheetInfo* psInfo = RemovePropW(hwndDlg, PropSheetInfoStr);
2718
2719 TRACE("\n");
2720 if (!psInfo) return;
2721 if (HIWORD(psInfo->ppshheader.pszCaption))
2722 Free ((LPVOID)psInfo->ppshheader.pszCaption);
2723
2724 for (i = 0; i < psInfo->nPages; i++)
2725 {
2726 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2727
2728 /* Unsubclass the page dialog window */
2729 if((psInfo->ppshheader.dwFlags & (PSH_WIZARD97_NEW | PSH_WIZARD97_OLD)) &&
2730 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2731 (psp->dwFlags & PSP_HIDEHEADER))
2732 {
2733 RemoveWindowSubclass(psInfo->proppage[i].hwndPage,
2734 PROPSHEET_WizardSubclassProc, 1);
2735 }
2736
2737 if(psInfo->proppage[i].hwndPage)
2738 DestroyWindow(psInfo->proppage[i].hwndPage);
2739
2740 if(psp)
2741 {
2742 if (psp->dwFlags & PSP_USETITLE)
2743 Free ((LPVOID)psInfo->proppage[i].pszText);
2744
2745 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2746 }
2747 }
2748
2749 DeleteObject(psInfo->hFont);
2750 DeleteObject(psInfo->hFontBold);
2751 /* If we created the bitmaps, destroy them */
2752 if ((psInfo->ppshheader.dwFlags & PSH_WATERMARK) &&
2753 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMWATERMARK)) )
2754 DeleteObject(psInfo->ppshheader.u4.hbmWatermark);
2755 if ((psInfo->ppshheader.dwFlags & PSH_HEADER) &&
2756 (!(psInfo->ppshheader.dwFlags & PSH_USEHBMHEADER)) )
2757 DeleteObject(psInfo->ppshheader.u5.hbmHeader);
2758
2759 Free(psInfo->proppage);
2760 Free(psInfo->strPropertiesFor);
2761 ImageList_Destroy(psInfo->hImageList);
2762
2763 GlobalFree(psInfo);
2764 }
2765
2766 static INT do_loop(const PropSheetInfo *psInfo)
2767 {
2768 MSG msg;
2769 INT ret = -1;
2770 HWND hwnd = psInfo->hwnd;
2771
2772 while(IsWindow(hwnd) && !psInfo->ended && (ret = GetMessageW(&msg, NULL, 0, 0)))
2773 {
2774 if(ret == -1)
2775 break;
2776
2777 if(!IsDialogMessageW(hwnd, &msg))
2778 {
2779 TranslateMessage(&msg);
2780 DispatchMessageW(&msg);
2781 }
2782 }
2783
2784 if(ret == 0)
2785 {
2786 PostQuitMessage(msg.wParam);
2787 ret = -1;
2788 }
2789
2790 if(ret != -1)
2791 ret = psInfo->result;
2792
2793 DestroyWindow(hwnd);
2794 return ret;
2795 }
2796
2797 /******************************************************************************
2798 * PROPSHEET_PropertySheet
2799 *
2800 * Common code between PropertySheetA/W
2801 */
2802 static INT_PTR PROPSHEET_PropertySheet(PropSheetInfo* psInfo, BOOL unicode)
2803 {
2804 INT_PTR bRet = 0;
2805 HWND parent = NULL;
2806 if (psInfo->active_page >= psInfo->nPages) psInfo->active_page = 0;
2807 TRACE("startpage: %d of %d pages\n", psInfo->active_page, psInfo->nPages);
2808
2809 psInfo->unicode = unicode;
2810 psInfo->ended = FALSE;
2811
2812 if(!psInfo->isModeless)
2813 {
2814 parent = psInfo->ppshheader.hwndParent;
2815 if (parent) EnableWindow(parent, FALSE);
2816 }
2817 bRet = PROPSHEET_CreateDialog(psInfo);
2818 if(!psInfo->isModeless)
2819 {
2820 bRet = do_loop(psInfo);
2821 if (parent) EnableWindow(parent, TRUE);
2822 }
2823 return bRet;
2824 }
2825
2826 /******************************************************************************
2827 * PropertySheet (COMCTL32.@)
2828 * PropertySheetA (COMCTL32.@)
2829 *
2830 * Creates a property sheet in the specified property sheet header.
2831 *
2832 * RETURNS
2833 * Modal property sheets: Positive if successful or -1 otherwise.
2834 * Modeless property sheets: Property sheet handle.
2835 * Or:
2836 *| ID_PSREBOOTSYSTEM - The user must reboot the computer for the changes to take effect.
2837 *| ID_PSRESTARTWINDOWS - The user must restart Windows for the changes to take effect.
2838 */
2839 INT_PTR WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2840 {
2841 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2842 UINT i, n;
2843 const BYTE* pByte;
2844
2845 TRACE("(%p)\n", lppsh);
2846
2847 PROPSHEET_CollectSheetInfoA(lppsh, psInfo);
2848
2849 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2850 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2851
2852 for (n = i = 0; i < lppsh->nPages; i++, n++)
2853 {
2854 if (!psInfo->usePropPage)
2855 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2856 else
2857 {
2858 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2859 pByte += ((LPCPROPSHEETPAGEA)pByte)->dwSize;
2860 }
2861
2862 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2863 psInfo, n, TRUE))
2864 {
2865 if (psInfo->usePropPage)
2866 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2867 n--;
2868 psInfo->nPages--;
2869 }
2870 }
2871
2872 return PROPSHEET_PropertySheet(psInfo, FALSE);
2873 }
2874
2875 /******************************************************************************
2876 * PropertySheetW (COMCTL32.@)
2877 *
2878 * See PropertySheetA.
2879 */
2880 INT_PTR WINAPI PropertySheetW(LPCPROPSHEETHEADERW lppsh)
2881 {
2882 PropSheetInfo* psInfo = GlobalAlloc(GPTR, sizeof(PropSheetInfo));
2883 UINT i, n;
2884 const BYTE* pByte;
2885
2886 TRACE("(%p)\n", lppsh);
2887
2888 PROPSHEET_CollectSheetInfoW(lppsh, psInfo);
2889
2890 psInfo->proppage = Alloc(sizeof(PropPageInfo) * lppsh->nPages);
2891 pByte = (const BYTE*) psInfo->ppshheader.u3.ppsp;
2892
2893 for (n = i = 0; i < lppsh->nPages; i++, n++)
2894 {
2895 if (!psInfo->usePropPage)
2896 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
2897 else
2898 {
2899 psInfo->proppage[n].hpage = CreatePropertySheetPageW((LPCPROPSHEETPAGEW)pByte);
2900 pByte += ((LPCPROPSHEETPAGEW)pByte)->dwSize;
2901 }
2902
2903 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEW)psInfo->proppage[n].hpage,
2904 psInfo, n, TRUE))
2905 {
2906 if (psInfo->usePropPage)
2907 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
2908 n--;
2909 psInfo->nPages--;
2910 }
2911 }
2912
2913 return PROPSHEET_PropertySheet(psInfo, TRUE);
2914 }
2915
2916 static LPWSTR load_string( HINSTANCE instance, LPCWSTR str )
2917 {
2918 LPWSTR ret;
2919
2920 if (IS_INTRESOURCE(str))
2921 {
2922 HRSRC hrsrc;
2923 HGLOBAL hmem;
2924 WCHAR *ptr;
2925 WORD i, id = LOWORD(str);
2926 UINT len;
2927
2928 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((id >> 4) + 1), (LPWSTR)RT_STRING )))
2929 return NULL;
2930 if (!(hmem = LoadResource( instance, hrsrc ))) return NULL;
2931 if (!(ptr = LockResource( hmem ))) return NULL;
2932 for (i = id & 0x0f; i > 0; i--) ptr += *ptr + 1;
2933 len = *ptr;
2934 if (!len) return NULL;
2935 ret = Alloc( (len + 1) * sizeof(WCHAR) );
2936 if (ret)
2937 {
2938 memcpy( ret, ptr + 1, len * sizeof(WCHAR) );
2939 ret[len] = 0;
2940 }
2941 }
2942 else
2943 {
2944 int len = (strlenW(str) + 1) * sizeof(WCHAR);
2945 ret = Alloc( len );
2946 if (ret) memcpy( ret, str, len );
2947 }
2948 return ret;
2949 }
2950
2951
2952 /******************************************************************************
2953 * CreatePropertySheetPage (COMCTL32.@)
2954 * CreatePropertySheetPageA (COMCTL32.@)
2955 *
2956 * Creates a new property sheet page.
2957 *
2958 * RETURNS
2959 * Success: Handle to new property sheet page.
2960 * Failure: NULL.
2961 *
2962 * NOTES
2963 * An application must use the PSM_ADDPAGE message to add the new page to
2964 * an existing property sheet.
2965 */
2966 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2967 LPCPROPSHEETPAGEA lpPropSheetPage)
2968 {
2969 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
2970
2971 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2972
2973 ppsp->dwFlags &= ~ PSP_INTERNAL_UNICODE;
2974
2975 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
2976 {
2977 if (HIWORD( ppsp->u.pszTemplate ))
2978 {
2979 int len = strlen(lpPropSheetPage->u.pszTemplate) + 1;
2980 char *template = Alloc( len );
2981
2982 ppsp->u.pszTemplate = (LPWSTR)strcpy( template, lpPropSheetPage->u.pszTemplate );
2983 }
2984 }
2985
2986 if (ppsp->dwFlags & PSP_USEICONID)
2987 {
2988 if (HIWORD( ppsp->u2.pszIcon ))
2989 PROPSHEET_AtoW(&ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon);
2990 }
2991
2992 if (ppsp->dwFlags & PSP_USETITLE)
2993 {
2994 if (HIWORD( ppsp->pszTitle ))
2995 PROPSHEET_AtoW( &ppsp->pszTitle, lpPropSheetPage->pszTitle );
2996 else
2997 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
2998 }
2999 else
3000 ppsp->pszTitle = NULL;
3001
3002 if (ppsp->dwFlags & PSP_HIDEHEADER)
3003 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3004
3005 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3006 {
3007 if (HIWORD( ppsp->pszHeaderTitle ))
3008 PROPSHEET_AtoW(&ppsp->pszHeaderTitle, lpPropSheetPage->pszHeaderTitle);
3009 else
3010 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3011 }
3012 else
3013 ppsp->pszHeaderTitle = NULL;
3014
3015 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3016 {
3017 if (HIWORD( ppsp->pszHeaderSubTitle ))
3018 PROPSHEET_AtoW(&ppsp->pszHeaderSubTitle, lpPropSheetPage->pszHeaderSubTitle);
3019 else
3020 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3021 }
3022 else
3023 ppsp->pszHeaderSubTitle = NULL;
3024
3025 return (HPROPSHEETPAGE)ppsp;
3026 }
3027
3028 /******************************************************************************
3029 * CreatePropertySheetPageW (COMCTL32.@)
3030 *
3031 * See CreatePropertySheetA.
3032 */
3033 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
3034 {
3035 PROPSHEETPAGEW* ppsp = Alloc(sizeof(PROPSHEETPAGEW));
3036
3037 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEW)));
3038
3039 ppsp->dwFlags |= PSP_INTERNAL_UNICODE;
3040
3041 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) )
3042 {
3043 if (HIWORD( ppsp->u.pszTemplate ))
3044 {
3045 int len = strlenW(lpPropSheetPage->u.pszTemplate) + 1;
3046 WCHAR *template = Alloc( len * sizeof (WCHAR) );
3047
3048 ppsp->u.pszTemplate = strcpyW( template, lpPropSheetPage->u.pszTemplate );
3049 }
3050 }
3051
3052 if ( ppsp->dwFlags & PSP_USEICONID )
3053 {
3054 if (HIWORD( ppsp->u2.pszIcon ))
3055 {
3056 int len = strlenW(lpPropSheetPage->u2.pszIcon) + 1;
3057 WCHAR *icon = Alloc( len * sizeof (WCHAR) );
3058
3059 ppsp->u2.pszIcon = strcpyW( icon, lpPropSheetPage->u2.pszIcon );
3060 }
3061 }
3062
3063 if (ppsp->dwFlags & PSP_USETITLE)
3064 ppsp->pszTitle = load_string( ppsp->hInstance, ppsp->pszTitle );
3065 else
3066 ppsp->pszTitle = NULL;
3067
3068 if (ppsp->dwFlags & PSP_HIDEHEADER)
3069 ppsp->dwFlags &= ~(PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE);
3070
3071 if (ppsp->dwFlags & PSP_USEHEADERTITLE)
3072 ppsp->pszHeaderTitle = load_string( ppsp->hInstance, ppsp->pszHeaderTitle );
3073 else
3074 ppsp->pszHeaderTitle = NULL;
3075
3076 if (ppsp->dwFlags & PSP_USEHEADERSUBTITLE)
3077 ppsp->pszHeaderSubTitle = load_string( ppsp->hInstance, ppsp->pszHeaderSubTitle );
3078 else
3079 ppsp->pszHeaderSubTitle = NULL;
3080
3081 return (HPROPSHEETPAGE)ppsp;
3082 }
3083
3084 /******************************************************************************
3085 * DestroyPropertySheetPage (COMCTL32.@)
3086 *
3087 * Destroys a property sheet page previously created with
3088 * CreatePropertySheetA() or CreatePropertySheetW() and frees the associated
3089 * memory.
3090 *
3091 * RETURNS
3092 * Success: TRUE
3093 * Failure: FALSE
3094 */
3095 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
3096 {
3097 PROPSHEETPAGEW *psp = (PROPSHEETPAGEW *)hPropPage;
3098
3099 if (!psp)
3100 return FALSE;
3101
3102 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
3103 Free ((LPVOID)psp->u.pszTemplate);
3104
3105 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
3106 Free ((LPVOID)psp->u2.pszIcon);
3107
3108 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
3109 Free ((LPVOID)psp->pszTitle);
3110
3111 Free(hPropPage);
3112
3113 return TRUE;
3114 }
3115
3116 /******************************************************************************
3117 * PROPSHEET_IsDialogMessage
3118 */
3119 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
3120 {
3121 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3122
3123 TRACE("\n");
3124 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
3125 return FALSE;
3126
3127 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
3128 {
3129 int new_page = 0;
3130 INT dlgCode = SendMessageW(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
3131
3132 if (!(dlgCode & DLGC_WANTMESSAGE))
3133 {
3134 switch (lpMsg->wParam)
3135 {
3136 case VK_TAB:
3137 if (GetKeyState(VK_SHIFT) & 0x8000)
3138 new_page = -1;
3139 else
3140 new_page = 1;
3141 break;
3142
3143 case VK_NEXT: new_page = 1; break;
3144 case VK_PRIOR: new_page = -1; break;
3145 }
3146 }
3147
3148 if (new_page)
3149 {
3150 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
3151 {
3152 new_page += psInfo->active_page;
3153
3154 if (new_page < 0)
3155 new_page = psInfo->nPages - 1;
3156 else if (new_page >= psInfo->nPages)
3157 new_page = 0;
3158
3159 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
3160 }
3161
3162 return TRUE;
3163 }
3164 }
3165
3166 return IsDialogMessageW(hwnd, lpMsg);
3167 }
3168
3169 /******************************************************************************
3170 * PROPSHEET_DoCommand
3171 */
3172 static BOOL PROPSHEET_DoCommand(HWND hwnd, WORD wID)
3173 {
3174
3175 switch (wID) {
3176
3177 case IDOK:
3178 case IDC_APPLY_BUTTON:
3179 {
3180 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
3181
3182 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
3183 break;
3184
3185 if (wID == IDOK)
3186 {
3187 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3188
3189 /* don't overwrite ID_PSRESTARTWINDOWS or ID_PSREBOOTSYSTEM */
3190 if (psInfo->result == 0)
3191 psInfo->result = IDOK;
3192
3193 if (psInfo->isModeless)
3194 psInfo->activeValid = FALSE;
3195 else
3196 psInfo->ended = TRUE;
3197 }
3198 else
3199 EnableWindow(hwndApplyBtn, FALSE);
3200
3201 break;
3202 }
3203
3204 case IDC_BACK_BUTTON:
3205 PROPSHEET_Back(hwnd);
3206 break;
3207
3208 case IDC_NEXT_BUTTON:
3209 PROPSHEET_Next(hwnd);
3210 break;
3211
3212 case IDC_FINISH_BUTTON:
3213 PROPSHEET_Finish(hwnd);
3214 break;
3215
3216 case IDCANCEL:
3217 PROPSHEET_Cancel(hwnd, 0);
3218 break;
3219
3220 case IDHELP:
3221 PROPSHEET_Help(hwnd);
3222 break;
3223
3224 default:
3225 return FALSE;
3226 }
3227
3228 return TRUE;
3229 }
3230
3231 /******************************************************************************
3232 * PROPSHEET_Paint
3233 */
3234 static LRESULT PROPSHEET_Paint(HWND hwnd, HDC hdcParam)
3235 {
3236 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3237 PAINTSTRUCT ps;
3238 HDC hdc, hdcSrc;
3239 BITMAP bm;
3240 HBITMAP hbmp;
3241 HPALETTE hOldPal = 0;
3242 int offsety = 0;
3243 HBRUSH hbr;
3244 RECT r, rzone;
3245 LPCPROPSHEETPAGEW ppshpage;
3246 WCHAR szBuffer[256];
3247 int nLength;
3248
3249 if (psInfo->active_page < 0) return 1;
3250 hdc = hdcParam ? hdcParam : BeginPaint(hwnd, &ps);
3251 if (!hdc) return 1;
3252
3253 hdcSrc = CreateCompatibleDC(0);
3254 ppshpage = (LPCPROPSHEETPAGEW)psInfo->proppage[psInfo->active_page].hpage;
3255
3256 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3257 hOldPal = SelectPalette(hdc, psInfo->ppshheader.hplWatermark, FALSE);
3258
3259 if ( (!(ppshpage->dwFlags & PSP_HIDEHEADER)) &&
3260 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3261 (psInfo->ppshheader.dwFlags & PSH_HEADER) )
3262 {
3263 HWND hwndLineHeader = GetDlgItem(hwnd, IDC_SUNKEN_LINEHEADER);
3264 HFONT hOldFont;
3265 COLORREF clrOld = 0;
3266 int oldBkMode = 0;
3267
3268 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u5.hbmHeader);
3269 hOldFont = SelectObject(hdc, psInfo->hFontBold);
3270
3271 GetClientRect(hwndLineHeader, &r);
3272 MapWindowPoints(hwndLineHeader, hwnd, (LPPOINT) &r, 2);
3273 SetRect(&rzone, 0, 0, r.right + 1, r.top - 1);
3274
3275 GetObjectW(psInfo->ppshheader.u5.hbmHeader, sizeof(BITMAP), &bm);
3276
3277 if (psInfo->ppshheader.dwFlags & PSH_WIZARD97_OLD)
3278 {
3279 /* Fill the unoccupied part of the header with color of the
3280 * left-top pixel, but do it only when needed.
3281 */
3282 if (bm.bmWidth < r.right || bm.bmHeight < r.bottom)
3283 {
3284 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3285 CopyRect(&r, &rzone);
3286 if (bm.bmWidth < r.right)
3287 {
3288 r.left = bm.bmWidth;
3289 FillRect(hdc, &r, hbr);
3290 }
3291 if (bm.bmHeight < r.bottom)
3292 {
3293 r.left = 0;
3294 r.top = bm.bmHeight;
3295 FillRect(hdc, &r, hbr);
3296 }
3297 DeleteObject(hbr);
3298 }
3299
3300 /* Draw the header itself. */
3301 BitBlt(hdc, 0, 0,
3302 bm.bmWidth, min(bm.bmHeight, rzone.bottom),
3303 hdcSrc, 0, 0, SRCCOPY);
3304 }
3305 else
3306 {
3307 int margin;
3308 hbr = GetSysColorBrush(COLOR_WINDOW);
3309 FillRect(hdc, &rzone, hbr);
3310
3311 /* Draw the header bitmap. It's always centered like a
3312 * common 49 x 49 bitmap. */
3313 margin = (rzone.bottom - 49) / 2;
3314 BitBlt(hdc, rzone.right - 49 - margin, margin,
3315 min(bm.bmWidth, 49), min(bm.bmHeight, 49),
3316 hdcSrc, 0, 0, SRCCOPY);
3317
3318 /* NOTE: Native COMCTL32 draws a white stripe over the bitmap
3319 * if its height is smaller than 49 pixels. Because the reason
3320 * for this bug is unknown the current code doesn't try to
3321 * replicate it. */
3322 }
3323
3324 clrOld = SetTextColor (hdc, 0x00000000);
3325 oldBkMode = SetBkMode (hdc, TRANSPARENT);
3326
3327 if (ppshpage->dwFlags & PSP_USEHEADERTITLE) {
3328 SetRect(&r, 20, 10, 0, 0);
3329 if (HIWORD(ppshpage->pszHeaderTitle))
3330 DrawTextW(hdc, ppshpage->pszHeaderTitle, -1, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3331 else
3332 {
3333 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderTitle,
3334 szBuffer, 256);
3335 if (nLength != 0)
3336 {
3337 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_SINGLELINE | DT_NOCLIP);
3338 }
3339 }
3340 }
3341
3342 if (ppshpage->dwFlags & PSP_USEHEADERSUBTITLE) {
3343 SelectObject(hdc, psInfo->hFont);
3344 SetRect(&r, 40, 25, rzone.right - 69, rzone.bottom);
3345 if (HIWORD(ppshpage->pszHeaderTitle))
3346 DrawTextW(hdc, ppshpage->pszHeaderSubTitle, -1, &r, DT_LEFT | DT_WORDBREAK);
3347 else
3348 {
3349 nLength = LoadStringW(ppshpage->hInstance, (UINT_PTR)ppshpage->pszHeaderSubTitle,
3350 szBuffer, 256);
3351 if (nLength != 0)
3352 {
3353 DrawTextW(hdc, szBuffer, nLength, &r, DT_LEFT | DT_WORDBREAK);
3354 }
3355 }
3356 }
3357
3358 offsety = rzone.bottom + 2;
3359
3360 SetTextColor(hdc, clrOld);
3361 SetBkMode(hdc, oldBkMode);
3362 SelectObject(hdc, hOldFont);
3363 SelectObject(hdcSrc, hbmp);
3364 }
3365
3366 if ( (ppshpage->dwFlags & PSP_HIDEHEADER) &&
3367 (psInfo->ppshheader.dwFlags & (PSH_WIZARD97_OLD | PSH_WIZARD97_NEW)) &&
3368 (psInfo->ppshheader.dwFlags & PSH_WATERMARK) )
3369 {
3370 HWND hwndLine = GetDlgItem(hwnd, IDC_SUNKEN_LINE);
3371
3372 GetClientRect(hwndLine, &r);
3373 MapWindowPoints(hwndLine, hwnd, (LPPOINT) &r, 2);
3374
3375 rzone.left = 0;
3376 rzone.top = 0;
3377 rzone.right = r.right;
3378 rzone.bottom = r.top - 1;
3379
3380 hbr = GetSysColorBrush(COLOR_WINDOW);
3381 FillRect(hdc, &rzone, hbr);
3382
3383 GetObjectW(psInfo->ppshheader.u4.hbmWatermark, sizeof(BITMAP), &bm);
3384 hbmp = SelectObject(hdcSrc, psInfo->ppshheader.u4.hbmWatermark);
3385
3386 /* The watermark is truncated to a width of 164 pixels */
3387 r.right = min(r.right, 164);
3388 BitBlt(hdc, 0, offsety, min(bm.bmWidth, r.right),
3389 min(bm.bmHeight, r.bottom), hdcSrc, 0, 0, SRCCOPY);
3390
3391 /* If the bitmap is not big enough, fill the remaining area
3392 with the color of pixel (0,0) of bitmap - see MSDN */
3393 if (r.top > bm.bmHeight) {
3394 r.bottom = r.top - 1;
3395 r.top = bm.bmHeight;
3396 r.left = 0;
3397 r.right = bm.bmWidth;
3398 hbr = CreateSolidBrush(GetPixel(hdcSrc, 0, 0));
3399 FillRect(hdc, &r, hbr);
3400 DeleteObject(hbr);
3401 }
3402
3403 SelectObject(hdcSrc, hbmp);
3404 }
3405
3406 if (psInfo->ppshheader.dwFlags & PSH_USEHPLWATERMARK)
3407 SelectPalette(hdc, hOldPal, FALSE);
3408
3409 DeleteDC(hdcSrc);
3410
3411 if (!hdcParam) EndPaint(hwnd, &ps);
3412
3413 return 0;
3414 }
3415
3416 /******************************************************************************
3417 * PROPSHEET_DialogProc
3418 */
3419 static INT_PTR CALLBACK
3420 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3421 {
3422 TRACE("hwnd=%p msg=0x%04x wparam=%lx lparam=%lx\n",
3423 hwnd, uMsg, wParam, lParam);
3424
3425 switch (uMsg)
3426 {
3427 case WM_INITDIALOG:
3428 {
3429 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
3430 WCHAR* strCaption = Alloc(MAX_CAPTION_LENGTH*sizeof(WCHAR));
3431 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3432 int idx;
3433 LOGFONTW logFont;
3434
3435 /* Using PropSheetInfoStr to store extra data doesn't match the native
3436 * common control: native uses TCM_[GS]ETITEM
3437 */
3438 SetPropW(hwnd, PropSheetInfoStr, psInfo);
3439
3440 /*
3441 * psInfo->hwnd is not being used by WINE code - it exists
3442 * for compatibility with "real" Windoze. The same about
3443 * SetWindowLongPtr - WINE is only using the PropSheetInfoStr
3444 * property.
3445 */
3446 psInfo->hwnd = hwnd;
3447 SetWindowLongPtrW(hwnd, DWLP_USER, (DWORD_PTR)psInfo);
3448
3449 /* set up the Next and Back buttons by default */
3450 PROPSHEET_SetWizButtons(hwnd, PSWIZB_BACK|PSWIZB_NEXT);
3451 SetFocus(GetDlgItem(hwnd, IDC_NEXT_BUTTON));
3452
3453 /* Set up fonts */
3454 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
3455 psInfo->hFont = CreateFontIndirectW (&logFont);
3456 logFont.lfWeight = FW_BOLD;
3457 psInfo->hFontBold = CreateFontIndirectW (&logFont);
3458
3459 /*
3460 * Small icon in the title bar.
3461 */
3462 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
3463 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
3464 {
3465 HICON hIcon;
3466 int icon_cx = GetSystemMetrics(SM_CXSMICON);
3467 int icon_cy = GetSystemMetrics(SM_CYSMICON);
3468
3469 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
3470 hIcon = LoadImageW(psInfo->ppshheader.hInstance,
3471 psInfo->ppshheader.u.pszIcon,
3472 IMAGE_ICON,
3473 icon_cx, icon_cy,
3474 LR_DEFAULTCOLOR);
3475 else
3476 hIcon = psInfo->ppshheader.u.hIcon;
3477
3478 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)hIcon);
3479 }
3480
3481 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
3482 SendMessageW(hwnd, WM_SETICON, 0, (LPARAM)psInfo->ppshheader.u.hIcon);
3483
3484 psInfo->strPropertiesFor = strCaption;
3485
3486 GetWindowTextW(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
3487
3488 PROPSHEET_CreateTabControl(hwnd, psInfo);
3489
3490 PROPSHEET_LoadWizardBitmaps(psInfo);
3491
3492 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3493 {
3494 ShowWindow(hwndTabCtrl, SW_HIDE);
3495 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
3496 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
3497 }
3498 else
3499 {
3500 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
3501 {
3502 PROPSHEET_AdjustSize(hwnd, psInfo);
3503 PROPSHEET_AdjustButtons(hwnd, psInfo);
3504 }
3505 }
3506
3507 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
3508 psInfo->ppshheader.hInstance)
3509 {
3510 WCHAR szText[256];
3511
3512 if (LoadStringW(psInfo->ppshheader.hInstance,
3513 (UINT_PTR)psInfo->ppshheader.pszCaption, szText, 255))
3514 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags, szText);
3515 }
3516 else
3517 {
3518 PROPSHEET_SetTitleW(hwnd, psInfo->ppshheader.dwFlags,
3519 psInfo->ppshheader.pszCaption);
3520 }
3521
3522
3523 if (psInfo->useCallback)
3524 (*(psInfo->ppshheader.pfnCallback))(hwnd, PSCB_INITIALIZED, 0);
3525
3526 idx = psInfo->active_page;
3527 psInfo->active_page = -1;
3528
3529 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
3530
3531 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
3532 * as some programs call TCM_GETCURSEL to get the current selection
3533 * from which to switch to the next page */
3534 SendMessageW(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
3535
3536 PROPSHEET_UnChanged(hwnd, NULL);
3537
3538 /* wizards set their focus during init */
3539 if (psInfo->ppshheader.dwFlags & INTRNL_ANY_WIZARD)
3540 return FALSE;
3541
3542 return TRUE;
3543 }
3544
3545 case WM_PRINTCLIENT:
3546 case WM_PAINT:
3547 PROPSHEET_Paint(hwnd, (HDC)wParam);
3548 return TRUE;
3549
3550 case WM_DESTROY:
3551 PROPSHEET_CleanUp(hwnd);
3552 return TRUE;
3553
3554 case WM_CLOSE:
3555 PROPSHEET_Cancel(hwnd, 1);
3556 return FALSE; /* let DefDlgProc post us WM_COMMAND/IDCANCEL */
3557
3558 case WM_COMMAND:
3559 if (!PROPSHEET_DoCommand(hwnd, LOWORD(wParam)))
3560 {
3561 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3562
3563 if (!psInfo)
3564 return FALSE;
3565
3566 /* No default handler, forward notification to active page */
3567 if (psInfo->activeValid && psInfo->active_page != -1)
3568 {
3569 HWND hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3570 SendMessageW(hwndPage, WM_COMMAND, wParam, lParam);
3571 }
3572 }
3573 return TRUE;
3574
3575 case WM_NOTIFY:
3576 {
3577 NMHDR* pnmh = (LPNMHDR) lParam;
3578
3579 if (pnmh->code == TCN_SELCHANGE)
3580 {
3581 int index = SendMessageW(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
3582 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
3583 }
3584
3585 if(pnmh->code == TCN_SELCHANGING)
3586 {
3587 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
3588 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, !bRet);
3589 return TRUE;
3590 }
3591
3592 return FALSE;
3593 }
3594
3595 case WM_SYSCOLORCHANGE:
3596 COMCTL32_RefreshSysColors();
3597 return FALSE;
3598
3599 case PSM_GETCURRENTPAGEHWND:
3600 {
3601 PropSheetInfo* psInfo = GetPropW(hwnd, PropSheetInfoStr);
3602 HWND hwndPage = 0;
3603
3604 if (!psInfo)
3605 return FALSE;
3606
3607 if (psInfo->activeValid && psInfo->active_page != -1)
3608 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
3609
3610 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndPage);
3611
3612 return TRUE;
3613 }
3614
3615 case PSM_CHANGED:
3616 PROPSHEET_Changed(hwnd, (HWND)wParam);
3617 return TRUE;
3618
3619 case PSM_UNCHANGED:
3620 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
3621 return TRUE;
3622
3623 case PSM_GETTABCONTROL:
3624 {
3625 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
3626
3627 SetWindowLongPtrW(hwnd, DWLP_MSGRESULT, (DWORD_PTR)hwndTabCtrl);
3628
3629 return TRUE;
3630 }
3631
3632 case PSM_SETCURSEL:
3633 {
3634 BOOL msgResult;
3635
3636 msgResult = PROPSHEET_CanSetCurSel(hwnd);
3637 if(msgResult != FALSE)
3638 {
3639 msgResult = PROPSHEET_SetCurSel(hwnd,
3640 (int)wParam,
3641 1,
3642 (HPROPSHEETPAGE)lParam);
3643 }