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