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