ReactOS  0.4.13-dev-249-gcba1a2f
key_settings_dialog.c
Go to the documentation of this file.
1 /*
2 * PROJECT: input.dll
3 * FILE: dll/cpl/input/key_settings_dialog.c
4 * PURPOSE: input.dll
5 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6 */
7 
8 #include "input.h"
9 
10 static KEY_SETTINGS _KeySettings = { 0 };
11 
12 
13 DWORD
15 {
16  DWORD dwAttributes = 0;
17  HKEY hKey;
18 
20  L"Keyboard Layout",
21  0,
23  &hKey) == ERROR_SUCCESS)
24  {
25  DWORD dwSize = sizeof(dwAttributes);
26 
27  RegQueryValueExW(hKey,
28  L"Attributes",
29  NULL, NULL,
31  &dwSize);
32 
33  RegCloseKey(hKey);
34  }
35 
36  return dwAttributes;
37 }
38 
39 static VOID
41 {
42  HKEY hKey;
43 
45 
47  L"Keyboard Layout\\Toggle",
48  0,
50  &hKey) == ERROR_SUCCESS)
51  {
52  WCHAR szBuffer[MAX_PATH];
53  DWORD dwSize;
54 
55  dwSize = sizeof(szBuffer);
56 
57  if (RegQueryValueExW(hKey,
58  L"Language Hotkey",
59  NULL, NULL,
60  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
61  {
62  _KeySettings.dwLanguage = _wtoi(szBuffer);
63  }
64 
65  dwSize = sizeof(szBuffer);
66 
67  if (RegQueryValueExW(hKey,
68  L"Layout Hotkey",
69  NULL, NULL,
70  (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
71  {
72  _KeySettings.dwLayout = _wtoi(szBuffer);
73  }
74 
75  RegCloseKey(hKey);
76  }
77 }
78 
79 
80 static VOID
82 {
83  HKEY hKey;
84 
86  L"Keyboard Layout",
87  0,
89  &hKey) == ERROR_SUCCESS)
90  {
91  RegSetValueExW(hKey,
92  L"Attributes",
93  0,
94  REG_DWORD,
96  sizeof(DWORD));
97 
98  RegCloseKey(hKey);
99  }
100 
102  L"Keyboard Layout\\Toggle",
103  0,
105  &hKey) == ERROR_SUCCESS)
106  {
107  WCHAR szBuffer[MAX_PATH];
108 
109  StringCchPrintfW(szBuffer, ARRAYSIZE(szBuffer), L"%lu", _KeySettings.dwLanguage);
110 
111  RegSetValueExW(hKey,
112  L"Hotkey",
113  0,
114  REG_SZ,
115  (LPBYTE)szBuffer,
116  (wcslen(szBuffer) + 1) * sizeof(WCHAR));
117 
118  RegSetValueExW(hKey,
119  L"Language Hotkey",
120  0,
121  REG_SZ,
122  (LPBYTE)szBuffer,
123  (wcslen(szBuffer) + 1) * sizeof(WCHAR));
124 
125  StringCchPrintfW(szBuffer, ARRAYSIZE(szBuffer), L"%lu", _KeySettings.dwLayout);
126 
127  RegSetValueExW(hKey,
128  L"Layout Hotkey",
129  0,
130  REG_SZ,
131  (LPBYTE)szBuffer,
132  (wcslen(szBuffer) + 1) * sizeof(WCHAR));
133 
134  RegCloseKey(hKey);
135  }
136 
137  /* Notice system of change hotkeys parameters */
138  SystemParametersInfoW(SPI_SETLANGTOGGLE, 0, NULL, 0);
139 
140  /* Notice system of change CapsLock mode parameters */
142 }
143 
144 
145 static VOID
147 {
148  WCHAR szBuffer[MAX_STR_LEN];
149  LV_ITEM item;
150  INT iItemIndex;
151 
152  ListView_DeleteAllItems(hwndList);
153 
154  ZeroMemory(&item, sizeof(item));
155 
156  LoadStringW(hApplet, IDS_SWITCH_BET_INLANG, szBuffer, ARRAYSIZE(szBuffer));
157  item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
158  item.pszText = szBuffer;
159  item.iItem = 0;
160 
161  iItemIndex = ListView_InsertItem(hwndList, &item);
162 
163  if (_KeySettings.dwLanguage == 1)
164  {
165  LoadStringW(hApplet, IDS_LEFT_ALT_SHIFT, szBuffer, ARRAYSIZE(szBuffer));
166  }
167  else if (_KeySettings.dwLanguage == 2)
168  {
169  LoadStringW(hApplet, IDS_CTRL_SHIFT, szBuffer, ARRAYSIZE(szBuffer));
170  }
171  else
172  {
173  LoadStringW(hApplet, IDS_NONE, szBuffer, ARRAYSIZE(szBuffer));
174  }
175 
176  ListView_SetItemText(hwndList, iItemIndex, 1, szBuffer);
177 }
178 
179 
180 static VOID
182 {
184  HWND hwndList;
185 
187 
188  if (_KeySettings.dwAttributes & KLF_SHIFTLOCK)
189  {
192  }
193  else
194  {
197  }
198 
199  hwndList = GetDlgItem(hwndDlg, IDC_KEY_LISTVIEW);
200 
202 
203  ZeroMemory(&column, sizeof(column));
204 
206 
207  column.fmt = LVCFMT_LEFT;
208  column.iSubItem = 0;
209  column.pszText = L"";
210  column.cx = 210;
211  ListView_InsertColumn(hwndList, 0, &column);
212 
213  column.fmt = LVCFMT_RIGHT;
214  column.cx = 145;
215  column.iSubItem = 1;
216  column.pszText = L"";
217  ListView_InsertColumn(hwndList, 1, &column);
218 
219  UpdateKeySettingsListView(hwndList);
220 }
221 
222 
225 {
227 
228  switch (uMsg)
229  {
230  case WM_INITDIALOG:
231  {
232  OnInitKeySettingsDialog(hwndDlg);
233  }
234  break;
235 
236  case WM_COMMAND:
237  {
238  switch (LOWORD(wParam))
239  {
241  {
244  hwndDlg,
246  (LPARAM)&_KeySettings) == IDOK)
247  {
249  }
250  }
251  break;
252 
253  case IDOK:
254  {
256  {
257  _KeySettings.dwAttributes &= ~KLF_SHIFTLOCK;
258  }
259  else
260  {
261  _KeySettings.dwAttributes |= KLF_SHIFTLOCK;
262  }
263 
265  EndDialog(hwndDlg, LOWORD(wParam));
266  }
267  break;
268 
269  case IDCANCEL:
270  {
271  EndDialog(hwndDlg, LOWORD(wParam));
272  }
273  break;
274  }
275  }
276  break;
277  }
278 
279  return FALSE;
280 }
#define LV_ITEM
Definition: commctrl.h:2309
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
HKL WINAPI ActivateKeyboardLayout(_In_ HKL, _In_ UINT)
#define IDOK
Definition: winuser.h:824
#define LVCF_WIDTH
Definition: commctrl.h:2559
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
static VOID UpdateKeySettingsListView(HWND hwndList)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define LVCF_TEXT
Definition: commctrl.h:2560
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define IDC_CHANGE_KEY_SEQ_BTN
Definition: resource.h:29
#define HKEY_CURRENT_USER
Definition: winreg.h:11
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define LV_COLUMN
Definition: commctrl.h:2519
#define IDC_PRESS_SHIFT_KEY_RB
Definition: resource.h:27
#define IDS_NONE
Definition: resource.h:122
#define LVCFMT_RIGHT
Definition: commctrl.h:2571
DWORD dwLayout
Definition: input.h:63
#define CALLBACK
Definition: compat.h:27
#define LVS_EX_FULLROWSELECT
Definition: commctrl.h:2706
DWORD dwLanguage
Definition: input.h:62
#define LVCFMT_LEFT
Definition: commctrl.h:2570
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
HINSTANCE hApplet
Definition: access.c:17
UINT_PTR WPARAM
Definition: windef.h:207
#define ListView_InsertItem(hwnd, pitem)
Definition: commctrl.h:2380
INT_PTR CALLBACK KeySettingsDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
int32_t INT_PTR
Definition: typedefs.h:62
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
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
DWORD dwAttributes
Definition: vdmdbg.h:34
#define IDD_CHANGE_KEY_SEQ
Definition: resource.h:15
#define LVIF_TEXT
Definition: commctrl.h:2281
#define LVCF_SUBITEM
Definition: commctrl.h:2561
#define IDC_KEY_LISTVIEW
Definition: resource.h:28
#define IDS_SWITCH_BET_INLANG
Definition: resource.h:58
#define ListView_InsertColumn(hwnd, iCol, pcol)
Definition: commctrl.h:2608
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
DWORD ReadAttributes(VOID)
#define IDC_PRESS_CL_KEY_RB
Definition: resource.h:26
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
INT_PTR CALLBACK ChangeKeySeqDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define ListView_SetItemText(hwndLV, i, iSubItem_, pszText_)
Definition: commctrl.h:2663
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
BOOL WINAPI SystemParametersInfoW(_In_ UINT, _In_ UINT, _Inout_opt_ PVOID, _In_ UINT)
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
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ListView_SetExtendedListViewStyle(hwndLV, dw)
Definition: commctrl.h:2697
static VOID ReadKeysSettings(VOID)
static const WCHAR L[]
Definition: oid.c:1250
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
#define IDS_LEFT_ALT_SHIFT
Definition: resource.h:57
#define LVCF_FMT
Definition: commctrl.h:2558
static VOID OnInitKeySettingsDialog(HWND hwndDlg)
static ATOM item
Definition: dde.c:856
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
PKEYBOARD_LAYOUT GetKeyboardLayout()
Definition: utils.c:194
unsigned int UINT
Definition: ndis.h:50
#define BST_CHECKED
Definition: winuser.h:197
#define MAX_STR_LEN
Definition: defines.h:33
#define LVIF_PARAM
Definition: commctrl.h:2283
DWORD dwAttributes
Definition: input.h:61
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLenum GLenum GLvoid GLvoid * column
Definition: glext.h:5664
#define IDCANCEL
Definition: winuser.h:825
#define LVIF_STATE
Definition: commctrl.h:2284
#define REG_DWORD
Definition: sdbapi.c:596
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
static KEY_SETTINGS _KeySettings
#define ListView_DeleteAllItems(hwnd)
Definition: commctrl.h:2386
static VOID WriteKeysSettings(VOID)
#define IDS_CTRL_SHIFT
Definition: resource.h:56
#define REG_SZ
Definition: layer.c:22