ReactOS 0.4.16-dev-319-g6cf4263
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 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7 */
8
9#include "layout_list.h"
10
12
13static LAYOUT_LIST_NODE*
14LayoutList_AppendNode(DWORD dwKLID, WORD wSpecialId, LPCWSTR pszFile, LPCWSTR pszName,
15 LPCWSTR pszImeFile)
16{
17 LAYOUT_LIST_NODE *pCurrent;
18 LAYOUT_LIST_NODE *pNew;
19
20 if (pszName == NULL)
21 return NULL;
22
23 pCurrent = _LayoutList;
24
26 if (pNew == NULL)
27 return NULL;
28
29 ZeroMemory(pNew, sizeof(LAYOUT_LIST_NODE));
30
31 pNew->dwKLID = dwKLID;
32 pNew->wSpecialId = wSpecialId;
33
34 pNew->pszName = _wcsdup(pszName);
35 pNew->pszFile = _wcsdup(pszFile);
36 pNew->pszImeFile = _wcsdup(pszImeFile);
37 if (pNew->pszName == NULL || pNew->pszFile == NULL ||
38 (pszImeFile && pNew->pszImeFile == NULL))
39 {
40 free(pNew->pszName);
41 free(pNew->pszFile);
42 free(pNew->pszImeFile);
43 free(pNew);
44 return NULL;
45 }
46
47 if (pCurrent == NULL)
48 {
49 _LayoutList = pNew;
50 }
51 else
52 {
53 while (pCurrent->pNext != NULL)
54 {
55 pCurrent = pCurrent->pNext;
56 }
57
58 pNew->pPrev = pCurrent;
59 pCurrent->pNext = pNew;
60 }
61
62 return pNew;
63}
64
65
66VOID
68{
69 LAYOUT_LIST_NODE *pCurrent;
70 LAYOUT_LIST_NODE *pNext;
71
72 if (_LayoutList == NULL)
73 return;
74
75 for (pCurrent = _LayoutList; pCurrent; pCurrent = pNext)
76 {
77 pNext = pCurrent->pNext;
78
79 free(pCurrent->pszName);
80 free(pCurrent->pszFile);
81 free(pCurrent->pszImeFile);
82 free(pCurrent);
83 }
84
86}
87
89
91{
93 HINSTANCE hSHLWAPI = LoadLibraryW(L"shlwapi");
96 if (fn)
97 hr = fn(hkey, value, buf, size);
98 FreeLibrary(hSHLWAPI);
99 return hr;
100}
101
102static BOOL
103LayoutList_ReadLayout(HKEY hLayoutKey, LPCWSTR szKLID, LPCWSTR szSystemDirectory)
104{
105 WCHAR szFile[80], szImeFile[80], szBuffer[MAX_PATH], szFilePath[MAX_PATH];
106 DWORD dwSize, dwKLID = DWORDfromString(szKLID);
107 WORD wSpecialId = 0;
108 LPWSTR pszImeFile = NULL;
109
110 dwSize = sizeof(szFile);
111 if (RegQueryValueExW(hLayoutKey, L"Layout File", NULL, NULL,
112 (LPBYTE)szFile, &dwSize) != ERROR_SUCCESS)
113 {
114 return FALSE; /* No "Layout File" value */
115 }
116
117 if (IS_IME_KLID(dwKLID))
118 {
120 dwSize = sizeof(szImeFile);
121 if (RegQueryValueExW(hLayoutKey, L"IME File", NULL, NULL,
122 (LPBYTE)szImeFile, &dwSize) != ERROR_SUCCESS)
123 {
124 return FALSE; /* No "IME File" value */
125 }
126
127 if (wcschr(szImeFile, L'\\') != NULL)
128 return FALSE; /* Invalid character */
129
132 return FALSE; /* Does not exist */
133
134 pszImeFile = szImeFile;
135 }
136
137 /* Build the "Layout File" full path and check existence */
138 StringCchPrintfW(szFilePath, ARRAYSIZE(szFilePath), L"%s\\%s", szSystemDirectory, szFile);
140 return FALSE; /* No layout file found */
141
142 /* Get the special ID */
143 dwSize = sizeof(szBuffer);
144 if (RegQueryValueExW(hLayoutKey, L"Layout Id", NULL, NULL,
145 (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
146 {
147 wSpecialId = LOWORD(DWORDfromString(szBuffer));
148 }
149
150 /* If there is a valid "Layout Display Name", then use it as the entry name */
151 if (FakeSHLoadRegUIStringW(hLayoutKey, L"Layout Display Name",
152 szBuffer, ARRAYSIZE(szBuffer)) == S_OK)
153 {
154 LayoutList_AppendNode(dwKLID, wSpecialId, szFile, szBuffer, pszImeFile);
155 return TRUE;
156 }
157
158 /* Otherwise, use "Layout Text" value as the entry name */
159 dwSize = sizeof(szBuffer);
160 if (RegQueryValueExW(hLayoutKey, L"Layout Text", NULL, NULL,
161 (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
162 {
163 LayoutList_AppendNode(dwKLID, wSpecialId, szFile, szBuffer, pszImeFile);
164 return TRUE;
165 }
166
167 return FALSE;
168}
169
170VOID
172{
173 WCHAR szSystemDirectory[MAX_PATH], szKLID[KL_NAMELENGTH];
174 DWORD dwSize, dwIndex;
175 HKEY hKey, hLayoutKey;
176
177 if (!GetSystemDirectoryW(szSystemDirectory, ARRAYSIZE(szSystemDirectory)))
178 return;
179
180 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts",
181 0, KEY_READ, &hKey) != ERROR_SUCCESS)
182 {
183 return;
184 }
185
186 for (dwIndex = 0; ; ++dwIndex)
187 {
188 dwSize = ARRAYSIZE(szKLID);
189 if (RegEnumKeyExW(hKey, dwIndex, szKLID, &dwSize, NULL, NULL,
191 {
192 break;
193 }
194
195 if (RegOpenKeyExW(hKey, szKLID, 0, KEY_QUERY_VALUE, &hLayoutKey) == ERROR_SUCCESS)
196 {
197 LayoutList_ReadLayout(hLayoutKey, szKLID, szSystemDirectory);
198 RegCloseKey(hLayoutKey);
199 }
200 }
201
203}
204
205
208{
209 LAYOUT_LIST_NODE *pCurrent;
210
211 if (IS_SPECIAL_HKL(hkl))
212 {
213 WORD wSpecialId = SPECIALIDFROMHKL(hkl);
214
215 for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
216 {
217 if (wSpecialId == pCurrent->wSpecialId)
218 {
219 return pCurrent;
220 }
221 }
222 }
223 else if (IS_IME_HKL(hkl))
224 {
225 for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
226 {
227 if (hkl == UlongToHandle(pCurrent->dwKLID))
228 {
229 return pCurrent;
230 }
231 }
232 }
233 else
234 {
235 for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
236 {
237 if (HIWORD(hkl) == LOWORD(pCurrent->dwKLID))
238 {
239 return pCurrent;
240 }
241 }
242 }
243
244 return NULL;
245}
246
247
250{
251 return _LayoutList;
252}
#define UlongToHandle(ul)
Definition: basetsd.h:97
HANDLE HKEY
Definition: registry.h:26
#define RegCloseKey(hKey)
Definition: registry.h:49
#define E_FAIL
Definition: ddrawi.h:102
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static DWORD DWORDfromString(const WCHAR *pszString)
Definition: input.h:80
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
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:2504
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define wcschr
Definition: compat.h:17
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
FxAutoRegKey hKey
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define SPECIALIDFROMHKL(hKL)
Definition: imm32_undoc.h:22
#define IS_SPECIAL_HKL(hKL)
Definition: imm32_undoc.h:21
#define IS_IME_KLID(dwKLID)
Definition: imm32_undoc.h:24
#define IS_IME_HKL(hKL)
Definition: imm32_undoc.h:20
#define S_OK
Definition: intsafe.h:52
static BOOL GetSystemLibraryPath(LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
Definition: kbswitch.c:187
VOID LayoutList_Create(VOID)
Definition: layout_list.c:171
VOID LayoutList_Destroy(VOID)
Definition: layout_list.c:67
LAYOUT_LIST_NODE * LayoutList_GetByHkl(HKL hkl)
Definition: layout_list.c:207
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11
HRESULT FakeSHLoadRegUIStringW(HKEY hkey, LPCWSTR value, LPWSTR buf, DWORD size)
Definition: layout_list.c:90
LAYOUT_LIST_NODE * LayoutList_GetFirst(VOID)
Definition: layout_list.c:249
static LAYOUT_LIST_NODE * LayoutList_AppendNode(DWORD dwKLID, WORD wSpecialId, LPCWSTR pszFile, LPCWSTR pszName, LPCWSTR pszImeFile)
Definition: layout_list.c:14
static BOOL LayoutList_ReadLayout(HKEY hLayoutKey, LPCWSTR szKLID, LPCWSTR szSystemDirectory)
Definition: layout_list.c:103
HRESULT(WINAPI * FN_SHLoadRegUIStringW)(HKEY, LPCWSTR, LPWSTR, DWORD)
Definition: layout_list.c:88
LPCWSTR szPath
Definition: env.c:37
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
HKL hkl
Definition: msctf.idl:650
UINT_PTR HKL
Definition: msctf.idl:143
#define KEY_READ
Definition: nt_native.h:1023
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
static WCHAR szFilePath[]
Definition: qotd.c:14
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)
HRESULT hr
Definition: shlfolder.c:183
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
struct _LAYOUT_LIST_NODE * pPrev
Definition: layout_list.h:13
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:14
int32_t INT_PTR
Definition: typedefs.h:64
unsigned char * LPBYTE
Definition: typedefs.h:53
#define HIWORD(l)
Definition: typedefs.h:247
Definition: pdh_main.c:94
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
#define ZeroMemory
Definition: winbase.h:1737
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KL_NAMELENGTH
Definition: winuser.h:122
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185