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