2
* Copyright (c) 2005 Alexander Gottwald
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
* DEALINGS IN THE SOFTWARE.
22
* Except as contained in this notice, the name(s) of the above copyright
23
* holders shall not be used in advertising or otherwise to promote the sale,
24
* use or other dealings in this Software without prior written authorization.
29
CWizard::CWizard() : pages()
33
void CWizard::AddPage(const PROPSHEETPAGE &page)
35
pages.push_back(page);
38
void CWizard::AddPage(const char *page, HINSTANCE instance)
42
instance = GetModuleHandle(NULL);
44
memset(&psp, 0, sizeof(psp));
45
psp.dwSize = sizeof(PROPSHEETPAGE);
46
psp.dwFlags = PSP_DEFAULT;
47
psp.hInstance = instance;
48
psp.pszTemplate = page;
49
psp.pfnDlgProc = WizardDialogProc;
50
psp.lParam = (LPARAM)this;
55
void CWizard::AddPage(DWORD id, DWORD title, DWORD subtitle, HINSTANCE instance)
59
instance = GetModuleHandle(NULL);
61
memset(&psp, 0, sizeof(psp));
62
psp.dwSize = sizeof(PROPSHEETPAGE);
63
psp.dwFlags = PSP_DEFAULT;
64
#if _WIN32_IE >= 0x0500
67
psp.dwFlags |= PSP_USEHEADERTITLE;
68
psp.pszHeaderTitle = MAKEINTRESOURCE(title);
72
psp.dwFlags |= PSP_USEHEADERSUBTITLE;
73
psp.pszHeaderSubTitle = MAKEINTRESOURCE(subtitle);
77
psp.hInstance = instance;
78
psp.pszTemplate = MAKEINTRESOURCE(id);
79
psp.pfnDlgProc = WizardDialogProc;
80
psp.lParam = (LPARAM)this;
85
HWND CWizard::CreateWindowHandle()
90
PrepareSheetHeader(psh, FALSE);
91
ret = (HWND)PropertySheet(&psh);
94
throw win32_error("PropertySheet failed");
98
int CWizard::ShowModal()
103
PrepareSheetHeader(psh, TRUE);
104
ret = PropertySheet(&psh);
109
void CWizard::PrepareSheetHeader(PROPSHEETHEADER &psh, BOOL modal)
111
HPROPSHEETPAGE *phpage = (HPROPSHEETPAGE*)malloc(pages.size() * sizeof(HPROPSHEETPAGE));
117
modeflag = PSH_MODELESS;
119
for (unsigned i = 0; i < pages.size(); i++)
121
phpage[i] = CreatePropertySheetPage(&pages[i]);
122
if (phpage[i] == NULL)
124
DWORD err = GetLastError();
126
throw win32_error("CreatePropertySheetPage failed", err);
130
memset(&psh, 0, sizeof(psh));
131
psh.dwSize = sizeof(PROPSHEETHEADER);
132
#if _WIN32_IE >= 0x0500
133
psh.dwFlags = PSH_WIZARD97 | modeflag;
135
psh.dwFlags = PSH_WIZARD | modeflag;
137
psh.hwndParent = NULL;
138
psh.hInstance = GetModuleHandle(NULL);
140
psh.pszCaption = (LPSTR) "Cell Properties";
141
psh.nPages = pages.size();
144
psh.pfnCallback = NULL;
147
DWORD CWizard::PageID(unsigned index)
149
if (index < pages.size() && IS_INTRESOURCE(pages[index].pszTemplate))
150
return (DWORD)pages[index].pszTemplate;
154
unsigned CWizard::PageIndex(PROPSHEETPAGE *psp)
156
for (unsigned i = 0; i < pages.size(); i++)
158
if (IS_INTRESOURCE(psp->pszTemplate) || IS_INTRESOURCE(pages[i].pszTemplate ))
160
if (psp->pszTemplate == pages[i].pszTemplate)
163
else if (psp->pszTemplate && pages[i].pszTemplate)
165
if (strcmp(psp->pszTemplate, pages[i].pszTemplate) == 0)
172
INT_PTR CWizard::DlgDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
174
return CBaseDialog::DlgDispatch(hwndDlg, uMsg, wParam, lParam);
177
INT_PTR CWizard::PageDispatch(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam, PROPSHEETPAGE *psp)
179
LPNMHDR pnmh = (LPNMHDR)lParam;
189
printf("PSN_SETACTIVE %d\n", PageIndex(psp));
191
pageindex = PageIndex(psp);
192
if (pageindex != (unsigned)-1)
196
flags |= PSWIZB_BACK;
197
if ((unsigned)pageindex + 1 == pages.size())
198
flags |= PSWIZB_FINISH;
199
if ((unsigned)pageindex + 1 < pages.size())
200
flags |= PSWIZB_NEXT;
201
PropSheet_SetWizButtons(GetParent(hwndDlg), flags);
203
WizardActivate(hwndDlg, pageindex);
206
if (WizardNext(hwndDlg, PageIndex(psp)))
210
if (WizardBack(hwndDlg, PageIndex(psp)))
214
if (WizardFinish(hwndDlg, PageIndex(psp)))
216
DestroyWindow(GetParent(hwndDlg));
218
if (WizardReset(hwndDlg, PageIndex(psp)))
220
DestroyWindow(GetParent(hwndDlg));
224
return DlgDispatch(hwndDlg, uMsg, wParam, lParam);
228
INT_PTR CALLBACK CWizard::WizardDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
230
MessageDebug::debug(hwndDlg, uMsg, wParam, lParam, __FUNCTION__);
231
PROPSHEETPAGE *psp = (PROPSHEETPAGE*)lParam;
235
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)psp);
238
psp = (PROPSHEETPAGE*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
239
CWizard* wizard = psp?(CWizard*)psp->lParam:NULL;
241
return wizard->PageDispatch(hwndDlg, uMsg, wParam, lParam, psp);