[INPUT]
[reactos.git] / reactos / dll / cpl / input / changekeyseq.c
1 /*
2 * PROJECT: input.dll
3 * FILE: dll/win32/input/changekeyseq.c
4 * PURPOSE: input.dll
5 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6 * UPDATE HISTORY:
7 * 06-09-2007 Created
8 */
9
10 #include "input.h"
11
12 BOOL
13 GetHotkeys(LPTSTR szHotkey, LPTSTR szLangHotkey, LPTSTR szLayoutHotkey)
14 {
15 HKEY hKey;
16 DWORD dwSize;
17
18 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Toggle"),
19 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
20 {
21 dwSize = (1 + 1) * sizeof(TCHAR);
22 if (RegQueryValueEx(hKey, _T("Hotkey"), NULL, NULL,
23 (LPBYTE)szHotkey, &dwSize) != ERROR_SUCCESS)
24 {
25 RegCloseKey(hKey);
26 return FALSE;
27 }
28
29 dwSize = (1 + 1) * sizeof(TCHAR);
30 if (RegQueryValueEx(hKey, _T("Language Hotkey"), NULL, NULL,
31 (LPBYTE)szLangHotkey, &dwSize) != ERROR_SUCCESS)
32 {
33 RegCloseKey(hKey);
34 return FALSE;
35 }
36
37 dwSize = (1 + 1) * sizeof(TCHAR);
38 if (RegQueryValueEx(hKey, _T("Layout Hotkey"), NULL, NULL,
39 (LPBYTE)szLayoutHotkey, &dwSize) != ERROR_SUCCESS)
40 {
41 RegCloseKey(hKey);
42 return FALSE;
43 }
44
45 RegCloseKey(hKey);
46 }
47 else return FALSE;
48
49 return TRUE;
50 }
51
52 static VOID
53 SaveKeySeq(HWND hDlg)
54 {
55 TCHAR szLang[1 + 1], szLayout[1 + 1];
56 HKEY hKey;
57
58 if (SendDlgItemMessage(hDlg, IDC_SWITCH_INPUT_LANG_CB, BM_GETCHECK, 0, 0) == BST_CHECKED)
59 {
60 if (SendDlgItemMessage(hDlg, IDC_CTRL_LANG, BM_GETCHECK, 0, 0) == BST_CHECKED)
61 _tcscpy(szLang, _T("2"));
62 else
63 _tcscpy(szLang, _T("1"));
64 }
65 else
66 {
67 _tcscpy(szLang, _T("3"));
68 }
69
70 if (SendDlgItemMessage(hDlg, IDC_SWITCH_KBLAYOUTS_CB, BM_GETCHECK, 0, 0) == BST_CHECKED)
71 {
72 if (SendDlgItemMessage(hDlg, IDC_CTRL_LAYOUT, BM_GETCHECK, 0, 0) == BST_CHECKED)
73 _tcscpy(szLayout, _T("2"));
74 else
75 _tcscpy(szLayout, _T("1"));
76 }
77 else
78 {
79 _tcscpy(szLayout, _T("3"));
80 }
81
82 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Toggle"), 0, NULL,
83 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
84 NULL, &hKey, NULL) == ERROR_SUCCESS)
85 {
86 if (RegSetValueEx(hKey, _T("Hotkey"), 0, REG_SZ, (LPBYTE)szLang,
87 (DWORD)((1 + 1) * sizeof(TCHAR))) != ERROR_SUCCESS)
88 {
89 RegCloseKey(hKey);
90 return;
91 }
92
93 if (RegSetValueEx(hKey, _T("Language Hotkey"), 0, REG_SZ, (LPBYTE)szLang,
94 (DWORD)((1 + 1) * sizeof(TCHAR))) != ERROR_SUCCESS)
95 {
96 RegCloseKey(hKey);
97 return;
98 }
99
100 if (RegSetValueEx(hKey, _T("Layout Hotkey"), 0, REG_SZ, (LPBYTE)szLayout,
101 (DWORD)((1 + 1) * sizeof(TCHAR))) != ERROR_SUCCESS)
102 {
103 RegCloseKey(hKey);
104 return;
105 }
106
107 RegCloseKey(hKey);
108 UpdateKeySettingsList();
109 }
110 }
111
112 static VOID
113 InitChangeKeySeqDlg(HWND hDlg)
114 {
115 TCHAR szHotkey[1 + 1], szLangHotkey[1 + 1], szLayoutHotkey[1 + 1];
116
117 if (!GetHotkeys(szHotkey, szLangHotkey, szLayoutHotkey))
118 return;
119
120 if (_tcscmp(szLangHotkey, _T("3")) == 0)
121 {
122 SendDlgItemMessage(hDlg, IDC_CTRL_LANG, BM_SETCHECK, 1, 1);
123 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LANG), FALSE);
124 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LANG), FALSE);
125 }
126 else
127 {
128 SendDlgItemMessage(hDlg, IDC_SWITCH_INPUT_LANG_CB, BM_SETCHECK, 1, 1);
129
130 if (_tcscmp(szLangHotkey, _T("1")) == 0)
131 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LANG, BM_SETCHECK, 1, 1);
132 else
133 SendDlgItemMessage(hDlg, IDC_CTRL_LANG, BM_SETCHECK, 1, 1);
134 }
135
136 if (_tcscmp(szLayoutHotkey, _T("3")) == 0)
137 {
138 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LAYOUT, BM_SETCHECK, 1, 1);
139 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LAYOUT), FALSE);
140 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LAYOUT), FALSE);
141 }
142 else
143 {
144 SendDlgItemMessage(hDlg, IDC_SWITCH_KBLAYOUTS_CB, BM_SETCHECK, 1, 1);
145
146 if (_tcscmp(szLayoutHotkey, _T("1")) == 0)
147 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LAYOUT, BM_SETCHECK, 1, 1);
148 else
149 SendDlgItemMessage(hDlg, IDC_CTRL_LAYOUT, BM_SETCHECK, 1, 1);
150 }
151 }
152
153 INT_PTR CALLBACK
154 ChangeKeySeqDlgProc(HWND hDlg,
155 UINT message,
156 WPARAM wParam,
157 LPARAM lParam)
158 {
159 UNREFERENCED_PARAMETER(lParam);
160
161 switch (message)
162 {
163 case WM_INITDIALOG:
164 InitChangeKeySeqDlg(hDlg);
165 break;
166
167 case WM_COMMAND:
168 switch (LOWORD(wParam))
169 {
170 case IDC_SWITCH_INPUT_LANG_CB:
171 if (HIWORD(wParam) == BN_CLICKED)
172 {
173 if (SendDlgItemMessage(hDlg, IDC_SWITCH_INPUT_LANG_CB, BM_GETCHECK, 0, 0) == BST_CHECKED)
174 {
175 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LANG), TRUE);
176 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LANG), TRUE);
177 }
178 else
179 {
180 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LANG), FALSE);
181 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LANG), FALSE);
182 }
183 }
184 break;
185
186 case IDC_SWITCH_KBLAYOUTS_CB:
187 if (HIWORD(wParam) == BN_CLICKED)
188 {
189 if (SendDlgItemMessage(hDlg, IDC_SWITCH_KBLAYOUTS_CB, BM_GETCHECK, 0, 0) == BST_CHECKED)
190 {
191 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LAYOUT), TRUE);
192 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LAYOUT), TRUE);
193 }
194 else
195 {
196 EnableWindow(GetDlgItem(hDlg, IDC_CTRL_LAYOUT), FALSE);
197 EnableWindow(GetDlgItem(hDlg, IDC_LEFT_ALT_LAYOUT), FALSE);
198 }
199 }
200 break;
201
202 case IDC_CTRL_LANG:
203 if (HIWORD(wParam) == BN_CLICKED)
204 {
205 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LAYOUT, BM_SETCHECK, 1, 1);
206 SendDlgItemMessage(hDlg, IDC_CTRL_LAYOUT, BM_SETCHECK, 0, 0);
207 }
208 break;
209
210 case IDC_LEFT_ALT_LANG:
211 if (HIWORD(wParam) == BN_CLICKED)
212 {
213 SendDlgItemMessage(hDlg, IDC_CTRL_LAYOUT, BM_SETCHECK, 1, 1);
214 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LAYOUT, BM_SETCHECK, 0, 0);
215 }
216 break;
217
218 case IDC_CTRL_LAYOUT:
219 if (HIWORD(wParam) == BN_CLICKED)
220 {
221 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LANG, BM_SETCHECK, 1, 1);
222 SendDlgItemMessage(hDlg, IDC_CTRL_LANG, BM_SETCHECK, 0, 0);
223 }
224 break;
225
226 case IDC_LEFT_ALT_LAYOUT:
227 if (HIWORD(wParam) == BN_CLICKED)
228 {
229 SendDlgItemMessage(hDlg, IDC_CTRL_LANG, BM_SETCHECK, 1, 1);
230 SendDlgItemMessage(hDlg, IDC_LEFT_ALT_LANG, BM_SETCHECK, 0, 0);
231 }
232 break;
233
234 case IDOK:
235 SaveKeySeq(hDlg);
236 EndDialog(hDlg, LOWORD(wParam));
237 break;
238
239 case IDCANCEL:
240 EndDialog(hDlg, LOWORD(wParam));
241 break;
242 }
243 break;
244 }
245
246 return FALSE;
247 }
248
249 /* EOF */