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,
116 HPROPSHEETPAGE hpage);
117 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
118 WPARAM wParam, LPARAM lParam);
119 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
120 HPROPSHEETPAGE hpage);
122 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
124 HPROPSHEETPAGE hpage);
125 static void PROPSHEET_CleanUp();
126 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo);
127 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags);
128 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo* psInfo);
129 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg);
132 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
134 DEFAULT_DEBUG_CHANNEL(propsheet);
136 /******************************************************************************
137 * PROPSHEET_CollectSheetInfo
139 * Collect relevant data.
141 static BOOL PROPSHEET_CollectSheetInfo(LPCPROPSHEETHEADERA lppsh,
142 PropSheetInfo * psInfo)
144 DWORD dwSize = min(lppsh->dwSize,sizeof(PROPSHEETHEADERA));
145 DWORD dwFlags = lppsh->dwFlags;
147 psInfo->hasHelp = dwFlags & PSH_HASHELP;
148 psInfo->hasApply = !(dwFlags & PSH_NOAPPLYNOW);
149 psInfo->useCallback = dwFlags & PSH_USECALLBACK;
150 psInfo->isModeless = dwFlags & PSH_MODELESS;
152 memcpy(&psInfo->ppshheader,lppsh,dwSize);
154 if (HIWORD(lppsh->pszCaption))
155 psInfo->ppshheader.pszCaption = HEAP_strdupA( GetProcessHeap(),
156 0, lppsh->pszCaption );
158 psInfo->nPages = lppsh->nPages;
160 if (dwFlags & PSH_USEPSTARTPAGE)
162 TRACE("PSH_USEPSTARTPAGE is on");
163 psInfo->active_page = 0;
166 psInfo->active_page = lppsh->u2.nStartPage;
168 if (psInfo->active_page < 0 || psInfo->active_page >= psInfo->nPages)
169 psInfo->active_page = 0;
171 psInfo->restartWindows = FALSE;
172 psInfo->rebootSystem = FALSE;
173 psInfo->hImageList = 0;
174 psInfo->activeValid = FALSE;
179 /******************************************************************************
180 * PROPSHEET_CollectPageInfo
182 * Collect property sheet data.
183 * With code taken from DIALOG_ParseTemplate32.
185 BOOL PROPSHEET_CollectPageInfo(LPCPROPSHEETPAGEA lppsp,
186 PropSheetInfo * psInfo,
189 DLGTEMPLATE* pTemplate;
194 psInfo->proppage[index].hpage = (HPROPSHEETPAGE)lppsp;
195 psInfo->proppage[index].hwndPage = 0;
196 psInfo->proppage[index].isDirty = FALSE;
199 * Process property page flags.
201 dwFlags = lppsp->dwFlags;
202 psInfo->proppage[index].useCallback = dwFlags & PSP_USECALLBACK;
203 psInfo->proppage[index].hasHelp = dwFlags & PSP_HASHELP;
204 psInfo->proppage[index].hasIcon = dwFlags & (PSP_USEHICON | PSP_USEICONID);
206 /* as soon as we have a page with the help flag, set the sheet flag on */
207 if (psInfo->proppage[index].hasHelp)
208 psInfo->hasHelp = TRUE;
211 * Process page template.
213 if (dwFlags & PSP_DLGINDIRECT)
214 pTemplate = (DLGTEMPLATE*)lppsp->u.pResource;
217 HRSRC hResource = FindResourceA(lppsp->hInstance,
218 lppsp->u.pszTemplate,
220 HGLOBAL hTemplate = LoadResource(lppsp->hInstance,
222 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
226 * Extract the size of the page and the caption.
231 p = (const WORD *)pTemplate;
233 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
235 /* DIALOGEX template */
239 p += 2; /* help ID */
240 p += 2; /* ext style */
245 /* DIALOG template */
248 p += 2; /* ext style */
254 width = (WORD)*p; p++;
255 height = (WORD)*p; p++;
257 /* remember the largest width and height */
258 if (width > psInfo->width)
259 psInfo->width = width;
261 if (height > psInfo->height)
262 psInfo->height = height;
274 p += lstrlenW( (LPCWSTR)p ) + 1;
288 p += lstrlenW( (LPCWSTR)p ) + 1;
292 /* Extract the caption */
293 psInfo->proppage[index].pszText = (LPCWSTR)p;
294 TRACE("Tab %d %s\n",index,debugstr_w((LPCWSTR)p));
295 p += lstrlenW((LPCWSTR)p) + 1;
297 if (dwFlags & PSP_USETITLE)
299 if ( !HIWORD( lppsp->pszTitle ) )
303 if ( !LoadStringA( lppsp->hInstance, (UINT) lppsp->pszTitle, szTitle, 256 ) )
306 psInfo->proppage[index].pszText = HEAP_strdupAtoW( GetProcessHeap(),
310 psInfo->proppage[index].pszText = HEAP_strdupAtoW(GetProcessHeap(),
316 * Build the image list for icons
318 if ((dwFlags & PSP_USEHICON) || (dwFlags & PSP_USEICONID))
321 int icon_cx = GetSystemMetrics(SM_CXSMICON);
322 int icon_cy = GetSystemMetrics(SM_CYSMICON);
324 if (dwFlags & PSP_USEICONID)
325 hIcon = LoadImageA(lppsp->hInstance, lppsp->u2.pszIcon, IMAGE_ICON,
326 icon_cx, icon_cy, LR_DEFAULTCOLOR);
328 hIcon = lppsp->u2.hIcon;
332 if (psInfo->hImageList == 0 )
333 psInfo->hImageList = ImageList_Create(icon_cx, icon_cy, ILC_COLOR, 1, 1);
335 ImageList_AddIcon(psInfo->hImageList, hIcon);
344 /******************************************************************************
345 * PROPSHEET_CreateDialog
347 * Creates the actual property sheet.
349 BOOL PROPSHEET_CreateDialog(PropSheetInfo* psInfo)
356 WORD resID = IDD_PROPSHEET;
358 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
361 if(!(hRes = FindResourceA(COMCTL32_hModule,
362 MAKEINTRESOURCEA(resID),
366 if(!(template = (LPVOID)LoadResource(COMCTL32_hModule, hRes)))
370 * Make a copy of the dialog template.
372 resSize = SizeofResource(COMCTL32_hModule, hRes);
374 temp = COMCTL32_Alloc(resSize);
379 memcpy(temp, template, resSize);
381 if (psInfo->useCallback)
382 (*(psInfo->ppshheader.pfnCallback))(0, PSCB_PRECREATE, (LPARAM)temp);
384 if (!(psInfo->ppshheader.dwFlags & PSH_MODELESS))
385 ret = DialogBoxIndirectParamA(psInfo->ppshheader.hInstance,
386 (LPDLGTEMPLATEA) temp,
387 psInfo->ppshheader.hwndParent,
388 (DLGPROC) PROPSHEET_DialogProc,
391 ret = CreateDialogIndirectParamA(psInfo->ppshheader.hInstance,
392 (LPDLGTEMPLATEA) temp,
393 psInfo->ppshheader.hwndParent,
394 (DLGPROC) PROPSHEET_DialogProc,
402 /******************************************************************************
403 * PROPSHEET_SizeMismatch
405 * Verify that the tab control and the "largest" property sheet page dlg. template
408 static BOOL PROPSHEET_SizeMismatch(HWND hwndDlg, PropSheetInfo* psInfo)
410 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
411 RECT rcOrigTab, rcPage;
416 GetClientRect(hwndTabCtrl, &rcOrigTab);
417 TRACE("orig tab %d %d %d %d\n", rcOrigTab.left, rcOrigTab.top,
418 rcOrigTab.right, rcOrigTab.bottom);
423 rcPage.left = psInfo->x;
424 rcPage.top = psInfo->y;
425 rcPage.right = psInfo->width;
426 rcPage.bottom = psInfo->height;
428 MapDialogRect(hwndDlg, &rcPage);
429 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
430 rcPage.right, rcPage.bottom);
432 if ( (rcPage.right - rcPage.left) != (rcOrigTab.right - rcOrigTab.left) )
434 if ( (rcPage.bottom - rcPage.top) != (rcOrigTab.bottom - rcOrigTab.top) )
440 /******************************************************************************
441 * PROPSHEET_IsTooSmallWizard
443 * Verify that the default property sheet is big enough.
445 static BOOL PROPSHEET_IsTooSmallWizard(HWND hwndDlg, PropSheetInfo* psInfo)
447 RECT rcSheetRect, rcPage, rcLine, rcSheetClient;
448 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
449 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
451 GetClientRect(hwndDlg, &rcSheetClient);
452 GetWindowRect(hwndDlg, &rcSheetRect);
453 GetWindowRect(hwndLine, &rcLine);
455 /* Remove the space below the sunken line */
456 rcSheetClient.bottom -= (rcSheetRect.bottom - rcLine.top);
458 /* Remove the buffer zone all around the edge */
459 rcSheetClient.bottom -= (padding.y * 2);
460 rcSheetClient.right -= (padding.x * 2);
465 rcPage.left = psInfo->x;
466 rcPage.top = psInfo->y;
467 rcPage.right = psInfo->width;
468 rcPage.bottom = psInfo->height;
470 MapDialogRect(hwndDlg, &rcPage);
471 TRACE("biggest page %d %d %d %d\n", rcPage.left, rcPage.top,
472 rcPage.right, rcPage.bottom);
474 if (rcPage.right > rcSheetClient.right)
477 if (rcPage.bottom > rcSheetClient.bottom)
483 /******************************************************************************
484 * PROPSHEET_AdjustSize
486 * Resizes the property sheet and the tab control to fit the largest page.
488 static BOOL PROPSHEET_AdjustSize(HWND hwndDlg, PropSheetInfo* psInfo)
490 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
491 HWND hwndButton = GetDlgItem(hwndDlg, IDOK);
493 int tabOffsetX, tabOffsetY, buttonHeight;
494 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndDlg);
497 /* Get the height of buttons */
498 GetClientRect(hwndButton, &rc);
499 buttonHeight = rc.bottom;
506 rc.right = psInfo->width;
507 rc.bottom = psInfo->height;
509 MapDialogRect(hwndDlg, &rc);
511 /* retrieve the dialog units */
512 units.left = units.right = 4;
513 units.top = units.bottom = 8;
514 MapDialogRect(hwndDlg, &units);
517 * Resize the tab control.
519 GetClientRect(hwndTabCtrl,&tabRect);
521 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&tabRect);
523 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
525 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
526 psInfo->height = MulDiv((rc.bottom - rc.top),8,units.top);
529 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
531 rc.right = rc.left + tabRect.right - tabRect.left;
532 psInfo->width = MulDiv((rc.right - rc.left),4,units.left);
535 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, TRUE, (LPARAM)&rc);
537 tabOffsetX = -(rc.left);
538 tabOffsetY = -(rc.top);
542 SetWindowPos(hwndTabCtrl, 0, 0, 0, rc.right, rc.bottom,
543 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
545 GetClientRect(hwndTabCtrl, &rc);
547 TRACE("tab client rc %d %d %d %d\n",
548 rc.left, rc.top, rc.right, rc.bottom);
550 rc.right += ((padding.x * 2) + tabOffsetX);
551 rc.bottom += (buttonHeight + (3 * padding.y) + tabOffsetY);
554 * Resize the property sheet.
556 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
557 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
561 /******************************************************************************
562 * PROPSHEET_AdjustSizeWizard
564 * Resizes the property sheet to fit the largest page.
566 static BOOL PROPSHEET_AdjustSizeWizard(HWND hwndDlg, PropSheetInfo* psInfo)
568 HWND hwndButton = GetDlgItem(hwndDlg, IDCANCEL);
569 HWND hwndLine = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
570 HWND hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
572 int buttonHeight, lineHeight;
573 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndDlg, psInfo);
576 /* Get the height of buttons */
577 GetClientRect(hwndButton, &rc);
578 buttonHeight = rc.bottom;
580 GetClientRect(hwndLine, &rc);
581 lineHeight = rc.bottom;
583 /* retrieve the dialog units */
584 units.left = units.right = 4;
585 units.top = units.bottom = 8;
586 MapDialogRect(hwndDlg, &units);
593 rc.right = psInfo->width;
594 rc.bottom = psInfo->height;
596 MapDialogRect(hwndDlg, &rc);
598 GetClientRect(hwndTabCtrl,&tabRect);
600 if ((rc.bottom - rc.top) < (tabRect.bottom - tabRect.top))
602 rc.bottom = rc.top + tabRect.bottom - tabRect.top;
603 psInfo->height = MulDiv((rc.bottom - rc.top), 8, units.top);
606 if ((rc.right - rc.left) < (tabRect.right - tabRect.left))
608 rc.right = rc.left + tabRect.right - tabRect.left;
609 psInfo->width = MulDiv((rc.right - rc.left), 4, units.left);
612 TRACE("Biggest page %d %d %d %d\n", rc.left, rc.top, rc.right, rc.bottom);
615 rc.right += (padding.x * 2);
616 rc.bottom += (buttonHeight + (5 * padding.y) + lineHeight);
619 * Resize the property sheet.
621 SetWindowPos(hwndDlg, 0, 0, 0, rc.right, rc.bottom,
622 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
626 /******************************************************************************
627 * PROPSHEET_AdjustButtons
629 * Adjusts the buttons' positions.
631 static BOOL PROPSHEET_AdjustButtons(HWND hwndParent, PropSheetInfo* psInfo)
633 HWND hwndButton = GetDlgItem(hwndParent, IDOK);
637 int buttonWidth, buttonHeight;
638 PADDING_INFO padding = PROPSHEET_GetPaddingInfo(hwndParent);
640 if (psInfo->hasApply)
647 * Obtain the size of the buttons.
649 GetClientRect(hwndButton, &rcSheet);
650 buttonWidth = rcSheet.right;
651 buttonHeight = rcSheet.bottom;
654 * Get the size of the property sheet.
656 GetClientRect(hwndParent, &rcSheet);
659 * All buttons will be at this y coordinate.
661 y = rcSheet.bottom - (padding.y + buttonHeight);
664 * Position OK button.
666 hwndButton = GetDlgItem(hwndParent, IDOK);
668 x = rcSheet.right - ((padding.x + buttonWidth) * num_buttons);
670 SetWindowPos(hwndButton, 0, x, y, 0, 0,
671 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
674 * Position Cancel button.
676 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
678 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
680 SetWindowPos(hwndButton, 0, x, y, 0, 0,
681 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
684 * Position Apply button.
686 hwndButton = GetDlgItem(hwndParent, IDC_APPLY_BUTTON);
688 if (psInfo->hasApply)
691 x = rcSheet.right - ((padding.x + buttonWidth) * 2);
693 x = rcSheet.right - (padding.x + buttonWidth);
695 SetWindowPos(hwndButton, 0, x, y, 0, 0,
696 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
698 EnableWindow(hwndButton, FALSE);
701 ShowWindow(hwndButton, SW_HIDE);
704 * Position Help button.
706 hwndButton = GetDlgItem(hwndParent, IDHELP);
710 x = rcSheet.right - (padding.x + buttonWidth);
712 SetWindowPos(hwndButton, 0, x, y, 0, 0,
713 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
716 ShowWindow(hwndButton, SW_HIDE);
721 /******************************************************************************
722 * PROPSHEET_AdjustButtonsWizard
724 * Adjusts the buttons' positions.
726 static BOOL PROPSHEET_AdjustButtonsWizard(HWND hwndParent,
727 PropSheetInfo* psInfo)
729 HWND hwndButton = GetDlgItem(hwndParent, IDCANCEL);
730 HWND hwndLine = GetDlgItem(hwndParent, IDC_SUNKEN_LINE);
734 int buttonWidth, buttonHeight, lineHeight, lineWidth;
735 PADDING_INFO padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
741 * Obtain the size of the buttons.
743 GetClientRect(hwndButton, &rcSheet);
744 buttonWidth = rcSheet.right;
745 buttonHeight = rcSheet.bottom;
747 GetClientRect(hwndLine, &rcSheet);
748 lineHeight = rcSheet.bottom;
751 * Get the size of the property sheet.
753 GetClientRect(hwndParent, &rcSheet);
756 * All buttons will be at this y coordinate.
758 y = rcSheet.bottom - (padding.y + buttonHeight);
761 * Position the Next and the Finish buttons.
763 hwndButton = GetDlgItem(hwndParent, IDC_NEXT_BUTTON);
765 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 1));
767 SetWindowPos(hwndButton, 0, x, y, 0, 0,
768 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
770 hwndButton = GetDlgItem(hwndParent, IDC_FINISH_BUTTON);
772 SetWindowPos(hwndButton, 0, x, y, 0, 0,
773 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
775 ShowWindow(hwndButton, SW_HIDE);
778 * Position the Back button.
780 hwndButton = GetDlgItem(hwndParent, IDC_BACK_BUTTON);
784 SetWindowPos(hwndButton, 0, x, y, 0, 0,
785 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
788 * Position the Cancel button.
790 hwndButton = GetDlgItem(hwndParent, IDCANCEL);
792 x = rcSheet.right - ((padding.x + buttonWidth) * (num_buttons - 2));
794 SetWindowPos(hwndButton, 0, x, y, 0, 0,
795 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
798 * Position Help button.
800 hwndButton = GetDlgItem(hwndParent, IDHELP);
804 x = rcSheet.right - (padding.x + buttonWidth);
806 SetWindowPos(hwndButton, 0, x, y, 0, 0,
807 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
810 ShowWindow(hwndButton, SW_HIDE);
813 * Position and resize the sunken line.
816 y = rcSheet.bottom - ((padding.y * 2) + buttonHeight + lineHeight);
818 GetClientRect(hwndParent, &rcSheet);
819 lineWidth = rcSheet.right - (padding.x * 2);
821 SetWindowPos(hwndLine, 0, x, y, lineWidth, 2,
822 SWP_NOZORDER | SWP_NOACTIVATE);
827 /******************************************************************************
828 * PROPSHEET_GetPaddingInfo
830 * Returns the layout information.
832 static PADDING_INFO PROPSHEET_GetPaddingInfo(HWND hwndDlg)
834 HWND hwndTab = GetDlgItem(hwndDlg, IDC_TABCONTROL);
837 PADDING_INFO padding;
839 GetWindowRect(hwndTab, &rcTab);
844 ScreenToClient(hwndDlg, &tl);
852 /******************************************************************************
853 * PROPSHEET_GetPaddingInfoWizard
855 * Returns the layout information.
856 * Vertical spacing is the distance between the line and the buttons.
857 * Do NOT use the Help button to gather padding information when it isn't mapped
858 * (PSH_HASHELP), as app writers aren't forced to supply correct coordinates
859 * for it in this case !
860 * FIXME: I'm not sure about any other coordinate problems with these evil
861 * buttons. Fix it in case additional problems appear or maybe calculate
862 * a padding in a completely different way, as this is somewhat messy.
864 static PADDING_INFO PROPSHEET_GetPaddingInfoWizard(HWND hwndDlg, const PropSheetInfo*
867 PADDING_INFO padding;
871 POINT ptButton, ptLine;
879 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
881 idButton = IDC_NEXT_BUTTON;
885 /* hopefully this is ok */
890 hwndControl = GetDlgItem(hwndDlg, idButton);
891 GetWindowRect(hwndControl, &rc);
893 ptButton.x = rc.left;
896 ScreenToClient(hwndDlg, &ptButton);
899 hwndControl = GetDlgItem(hwndDlg, IDC_SUNKEN_LINE);
900 GetWindowRect(hwndControl, &rc);
903 ptLine.y = rc.bottom;
905 ScreenToClient(hwndDlg, &ptLine);
907 padding.y = ptButton.y - ptLine.y;
910 ERR("padding negative ! Please report this !\n");
912 /* this is most probably not correct, but the best we have now */
913 padding.x = padding.y;
917 /******************************************************************************
918 * PROPSHEET_CreateTabControl
920 * Insert the tabs in the tab control.
922 static BOOL PROPSHEET_CreateTabControl(HWND hwndParent,
923 PropSheetInfo * psInfo)
925 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
929 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
931 item.mask = TCIF_TEXT;
932 item.pszText = tabtext;
933 item.cchTextMax = MAX_TABTEXT_LENGTH;
935 nTabs = psInfo->nPages;
938 * Set the image list for icons.
940 if (psInfo->hImageList)
942 SendMessageA(hwndTabCtrl, TCM_SETIMAGELIST, 0, (LPARAM)psInfo->hImageList);
945 for (i = 0; i < nTabs; i++)
947 if ( psInfo->proppage[i].hasIcon )
949 item.mask |= TCIF_IMAGE;
950 item.iImage = iImage++;
954 item.mask &= ~TCIF_IMAGE;
957 WideCharToMultiByte(CP_ACP, 0,
958 (LPCWSTR)psInfo->proppage[i].pszText,
959 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
961 SendMessageA(hwndTabCtrl, TCM_INSERTITEMA, (WPARAM)i, (LPARAM)&item);
967 /******************************************************************************
968 * PROPSHEET_CreatePage
972 static BOOL PROPSHEET_CreatePage(HWND hwndParent,
974 const PropSheetInfo * psInfo,
975 LPCPROPSHEETPAGEA ppshpage)
977 DLGTEMPLATE* pTemplate;
980 PropPageInfo* ppInfo = psInfo->proppage;
981 PADDING_INFO padding;
982 UINT pageWidth,pageHeight;
986 TRACE("index %d\n", index);
988 if (ppshpage->dwFlags & PSP_DLGINDIRECT)
989 pTemplate = (DLGTEMPLATE*)ppshpage->u.pResource;
995 hResource = FindResourceA(ppshpage->hInstance,
996 ppshpage->u.pszTemplate,
1001 resSize = SizeofResource(ppshpage->hInstance, hResource);
1003 hTemplate = LoadResource(ppshpage->hInstance, hResource);
1007 pTemplate = (LPDLGTEMPLATEA)LockResource(hTemplate);
1009 * Make a copy of the dialog template to make it writable
1011 temp = COMCTL32_Alloc(resSize);
1015 memcpy(temp, pTemplate, resSize);
1019 if (((MyDLGTEMPLATEEX*)pTemplate)->signature == 0xFFFF)
1021 ((MyDLGTEMPLATEEX*)pTemplate)->style |= WS_CHILD | DS_CONTROL;
1022 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~DS_MODALFRAME;
1023 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_CAPTION;
1024 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_SYSMENU;
1025 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_POPUP;
1026 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_DISABLED;
1027 ((MyDLGTEMPLATEEX*)pTemplate)->style &= ~WS_VISIBLE;
1031 pTemplate->style |= WS_CHILD | DS_CONTROL;
1032 pTemplate->style &= ~DS_MODALFRAME;
1033 pTemplate->style &= ~WS_CAPTION;
1034 pTemplate->style &= ~WS_SYSMENU;
1035 pTemplate->style &= ~WS_POPUP;
1036 pTemplate->style &= ~WS_DISABLED;
1037 pTemplate->style &= ~WS_VISIBLE;
1040 if (psInfo->proppage[index].useCallback)
1041 (*(ppshpage->pfnCallback))(hwndParent,
1043 (LPPROPSHEETPAGEA)ppshpage);
1045 hwndPage = CreateDialogIndirectParamA(ppshpage->hInstance,
1048 ppshpage->pfnDlgProc,
1050 /* Free a no more needed copy */
1052 COMCTL32_Free(temp);
1054 ppInfo[index].hwndPage = hwndPage;
1056 rc.left = psInfo->x;
1058 rc.right = psInfo->width;
1059 rc.bottom = psInfo->height;
1061 MapDialogRect(hwndParent, &rc);
1063 pageWidth = rc.right - rc.left;
1064 pageHeight = rc.bottom - rc.top;
1066 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
1067 padding = PROPSHEET_GetPaddingInfoWizard(hwndParent, psInfo);
1071 * Ask the Tab control to fit this page in.
1074 HWND hwndTabCtrl = GetDlgItem(hwndParent, IDC_TABCONTROL);
1075 SendMessageA(hwndTabCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rc);
1076 padding = PROPSHEET_GetPaddingInfo(hwndParent);
1079 SetWindowPos(hwndPage, HWND_TOP,
1080 rc.left + padding.x,
1082 pageWidth, pageHeight, 0);
1087 /******************************************************************************
1088 * PROPSHEET_ShowPage
1090 * Displays or creates the specified page.
1092 static BOOL PROPSHEET_ShowPage(HWND hwndDlg, int index, PropSheetInfo * psInfo)
1094 if (index == psInfo->active_page)
1096 if (GetTopWindow(hwndDlg) != psInfo->proppage[index].hwndPage)
1097 SetWindowPos(psInfo->proppage[index].hwndPage, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
1101 if (psInfo->proppage[index].hwndPage == 0)
1103 LPCPROPSHEETPAGEA ppshpage;
1106 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[index].hpage;
1107 PROPSHEET_CreatePage(hwndDlg, index, psInfo, ppshpage);
1109 psn.hdr.hwndFrom = hwndDlg;
1110 psn.hdr.code = PSN_SETACTIVE;
1114 /* Send the notification before showing the page. */
1115 SendMessageA(psInfo->proppage[index].hwndPage,
1116 WM_NOTIFY, 0, (LPARAM) &psn);
1119 * TODO: check return value.
1123 if (psInfo->active_page != -1)
1124 ShowWindow(psInfo->proppage[psInfo->active_page].hwndPage, SW_HIDE);
1126 ShowWindow(psInfo->proppage[index].hwndPage, SW_SHOW);
1128 if (!(psInfo->ppshheader.dwFlags & PSH_WIZARD))
1132 /* Synchronize current selection with tab control */
1133 hwndTabCtrl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1134 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, index, 0);
1137 psInfo->active_page = index;
1138 psInfo->activeValid = TRUE;
1143 /******************************************************************************
1146 static BOOL PROPSHEET_Back(HWND hwndDlg)
1151 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1154 if (psInfo->active_page < 0)
1157 psn.hdr.code = PSN_WIZBACK;
1158 psn.hdr.hwndFrom = hwndDlg;
1162 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1164 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) == -1)
1167 if (psInfo->active_page > 0)
1169 res = PROPSHEET_CanSetCurSel(hwndDlg);
1172 res = PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page - 1, 0);
1179 /******************************************************************************
1182 static BOOL PROPSHEET_Next(HWND hwndDlg)
1186 LRESULT msgResult = 0;
1187 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1190 if (psInfo->active_page < 0)
1193 psn.hdr.code = PSN_WIZNEXT;
1194 psn.hdr.hwndFrom = hwndDlg;
1198 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1200 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1202 TRACE("msg result %ld\n", msgResult);
1204 if (msgResult == -1)
1207 if(PROPSHEET_CanSetCurSel(hwndDlg) != FALSE)
1209 PROPSHEET_SetCurSel(hwndDlg, psInfo->active_page + 1, 0);
1215 /******************************************************************************
1218 static BOOL PROPSHEET_Finish(HWND hwndDlg)
1222 LRESULT msgResult = 0;
1223 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1226 if (psInfo->active_page < 0)
1229 psn.hdr.code = PSN_WIZFINISH;
1230 psn.hdr.hwndFrom = hwndDlg;
1234 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1236 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1238 TRACE("msg result %ld\n", msgResult);
1243 if (psInfo->isModeless)
1244 psInfo->activeValid = FALSE;
1246 EndDialog(hwndDlg, TRUE);
1251 /******************************************************************************
1254 static BOOL PROPSHEET_Apply(HWND hwndDlg, LPARAM lParam)
1260 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1263 if (psInfo->active_page < 0)
1266 psn.hdr.hwndFrom = hwndDlg;
1272 * Send PSN_KILLACTIVE to the current page.
1274 psn.hdr.code = PSN_KILLACTIVE;
1276 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1278 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn) != FALSE)
1282 * Send PSN_APPLY to all pages.
1284 psn.hdr.code = PSN_APPLY;
1285 psn.lParam = lParam;
1287 for (i = 0; i < psInfo->nPages; i++)
1289 hwndPage = psInfo->proppage[i].hwndPage;
1292 msgResult = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1293 if (msgResult == PSNRET_INVALID_NOCHANGEPAGE)
1300 psInfo->activeValid = FALSE;
1302 else if(psInfo->active_page >= 0)
1304 psn.hdr.code = PSN_SETACTIVE;
1306 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1307 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1313 /******************************************************************************
1316 static void PROPSHEET_Cancel(HWND hwndDlg, LPARAM lParam)
1318 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1324 if (psInfo->active_page < 0)
1327 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1328 psn.hdr.code = PSN_QUERYCANCEL;
1329 psn.hdr.hwndFrom = hwndDlg;
1333 if (SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn))
1336 psn.hdr.code = PSN_RESET;
1337 psn.lParam = lParam;
1339 for (i = 0; i < psInfo->nPages; i++)
1341 hwndPage = psInfo->proppage[i].hwndPage;
1344 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1347 if (psInfo->isModeless)
1349 /* makes PSM_GETCURRENTPAGEHWND return NULL */
1350 psInfo->activeValid = FALSE;
1353 EndDialog(hwndDlg, FALSE);
1356 /******************************************************************************
1359 static void PROPSHEET_Help(HWND hwndDlg)
1361 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1366 if (psInfo->active_page < 0)
1369 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1370 psn.hdr.code = PSN_HELP;
1371 psn.hdr.hwndFrom = hwndDlg;
1375 SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1378 /******************************************************************************
1381 static void PROPSHEET_Changed(HWND hwndDlg, HWND hwndDirtyPage)
1384 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,
1419 if ( !psInfo ) return;
1420 for (i = 0; i < psInfo->nPages; i++)
1422 /* set the specified page as clean */
1423 if (psInfo->proppage[i].hwndPage == hwndCleanPage)
1424 psInfo->proppage[i].isDirty = FALSE;
1426 /* look to see if there's any dirty pages */
1427 if (psInfo->proppage[i].isDirty)
1428 noPageDirty = FALSE;
1432 * Disable Apply button.
1435 EnableWindow(hwndApplyBtn, FALSE);
1438 /******************************************************************************
1439 * PROPSHEET_PressButton
1441 static void PROPSHEET_PressButton(HWND hwndDlg, int buttonID)
1445 case PSBTN_APPLYNOW:
1446 SendMessageA(hwndDlg, WM_COMMAND, IDC_APPLY_BUTTON, 0);
1449 PROPSHEET_Back(hwndDlg);
1452 SendMessageA(hwndDlg, WM_COMMAND, IDCANCEL, 0);
1455 PROPSHEET_Finish(hwndDlg);
1458 SendMessageA(hwndDlg, WM_COMMAND, IDHELP, 0);
1461 PROPSHEET_Next(hwndDlg);
1464 SendMessageA(hwndDlg, WM_COMMAND, IDOK, 0);
1467 FIXME("Invalid button index %d\n", buttonID);
1472 /*************************************************************************
1473 * BOOL PROPSHEET_CanSetCurSel [Internal]
1475 * Test whether the current page can be changed by sending a PSN_KILLACTIVE
1478 * hwndDlg [I] handle to a Dialog hWnd
1481 * TRUE if Current Selection can change
1485 static BOOL PROPSHEET_CanSetCurSel(HWND hwndDlg)
1487 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1495 if (psInfo->active_page < 0)
1499 * Notify the current page.
1501 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
1502 psn.hdr.code = PSN_KILLACTIVE;
1503 psn.hdr.hwndFrom = hwndDlg;
1507 return !SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1510 /******************************************************************************
1511 * PROPSHEET_SetCurSel
1513 static BOOL PROPSHEET_SetCurSel(HWND hwndDlg,
1515 HPROPSHEETPAGE hpage)
1517 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1520 HWND hwndHelp = GetDlgItem(hwndDlg, IDHELP);
1522 /* hpage takes precedence over index */
1524 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1526 if (index < 0 || index >= psInfo->nPages)
1528 TRACE("Could not find page to select!\n");
1532 hwndPage = psInfo->proppage[index].hwndPage;
1535 * Notify the new page if it's already created.
1536 * If not it will get created and notified in PROPSHEET_ShowPage.
1543 psn.hdr.code = PSN_SETACTIVE;
1544 psn.hdr.hwndFrom = hwndDlg;
1548 result = SendMessageA(hwndPage, WM_NOTIFY, 0, (LPARAM) &psn);
1551 * TODO: check return value.
1556 * Display the new page.
1558 PROPSHEET_ShowPage(hwndDlg, index, psInfo);
1560 if (psInfo->proppage[index].hasHelp)
1561 EnableWindow(hwndHelp, TRUE);
1563 EnableWindow(hwndHelp, FALSE);
1568 /******************************************************************************
1569 * PROPSHEET_SetTitleA
1571 static void PROPSHEET_SetTitleA(HWND hwndDlg, DWORD dwStyle, LPCSTR lpszText)
1573 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg, PropSheetInfoStr);
1576 if (HIWORD(lpszText) == 0) {
1577 if (!LoadStringA(psInfo->ppshheader.hInstance,
1578 LOWORD(lpszText), szTitle, sizeof(szTitle)-1))
1582 if (dwStyle & PSH_PROPTITLE)
1585 int lentitle = strlen(lpszText);
1586 int lenprop = strlen(psInfo->strPropertiesFor);
1588 dest = COMCTL32_Alloc(lentitle + lenprop + 1);
1589 strcpy(dest, psInfo->strPropertiesFor);
1590 strcat(dest, lpszText);
1592 SetWindowTextA(hwndDlg, dest);
1593 COMCTL32_Free(dest);
1596 SetWindowTextA(hwndDlg, lpszText);
1599 /******************************************************************************
1600 * PROPSHEET_SetFinishTextA
1602 static void PROPSHEET_SetFinishTextA(HWND hwndDlg, LPCSTR lpszText)
1604 HWND hwndButton = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1606 /* Set text, show and enable the Finish button */
1607 SetWindowTextA(hwndButton, lpszText);
1608 ShowWindow(hwndButton, SW_SHOW);
1609 EnableWindow(hwndButton, TRUE);
1611 /* Make it default pushbutton */
1612 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1614 /* Hide Back button */
1615 hwndButton = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1616 ShowWindow(hwndButton, SW_HIDE);
1618 /* Hide Next button */
1619 hwndButton = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1620 ShowWindow(hwndButton, SW_HIDE);
1623 /******************************************************************************
1624 * PROPSHEET_QuerySiblings
1626 static LRESULT PROPSHEET_QuerySiblings(HWND hwndDlg,
1627 WPARAM wParam, LPARAM lParam)
1631 LRESULT msgResult = 0;
1632 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1635 while ((i < psInfo->nPages) && (msgResult == 0))
1637 hwndPage = psInfo->proppage[i].hwndPage;
1638 msgResult = SendMessageA(hwndPage, PSM_QUERYSIBLINGS, wParam, lParam);
1646 /******************************************************************************
1649 static BOOL PROPSHEET_AddPage(HWND hwndDlg,
1650 HPROPSHEETPAGE hpage)
1652 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1654 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1656 char tabtext[MAX_TABTEXT_LENGTH] = "Tab text";
1657 LPCPROPSHEETPAGEA ppsp = (LPCPROPSHEETPAGEA)hpage;
1660 * Allocate and fill in a new PropPageInfo entry.
1662 psInfo->proppage = (PropPageInfo*) COMCTL32_ReAlloc(psInfo->proppage,
1663 sizeof(PropPageInfo) *
1664 (psInfo->nPages + 1));
1665 if (!PROPSHEET_CollectPageInfo(ppsp, psInfo, psInfo->nPages))
1668 psInfo->proppage[psInfo->nPages].hpage = hpage;
1670 if (ppsp->dwFlags & PSP_PREMATURE)
1672 /* Create the page but don't show it */
1673 PROPSHEET_CreatePage(hwndDlg, psInfo->nPages, psInfo, ppsp);
1677 * Add a new tab to the tab control.
1679 item.mask = TCIF_TEXT;
1680 item.pszText = tabtext;
1681 item.cchTextMax = MAX_TABTEXT_LENGTH;
1683 WideCharToMultiByte(CP_ACP, 0,
1684 (LPCWSTR)psInfo->proppage[psInfo->nPages].pszText,
1685 -1, tabtext, MAX_TABTEXT_LENGTH, NULL, NULL);
1687 SendMessageA(hwndTabControl, TCM_INSERTITEMA, psInfo->nPages + 1,
1692 /* If it is the only page - show it */
1693 if(psInfo->nPages == 1)
1694 PROPSHEET_ShowPage(hwndDlg, 0, psInfo);
1699 /******************************************************************************
1700 * PROPSHEET_RemovePage
1702 static BOOL PROPSHEET_RemovePage(HWND hwndDlg,
1704 HPROPSHEETPAGE hpage)
1706 PropSheetInfo * psInfo = (PropSheetInfo*) GetPropA(hwndDlg,
1708 HWND hwndTabControl = GetDlgItem(hwndDlg, IDC_TABCONTROL);
1709 PropPageInfo* oldPages;
1714 oldPages = psInfo->proppage;
1716 * hpage takes precedence over index.
1720 index = PROPSHEET_GetPageIndex(hpage, psInfo);
1723 /* Make sure that index is within range */
1724 if (index < 0 || index >= psInfo->nPages)
1726 TRACE("Could not find page to remove!\n");
1730 TRACE("total pages %d removing page %d active page %d\n",
1731 psInfo->nPages, index, psInfo->active_page);
1733 * Check if we're removing the active page.
1735 if (index == psInfo->active_page)
1737 if (psInfo->nPages > 1)
1741 /* activate previous page */
1742 PROPSHEET_ShowPage(hwndDlg, index - 1, psInfo);
1746 /* activate the next page */
1747 PROPSHEET_ShowPage(hwndDlg, index + 1, psInfo);
1748 psInfo->active_page = index;
1753 psInfo->active_page = -1;
1754 if (!psInfo->isModeless)
1756 EndDialog(hwndDlg, FALSE);
1761 else if (index < psInfo->active_page)
1762 psInfo->active_page--;
1764 /* Destroy page dialog window */
1765 DestroyWindow(psInfo->proppage[index].hwndPage);
1767 /* Free page resources */
1768 if(psInfo->proppage[index].hpage)
1770 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[index].hpage;
1772 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[index].pszText)
1773 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[index].pszText);
1775 DestroyPropertySheetPage(psInfo->proppage[index].hpage);
1778 /* Remove the tab */
1779 SendMessageA(hwndTabControl, TCM_DELETEITEM, index, 0);
1782 psInfo->proppage = COMCTL32_Alloc(sizeof(PropPageInfo) * psInfo->nPages);
1785 memcpy(&psInfo->proppage[0], &oldPages[0], index * sizeof(PropPageInfo));
1787 if (index < psInfo->nPages)
1788 memcpy(&psInfo->proppage[index], &oldPages[index + 1],
1789 (psInfo->nPages - index) * sizeof(PropPageInfo));
1791 COMCTL32_Free(oldPages);
1796 /******************************************************************************
1797 * PROPSHEET_SetWizButtons
1799 * This code will work if (and assumes that) the Next button is on top of the
1800 * Finish button. ie. Finish comes after Next in the Z order.
1801 * This means make sure the dialog template reflects this.
1804 static void PROPSHEET_SetWizButtons(HWND hwndDlg, DWORD dwFlags)
1806 HWND hwndBack = GetDlgItem(hwndDlg, IDC_BACK_BUTTON);
1807 HWND hwndNext = GetDlgItem(hwndDlg, IDC_NEXT_BUTTON);
1808 HWND hwndFinish = GetDlgItem(hwndDlg, IDC_FINISH_BUTTON);
1810 TRACE("%ld\n", dwFlags);
1812 EnableWindow(hwndBack, FALSE);
1813 EnableWindow(hwndNext, FALSE);
1814 EnableWindow(hwndFinish, FALSE);
1816 if (dwFlags & PSWIZB_BACK)
1817 EnableWindow(hwndBack, TRUE);
1819 if (dwFlags & PSWIZB_NEXT)
1821 /* Hide the Finish button */
1822 ShowWindow(hwndFinish, SW_HIDE);
1824 /* Show and enable the Next button */
1825 ShowWindow(hwndNext, SW_SHOW);
1826 EnableWindow(hwndNext, TRUE);
1828 /* Set the Next button as the default pushbutton */
1829 SendMessageA(hwndDlg, DM_SETDEFID, IDC_NEXT_BUTTON, 0);
1832 if ((dwFlags & PSWIZB_FINISH) || (dwFlags & PSWIZB_DISABLEDFINISH))
1834 /* Hide the Next button */
1835 ShowWindow(hwndNext, SW_HIDE);
1837 /* Show the Finish button */
1838 ShowWindow(hwndFinish, SW_SHOW);
1840 if (dwFlags & PSWIZB_FINISH)
1841 EnableWindow(hwndFinish, TRUE);
1843 /* Set the Finish button as the default pushbutton */
1844 SendMessageA(hwndDlg, DM_SETDEFID, IDC_FINISH_BUTTON, 0);
1848 /******************************************************************************
1849 * PROPSHEET_GetPageIndex
1851 * Given a HPROPSHEETPAGE, returns the index of the corresponding page from
1852 * the array of PropPageInfo.
1854 static int PROPSHEET_GetPageIndex(HPROPSHEETPAGE hpage, PropSheetInfo* psInfo)
1859 while ((index < psInfo->nPages) && (found == FALSE))
1861 if (psInfo->proppage[index].hpage == hpage)
1873 /******************************************************************************
1876 static void PROPSHEET_CleanUp(HWND hwndDlg)
1879 PropSheetInfo* psInfo = (PropSheetInfo*) RemovePropA(hwndDlg,
1883 if (HIWORD(psInfo->ppshheader.pszCaption))
1884 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->ppshheader.pszCaption);
1886 for (i = 0; i < psInfo->nPages; i++)
1888 PROPSHEETPAGEA* psp = (PROPSHEETPAGEA*)psInfo->proppage[i].hpage;
1890 if(psInfo->proppage[i].hwndPage)
1891 DestroyWindow(psInfo->proppage[i].hwndPage);
1895 if ((psp->dwFlags & PSP_USETITLE) && psInfo->proppage[i].pszText)
1896 HeapFree(GetProcessHeap(), 0, (LPVOID)psInfo->proppage[i].pszText);
1898 DestroyPropertySheetPage(psInfo->proppage[i].hpage);
1902 COMCTL32_Free(psInfo->proppage);
1903 COMCTL32_Free(psInfo->strPropertiesFor);
1904 ImageList_Destroy(psInfo->hImageList);
1906 GlobalFree((HGLOBAL)psInfo);
1909 /******************************************************************************
1910 * PropertySheetA (COMCTL32.84)(COMCTL32.83)
1912 INT WINAPI PropertySheetA(LPCPROPSHEETHEADERA lppsh)
1915 PropSheetInfo* psInfo = (PropSheetInfo*) GlobalAlloc(GPTR,
1916 sizeof(PropSheetInfo));
1920 PROPSHEET_CollectSheetInfo(lppsh, psInfo);
1922 psInfo->proppage = (PropPageInfo*) COMCTL32_Alloc(sizeof(PropPageInfo) *
1924 pByte = (BYTE*) psInfo->ppshheader.u3.ppsp;
1926 for (n = i = 0; i < lppsh->nPages; i++, n++)
1928 if (!(lppsh->dwFlags & PSH_PROPSHEETPAGE))
1929 psInfo->proppage[n].hpage = psInfo->ppshheader.u3.phpage[i];
1932 psInfo->proppage[n].hpage = CreatePropertySheetPageA((LPCPROPSHEETPAGEA)pByte);
1933 pByte += ((LPPROPSHEETPAGEA)pByte)->dwSize;
1936 if (!PROPSHEET_CollectPageInfo((LPCPROPSHEETPAGEA)psInfo->proppage[n].hpage,
1939 if (lppsh->dwFlags & PSH_PROPSHEETPAGE)
1940 DestroyPropertySheetPage(psInfo->proppage[n].hpage);
1946 bRet = PROPSHEET_CreateDialog(psInfo);
1951 /******************************************************************************
1952 * PropertySheetW (COMCTL32.85)
1954 INT WINAPI PropertySheetW(LPCPROPSHEETHEADERW propertySheetHeader)
1956 FIXME("(%p): stub\n", propertySheetHeader);
1961 /******************************************************************************
1962 * CreatePropertySheetPageA (COMCTL32.19)(COMCTL32.18)
1964 HPROPSHEETPAGE WINAPI CreatePropertySheetPageA(
1965 LPCPROPSHEETPAGEA lpPropSheetPage)
1967 PROPSHEETPAGEA* ppsp = COMCTL32_Alloc(sizeof(PROPSHEETPAGEA));
1969 memcpy(ppsp,lpPropSheetPage,min(lpPropSheetPage->dwSize,sizeof(PROPSHEETPAGEA)));
1971 if ( !(ppsp->dwFlags & PSP_DLGINDIRECT) && HIWORD( ppsp->u.pszTemplate ) )
1972 ppsp->u.pszTemplate = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->u.pszTemplate );
1974 if ( (ppsp->dwFlags & PSP_USEICONID) && HIWORD( ppsp->u2.pszIcon ) )
1975 ppsp->u2.pszIcon = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->u2.pszIcon );
1978 if ((ppsp->dwFlags & PSP_USETITLE) && HIWORD( ppsp->pszTitle ))
1979 ppsp->pszTitle = HEAP_strdupA( GetProcessHeap(), 0, lpPropSheetPage->pszTitle );
1980 else if ( !(ppsp->dwFlags & PSP_USETITLE) )
1981 ppsp->pszTitle = NULL;
1983 return (HPROPSHEETPAGE)ppsp;
1986 /******************************************************************************
1987 * CreatePropertySheetPageW (COMCTL32.20)
1989 HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
1991 FIXME("(%p): stub\n", lpPropSheetPage);
1996 /******************************************************************************
1997 * DestroyPropertySheetPage (COMCTL32.24)
1999 BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
2001 PROPSHEETPAGEA *psp = (PROPSHEETPAGEA *)hPropPage;
2006 if ( !(psp->dwFlags & PSP_DLGINDIRECT) && HIWORD( psp->u.pszTemplate ) )
2007 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u.pszTemplate);
2009 if ( (psp->dwFlags & PSP_USEICONID) && HIWORD( psp->u2.pszIcon ) )
2010 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->u2.pszIcon);
2012 if ((psp->dwFlags & PSP_USETITLE) && HIWORD( psp->pszTitle ))
2013 HeapFree(GetProcessHeap(), 0, (LPVOID)psp->pszTitle);
2015 COMCTL32_Free(hPropPage);
2020 /******************************************************************************
2021 * PROPSHEET_IsDialogMessage
2023 static BOOL PROPSHEET_IsDialogMessage(HWND hwnd, LPMSG lpMsg)
2025 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd, PropSheetInfoStr);
2027 if (!psInfo || (hwnd != lpMsg->hwnd && !IsChild(hwnd, lpMsg->hwnd)))
2030 if (lpMsg->message == WM_KEYDOWN && (GetKeyState(VK_CONTROL) & 0x8000))
2033 INT dlgCode = SendMessageA(lpMsg->hwnd, WM_GETDLGCODE, 0, (LPARAM)lpMsg);
2035 if (!(dlgCode & DLGC_WANTMESSAGE))
2037 switch (lpMsg->wParam)
2040 if (GetKeyState(VK_SHIFT) & 0x8000)
2046 case VK_NEXT: new_page = 1; break;
2047 case VK_PRIOR: new_page = -1; break;
2053 if (PROPSHEET_CanSetCurSel(hwnd) != FALSE)
2055 new_page += psInfo->active_page;
2058 new_page = psInfo->nPages - 1;
2059 else if (new_page >= psInfo->nPages)
2062 PROPSHEET_SetCurSel(hwnd, new_page, 0);
2069 return IsDialogMessageA(hwnd, lpMsg);
2072 /******************************************************************************
2073 * PROPSHEET_DialogProc
2076 PROPSHEET_DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2082 PropSheetInfo* psInfo = (PropSheetInfo*) lParam;
2083 char* strCaption = (char*)COMCTL32_Alloc(MAX_CAPTION_LENGTH);
2084 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2085 LPCPROPSHEETPAGEA ppshpage;
2088 SetPropA(hwnd, PropSheetInfoStr, (HANDLE)psInfo);
2091 * psInfo->hwnd is not being used by WINE code - it exists
2092 * for compatibility with "real" Windoze. The same about
2093 * SetWindowLong - WINE is only using the PropSheetInfoStr
2096 psInfo->hwnd = hwnd;
2097 SetWindowLongA(hwnd,DWL_USER,(LONG)psInfo);
2100 * Small icon in the title bar.
2102 if ((psInfo->ppshheader.dwFlags & PSH_USEICONID) ||
2103 (psInfo->ppshheader.dwFlags & PSH_USEHICON))
2106 int icon_cx = GetSystemMetrics(SM_CXSMICON);
2107 int icon_cy = GetSystemMetrics(SM_CYSMICON);
2109 if (psInfo->ppshheader.dwFlags & PSH_USEICONID)
2110 hIcon = LoadImageA(psInfo->ppshheader.hInstance,
2111 psInfo->ppshheader.u.pszIcon,
2116 hIcon = psInfo->ppshheader.u.hIcon;
2118 SendMessageA(hwnd, WM_SETICON, 0, hIcon);
2121 if (psInfo->ppshheader.dwFlags & PSH_USEHICON)
2122 SendMessageA(hwnd, WM_SETICON, 0, psInfo->ppshheader.u.hIcon);
2124 psInfo->strPropertiesFor = strCaption;
2126 GetWindowTextA(hwnd, psInfo->strPropertiesFor, MAX_CAPTION_LENGTH);
2128 PROPSHEET_CreateTabControl(hwnd, psInfo);
2130 if (psInfo->ppshheader.dwFlags & PSH_WIZARD)
2132 if (PROPSHEET_IsTooSmallWizard(hwnd, psInfo))
2134 PROPSHEET_AdjustSizeWizard(hwnd, psInfo);
2135 PROPSHEET_AdjustButtonsWizard(hwnd, psInfo);
2140 if (PROPSHEET_SizeMismatch(hwnd, psInfo))
2142 PROPSHEET_AdjustSize(hwnd, psInfo);
2143 PROPSHEET_AdjustButtons(hwnd, psInfo);
2147 if (psInfo->useCallback)
2148 (*(psInfo->ppshheader.pfnCallback))(hwnd,
2149 PSCB_INITIALIZED, (LPARAM)0);
2151 idx = psInfo->active_page;
2152 ppshpage = (LPCPROPSHEETPAGEA)psInfo->proppage[idx].hpage;
2153 psInfo->active_page = -1;
2155 PROPSHEET_SetCurSel(hwnd, idx, psInfo->proppage[idx].hpage);
2157 if (!(psInfo->ppshheader.dwFlags & PSH_WIZARD))
2158 SendMessageA(hwndTabCtrl, TCM_SETCURSEL, psInfo->active_page, 0);
2160 if (!HIWORD(psInfo->ppshheader.pszCaption) &&
2161 psInfo->ppshheader.hInstance)
2165 if (LoadStringA(psInfo->ppshheader.hInstance,
2166 (UINT)psInfo->ppshheader.pszCaption, szText, 255))
2167 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags, szText);
2171 PROPSHEET_SetTitleA(hwnd, psInfo->ppshheader.dwFlags,
2172 psInfo->ppshheader.pszCaption);
2179 PROPSHEET_CleanUp(hwnd);
2183 PROPSHEET_Cancel(hwnd, 1);
2188 WORD wID = LOWORD(wParam);
2193 case IDC_APPLY_BUTTON:
2195 HWND hwndApplyBtn = GetDlgItem(hwnd, IDC_APPLY_BUTTON);
2197 if (PROPSHEET_Apply(hwnd, wID == IDOK ? 1: 0) == FALSE)
2202 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2206 if (psInfo->restartWindows)
2207 result = ID_PSRESTARTWINDOWS;
2209 /* reboot system takes precedence over restart windows */
2210 if (psInfo->rebootSystem)
2211 result = ID_PSREBOOTSYSTEM;
2213 if (psInfo->isModeless)
2214 psInfo->activeValid = FALSE;
2216 EndDialog(hwnd, result);
2219 EnableWindow(hwndApplyBtn, FALSE);
2224 case IDC_BACK_BUTTON:
2225 PROPSHEET_Back(hwnd);
2228 case IDC_NEXT_BUTTON:
2229 PROPSHEET_Next(hwnd);
2232 case IDC_FINISH_BUTTON:
2233 PROPSHEET_Finish(hwnd);
2237 PROPSHEET_Cancel(hwnd, 0);
2241 PROPSHEET_Help(hwnd);
2250 NMHDR* pnmh = (LPNMHDR) lParam;
2252 if (pnmh->code == TCN_SELCHANGE)
2254 int index = SendMessageA(pnmh->hwndFrom, TCM_GETCURSEL, 0, 0);
2255 PROPSHEET_SetCurSel(hwnd, index, 0);
2258 if(pnmh->code == TCN_SELCHANGING)
2260 BOOL bRet = PROPSHEET_CanSetCurSel(hwnd);
2261 SetWindowLongA(hwnd, DWL_MSGRESULT, !bRet);
2268 case PSM_GETCURRENTPAGEHWND:
2270 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2274 if (psInfo->activeValid && psInfo->active_page != -1)
2275 hwndPage = psInfo->proppage[psInfo->active_page].hwndPage;
2277 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndPage);
2283 PROPSHEET_Changed(hwnd, (HWND)wParam);
2287 PROPSHEET_UnChanged(hwnd, (HWND)wParam);
2290 case PSM_GETTABCONTROL:
2292 HWND hwndTabCtrl = GetDlgItem(hwnd, IDC_TABCONTROL);
2294 SetWindowLongA(hwnd, DWL_MSGRESULT, hwndTabCtrl);
2303 msgResult = PROPSHEET_CanSetCurSel(hwnd);
2304 if(msgResult != FALSE)
2306 msgResult = PROPSHEET_SetCurSel(hwnd,
2308 (HPROPSHEETPAGE)lParam);
2311 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2316 case PSM_CANCELTOCLOSE:
2318 char buf[MAX_BUTTONTEXT_LENGTH];
2319 HWND hwndOK = GetDlgItem(hwnd, IDOK);
2320 HWND hwndCancel = GetDlgItem(hwnd, IDCANCEL);
2322 EnableWindow(hwndCancel, FALSE);
2323 if (LoadStringA(COMCTL32_hModule, IDS_CLOSE, buf, sizeof(buf)))
2324 SetWindowTextA(hwndOK, buf);
2329 case PSM_RESTARTWINDOWS:
2331 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2334 psInfo->restartWindows = TRUE;
2338 case PSM_REBOOTSYSTEM:
2340 PropSheetInfo* psInfo = (PropSheetInfo*) GetPropA(hwnd,
2343 psInfo->rebootSystem = TRUE;
2348 PROPSHEET_SetTitleA(hwnd, (DWORD) wParam, (LPCSTR) lParam);
2353 BOOL msgResult = PROPSHEET_Apply(hwnd, 0);
2355 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2360 case PSM_QUERYSIBLINGS:
2362 LRESULT msgResult = PROPSHEET_QuerySiblings(hwnd, wParam, lParam);
2364 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2372 * Note: MSVC++ 6.0 documentation says that PSM_ADDPAGE does not have
2373 * a return value. This is not true. PSM_ADDPAGE returns TRUE
2374 * on success or FALSE otherwise, as specified on MSDN Online.
2375 * Also see the MFC code for
2376 * CPropertySheet::AddPage(CPropertyPage* pPage).
2379 BOOL msgResult = PROPSHEET_AddPage(hwnd, (HPROPSHEETPAGE)lParam);
2381 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2386 case PSM_REMOVEPAGE:
2387 PROPSHEET_RemovePage(hwnd, (int)wParam, (HPROPSHEETPAGE)lParam);
2390 case PSM_ISDIALOGMESSAGE:
2392 BOOL msgResult = PROPSHEET_IsDialogMessage(hwnd, (LPMSG)lParam);
2393 SetWindowLongA(hwnd, DWL_MSGRESULT, msgResult);
2397 case PSM_PRESSBUTTON:
2398 PROPSHEET_PressButton(hwnd, (int)wParam);
2401 case PSM_SETFINISHTEXTA:
2402 PROPSHEET_SetFinishTextA(hwnd, (LPCSTR) lParam);
2405 case PSM_SETWIZBUTTONS:
2406 PROPSHEET_SetWizButtons(hwnd, (DWORD)lParam);
2410 FIXME("Unimplemented msg PSM_SETTITLE32W\n");
2413 case PSM_SETCURSELID:
2414 FIXME("Unimplemented msg PSM_SETCURSELID\n");
2417 case PSM_SETFINISHTEXTW:
2418 FIXME("Unimplemented msg PSM_SETFINISHTEXT32W\n");