]> cygwin.com Git - cygwin-apps/setup.git/blob - proppage.cc
2003-07-27 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / proppage.cc
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"
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 = (LPCSTR) 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 // Set header title font of each internal page to MS Sans Serif, Bold, 8 Pt.
120 // This will just silently fail on the first and last pages.
121 SetDlgItemFont(IDC_STATIC_HEADER_TITLE, "MS Sans Serif", 8, FW_BOLD);
122
123 // TRUE = Set focus to default control (in wParam).
124 return TRUE;
125 break;
126 }
127 case WM_NOTIFY:
128 switch (((NMHDR FAR *) lParam)->code)
129 {
130 case PSN_APPLY:
131 SetWindowLong (GetHWND (), DWL_MSGRESULT, PSNRET_NOERROR);
132 return TRUE;
133 break;
134 case PSN_SETACTIVE:
135 {
136 if (DoOnceForSheet)
137 {
138 // Tell our parent PropSheet what its own HWND is.
139 GetOwner ()->SetHWNDFromPage (((NMHDR FAR *) lParam)->
140 hwndFrom);
141 GetOwner ()->CenterWindow ();
142 DoOnceForSheet = false;
143 }
144
145 // Set the wizard buttons apropriately
146 if (IsFirst)
147 {
148 // Disable "Back" on first page.
149 GetOwner ()->SetButtons (PSWIZB_NEXT);
150 }
151 else if (IsLast)
152 {
153 // Disable "Next", enable "Finish" on last page
154 GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_FINISH);
155 }
156 else
157 {
158 // Middle page, enable both "Next" and "Back" buttons
159 GetOwner ()->SetButtons (PSWIZB_BACK | PSWIZB_NEXT);
160 }
161
162 OnActivate ();
163
164 if (unattended_mode)
165 {
166 // -2 == disable unattended mode, display page
167 // -1 == display page but stay in unattended mode (progress bars)
168 // 0 == skip to next page
169 // IDD_* == skip to specified page
170 long nextwindow = OnUnattended();
171 if (nextwindow == -2)
172 {
173 unattended_mode = false;
174 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
175 return TRUE;
176 }
177 else if (nextwindow == -1)
178 {
179 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
180 return TRUE;
181 }
182 else if (nextwindow == 0)
183 {
184 SetWindowLong (GetHWND (), DWL_MSGRESULT, -1);
185 return TRUE;
186 }
187 else
188 {
189 SetWindowLong (GetHWND (), DWL_MSGRESULT, nextwindow);
190 return TRUE;
191 }
192 }
193 else
194 {
195 // 0 == Accept activation, -1 = Don't accept
196 ::SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
197 return TRUE;
198 }
199
200 }
201 break;
202 case PSN_KILLACTIVE:
203 OnDeactivate ();
204 // FALSE = Allow deactivation
205 SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE);
206 return TRUE;
207 break;
208 case PSN_WIZNEXT:
209 {
210 LONG retval;
211 retval = OnNext ();
212 SetWindowLong (GetHWND (), DWL_MSGRESULT, retval);
213 return TRUE;
214 }
215 break;
216 case PSN_WIZBACK:
217 {
218 LONG retval;
219 retval = OnBack ();
220 SetWindowLong (GetHWND (), DWL_MSGRESULT, retval);
221 return TRUE;
222 }
223 break;
224 case PSN_WIZFINISH:
225 retval = OnFinish ();
226 // False = Allow the wizard to finish
227 SetWindowLong (GetHWND (), DWL_MSGRESULT, FALSE);
228 return TRUE;
229 break;
230 default:
231 // Unrecognized notification
232 return FALSE;
233 break;
234 }
235 break;
236 case WM_COMMAND:
237 {
238 bool retval;
239
240 retval =
241 OnMessageCmd (LOWORD (wParam), (HWND) lParam, HIWORD (wParam));
242 if (retval == true)
243 {
244 // Handled, return 0
245 SetWindowLong (GetHWND (), DWL_MSGRESULT, 0);
246 return TRUE;
247 }
248 else if (cmdproc != NULL)
249 {
250 return HANDLE_WM_COMMAND (GetHWND (), wParam, lParam, cmdproc);
251 }
252 break;
253 }
254 default:
255 break;
256 }
257
258 if ((message >= WM_APP) && (message < 0xC000))
259 {
260 // It's a private app message
261 return OnMessageApp (message, wParam, lParam);
262 }
263
264 // Wasn't handled
265 return FALSE;
266 }
This page took 0.047419 seconds and 5 git commands to generate.