- Update to r53061
[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: lib/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
71 if(!lpSwitch)
72 {
73 return FALSE;
74 }
75
76 len = _tcslen(lpSwitch);
77 if (len < 5)
78 {
79 return FALSE;
80 }
81
82 if(lpSwitch[len-1] != _T('\"'))
83 {
84 return FALSE;
85 }
86
87 lpSwitch[len-1] = _T('\0');
88
89 hSetupInf = SetupOpenInfFile(&lpSwitch[4], NULL,
90 INF_STYLE_OLDNT, NULL);
91
92 return (hSetupInf != INVALID_HANDLE_VALUE);
93 }
94
95 VOID
96 ParseSetupInf(VOID)
97 {
98 INFCONTEXT InfContext;
99 TCHAR szBuffer[30];
100
101 if (!SetupFindFirstLine(hSetupInf,
102 _T("Unattend"),
103 _T("LocaleID"),
104 &InfContext))
105 {
106 SetupCloseInfFile(hSetupInf);
107 return;
108 }
109
110 if (!SetupGetStringField(&InfContext, 1, szBuffer,
111 sizeof(szBuffer) / sizeof(TCHAR), NULL))
112 {
113 SetupCloseInfFile(hSetupInf);
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 }
210