]> cygwin.com Git - cygwin-apps/setup.git/blob - proppage.cc
2003-10-23 Jerry D. Hedden <jerry@hedden.us>
[cygwin-apps/setup.git] / proppage.cc
1 /*
2 * Copyright (c) 2001, 2002, 2003 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"
22 #include "resource.h"
23 #include "state.h"
24
25 #include "getopt++/BoolOption.h"
26
27 bool PropertyPage::DoOnceForSheet = true;
28
29 PropertyPage::PropertyPage ()
30 {
31 proc = NULL;
32 cmdproc = NULL;
33 IsFirst = false;
34 IsLast = false;
35 }
36
37 PropertyPage::~PropertyPage ()
38 {
39 }
40
41 bool PropertyPage::Create (int TemplateID)
42 {
43 return Create (NULL, NULL, TemplateID);
44 }
45
46 bool PropertyPage::Create (DLGPROC dlgproc, int TemplateID)
47 {
48 return Create (dlgproc, NULL, TemplateID);
49 }
50
51 bool
52 PropertyPage::Create (DLGPROC dlgproc,
53 BOOL (*cproc) (HWND h, int id, HWND hwndctl,
54 UINT code), int TemplateID)
55 {
56 psp.dwSize = sizeof (PROPSHEETPAGE);
57 psp.dwFlags = 0;
58 psp.hInstance = GetInstance ();
59 psp.pfnDlgProc = FirstDialogProcReflector;
60 psp.pszTemplate = MAKEINTRESOURCE(TemplateID);
61 psp.lParam = (LPARAM) this;
62 psp.pfnCallback = NULL;
63
64 proc = dlgproc;
65 cmdproc = cproc;
66
67 return true;
68 }
69
70 BOOL CALLBACK
71 PropertyPage::FirstDialogProcReflector (HWND hwnd, UINT message,
72 WPARAM wParam, LPARAM lParam)
73 {
74 PropertyPage *This;
75
76 if (message != WM_INITDIALOG)
77 {
78 // Don't handle anything until we get a WM_INITDIALOG message, which
79 // will have our 'this' pointer with it.
80 return FALSE;
81 }
82
83 This = (PropertyPage *) (((PROPSHEETPAGE *) lParam)->lParam);
84
85 SetWindowLong (hwnd, DWL_USER, (DWORD) This);
86 SetWindowLong (hwnd, DWL_DLGPROC, (DWORD) DialogProcReflector);
87
88 This->SetHWND (hwnd);
89 return This->DialogProc (message, wParam, lParam);
90 }
91
92 BOOL CALLBACK
93 PropertyPage::DialogProcReflector (HWND hwnd, UINT message, WPARAM wParam,
94 LPARAM lParam)
95 {
96 PropertyPage *This;
97
98 This = (PropertyPage *) GetWindowLong (hwnd, DWL_USER);
99
100 return This->DialogProc (message, wParam, lParam);
101 }
102
103 BOOL CALLBACK
104 PropertyPage::DialogProc (UINT message, WPARAM wParam, LPARAM lParam)
105 {
106 if (proc != NULL)
107 {
108 proc (GetHWND (), message, wParam, lParam);
109 }
110
111 bool retval;
112
113 switch (message)
114 {
115 case WM_INITDIALOG:
116 {
117 OnInit ();
118
119 setTitleFont ();
120
121 // TRUE = Set focus to default control (in wParam).
122 return TRUE;
123 break;
124 }
125 case WM_NOTIFY:
126 switch (((NMHDR FAR *) lParam)->code)
127 {
128 case PSN_APPLY:
129 SetWindowLong (GetHWND (), DWL_MSGRESULT, PSNRET_NOERROR);
130 return TRUE;
131 break;
132 case PSN_SETACTIVE:
133 {
134 if (DoOnceForSheet)
135 {
136 // Tell our parent PropSheet what its own HWND is.
137 GetOwner ()->SetHWNDFromPage (((NMHDR FAR *) lParam)->
138 hwndFrom);
139 GetOwner ()->CenterWindow ();
140 DoOnceForSheet = false;
141 }
142
143 // Set the wizard buttons apropriately
144 if (IsFirst)
145 {
146 // Disable "Back" on first page.
147 GetOwner ()->SetButtons (PSWIZB_NEXT);
148 }
149 else if (IsLast)
150 {
151 // Disable "Next", enable "Finish" on last page
152 GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_FINISH);
153 }
154 else
155 {
156 // Middle page, enable both "Next" and "Back" buttons
157 GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_NEXT);
158 }
159
160 if(!wantsActivation())
161 {
162 ::SetWindowLong (GetHWND (), DWL_MSGRESULT, -1);
163 return TRUE;
164 }
165
166 OnActivate ();
167
168 if (unattended_mode)
169 {
170 // -2 == disable unattended mode, display page
171 // -1 == display page but stay in unattended mode (progress bars)
172 // 0 == skip to next page
173 // IDD_* == skip to specified page
174 long nextwindow = OnUnattended();
175 if (nextwindow == -2)
176 {
177 unattended_mode = false;
178 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
179 return TRUE;
180 }
181 else if (nextwindow == -1)
182 {
183 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
184 return TRUE;
185 }
186 else if (nextwindow == 0)
187 {
188 SetWindowLong (GetHWND (), DWL_MSGRESULT, -1);
189 return TRUE;
190 }
191 else
192 {
193 SetWindowLong (GetHWND (), DWL_MSGRESULT, nextwindow);
194 return TRUE;
195 }
196 }
197 else
198 {
199 // 0 == Accept activation, -1 = Don't accept
200 ::SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
201 return TRUE;
202 }
203
204 }
205 break;
206 case PSN_KILLACTIVE:
207 OnDeactivate ();
208 // FALSE = Allow deactivation
209 SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE);
210 return TRUE;
211 break;
212 case PSN_WIZNEXT:
213 {
214 LONG retval;
215 retval = OnNext ();
216 SetWindowLong (GetHWND (), DWL_MSGRESULT, retval);
217 return TRUE;
218 }
219 break;
220 case PSN_WIZBACK:
221 {
222 LONG retval;
223 retval = OnBack ();
224 SetWindowLong (GetHWND (), DWL_MSGRESULT, retval);
225 return TRUE;
226 }
227 break;
228 case PSN_WIZFINISH:
229 retval = OnFinish ();
230 // False = Allow the wizard to finish
231 SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE);
232 return TRUE;
233 break;
234 default:
235 // Unrecognized notification
236 return FALSE;
237 break;
238 }
239 break;
240 case WM_COMMAND:
241 {
242 bool retval;
243
244 retval =
245 OnMessageCmd (LOWORD (wParam), (HWND) lParam, HIWORD (wParam));
246 if (retval == true)
247 {
248 // Handled, return 0
249 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
250 return TRUE;
251 }
252 else if (cmdproc != NULL)
253 {
254 return HANDLE_WM_COMMAND (GetHWND (), wParam, lParam, cmdproc);
255 }
256 break;
257 }
258 default:
259 break;
260 }
261
262 if ((message >= WM_APP) && (message < 0xC000))
263 {
264 // It's a private app message
265 return OnMessageApp (message, wParam, lParam);
266 }
267
268 // Wasn't handled
269 return FALSE;
270 }
271
272 void
273 PropertyPage::setTitleFont ()
274 {
275 // These font settings will just silently fail when the resource id
276 // is not present on a page.
277 // Set header title font of each internal page
278 SetDlgItemFont(IDC_STATIC_HEADER_TITLE, "MS Shell Dlg", 8, FW_BOLD);
279 // Set the font for the IDC_STATIC_WELCOME_TITLE
280 SetDlgItemFont(IDC_STATIC_WELCOME_TITLE, "Arial", 12, FW_BOLD);
281 }
This page took 0.048423 seconds and 5 git commands to generate.