xref: /reactos/dll/shellext/netshell/setup.cpp (revision 4567e13e)
1 /*
2  * PROJECT:     ReactOS Shell
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     ReactOS Networking Configuration
5  * COPYRIGHT:   Copyright 2016 Eric Kohl
6  */
7 
8 #include "precomp.h"
9 
10 #include <syssetup/syssetup.h>
11 
12 
13 #define NETWORK_SETUP_MAGIC 0x50515253
14 
15 typedef struct _NETWORKSETUPDATA
16 {
17     DWORD dwMagic;
18     BOOL bTypicalNetworkSetup;
19 
20 
21     PSETUPDATA pSetupData;
22 } NETWORKSETUPDATA, *PNETWORKSETUPDATA;
23 
24 
25 extern "C"
26 {
27 
28 static
29 VOID
30 SetBoldText(
31     HWND hwndDlg,
32     INT control,
33     PSETUPDATA pSetupData)
34 {
35     SendDlgItemMessageW(hwndDlg, control, WM_SETFONT, (WPARAM)pSetupData->hBoldFont, MAKELPARAM(TRUE, 0));
36 }
37 
38 static
39 INT_PTR
40 CALLBACK
41 NetworkSettingsPageDlgProc(
42     HWND hwndDlg,
43     UINT uMsg,
44     WPARAM wParam,
45     LPARAM lParam)
46 {
47     PNETWORKSETUPDATA pNetworkSetupData;
48     PSETUPDATA pSetupData;
49     LPNMHDR lpnm;
50 
51     /* Retrieve pointer to the global setup data */
52     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
53     if ((pNetworkSetupData != NULL) &&
54         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
55         pSetupData = pNetworkSetupData->pSetupData;
56 
57     switch (uMsg)
58     {
59         case WM_INITDIALOG:
60             /* Save pointer to the global setup data */
61             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
62             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
63             pSetupData = pNetworkSetupData->pSetupData;
64 
65             /* Set the fonts of both the options to bold */
66             SetBoldText(hwndDlg, IDC_NETWORK_TYPICAL, pSetupData);
67             SetBoldText(hwndDlg, IDC_NETWORK_CUSTOM, pSetupData);
68 
69             /* Set the typical settings option as the default */
70             SendDlgItemMessage(hwndDlg, IDC_NETWORK_TYPICAL, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
71 
72             if (pSetupData->UnattendSetup)
73             {
74                 //...
75             }
76             break;
77 
78         case WM_DESTROY:
79             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
80             //...
81             break;
82 
83         case WM_NOTIFY:
84             lpnm = (LPNMHDR)lParam;
85 
86             switch (lpnm->code)
87             {
88                 case PSN_SETACTIVE:
89                     /* Enable the Back and Next buttons */
90                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
91                     if (pSetupData->UnattendSetup)
92                     {
93                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKCOMPONENTPAGE);
94                         return TRUE;
95                     }
96                     break;
97 
98                 case PSN_WIZNEXT:
99                     pNetworkSetupData->bTypicalNetworkSetup = FALSE;
100 
101                     /* If the Typical Settings button is chosen, then skip to the Domain Page */
102                     if (IsDlgButtonChecked(hwndDlg, IDC_NETWORK_TYPICAL) == BST_CHECKED)
103                     {
104                         pNetworkSetupData->bTypicalNetworkSetup = TRUE;
105                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
106                         return TRUE;
107                     }
108                     break;
109 
110                 case PSN_WIZBACK:
111                     pSetupData->UnattendSetup = FALSE;
112                     break;
113             }
114             break;
115 
116         default:
117             break;
118     }
119 
120     return FALSE;
121 }
122 
123 static
124 INT_PTR
125 CALLBACK
126 NetworkComponentPageDlgProc(
127     HWND hwndDlg,
128     UINT uMsg,
129     WPARAM wParam,
130     LPARAM lParam)
131 {
132     PNETWORKSETUPDATA pNetworkSetupData;
133     PSETUPDATA pSetupData;
134     LPNMHDR lpnm;
135 
136     /* Retrieve pointer to the global setup data */
137     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
138     if ((pNetworkSetupData != NULL) &&
139         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
140         pSetupData = pNetworkSetupData->pSetupData;
141 
142     switch (uMsg)
143     {
144         case WM_INITDIALOG:
145             /* Save pointer to the global setup data */
146             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
147             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
148             pSetupData = pNetworkSetupData->pSetupData;
149 
150             SetBoldText(hwndDlg, IDC_NETWORK_DEVICE, pSetupData);
151 
152             if (pSetupData->UnattendSetup)
153             {
154                 //...
155             }
156             break;
157 
158         case WM_DESTROY:
159             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
160             //...
161             break;
162 
163         case WM_NOTIFY:
164             lpnm = (LPNMHDR)lParam;
165 
166             switch (lpnm->code)
167             {
168                 case PSN_SETACTIVE:
169                     /* Enable the Back and Next buttons */
170                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
171                     if (pSetupData->UnattendSetup)
172                     {
173                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKDOMAINPAGE);
174                         return TRUE;
175                     }
176                     break;
177 
178                 case PSN_WIZBACK:
179                     pSetupData->UnattendSetup = FALSE;
180                     break;
181             }
182             break;
183 
184         default:
185             break;
186     }
187 
188     return FALSE;
189 }
190 
191 static
192 INT_PTR
193 CALLBACK
194 NetworkDomainPageDlgProc(
195     HWND hwndDlg,
196     UINT uMsg,
197     WPARAM wParam,
198     LPARAM lParam)
199 {
200     PNETWORKSETUPDATA pNetworkSetupData;
201     PSETUPDATA pSetupData;
202     WCHAR DomainName[51];
203     WCHAR Title[64];
204     WCHAR ErrorName[256];
205     LPNMHDR lpnm;
206 
207     /* Retrieve pointer to the global setup data */
208     pNetworkSetupData = (PNETWORKSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
209     if ((pNetworkSetupData != NULL) &&
210         (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
211         pSetupData = pNetworkSetupData->pSetupData;
212 
213     switch (uMsg)
214     {
215         case WM_INITDIALOG:
216             /* Save pointer to the global setup data */
217             pNetworkSetupData = (PNETWORKSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
218             SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pNetworkSetupData);
219             pSetupData = pNetworkSetupData->pSetupData;
220 
221             /* Set the workgroup option as the default */
222             SendDlgItemMessage(hwndDlg, IDC_SELECT_WORKGROUP, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
223 
224             wcscpy(DomainName, L"WORKGROUP");
225 
226             /* Display current computer name */
227             SetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName);
228 
229             /* Set focus to owner name */
230             SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
231 
232             if (pSetupData->UnattendSetup)
233             {
234                 //...
235             }
236             break;
237 
238         case WM_DESTROY:
239             //...
240             /* ATTENTION: Free pNetworkSetupData only in one of the page functions!!! */
241             if (pNetworkSetupData != NULL)
242             {
243                 if ((!IsBadReadPtr(pNetworkSetupData, sizeof(NETWORKSETUPDATA))) &&
244                     (pNetworkSetupData->dwMagic == NETWORK_SETUP_MAGIC))
245                     HeapFree(GetProcessHeap(), 0, pNetworkSetupData);
246 
247                 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)NULL);
248             }
249             break;
250 
251         case WM_NOTIFY:
252             lpnm = (LPNMHDR)lParam;
253 
254             switch (lpnm->code)
255             {
256                 case PSN_SETACTIVE:
257                     /* Enable the Back and Next buttons */
258                     PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
259                     if (pSetupData->UnattendSetup)
260                     {
261                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, pSetupData->uPostNetworkWizardPage);
262                         return TRUE;
263                     }
264                     break;
265 
266                 case PSN_WIZNEXT:
267                     DomainName[0] = 0;
268                     if (GetDlgItemTextW(hwndDlg, IDC_DOMAIN_NAME, DomainName, 50) == 0)
269                     {
270                         if (0 == LoadStringW(netshell_hInstance, IDS_REACTOS_SETUP, Title, sizeof(Title) / sizeof(Title[0])))
271                         {
272                             wcscpy(Title, L"ReactOS Setup");
273                         }
274                         if (0 == LoadStringW(netshell_hInstance, IDS_WZD_DOMAIN_NAME, ErrorName, sizeof(ErrorName) / sizeof(ErrorName[0])))
275                         {
276                             wcscpy(ErrorName, L"Setup cannot continue until you\nenter the name of your domain/workgroup.");
277                         }
278                         MessageBoxW(hwndDlg, ErrorName, Title, MB_ICONERROR | MB_OK);
279 
280                         SetFocus(GetDlgItem(hwndDlg, IDC_DOMAIN_NAME));
281                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
282 
283                         //TODO: Implement setting the Domain/Workgroup
284 
285                         return TRUE;
286                     }
287                     break;
288 
289                 case PSN_WIZBACK:
290                     pSetupData->UnattendSetup = FALSE;
291 
292                     /* If the Typical setup chosen, then skip back to the Settings Page */
293                     if (pNetworkSetupData->bTypicalNetworkSetup == TRUE)
294                     {
295                         SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, IDD_NETWORKSETTINGSPAGE);
296                         return TRUE;
297                     }
298                     break;
299             }
300             break;
301 
302         default:
303             break;
304     }
305 
306     return FALSE;
307 }
308 
309 
310 DWORD
311 WINAPI
312 NetSetupRequestWizardPages(
313     PDWORD pPageCount,
314     HPROPSHEETPAGE *pPages,
315     PSETUPDATA pSetupData)
316 {
317     PNETWORKSETUPDATA pNetworkSetupData;
318     PROPSHEETPAGE psp = {0};
319     DWORD dwPageCount = 3;
320     INT nPage = 0;
321 
322     if (pPageCount == NULL)
323         return ERROR_INVALID_PARAMETER;
324 
325     if (pPages == NULL)
326     {
327         *pPageCount = dwPageCount;
328         return ERROR_SUCCESS;
329     }
330 
331     if (*pPageCount < dwPageCount)
332         return ERROR_BUFFER_OVERFLOW;
333 
334     pSetupData->uFirstNetworkWizardPage = IDD_NETWORKSETTINGSPAGE;
335 
336     pNetworkSetupData = (PNETWORKSETUPDATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(NETWORKSETUPDATA));
337     if (pNetworkSetupData == NULL)
338         return ERROR_OUTOFMEMORY;
339 
340     pNetworkSetupData->dwMagic = NETWORK_SETUP_MAGIC;
341     pNetworkSetupData->pSetupData = pSetupData;
342 
343 
344     /* Create the Network Settings page */
345     psp.dwSize = sizeof(PROPSHEETPAGE);
346     psp.hInstance = netshell_hInstance;
347     psp.lParam = (LPARAM)pNetworkSetupData;
348 
349     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
350     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSTITLE);
351     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKSETTINGSSUBTITLE);
352     psp.pfnDlgProc = NetworkSettingsPageDlgProc;
353     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKSETTINGSPAGE);
354     pPages[nPage++] = CreatePropertySheetPage(&psp);
355 
356     /* Create the Network Components page */
357     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
358     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTTITLE);
359     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKCOMPONENTSUBTITLE);
360     psp.pfnDlgProc = NetworkComponentPageDlgProc;
361     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKCOMPONENTPAGE);
362     pPages[nPage++] = CreatePropertySheetPage(&psp);
363 
364     /* Create the Domain/Workgroup page */
365     psp.dwFlags = PSP_DEFAULT | PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
366     psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINTITLE);
367     psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_NETWORKDOMAINSUBTITLE);
368     psp.pfnDlgProc = NetworkDomainPageDlgProc;
369     psp.pszTemplate = MAKEINTRESOURCE(IDD_NETWORKDOMAINPAGE);
370     pPages[nPage++] = CreatePropertySheetPage(&psp);
371 
372     *pPageCount = dwPageCount;
373 
374     return ERROR_SUCCESS;
375 }
376 
377 } // extern "C"
378