ReactOS 0.4.15-dev-7953-g1f49173
keyboard.c
Go to the documentation of this file.
1/*
2 * ReactOS
3 * Copyright (C) 2004, 2007 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19/*
20 * PROJECT: ReactOS Main Control Panel
21 * FILE: dll/cpl/main/keyboard.c
22 * PURPOSE: Keyboard Control Panel
23 * PROGRAMMER: Eric Kohl
24 */
25
26#include "main.h"
27
28#define ID_BLINK_TIMER 345
29
30typedef struct _SPEED_DATA
31{
41
42static VOID
44 _In_ UINT uCaretBlinkTime)
45{
46 HKEY hKey;
47 WCHAR szBuffer[12];
48
50 L"Control Panel\\Desktop",
53 {
54 return;
55 }
56
57 wsprintf(szBuffer, L"%d", uCaretBlinkTime);
58
59 RegSetValueExW(hKey, L"CursorBlinkRate",
60 0, REG_SZ,
61 (CONST BYTE*)szBuffer,
62 (wcslen(szBuffer) + 1) * sizeof(WCHAR));
63
65}
66
67/* Property page dialog callback */
68static INT_PTR CALLBACK
70 IN UINT uMsg,
73{
74 PSPEED_DATA pSpeedData;
75
76 pSpeedData = (PSPEED_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
77
78 switch (uMsg)
79 {
80 case WM_INITDIALOG:
81 pSpeedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SPEED_DATA));
82 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSpeedData);
83
84 /* Get current keyboard delay */
86 sizeof(INT),
87 &pSpeedData->nKeyboardDelay,
88 0))
89 {
90 pSpeedData->nKeyboardDelay = 2;
91 }
92
93 pSpeedData->nOrigKeyboardDelay = pSpeedData->nKeyboardDelay;
94
95 /* Get current keyboard delay */
97 sizeof(DWORD),
98 &pSpeedData->dwKeyboardSpeed,
99 0))
100 {
101 pSpeedData->dwKeyboardSpeed = 31;
102 }
103
104 pSpeedData->dwOrigKeyboardSpeed = pSpeedData->dwKeyboardSpeed;
105
106 pSpeedData->fShowCursor = TRUE;
107 GetWindowRect(GetDlgItem(hwndDlg, IDC_TEXT_CURSOR_BLINK), &pSpeedData->rcCursor);
108 ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.left);
109 ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.right);
110
111 /* Get the caret blink time and save its original value */
112 pSpeedData->uOrigCaretBlinkTime = GetCaretBlinkTime();
113 pSpeedData->uCaretBlinkTime = pSpeedData->uOrigCaretBlinkTime;
114
116 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(3 - pSpeedData->nKeyboardDelay));
117
119 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pSpeedData->dwKeyboardSpeed);
120
122 SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(12 - (pSpeedData->uCaretBlinkTime / 100)));
123
124 /* Start the blink timer */
125 pSpeedData->uCaretBlinkTime = pSpeedData->uCaretBlinkTime >= 1200 ? -1 : pSpeedData->uCaretBlinkTime;
126 if ((INT)pSpeedData->uCaretBlinkTime > 0)
127 {
128 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
129 }
130 else
131 {
132 PostMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
133 }
134
135 break;
136
137 case WM_HSCROLL:
139 {
140 switch (LOWORD(wParam))
141 {
142 case TB_LINEUP:
143 case TB_LINEDOWN:
144 case TB_PAGEUP:
145 case TB_PAGEDOWN:
146 case TB_TOP:
147 case TB_BOTTOM:
148 case TB_ENDTRACK:
149 pSpeedData->nKeyboardDelay = 3 - (INT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_GETPOS, 0, 0);
151 pSpeedData->nKeyboardDelay,
152 0,
153 0);
154 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
155 break;
156
157 case TB_THUMBTRACK:
158 pSpeedData->nKeyboardDelay = 3 - (INT)HIWORD(wParam);
160 pSpeedData->nKeyboardDelay,
161 0,
162 0);
163 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
164 break;
165 }
166 }
167 else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_REPEAT_RATE))
168 {
169 switch (LOWORD(wParam))
170 {
171 case TB_LINEUP:
172 case TB_LINEDOWN:
173 case TB_PAGEUP:
174 case TB_PAGEDOWN:
175 case TB_TOP:
176 case TB_BOTTOM:
177 case TB_ENDTRACK:
178 pSpeedData->dwKeyboardSpeed = (DWORD)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_GETPOS, 0, 0);
180 pSpeedData->dwKeyboardSpeed,
181 0,
182 0);
183 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
184 break;
185
186 case TB_THUMBTRACK:
187 pSpeedData->dwKeyboardSpeed = (DWORD)HIWORD(wParam);
189 pSpeedData->dwKeyboardSpeed,
190 0,
191 0);
192 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
193 break;
194 }
195 }
196 else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_CURSOR_BLINK))
197 {
198 switch (LOWORD(wParam))
199 {
200 case TB_LINEUP:
201 case TB_LINEDOWN:
202 case TB_PAGEUP:
203 case TB_PAGEDOWN:
204 case TB_TOP:
205 case TB_BOTTOM:
206 case TB_ENDTRACK:
207 pSpeedData->uCaretBlinkTime = (12 - (UINT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_GETPOS, 0, 0)) * 100;
208 KillTimer(hwndDlg, ID_BLINK_TIMER);
209 pSpeedData->uCaretBlinkTime = pSpeedData->uCaretBlinkTime >= 1200 ? -1 : pSpeedData->uCaretBlinkTime;
210 if ((INT)pSpeedData->uCaretBlinkTime > 0)
211 {
212 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
213 }
214 else if (pSpeedData->fShowCursor)
215 {
216 SendMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
217 }
218 SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
219 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
220 break;
221
222 case TB_THUMBTRACK:
223 pSpeedData->uCaretBlinkTime = (12 - (UINT)HIWORD(wParam)) * 100;
224 KillTimer(hwndDlg, ID_BLINK_TIMER);
225 pSpeedData->uCaretBlinkTime = pSpeedData->uCaretBlinkTime >= 1200 ? -1 : pSpeedData->uCaretBlinkTime;
226 if ((INT)pSpeedData->uCaretBlinkTime > 0)
227 {
228 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
229 }
230 else if (pSpeedData->fShowCursor)
231 {
232 SendMessage(hwndDlg, WM_TIMER, ID_BLINK_TIMER, 0);
233 }
234 SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
235 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
236 break;
237 }
238 }
239 break;
240
241 case WM_TIMER:
242 if (wParam == ID_BLINK_TIMER)
243 {
244 if (pSpeedData->fShowCursor)
245 {
246 HDC hDC = GetDC(hwndDlg);
247 HBRUSH hBrush = GetSysColorBrush(COLOR_BTNTEXT);
248 FillRect(hDC, &pSpeedData->rcCursor, hBrush);
249 ReleaseDC(hwndDlg, hDC);
250 }
251 else
252 {
253 InvalidateRect(hwndDlg, &pSpeedData->rcCursor, TRUE);
254 }
255
256 pSpeedData->fShowCursor = !pSpeedData->fShowCursor;
257 }
258 break;
259
260 case WM_NOTIFY:
261 {
262 LPNMHDR lpnm = (LPNMHDR)lParam;
263
264 switch(lpnm->code)
265 {
266 case PSN_APPLY:
267 /* Set the new keyboard settings */
268 if (pSpeedData->uOrigCaretBlinkTime != pSpeedData->uCaretBlinkTime)
269 {
270 UpdateCaretBlinkTimeReg(pSpeedData->uCaretBlinkTime);
271 }
272
274 pSpeedData->nKeyboardDelay,
275 0,
276 0);
278 pSpeedData->dwKeyboardSpeed,
279 0,
281 return TRUE;
282
283 case PSN_RESET:
284 /* Restore the original settings */
285 SetCaretBlinkTime(pSpeedData->uOrigCaretBlinkTime);
287 pSpeedData->nOrigKeyboardDelay,
288 0,
289 0);
291 pSpeedData->dwOrigKeyboardSpeed,
292 0,
293 0);
294 break;
295
296 default:
297 break;
298 }
299 }
300 break;
301
302 case WM_DESTROY:
303 KillTimer(hwndDlg, ID_BLINK_TIMER);
304 HeapFree(GetProcessHeap(), 0, pSpeedData);
305 break;
306 }
307
308 return FALSE;
309}
310
311
312/* Property page dialog callback */
313static INT_PTR CALLBACK
315 IN UINT uMsg,
318{
319 GUID Guids[1];
320 Guids[0] = GUID_DEVCLASS_KEYBOARD;
321
324
325 switch(uMsg)
326 {
327 case WM_INITDIALOG:
328 /* Create the hardware page */
330 Guids,
331 sizeof(Guids) / sizeof(Guids[0]),
333 break;
334 }
335
336 return FALSE;
337}
338
339static int CALLBACK
341{
342 // NOTE: This callback is needed to set large icon correctly.
343 HICON hIcon;
344 switch (uMsg)
345 {
346 case PSCB_INITIALIZED:
347 {
349 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
350 break;
351 }
352 }
353 return 0;
354}
355
358{
360 PROPSHEETHEADER psh;
361 HPSXA hpsxa;
362 INT nPage = 0;
363 LONG ret;
364
369
370 if (uMsg == CPL_STARTWPARMSW && lParam != 0)
371 nPage = _wtoi((PWSTR)lParam);
372
373 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
374 psh.dwSize = sizeof(PROPSHEETHEADER);
376 psh.hwndParent = hwnd;
377 psh.hInstance = hApplet;
378 psh.pszIcon = MAKEINTRESOURCE(IDC_CPLICON_2);
379 psh.pszCaption = MAKEINTRESOURCE(IDS_CPLNAME_2);
380 psh.nStartPage = 0;
381 psh.phpage = hpsp;
382 psh.pfnCallback = PropSheetProc;
383
384 /* Load additional pages provided by shell extensions */
386
387 /* NOTE: The speed page (CPLPAGE_KEYBOARD_SPEED) cannot be replaced by
388 shell extensions since Win2k! */
391
392 if (hpsxa != NULL)
394
395 if (nPage != 0 && nPage <= psh.nPages)
396 psh.nStartPage = nPage;
397
398 ret = (LONG)(PropertySheet(&psh) != -1);
399
400 if (hpsxa != NULL)
402
403 return ret;
404}
405
406/* EOF */
static HDC hDC
Definition: 3dtext.c:33
static BOOL CALLBACK PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
Definition: advmon.c:13
static VOID InitPropSheetPage(PROPSHEETPAGE *psp, PSERVICEPROPSHEET dlgInfo, WORD idDlg, DLGPROC DlgProc)
Definition: propsheet.c:15
#define RegCloseKey(hKey)
Definition: registry.h:49
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define CPL_STARTWPARMSW
Definition: cpl.h:21
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HINSTANCE hApplet
Definition: access.c:17
#define ID_BLINK_TIMER
Definition: keyboard.c:28
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: keyboard.c:340
static INT_PTR CALLBACK KeybHardwareProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: keyboard.c:314
struct _SPEED_DATA * PSPEED_DATA
LONG APIENTRY KeyboardApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: keyboard.c:357
struct _SPEED_DATA SPEED_DATA
static INT_PTR CALLBACK KeyboardSpeedProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: keyboard.c:69
static VOID UpdateCaretBlinkTimeReg(_In_ UINT uCaretBlinkTime)
Definition: keyboard.c:43
@ HWPD_STANDARDLIST
Definition: main.h:24
HWND WINAPI DeviceCreateHardwarePageEx(HWND hWndParent, LPGUID lpGuids, UINT uNumberOfGuids, HWPAGE_DISPLAYMODE DisplayMode)
#define MAX_CPL_PAGES
Definition: main.h:47
#define IDC_SLIDER_CURSOR_BLINK
Definition: resource.h:104
#define IDC_SLIDER_REPEAT_RATE
Definition: resource.h:102
#define IDC_CPLICON_2
Definition: resource.h:6
#define IDC_SLIDER_REPEAT_DELAY
Definition: resource.h:100
#define IDS_CPLNAME_2
Definition: resource.h:38
#define IDC_TEXT_CURSOR_BLINK
Definition: resource.h:105
#define IDD_HARDWARE
Definition: resource.h:30
#define IDD_KEYBSPEED
Definition: resource.h:31
#define APIENTRY
Definition: api.h:79
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
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:4882
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define TEXT(s)
Definition: k32.h:26
#define REG_SZ
Definition: layer.c:22
static HDC
Definition: imagelist.c:92
static HICON
Definition: imagelist.c:84
#define _In_
Definition: ms_sal.h:308
HICON hIcon
Definition: msconfig.c:44
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define DWORD
Definition: nt_native.h:44
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define CONST
Definition: pedump.c:81
long LONG
Definition: pedump.c:60
#define INT
Definition: polytest.cpp:20
#define PROPSHEETHEADER
Definition: prsht.h:392
#define PSH_PROPTITLE
Definition: prsht.h:40
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSH_USECALLBACK
Definition: prsht.h:48
#define PSN_APPLY
Definition: prsht.h:117
#define PropertySheet
Definition: prsht.h:400
#define PSH_USEICONID
Definition: prsht.h:42
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define PSN_RESET
Definition: prsht.h:118
#define TB_TOP
Definition: commctrl.h:2079
#define TB_ENDTRACK
Definition: commctrl.h:2081
#define TB_PAGEUP
Definition: commctrl.h:2075
#define TB_BOTTOM
Definition: commctrl.h:2080
#define TBM_GETPOS
Definition: commctrl.h:2031
#define TB_PAGEDOWN
Definition: commctrl.h:2076
#define TBM_SETRANGE
Definition: commctrl.h:2037
#define TB_THUMBTRACK
Definition: commctrl.h:2078
#define TB_LINEUP
Definition: commctrl.h:2073
#define TBM_SETPOS
Definition: commctrl.h:2036
#define TB_LINEDOWN
Definition: commctrl.h:2074
#define REGSTR_PATH_CONTROLSFOLDER
Definition: regstr.h:76
#define WM_NOTIFY
Definition: richedit.h:61
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:2190
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:2013
HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
Definition: shellord.c:2043
DWORD dwOrigKeyboardSpeed
Definition: keyboard.c:35
BOOL fShowCursor
Definition: keyboard.c:38
RECT rcCursor
Definition: keyboard.c:39
UINT uOrigCaretBlinkTime
Definition: keyboard.c:37
INT nOrigKeyboardDelay
Definition: keyboard.c:33
INT nKeyboardDelay
Definition: keyboard.c:32
DWORD dwKeyboardSpeed
Definition: keyboard.c:34
UINT uCaretBlinkTime
Definition: keyboard.c:36
UINT code
Definition: winuser.h:3159
#define ICON_BIG
Definition: tnclass.cpp:51
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define IN
Definition: typedefs.h:39
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define HIWORD(l)
Definition: typedefs.h:247
int ret
#define ZeroMemory
Definition: winbase.h:1712
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define COLOR_BTNTEXT
Definition: winuser.h:933
#define DWLP_USER
Definition: winuser.h:872
#define WM_HSCROLL
Definition: winuser.h:1743
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
HBRUSH WINAPI GetSysColorBrush(_In_ int)
BOOL WINAPI SetCaretBlinkTime(_In_ UINT)
#define WM_INITDIALOG
Definition: winuser.h:1739
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define SPIF_SENDCHANGE
Definition: winuser.h:1572
#define SPI_SETKEYBOARDSPEED
Definition: winuser.h:1360
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1571
#define WM_TIMER
Definition: winuser.h:1742
#define SPI_GETKEYBOARDSPEED
Definition: winuser.h:1359
struct tagNMHDR * LPNMHDR
#define SendMessage
Definition: winuser.h:5843
HDC WINAPI GetDC(_In_opt_ HWND)
#define wsprintf
Definition: winuser.h:5865
#define PostMessage
Definition: winuser.h:5832
HWND WINAPI GetParent(_In_ HWND)
#define WM_DESTROY
Definition: winuser.h:1609
#define SPI_GETKEYBOARDDELAY
Definition: winuser.h:1371
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SystemParametersInfo
Definition: winuser.h:5858
#define SendDlgItemMessage
Definition: winuser.h:5842
#define SPI_SETKEYBOARDDELAY
Definition: winuser.h:1372
#define MAKEINTRESOURCE
Definition: winuser.h:591
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE hInstance, _In_ LPCWSTR lpIconName)
Definition: cursoricon.c:2075
UINT WINAPI GetCaretBlinkTime(void)
Definition: ntwrapper.h:166
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193