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