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