Sync with trunk r63502.
[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 TCHAR szErrorText[BUFFERSIZE];
55 TCHAR szErrorCaption[BUFFERSIZE];
56
57 LoadString(hApplet, msg, szErrorText, sizeof(szErrorText)/sizeof(TCHAR));
58 LoadString(hApplet, IDS_ERROR, szErrorCaption, sizeof(szErrorCaption)/sizeof(TCHAR));
59
60 MessageBox(NULL, szErrorText, szErrorCaption, MB_OK | MB_ICONERROR);
61 }
62
63 static VOID
64 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
65 {
66 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
67 psp->dwSize = sizeof(PROPSHEETPAGE);
68 psp->dwFlags = PSP_DEFAULT;
69 psp->hInstance = hApplet;
70 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
71 psp->pfnDlgProc = DlgProc;
72 }
73
74 BOOL
75 OpenSetupInf(VOID)
76 {
77 LPTSTR lpCmdLine;
78 LPTSTR lpSwitch;
79 size_t len;
80
81 lpCmdLine = GetCommandLine();
82
83 lpSwitch = _tcsstr(lpCmdLine, _T("/f:\""));
84 if (!lpSwitch)
85 return FALSE;
86
87 len = _tcslen(lpSwitch);
88 if (len < 5 || lpSwitch[len-1] != _T('\"'))
89 {
90 DPRINT1("Invalid switch: %ls\n", lpSwitch);
91 return FALSE;
92 }
93
94 lpSwitch[len-1] = _T('\0');
95
96 hSetupInf = SetupOpenInfFile(&lpSwitch[4], NULL, INF_STYLE_OLDNT, NULL);
97 if (hSetupInf == INVALID_HANDLE_VALUE)
98 {
99 DPRINT1("Failed to open INF file: %ls\n", &lpSwitch[4]);
100 return FALSE;
101 }
102
103 return TRUE;
104 }
105
106 VOID
107 ParseSetupInf(VOID)
108 {
109 INFCONTEXT InfContext;
110 TCHAR szBuffer[30];
111
112 if (!SetupFindFirstLine(hSetupInf,
113 _T("Unattend"),
114 _T("LocaleID"),
115 &InfContext))
116 {
117 SetupCloseInfFile(hSetupInf);
118 DPRINT1("SetupFindFirstLine failed\n");
119 return;
120 }
121
122 if (!SetupGetStringField(&InfContext, 1, szBuffer,
123 sizeof(szBuffer) / sizeof(TCHAR), NULL))
124 {
125 SetupCloseInfFile(hSetupInf);
126 DPRINT1("SetupGetStringField failed\n");
127 return;
128 }
129
130 UnattendLCID = _tcstoul(szBuffer, NULL, 16);
131 IsUnattendedSetupEnabled = 1;
132 SetupCloseInfFile(hSetupInf);
133 }
134
135 static LONG APIENTRY
136 Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
137 {
138 PROPSHEETPAGE psp[3];
139 PROPSHEETHEADER psh;
140 TCHAR Caption[BUFFERSIZE];
141
142 if (OpenSetupInf())
143 {
144 ParseSetupInf();
145 }
146
147 LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
148
149 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
150 psh.dwSize = sizeof(PROPSHEETHEADER);
151 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
152 psh.hwndParent = hCPLWindow;
153 psh.hInstance = hApplet;
154 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
155 psh.pszCaption = Caption;
156 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
157 psh.nStartPage = 0;
158 psh.ppsp = psp;
159
160 InitPropSheetPage(&psp[0], IDD_GENERALPAGE, GeneralPageProc);
161 InitPropSheetPage(&psp[1], IDD_LANGUAGESPAGE, LanguagesPageProc);
162 InitPropSheetPage(&psp[2], IDD_ADVANCEDPAGE, AdvancedPageProc);
163
164 return (LONG)(PropertySheet(&psh) != -1);
165 }
166
167
168 /* Control Panel Callback */
169 LONG APIENTRY
170 CPlApplet(HWND hwndCpl,
171 UINT uMsg,
172 LPARAM lParam1,
173 LPARAM lParam2)
174 {
175 switch(uMsg)
176 {
177 case CPL_INIT:
178 return TRUE;
179
180 case CPL_GETCOUNT:
181 return NUM_APPLETS;
182
183 case CPL_INQUIRE:
184 {
185 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
186 UINT uAppIndex = (UINT)lParam1;
187
188 CPlInfo->lData = 0;
189 CPlInfo->idIcon = Applets[uAppIndex].idIcon;
190 CPlInfo->idName = Applets[uAppIndex].idName;
191 CPlInfo->idInfo = Applets[uAppIndex].idDescription;
192 break;
193 }
194
195 case CPL_DBLCLK:
196 {
197 UINT uAppIndex = (UINT)lParam1;
198 hCPLWindow = hwndCpl;
199 Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
200 break;
201 }
202 }
203
204 return FALSE;
205 }
206
207
208 BOOL WINAPI
209 DllMain(HINSTANCE hinstDLL,
210 DWORD dwReason,
211 LPVOID lpReserved)
212 {
213 switch(dwReason)
214 {
215 case DLL_PROCESS_ATTACH:
216 case DLL_THREAD_ATTACH:
217 hApplet = hinstDLL;
218 break;
219 }
220
221 return TRUE;
222 }