4 * Copyright 1998 Francis Beaudet
5 * Copyright 1999 Thuy Nguyen
9 * - Unicode property sheets
18 #include "debugtools.h"
22 /******************************************************************************
34 typedef struct tagPropPageInfo
36 HPROPSHEETPAGE hpage; /* to keep track of pages not passed to PropertySheet */
45 typedef struct tagPropSheetInfo
48 PROPSHEETHEADERA ppshheader;
49 LPSTR strPropertiesFor;
59 PropPageInfo* proppage;
64 HIMAGELIST hImageList;
73 /******************************************************************************
74 * Defines and global variables
77 const char * PropSheetInfoStr = "PropertySheetInfo";
79 #define MAX_CAPTION_LENGTH 255
80 #define MAX_TABTEXT_LENGTH 255
81 #define MAX_BUTTONTEXT_LENGTH 64
83 /******************************************************************************
86 static BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo);
87 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo);
88 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo);
89 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo);
90 static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
91 PropSheetInfo * psInfo);
92 static BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
93 PropSheetInfo * psInfo,
95 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
96 PropSheetInfo * psInfo);
97 static BOOL PROPSHEET_CreatePage(HWND hwndParent, int index,
98 const PropSheetInfo * psInfo,
99 LPCPROPSHEETPAGEA ppshpage);
100 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo);
101 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg);
102 static BOOL PROPSHEET_Back(HWND hwndDlg);
103 static BOOL PROPSHEET_Next(HWND hwndDlg);
104 static BOOL PROPSHEET_Finish(HWND hwndDlg);
105 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam);
106 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam);
107 static void PROPSHEET_Help(HWND hwndDlg);
108 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage);
109 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage);
110 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID);
111 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText);
112 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText);
113 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg);
114 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
117 HPROPSHEETPAGE hpage);
118 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
119 WPARAM wParam, LPARAM lParam);
120 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
121 HPROPSHEETPAGE hpage);
123 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
125 HPROPSHEETPAGE hpage);
126 static void PROPSHEET_CleanUp();
127 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
128 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
129 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
130 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
133 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
135 DEFAULT_DEBUG_CHANNEL(propsheet);
137 /******************************************************************************
138 * PROPSHEET_CollectSheetInfo
140 * Collect relevant data.
142 static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
143 PropSheetInfo * psInfo)
145 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
146 DWORD dwFlags = lppsh->dwFlags;
148 psInfo->hasHelp = dwFlags & PSH_HASHELP;
149 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
150 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
151 psInfo->isModeless = dwFlags & PSH_MODELESS;
153 memcpy(&psInfo->ppshheader,lppsh,dwSize);
154 TRACE("\n** PROPSHEETHEADER **\ndwSize\t\t%ld\ndwFlags\t\t%08lx\nhwndParent\t%04x\nhInstance\t%08x\npszCaption\t'%s'\nnPages\t\t%d\npfnCallback\t%p\n",
155 lppsh->dwSize, lppsh->dwFlags, lppsh->hwndParent, lppsh->hInstance, lppsh->pszCaption, lppsh->nPages, lppsh->pfnCallback);
157 if (HIWORD(lppsh->pszCaption))
159 psInfo->ppshheader.pszCaption = HeapAlloc( GetProcessHeap(), 0, strlen(lppsh->pszCaption)+1 );
160 strcpy( (char *)psInfo->ppshheader.pszCaption, lppsh->pszCaption );
162 psInfo->nPages = lppsh->nPages;
164 if (dwFlags & PSH_USEPSTARTPAGE)
166 TRACE("PSH_USEPSTARTPAGE is on");
167 psInfo->active_page = 0;
170 psInfo->active_page = lppsh->u2.nStartPage;
172 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
173 psInfo->active_page = 0;
175 psInfo->restartWindows = FALSE;
176 psInfo->rebootSystem = FALSE;
177 psInfo->hImageList = 0;
178 psInfo->activeValid = FALSE;
183 /******************************************************************************
184 * PROPSHEET_CollectPageInfo
186 * Collect property sheet data.
187 * With code taken from DIALOG_ParseTemplate32.
189 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
190 PropSheetInfo * psInfo,
193 DLGTEMPLATE* pTemplate;
199 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
200 psInfo->proppage[index].hwndPage = 0;
201 psInfo->proppage[index].isDirty = FALSE;
204 * Process property page flags.
206 dwFlags = lppsp->dwFlags;
207 psInfo->proppage[index].useCallback = (dwFlags & PSP_USECALLBACK) && (lppsp->pfnCallback);
208 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
209 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
211 /* as soon as we have a page with the help flag, set the sheet flag on */
212 if (psInfo->proppage[index].hasHelp)
213 psInfo->hasHelp = TRUE;
216 * Process page template.
218 if (dwFlags & PSP_DLGINDIRECT)
219 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
222 HRSRC hResource = FindResourceA(lppsp->hInstance,
223 lppsp->u.pszTemplate,
225 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
227 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
231 * Extract the size of the page and the caption.
236 p = (const WORD *)pTemplate;
238 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
240 /* DIALOGEX template */
244 p += 2; /* help ID */
245 p += 2; /* ext style */
250 /* DIALOG template */
253 p += 2; /* ext style */
259 width = (WORD)*p; p++;
260 height = (WORD)*p; p++;
262 /* remember the largest width and height */
263 if (width > psInfo->width)
264 psInfo->width = width;
266 if (height > psInfo->height)
267 psInfo->height = height;
279 p += lstrlenW( (LPCWSTR)p ) + 1;
293 p += lstrlenW( (LPCWSTR)p ) + 1;
297 /* Extract the caption */
298 psInfo->proppage[index].pszText = (LPCWSTR)p;
299 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
300 p += lstrlenW((LPCWSTR)p) + 1;
302 if (dwFlags & PSP_USETITLE)
304 if ( !HIWORD( lppsp->pszTitle ) )
308 if (LoadStringA( lppsp->hInstance, (UINT)lppsp->pszTitle,szTitle,256 )) {
309 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(), 0, szTitle );
311 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(), 0, "(null)" );
312 FIXME("Could not load resource #%04x?\n",LOWORD(lppsp->pszTitle));
316 psInfo->proppage[index].pszText = HEAP_strdupAtoW(GetProcessHeap(),
322 * Build the image list for icons
324 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
327 int icon_cx = GetSystemMetrics(SM_CXSMICON);
328 int icon_cy = GetSystemMetrics(SM_CYSMICON);
330 if (dwFlags & PSP_USEICONID)
331 hIcon = LoadImageA(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
332 icon_cx, icon_cy, LR_DEFAULTCOLOR);
334 hIcon = lppsp->u2.hIcon;
338 if (psInfo->hImageList == 0 )
339 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
341 ImageList_AddIcon(psInfo->hImageList, hIcon);
350 /******************************************************************************
351 * PROPSHEET_CreateDialog
353 * Creates the actual property sheet.
355 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
362 WORD resID = IDD_PROPSHEET;
365 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
368 if(!(hRes = FindResourceA(COMCTL32_hModule,
369 MAKEINTRESOURCEA(resID),
373 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
377 * Make a copy of the dialog template.
379 resSize = SizeofResource(COMCTL32_hModule, hRes);
381 temp = COMCTL32_Alloc(resSize);
386 memcpy(temp, template, resSize);
388 if (psInfo->useCallback)
389 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
391 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
392 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
393 (LPDLGTEMPLATEA) temp,
394 psInfo->ppshheader.hwndParent,
395 (DLGPROC) PROPSHEET_DialogProc,
398 ret = CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
399 (LPDLGTEMPLATEA) temp,
400 psInfo->ppshheader.hwndParent,
401 (DLGPROC) PROPSHEET_DialogProc,
409 /******************************************************************************
410 * PROPSHEET_SizeMismatch
412 * Verify that the tab control and the "largest" property sheet page dlg. template
415 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
417 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
418 RECT rcOrigTab, rcPage;
423 GetClientRect(hwndTabCtrl, &rcOrigTab);
424 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
425 rcOrigTab.right, rcOrigTab.bottom);
430 rcPage.left = psInfo->x;
431 rcPage.top = psInfo->y;
432 rcPage.right = psInfo->width;
433 rcPage.bottom = psInfo->height;
435 MapDialogRect(hwndDlg, &rcPage);
436 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
437 rcPage.right, rcPage.bottom);
439 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
441 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
447 /******************************************************************************
448 * PROPSHEET_IsTooSmallWizard
450 * Verify that the default property sheet is big enough.
452 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
454 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
455 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
456 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
458 GetClientRect(hwndDlg, &rcSheetClient);
459 GetWindowRect(hwndDlg, &rcSheetRect);
460 GetWindowRect(hwndLine, &rcLine);
462 /* Remove the space below the sunken line */
463 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
465 /* Remove the buffer zone all around the edge */
466 rcSheetClient.bottom -= (padding.y * 2);
467 rcSheetClient.right -= (padding.x * 2);
472 rcPage.left = psInfo->x;
473 rcPage.top = psInfo->y;
474 rcPage.right = psInfo->width;
475 rcPage.bottom = psInfo->height;
477 MapDialogRect(hwndDlg, &rcPage);
478 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
479 rcPage.right, rcPage.bottom);
481 if (rcPage.right > rcSheetClient.right)
484 if (rcPage.bottom > rcSheetClient.bottom)
490 /******************************************************************************
491 * PROPSHEET_AdjustSize
493 * Resizes the property sheet and the tab control to fit the largest page.
495 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
497 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
498 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
500 int tabOffsetX, tabOffsetY, buttonHeight;
501 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
504 /* Get the height of buttons */
505 GetClientRect(hwndButton, &rc);
506 buttonHeight = rc.bottom;
513 rc.right = psInfo->width;
514 rc.bottom = psInfo->height;
516 MapDialogRect(hwndDlg, &rc);
518 /* retrieve the dialog units */
519 units.left = units.right = 4;
520 units.top = units.bottom = 8;
521 MapDialogRect(hwndDlg, &units);
524 * Resize the tab control.
526 GetClientRect(hwndTabCtrl,&tabRect);
528 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
530 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
532 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
533 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
536 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
538 rc.right = rc.left + tabRect.right - tabRect.left;
539 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
542 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
544 tabOffsetX = -(rc.left);
545 tabOffsetY = -(rc.top);
549 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
550 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
552 GetClientRect(hwndTabCtrl, &rc);
554 TRACE("tab client rc %d %d %d %d\n",
555 rc.left, rc.top, rc.right, rc.bottom);
557 rc.right += ((padding.x * 2) + tabOffsetX);
558 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
561 * Resize the property sheet.
563 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
564 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
568 /******************************************************************************
569 * PROPSHEET_AdjustSizeWizard
571 * Resizes the property sheet to fit the largest page.
573 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
575 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
576 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
577 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
579 int buttonHeight, lineHeight;
580 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
583 /* Get the height of buttons */
584 GetClientRect(hwndButton, &rc);
585 buttonHeight = rc.bottom;
587 GetClientRect(hwndLine, &rc);
588 lineHeight = rc.bottom;
590 /* retrieve the dialog units */
591 units.left = units.right = 4;
592 units.top = units.bottom = 8;
593 MapDialogRect(hwndDlg, &units);
600 rc.right = psInfo->width;
601 rc.bottom = psInfo->height;
603 MapDialogRect(hwndDlg, &rc);
605 GetClientRect(hwndTabCtrl,&tabRect);
607 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
609 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
610 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
613 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
615 rc.right = rc.left + tabRect.right - tabRect.left;
616 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
619 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
622 rc.right += (padding.x * 2);
623 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
626 * Resize the property sheet.
628 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
629 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
633 /******************************************************************************
634 * PROPSHEET_AdjustButtons
636 * Adjusts the buttons' positions.
638 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
640 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
644 int buttonWidth, buttonHeight;
645 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
647 if (psInfo->hasApply)
654 * Obtain the size of the buttons.
656 GetClientRect(hwndButton, &rcSheet);
657 buttonWidth = rcSheet.right;
658 buttonHeight = rcSheet.bottom;
661 * Get the size of the property sheet.
663 GetClientRect(hwndParent, &rcSheet);
666 * All buttons will be at this y coordinate.
668 y = rcSheet.bottom - (padding.y + buttonHeight);
671 * Position OK button.
673 hwndButton = GetDlgItem(hwndParent, IDOK);
675 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
677 SetWindowPos(hwndButton, 0, x, y, 0, 0,
678 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
681 * Position Cancel button.
683 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
685 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
687 SetWindowPos(hwndButton, 0, x, y, 0, 0,
688 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
691 * Position Apply button.
693 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
695 if (psInfo->hasApply)
698 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
700 x = rcSheet.right - (padding.x + buttonWidth);
702 SetWindowPos(hwndButton, 0, x, y, 0, 0,
703 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
705 EnableWindow(hwndButton, FALSE);
708 ShowWindow(hwndButton, SW_HIDE);
711 * Position Help button.
713 hwndButton = GetDlgItem(hwndParent, IDHELP);
717 x = rcSheet.right - (padding.x + buttonWidth);
719 SetWindowPos(hwndButton, 0, x, y, 0, 0,
720 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
723 ShowWindow(hwndButton, SW_HIDE);
728 /******************************************************************************
729 * PROPSHEET_AdjustButtonsWizard
731 * Adjusts the buttons' positions.
733 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
734 PropSheetInfo* psInfo)
736 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
737 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
741 int buttonWidth, buttonHeight, lineHeight, lineWidth;
742 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
748 * Obtain the size of the buttons.
750 GetClientRect(hwndButton, &rcSheet);
751 buttonWidth = rcSheet.right;
752 buttonHeight = rcSheet.bottom;
754 GetClientRect(hwndLine, &rcSheet);
755 lineHeight = rcSheet.bottom;
758 * Get the size of the property sheet.
760 GetClientRect(hwndParent, &rcSheet);
763 * All buttons will be at this y coordinate.
765 y = rcSheet.bottom - (padding.y + buttonHeight);
768 * Position the Next and the Finish buttons.
770 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
772 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
774 SetWindowPos(hwndButton, 0, x, y, 0, 0,
775 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
777 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
779 SetWindowPos(hwndButton, 0, x, y, 0, 0,
780 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
782 ShowWindow(hwndButton, SW_HIDE);
785 * Position the Back button.
787 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
791 SetWindowPos(hwndButton, 0, x, y, 0, 0,
792 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
795 * Position the Cancel button.
797 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
799 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
801 SetWindowPos(hwndButton, 0, x, y, 0, 0,
802 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
805 * Position Help button.
807 hwndButton = GetDlgItem(hwndParent, IDHELP);
811 x = rcSheet.right - (padding.x + buttonWidth);
813 SetWindowPos(hwndButton, 0, x, y, 0, 0,
814 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
817 ShowWindow(hwndButton, SW_HIDE);
820 * Position and resize the sunken line.
823 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
825 GetClientRect(hwndParent, &rcSheet);
826 lineWidth = rcSheet.right - (padding.x * 2);
828 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
829 SWP_NOZORDER | SWP_NOACTIVATE);
834 /******************************************************************************
835 * PROPSHEET_GetPaddingInfo
837 * Returns the layout information.
839 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
841 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
844 PADDING_INFO padding;
846 GetWindowRect(hwndTab, &rcTab);
851 ScreenToClient(hwndDlg, &tl);
859 /******************************************************************************
860 * PROPSHEET_GetPaddingInfoWizard
862 * Returns the layout information.
863 * Vertical spacing is the distance between the line and the buttons.
864 * Do NOT use the Help button to gather padding information when it isn't mapped
865 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
866 * for it in this case !
867 * FIXME: I'm not sure about any other coordinate problems with these evil
868 * buttons. Fix it in case additional problems appear or maybe calculate
869 * a padding in a completely different way, as this is somewhat messy.
871 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
874 PADDING_INFO padding;
878 POINT ptButton, ptLine;
887 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
889 idButton = IDC_NEXT_BUTTON;
893 /* hopefully this is ok */
898 hwndControl = GetDlgItem(hwndDlg, idButton);
899 GetWindowRect(hwndControl, &rc);
901 ptButton.x = rc.left;
904 ScreenToClient(hwndDlg, &ptButton);
907 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
908 GetWindowRect(hwndControl, &rc);
911 ptLine.y = rc.bottom;
913 ScreenToClient(hwndDlg, &ptLine);
915 padding.y = ptButton.y - ptLine.y;
918 ERR("padding negative ! Please report this !\n");
920 /* this is most probably not correct, but the best we have now */
921 padding.x = padding.y;
925 /******************************************************************************
926 * PROPSHEET_CreateTabControl
928 * Insert the tabs in the tab control.
930 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
931 PropSheetInfo * psInfo)
933 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
937 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
940 item.mask = TCIF_TEXT;
941 item.pszText = tabtext;
942 item.cchTextMax = MAX_TABTEXT_LENGTH;
944 nTabs = psInfo->nPages;
947 * Set the image list for icons.
949 if (psInfo->hImageList)
951 SendMessageA(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
954 for (i = 0; i < nTabs; i++)
956 if ( psInfo->proppage[i].hasIcon )
958 item.mask |= TCIF_IMAGE;
959 item.iImage = iImage++;
963 item.mask &= ~TCIF_IMAGE;
966 WideCharToMultiByte(CP_ACP, 0,
967 (LPCWSTR)psInfo->proppage[i].pszText,
968 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
970 SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item);
976 /******************************************************************************
977 * PROPSHEET_CreatePage
981 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
983 const PropSheetInfo * psInfo,
984 LPCPROPSHEETPAGEA ppshpage)
986 DLGTEMPLATE* pTemplate;
989 PropPageInfo* ppInfo = psInfo->proppage;
990 PADDING_INFO padding;
991 UINT pageWidth,pageHeight;
995 TRACE("index %d\n", index);
997 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
998 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
1004 hResource = FindResourceA(ppshpage->hInstance,
1005 ppshpage->u.pszTemplate,
1010 resSize = SizeofResource(ppshpage->hInstance, hResource);
1012 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1016 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1018 * Make a copy of the dialog template to make it writable
1020 temp = COMCTL32_Alloc(resSize);
1024 memcpy(temp, pTemplate, resSize);
1028 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1030 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1031 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1032 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1033 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1034 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1035 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1036 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1040 pTemplate->style |= WS_CHILD | DS_CONTROL;
1041 pTemplate->style &= ~DS_MODALFRAME;
1042 pTemplate->style &= ~WS_CAPTION;
1043 pTemplate->style &= ~WS_SYSMENU;
1044 pTemplate->style &= ~WS_POPUP;
1045 pTemplate->style &= ~WS_DISABLED;
1046 pTemplate->style &= ~WS_VISIBLE;
1049 if (psInfo->proppage[index].useCallback)
1050 (*(ppshpage->pfnCallback))(hwndParent,
1052 (LPPROPSHEETPAGEA)ppshpage);
1054 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1057 ppshpage->pfnDlgProc,
1059 /* Free a no more needed copy */
1061 COMCTL32_Free(temp);
1063 ppInfo[index].hwndPage = hwndPage;
1065 rc.left = psInfo->x;
1067 rc.right = psInfo->width;
1068 rc.bottom = psInfo->height;
1070 MapDialogRect(hwndParent, &rc);
1072 pageWidth = rc.right - rc.left;
1073 pageHeight = rc.bottom - rc.top;
1075 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
1076 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1080 * Ask the Tab control to fit this page in.
1083 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1084 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1085 padding = PROPSHEET_GetPaddingInfo(hwndParent);
1088 SetWindowPos(hwndPage, HWND_TOP,
1089 rc.left + padding.x,
1091 pageWidth, pageHeight, 0);
1096 /******************************************************************************
1097 * PROPSHEET_ShowPage
1099 * Displays or creates the specified page.
1101 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1105 TRACE("active_page %d, index %d\n", psInfo->active_page, index);
1106 if (index == psInfo->active_page)
1108 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1109 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1113 if (psInfo->proppage[index].hwndPage == 0)
1115 LPCPROPSHEETPAGEA ppshpage;
1117 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[index].hpage;
1118 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1121 if (psInfo->active_page != -1)
1122 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1124 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1126 /* Synchronize current selection with tab control
1127 * It seems to be needed even in case of PSH_WIZARD (no tab controls there) */
1128 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1129 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1131 psInfo->active_page = index;
1132 psInfo->activeValid = TRUE;
1137 /******************************************************************************
1140 static BOOL PROPSHEET_Back(HWND hwndDlg)
1145 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1149 TRACE("active_page %d\n", psInfo->active_page);
1150 if (psInfo->active_page < 0)
1153 psn.hdr.code = PSN_WIZBACK;
1154 psn.hdr.hwndFrom = hwndDlg;
1158 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1160 result = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1164 if (psInfo->active_page > 0)
1166 res = PROPSHEET_CanSetCurSel(hwndDlg);
1169 res = PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page - 1, -1, 0);
1176 /******************************************************************************
1179 static BOOL PROPSHEET_Next(HWND hwndDlg)
1183 LRESULT msgResult = 0;
1184 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1187 TRACE("active_page %d\n", psInfo->active_page);
1188 if (psInfo->active_page < 0)
1191 psn.hdr.code = PSN_WIZNEXT;
1192 psn.hdr.hwndFrom = hwndDlg;
1196 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1198 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1199 if (msgResult == -1)
1202 if(PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1204 PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page + 1, 1, 0);
1210 /******************************************************************************
1213 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1217 LRESULT msgResult = 0;
1218 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1221 TRACE("active_page %d\n", psInfo->active_page);
1222 if (psInfo->active_page < 0)
1225 psn.hdr.code = PSN_WIZFINISH;
1226 psn.hdr.hwndFrom = hwndDlg;
1230 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1232 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1234 TRACE("msg result %ld\n", msgResult);
1239 if (psInfo->isModeless)
1240 psInfo->activeValid = FALSE;
1242 EndDialog(hwndDlg, TRUE);
1247 /******************************************************************************
1250 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1256 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1259 TRACE("active_page %d\n", psInfo->active_page);
1260 if (psInfo->active_page < 0)
1263 psn.hdr.hwndFrom = hwndDlg;
1269 * Send PSN_KILLACTIVE to the current page.
1271 psn.hdr.code = PSN_KILLACTIVE;
1273 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1275 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1279 * Send PSN_APPLY to all pages.
1281 psn.hdr.code = PSN_APPLY;
1282 psn.lParam = lParam;
1284 for (i = 0; i < psInfo->nPages; i++)
1286 hwndPage = psInfo->proppage[i].hwndPage;
1289 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1290 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1297 psInfo->activeValid = FALSE;
1299 else if(psInfo->active_page >= 0)
1301 psn.hdr.code = PSN_SETACTIVE;
1303 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1304 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1310 /******************************************************************************
1313 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1315 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1321 TRACE("active_page %d\n", psInfo->active_page);
1322 if (psInfo->active_page < 0)
1325 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1326 psn.hdr.code = PSN_QUERYCANCEL;
1327 psn.hdr.hwndFrom = hwndDlg;
1331 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1334 psn.hdr.code = PSN_RESET;
1335 psn.lParam = lParam;
1337 for (i = 0; i < psInfo->nPages; i++)
1339 hwndPage = psInfo->proppage[i].hwndPage;
1342 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1345 if (psInfo->isModeless)
1347 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1348 psInfo->activeValid = FALSE;
1351 EndDialog(hwndDlg, FALSE);
1354 /******************************************************************************
1357 static void PROPSHEET_Help(HWND hwndDlg)
1359 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1364 TRACE("active_page %d\n", psInfo->active_page);
1365 if (psInfo->active_page < 0)
1368 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1369 psn.hdr.code = PSN_HELP;
1370 psn.hdr.hwndFrom = hwndDlg;
1374 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1377 /******************************************************************************
1380 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1383 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1387 if (!psInfo) return;
1389 * Set the dirty flag of this page.
1391 for (i = 0; i < psInfo->nPages; i++)
1393 if (psInfo->proppage[i].hwndPage == hwndDirtyPage)
1394 psInfo->proppage[i].isDirty = TRUE;
1398 * Enable the Apply button.
1400 if (psInfo->hasApply)
1402 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1404 EnableWindow(hwndApplyBtn, TRUE);
1408 /******************************************************************************
1409 * PROPSHEET_UnChanged
1411 static void PROPSHEET_UnChanged(HWND hwndDlg, HWND hwndCleanPage)
1414 BOOL noPageDirty = TRUE;
1415 HWND hwndApplyBtn = GetDlgItem(hwndDlg, IDC_APPLY_BUTTON);
1416 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1420 if ( !psInfo ) return;
1421 for (i = 0; i < psInfo->nPages; i++)
1423 /* set the specified page as clean */
1424 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1425 psInfo->proppage[i].isDirty = FALSE;
1427 /* look to see if there's any dirty pages */
1428 if (psInfo->proppage[i].isDirty)
1429 noPageDirty = FALSE;
1433 * Disable Apply button.
1436 EnableWindow(hwndApplyBtn, FALSE);
1439 /******************************************************************************
1440 * PROPSHEET_PressButton
1442 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1444 TRACE("buttonID %d\n", buttonID);
1447 case PSBTN_APPLYNOW:
1448 SendMessageA(hwndDlg, WM_COMMAND, IDC_APPLY_BUTTON, 0);
1451 PROPSHEET_Back(hwndDlg);
1454 SendMessageA(hwndDlg, WM_COMMAND, IDCANCEL, 0);
1457 PROPSHEET_Finish(hwndDlg);
1460 SendMessageA(hwndDlg, WM_COMMAND, IDHELP, 0);
1463 PROPSHEET_Next(hwndDlg);
1466 SendMessageA(hwndDlg, WM_COMMAND, IDOK, 0);
1469 FIXME("Invalid button index %d\n", buttonID);
1474 /*************************************************************************
1475 * BOOL PROPSHEET_CanSetCurSel [Internal]
1477 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1480 * hwndDlg [I] handle to a Dialog hWnd
1483 * TRUE if Current Selection can change
1487 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1489 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1495 TRACE("active_page %d\n", psInfo->active_page);
1502 if (psInfo->active_page < 0)
1509 * Notify the current page.
1511 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1512 psn.hdr.code = PSN_KILLACTIVE;
1513 psn.hdr.hwndFrom = hwndDlg;
1517 res = !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1520 TRACE("<-- %d\n", res);
1524 /******************************************************************************
1525 * PROPSHEET_SetCurSel
1527 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1530 HPROPSHEETPAGE hpage
1533 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfoStr);
1534 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1536 TRACE("index %d, skipdir %d, hpage %p\n", index, skipdir, hpage);
1537 /* hpage takes precedence over index */
1539 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1541 if (index < 0 || index >= psInfo->nPages)
1543 TRACE("Could not find page to select!\n");
1551 psn.hdr.code = PSN_SETACTIVE;
1552 psn.hdr.hwndFrom = hwndDlg;
1556 if (!psInfo->proppage[index].hwndPage) {
1557 LPCPROPSHEETPAGEA ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[index].hpage;
1558 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1561 result = SendMessageA(psInfo->proppage[index].hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1568 FIXME("Tried to skip before first property sheet page!\n");
1571 if (index >= psInfo->nPages) {
1572 FIXME("Tried to skip after last property sheet page!\n");
1573 index = psInfo->nPages-1;
1579 * Display the new page.
1581 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1583 if (psInfo->proppage[index].hasHelp)
1584 EnableWindow(hwndHelp, TRUE);
1586 EnableWindow(hwndHelp, FALSE);
1591 /******************************************************************************
1592 * PROPSHEET_SetTitleA
1594 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1596 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfoStr);
1599 TRACE("'%s' (style %08lx)\n", lpszText, dwStyle);
1600 if (HIWORD(lpszText) == 0) {
1601 if (!LoadStringA(psInfo->ppshheader.hInstance,
1602 LOWORD(lpszText), szTitle, sizeof(szTitle)-1))
1606 if (dwStyle & PSH_PROPTITLE)
1609 int lentitle = strlen(lpszText);
1610 int lenprop = strlen(psInfo->strPropertiesFor);
1612 dest = COMCTL32_Alloc(lentitle + lenprop + 1);
1613 strcpy(dest, psInfo->strPropertiesFor);
1614 strcat(dest, lpszText);
1616 SetWindowTextA(hwndDlg, dest);
1617 COMCTL32_Free(dest);
1620 SetWindowTextA(hwndDlg, lpszText);
1623 /******************************************************************************
1624 * PROPSHEET_SetFinishTextA
1626 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1628 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1630 TRACE("'%s'\n", lpszText);
1631 /* Set text, show and enable the Finish button */
1632 SetWindowTextA(hwndButton, lpszText);
1633 ShowWindow(hwndButton, SW_SHOW);
1634 EnableWindow(hwndButton, TRUE);
1636 /* Make it default pushbutton */
1637 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1639 /* Hide Back button */
1640 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1641 ShowWindow(hwndButton, SW_HIDE);
1643 /* Hide Next button */
1644 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1645 ShowWindow(hwndButton, SW_HIDE);
1648 /******************************************************************************
1649 * PROPSHEET_QuerySiblings
1651 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1652 WPARAM wParam, LPARAM lParam)
1656 LRESULT msgResult = 0;
1657 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1660 while ((i < psInfo->nPages) && (msgResult == 0))
1662 hwndPage = psInfo->proppage[i].hwndPage;
1663 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1671 /******************************************************************************
1674 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1675 HPROPSHEETPAGE hpage)
1677 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1679 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1681 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
1682 LPCPROPSHEETPAGEA ppsp = (LPCPROPSHEETPAGEA)hpage;
1684 TRACE("hpage %p\n", hpage);
1686 * Allocate and fill in a new PropPageInfo entry.
1688 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1689 sizeof(PropPageInfo) *
1690 (psInfo->nPages + 1));
1691 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
1694 psInfo->proppage[psInfo->nPages].hpage = hpage;
1696 if (ppsp->dwFlags & PSP_PREMATURE)
1698 /* Create the page but don't show it */
1699 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
1703 * Add a new tab to the tab control.
1705 item.mask = TCIF_TEXT;
1706 item.pszText = tabtext;
1707 item.cchTextMax = MAX_TABTEXT_LENGTH;
1709 WideCharToMultiByte(CP_ACP, 0,
1710 (LPCWSTR)psInfo->proppage[psInfo->nPages].pszText,
1711 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
1713 SendMessageA(hwndTabControl, TCM_INSERTITEMA, psInfo->nPages + 1,
1718 /* If it is the only page - show it */
1719 if(psInfo->nPages == 1)
1720 PROPSHEET_SetCurSel(hwndDlg, 0, 1, 0);
1724 /******************************************************************************
1725 * PROPSHEET_RemovePage
1727 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
1729 HPROPSHEETPAGE hpage)
1731 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1733 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1734 PropPageInfo* oldPages;
1736 TRACE("index %d, hpage %p\n", index, hpage);
1740 oldPages = psInfo->proppage;
1742 * hpage takes precedence over index.
1746 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1749 /* Make sure that index is within range */
1750 if (index < 0 || index >= psInfo->nPages)
1752 TRACE("Could not find page to remove!\n");
1756 TRACE("total pages %d removing page %d active page %d\n",
1757 psInfo->nPages, index, psInfo->active_page);
1759 * Check if we're removing the active page.
1761 if (index == psInfo->active_page)
1763 if (psInfo->nPages > 1)
1767 /* activate previous page */
1768 PROPSHEET_SetCurSel(hwndDlg, index - 1, -1, 0);
1772 /* activate the next page */
1773 PROPSHEET_SetCurSel(hwndDlg, index + 1, 1, 0);
1774 psInfo->active_page = index;
1779 psInfo->active_page = -1;
1780 if (!psInfo->isModeless)
1782 EndDialog(hwndDlg, FALSE);
1787 else if (index < psInfo->active_page)
1788 psInfo->active_page--;
1790 /* Destroy page dialog window */
1791 DestroyWindow(psInfo->proppage[index].hwndPage);
1793 /* Free page resources */
1794 if(psInfo->proppage[index].hpage)
1796 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[index].hpage;
1798 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
1799 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
1801 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
1804 /* Remove the tab */
1805 SendMessageA(hwndTabControl, TCM_DELETEITEM, index, 0);
1808 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
1811 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
1813 if (index < psInfo->nPages)
1814 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
1815 (psInfo->nPages - index) * sizeof(PropPageInfo));
1817 COMCTL32_Free(oldPages);
1822 /******************************************************************************
1823 * PROPSHEET_SetWizButtons
1825 * This code will work if (and assumes that) the Next button is on top of the
1826 * Finish button. ie. Finish comes after Next in the Z order.
1827 * This means make sure the dialog template reflects this.
1830 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
1832 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1833 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1834 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1836 TRACE("%ld\n", dwFlags);
1838 EnableWindow(hwndBack, FALSE);
1839 EnableWindow(hwndNext, FALSE);
1840 EnableWindow(hwndFinish, FALSE);
1842 if (dwFlags & PSWIZB_BACK)
1843 EnableWindow(hwndBack, TRUE);
1845 if (dwFlags & PSWIZB_NEXT)
1847 /* Hide the Finish button */
1848 ShowWindow(hwndFinish, SW_HIDE);
1850 /* Show and enable the Next button */
1851 ShowWindow(hwndNext, SW_SHOW);
1852 EnableWindow(hwndNext, TRUE);
1854 /* Set the Next button as the default pushbutton */
1855 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1858 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
1860 /* Hide the Next button */
1861 ShowWindow(hwndNext, SW_HIDE);
1863 /* Show the Finish button */
1864 ShowWindow(hwndFinish, SW_SHOW);
1866 if (dwFlags & PSWIZB_FINISH)
1867 EnableWindow(hwndFinish, TRUE);
1869 /* Set the Finish button as the default pushbutton */
1870 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1874 /******************************************************************************
1875 * PROPSHEET_GetPageIndex
1877 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
1878 * the array of PropPageInfo.
1880 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
1885 TRACE("hpage %p\n", hpage);
1886 while ((index < psInfo->nPages) && (found == FALSE))
1888 if (psInfo->proppage[index].hpage == hpage)
1900 /******************************************************************************
1903 static void PROPSHEET_CleanUp(HWND hwndDlg)
1906 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropA(hwndDlg,
1910 if (HIWORD(psInfo->ppshheader.pszCaption))
1911 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
1913 for (i = 0; i < psInfo->nPages; i++)
1915 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
1917 if(psInfo->proppage[i].hwndPage)
1918 DestroyWindow(psInfo->proppage[i].hwndPage);
1922 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
1923 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
1925 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
1929 COMCTL32_Free(psInfo->proppage);
1930 COMCTL32_Free(psInfo->strPropertiesFor);
1931 ImageList_Destroy(psInfo->hImageList);
1933 GlobalFree((HGLOBAL)psInfo);
1936 /******************************************************************************
1937 * PropertySheet (COMCTL32.87)
1938 * PropertySheetA (COMCTL32.88)
1940 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
1943 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
1944 sizeof(PropSheetInfo));
1948 PROPSHEET_CollectSheetInfo(lppsh, psInfo);
1950 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
1952 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
1954 for (n = i = 0; i < lppsh->nPages; i++, n++)
1956 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
1957 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
1960 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
1961 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
1964 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEA)psInfo->proppage[n].hpage,
1967 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
1968 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
1974 bRet = PROPSHEET_CreateDialog(psInfo);
1979 /******************************************************************************
1980 * PropertySheetW (COMCTL32.89)
1982 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader)
1984 FIXME("(%p): stub\n", propertySheetHeader);
1989 /******************************************************************************
1990 * CreatePropertySheetPage (COMCTL32.18)
1991 * CreatePropertySheetPageA (COMCTL32.19)
1993 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
1994 LPCPROPSHEETPAGEA lpPropSheetPage)
1996 PROPSHEETPAGEA* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
1998 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
2000 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
2002 ppsp->u.pszTemplate = HeapAlloc( GetProcessHeap(),0,strlen(lpPropSheetPage->u.pszTemplate)+1 );
2003 strcpy( (char *)ppsp->u.pszTemplate, lpPropSheetPage->u.pszTemplate );
2005 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
2007 ppsp->u2.pszIcon = HeapAlloc( GetProcessHeap(), 0, strlen(lpPropSheetPage->u2.pszIcon)+1 );
2008 strcpy( (char *)ppsp->u2.pszIcon, lpPropSheetPage->u2.pszIcon );
2011 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
2013 ppsp->pszTitle = HeapAlloc( GetProcessHeap(), 0, strlen(lpPropSheetPage->pszTitle)+1 );
2014 strcpy( (char *)ppsp->pszTitle, lpPropSheetPage->pszTitle );
2016 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
2017 ppsp->pszTitle = NULL;
2019 return (HPROPSHEETPAGE)ppsp;
2022 /******************************************************************************
2023 * CreatePropertySheetPageW (COMCTL32.20)
2025 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
2027 FIXME("(%p): stub\n", lpPropSheetPage);
2032 /******************************************************************************
2033 * DestroyPropertySheetPage (COMCTL32.24)
2035 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2037 PROPSHEETPAGEA *psp = (PROPSHEETPAGEA *)hPropPage;
2042 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2043 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2045 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2046 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2048 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2049 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2051 COMCTL32_Free(hPropPage);
2056 /******************************************************************************
2057 * PROPSHEET_IsDialogMessage
2059 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2061 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd, PropSheetInfoStr);
2064 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2067 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2070 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2072 if (!(dlgCode & DLGC_WANTMESSAGE))
2074 switch (lpMsg->wParam)
2077 if (GetKeyState(VK_SHIFT) & 0x8000)
2083 case VK_NEXT: new_page = 1; break;
2084 case VK_PRIOR: new_page = -1; break;
2090 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2092 new_page += psInfo->active_page;
2095 new_page = psInfo->nPages - 1;
2096 else if (new_page >= psInfo->nPages)
2099 PROPSHEET_SetCurSel(hwnd, new_page, 1, 0);
2106 return IsDialogMessageA(hwnd, lpMsg);
2109 /******************************************************************************
2110 * PROPSHEET_DialogProc
2113 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2119 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2120 char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH);
2121 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2122 LPCPROPSHEETPAGEA ppshpage;
2125 SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2128 * psInfo->hwnd is not being used by WINE code - it exists
2129 * for compatibility with "real" Windoze. The same about
2130 * SetWindowLong - WINE is only using the PropSheetInfoStr
2133 psInfo->hwnd = hwnd;
2134 SetWindowLongA(hwnd,DWL_USER,(LONG)psInfo);
2137 * Small icon in the title bar.
2139 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2140 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2143 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2144 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2146 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2147 hIcon = LoadImageA(psInfo->ppshheader.hInstance,
2148 psInfo->ppshheader.u.pszIcon,
2153 hIcon = psInfo->ppshheader.u.hIcon;
2155 SendMessageA(hwnd, WM_SETICON, 0, hIcon);
2158 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2159 SendMessageA(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2161 psInfo->strPropertiesFor = strCaption;
2163 GetWindowTextA(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2165 PROPSHEET_CreateTabControl(hwnd, psInfo);
2167 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
2169 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2171 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2172 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2177 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2179 PROPSHEET_AdjustSize(hwnd, psInfo);
2180 PROPSHEET_AdjustButtons(hwnd, psInfo);
2184 if (psInfo->useCallback)
2185 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2186 PSCB_INITIALIZED, (LPARAM)0);
2188 idx = psInfo->active_page;
2189 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[idx].hpage;
2190 psInfo->active_page = -1;
2192 PROPSHEET_SetCurSel(hwnd, idx, 1, psInfo->proppage[idx].hpage);
2194 /* doing TCM_SETCURSEL seems to be needed even in case of PSH_WIZARD,
2195 * as some programs call TCM_GETCURSEL to get the current selection
2196 * from which to switch to the next page */
2197 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2199 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2200 psInfo->ppshheader.hInstance)
2204 if (LoadStringA(psInfo->ppshheader.hInstance,
2205 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2206 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags, szText);
2210 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags,
2211 psInfo->ppshheader.pszCaption);
2218 PROPSHEET_CleanUp(hwnd);
2222 PROPSHEET_Cancel(hwnd, 1);
2227 WORD wID = LOWORD(wParam);
2232 case IDC_APPLY_BUTTON:
2234 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2236 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2241 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2245 if (psInfo->restartWindows)
2246 result = ID_PSRESTARTWINDOWS;
2248 /* reboot system takes precedence over restart windows */
2249 if (psInfo->rebootSystem)
2250 result = ID_PSREBOOTSYSTEM;
2252 if (psInfo->isModeless)
2253 psInfo->activeValid = FALSE;
2255 EndDialog(hwnd, result);
2258 EnableWindow(hwndApplyBtn, FALSE);
2263 case IDC_BACK_BUTTON:
2264 PROPSHEET_Back(hwnd);
2267 case IDC_NEXT_BUTTON:
2268 PROPSHEET_Next(hwnd);
2271 case IDC_FINISH_BUTTON:
2272 PROPSHEET_Finish(hwnd);
2276 PROPSHEET_Cancel(hwnd, 0);
2280 PROPSHEET_Help(hwnd);
2289 NMHDR* pnmh = (LPNMHDR) lParam;
2291 if (pnmh->code == TCN_SELCHANGE)
2293 int index = SendMessageA(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2294 PROPSHEET_SetCurSel(hwnd, index, 1, 0);
2297 if(pnmh->code == TCN_SELCHANGING)
2299 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2300 SetWindowLongA(hwnd, DWL_MSGRESULT, !bRet);
2307 case PSM_GETCURRENTPAGEHWND:
2309 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2313 if (psInfo->activeValid && psInfo->active_page != -1)
2314 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2316 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndPage);
2322 PROPSHEET_Changed(hwnd, (HWND)wParam);
2326 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2329 case PSM_GETTABCONTROL:
2331 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2333 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2342 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2343 if(msgResult != FALSE)
2345 msgResult = PROPSHEET_SetCurSel(hwnd,
2348 (HPROPSHEETPAGE)lParam);
2351 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2356 case PSM_CANCELTOCLOSE:
2358 char buf[MAX_BUTTONTEXT_LENGTH];
2359 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2360 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2362 EnableWindow(hwndCancel, FALSE);
2363 if (LoadStringA(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2364 SetWindowTextA(hwndOK, buf);
2369 case PSM_RESTARTWINDOWS:
2371 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2374 psInfo->restartWindows = TRUE;
2378 case PSM_REBOOTSYSTEM:
2380 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2383 psInfo->rebootSystem = TRUE;
2388 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2393 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2395 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2400 case PSM_QUERYSIBLINGS:
2402 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2404 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2412 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2413 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2414 * on success or FALSE otherwise, as specified on MSDN Online.
2415 * Also see the MFC code for
2416 * CPropertySheet::AddPage(CPropertyPage* pPage).
2419 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2421 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2426 case PSM_REMOVEPAGE:
2427 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2430 case PSM_ISDIALOGMESSAGE:
2432 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2433 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2437 case PSM_PRESSBUTTON:
2438 PROPSHEET_PressButton(hwnd, (int)wParam);
2441 case PSM_SETFINISHTEXTA:
2442 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2445 case PSM_SETWIZBUTTONS:
2446 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2450 FIXME("Unimplemented msg PSM_SETTITLE32W\n");
2453 case PSM_SETCURSELID:
2454 FIXME("Unimplemented msg PSM_SETCURSELID\n");
2457 case PSM_SETFINISHTEXTW:
2458 FIXME("Unimplemented msg PSM_SETFINISHTEXT32W\n");