- Use new userenv.h prototypes.
[reactos.git] / reactos / lib / syssetup / wizard.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2004 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: wizard.c,v 1.2 2004/04/19 10:54:23 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS system libraries
23 * PURPOSE: System setup
24 * FILE: lib/syssetup/wizard.c
25 * PROGRAMER: Eric Kohl (ekohl@rz-online.de)
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <windows.h>
31 #include <commctrl.h>
32
33 #include <string.h>
34 #include <tchar.h>
35
36 #include <syssetup.h>
37
38 #include "globals.h"
39 #include "resource.h"
40
41
42 /* GLOBALS ******************************************************************/
43
44 static SETUPDATA SetupData;
45
46
47 /* FUNCTIONS ****************************************************************/
48
49
50 BOOL CALLBACK
51 WelcomeDlgProc(HWND hwndDlg,
52 UINT uMsg,
53 WPARAM wParam,
54 LPARAM lParam)
55 {
56 switch (uMsg)
57 {
58 case WM_INITDIALOG:
59 {
60 HWND hwndControl;
61 DWORD dwStyle;
62
63 /* Hide the system menu */
64 hwndControl = GetParent(hwndDlg);
65 dwStyle = GetWindowLong(hwndControl, GWL_STYLE);
66 SetWindowLong(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);
67
68 /* Hide and disable the 'Cancel' button */
69 hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
70 ShowWindow (hwndControl, SW_HIDE);
71 EnableWindow (hwndControl, FALSE);
72 }
73 break;
74
75
76 case WM_NOTIFY:
77 {
78 LPNMHDR lpnm = (LPNMHDR)lParam;
79
80 switch (lpnm->code)
81 {
82 case PSN_SETACTIVE:
83 /* Enable the Next button */
84 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
85 break;
86
87 default:
88 break;
89 }
90 }
91 break;
92
93 default:
94 break;
95 }
96 return FALSE;
97 }
98
99
100 INT_PTR CALLBACK
101 OwnerPageDlgProc(HWND hwndDlg,
102 UINT uMsg,
103 WPARAM wParam,
104 LPARAM lParam)
105 {
106 PSETUPDATA SetupData;
107
108 /* Retrieve pointer to the global setup data */
109 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
110
111 switch (uMsg)
112 {
113 case WM_INITDIALOG:
114 {
115 /* Save pointer to the global setup data */
116 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
117 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
118
119 SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
120 SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
121 }
122 break;
123
124
125 case WM_NOTIFY:
126 {
127 LPNMHDR lpnm = (LPNMHDR)lParam;
128
129 switch (lpnm->code)
130 {
131 case PSN_SETACTIVE:
132 /* Enable the Back and Next buttons */
133 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
134 break;
135
136 case PSN_WIZNEXT:
137 if (GetDlgItemText(hwndDlg, IDC_OWNERNAME, SetupData->OwnerName, 50) == 0)
138 {
139 MessageBox (hwndDlg,
140 _T("Setup cannot continue until you enter your name."),
141 _T("ReactOS Setup"),
142 MB_ICONERROR | MB_OK);
143 return -1;
144 }
145 GetDlgItemText(hwndDlg, IDC_OWNERORGANIZATION, SetupData->OwnerOrganization, 50);
146 break;
147
148 default:
149 break;
150 }
151 }
152 break;
153
154 default:
155 break;
156 }
157
158 return 0;
159 }
160
161
162 BOOL CALLBACK
163 ComputerPageDlgProc(HWND hwndDlg,
164 UINT uMsg,
165 WPARAM wParam,
166 LPARAM lParam)
167 {
168 PSETUPDATA SetupData;
169 TCHAR Password1[15];
170 TCHAR Password2[15];
171
172 /* Retrieve pointer to the global setup data */
173 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
174
175 switch (uMsg)
176 {
177 case WM_INITDIALOG:
178 {
179 DWORD Length;
180
181 /* Save pointer to the global setup data */
182 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
183 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
184
185 /* Retrieve current computer name */
186 Length = MAX_COMPUTERNAME_LENGTH + 1;
187 GetComputerNameA(SetupData->ComputerName, &Length);
188
189 /* Display current computer name */
190 SetDlgItemTextA(hwndDlg, IDC_COMPUTERNAME, SetupData->ComputerName);
191
192 /* Set text limits */
193 SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, 64, 0);
194 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 14, 0);
195 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 14, 0);
196 }
197 break;
198
199
200 case WM_NOTIFY:
201 {
202 LPNMHDR lpnm = (LPNMHDR)lParam;
203
204 switch (lpnm->code)
205 {
206 case PSN_SETACTIVE:
207 /* Enable the Back and Next buttons */
208 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
209 break;
210
211 case PSN_WIZNEXT:
212 if (GetDlgItemText(hwndDlg, IDC_COMPUTERNAME, SetupData->ComputerName, 64) == 0)
213 {
214 MessageBox (hwndDlg,
215 _T("Setup cannot continue until you enter the name of your computer."),
216 _T("ReactOS Setup"),
217 MB_ICONERROR | MB_OK);
218 return -1;
219 }
220
221 /* FIXME: check computer name for invalid characters */
222
223 /* Check admin passwords */
224 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15);
225 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15);
226 if (_tcscmp (Password1, Password2))
227 {
228 MessageBox (hwndDlg,
229 _T("The passwords you entered do not match. Please enter "\
230 "the desired password again."),
231 _T("ReactOS Setup"),
232 MB_ICONERROR | MB_OK);
233 return -1;
234 }
235
236 /* FIXME: check password for invalid characters */
237
238 _tcscpy (SetupData->AdminPassword, Password1);
239 break;
240
241 default:
242 break;
243 }
244 }
245 break;
246
247 default:
248 break;
249 }
250 return FALSE;
251 }
252
253
254 BOOL CALLBACK
255 FinishDlgProc(HWND hwndDlg,
256 UINT uMsg,
257 WPARAM wParam,
258 LPARAM lParam)
259 {
260
261 switch (uMsg)
262 {
263 case WM_INITDIALOG:
264 break;
265
266 case WM_NOTIFY:
267 {
268 LPNMHDR lpnm = (LPNMHDR)lParam;
269
270 switch (lpnm->code)
271 {
272 case PSN_SETACTIVE:
273 /* Enable the correct buttons on for the active page */
274 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
275 break;
276
277 case PSN_WIZBACK:
278 /* Handle a Back button click, if necessary */
279 break;
280
281 case PSN_WIZFINISH:
282 /* Handle a Finish button click, if necessary */
283 break;
284
285 default:
286 break;
287 }
288 }
289 break;
290
291 default:
292 break;
293 }
294
295 return 0;
296 }
297
298
299 VOID
300 InstallWizard (VOID)
301 {
302 PROPSHEETHEADER psh;
303 HPROPSHEETPAGE ahpsp[4];
304 PROPSHEETPAGE psp;
305 // SHAREDWIZDATA wizdata;
306
307 /* Clear setup data */
308 ZeroMemory (&SetupData, sizeof(SETUPDATA));
309
310 /* Create the Welcome page */
311 ZeroMemory (&psp, sizeof(PROPSHEETPAGE));
312 psp.dwSize = sizeof(PROPSHEETPAGE);
313 psp.dwFlags = PSP_DEFAULT; // | PSP_HIDEHEADER;
314 psp.hInstance = hDllInstance;
315 psp.lParam = (LPARAM)&SetupData;
316 psp.pfnDlgProc = WelcomeDlgProc;
317 psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
318 ahpsp[0] = CreatePropertySheetPage(&psp);
319
320 /* Create the Owner page */
321 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
322 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE2);
323 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE2);
324 psp.pszTemplate = MAKEINTRESOURCE(IDD_OWNERPAGE);
325 psp.pfnDlgProc = OwnerPageDlgProc;
326 ahpsp[1] = CreatePropertySheetPage(&psp);
327
328 /* Create the Computer page */
329 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
330 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE1);
331 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE1);
332 psp.pfnDlgProc = ComputerPageDlgProc;
333 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPUTERPAGE);
334 ahpsp[2] = CreatePropertySheetPage(&psp);
335
336
337
338 /* Create the Finish page */
339 psp.dwFlags = PSP_DEFAULT; // | PSP_HIDEHEADER;
340 psp.pfnDlgProc = FinishDlgProc;
341 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
342 ahpsp[3] = CreatePropertySheetPage(&psp);
343
344 /* Create the property sheet */
345 psh.dwSize = sizeof(PROPSHEETHEADER);
346 psh.dwFlags = PSH_WIZARD; //PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
347 psh.hInstance = hDllInstance;
348 psh.hwndParent = NULL;
349 psh.nPages = 4;
350 psh.nStartPage = 0;
351 psh.phpage = ahpsp;
352 // psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
353 // psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER);
354
355 /* Display the wizard */
356 PropertySheet (&psh);
357 }
358
359 /* EOF */