[SYSDM] Rename some functions. #179
[reactos.git] / dll / cpl / intl / intl.c
1 /*
2 * ReactOS
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * PROJECT: ReactOS International Control Panel
21 * FILE: dll/cpl/intl/intl.c
22 * PURPOSE: Property sheet code
23 * PROGRAMMER: Eric Kohl
24 */
25
26 #include "intl.h"
27
28 #include <debug.h>
29
30 #define NUM_APPLETS (1)
31
32 #define BUFFERSIZE 512
33
34 static LONG APIENTRY
35 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
36
37
38 HINSTANCE hApplet = 0;
39 HWND hCPLWindow;
40 HINF hSetupInf = INVALID_HANDLE_VALUE;
41 DWORD IsUnattendedSetupEnabled = 0;
42 DWORD UnattendLCID = 0;
43
44
45 /* Applets */
46 APPLET Applets[NUM_APPLETS] =
47 {
48 {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, Applet}
49 };
50
51 VOID
52 PrintErrorMsgBox(UINT msg)
53 {
54 WCHAR szErrorText[BUFFERSIZE];
55 WCHAR szErrorCaption[BUFFERSIZE];
56
57 LoadStringW(hApplet, msg, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
58 LoadStringW(hApplet, IDS_ERROR, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
59
60 MessageBoxW(NULL, szErrorText, szErrorCaption, MB_OK | MB_ICONERROR);
61 }
62
63 INT
64 ResourceMessageBox(
65 HWND hwnd,
66 UINT uType,
67 UINT uCaptionId,
68 UINT uMessageId)
69 {
70 WCHAR szErrorText[BUFFERSIZE];
71 WCHAR szErrorCaption[BUFFERSIZE];
72
73 LoadStringW(hApplet, uMessageId, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
74 LoadStringW(hApplet, uCaptionId, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
75
76 return MessageBoxW(hwnd, szErrorText, szErrorCaption, uType);
77 }
78
79 static VOID
80 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
81 {
82 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
83 psp->dwSize = sizeof(PROPSHEETPAGE);
84 psp->dwFlags = PSP_DEFAULT;
85 psp->hInstance = hApplet;
86 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
87 psp->pfnDlgProc = DlgProc;
88 psp->lParam = lParam;
89 }
90
91 BOOL
92 OpenSetupInf(VOID)
93 {
94 PWSTR lpCmdLine;
95 PWSTR lpSwitch;
96 size_t len;
97
98 lpCmdLine = GetCommandLineW();
99
100 lpSwitch = wcsstr(lpCmdLine, L"/f:\"");
101 if (!lpSwitch)
102 return FALSE;
103
104 len = wcslen(lpSwitch);
105 if (len < 5 || lpSwitch[len-1] != L'\"')
106 {
107 DPRINT1("Invalid switch: %ls\n", lpSwitch);
108 return FALSE;
109 }
110
111 lpSwitch[len-1] = L'\0';
112
113 hSetupInf = SetupOpenInfFileW(&lpSwitch[4], NULL, INF_STYLE_OLDNT, NULL);
114 if (hSetupInf == INVALID_HANDLE_VALUE)
115 {
116 DPRINT1("Failed to open INF file: %ls\n", &lpSwitch[4]);
117 return FALSE;
118 }
119
120 return TRUE;
121 }
122
123 VOID
124 ParseSetupInf(VOID)
125 {
126 INFCONTEXT InfContext;
127 WCHAR szBuffer[30];
128
129 if (!SetupFindFirstLineW(hSetupInf,
130 L"Unattend",
131 L"LocaleID",
132 &InfContext))
133 {
134 SetupCloseInfFile(hSetupInf);
135 DPRINT1("SetupFindFirstLine failed\n");
136 return;
137 }
138
139 if (!SetupGetStringFieldW(&InfContext, 1, szBuffer,
140 sizeof(szBuffer) / sizeof(WCHAR), NULL))
141 {
142 SetupCloseInfFile(hSetupInf);
143 DPRINT1("SetupGetStringField failed\n");
144 return;
145 }
146
147 UnattendLCID = wcstoul(szBuffer, NULL, 16);
148 IsUnattendedSetupEnabled = 1;
149 SetupCloseInfFile(hSetupInf);
150 }
151
152 static LONG APIENTRY
153 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
154 {
155 TCHAR Caption[BUFFERSIZE];
156 PROPSHEETPAGE psp[3];
157 PROPSHEETHEADER psh;
158 PGLOBALDATA pGlobalData;
159 LONG ret;
160
161 if (OpenSetupInf())
162 {
163 ParseSetupInf();
164 }
165
166 pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBALDATA));
167 if (pGlobalData == NULL)
168 return FALSE;
169
170 pGlobalData->SystemLCID = GetSystemDefaultLCID();
171 pGlobalData->bIsUserAdmin = IsUserAdmin();
172
173 LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
174
175 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
176 psh.dwSize = sizeof(PROPSHEETHEADER);
177 psh.dwFlags = PSH_PROPSHEETPAGE;
178 psh.hwndParent = hCPLWindow;
179 psh.hInstance = hApplet;
180 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
181 psh.pszCaption = Caption;
182 psh.nPages = 0; //sizeof(psp) / sizeof(PROPSHEETPAGE);
183 psh.nStartPage = 0;
184 psh.ppsp = psp;
185
186 InitPropSheetPage(&psp[0], IDD_GENERALPAGE, GeneralPageProc, (LPARAM)pGlobalData);
187 psh.nPages++;
188 InitPropSheetPage(&psp[1], IDD_LANGUAGESPAGE, LanguagesPageProc, (LPARAM)pGlobalData);
189 psh.nPages++;
190
191 if (pGlobalData->bIsUserAdmin)
192 {
193 InitPropSheetPage(&psp[2], IDD_ADVANCEDPAGE, AdvancedPageProc, (LPARAM)pGlobalData);
194 psh.nPages++;
195 }
196
197 ret = (LONG)(PropertySheet(&psh) != -1);
198
199 HeapFree(GetProcessHeap(), 0, pGlobalData);
200
201 return ret;
202 }
203
204
205 /* Control Panel Callback */
206 LONG APIENTRY
207 CPlApplet(HWND hwndCpl,
208 UINT uMsg,
209 LPARAM lParam1,
210 LPARAM lParam2)
211 {
212 switch(uMsg)
213 {
214 case CPL_INIT:
215 return TRUE;
216
217 case CPL_GETCOUNT:
218 return NUM_APPLETS;
219
220 case CPL_INQUIRE:
221 {
222 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
223 UINT uAppIndex = (UINT)lParam1;
224
225 CPlInfo->lData = 0;
226 CPlInfo->idIcon = Applets[uAppIndex].idIcon;
227 CPlInfo->idName = Applets[uAppIndex].idName;
228 CPlInfo->idInfo = Applets[uAppIndex].idDescription;
229 break;
230 }
231
232 case CPL_DBLCLK:
233 {
234 UINT uAppIndex = (UINT)lParam1;
235 hCPLWindow = hwndCpl;
236 Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
237 break;
238 }
239 }
240
241 return FALSE;
242 }
243
244
245 BOOL WINAPI
246 DllMain(HINSTANCE hinstDLL,
247 DWORD dwReason,
248 LPVOID lpReserved)
249 {
250 switch(dwReason)
251 {
252 case DLL_PROCESS_ATTACH:
253 case DLL_THREAD_ATTACH:
254 hApplet = hinstDLL;
255 break;
256 }
257
258 return TRUE;
259 }