ReactOS  0.4.13-dev-257-gfabbd7c
layout_list.c
Go to the documentation of this file.
1 /*
2  * PROJECT: input.dll
3  * FILE: dll/cpl/input/layout_list.c
4  * PURPOSE: input.dll
5  * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6  */
7 
8 #include "layout_list.h"
9 
10 
12 
13 
14 static LAYOUT_LIST_NODE*
15 LayoutList_AppendNode(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName)
16 {
17  LAYOUT_LIST_NODE *pCurrent;
18  LAYOUT_LIST_NODE *pNew;
19 
20  if (pszName == NULL)
21  return NULL;
22 
23  pCurrent = _LayoutList;
24 
25  pNew = (LAYOUT_LIST_NODE*)malloc(sizeof(LAYOUT_LIST_NODE));
26  if (pNew == NULL)
27  return NULL;
28 
29  ZeroMemory(pNew, sizeof(LAYOUT_LIST_NODE));
30 
31  pNew->pszName = _wcsdup(pszName);
32  if (pNew->pszName == NULL)
33  {
34  free(pNew);
35  return NULL;
36  }
37 
38  pNew->dwId = dwId;
39  pNew->dwSpecialId = dwSpecialId;
40 
41  if (pCurrent == NULL)
42  {
43  _LayoutList = pNew;
44  }
45  else
46  {
47  while (pCurrent->pNext != NULL)
48  {
49  pCurrent = pCurrent->pNext;
50  }
51 
52  pNew->pPrev = pCurrent;
53  pCurrent->pNext = pNew;
54  }
55 
56  return pNew;
57 }
58 
59 
60 VOID
62 {
63  LAYOUT_LIST_NODE *pCurrent;
64 
65  if (_LayoutList == NULL)
66  return;
67 
68  pCurrent = _LayoutList;
69 
70  while (pCurrent != NULL)
71  {
72  LAYOUT_LIST_NODE *pNext = pCurrent->pNext;
73 
74  free(pCurrent->pszName);
75  free(pCurrent);
76 
77  pCurrent = pNext;
78  }
79 
80  _LayoutList = NULL;
81 }
82 
83 
84 VOID
86 {
87  WCHAR szSystemDirectory[MAX_PATH];
88  WCHAR szLayoutId[MAX_PATH];
89  DWORD dwIndex = 0;
90  DWORD dwSize;
91  HKEY hKey;
92 
93  if (!GetSystemDirectoryW(szSystemDirectory, ARRAYSIZE(szSystemDirectory)))
94  {
95  return;
96  }
97 
99  L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts",
100  0,
102  &hKey) != ERROR_SUCCESS)
103  {
104  return;
105  }
106 
107  dwSize = ARRAYSIZE(szLayoutId);
108 
109  while (RegEnumKeyExW(hKey, dwIndex, szLayoutId, &dwSize,
111  {
112  HKEY hLayoutKey;
113 
114  if (RegOpenKeyExW(hKey,
115  szLayoutId,
116  0,
118  &hLayoutKey) == ERROR_SUCCESS)
119  {
120  WCHAR szBuffer[MAX_PATH];
121 
122  dwSize = sizeof(szBuffer);
123 
124  if (RegQueryValueExW(hLayoutKey,
125  L"Layout File",
126  NULL, NULL,
127  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
128  {
130 
132  L"%s\\%s", szSystemDirectory, szBuffer);
133 
135  {
136  DWORD dwSpecialId = 0;
137 
138  dwSize = sizeof(szBuffer);
139 
140  if (RegQueryValueExW(hLayoutKey,
141  L"Layout Id",
142  NULL, NULL,
143  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
144  {
145  dwSpecialId = DWORDfromString(szBuffer);
146  }
147 
148  dwSize = sizeof(szBuffer);
149 
150  if (RegQueryValueExW(hLayoutKey,
151  L"Layout Display Name",
152  NULL, NULL,
153  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS &&
154  szBuffer[0] == L'@')
155  {
156  WCHAR *pBuffer;
157  WCHAR *pIndex;
158 
159  /* Move to the position after the character "@" */
160  pBuffer = szBuffer + 1;
161 
162  /* Get a pointer to the beginning ",-" */
163  pIndex = wcsstr(pBuffer, L",-");
164 
165  if (pIndex != NULL)
166  {
168  INT iIndex;
169 
170  /* Convert the number in the string after the ",-" */
171  iIndex = _wtoi(pIndex + 2);
172 
173  pIndex[0] = 0;
174 
176  {
177  HANDLE hHandle;
178 
179  hHandle = LoadLibraryW(szPath);
180  if (hHandle != NULL)
181  {
182  INT iLength = LoadStringW(hHandle, iIndex, szBuffer, ARRAYSIZE(szBuffer));
183 
184  FreeLibrary(hHandle);
185 
186  if (iLength != 0)
187  {
188  DWORD dwLayoutId = DWORDfromString(szLayoutId);
189 
190  LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer);
191  }
192  else
193  {
194  goto NotTranslated;
195  }
196  }
197  else
198  {
199  goto NotTranslated;
200  }
201  }
202  else
203  {
204  goto NotTranslated;
205  }
206  }
207  else
208  {
209  goto NotTranslated;
210  }
211  }
212  else
213  {
214 NotTranslated:
215  dwSize = sizeof(szBuffer);
216 
217  if (RegQueryValueExW(hLayoutKey,
218  L"Layout Text",
219  NULL, NULL,
220  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
221  {
222  DWORD dwLayoutId = DWORDfromString(szLayoutId);
223 
224  LayoutList_AppendNode(dwLayoutId, dwSpecialId, szBuffer);
225  }
226  }
227  }
228  }
229 
230  RegCloseKey(hLayoutKey);
231  }
232 
233  dwSize = ARRAYSIZE(szLayoutId);
234  ++dwIndex;
235  }
236 
237  RegCloseKey(hKey);
238 }
239 
240 
243 {
244  LAYOUT_LIST_NODE *pCurrent;
245 
246  if ((HIWORD(hkl) & 0xF000) == 0xF000)
247  {
248  DWORD dwSpecialId = (HIWORD(hkl) & 0x0FFF);
249 
250  for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
251  {
252  if (dwSpecialId == pCurrent->dwSpecialId)
253  {
254  return pCurrent;
255  }
256  }
257  }
258  else
259  {
260  for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
261  {
262  if (HIWORD(hkl) == LOWORD(pCurrent->dwId))
263  {
264  return pCurrent;
265  }
266  }
267  }
268 
269  return NULL;
270 }
271 
272 
275 {
276  return _LayoutList;
277 }
static WCHAR szFilePath[]
Definition: qotd.c:14
#define ERROR_SUCCESS
Definition: deptool.c:10
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define free
Definition: debug_ros.c:5
VOID LayoutList_Create(VOID)
Definition: layout_list.c:85
LAYOUT_LIST_NODE * LayoutList_GetFirst(VOID)
Definition: layout_list.c:274
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
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
static LAYOUT_LIST_NODE * LayoutList_AppendNode(DWORD dwId, DWORD dwSpecialId, const WCHAR *pszName)
Definition: layout_list.c:15
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11
LAYOUT_LIST_NODE * LayoutList_GetByHkl(HKL hkl)
Definition: layout_list.c:242
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:13
#define FreeLibrary(x)
Definition: compat.h:405
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID LayoutList_Destroy(VOID)
Definition: layout_list.c:61
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR L[]
Definition: oid.c:1250
UINT_PTR HKL
Definition: msctf.idl:101
HKL hkl
Definition: msctf.idl:611
_Out_ PULONG _Out_ PULONG pIndex
Definition: ndis.h:4564
LPCWSTR szPath
Definition: env.c:35
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static DWORD DWORDfromString(const WCHAR *pszString)
Definition: input.h:78
struct _LAYOUT_LIST_NODE * pPrev
Definition: layout_list.h:12
struct _INPUT_LIST_NODE * pNext
Definition: input_list.h:26
#define HIWORD(l)
Definition: typedefs.h:246
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define malloc
Definition: debug_ros.c:4
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2541
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
#define LOWORD(l)
Definition: pedump.c:82
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019