ReactOS  0.4.15-dev-5462-g4d0d22a
layout_list.c File Reference
#include "layout_list.h"
Include dependency graph for layout_list.c:

Go to the source code of this file.

Typedefs

typedef HRESULT(WINAPIFN_SHLoadRegUIStringW) (HKEY, LPCWSTR, LPWSTR, DWORD)
 

Functions

static LAYOUT_LIST_NODELayoutList_AppendNode (DWORD dwKLID, WORD wSpecialId, LPCWSTR pszFile, LPCWSTR pszName, LPCWSTR pszImeFile)
 
VOID LayoutList_Destroy (VOID)
 
HRESULT FakeSHLoadRegUIStringW (HKEY hkey, LPCWSTR value, LPWSTR buf, DWORD size)
 
static BOOL LayoutList_ReadLayout (HKEY hLayoutKey, LPCWSTR szKLID, LPCWSTR szSystemDirectory)
 
VOID LayoutList_Create (VOID)
 
LAYOUT_LIST_NODELayoutList_GetByHkl (HKL hkl)
 
LAYOUT_LIST_NODELayoutList_GetFirst (VOID)
 

Variables

static LAYOUT_LIST_NODE_LayoutList = NULL
 

Typedef Documentation

◆ FN_SHLoadRegUIStringW

typedef HRESULT(WINAPI * FN_SHLoadRegUIStringW) (HKEY, LPCWSTR, LPWSTR, DWORD)

Definition at line 88 of file layout_list.c.

Function Documentation

◆ FakeSHLoadRegUIStringW()

HRESULT FakeSHLoadRegUIStringW ( HKEY  hkey,
LPCWSTR  value,
LPWSTR  buf,
DWORD  size 
)

Definition at line 91 of file layout_list.c.

92 {
93 #if 1
95  WCHAR szDllPath[MAX_PATH];
96  DWORD dwSize;
98  INT iIndex, iLength;
99 
100  dwSize = size * sizeof(WCHAR);
102  return E_FAIL;
103 
104  if (buf[0] != L'@')
105  return S_OK;
106 
107  /* Move to the position after the character "@" */
108  pBuffer = buf + 1;
109 
110  /* Get a pointer to the beginning ",-" */
111  pIndex = wcsstr(pBuffer, L",-");
112  if (!pIndex)
113  return E_FAIL;
114 
115  /* Convert the number in the string after the ",-" */
116  iIndex = _wtoi(pIndex + 2);
117 
118  *pIndex = 0; /* Cut the string */
119 
120  if (ExpandEnvironmentStringsW(pBuffer, szDllPath, ARRAYSIZE(szDllPath)) == 0)
121  return E_FAIL;
122 
123  hDllInst = LoadLibraryW(szDllPath);
124  if (!hDllInst)
125  return E_FAIL;
126 
127  iLength = LoadStringW(hDllInst, iIndex, buf, size);
129 
130  if (iLength <= 0)
131  return E_FAIL;
132 
133  return S_OK;
134 #else
135  HRESULT hr = E_FAIL;
136  HINSTANCE hSHLWAPI = LoadLibraryW(L"shlwapi");
139  if (fn)
140  hr = fn(hkey, value, buf, size);
141  FreeLibrary(hSHLWAPI);
142  return hr;
143 #endif
144 }
Definition: pdh_main.c:93
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
HINSTANCE hDllInst
Definition: system.c:45
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
_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 ARRAYSIZE(array)
Definition: filtermapper.c:47
uint16_t * PWCHAR
Definition: typedefs.h:56
int32_t INT_PTR
Definition: typedefs.h:64
#define E_FAIL
Definition: ddrawi.h:102
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:58
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define LoadLibraryW(x)
Definition: compat.h:747
PVOID pBuffer
const char * LPCSTR
Definition: xmlstorage.h:183
#define FreeLibrary(x)
Definition: compat.h:748
GLsizeiptr size
Definition: glext.h:5919
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
#define S_OK
Definition: intsafe.h:52
_Out_ PULONG _Out_ PULONG pIndex
Definition: ndis.h:4564
#define NULL
Definition: types.h:112
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HRESULT(WINAPI * FN_SHLoadRegUIStringW)(HKEY, LPCWSTR, LPWSTR, DWORD)
Definition: layout_list.c:88
#define GetProcAddress(x, y)
Definition: compat.h:753
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by LayoutList_ReadLayout().

◆ LayoutList_AppendNode()

static LAYOUT_LIST_NODE* LayoutList_AppendNode ( DWORD  dwKLID,
WORD  wSpecialId,
LPCWSTR  pszFile,
LPCWSTR  pszName,
LPCWSTR  pszImeFile 
)
static

Definition at line 14 of file layout_list.c.

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->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 }
#define free
Definition: debug_ros.c:5
#define ZeroMemory
Definition: winbase.h:1670
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:14
#define NULL
Definition: types.h:112
struct _LAYOUT_LIST_NODE * pPrev
Definition: layout_list.h:13
#define malloc
Definition: debug_ros.c:4
_Check_return_ _CRTIMP wchar_t *__cdecl _wcsdup(_In_z_ const wchar_t *_Str)

Referenced by LayoutList_ReadLayout().

◆ LayoutList_Create()

VOID LayoutList_Create ( VOID  )

Definition at line 215 of file layout_list.c.

216 {
217  WCHAR szSystemDirectory[MAX_PATH], szKLID[KL_NAMELENGTH];
218  DWORD dwSize, dwIndex;
219  HKEY hKey, hLayoutKey;
220 
221  if (!GetSystemDirectoryW(szSystemDirectory, ARRAYSIZE(szSystemDirectory)))
222  return;
223 
224  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Keyboard Layouts",
225  0, KEY_READ, &hKey) != ERROR_SUCCESS)
226  {
227  return;
228  }
229 
230  for (dwIndex = 0; ; ++dwIndex)
231  {
232  dwSize = ARRAYSIZE(szKLID);
233  if (RegEnumKeyExW(hKey, dwIndex, szKLID, &dwSize, NULL, NULL,
234  NULL, NULL) != ERROR_SUCCESS)
235  {
236  break;
237  }
238 
239  if (RegOpenKeyExW(hKey, szKLID, 0, KEY_QUERY_VALUE, &hLayoutKey) == ERROR_SUCCESS)
240  {
241  LayoutList_ReadLayout(hLayoutKey, szKLID, szSystemDirectory);
242  RegCloseKey(hLayoutKey);
243  }
244  }
245 
246  RegCloseKey(hKey);
247 }
#define KL_NAMELENGTH
Definition: winuser.h:122
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define L(x)
Definition: ntvdm.h:50
static BOOL LayoutList_ReadLayout(HKEY hLayoutKey, LPCWSTR szKLID, LPCWSTR szSystemDirectory)
Definition: layout_list.c:147
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
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:2527
#define RegCloseKey(hKey)
Definition: registry.h:47
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by OnInitSettingsPage().

◆ LayoutList_Destroy()

VOID LayoutList_Destroy ( VOID  )

Definition at line 67 of file layout_list.c.

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 
85  _LayoutList = NULL;
86 }
#define free
Definition: debug_ros.c:5
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:14
#define NULL
Definition: types.h:112

Referenced by OnDestroySettingsPage().

◆ LayoutList_GetByHkl()

LAYOUT_LIST_NODE* LayoutList_GetByHkl ( HKL  hkl)

Definition at line 251 of file layout_list.c.

252 {
253  LAYOUT_LIST_NODE *pCurrent;
254 
255  if (IS_SPECIAL_HKL(hkl))
256  {
257  WORD wSpecialId = SPECIALIDFROMHKL(hkl);
258 
259  for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
260  {
261  if (wSpecialId == pCurrent->wSpecialId)
262  {
263  return pCurrent;
264  }
265  }
266  }
267  else if (IS_IME_HKL(hkl))
268  {
269  for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
270  {
271  if (hkl == UlongToHandle(pCurrent->dwKLID))
272  {
273  return pCurrent;
274  }
275  }
276  }
277  else
278  {
279  for (pCurrent = _LayoutList; pCurrent != NULL; pCurrent = pCurrent->pNext)
280  {
281  if (HIWORD(hkl) == LOWORD(pCurrent->dwKLID))
282  {
283  return pCurrent;
284  }
285  }
286  }
287 
288  return NULL;
289 }
#define IS_SPECIAL_HKL(hKL)
Definition: input.h:89
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11
struct _LAYOUT_LIST_NODE * pNext
Definition: layout_list.h:14
#define UlongToHandle(ul)
Definition: basetsd.h:97
unsigned short WORD
Definition: ntddk_ex.h:93
#define SPECIALIDFROMHKL(hKL)
Definition: input.h:90
HKL hkl
Definition: msctf.idl:611
#define IS_IME_HKL(hKL)
Definition: input.h:88
#define NULL
Definition: types.h:112
#define HIWORD(l)
Definition: typedefs.h:247
#define LOWORD(l)
Definition: pedump.c:82

Referenced by InputList_Create().

◆ LayoutList_GetFirst()

LAYOUT_LIST_NODE* LayoutList_GetFirst ( VOID  )

Definition at line 293 of file layout_list.c.

294 {
295  return _LayoutList;
296 }
static LAYOUT_LIST_NODE * _LayoutList
Definition: layout_list.c:11

Referenced by EditDialogProc(), and OnInitAddDialog().

◆ LayoutList_ReadLayout()

static BOOL LayoutList_ReadLayout ( HKEY  hLayoutKey,
LPCWSTR  szKLID,
LPCWSTR  szSystemDirectory 
)
static

Definition at line 147 of file layout_list.c.

148 {
149  WCHAR szFile[80], szImeFile[80], szBuffer[MAX_PATH], szFilePath[MAX_PATH];
150  DWORD dwSize, dwKLID = DWORDfromString(szKLID);
151  WORD wSpecialId = 0;
152  LPWSTR pszImeFile = NULL;
153 
154  dwSize = sizeof(szFile);
155  if (RegQueryValueExW(hLayoutKey, L"Layout File", NULL, NULL,
156  (LPBYTE)szFile, &dwSize) != ERROR_SUCCESS)
157  {
158  return FALSE; /* No "Layout File" value */
159  }
160 
161  if (IS_IME_KLID(dwKLID))
162  {
164  dwSize = sizeof(szImeFile);
165  if (RegQueryValueExW(hLayoutKey, L"IME File", NULL, NULL,
166  (LPBYTE)szImeFile, &dwSize) != ERROR_SUCCESS)
167  {
168  return FALSE; /* No "IME File" value */
169  }
170 
171  if (wcschr(szImeFile, L'\\') != NULL)
172  return FALSE; /* Invalid character */
173 
176  return FALSE; /* Does not exist */
177 
178  pszImeFile = szImeFile;
179  }
180 
181  /* Build the "Layout File" full path and check existence */
182  StringCchPrintfW(szFilePath, ARRAYSIZE(szFilePath), L"%s\\%s", szSystemDirectory, szFile);
184  return FALSE; /* No layout file found */
185 
186  /* Get the special ID */
187  dwSize = sizeof(szBuffer);
188  if (RegQueryValueExW(hLayoutKey, L"Layout Id", NULL, NULL,
189  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
190  {
191  wSpecialId = LOWORD(DWORDfromString(szBuffer));
192  }
193 
194  /* If there is a valid "Layout Display Name", then use it as the entry name */
195  if (FakeSHLoadRegUIStringW(hLayoutKey, L"Layout Display Name",
196  szBuffer, ARRAYSIZE(szBuffer)) == S_OK)
197  {
198  LayoutList_AppendNode(dwKLID, wSpecialId, szFile, szBuffer, pszImeFile);
199  return TRUE;
200  }
201 
202  /* Otherwise, use "Layout Text" value as the entry name */
203  dwSize = sizeof(szBuffer);
204  if (RegQueryValueExW(hLayoutKey, L"Layout Text", NULL, NULL,
205  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
206  {
207  LayoutList_AppendNode(dwKLID, wSpecialId, szFile, szBuffer, pszImeFile);
208  return TRUE;
209  }
210 
211  return FALSE;
212 }
static WCHAR szFilePath[]
Definition: qotd.c:14
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IS_IME_KLID(dwKLID)
Definition: input.h:92
#define TRUE
Definition: types.h:120
HRESULT FakeSHLoadRegUIStringW(HKEY hkey, LPCWSTR value, LPWSTR buf, DWORD size)
Definition: layout_list.c:91
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static LAYOUT_LIST_NODE * LayoutList_AppendNode(DWORD dwKLID, WORD wSpecialId, LPCWSTR pszFile, LPCWSTR pszName, LPCWSTR pszImeFile)
Definition: layout_list.c:14
static BOOL GetSystemLibraryPath(LPTSTR szPath, SIZE_T cchPath, LPCTSTR FileName)
Definition: kbswitch.c:85
#define L(x)
Definition: ntvdm.h:50
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define S_OK
Definition: intsafe.h:52
LPCWSTR szPath
Definition: env.c:37
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
#define NULL
Definition: types.h:112
static DWORD DWORDfromString(const WCHAR *pszString)
Definition: input.h:77
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define LOWORD(l)
Definition: pedump.c:82
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56

Referenced by LayoutList_Create().

Variable Documentation

◆ _LayoutList

LAYOUT_LIST_NODE* _LayoutList = NULL
static