- Add more dialogs
[reactos.git] / reactos / dll / cpl / hdwwiz / hdwwiz.c
1 /*
2 * ReactOS New devices installation
3 * Copyright (C) 2005, 2008 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /*
20 * PROJECT: ReactOS Add hardware control panel
21 * FILE: dll/cpl/hdwwiz/hdwwiz.c
22 * PURPOSE: ReactOS Add hardware control panel
23 * PROGRAMMER: Hervé Poussineau (hpoussin@reactos.org)
24 * Dmitry Chapyshev (dmitry@reactos.org)
25 */
26
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <setupapi.h>
30 #include <cpl.h>
31 #include <tchar.h>
32 #include <stdio.h>
33
34 #define NDEBUG
35 #include <debug.h>
36
37 #include "resource.h"
38 #include "hdwwiz.h"
39
40 /* GLOBALS ******************************************************************/
41
42 HINSTANCE hApplet = NULL;
43 HFONT hTitleFont;
44
45 typedef BOOL (WINAPI *PINSTALL_NEW_DEVICE)(HWND, LPGUID, PDWORD);
46
47
48 BOOL CALLBACK
49 InstallNewDevice(HWND hwndParent, LPGUID ClassGuid, PDWORD pReboot)
50 {
51 return FALSE;
52 }
53
54 static HFONT
55 CreateTitleFont(VOID)
56 {
57 NONCLIENTMETRICS ncm;
58 LOGFONT LogFont;
59 HDC hdc;
60 INT FontSize;
61 HFONT hFont;
62
63 ncm.cbSize = sizeof(NONCLIENTMETRICS);
64 SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
65
66 LogFont = ncm.lfMessageFont;
67 LogFont.lfWeight = FW_BOLD;
68 _tcscpy(LogFont.lfFaceName, _T("MS Shell Dlg"));
69
70 hdc = GetDC(NULL);
71 FontSize = 12;
72 LogFont.lfHeight = 0 - GetDeviceCaps (hdc, LOGPIXELSY) * FontSize / 72;
73 hFont = CreateFontIndirect(&LogFont);
74 ReleaseDC(NULL, hdc);
75
76 return hFont;
77 }
78
79 static INT_PTR CALLBACK
80 StartPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
81 {
82 switch (uMsg)
83 {
84 case WM_INITDIALOG:
85 {
86 /* Set title font */
87 SendDlgItemMessage(hwndDlg, IDC_FINISHTITLE, WM_SETFONT, (WPARAM)hTitleFont, (LPARAM)TRUE);
88 }
89 break;
90 }
91
92 return FALSE;
93 }
94
95 static INT_PTR CALLBACK
96 SearchPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
97 {
98 return FALSE;
99 }
100
101 static INT_PTR CALLBACK
102 IsConnctedPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
103 {
104 switch (uMsg)
105 {
106 case WM_COMMAND:
107 {
108 if(HIWORD(wParam) == BN_CLICKED)
109 {
110 if ((SendDlgItemMessage(hwndDlg, IDC_CONNECTED, BM_GETCHECK, 0, 0) == BST_CHECKED) ||
111 (SendDlgItemMessage(hwndDlg, IDC_NOTCONNECTED, BM_GETCHECK, 0, 0) == BST_CHECKED))
112 {
113 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
114 }
115 else
116 {
117 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
118 }
119 }
120 }
121 break;
122
123 case WM_NOTIFY:
124 {
125 LPNMHDR lpnm = (LPNMHDR)lParam;
126
127 switch (lpnm->code)
128 {
129 case PSN_SETACTIVE:
130 {
131 /* Disable "Next" button */
132 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK);
133 }
134 break;
135 }
136 }
137 break;
138 }
139
140 return FALSE;
141 }
142
143 static INT_PTR CALLBACK
144 FinishPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
145 {
146 switch (uMsg)
147 {
148 case WM_INITDIALOG:
149 {
150 /* Set title font */
151 SendDlgItemMessage(hwndDlg, IDC_FINISHTITLE, WM_SETFONT, (WPARAM)hTitleFont, (LPARAM)TRUE);
152 }
153 break;
154
155 case WM_NOTIFY:
156 {
157 LPNMHDR lpnm = (LPNMHDR)lParam;
158
159 switch (lpnm->code)
160 {
161 case PSN_SETACTIVE:
162 {
163 /* Only "Finish" button */
164 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH);
165 }
166 break;
167 }
168 }
169 break;
170 }
171
172 return FALSE;
173 }
174
175 static VOID
176 HardwareWizardInit(HWND hwnd)
177 {
178 HPROPSHEETPAGE ahpsp[3];
179 PROPSHEETPAGE psp = {0};
180 PROPSHEETHEADER psh;
181 UINT nPages = 0;
182
183 /* Create the Start page, until setup is working */
184 psp.dwSize = sizeof(PROPSHEETPAGE);
185 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
186 psp.hInstance = hApplet;
187 psp.lParam = 0;
188 psp.pfnDlgProc = StartPageDlgProc;
189 psp.pszTemplate = MAKEINTRESOURCE(IDD_STARTPAGE);
190 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
191
192 /* Create search page */
193 psp.dwSize = sizeof(PROPSHEETPAGE);
194 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
195 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_SEARCHTITLE);
196 psp.pszHeaderSubTitle = NULL;
197 psp.hInstance = hApplet;
198 psp.lParam = 0;
199 psp.pfnDlgProc = SearchPageDlgProc;
200 psp.pszTemplate = MAKEINTRESOURCE(IDD_SEARCHPAGE);
201 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
202
203 /* Create is connected page */
204 psp.dwSize = sizeof(PROPSHEETPAGE);
205 psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
206 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_ISCONNECTED);
207 psp.pszHeaderSubTitle = NULL;
208 psp.hInstance = hApplet;
209 psp.lParam = 0;
210 psp.pfnDlgProc = IsConnctedPageDlgProc;
211 psp.pszTemplate = MAKEINTRESOURCE(IDD_ISCONNECTEDPAGE);
212 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
213
214 /* Create finish page */
215 psp.dwSize = sizeof(PROPSHEETPAGE);
216 psp.dwFlags = PSP_DEFAULT | PSP_HIDEHEADER;
217 psp.hInstance = hApplet;
218 psp.lParam = 0;
219 psp.pfnDlgProc = FinishPageDlgProc;
220 psp.pszTemplate = MAKEINTRESOURCE(IDD_FINISHPAGE);
221 ahpsp[nPages++] = CreatePropertySheetPage(&psp);
222
223 /* Create the property sheet */
224 psh.dwSize = sizeof(PROPSHEETHEADER);
225 psh.dwFlags = PSH_WIZARD97 | PSH_WATERMARK | PSH_HEADER;
226 psh.hInstance = hApplet;
227 psh.hwndParent = NULL;
228 psh.nPages = nPages;
229 psh.nStartPage = 0;
230 psh.phpage = ahpsp;
231 psh.pszbmWatermark = MAKEINTRESOURCE(IDB_WATERMARK);
232 psh.pszbmHeader = MAKEINTRESOURCE(IDB_HEADER);
233
234 /* Create title font */
235 hTitleFont = CreateTitleFont();
236
237 /* Display the wizard */
238 PropertySheet(&psh);
239
240 DeleteObject(hTitleFont);
241 }
242
243 VOID CALLBACK
244 AddHardwareWizard(HWND hwnd, LPWSTR lpName)
245 {
246 if (lpName != NULL)
247 {
248 DPRINT1("No support of remote installation yet!\n");
249 return;
250 }
251
252 HardwareWizardInit(hwnd);
253 }
254
255 /* Control Panel Callback */
256 LONG CALLBACK
257 CPlApplet(HWND hwndCpl,
258 UINT uMsg,
259 LPARAM lParam1,
260 LPARAM lParam2)
261 {
262 switch (uMsg)
263 {
264 case CPL_INIT:
265 return TRUE;
266
267 case CPL_GETCOUNT:
268 return 1;
269
270 case CPL_INQUIRE:
271 {
272 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
273 CPlInfo->lData = 0;
274 CPlInfo->idIcon = IDI_CPLICON;
275 CPlInfo->idName = IDS_CPLNAME;
276 CPlInfo->idInfo = IDS_CPLDESCRIPTION;
277 }
278 break;
279
280 case CPL_DBLCLK:
281 AddHardwareWizard(hwndCpl, NULL);
282 break;
283 }
284
285 return FALSE;
286 }
287
288
289 BOOL WINAPI
290 DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
291 {
292 UNREFERENCED_PARAMETER(lpvReserved);
293
294 switch (dwReason)
295 {
296 case DLL_PROCESS_ATTACH:
297 hApplet = hinstDLL;
298 break;
299 }
300
301 return TRUE;
302 }