bab00a73051c62cbcff54e5b9fbbc188388ce631
[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.4 2004/06/17 21:23:50 kuehng 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 static VOID
50 CenterWindow(HWND hWnd)
51 {
52 HWND hWndParent;
53 RECT rcParent;
54 RECT rcWindow;
55
56 hWndParent = GetParent(hWnd);
57 if (hWndParent == NULL)
58 hWndParent = GetDesktopWindow();
59
60 GetWindowRect(hWndParent, &rcParent);
61 GetWindowRect(hWnd, &rcWindow);
62
63 SetWindowPos(hWnd,
64 HWND_TOP,
65 ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
66 ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
67 0,
68 0,
69 SWP_NOSIZE);
70 }
71
72
73 BOOL CALLBACK
74 WelcomeDlgProc(HWND hwndDlg,
75 UINT uMsg,
76 WPARAM wParam,
77 LPARAM lParam)
78 {
79 switch (uMsg)
80 {
81 case WM_INITDIALOG:
82 {
83 HWND hwndControl;
84 DWORD dwStyle;
85
86 hwndControl = GetParent(hwndDlg);
87
88 /* Center the wizard window */
89 CenterWindow (hwndControl);
90
91 /* Hide the system menu */
92 dwStyle = GetWindowLong(hwndControl, GWL_STYLE);
93 SetWindowLong(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);
94
95 /* Hide and disable the 'Cancel' button */
96 hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
97 ShowWindow (hwndControl, SW_HIDE);
98 EnableWindow (hwndControl, FALSE);
99 }
100 break;
101
102
103 case WM_NOTIFY:
104 {
105 LPNMHDR lpnm = (LPNMHDR)lParam;
106
107 switch (lpnm->code)
108 {
109 case PSN_SETACTIVE:
110 /* Enable the Next button */
111 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
112 break;
113
114 default:
115 break;
116 }
117 }
118 break;
119
120 default:
121 break;
122 }
123
124 return FALSE;
125 }
126
127
128 INT_PTR CALLBACK
129 OwnerPageDlgProc(HWND hwndDlg,
130 UINT uMsg,
131 WPARAM wParam,
132 LPARAM lParam)
133 {
134 PSETUPDATA SetupData;
135
136 /* Retrieve pointer to the global setup data */
137 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
138
139 switch (uMsg)
140 {
141 case WM_INITDIALOG:
142 {
143 /* Save pointer to the global setup data */
144 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
145 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
146
147 SendDlgItemMessage(hwndDlg, IDC_OWNERNAME, EM_LIMITTEXT, 50, 0);
148 SendDlgItemMessage(hwndDlg, IDC_OWNERORGANIZATION, EM_LIMITTEXT, 50, 0);
149
150 /* set focus to owner name */
151 SetFocus(GetDlgItem(hwndDlg,IDC_OWNERNAME));
152 }
153 break;
154
155
156 case WM_NOTIFY:
157 {
158 LPNMHDR lpnm = (LPNMHDR)lParam;
159
160 switch (lpnm->code)
161 {
162 case PSN_SETACTIVE:
163 /* Enable the Back and Next buttons */
164 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
165 break;
166
167 case PSN_WIZNEXT:
168 if (GetDlgItemText(hwndDlg, IDC_OWNERNAME, SetupData->OwnerName, 50) == 0)
169 {
170 MessageBox (hwndDlg,
171 _T("Setup cannot continue until you enter your name."),
172 _T("ReactOS Setup"),
173 MB_ICONERROR | MB_OK);
174 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
175 return TRUE;
176 }
177 GetDlgItemText(hwndDlg, IDC_OWNERORGANIZATION, SetupData->OwnerOrganization, 50);
178 break;
179
180 default:
181 break;
182 }
183 }
184 break;
185
186 default:
187 break;
188 }
189
190 return FALSE;
191 }
192
193
194 BOOL CALLBACK
195 ComputerPageDlgProc(HWND hwndDlg,
196 UINT uMsg,
197 WPARAM wParam,
198 LPARAM lParam)
199 {
200 PSETUPDATA SetupData;
201 TCHAR Password1[15];
202 TCHAR Password2[15];
203
204 /* Retrieve pointer to the global setup data */
205 SetupData = (PSETUPDATA)GetWindowLong (hwndDlg, GWL_USERDATA);
206
207 switch (uMsg)
208 {
209 case WM_INITDIALOG:
210 {
211 DWORD Length;
212
213 /* Save pointer to the global setup data */
214 SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
215 SetWindowLong(hwndDlg, GWL_USERDATA, (LONG)SetupData);
216
217 /* Retrieve current computer name */
218 Length = MAX_COMPUTERNAME_LENGTH + 1;
219 GetComputerNameA(SetupData->ComputerName, &Length);
220
221 /* Display current computer name */
222 SetDlgItemTextA(hwndDlg, IDC_COMPUTERNAME, SetupData->ComputerName);
223
224 /* Set text limits */
225 SendDlgItemMessage(hwndDlg, IDC_COMPUTERNAME, EM_LIMITTEXT, 64, 0);
226 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD1, EM_LIMITTEXT, 14, 0);
227 SendDlgItemMessage(hwndDlg, IDC_ADMINPASSWORD2, EM_LIMITTEXT, 14, 0);
228 }
229 break;
230
231
232 case WM_NOTIFY:
233 {
234 LPNMHDR lpnm = (LPNMHDR)lParam;
235
236 switch (lpnm->code)
237 {
238 case PSN_SETACTIVE:
239 /* Enable the Back and Next buttons */
240 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
241 break;
242
243 case PSN_WIZNEXT:
244 if (GetDlgItemText(hwndDlg, IDC_COMPUTERNAME, SetupData->ComputerName, 64) == 0)
245 {
246 MessageBox (hwndDlg,
247 _T("Setup cannot continue until you enter the name of your computer."),
248 _T("ReactOS Setup"),
249 MB_ICONERROR | MB_OK);
250 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
251 return TRUE;
252 }
253
254 /* FIXME: check computer name for invalid characters */
255
256 /* Check admin passwords */
257 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD1, Password1, 15);
258 GetDlgItemText(hwndDlg, IDC_ADMINPASSWORD2, Password2, 15);
259 if (_tcscmp (Password1, Password2))
260 {
261 MessageBox (hwndDlg,
262 _T("The passwords you entered do not match. Please enter "\
263 "the desired password again."),
264 _T("ReactOS Setup"),
265 MB_ICONERROR | MB_OK);
266 SetWindowLong(hwndDlg, DWL_MSGRESULT, -1);
267 return TRUE;
268 }
269
270 /* FIXME: check password for invalid characters */
271
272 _tcscpy (SetupData->AdminPassword, Password1);
273 break;
274
275 default:
276 break;
277 }
278 }
279 break;
280
281 default:
282 break;
283 }
284
285 return FALSE;
286 }
287
288
289 BOOL CALLBACK
290 FinishDlgProc(HWND hwndDlg,
291 UINT uMsg,
292 WPARAM wParam,
293 LPARAM lParam)
294 {
295
296 switch (uMsg)
297 {
298 case WM_INITDIALOG:
299 break;
300
301 case WM_NOTIFY:
302 {
303 LPNMHDR lpnm = (LPNMHDR)lParam;
304
305 switch (lpnm->code)
306 {
307 case PSN_SETACTIVE:
308 /* Enable the correct buttons on for the active page */
309 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_FINISH);
310 break;
311
312 case PSN_WIZBACK:
313 /* Handle a Back button click, if necessary */
314 break;
315
316 case PSN_WIZFINISH:
317 /* Handle a Finish button click, if necessary */
318 break;
319
320 default:
321 break;
322 }
323 }
324 break;
325
326 default:
327 break;
328 }
329
330 return FALSE;
331 }
332
333
334 VOID
335 InstallWizard (VOID)
336 {
337 PROPSHEETHEADER psh;
338 HPROPSHEETPAGE ahpsp[4];
339 PROPSHEETPAGE psp;
340 // SHAREDWIZDATA wizdata;
341
342 /* Clear setup data */
343 ZeroMemory (&SetupData, sizeof(SETUPDATA));
344
345 /* Create the Welcome page */
346 ZeroMemory (&psp, sizeof(PROPSHEETPAGE));
347 psp.dwSize = sizeof(PROPSHEETPAGE);
348 psp.dwFlags = PSP_DEFAULT; // | PSP_HIDEHEADER;
349 psp.hInstance = hDllInstance;
350 psp.lParam = (LPARAM)&SetupData;
351 psp.pfnDlgProc = WelcomeDlgProc;
352 psp.pszTemplate = MAKEINTRESOURCE(IDD_WELCOMEPAGE);
353 ahpsp[0] = CreatePropertySheetPage(&psp);
354
355 /* Create the Owner page */
356 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
357 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE2);
358 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE2);
359 psp.pszTemplate = MAKEINTRESOURCE(IDD_OWNERPAGE);
360 psp.pfnDlgProc = OwnerPageDlgProc;
361 ahpsp[1] = CreatePropertySheetPage(&psp);
362
363 /* Create the Computer page */
364 psp.dwFlags = PSP_DEFAULT; // | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
365 // psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_TITLE1);
366 // psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_SUBTITLE1);
367 psp.pfnDlgProc = ComputerPageDlgProc;
368 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPUTERPAGE);
369 ahpsp[2] = CreatePropertySheetPage(&psp);
370
371
372
373 /* Create the Finish page */
374 psp.dwFlags = PSP_DEFAULT; // | PSP_HIDEHEADER;
375 psp.pfnDlgProc = FinishDlgProc;
376 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
377 ahpsp[3] = CreatePropertySheetPage(&psp);
378
379 /* Create the property sheet */
380 psh.dwSize = sizeof(PROPSHEETHEADER);
381 psh.dwFlags = PSH_WIZARD; //PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
382 psh.hInstance = hDllInstance;
383 psh.hwndParent = NULL;
384 psh.nPages = 4;
385 psh.nStartPage = 0;
386 psh.phpage = ahpsp;
387 // psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
388 // psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER);
389
390 /* Display the wizard */
391 PropertySheet(&psh);
392 }
393
394 /* EOF */