ReactOS 0.4.16-dev-329-g9223134
intl.c
Go to the documentation of this file.
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#define BUFFERSIZE 512
33
34static LONG APIENTRY
36
37
42
43
44/* Applets */
46{
48};
49
50VOID
52{
53 WCHAR szErrorText[BUFFERSIZE];
54 WCHAR szErrorCaption[BUFFERSIZE];
55
56 LoadStringW(hApplet, msg, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
57 LoadStringW(hApplet, IDS_ERROR, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
58
59 MessageBoxW(NULL, szErrorText, szErrorCaption, MB_OK | MB_ICONERROR);
60}
61
62INT
64 HWND hwnd,
65 UINT uType,
66 UINT uCaptionId,
67 UINT uMessageId)
68{
69 WCHAR szErrorText[BUFFERSIZE];
70 WCHAR szErrorCaption[BUFFERSIZE];
71
72 LoadStringW(hApplet, uMessageId, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
73 LoadStringW(hApplet, uCaptionId, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
74
75 return MessageBoxW(hwnd, szErrorText, szErrorCaption, uType);
76}
77
78static VOID
80{
81 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
82 psp->dwSize = sizeof(PROPSHEETPAGE);
83 psp->dwFlags = PSP_DEFAULT;
84 psp->hInstance = hApplet;
85 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
86 psp->pfnDlgProc = DlgProc;
87 psp->lParam = lParam;
88}
89
90BOOL
92{
93 PWSTR lpCmdLine;
94 PWSTR lpSwitch;
95 size_t len;
96
97 lpCmdLine = GetCommandLineW();
98
99 lpSwitch = wcsstr(lpCmdLine, L"/f:\"");
100 if (!lpSwitch)
101 return FALSE;
102
103 len = wcslen(lpSwitch);
104 if (len < 5 || lpSwitch[len-1] != L'\"')
105 {
106 DPRINT1("Invalid switch: %ls\n", lpSwitch);
107 return FALSE;
108 }
109
110 lpSwitch[len-1] = L'\0';
111
114 {
115 DPRINT1("Failed to open INF file: %ls\n", &lpSwitch[4]);
116 return FALSE;
117 }
118
119 return TRUE;
120}
121
122VOID
124{
125 INFCONTEXT InfContext;
126 WCHAR szBuffer[30];
127
129 L"Unattend",
130 L"LocaleID",
131 &InfContext))
132 {
134 DPRINT1("SetupFindFirstLine failed\n");
135 return;
136 }
137
138 if (!SetupGetStringFieldW(&InfContext, 1, szBuffer,
139 sizeof(szBuffer) / sizeof(WCHAR), NULL))
140 {
142 DPRINT1("SetupGetStringField failed\n");
143 return;
144 }
145
146 UnattendLCID = wcstoul(szBuffer, NULL, 16);
149}
150
151static int CALLBACK
153{
154 // NOTE: This callback is needed to set large icon correctly.
155 HICON hIcon;
156 switch (uMsg)
157 {
158 case PSCB_INITIALIZED:
159 {
161 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
162 break;
163 }
164 }
165 return 0;
166}
167
168static LONG APIENTRY
170{
171 PROPSHEETPAGE psp[3];
172 PROPSHEETHEADER psh;
173 PGLOBALDATA pGlobalData;
174 INT nPage = 0;
175 LONG ret;
176
177 if (OpenSetupInf())
178 {
180 }
181
182 if (uMsg == CPL_STARTWPARMSW && lParam != 0)
183 nPage = _wtoi((PWSTR)lParam);
184
185 pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBALDATA));
186 if (pGlobalData == NULL)
187 return FALSE;
188
189 pGlobalData->SystemLCID = GetSystemDefaultLCID();
190 pGlobalData->bIsUserAdmin = IsUserAdmin();
191
192 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
193 psh.dwSize = sizeof(PROPSHEETHEADER);
195 psh.hwndParent = hwnd;
196 psh.hInstance = hApplet;
197 psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON);
198 psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLNAME);
199 psh.nPages = 0;
200 psh.nStartPage = 0;
201 psh.ppsp = psp;
202 psh.pfnCallback = PropSheetProc;
203
205 psh.nPages++;
207 psh.nPages++;
208
209 if (pGlobalData->bIsUserAdmin)
210 {
212 psh.nPages++;
213 }
214
215 if (nPage != 0 && nPage <= psh.nPages)
216 psh.nStartPage = nPage;
217
218 ret = (LONG)(PropertySheet(&psh) != -1);
219 if (ret > 0)
221
222 HeapFree(GetProcessHeap(), 0, pGlobalData);
223
224 return ret;
225}
226
227
228/* Control Panel Callback */
231 UINT uMsg,
232 LPARAM lParam1,
233 LPARAM lParam2)
234{
235 UINT i = (UINT)lParam1;
236
237 switch (uMsg)
238 {
239 case CPL_INIT:
240 return TRUE;
241
242 case CPL_GETCOUNT:
243 return NUM_APPLETS;
244
245 case CPL_INQUIRE:
246 if (i < NUM_APPLETS)
247 {
248 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
249 CPlInfo->lData = 0;
250 CPlInfo->idIcon = Applets[i].idIcon;
251 CPlInfo->idName = Applets[i].idName;
252 CPlInfo->idInfo = Applets[i].idDescription;
253 }
254 else
255 {
256 return TRUE;
257 }
258 break;
259
260 case CPL_DBLCLK:
261 if (i < NUM_APPLETS)
262 Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
263 else
264 return TRUE;
265 break;
266
267 case CPL_STARTWPARMSW:
268 if (i < NUM_APPLETS)
269 return Applets[i].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
270 break;
271 }
272
273 return FALSE;
274}
275
276
280 LPVOID lpReserved)
281{
282 switch(dwReason)
283 {
286 hApplet = hinstDLL;
287 break;
288 }
289
290 return TRUE;
291}
#define msg(x)
Definition: auth_time.c:54
#define IDS_ERROR
Definition: resource.h:18
INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:141
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define CPL_INQUIRE
Definition: cpl.h:14
#define CPL_DBLCLK
Definition: cpl.h:16
#define CPL_STARTWPARMSW
Definition: cpl.h:21
#define CPL_INIT
Definition: cpl.h:12
#define CPL_GETCOUNT
Definition: cpl.h:13
#define DLGPROC
Definition: maze.c:62
WORD idDlg
Definition: desk.c:121
DLGPROC DlgProc
Definition: desk.c:122
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define IDC_CPLICON
Definition: resource.h:7
#define IDS_CPLNAME
Definition: resource.h:8
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
INT_PTR CALLBACK AdvancedPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advanced.c:422
#define IDD_GENERALPAGE
Definition: resource.h:9
#define IDD_LANGUAGESPAGE
Definition: resource.h:12
#define IDD_ADVANCEDPAGE
Definition: resource.h:13
#define APIENTRY
Definition: api.h:79
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define DLL_THREAD_ATTACH
Definition: compat.h:132
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2019
LCID WINAPI GetSystemDefaultLCID(void)
Definition: locale.c:1230
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define INF_STYLE_OLDNT
Definition: infsupp.h:39
HINF hSetupInf
Definition: intl.c:39
#define NUM_APPLETS
Definition: intl.c:30
DWORD UnattendLCID
Definition: intl.c:41
DWORD IsUnattendedSetupEnabled
Definition: intl.c:40
INT ResourceMessageBox(HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: intl.c:63
VOID ParseSetupInf(VOID)
Definition: intl.c:123
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: intl.c:152
static LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: intl.c:169
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
Definition: intl.c:278
static VOID InitIntlPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
Definition: intl.c:79
APPLET Applets[NUM_APPLETS]
Definition: intl.c:45
BOOL OpenSetupInf(VOID)
Definition: intl.c:91
#define BUFFERSIZE
Definition: intl.c:32
VOID PrintErrorMsgBox(UINT msg)
Definition: intl.c:51
HINSTANCE hApplet
Definition: intl.c:38
INT_PTR CALLBACK LanguagesPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: languages.c:48
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
static BOOL IsUserAdmin(VOID)
Definition: netid.c:163
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define PROPSHEETHEADER
Definition: prsht.h:392
#define PSH_USECALLBACK
Definition: prsht.h:48
#define PSP_DEFAULT
Definition: prsht.h:22
#define PropertySheet
Definition: prsht.h:400
#define PSH_PROPSHEETPAGE
Definition: prsht.h:43
#define PSH_USEICONID
Definition: prsht.h:42
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define PROPSHEETPAGE
Definition: prsht.h:389
Definition: hotplug.h:34
int idDescription
Definition: hotplug.h:37
int idName
Definition: hotplug.h:36
int idIcon
Definition: hotplug.h:35
APPLET_PROC AppletProc
Definition: hotplug.h:38
BOOL bIsUserAdmin
Definition: intl.h:122
LCID SystemLCID
Definition: intl.h:114
Definition: cpl.h:24
LONG_PTR lData
Definition: cpl.h:28
int idName
Definition: cpl.h:26
int idInfo
Definition: cpl.h:27
int idIcon
Definition: cpl.h:25
#define ICON_BIG
Definition: tnclass.cpp:51
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:186
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:56
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:45
int ret
#define ZeroMemory
Definition: winbase.h:1737
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define WINAPI
Definition: msvc.h:6
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define HWND_BROADCAST
Definition: winuser.h:1207
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
#define MB_ICONERROR
Definition: winuser.h:790
#define WM_SETTINGCHANGE
Definition: winuser.h:1632
#define MB_OK
Definition: winuser.h:793
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define MAKEINTRESOURCE
Definition: winuser.h:591
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2127
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__wchar_t WCHAR
Definition: xmlstorage.h:180