source: trunk/src/comctl32/propsheet.cpp@ 7541

Last change on this file since 7541 was 7541, checked in by sandervl, 24 years ago

Hack added for proper resizing of wizard property sheet

File size: 68.7 KB
Line 
1/* $Id: propsheet.cpp,v 1.12 2001-12-04 11:26:26 sandervl Exp $ */
2/*
3 * Property Sheets
4 *
5 * Copyright 1998 Francis Beaudet
6 * Copyright 1999 Thuy Nguyen
7 * Copyright 1999 Achim Hasenmueller
8 * Copyright 1999-2000 Christoph Bratschi
9 *
10 * TODO:
11 * - Tab order
12 * - Unicode property sheets
13 * - Wizard bugs
14 */
15
16/*
17 - Corel WINE 20000807 level
18 - (WINE 991212 level)
19*/
20
21#include <string.h>
22#include "winbase.h"
23#include "commctrl.h"
24#include "prsht.h"
25#include "dialog.h"
26#include "winnls.h"
27#include "comctl32.h"
28#include "heapstring.h"
29#include <debugtools.h>
30
31/******************************************************************************
32 * Data structures
33 */
34typedef struct
35{
36 WORD dlgVer;
37 WORD signature;
38 DWORD helpID;
39 DWORD exStyle;
40 DWORD style;
41} MyDLGTEMPLATEEX;
42
43typedef struct tagPropPageInfo
44{
45 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
46 HWND hwndPage;
47 BOOL isDirty;
48 LPCWSTR pszText;
49 BOOL hasHelp;
50 BOOL useCallback;
51 BOOL hasIcon;
52} PropPageInfo;
53
54typedef struct tagPropSheetInfo
55{
56 LPSTR strPropertiesFor;
57 int nPages;
58 int active_page;
59 LPPROPSHEETHEADERA ppshheader;
60 BOOL isModeless;
61 BOOL hasHelp;
62 BOOL hasApply;
63 BOOL useCallback;
64 BOOL restartWindows;
65 BOOL rebootSystem;
66 BOOL activeValid;
67 PropPageInfo* proppage;
68 int x;
69 int y;
70 int width;
71 int height;
72 HIMAGELIST hImageList;
73} PropSheetInfo;
74
75typedef struct
76{
77 int x;
78 int y;
79} PADDING_INFO;
80
81/******************************************************************************
82 * Defines and global variables
83 */
84
85const char * PropSheetInfoStr = "PropertySheetInfo";
86
87#define MAX_CAPTION_LENGTH 255
88#define MAX_TABTEXT_LENGTH 255
89#define MAX_BUTTONTEXT_LENGTH 64
90
91/******************************************************************************
92 * Prototypes
93 */
94static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
95static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
96static BOOL PROPSHEET_IsTooSmall(HWND hwndDlg, PropSheetInfo* psInfo);
97static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
98static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
99static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
100 PropSheetInfo * psInfo);
101static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
102 PropSheetInfo * psInfo,
103 int index);
104static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
105 PropSheetInfo * psInfo);
106static int PROPSHEET_CreatePage(HWND hwndParent, int index,
107 const PropSheetInfo * psInfo,
108 LPPROPSHEETPAGEA ppshpage);
109static int PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
110static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
111static void PROPSHEET_Back(HWND hwndDlg);
112static void PROPSHEET_Next(HWND hwndDlg);
113static void PROPSHEET_Finish(HWND hwndDlg);
114static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
115static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
116static void PROPSHEET_Help(HWND hwndDlg);
117static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
118static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
119static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
120static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
121static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
122static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
123static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
124 int index,
125 HPROPSHEETPAGE hpage);
126static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
127 WPARAM wParam, LPARAM lParam);
128static BOOL PROPSHEET_AddPage(HWND hwndDlg,
129 HPROPSHEETPAGE hpage);
130
131static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
132 int index,
133 HPROPSHEETPAGE hpage);
134static void PROPSHEET_CleanUp();
135static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
136static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
137static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg,PropSheetInfo* psInfo);
138static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
139static INT PROPSHEET_DoDialogBox( HWND hwnd, HWND owner);
140
141BOOL WINAPI
142PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
143
144
145/******************************************************************************
146 * PROPSHEET_CollectSheetInfo
147 *
148 * Collect relevant data.
149 */
150static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
151 PropSheetInfo * psInfo)
152{
153 DWORD dwFlags = lppsh->dwFlags;
154
155 psInfo->hasHelp = dwFlags & PSH_HASHELP;
156 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
157 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
158 psInfo->isModeless = dwFlags & PSH_MODELESS;
159 psInfo->ppshheader = (PROPSHEETHEADERA*)lppsh;
160 psInfo->ppshheader = (PROPSHEETHEADERA*)COMCTL32_Alloc(sizeof(PROPSHEETHEADERA));
161 *psInfo->ppshheader = *lppsh;
162
163 if (HIWORD(lppsh->pszCaption))
164 psInfo->ppshheader->pszCaption = HEAP_strdupA( GetProcessHeap(),
165 0, lppsh->pszCaption );
166
167 psInfo->nPages = lppsh->nPages;
168
169 if (dwFlags & PSH_USEPSTARTPAGE)
170 {
171 TRACE("PSH_USEPSTARTPAGE is on");
172 psInfo->active_page = 0;
173 }
174 else
175 psInfo->active_page = lppsh->nStartPage;
176
177 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
178 psInfo->active_page = 0;
179
180 psInfo->restartWindows = FALSE;
181 psInfo->rebootSystem = FALSE;
182 psInfo->hImageList = 0;
183 psInfo->activeValid = FALSE;
184
185 return TRUE;
186}
187
188/******************************************************************************
189 * PROPSHEET_FindPageByResId
190 *
191 * Find page index corresponding to page resource id.
192 */
193INT PROPSHEET_FindPageByResId(PropSheetInfo * psInfo, LRESULT resId)
194{
195 INT i;
196
197 for (i = 0; i < psInfo->nPages; i++)
198 {
199 LPCPROPSHEETPAGEA lppsp = (LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage;
200
201 /* Fixme: if resource ID is a string shall we use strcmp ??? */
202 if (lppsp->pszTemplate == (LPVOID)resId)
203 break;
204 }
205
206 return i;
207}
208
209/******************************************************************************
210 * PROPSHEET_CollectPageInfo
211 *
212 * Collect property sheet data.
213 * With code taken from DIALOG_ParseTemplate32.
214 */
215BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
216 PropSheetInfo * psInfo,
217 int index)
218{
219 DLGTEMPLATE* pTemplate;
220 const WORD* p;
221 DWORD dwFlags;
222 int width, height;
223
224 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
225 psInfo->proppage[index].hwndPage = 0;
226 psInfo->proppage[index].isDirty = FALSE;
227
228 /*
229 * Process property page flags.
230 */
231 dwFlags = lppsp->dwFlags;
232 psInfo->proppage[index].useCallback = dwFlags & PSP_USECALLBACK;
233 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
234 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
235
236 /* as soon as we have a page with the help flag, set the sheet flag on */
237 if (psInfo->proppage[index].hasHelp)
238 psInfo->hasHelp = TRUE;
239
240 /*
241 * Process page template.
242 */
243 if (dwFlags & PSP_DLGINDIRECT)
244 pTemplate = (DLGTEMPLATE*)lppsp->pResource;
245 else
246 {
247 HRSRC hResource = FindResourceA(lppsp->hInstance,
248 lppsp->pszTemplate,
249 RT_DIALOGA);
250 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
251 hResource);
252 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
253 }
254
255 /*
256 * Extract the size of the page and the caption.
257 */
258 p = (const WORD *)pTemplate;
259
260 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
261 {
262 /* DIALOGEX template */
263
264 p++; /* dlgVer */
265 p++; /* signature */
266 p += 2; /* help ID */
267 p += 2; /* ext style */
268 p += 2; /* style */
269 }
270 else
271 {
272 /* DIALOG template */
273
274 p += 2; /* style */
275 p += 2; /* ext style */
276 }
277
278 p++; /* nb items */
279 p++; /* x */
280 p++; /* y */
281 width = (WORD)*p; p++;
282 height = (WORD)*p; p++;
283
284 /* remember the largest width and height */
285 if (width > psInfo->width)
286 psInfo->width = width;
287
288 if (height > psInfo->height)
289 psInfo->height = height;
290
291 /* menu */
292 switch ((WORD)*p)
293 {
294 case 0x0000:
295 p++;
296 break;
297 case 0xffff:
298 p += 2;
299 break;
300 default:
301 p += lstrlenW( (LPCWSTR)p ) + 1;
302 break;
303 }
304
305 /* class */
306 switch ((WORD)*p)
307 {
308 case 0x0000:
309 p++;
310 break;
311 case 0xffff:
312 p += 2;
313 break;
314 default:
315 p += lstrlenW( (LPCWSTR)p ) + 1;
316 break;
317 }
318
319 /* Extract the caption */
320 psInfo->proppage[index].pszText = (LPCWSTR)p;
321 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
322 p += lstrlenW((LPCWSTR)p) + 1;
323
324 if (dwFlags & PSP_USETITLE)
325 {
326 if ( !HIWORD( lppsp->pszTitle ) )
327 {
328 char szTitle[256];
329
330 if ( !LoadStringA( lppsp->hInstance, (UINT) lppsp->pszTitle, szTitle, 256 ) )
331 return FALSE;
332
333 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(),
334 0, szTitle );
335 }
336 else
337 psInfo->proppage[index].pszText = HEAP_strdupAtoW(GetProcessHeap(),
338 0,
339 lppsp->pszTitle);
340 }
341
342 /*
343 * Build the image list for icons
344 */
345 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
346 {
347 HICON hIcon;
348 int icon_cx = GetSystemMetrics(SM_CXSMICON);
349 int icon_cy = GetSystemMetrics(SM_CYSMICON);
350
351 if (dwFlags & PSP_USEICONID)
352 hIcon = LoadImageA(lppsp->hInstance, lppsp->pszIcon, IMAGE_ICON,
353 icon_cx, icon_cy, LR_DEFAULTCOLOR);
354 else
355 hIcon = lppsp->hIcon;
356
357 if ( hIcon )
358 {
359 if (psInfo->hImageList == 0 )
360 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
361
362 ImageList_AddIcon(psInfo->hImageList, hIcon);
363 }
364
365 }
366
367 return TRUE;
368}
369
370/******************************************************************************
371 * PROPSHEET_DoDialogBox
372 *
373 * Copied from windows/dialog.c:DIALOG_DoDialogBox
374 */
375static INT PROPSHEET_DoDialogBox( HWND hwnd, HWND owner)
376{
377 DIALOGINFO * dlgInfo;
378 MSG msg;
379 INT retval;
380
381 dprintf(("PROPSHEET: PROPSHEET_DoDialogBox not implemented!!!"));
382
383#if 0 //CB: implement! sync with user32\win32dlg.cpp DoDialogBox method (not easy)
384 // this functions isn't used so far
385 /* Owner must be a top-level window */
386 owner = WIN_GetTopParent( owner );
387 if (!IsWindow(hwnd))) return -1;
388 dlgInfo = (DIALOGINFO*)wndPtr->wExtra;
389
390 if (!dlgInfo->flags & DF_END) /* was EndDialog called in WM_INITDIALOG ? */
391 {
392 EnableWindow( owner, FALSE );
393 ShowWindow( hwnd, SW_SHOW );
394 while (GetMessageA(&msg, 0, 0, 0))
395 {
396 if (!PROPSHEET_IsDialogMessage( hwnd, &msg))
397 {
398 TranslateMessage( &msg );
399 DispatchMessageA( &msg );
400 }
401 if (dlgInfo->flags & DF_END) break;
402 }
403 EnableWindow( owner, TRUE );
404 }
405 retval = dlgInfo->dlgExtra->idResult;
406#endif
407 DestroyWindow( hwnd );
408 return retval;
409}
410
411/******************************************************************************
412 * PROPSHEET_CreateDialog
413 *
414 * Creates the actual property sheet.
415 */
416
417BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
418{
419 LRESULT ret;
420 LPCVOID templ;
421 LPVOID temp = 0;
422 HRSRC hRes;
423 DWORD resSize;
424 WORD resID = IDD_PROPSHEET;
425
426 if (psInfo->ppshheader->dwFlags & PSH_WIZARD)
427 resID = IDD_WIZARD;
428
429 if(!(hRes = FindResourceA(COMCTL32_hModule,
430 MAKEINTRESOURCEA(resID),
431 RT_DIALOGA)))
432 return FALSE;
433
434 if(!(templ = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
435 return FALSE;
436
437 /*
438 * Make a copy of the dialog template.
439 */
440 resSize = SizeofResource(COMCTL32_hModule, hRes);
441
442 temp = COMCTL32_Alloc(resSize);
443
444 if (!temp)
445 return FALSE;
446
447 memcpy(temp, templ, resSize);
448
449 if (psInfo->useCallback)
450 (*(psInfo->ppshheader->pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
451
452 if (psInfo->ppshheader->dwFlags & PSH_MODELESS)
453 ret = CreateDialogIndirectParamA(psInfo->ppshheader->hInstance,
454 (LPDLGTEMPLATEA) temp,
455 psInfo->ppshheader->hwndParent,
456 (DLGPROC) PROPSHEET_DialogProc,
457 (LPARAM)psInfo);
458 else
459 ret = DialogBoxIndirectParamA(psInfo->ppshheader->hInstance,
460 (LPDLGTEMPLATEA) temp,
461 psInfo->ppshheader->hwndParent,
462 (DLGPROC) PROPSHEET_DialogProc,
463 (LPARAM)psInfo);
464
465 COMCTL32_Free(temp);
466
467 return ret;
468}
469
470/******************************************************************************
471 * PROPSHEET_IsTooSmall
472 *
473 * Verify that the resource property sheet is big enough.
474 */
475static BOOL PROPSHEET_IsTooSmall(HWND hwndDlg, PropSheetInfo* psInfo)
476{
477 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
478 RECT rcOrigTab, rcPage;
479
480 /*
481 * Original tab size.
482 */
483 GetClientRect(hwndTabCtrl, &rcOrigTab);
484 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
485 rcOrigTab.right, rcOrigTab.bottom);
486
487 /*
488 * Biggest page size.
489 */
490 rcPage.left = psInfo->x;
491 rcPage.top = psInfo->y;
492 rcPage.right = psInfo->width;
493 rcPage.bottom = psInfo->height;
494
495 MapDialogRect(hwndDlg, &rcPage);
496 TRACE("biggest page %d %d %d %d (old %,%d)\n", rcPage.left, rcPage.top,
497 rcPage.right, rcPage.bottom, rcOrigTab.right, rcOrigTab.bottom);
498
499 if (rcPage.right > rcOrigTab.right)
500 return TRUE;
501
502 if (rcPage.bottom > rcOrigTab.bottom)
503 return TRUE;
504
505 return FALSE;
506}
507
508/******************************************************************************
509 * PROPSHEET_SizeMismatch
510 *
511 * Verify that the tab control and the "largest" property sheet page dlg. template
512 * match in size.
513 */
514static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
515{
516 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
517 RECT rcOrigTab, rcPage;
518
519 /*
520 * Original tab size.
521 */
522 GetClientRect(hwndTabCtrl, &rcOrigTab);
523 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
524 rcOrigTab.right, rcOrigTab.bottom);
525
526 /*
527 * Biggest page size.
528 */
529 rcPage.left = psInfo->x;
530 rcPage.top = psInfo->y;
531 rcPage.right = psInfo->width;
532 rcPage.bottom = psInfo->height;
533
534 MapDialogRect(hwndDlg, &rcPage);
535 TRACE("biggest page %d %d %d %d (old %d,%d %d,%d,)\n", rcPage.left, rcPage.top,
536 rcPage.right, rcPage.bottom, rcOrigTab.left, rcOrigTab.top, rcOrigTab.right, rcOrigTab.bottom);
537
538 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
539 return TRUE;
540 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
541 return TRUE;
542
543 return FALSE;
544}
545
546/******************************************************************************
547 * PROPSHEET_IsTooSmallWizard
548 *
549 * Verify that the default property sheet is big enough.
550 */
551static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
552{
553 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
554 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
555 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg,psInfo);
556
557 GetClientRect(hwndDlg, &rcSheetClient);
558 GetWindowRect(hwndDlg, &rcSheetRect);
559 GetWindowRect(hwndLine, &rcLine);
560
561 /* Remove the space below the sunken line */
562 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
563
564 /* Remove the buffer zone all around the edge */
565 rcSheetClient.bottom -= (padding.y * 2);
566 rcSheetClient.right -= (padding.x * 2);
567
568 /*
569 * Biggest page size.
570 */
571 rcPage.left = psInfo->x;
572 rcPage.top = psInfo->y;
573 rcPage.right = psInfo->width;
574 rcPage.bottom = psInfo->height;
575
576 MapDialogRect(hwndDlg, &rcPage);
577 TRACE("biggest page %d %d %d %d (old %d,%d)\n", rcPage.left, rcPage.top,
578 rcPage.right, rcPage.bottom, rcSheetClient.right, rcSheetClient.bottom);
579
580 if (rcPage.right > rcSheetClient.right)
581 return TRUE;
582
583 if (rcPage.bottom > rcSheetClient.bottom)
584 return TRUE;
585
586 return FALSE;
587}
588
589/******************************************************************************
590 * PROPSHEET_AdjustSize
591 *
592 * Resizes the property sheet and the tab control to fit the largest page.
593 */
594static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
595{
596 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
597 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
598 RECT rc;
599 int tabOffsetX, tabOffsetY, buttonHeight;
600 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
601
602 /* Get the height of buttons */
603 GetClientRect(hwndButton, &rc);
604 buttonHeight = rc.bottom;
605
606 /*
607 * Biggest page size.
608 */
609 rc.left = psInfo->x;
610 rc.top = psInfo->y;
611 rc.right = psInfo->width;
612 rc.bottom = psInfo->height;
613
614 MapDialogRect(hwndDlg, &rc);
615
616 /*
617 * Resize the tab control.
618 */
619 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
620
621 tabOffsetX = -(rc.left);
622 tabOffsetY = -(rc.top);
623
624 rc.right -= rc.left;
625 rc.bottom -= rc.top;
626 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
627 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
628
629 GetClientRect(hwndTabCtrl, &rc);
630
631 TRACE("tab client rc %d %d %d %d\n",
632 rc.left, rc.top, rc.right, rc.bottom);
633
634 rc.right += ((padding.x * 2) + tabOffsetX);
635 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
636
637 /*
638 * Resize the property sheet.
639 */
640 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
641 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
642
643 return TRUE;
644}
645/******************************************************************************
646 * PROPSHEET_AdjustSizeWizard
647 *
648 * Resizes the property sheet to fit the largest page.
649 */
650static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
651{
652 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
653 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
654 RECT rc;
655 int buttonHeight, lineHeight;
656 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg,psInfo);
657
658 dprintf(("PROPSHEET_AdjustSizeWizard %x", hwndDlg));
659
660 /* Get the height of buttons */
661 GetClientRect(hwndButton, &rc);
662 buttonHeight = rc.bottom;
663
664 GetClientRect(hwndLine, &rc);
665 lineHeight = rc.bottom;
666
667 /*
668 * Biggest page size.
669 */
670 rc.left = psInfo->x;
671 rc.top = psInfo->y;
672 rc.right = psInfo->width;
673 rc.bottom = psInfo->height;
674
675 MapDialogRect(hwndDlg, &rc);
676
677 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
678
679 /* Make room */
680 rc.right += (padding.x * 2);
681 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
682
683 /*
684 * Resize the property sheet.
685 */
686 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
687 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
688
689 dprintf(("PROPSHEET_AdjustSizeWizard %x DONE", hwndDlg));
690 return TRUE;
691}
692
693
694/******************************************************************************
695 * PROPSHEET_AdjustButtons
696 *
697 * Adjusts the buttons' positions.
698 */
699static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
700{
701 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
702 RECT rcSheet;
703 int x, y;
704 int num_buttons = 2;
705 int buttonWidth, buttonHeight;
706 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
707
708 if (psInfo->hasApply)
709 num_buttons++;
710
711 if (psInfo->hasHelp)
712 num_buttons++;
713
714 /*
715 * Obtain the size of the buttons.
716 */
717 GetClientRect(hwndButton, &rcSheet);
718 buttonWidth = rcSheet.right;
719 buttonHeight = rcSheet.bottom;
720
721 /*
722 * Get the size of the property sheet.
723 */
724 GetClientRect(hwndParent, &rcSheet);
725
726 /*
727 * All buttons will be at this y coordinate.
728 */
729 y = rcSheet.bottom - (padding.y + buttonHeight);
730
731 /*
732 * Position OK button.
733 */
734 hwndButton = GetDlgItem(hwndParent, IDOK);
735
736 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
737
738 SetWindowPos(hwndButton, 0, x, y, 0, 0,
739 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
740
741 /*
742 * Position Cancel button.
743 */
744 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
745
746 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
747
748 SetWindowPos(hwndButton, 0, x, y, 0, 0,
749 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
750
751 /*
752 * Position Apply button.
753 */
754 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
755
756 if (psInfo->hasApply)
757 {
758 if (psInfo->hasHelp)
759 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
760 else
761 x = rcSheet.right - (padding.x + buttonWidth);
762
763 SetWindowPos(hwndButton, 0, x, y, 0, 0,
764 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
765
766 EnableWindow(hwndButton, FALSE);
767 }
768 else
769 ShowWindow(hwndButton, SW_HIDE);
770
771 /*
772 * Position Help button.
773 */
774 hwndButton = GetDlgItem(hwndParent, IDHELP);
775
776 if (psInfo->hasHelp)
777 {
778 x = rcSheet.right - (padding.x + buttonWidth);
779
780 SetWindowPos(hwndButton, 0, x, y, 0, 0,
781 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
782 }
783 else
784 ShowWindow(hwndButton, SW_HIDE);
785
786 return TRUE;
787}
788
789/******************************************************************************
790 * PROPSHEET_AdjustButtonsWizard
791 *
792 * Adjusts the buttons' positions.
793 */
794static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
795 PropSheetInfo* psInfo)
796{
797 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
798 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
799 RECT rcSheet;
800 int x, y;
801 int num_buttons = 3;
802 int buttonWidth, buttonHeight, lineHeight, lineWidth;
803 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent,psInfo);
804
805 if (psInfo->hasHelp)
806 num_buttons++;
807
808 /*
809 * Obtain the size of the buttons.
810 */
811 GetClientRect(hwndButton, &rcSheet);
812 buttonWidth = rcSheet.right;
813 buttonHeight = rcSheet.bottom;
814
815 GetClientRect(hwndLine, &rcSheet);
816 lineHeight = rcSheet.bottom;
817
818 /*
819 * Get the size of the property sheet.
820 */
821 GetClientRect(hwndParent, &rcSheet);
822
823 /*
824 * All buttons will be at this y coordinate.
825 */
826 y = rcSheet.bottom - (padding.y + buttonHeight);
827
828 /*
829 * Position the Next and the Finish buttons.
830 */
831 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
832
833 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
834
835 SetWindowPos(hwndButton, 0, x, y, 0, 0,
836 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
837
838 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
839
840 SetWindowPos(hwndButton, 0, x, y, 0, 0,
841 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
842
843 ShowWindow(hwndButton, SW_HIDE);
844
845 /*
846 * Position the Back button.
847 */
848 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
849
850 x -= buttonWidth;
851
852 SetWindowPos(hwndButton, 0, x, y, 0, 0,
853 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
854
855 /*
856 * Position the Cancel button.
857 */
858 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
859
860 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
861
862 SetWindowPos(hwndButton, 0, x, y, 0, 0,
863 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
864
865 /*
866 * Position Help button.
867 */
868 hwndButton = GetDlgItem(hwndParent, IDHELP);
869
870 if (psInfo->hasHelp)
871 {
872 x = rcSheet.right - (padding.x + buttonWidth);
873
874 SetWindowPos(hwndButton, 0, x, y, 0, 0,
875 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
876 }
877 else
878 ShowWindow(hwndButton, SW_HIDE);
879
880 /*
881 * Position and resize the sunken line.
882 */
883 x = padding.x;
884 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
885
886 GetClientRect(hwndParent, &rcSheet);
887 lineWidth = rcSheet.right - (padding.x * 2);
888
889 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
890 SWP_NOZORDER | SWP_NOACTIVATE);
891
892 return TRUE;
893}
894
895/******************************************************************************
896 * PROPSHEET_GetPaddingInfo
897 *
898 * Returns the layout information.
899 */
900static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
901{
902 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
903 RECT rcTab;
904 POINT tl;
905 PADDING_INFO padding;
906
907 GetWindowRect(hwndTab, &rcTab);
908
909 tl.x = rcTab.left;
910 tl.y = rcTab.top;
911
912 ScreenToClient(hwndDlg, &tl);
913
914 padding.x = tl.x;
915 padding.y = tl.y;
916
917 return padding;
918}
919
920/******************************************************************************
921 * PROPSHEET_GetPaddingInfoWizard
922 *
923 * Returns the layout information.
924 * Vertical spacing is the distance between the line and the buttons.
925 * Do NOT use the Help button to gather padding information when it isn't mapped
926 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
927 * for it in this case !
928 * FIXME: I'm not sure about any other coordinate problems with these evil
929 * buttons. Fix it in case additional problems appear or maybe calculate
930 * a padding in a completely different way, as this is somewhat messy.
931 */
932static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, PropSheetInfo* psInfo)
933{
934 PADDING_INFO padding;
935 RECT rc;
936 HWND hwndControl;
937 INT idButton;
938 POINT ptButton, ptLine;
939
940 TRACE("\n");
941 if (psInfo->hasHelp)
942 {
943 idButton = IDHELP;
944 }
945 else
946 {
947 if (psInfo->ppshheader->dwFlags & PSH_WIZARD)
948 {
949 idButton = IDC_NEXT_BUTTON;
950 }
951 else
952 {
953 /* hopefully this is ok */
954 idButton = IDCANCEL;
955 }
956 }
957
958 hwndControl = GetDlgItem(hwndDlg, idButton);
959 GetWindowRect(hwndControl, &rc);
960
961 ptButton.x = rc.left;
962 ptButton.y = rc.top;
963
964 ScreenToClient(hwndDlg, &ptButton);
965
966 /* Line */
967 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
968 GetWindowRect(hwndControl, &rc);
969
970 ptLine.x = 0;
971 ptLine.y = rc.bottom;
972
973 ScreenToClient(hwndDlg, &ptLine);
974
975 padding.y = ptButton.y - ptLine.y;
976
977 if (padding.y < 0)
978 ERR("padding negative ! Please report this !\n");
979
980 /* this is most probably not correct, but the best we have now */
981 padding.x = padding.y;
982
983 return padding;
984}
985
986/******************************************************************************
987 * PROPSHEET_CreateTabControl
988 *
989 * Insert the tabs in the tab control.
990 */
991static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
992 PropSheetInfo * psInfo)
993{
994 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
995 TCITEMA item;
996 int i, nTabs;
997 int iImage = 0;
998 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
999
1000 item.mask = TCIF_TEXT;
1001 item.pszText = tabtext;
1002 item.cchTextMax = MAX_TABTEXT_LENGTH;
1003
1004 nTabs = psInfo->ppshheader->nPages;
1005
1006 /*
1007 * Set the image list for icons.
1008 */
1009 if (psInfo->hImageList)
1010 {
1011 SendMessageA(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
1012 }
1013
1014 for (i = 0; i < nTabs; i++)
1015 {
1016 if ( psInfo->proppage[i].hasIcon )
1017 {
1018 item.mask |= TCIF_IMAGE;
1019 item.iImage = iImage++;
1020 }
1021 else
1022 {
1023 item.mask &= ~TCIF_IMAGE;
1024 }
1025
1026 WideCharToMultiByte(CP_ACP, 0,
1027 (LPCWSTR)psInfo->proppage[i].pszText,
1028 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
1029
1030 SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item);
1031 }
1032
1033 return TRUE;
1034}
1035
1036/******************************************************************************
1037 * PROPSHEET_CreatePage
1038 *
1039 * Creates a page.
1040 */
1041static int PROPSHEET_CreatePage(HWND hwndParent,
1042 int index,
1043 const PropSheetInfo * psInfo,
1044 LPPROPSHEETPAGEA ppshpage)
1045{
1046 DLGTEMPLATE* pTemplate;
1047 HWND hwndPage;
1048 RECT rc;
1049 PropPageInfo* ppInfo = psInfo->proppage;
1050 PADDING_INFO padding;
1051 UINT pageWidth,pageHeight;
1052 DWORD resSize;
1053 LPVOID temp = NULL;
1054
1055 TRACE("index %d\n", index);
1056
1057#ifdef __WIN32OS2__
1058 //AH: Check if ppshpage is valid
1059 if (ppshpage == NULL)
1060 {
1061 dprintf(("COMCTL32:PROPSHEET_CreatePage: ERROR!!! ppshpage == NULL!!!\n"));
1062 return FALSE;
1063 }
1064#endif
1065
1066 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
1067 pTemplate = (DLGTEMPLATE*)ppshpage->pResource;
1068 else
1069 {
1070 HRSRC hResource;
1071 HANDLE hTemplate;
1072
1073 hResource = FindResourceA(ppshpage->hInstance,
1074 ppshpage->pszTemplate,
1075 RT_DIALOGA);
1076 if(!hResource)
1077 return FALSE;
1078
1079 resSize = SizeofResource(ppshpage->hInstance, hResource);
1080
1081 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1082 if(!hTemplate)
1083 return FALSE;
1084
1085 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1086 /*
1087 * Make a copy of the dialog template to make it writable
1088 */
1089 temp = COMCTL32_Alloc(resSize);
1090 if (!temp)
1091 return FALSE;
1092
1093 memcpy(temp, pTemplate, resSize);
1094 pTemplate = (DLGTEMPLATE*)temp;
1095 }
1096
1097 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1098 {
1099 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1100 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1101 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1102 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1103 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1104 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1105 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1106#ifdef __WIN32OS2__
1107 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_THICKFRAME;
1108#endif
1109 }
1110 else
1111 {
1112 pTemplate->style |= WS_CHILD | DS_CONTROL;
1113 pTemplate->style &= ~DS_MODALFRAME;
1114 pTemplate->style &= ~WS_CAPTION;
1115 pTemplate->style &= ~WS_SYSMENU;
1116 pTemplate->style &= ~WS_POPUP;
1117 pTemplate->style &= ~WS_DISABLED;
1118 pTemplate->style &= ~WS_VISIBLE;
1119#ifdef __WIN32OS2__
1120 pTemplate->style &= ~WS_THICKFRAME;
1121#endif
1122 }
1123
1124 if (psInfo->proppage[index].useCallback)
1125 (*(ppshpage->pfnCallback))(hwndParent,
1126 PSPCB_CREATE,
1127 (LPPROPSHEETPAGEA)ppshpage);
1128
1129 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1130 pTemplate,
1131 hwndParent,
1132 ppshpage->pfnDlgProc,
1133 (LPARAM)ppshpage);
1134 /* Free a no more needed copy */
1135 if(temp)
1136 COMCTL32_Free(temp);
1137
1138 ppInfo[index].hwndPage = hwndPage;
1139
1140 rc.left = psInfo->x;
1141 rc.top = psInfo->y;
1142 rc.right = psInfo->width;
1143 rc.bottom = psInfo->height;
1144
1145 MapDialogRect(hwndParent, &rc);
1146
1147 pageWidth = rc.right - rc.left;
1148 pageHeight = rc.bottom - rc.top;
1149
1150 if (psInfo->ppshheader->dwFlags & PSH_WIZARD)
1151 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, (PropSheetInfo* )psInfo);
1152 else
1153 {
1154 /*
1155 * Ask the Tab control to fit this page in.
1156 */
1157
1158 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1159 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1160 padding = PROPSHEET_GetPaddingInfo(hwndParent);
1161 }
1162
1163#ifdef __WIN32OS2__
1164 //HACK alert!
1165 //SvL: CVP multiplies y padding by two to calculate the new height
1166 //I have no idea if this is always correct
1167 SetWindowPos(hwndPage, HWND_TOP,
1168 rc.left + padding.x/2,
1169 rc.top + padding.y/2,
1170 pageWidth, pageHeight, 0);
1171#else
1172 SetWindowPos(hwndPage, HWND_TOP,
1173 rc.left + padding.x,
1174 rc.top + padding.y,
1175 pageWidth, pageHeight, 0);
1176#endif
1177
1178 return TRUE;
1179}
1180
1181/******************************************************************************
1182 * PROPSHEET_ShowPage
1183 *
1184 * Displays or creates the specified page.
1185 *
1186 * Returns: 1 - specified page is activated.
1187 * 0 - function fails
1188 * -1 - some other page is activated
1189 */
1190static int PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1191{
1192 RECT rc;
1193 PADDING_INFO padding;
1194 UINT pageWidth,pageHeight;
1195
1196 if (index == psInfo->active_page)
1197 {
1198 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1199 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1200
1201 return 1;
1202 }
1203
1204 if (psInfo->active_page != -1)
1205 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1206
1207 if (psInfo->proppage[index].hwndPage == 0)
1208 {
1209 LPCPROPSHEETPAGEA ppshpage;
1210 PSHNOTIFY psn;
1211 LRESULT ret;
1212
1213 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[index].hpage;
1214 PROPSHEET_CreatePage(hwndDlg, index, psInfo, (PROPSHEETPAGEA*)ppshpage);
1215
1216 if (psInfo->proppage[index].hwndPage == 0)
1217 return 0;
1218
1219 psn.hdr.hwndFrom = hwndDlg;
1220 psn.hdr.code = PSN_SETACTIVE;
1221 psn.hdr.idFrom = 0;
1222 psn.lParam = 0;
1223
1224 /* Send the notification before showing the page. */
1225 ret = SendMessageA(psInfo->proppage[index].hwndPage,
1226 WM_NOTIFY, 0, (LPARAM) &psn);
1227
1228 if (ret)
1229 {
1230 /* User doesn't accept new selection - find desired page and reselect */
1231 if (ret == -1)
1232 {
1233 if (index > psInfo->active_page)
1234 index++;
1235 else
1236 index--;
1237 }
1238 else
1239 index = PROPSHEET_FindPageByResId(psInfo, ret);
1240
1241 return PROPSHEET_SetCurSel(hwndDlg, index, 0) ? -1 : 0;
1242 }
1243 }
1244
1245 if (psInfo->active_page != -1)
1246 {
1247 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1248 }
1249
1250#if 1
1251 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1252
1253 /* Synchronize current selection with tab control
1254 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1255 HWND hwndTabCtrl;
1256 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1257 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1258
1259 psInfo->active_page = index;
1260 psInfo->activeValid = TRUE;
1261#else
1262 /* HACK: Sometimes a property page doesn't get displayed at the right place inside the
1263 * property sheet. This will force the window to be placed at the proper location
1264 * before it is displayed.
1265 */
1266 rc.left = psInfo->x;
1267 rc.top = psInfo->y;
1268 rc.right = psInfo->width;
1269 rc.bottom = psInfo->height;
1270
1271 MapDialogRect(hwndDlg, &rc);
1272
1273 pageWidth = rc.right - rc.left;
1274 pageHeight = rc.bottom - rc.top;
1275
1276 if (psInfo->ppshheader->dwFlags & PSH_WIZARD)
1277 padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg,psInfo);
1278 else
1279 {
1280 /*
1281 * Ask the Tab control to fit this page in.
1282 */
1283
1284 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1285 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1286 padding = PROPSHEET_GetPaddingInfo(hwndDlg);
1287 }
1288
1289 SetWindowPos(psInfo->proppage[index].hwndPage,HWND_TOP,rc.left+padding.x,rc.top+padding.y,pageWidth,pageHeight,SWP_SHOWWINDOW);
1290
1291 if (!(psInfo->ppshheader->dwFlags & PSH_WIZARD))
1292 {
1293 HWND hwndTabCtrl;
1294
1295 /* Synchronize current selection with tab control */
1296 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1297 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1298 }
1299
1300 psInfo->active_page = index;
1301 psInfo->activeValid = TRUE;
1302#endif
1303 return 1;
1304}
1305
1306/******************************************************************************
1307 * PROPSHEET_Back
1308 */
1309static void PROPSHEET_Back(HWND hwndDlg)
1310{
1311 PSHNOTIFY psn;
1312 HWND hwndPage;
1313 LRESULT msgResult = 0;
1314 INT idx;
1315 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1316 PropSheetInfoStr);
1317
1318 if (psInfo->active_page < 0)
1319 return;
1320
1321 psn.hdr.code = PSN_WIZBACK;
1322 psn.hdr.hwndFrom = hwndDlg;
1323 psn.hdr.idFrom = 0;
1324 psn.lParam = 0;
1325
1326 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1327
1328 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1329
1330 if (msgResult == -1)
1331 return;
1332 else if (msgResult == 0)
1333 idx = psInfo->active_page - 1;
1334 else
1335 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1336
1337 if (idx >= 0 && idx < psInfo->nPages)
1338 {
1339 if (PROPSHEET_CanSetCurSel(hwndDlg))
1340 PROPSHEET_SetCurSel(hwndDlg, idx, 0);
1341 }
1342}
1343
1344/******************************************************************************
1345 * PROPSHEET_Next
1346 */
1347static void PROPSHEET_Next(HWND hwndDlg)
1348{
1349 PSHNOTIFY psn;
1350 HWND hwndPage;
1351 LRESULT msgResult = 0;
1352 INT idx;
1353 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1354 PropSheetInfoStr);
1355
1356 if (psInfo->active_page < 0)
1357 return;
1358
1359 psn.hdr.code = PSN_WIZNEXT;
1360 psn.hdr.hwndFrom = hwndDlg;
1361 psn.hdr.idFrom = 0;
1362 psn.lParam = 0;
1363
1364 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1365
1366 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1367
1368 TRACE("msg result %ld\n", msgResult);
1369
1370 if (msgResult == -1)
1371 return;
1372 else if (msgResult == 0)
1373 idx = psInfo->active_page + 1;
1374 else
1375 idx = PROPSHEET_FindPageByResId(psInfo, msgResult);
1376
1377 if (idx < psInfo->nPages )
1378 {
1379 if (PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1380 PROPSHEET_SetCurSel(hwndDlg, idx, 0);
1381 }
1382}
1383
1384/******************************************************************************
1385 * PROPSHEET_Finish
1386 */
1387static void PROPSHEET_Finish(HWND hwndDlg)
1388{
1389 PSHNOTIFY psn;
1390 HWND hwndPage;
1391 LRESULT msgResult = 0;
1392 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1393 PropSheetInfoStr);
1394
1395 if (psInfo->active_page < 0)
1396 return;
1397
1398 psn.hdr.code = PSN_WIZFINISH;
1399 psn.hdr.hwndFrom = hwndDlg;
1400 psn.hdr.idFrom = 0;
1401 psn.lParam = 0;
1402
1403 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1404
1405 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1406
1407 TRACE("msg result %ld\n", msgResult);
1408
1409 if (msgResult != 0)
1410 return;
1411
1412 if (psInfo->isModeless)
1413 psInfo->activeValid = FALSE;
1414 else
1415 EndDialog(hwndDlg, TRUE);
1416}
1417
1418/******************************************************************************
1419 * PROPSHEET_Apply
1420 */
1421static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1422{
1423 int i;
1424 HWND hwndPage;
1425 PSHNOTIFY psn;
1426 LRESULT msgResult;
1427 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1428 PropSheetInfoStr);
1429
1430 if (psInfo->active_page < 0)
1431 return FALSE;
1432
1433 psn.hdr.hwndFrom = hwndDlg;
1434 psn.hdr.idFrom = 0;
1435 psn.lParam = 0;
1436
1437
1438 /*
1439 * Send PSN_KILLACTIVE to the current page.
1440 */
1441 psn.hdr.code = PSN_KILLACTIVE;
1442
1443 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1444
1445 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1446 return FALSE;
1447
1448 /*
1449 * Send PSN_APPLY to all pages.
1450 */
1451 psn.hdr.code = PSN_APPLY;
1452 psn.lParam = lParam;
1453
1454 for (i = 0; i < psInfo->nPages; i++)
1455 {
1456 hwndPage = psInfo->proppage[i].hwndPage;
1457 if (hwndPage)
1458 {
1459 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1460 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1461 return FALSE;
1462 else if (msgResult == PSNRET_INVALID)
1463 {
1464 PROPSHEET_SetCurSel(hwndDlg, i, 0);
1465 return FALSE;
1466 }
1467 }
1468 }
1469
1470 EnableWindow(GetDlgItem(hwndDlg, IDC_APPLY_BUTTON), FALSE);
1471
1472 if(lParam)
1473 {
1474 int result = TRUE;
1475
1476 psInfo->activeValid = FALSE;
1477
1478 if (psInfo->restartWindows)
1479 result = ID_PSRESTARTWINDOWS;
1480
1481 /* reboot system takes precedence over restart windows */
1482 if (psInfo->rebootSystem)
1483 result = ID_PSREBOOTSYSTEM;
1484
1485 if (!psInfo->isModeless)
1486 EndDialog(hwndDlg, result);
1487 }
1488 else if(psInfo->active_page >= 0)
1489 {
1490 psn.hdr.code = PSN_SETACTIVE;
1491 psn.lParam = 0;
1492 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1493 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1494 /* Fixme: probably we have to handle return value */
1495 }
1496
1497 return TRUE;
1498}
1499
1500/******************************************************************************
1501 * PROPSHEET_Cancel
1502 */
1503static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1504{
1505 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1506 PropSheetInfoStr);
1507 HWND hwndPage;
1508 PSHNOTIFY psn;
1509 int i;
1510
1511 if (psInfo->active_page < 0)
1512 return;
1513
1514 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1515 psn.hdr.code = PSN_QUERYCANCEL;
1516 psn.hdr.hwndFrom = hwndDlg;
1517 psn.hdr.idFrom = 0;
1518 psn.lParam = 0;
1519
1520 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1521 return;
1522
1523 psn.hdr.code = PSN_RESET;
1524 psn.lParam = lParam;
1525
1526 for (i = 0; i < psInfo->nPages; i++)
1527 {
1528 hwndPage = psInfo->proppage[i].hwndPage;
1529
1530 if (hwndPage)
1531 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1532 /* No return value */
1533 }
1534
1535 if (psInfo->isModeless)
1536 {
1537 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1538 psInfo->activeValid = FALSE;
1539 }
1540 else
1541 EndDialog(hwndDlg, FALSE);
1542}
1543
1544/******************************************************************************
1545 * PROPSHEET_Help
1546 */
1547static void PROPSHEET_Help(HWND hwndDlg)
1548{
1549 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1550 PropSheetInfoStr);
1551 HWND hwndPage;
1552 PSHNOTIFY psn;
1553
1554 if (psInfo->active_page < 0)
1555 return;
1556
1557 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1558 psn.hdr.code = PSN_HELP;
1559 psn.hdr.hwndFrom = hwndDlg;
1560 psn.hdr.idFrom = 0;
1561 psn.lParam = 0;
1562
1563 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1564}
1565
1566/******************************************************************************
1567 * PROPSHEET_Changed
1568 */
1569static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1570{
1571 int i;
1572 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1573 PropSheetInfoStr);
1574 if (!psInfo) return;
1575 /*
1576 * Set the dirty flag of this page.
1577 */
1578 for (i = 0; i < psInfo->nPages; i++)
1579 {
1580 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1581 psInfo->proppage[i].isDirty = TRUE;
1582 }
1583
1584 /*
1585 * Enable the Apply button.
1586 */
1587 if (psInfo->hasApply)
1588 {
1589 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1590
1591 EnableWindow(hwndApplyBtn, TRUE);
1592 }
1593}
1594
1595/******************************************************************************
1596 * PROPSHEET_UnChanged
1597 */
1598static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1599{
1600 int i;
1601 BOOL noPageDirty = TRUE;
1602 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1603 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1604 PropSheetInfoStr);
1605 if ( !psInfo ) return;
1606 for (i = 0; i < psInfo->nPages; i++)
1607 {
1608 /* set the specified page as clean */
1609 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1610 psInfo->proppage[i].isDirty = FALSE;
1611
1612 /* look to see if there's any dirty pages */
1613 if (psInfo->proppage[i].isDirty)
1614 noPageDirty = FALSE;
1615 }
1616
1617 /*
1618 * Disable Apply button.
1619 */
1620 if (noPageDirty)
1621 EnableWindow(hwndApplyBtn, FALSE);
1622}
1623
1624/******************************************************************************
1625 * PROPSHEET_PressButton
1626 */
1627static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1628{
1629 switch (buttonID)
1630 {
1631 case PSBTN_APPLYNOW:
1632 PROPSHEET_Apply(hwndDlg, 0);
1633 break;
1634
1635 case PSBTN_BACK:
1636 PROPSHEET_Back(hwndDlg);
1637 break;
1638
1639 case PSBTN_CANCEL:
1640 PROPSHEET_Cancel(hwndDlg, 0);
1641 break;
1642
1643 case PSBTN_FINISH:
1644 PROPSHEET_Finish(hwndDlg);
1645 break;
1646
1647 case PSBTN_HELP:
1648 PROPSHEET_Help(hwndDlg);
1649 break;
1650
1651 case PSBTN_NEXT:
1652 PROPSHEET_Next(hwndDlg);
1653 break;
1654
1655 case PSBTN_OK:
1656 PROPSHEET_Apply(hwndDlg, 1);
1657 break;
1658
1659 //default:
1660 // FIXME("Invalid button index %d\n", buttonID);
1661 }
1662}
1663
1664/*************************************************************************
1665 * BOOL PROPSHEET_CanSetCurSel [Internal]
1666 *
1667 * Test weither the current page can be changed by sending a PSN_KILLACTIVE
1668 *
1669 * PARAMS
1670 * hwndDlg [I] handle to a Dialog hWnd
1671 *
1672 * RETURNS
1673 * TRUE if Current Selection can change
1674 *
1675 * NOTES
1676 */
1677static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1678{
1679 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1680 PropSheetInfoStr);
1681 HWND hwndPage;
1682 PSHNOTIFY psn;
1683
1684 if (!psInfo)
1685 return FALSE;
1686
1687 if (psInfo->active_page < 0)
1688 return TRUE;
1689
1690 /*
1691 * Notify the current page.
1692 */
1693 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1694 psn.hdr.code = PSN_KILLACTIVE;
1695 psn.hdr.hwndFrom = hwndDlg;
1696 psn.hdr.idFrom = 0;
1697 psn.lParam = 0;
1698
1699 return !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1700}
1701
1702/******************************************************************************
1703 * PROPSHEET_SetCurSel
1704 */
1705static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1706 int index,
1707 HPROPSHEETPAGE hpage)
1708{
1709 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1710 PropSheetInfoStr);
1711 HWND hwndPage;
1712 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1713 int i;
1714
1715 /* hpage takes precedence over index */
1716 if (hpage != NULL)
1717 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1718
1719 again:
1720
1721 if (index < 0 || index >= psInfo->nPages)
1722 {
1723 TRACE("Could not find page to select!\n");
1724 return FALSE;
1725 }
1726
1727 if (!psInfo->proppage[index].hwndPage) {
1728 LPPROPSHEETPAGEA ppshpage = (LPPROPSHEETPAGEA)psInfo->proppage[index].hpage;
1729 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1730 }
1731 hwndPage = psInfo->proppage[index].hwndPage;
1732
1733 /*
1734 * Notify the new page if it's already created.
1735 * If not it will get created and notified in PROPSHEET_ShowPage.
1736 */
1737
1738 if (hwndPage)
1739 {
1740 LRESULT result;
1741 PSHNOTIFY psn;
1742
1743 psn.hdr.code = PSN_SETACTIVE;
1744 psn.hdr.hwndFrom = hwndDlg;
1745 psn.hdr.idFrom = 0;
1746 psn.lParam = 0;
1747
1748 result = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1749
1750 /* Fixme: If user doesn't accept new selection shall we send
1751 * notifications to the page specified by user, or select it
1752 * silently?
1753 */
1754 if (result == -1)
1755 {
1756 if (index != psInfo->active_page)
1757 {
1758 if (index > psInfo->active_page)
1759 index++;
1760 else if (index < psInfo->active_page)
1761 index--;
1762
1763 goto again;
1764 }
1765 }
1766 else if (result != 0)
1767 {
1768 index = PROPSHEET_FindPageByResId(psInfo, result);
1769 goto again;
1770 }
1771 }
1772
1773 /*
1774 * Display the new page.
1775 */
1776 i = PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1777
1778 /* 0 - function is failed,
1779 * -1 - some other page is activated (via recursive call to SetCurSel) -
1780 * exit now to avoid overwriting state of help button.
1781 */
1782 if (i <= 0)
1783 return (BOOL)i;
1784
1785 if (psInfo->proppage[index].hasHelp)
1786 EnableWindow(hwndHelp, TRUE);
1787 else
1788 EnableWindow(hwndHelp, FALSE);
1789
1790 return TRUE;
1791}
1792
1793/******************************************************************************
1794 * PROPSHEET_SetTitleA
1795 */
1796static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1797{
1798 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfoStr);
1799 char szTitle[256];
1800
1801 if (HIWORD(lpszText) == 0) {
1802 if (!LoadStringA(psInfo->ppshheader->hInstance,
1803 LOWORD(lpszText), szTitle, sizeof(szTitle)-1))
1804 return;
1805 lpszText = szTitle;
1806 }
1807 if (dwStyle & PSH_PROPTITLE)
1808 {
1809 char* dest;
1810 int lentitle = strlen(lpszText);
1811 int lenprop = strlen(psInfo->strPropertiesFor);
1812
1813 dest = (CHAR*)COMCTL32_Alloc(lentitle + lenprop + 1);
1814 strcpy(dest, psInfo->strPropertiesFor);
1815 strcat(dest, lpszText);
1816
1817 SetWindowTextA(hwndDlg, dest);
1818 COMCTL32_Free(dest);
1819 }
1820 else
1821 SetWindowTextA(hwndDlg, lpszText);
1822}
1823
1824/******************************************************************************
1825 * PROPSHEET_SetFinishTextA
1826 */
1827static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1828{
1829 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1830
1831 /* Set text, show and enable the Finish button */
1832 SetWindowTextA(hwndButton, lpszText);
1833 ShowWindow(hwndButton, SW_SHOW);
1834 EnableWindow(hwndButton, TRUE);
1835
1836 /* Make it default pushbutton */
1837 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1838
1839 /* Hide Back button */
1840 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1841 ShowWindow(hwndButton, SW_HIDE);
1842
1843 /* Hide Next button */
1844 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1845 ShowWindow(hwndButton, SW_HIDE);
1846}
1847
1848/******************************************************************************
1849 * PROPSHEET_QuerySiblings
1850 */
1851static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1852 WPARAM wParam, LPARAM lParam)
1853{
1854 int i = 0;
1855 HWND hwndPage;
1856 LRESULT msgResult = 0;
1857 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1858 PropSheetInfoStr);
1859
1860 while ((i < psInfo->nPages) && (msgResult == 0))
1861 {
1862 hwndPage = psInfo->proppage[i].hwndPage;
1863 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1864 i++;
1865 }
1866
1867 return msgResult;
1868}
1869
1870
1871/******************************************************************************
1872 * PROPSHEET_AddPage
1873 */
1874static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1875 HPROPSHEETPAGE hpage)
1876{
1877 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1878 PropSheetInfoStr);
1879 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1880 TCITEMA item;
1881 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
1882 LPCPROPSHEETPAGEA ppsp = (LPCPROPSHEETPAGEA)hpage;
1883
1884 /*
1885 * Allocate and fill in a new PropPageInfo entry.
1886 */
1887 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1888 sizeof(PropPageInfo) *
1889 (psInfo->nPages + 1));
1890
1891 PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages);
1892 psInfo->proppage[psInfo->nPages].hpage = hpage;
1893
1894 if (ppsp->dwFlags & PSP_PREMATURE)
1895 {
1896 /* Create the page but don't show it */
1897 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, (PROPSHEETPAGEA*)ppsp);
1898 }
1899
1900 /*
1901 * Add a new tab to the tab control.
1902 */
1903 item.mask = TCIF_TEXT;
1904 item.pszText = tabtext;
1905 item.cchTextMax = MAX_TABTEXT_LENGTH;
1906
1907 WideCharToMultiByte(CP_ACP, 0,
1908 (LPCWSTR)psInfo->proppage[psInfo->nPages].pszText,
1909 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
1910
1911 SendMessageA(hwndTabControl, TCM_INSERTITEMA, psInfo->nPages + 1,
1912 (LPARAM)&item);
1913
1914 psInfo->nPages++;
1915
1916 /* If it is the only page - show it */
1917 if(psInfo->nPages == 1)
1918 PROPSHEET_ShowPage(hwndDlg, 0, psInfo);
1919
1920 return TRUE;
1921}
1922
1923/******************************************************************************
1924 * PROPSHEET_RemovePage
1925 */
1926static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
1927 int index,
1928 HPROPSHEETPAGE hpage)
1929{
1930 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1931 PropSheetInfoStr);
1932 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1933 PropPageInfo* oldPages;
1934
1935 if (!psInfo) {
1936 return FALSE;
1937 }
1938 oldPages = psInfo->proppage;
1939 /*
1940 * hpage takes precedence over index.
1941 */
1942 if (hpage != 0)
1943 {
1944 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1945 }
1946
1947 /* Make shure that index is within range */
1948 if (index < 0 || index >= psInfo->nPages)
1949 {
1950 TRACE("Could not find page to remove!\n");
1951 return FALSE;
1952 }
1953
1954 TRACE("total pages %d removing page %d active page %d\n",
1955 psInfo->nPages, index, psInfo->active_page);
1956 /*
1957 * Check if we're removing the active page.
1958 */
1959 if (index == psInfo->active_page)
1960 {
1961 if (psInfo->nPages > 1)
1962 {
1963 if (index > 0)
1964 {
1965 /* activate previous page */
1966 PROPSHEET_ShowPage(hwndDlg, index - 1, psInfo);
1967 }
1968 else
1969 {
1970 /* activate the next page */
1971 PROPSHEET_ShowPage(hwndDlg, index + 1, psInfo);
1972 psInfo->active_page = index;
1973 }
1974 }
1975 else
1976 {
1977 psInfo->active_page = -1;
1978 if (!psInfo->isModeless)
1979 {
1980 EndDialog(hwndDlg, FALSE);
1981 return TRUE;
1982 }
1983 }
1984 }
1985 else if (index < psInfo->active_page)
1986 psInfo->active_page--;
1987
1988 /* Destroy page dialog window */
1989 DestroyWindow(psInfo->proppage[index].hwndPage);
1990
1991 /* Free page resources */
1992 if(psInfo->proppage[index].hpage)
1993 {
1994 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[index].hpage;
1995
1996 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
1997 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
1998
1999 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
2000 }
2001
2002 /* Remove the tab */
2003 SendMessageA(hwndTabControl, TCM_DELETEITEM, index, 0);
2004
2005 psInfo->nPages--;
2006 psInfo->proppage = (PropPageInfo*)COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
2007
2008 if (index > 0)
2009 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
2010
2011 if (index < psInfo->nPages)
2012 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
2013 (psInfo->nPages - index) * sizeof(PropPageInfo));
2014
2015 COMCTL32_Free(oldPages);
2016
2017 return FALSE;
2018}
2019
2020/******************************************************************************
2021 * PROPSHEET_SetWizButtons
2022 *
2023 * This code will work if (and assumes that) the Next button is on top of the
2024 * Finish button. ie. Finish comes after Next in the Z order.
2025 * This means make sure the dialog template reflects this.
2026 *
2027 */
2028static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
2029{
2030 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
2031 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
2032 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
2033
2034 TRACE("%ld\n", dwFlags);
2035
2036 EnableWindow(hwndBack, FALSE);
2037 EnableWindow(hwndNext, FALSE);
2038 EnableWindow(hwndFinish, FALSE);
2039
2040 if (dwFlags & PSWIZB_BACK)
2041 EnableWindow(hwndBack, TRUE);
2042
2043 if (dwFlags & PSWIZB_NEXT)
2044 {
2045 /* Hide the Finish button */
2046 ShowWindow(hwndFinish, SW_HIDE);
2047
2048 /* Show and enable the Next button */
2049 ShowWindow(hwndNext, SW_SHOW);
2050 EnableWindow(hwndNext, TRUE);
2051
2052 /* Set the Next button as the default pushbutton */
2053 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
2054 }
2055
2056 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
2057 {
2058 /* Hide the Next button */
2059 ShowWindow(hwndNext, SW_HIDE);
2060
2061 /* Show the Finish button */
2062 ShowWindow(hwndFinish, SW_SHOW);
2063
2064 if (dwFlags & PSWIZB_FINISH)
2065 EnableWindow(hwndFinish, TRUE);
2066
2067 /* Set the Finish button as the default pushbutton */
2068 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
2069 }
2070}
2071
2072/******************************************************************************
2073 * PROPSHEET_GetPageIndex
2074 *
2075 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
2076 * the array of PropPageInfo.
2077 */
2078static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
2079{
2080 BOOL found = FALSE;
2081 int index = 0;
2082
2083 while ((index < psInfo->nPages) && (found == FALSE))
2084 {
2085 if (psInfo->proppage[index].hpage == hpage)
2086 found = TRUE;
2087 else
2088 index++;
2089 }
2090
2091 if (found == FALSE)
2092 index = -1;
2093
2094 return index;
2095}
2096
2097/******************************************************************************
2098 * PROPSHEET_CleanUp
2099 */
2100static void PROPSHEET_CleanUp(HWND hwndDlg)
2101{
2102 int i;
2103 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropA(hwndDlg,
2104 PropSheetInfoStr);
2105
2106 TRACE("\n");
2107 if (HIWORD(psInfo->ppshheader->pszCaption))
2108 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader->pszCaption);
2109
2110 COMCTL32_Free((LPVOID)psInfo->ppshheader);
2111
2112 for (i = 0; i < psInfo->nPages; i++)
2113 {
2114 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
2115
2116 if(psInfo->proppage[i].hwndPage)
2117 DestroyWindow(psInfo->proppage[i].hwndPage);
2118
2119 if(psp)
2120 {
2121 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
2122 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
2123
2124 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
2125 }
2126 }
2127
2128 COMCTL32_Free(psInfo->proppage);
2129 COMCTL32_Free(psInfo->strPropertiesFor);
2130 ImageList_Destroy(psInfo->hImageList);
2131
2132 GlobalFree((HGLOBAL)psInfo);
2133}
2134
2135/******************************************************************************
2136 * PropertySheetA (COMCTL32.84)(COMCTL32.83)
2137 */
2138INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
2139{
2140 int bRet = 0;
2141 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
2142 sizeof(PropSheetInfo));
2143 int i;
2144 BYTE* pByte;
2145
2146 dprintf(("COMCTL32: PropertySheetA"));
2147
2148 PROPSHEET_CollectSheetInfo(lppsh, psInfo);
2149
2150 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
2151 lppsh->nPages);
2152 pByte = (BYTE*) psInfo->ppshheader->ppsp;
2153
2154 for (i = 0; i < lppsh->nPages; i++)
2155 {
2156 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
2157 psInfo->proppage[i].hpage = psInfo->ppshheader->phpage[i];
2158 else
2159 {
2160 psInfo->proppage[i].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
2161 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
2162 }
2163
2164 PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEA)psInfo->proppage[i].hpage,
2165 psInfo, i);
2166 }
2167
2168 bRet = PROPSHEET_CreateDialog(psInfo);
2169
2170 return bRet;
2171}
2172
2173/******************************************************************************
2174 * PropertySheet32W (COMCTL32.85)
2175 */
2176INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader)
2177{
2178 dprintf(("COMCTL32: PropertySheetW - empty stub!"));
2179
2180 return -1;
2181}
2182
2183/******************************************************************************
2184 * CreatePropertySheetPageA (COMCTL32.19)(COMCTL32.18)
2185 */
2186HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
2187 LPCPROPSHEETPAGEA lpPropSheetPage)
2188{
2189 PROPSHEETPAGEA* ppsp = (PROPSHEETPAGEA*)COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
2190
2191 dprintf(("COMCTL32: CreatePropertySheetPageA"));
2192
2193 *ppsp = *lpPropSheetPage;
2194
2195 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->pszTemplate ) )
2196 ppsp->pszTemplate = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->pszTemplate );
2197
2198 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->pszIcon ) )
2199 ppsp->pszIcon = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->pszIcon );
2200
2201
2202 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2203 ppsp->pszTitle = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->pszTitle );
2204 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2205 ppsp->pszTitle = NULL;
2206
2207 return (HPROPSHEETPAGE)ppsp;
2208}
2209
2210/******************************************************************************
2211 * CreatePropertySheetPageW (COMCTL32.20)
2212 */
2213HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2214{
2215 dprintf(("COMCTL32: CreatePropertySheetPageW - empty stub!"));
2216
2217 return 0;
2218}
2219
2220/******************************************************************************
2221 * DestroyPropertySheetPage (COMCTL32.24)
2222 */
2223BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2224{
2225 PROPSHEETPAGEA *psp = (PROPSHEETPAGEA *)hPropPage;
2226
2227 dprintf(("COMCTL32: DestroyPropertySheetPage"));
2228
2229 if (!psp)
2230 return FALSE;
2231
2232 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->pszTemplate ) )
2233 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTemplate);
2234
2235 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->pszIcon ) )
2236 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszIcon);
2237
2238 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2239 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2240
2241 COMCTL32_Free(hPropPage);
2242
2243 return TRUE;
2244}
2245
2246/******************************************************************************
2247 * PROPSHEET_IsDialogMessage
2248 */
2249static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2250{
2251 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd, PropSheetInfoStr);
2252
2253 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2254 return FALSE;
2255
2256 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2257 {
2258 int new_page = 0;
2259 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2260
2261 if (!(dlgCode & DLGC_WANTMESSAGE))
2262 {
2263 switch (lpMsg->wParam)
2264 {
2265 case VK_TAB:
2266 if (GetKeyState(VK_SHIFT) & 0x8000)
2267 new_page = -1;
2268 else
2269 new_page = 1;
2270 break;
2271
2272 case VK_NEXT: new_page = 1; break;
2273 case VK_PRIOR: new_page = -1; break;
2274 }
2275 }
2276
2277 if (new_page)
2278 {
2279 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2280 {
2281 new_page += psInfo->active_page;
2282
2283 if (new_page < 0)
2284 new_page = psInfo->nPages - 1;
2285 else if (new_page >= psInfo->nPages)
2286 new_page = 0;
2287
2288 PROPSHEET_SetCurSel(hwnd, new_page, 0);
2289 }
2290
2291 return TRUE;
2292 }
2293 }
2294
2295 return IsDialogMessageA(hwnd, lpMsg);
2296}
2297
2298/******************************************************************************
2299 * PROPSHEET_DialogProc
2300 */
2301BOOL WINAPI
2302PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2303{
2304 switch (uMsg)
2305 {
2306 case WM_INITDIALOG:
2307 {
2308 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2309 char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH);
2310 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2311 LPCPROPSHEETPAGEA ppshpage;
2312 int idx;
2313
2314 SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2315
2316 /*
2317 * Small icon in the title bar.
2318 */
2319 if ((psInfo->ppshheader->dwFlags & PSH_USEICONID) ||
2320 (psInfo->ppshheader->dwFlags & PSH_USEHICON))
2321 {
2322 HICON hIcon;
2323 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2324 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2325
2326 if (psInfo->ppshheader->dwFlags & PSH_USEICONID)
2327 hIcon = LoadImageA(psInfo->ppshheader->hInstance,
2328 psInfo->ppshheader->pszIcon,
2329 IMAGE_ICON,
2330 icon_cx, icon_cy,
2331 LR_DEFAULTCOLOR);
2332 else
2333 hIcon = psInfo->ppshheader->hIcon;
2334
2335 SendMessageA(hwnd, WM_SETICON, 0, hIcon);
2336 }
2337
2338 if (psInfo->ppshheader->dwFlags & PSH_USEHICON)
2339 SendMessageA(hwnd, WM_SETICON, 0, psInfo->ppshheader->hIcon);
2340
2341 psInfo->strPropertiesFor = strCaption;
2342
2343 GetWindowTextA(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2344
2345 PROPSHEET_CreateTabControl(hwnd, psInfo);
2346
2347 if (psInfo->ppshheader->dwFlags & PSH_WIZARD)
2348 {
2349 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2350 {
2351 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2352 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2353 }
2354 }
2355 else
2356 {
2357 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2358 {
2359 PROPSHEET_AdjustSize(hwnd, psInfo);
2360 PROPSHEET_AdjustButtons(hwnd, psInfo);
2361 }
2362 }
2363
2364 if (psInfo->useCallback)
2365 (*(psInfo->ppshheader->pfnCallback))(hwnd,
2366 PSCB_INITIALIZED, (LPARAM)0);
2367
2368 idx = psInfo->active_page;
2369 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[idx].hpage;
2370 psInfo->active_page = -1;
2371
2372 PROPSHEET_SetCurSel(hwnd, idx, psInfo->proppage[idx].hpage);
2373
2374 if (!(psInfo->ppshheader->dwFlags & PSH_WIZARD))
2375 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2376
2377 if (!HIWORD(psInfo->ppshheader->pszCaption) &&
2378 psInfo->ppshheader->hInstance)
2379 {
2380 char szText[256];
2381
2382 if (LoadStringA(psInfo->ppshheader->hInstance,
2383 (UINT)psInfo->ppshheader->pszCaption, szText, 255))
2384 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader->dwFlags, szText);
2385 }
2386 else
2387 {
2388 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader->dwFlags,
2389 psInfo->ppshheader->pszCaption);
2390 }
2391
2392 return TRUE;
2393 }
2394
2395 case WM_DESTROY:
2396 PROPSHEET_CleanUp(hwnd);
2397 return TRUE;
2398
2399 case WM_CLOSE:
2400 PROPSHEET_Cancel(hwnd, 1);
2401 return TRUE;
2402
2403 case WM_COMMAND:
2404 {
2405 WORD wID = LOWORD(wParam);
2406 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,PropSheetInfoStr);
2407
2408 switch (wID)
2409 {
2410 case IDOK:
2411 case IDC_APPLY_BUTTON:
2412 PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0);
2413 break;
2414
2415 case IDC_BACK_BUTTON:
2416 PROPSHEET_Back(hwnd);
2417 break;
2418
2419 case IDC_NEXT_BUTTON:
2420 PROPSHEET_Next(hwnd);
2421 break;
2422
2423 case IDC_FINISH_BUTTON:
2424 PROPSHEET_Finish(hwnd);
2425 break;
2426
2427 case IDCANCEL:
2428 PROPSHEET_Cancel(hwnd, 0);
2429 break;
2430
2431 case IDHELP:
2432 PROPSHEET_Help(hwnd);
2433 break;
2434
2435 default:
2436 if(psInfo->active_page != -1)
2437 {
2438 return SendMessageA(psInfo->proppage[psInfo->active_page].hwndPage,
2439 uMsg, wParam, lParam);
2440 }
2441 }
2442
2443 return TRUE;
2444 }
2445
2446 case WM_NOTIFY:
2447 {
2448 NMHDR* pnmh = (LPNMHDR) lParam;
2449
2450 if (pnmh->code == TCN_SELCHANGE)
2451 {
2452 int index = SendMessageA(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2453 PROPSHEET_SetCurSel(hwnd, index, 0);
2454 }
2455
2456 if(pnmh->code == TCN_SELCHANGING)
2457 {
2458 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2459 SetWindowLongA(hwnd, DWL_MSGRESULT, !bRet);
2460 return TRUE;
2461 }
2462
2463
2464 return 0;
2465 }
2466
2467 case PSM_GETCURRENTPAGEHWND:
2468 {
2469 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2470 PropSheetInfoStr);
2471 HWND hwndPage = 0;
2472
2473 if (psInfo->activeValid && psInfo->active_page != -1)
2474 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2475
2476 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndPage);
2477
2478 return TRUE;
2479 }
2480
2481 case PSM_CHANGED:
2482 PROPSHEET_Changed(hwnd, (HWND)wParam);
2483 return TRUE;
2484
2485 case PSM_UNCHANGED:
2486 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2487 return TRUE;
2488
2489 case PSM_GETTABCONTROL:
2490 {
2491 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2492
2493 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2494
2495 return TRUE;
2496 }
2497
2498 case PSM_SETCURSEL:
2499 {
2500 BOOL msgResult;
2501
2502 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2503 if(msgResult != FALSE)
2504 {
2505 msgResult = PROPSHEET_SetCurSel(hwnd,
2506 (int)wParam,
2507 (HPROPSHEETPAGE)lParam);
2508 }
2509
2510 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2511
2512 return TRUE;
2513 }
2514
2515 case PSM_CANCELTOCLOSE:
2516 {
2517 char buf[MAX_BUTTONTEXT_LENGTH];
2518 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2519 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2520
2521 EnableWindow(hwndCancel, FALSE);
2522 if (LoadStringA(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2523 SetWindowTextA(hwndOK, buf);
2524
2525 return FALSE;
2526 }
2527
2528 case PSM_RESTARTWINDOWS:
2529 {
2530 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2531 PropSheetInfoStr);
2532
2533 psInfo->restartWindows = TRUE;
2534 return TRUE;
2535 }
2536
2537 case PSM_REBOOTSYSTEM:
2538 {
2539 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2540 PropSheetInfoStr);
2541
2542 psInfo->rebootSystem = TRUE;
2543 return TRUE;
2544 }
2545
2546 case PSM_SETTITLEA:
2547 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2548 return TRUE;
2549
2550 case PSM_APPLY:
2551 {
2552 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2553
2554 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2555
2556 return TRUE;
2557 }
2558
2559 case PSM_QUERYSIBLINGS:
2560 {
2561 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2562
2563 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2564
2565 return TRUE;
2566 }
2567
2568 case PSM_ADDPAGE:
2569 {
2570 /*
2571 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2572 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2573 * on success or FALSE otherwise, as specified on MSDN Online.
2574 * Also see the MFC code for
2575 * CPropertySheet::AddPage(CPropertyPage* pPage).
2576 */
2577
2578 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2579
2580 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2581
2582 return TRUE;
2583 }
2584
2585 case PSM_REMOVEPAGE:
2586 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2587 return TRUE;
2588
2589 case PSM_ISDIALOGMESSAGE:
2590 {
2591 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2592 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2593 return TRUE;
2594 }
2595
2596 case PSM_PRESSBUTTON:
2597 PROPSHEET_PressButton(hwnd, (int)wParam);
2598 return TRUE;
2599
2600 case PSM_SETFINISHTEXTA:
2601 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2602 return TRUE;
2603
2604 case PSM_SETWIZBUTTONS:
2605 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2606 return TRUE;
2607
2608 case PSM_SETTITLEW:
2609 //FIXME("Unimplemented msg PSM_SETTITLE32W\n");
2610 return 0;
2611 case PSM_SETCURSELID:
2612 //FIXME("Unimplemented msg PSM_SETCURSELID\n");
2613 return 0;
2614 case PSM_SETFINISHTEXTW:
2615 //FIXME("Unimplemented msg PSM_SETFINISHTEXT32W\n");
2616 return 0;
2617
2618 default:
2619 return FALSE;
2620 }
2621}
2622
Note: See TracBrowser for help on using the repository browser.