]>
Commit | Line | Data |
---|---|---|
df62e023 RC |
1 | /* |
2 | * Copyright (c) 2001, Gary R. Van Sickle. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Gary R. Van Sickle <g.r.vansickle@worldnet.att.net> | |
13 | * | |
14 | */ | |
15 | ||
16 | // This is the implementation of the PropertyPage class. It works closely with the | |
17 | // PropSheet class to implement a single page of the property sheet. | |
18 | ||
19 | #include "proppage.h" | |
20 | #include "propsheet.h" | |
21 | #include "win32.h" | |
b7301c43 | 22 | #include "resource.h" |
df62e023 RC |
23 | |
24 | bool PropertyPage::DoOnceForSheet = true; | |
25 | ||
26 | PropertyPage::PropertyPage () | |
27 | { | |
28 | proc = NULL; | |
29 | cmdproc = NULL; | |
30 | IsFirst = false; | |
31 | IsLast = false; | |
32 | } | |
33 | ||
34 | PropertyPage::~PropertyPage () | |
35 | { | |
36 | } | |
37 | ||
38 | bool PropertyPage::Create (int TemplateID) | |
39 | { | |
40 | return Create (NULL, NULL, TemplateID); | |
41 | } | |
42 | ||
43 | bool PropertyPage::Create (DLGPROC dlgproc, int TemplateID) | |
44 | { | |
45 | return Create (dlgproc, NULL, TemplateID); | |
46 | } | |
47 | ||
48 | bool | |
49 | PropertyPage::Create (DLGPROC dlgproc, | |
50 | BOOL (*cproc) (HWND h, int id, HWND hwndctl, | |
51 | UINT code), int TemplateID) | |
52 | { | |
53 | psp.dwSize = sizeof (PROPSHEETPAGE); | |
54 | psp.dwFlags = 0; | |
55 | psp.hInstance = GetInstance (); | |
56 | psp.pfnDlgProc = FirstDialogProcReflector; | |
57 | psp.pszTemplate = (LPCSTR) TemplateID; | |
58 | psp.lParam = (LPARAM) this; | |
59 | psp.pfnCallback = NULL; | |
60 | ||
61 | proc = dlgproc; | |
62 | cmdproc = cproc; | |
63 | ||
64 | return true; | |
65 | } | |
66 | ||
67 | BOOL CALLBACK | |
68 | PropertyPage::FirstDialogProcReflector (HWND hwnd, UINT message, | |
69 | WPARAM wParam, LPARAM lParam) | |
70 | { | |
71 | PropertyPage *This; | |
72 | ||
73 | if (message != WM_INITDIALOG) | |
74 | { | |
75 | // Don't handle anything until we get a WM_INITDIALOG message, which | |
76 | // will have our this pointer with it. | |
77 | return FALSE; | |
78 | } | |
79 | ||
80 | This = (PropertyPage *) (((PROPSHEETPAGE *) lParam)->lParam); | |
81 | ||
82 | SetWindowLong (hwnd, DWL_USER, (DWORD) This); | |
83 | SetWindowLong (hwnd, DWL_DLGPROC, (DWORD) DialogProcReflector); | |
84 | ||
85 | This->SetHWND (hwnd); | |
86 | return This->DialogProc (message, wParam, lParam); | |
87 | } | |
88 | ||
89 | BOOL CALLBACK | |
90 | PropertyPage::DialogProcReflector (HWND hwnd, UINT message, WPARAM wParam, | |
91 | LPARAM lParam) | |
92 | { | |
93 | PropertyPage *This; | |
94 | ||
95 | This = (PropertyPage *) GetWindowLong (hwnd, DWL_USER); | |
96 | ||
97 | return This->DialogProc (message, wParam, lParam); | |
98 | } | |
99 | ||
100 | BOOL CALLBACK | |
101 | PropertyPage::DialogProc (UINT message, WPARAM wParam, LPARAM lParam) | |
102 | { | |
103 | if (proc != NULL) | |
104 | { | |
105 | proc (GetHWND (), message, wParam, lParam); | |
106 | } | |
107 | ||
108 | bool retval; | |
109 | ||
110 | switch (message) | |
111 | { | |
112 | case WM_INITDIALOG: | |
113 | { | |
114 | OnInit (); | |
b7301c43 RC |
115 | |
116 | // Set header title font of each internal page to MS Sans Serif, Bold, 8 Pt. | |
117 | // This will just silently fail on the first and last pages. | |
118 | SetDlgItemFont(IDC_STATIC_HEADER_TITLE, "MS Sans Serif", 8, FW_BOLD); | |
119 | ||
df62e023 RC |
120 | // TRUE = Set focus to default control (in wParam). |
121 | return TRUE; | |
122 | break; | |
123 | } | |
124 | case WM_NOTIFY: | |
125 | switch (((NMHDR FAR *) lParam)->code) | |
126 | { | |
127 | case PSN_APPLY: | |
128 | SetWindowLong (GetHWND (), DWL_MSGRESULT, PSNRET_NOERROR); | |
129 | return TRUE; | |
130 | break; | |
131 | case PSN_SETACTIVE: | |
132 | { | |
133 | if (DoOnceForSheet) | |
134 | { | |
135 | // Tell our parent PropSheet what its own HWND is. | |
136 | GetOwner ()->SetHWNDFromPage (((NMHDR FAR *) lParam)-> | |
137 | hwndFrom); | |
138 | GetOwner ()->CenterWindow (); | |
df62e023 RC |
139 | DoOnceForSheet = false; |
140 | } | |
141 | ||
142 | // Set the wizard buttons apropriately | |
143 | if (IsFirst) | |
144 | { | |
145 | // Disable "Back" on first page. | |
146 | GetOwner ()->SetButtons (PSWIZB_NEXT); | |
df62e023 RC |
147 | } |
148 | else if (IsLast) | |
149 | { | |
150 | // Disable "Next", enable "Finish" on last page | |
151 | GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_FINISH); | |
df62e023 RC |
152 | } |
153 | else | |
154 | { | |
155 | // Middle page, enable both "Next" and "Back" buttons | |
156 | GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_NEXT); | |
df62e023 RC |
157 | } |
158 | ||
159 | OnActivate (); | |
160 | ||
161 | // 0 == Accept activation, -1 = Don't accept | |
162 | ::SetWindowLong (GetHWND (), DWL_MSGRESULT, 0); | |
163 | return TRUE; | |
164 | } | |
165 | break; | |
166 | case PSN_KILLACTIVE: | |
167 | OnDeactivate (); | |
168 | // FALSE = Allow deactivation | |
169 | SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE); | |
170 | return TRUE; | |
171 | break; | |
172 | case PSN_WIZNEXT: | |
173 | { | |
174 | LONG retval; | |
175 | retval = OnNext (); | |
176 | SetWindowLong (GetHWND (), DWL_MSGRESULT, retval); | |
177 | return TRUE; | |
178 | } | |
179 | break; | |
180 | case PSN_WIZBACK: | |
181 | { | |
182 | LONG retval; | |
183 | retval = OnBack (); | |
184 | SetWindowLong (GetHWND (), DWL_MSGRESULT, retval); | |
185 | return TRUE; | |
186 | } | |
187 | break; | |
188 | case PSN_WIZFINISH: | |
189 | retval = OnFinish (); | |
190 | // False = Allow the wizard to finish | |
191 | SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE); | |
192 | return TRUE; | |
193 | break; | |
194 | default: | |
195 | // Unrecognized notification | |
196 | return FALSE; | |
197 | break; | |
198 | } | |
199 | break; | |
200 | case WM_COMMAND: | |
b7301c43 RC |
201 | { |
202 | bool retval; | |
203 | ||
204 | retval = | |
205 | OnMessageCmd (LOWORD (wParam), (HWND) lParam, HIWORD (wParam)); | |
206 | if (retval == true) | |
207 | { | |
208 | // Handled, return 0 | |
209 | SetWindowLong (GetHWND (), DWL_MSGRESULT, 0); | |
210 | return TRUE; | |
211 | } | |
212 | else if (cmdproc != NULL) | |
213 | { | |
214 | return HANDLE_WM_COMMAND (GetHWND (), wParam, lParam, cmdproc); | |
215 | } | |
216 | break; | |
217 | } | |
df62e023 RC |
218 | default: |
219 | break; | |
220 | } | |
221 | ||
222 | if ((message >= WM_APP) && (message < 0xC000)) | |
223 | { | |
224 | // It's a private app message | |
225 | return OnMessageApp (message, wParam, lParam); | |
226 | } | |
227 | ||
228 | // Wasn't handled | |
229 | return FALSE; | |
230 | } |