ReactOS  0.4.14-dev-297-g23e575c
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 
34 static LONG APIENTRY
36 
37 
43 
44 
45 /* Applets */
47 {
49 };
50 
51 VOID
53 {
54  WCHAR szErrorText[BUFFERSIZE];
55  WCHAR szErrorCaption[BUFFERSIZE];
56 
57  LoadStringW(hApplet, msg, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
58  LoadStringW(hApplet, IDS_ERROR, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
59 
60  MessageBoxW(NULL, szErrorText, szErrorCaption, MB_OK | MB_ICONERROR);
61 }
62 
63 INT
65  HWND hwnd,
66  UINT uType,
67  UINT uCaptionId,
68  UINT uMessageId)
69 {
70  WCHAR szErrorText[BUFFERSIZE];
71  WCHAR szErrorCaption[BUFFERSIZE];
72 
73  LoadStringW(hApplet, uMessageId, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
74  LoadStringW(hApplet, uCaptionId, szErrorCaption, sizeof(szErrorCaption) / sizeof(WCHAR));
75 
76  return MessageBoxW(hwnd, szErrorText, szErrorCaption, uType);
77 }
78 
79 static VOID
81 {
82  ZeroMemory(psp, sizeof(PROPSHEETPAGE));
83  psp->dwSize = sizeof(PROPSHEETPAGE);
84  psp->dwFlags = PSP_DEFAULT;
85  psp->hInstance = hApplet;
86  psp->pszTemplate = MAKEINTRESOURCE(idDlg);
87  psp->pfnDlgProc = DlgProc;
88  psp->lParam = lParam;
89 }
90 
91 BOOL
93 {
94  PWSTR lpCmdLine;
95  PWSTR lpSwitch;
96  size_t len;
97 
98  lpCmdLine = GetCommandLineW();
99 
100  lpSwitch = wcsstr(lpCmdLine, L"/f:\"");
101  if (!lpSwitch)
102  return FALSE;
103 
104  len = wcslen(lpSwitch);
105  if (len < 5 || lpSwitch[len-1] != L'\"')
106  {
107  DPRINT1("Invalid switch: %ls\n", lpSwitch);
108  return FALSE;
109  }
110 
111  lpSwitch[len-1] = L'\0';
112 
115  {
116  DPRINT1("Failed to open INF file: %ls\n", &lpSwitch[4]);
117  return FALSE;
118  }
119 
120  return TRUE;
121 }
122 
123 VOID
125 {
126  INFCONTEXT InfContext;
127  WCHAR szBuffer[30];
128 
130  L"Unattend",
131  L"LocaleID",
132  &InfContext))
133  {
135  DPRINT1("SetupFindFirstLine failed\n");
136  return;
137  }
138 
139  if (!SetupGetStringFieldW(&InfContext, 1, szBuffer,
140  sizeof(szBuffer) / sizeof(WCHAR), NULL))
141  {
143  DPRINT1("SetupGetStringField failed\n");
144  return;
145  }
146 
147  UnattendLCID = wcstoul(szBuffer, NULL, 16);
150 }
151 
152 static int CALLBACK
154 {
155  // NOTE: This callback is needed to set large icon correctly.
156  HICON hIcon;
157  switch (uMsg)
158  {
159  case PSCB_INITIALIZED:
160  {
162  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
163  break;
164  }
165  }
166  return 0;
167 }
168 
169 static LONG APIENTRY
171 {
172  TCHAR Caption[BUFFERSIZE];
173  PROPSHEETPAGE psp[3];
174  PROPSHEETHEADER psh;
175  PGLOBALDATA pGlobalData;
176  LONG ret;
177 
178  if (OpenSetupInf())
179  {
180  ParseSetupInf();
181  }
182 
183  pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBALDATA));
184  if (pGlobalData == NULL)
185  return FALSE;
186 
187  pGlobalData->SystemLCID = GetSystemDefaultLCID();
188  pGlobalData->bIsUserAdmin = IsUserAdmin();
189 
190  LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
191 
192  ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
193  psh.dwSize = sizeof(PROPSHEETHEADER);
195  psh.hwndParent = hCPLWindow;
196  psh.hInstance = hApplet;
197  psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON);
198  psh.pszCaption = Caption;
199  psh.nPages = 0; //sizeof(psp) / sizeof(PROPSHEETPAGE);
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  ret = (LONG)(PropertySheet(&psh) != -1);
216 
217  HeapFree(GetProcessHeap(), 0, pGlobalData);
218 
219  return ret;
220 }
221 
222 
223 /* Control Panel Callback */
225 CPlApplet(HWND hwndCpl,
226  UINT uMsg,
227  LPARAM lParam1,
228  LPARAM lParam2)
229 {
230  switch(uMsg)
231  {
232  case CPL_INIT:
233  return TRUE;
234 
235  case CPL_GETCOUNT:
236  return NUM_APPLETS;
237 
238  case CPL_INQUIRE:
239  {
240  CPLINFO *CPlInfo = (CPLINFO*)lParam2;
241  UINT uAppIndex = (UINT)lParam1;
242 
243  CPlInfo->lData = 0;
244  CPlInfo->idIcon = Applets[uAppIndex].idIcon;
245  CPlInfo->idName = Applets[uAppIndex].idName;
246  CPlInfo->idInfo = Applets[uAppIndex].idDescription;
247  break;
248  }
249 
250  case CPL_DBLCLK:
251  {
252  UINT uAppIndex = (UINT)lParam1;
253  hCPLWindow = hwndCpl;
254  Applets[uAppIndex].AppletProc(hwndCpl, uMsg, lParam1, lParam2);
255  break;
256  }
257  }
258 
259  return FALSE;
260 }
261 
262 
263 BOOL WINAPI
265  DWORD dwReason,
266  LPVOID lpReserved)
267 {
268  switch(dwReason)
269  {
270  case DLL_PROCESS_ATTACH:
271  case DLL_THREAD_ATTACH:
272  hApplet = hinstDLL;
273  break;
274  }
275 
276  return TRUE;
277 }
DWORD IsUnattendedSetupEnabled
Definition: intl.c:41
BOOL WINAPI SetupFindFirstLineW(IN HINF InfHandle, IN PCWSTR Section, IN PCWSTR Key, IN OUT PINFCONTEXT Context)
Definition: infsupp.c:54
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
WORD idDlg
Definition: desk.c:109
#define MAKEINTRESOURCE
Definition: winuser.h:591
HINF hSetupInf
Definition: intl.c:40
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
Definition: cpl.h:24
BOOL OpenSetupInf(VOID)
Definition: intl.c:92
BOOL bIsUserAdmin
Definition: intl.h:122
BOOL WINAPI IsUserAdmin(VOID)
#define DLL_THREAD_ATTACH
Definition: compat.h:121
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
uint16_t * PWSTR
Definition: typedefs.h:54
int idName
Definition: hotplug.h:27
HINSTANCE hApplet
Definition: intl.c:38
DWORD UnattendLCID
Definition: intl.c:42
#define INF_STYLE_OLDNT
Definition: infsupp.h:37
int idIcon
Definition: hotplug.h:26
#define CALLBACK
Definition: compat.h:27
#define IDD_ADVANCEDPAGE
Definition: resource.h:13
int idInfo
Definition: cpl.h:27
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#define ZeroMemory
Definition: winbase.h:1642
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define PSH_USECALLBACK
Definition: prsht.h:48
#define IDC_CPLICON
Definition: resource.h:7
HINF WINAPI SetupOpenInfFileW(PCWSTR name, PCWSTR class, DWORD style, UINT *error)
Definition: parser.c:1229
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
WPARAM wParam
Definition: combotst.c:138
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
int idIcon
Definition: cpl.h:25
int idDescription
Definition: hotplug.h:28
#define CPL_DBLCLK
Definition: cpl.h:16
DWORD dwReason
Definition: misc.cpp:154
#define IDS_CPLNAME
Definition: resource.h:8
#define NUM_APPLETS
Definition: intl.c:30
#define PSH_USEICONID
Definition: prsht.h:42
INT_PTR CALLBACK GeneralPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
LPWSTR WINAPI GetCommandLineW(VOID)
Definition: proc.c:2013
smooth NULL
Definition: ftsmooth.c:416
#define PROPSHEETHEADER
Definition: prsht.h:374
LONG_PTR LPARAM
Definition: windef.h:208
LCID WINAPI GetSystemDefaultLCID(void)
Definition: lang.c:787
#define IDS_CPLDESCRIPTION
Definition: resource.h:9
char TCHAR
Definition: xmlstorage.h:189
#define PSP_DEFAULT
Definition: prsht.h:22
INT_PTR CALLBACK LanguagesPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: languages.c:7
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LCID SystemLCID
Definition: intl.h:114
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
APPLET_PROC AppletProc
Definition: hotplug.h:29
#define WINAPI
Definition: msvc.h:8
VOID ParseSetupInf(VOID)
Definition: intl.c:124
APPLET Applets[NUM_APPLETS]
Definition: intl.c:46
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define CPL_INIT
Definition: cpl.h:12
LONG APIENTRY CPlApplet(HWND hwndCpl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
Definition: intl.c:225
int ret
static LONG APIENTRY Applet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: intl.c:170
#define CPL_INQUIRE
Definition: cpl.h:14
static const WCHAR L[]
Definition: oid.c:1250
#define MB_ICONERROR
Definition: winuser.h:781
GLenum GLsizei len
Definition: glext.h:6722
LONG_PTR lData
Definition: cpl.h:28
#define IDD_LANGUAGESPAGE
Definition: resource.h:12
int idName
Definition: cpl.h:26
static VOID InitIntlPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
Definition: intl.c:80
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2870
#define IDD_GENERALPAGE
Definition: resource.h:9
#define PSCB_INITIALIZED
Definition: prsht.h:75
HICON hIcon
Definition: msconfig.c:44
#define PSH_PROPSHEETPAGE
Definition: prsht.h:43
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
Definition: intl.c:264
HWND hCPLWindow
Definition: intl.c:39
unsigned int UINT
Definition: ndis.h:50
#define MB_OK
Definition: winuser.h:784
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
INT ResourceMessageBox(HWND hwnd, UINT uType, UINT uCaptionId, UINT uMessageId)
Definition: intl.c:64
#define DPRINT1
Definition: precomp.h:8
#define msg(x)
Definition: auth_time.c:54
#define IDS_ERROR
Definition: resource.h:18
#define PropertySheet
Definition: prsht.h:382
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: intl.c:153
#define BUFFERSIZE
Definition: intl.c:32
VOID PrintErrorMsgBox(UINT msg)
Definition: intl.c:52
LPARAM lParam
Definition: combotst.c:139
DLGPROC DlgProc
Definition: desk.c:110
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
INT_PTR CALLBACK AdvancedPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: advanced.c:423
#define CPL_GETCOUNT
Definition: cpl.h:13
#define LoadString
Definition: winuser.h:5720
#define PROPSHEETPAGE
Definition: prsht.h:371
#define APIENTRY
Definition: api.h:79
#define ICON_BIG
Definition: tnclass.cpp:51
Definition: hotplug.h:24
BOOL WINAPI SetupGetStringFieldW(IN PINFCONTEXT Context, IN ULONG FieldIndex, OUT PWSTR ReturnBuffer, IN ULONG ReturnBufferSize, OUT PULONG RequiredSize)
Definition: infsupp.c:184