[INPUT]
[reactos.git] / reactos / dll / cpl / input / keysettings.c
1 /*
2 * PROJECT: input.dll
3 * FILE: dll/win32/input/keysettings.c
4 * PURPOSE: input.dll
5 * PROGRAMMER: Dmitry Chapyshev (dmitry@reactos.org)
6 * Colin Finck
7 * UPDATE HISTORY:
8 * 06-09-2007 Created
9 */
10
11 #include "input.h"
12
13 static HWND hKeySettingsWnd;
14
15 static VOID
16 AddListColumn(HWND hDlg)
17 {
18 LV_COLUMN column;
19 HWND hList = GetDlgItem(hDlg, IDC_KEY_LISTVIEW);
20
21 ZeroMemory(&column, sizeof(LV_COLUMN));
22 column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
23
24 column.fmt = LVCFMT_LEFT;
25 column.iSubItem = 0;
26 column.pszText = _T("");
27 column.cx = 210;
28 (VOID) ListView_InsertColumn(hList, 0, &column);
29
30 column.fmt = LVCFMT_RIGHT;
31 column.cx = 145;
32 column.iSubItem = 1;
33 column.pszText = _T("");
34 (VOID) ListView_InsertColumn(hList, 1, &column);
35 }
36
37 static DWORD
38 GetAttributes()
39 {
40 DWORD dwValue, dwType, dwSize;
41 HKEY hKey;
42
43 if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout"), 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
44 return 0x0;
45
46 dwType = REG_DWORD;
47 dwSize = sizeof(DWORD);
48
49 if (RegQueryValueEx(hKey, _T("Attributes"), NULL, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS)
50 {
51 RegCloseKey(hKey);
52 return 0x0;
53 }
54
55 RegCloseKey(hKey);
56 return dwValue;
57 }
58
59 static VOID
60 SaveKeySettings(HWND hDlg)
61 {
62 HKEY hKey;
63 DWORD dwValue;
64
65 if (SendDlgItemMessage(hDlg, IDC_PRESS_CL_KEY_RB, BM_GETCHECK, 0, 0) == BST_CHECKED)
66 dwValue = 0x0;
67 else
68 dwValue = 0x10000;
69
70 if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout"), 0, NULL,
71 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,
72 NULL, &hKey, NULL) == ERROR_SUCCESS)
73 {
74 RegSetValueEx(hKey, _T("Attributes"), 0, REG_DWORD, (LPBYTE)&dwValue, sizeof(DWORD));
75
76 RegCloseKey(hKey);
77 }
78 }
79
80 static VOID
81 InitKeySettingsDlg(HWND hDlg)
82 {
83 TCHAR szHotkey[1 + 1], szLangHotkey[1 + 1], szLayoutHotkey[1 + 1],
84 szTitle[MAX_PATH], szText[MAX_PATH];
85 LV_ITEM item = {0};
86 HWND hHotkeyList = GetDlgItem(hDlg, IDC_KEY_LISTVIEW);
87 INT i;
88
89 if (GetAttributes() != 0x0)
90 SendDlgItemMessage(hDlg, IDC_PRESS_SHIFT_KEY_RB, BM_SETCHECK, 1, 1);
91 else
92 SendDlgItemMessage(hDlg, IDC_PRESS_CL_KEY_RB, BM_SETCHECK, 1, 1);
93
94 if (!GetHotkeys(szHotkey, szLangHotkey, szLayoutHotkey))
95 return;
96
97 if (!LoadString(hApplet, IDS_SWITCH_BET_INLANG, szTitle, sizeof(szTitle) / sizeof(TCHAR)))
98 return;
99
100 if (_tcscmp(szLangHotkey, _T("2")) == 0)
101 LoadString(hApplet, IDS_CTRL_SHIFT, szText, sizeof(szText) / sizeof(TCHAR));
102 else if (_tcscmp(szLangHotkey, _T("1")) == 0)
103 LoadString(hApplet, IDS_LEFT_ALT_SHIFT, szText, sizeof(szText) / sizeof(TCHAR));
104 else
105 LoadString(hApplet, IDS_NONE, szText, sizeof(szText) / sizeof(TCHAR));
106
107 item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
108 item.pszText = szTitle;
109 item.iItem = 0;
110 i = ListView_InsertItem(hHotkeyList, &item);
111
112 ListView_SetItemText(hHotkeyList, i, 1, szText);
113
114 (VOID) ListView_SetHotItem(hHotkeyList, i);
115 ListView_SetItemState(hHotkeyList, i, LVIS_SELECTED, LVIS_OVERLAYMASK);
116 }
117
118 VOID
119 UpdateKeySettingsList()
120 {
121 (VOID) ListView_DeleteAllItems(GetDlgItem(hKeySettingsWnd, IDC_KEY_LISTVIEW));
122 InitKeySettingsDlg(hKeySettingsWnd);
123 }
124
125 INT_PTR CALLBACK
126 KeySettingsDlgProc(HWND hDlg,
127 UINT message,
128 WPARAM wParam,
129 LPARAM lParam)
130 {
131 UNREFERENCED_PARAMETER(lParam);
132
133 switch (message)
134 {
135 case WM_INITDIALOG:
136 hKeySettingsWnd = hDlg;
137 AddListColumn(hDlg);
138 (VOID) ListView_SetExtendedListViewStyle(GetDlgItem(hDlg, IDC_KEY_LISTVIEW),
139 LVS_EX_FULLROWSELECT);
140 InitKeySettingsDlg(hDlg);
141 break;
142
143 case WM_COMMAND:
144 switch (LOWORD(wParam))
145 {
146 case IDC_CHANGE_KEY_SEQ_BTN:
147 DialogBox(hApplet,
148 MAKEINTRESOURCE(IDD_CHANGE_KEY_SEQ),
149 hDlg,
150 ChangeKeySeqDlgProc);
151 break;
152
153 case IDOK:
154 SaveKeySettings(hDlg);
155 EndDialog(hDlg, LOWORD(wParam));
156 break;
157
158 case IDCANCEL:
159 EndDialog(hDlg, LOWORD(wParam));
160 break;
161 }
162 break;
163 }
164
165 return FALSE;
166 }
167
168 /* EOF */