ReactOS  0.4.14-dev-57-g333b8f1
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 
30 typedef struct _SPEED_DATA
31 {
41 
42 /* Property page dialog callback */
43 static INT_PTR CALLBACK
45  IN UINT uMsg,
48 {
49  PSPEED_DATA pSpeedData;
50 
51  pSpeedData = (PSPEED_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
52 
53  switch (uMsg)
54  {
55  case WM_INITDIALOG:
56  pSpeedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SPEED_DATA));
57  SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSpeedData);
58 
59  /* Get current keyboard delay */
61  sizeof(INT),
62  &pSpeedData->nKeyboardDelay,
63  0))
64  {
65  pSpeedData->nKeyboardDelay = 2;
66  }
67 
68  pSpeedData->nOrigKeyboardDelay = pSpeedData->nKeyboardDelay;
69 
70  /* Get current keyboard delay */
72  sizeof(DWORD),
73  &pSpeedData->dwKeyboardSpeed,
74  0))
75  {
76  pSpeedData->dwKeyboardSpeed = 31;
77  }
78 
79  pSpeedData->dwOrigKeyboardSpeed = pSpeedData->dwKeyboardSpeed;
80 
81  pSpeedData->fShowCursor = TRUE;
82  GetWindowRect(GetDlgItem(hwndDlg, IDC_TEXT_CURSOR_BLINK), &pSpeedData->rcCursor);
83  ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.left);
84  ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.right);
85 
86  /* Get the caret blink time and save its original value */
87  pSpeedData->uOrigCaretBlinkTime = GetCaretBlinkTime();
88  pSpeedData->uCaretBlinkTime = pSpeedData->uOrigCaretBlinkTime;
89 
91  SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(3 - pSpeedData->nKeyboardDelay));
92 
94  SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pSpeedData->dwKeyboardSpeed);
95 
97  SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(12 - (pSpeedData->uCaretBlinkTime / 100)));
98 
99  /* Start the blink timer */
100  SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
101  break;
102 
103  case WM_HSCROLL:
104  if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_REPEAT_DELAY))
105  {
106  switch (LOWORD(wParam))
107  {
108  case TB_LINEUP:
109  case TB_LINEDOWN:
110  case TB_PAGEUP:
111  case TB_PAGEDOWN:
112  case TB_TOP:
113  case TB_BOTTOM:
114  case TB_ENDTRACK:
115  pSpeedData->nKeyboardDelay = 3 - (INT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_GETPOS, 0, 0);
117  pSpeedData->nKeyboardDelay,
118  0,
119  0);
120  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
121  break;
122 
123  case TB_THUMBTRACK:
124  pSpeedData->nKeyboardDelay = 3 - (INT)HIWORD(wParam);
126  pSpeedData->nKeyboardDelay,
127  0,
128  0);
129  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
130  break;
131  }
132  }
133  else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_REPEAT_RATE))
134  {
135  switch (LOWORD(wParam))
136  {
137  case TB_LINEUP:
138  case TB_LINEDOWN:
139  case TB_PAGEUP:
140  case TB_PAGEDOWN:
141  case TB_TOP:
142  case TB_BOTTOM:
143  case TB_ENDTRACK:
144  pSpeedData->dwKeyboardSpeed = (DWORD)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_GETPOS, 0, 0);
146  pSpeedData->dwKeyboardSpeed,
147  0,
148  0);
149  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
150  break;
151 
152  case TB_THUMBTRACK:
153  pSpeedData->dwKeyboardSpeed = (DWORD)HIWORD(wParam);
155  pSpeedData->dwKeyboardSpeed,
156  0,
157  0);
158  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
159  break;
160  }
161  }
162  else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_CURSOR_BLINK))
163  {
164  switch (LOWORD(wParam))
165  {
166  case TB_LINEUP:
167  case TB_LINEDOWN:
168  case TB_PAGEUP:
169  case TB_PAGEDOWN:
170  case TB_TOP:
171  case TB_BOTTOM:
172  case TB_ENDTRACK:
173  pSpeedData->uCaretBlinkTime = (12 - (UINT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_GETPOS, 0, 0)) * 100;
174  KillTimer(hwndDlg, ID_BLINK_TIMER);
175  SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
176  SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
177  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
178  break;
179 
180  case TB_THUMBTRACK:
181  pSpeedData->uCaretBlinkTime = (12 - (UINT)HIWORD(wParam)) * 100;
182  KillTimer(hwndDlg, ID_BLINK_TIMER);
183  SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL);
184  SetCaretBlinkTime(pSpeedData->uCaretBlinkTime);
185  PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
186  break;
187  }
188  }
189  break;
190 
191  case WM_TIMER:
192  if (wParam == ID_BLINK_TIMER)
193  {
194  if (pSpeedData->fShowCursor)
195  {
196  HDC hDC = GetDC(hwndDlg);
197  HBRUSH hBrush = GetSysColorBrush(COLOR_BTNTEXT);
198  FillRect(hDC, &pSpeedData->rcCursor, hBrush);
199  DeleteObject(hBrush);
200  ReleaseDC(hwndDlg, hDC);
201  }
202  else
203  {
204  InvalidateRect(hwndDlg, &pSpeedData->rcCursor, TRUE);
205  }
206 
207  pSpeedData->fShowCursor = !pSpeedData->fShowCursor;
208  }
209  break;
210 
211  case WM_NOTIFY:
212  {
213  LPNMHDR lpnm = (LPNMHDR)lParam;
214 
215  switch(lpnm->code)
216  {
217  case PSN_APPLY:
218  /* Set the new keyboard settings */
220  pSpeedData->nKeyboardDelay,
221  0,
222  0);
224  pSpeedData->dwKeyboardSpeed,
225  0,
227  return TRUE;
228 
229  case PSN_RESET:
230  /* Restore the original settings */
231  SetCaretBlinkTime(pSpeedData->uOrigCaretBlinkTime);
233  pSpeedData->nOrigKeyboardDelay,
234  0,
235  0);
237  pSpeedData->dwOrigKeyboardSpeed,
238  0,
239  0);
240  break;
241 
242  default:
243  break;
244  }
245  }
246  break;
247 
248  case WM_DESTROY:
249  KillTimer(hwndDlg, ID_BLINK_TIMER);
250  HeapFree(GetProcessHeap(), 0, pSpeedData);
251  break;
252  }
253 
254  return FALSE;
255 }
256 
257 
258 /* Property page dialog callback */
259 static INT_PTR CALLBACK
261  IN UINT uMsg,
262  IN WPARAM wParam,
263  IN LPARAM lParam)
264 {
265  GUID Guids[1];
266  Guids[0] = GUID_DEVCLASS_KEYBOARD;
267 
270 
271  switch(uMsg)
272  {
273  case WM_INITDIALOG:
274  /* Create the hardware page */
276  Guids,
277  sizeof(Guids) / sizeof(Guids[0]),
279  break;
280  }
281 
282  return FALSE;
283 }
284 
285 static int CALLBACK
287 {
288  // NOTE: This callback is needed to set large icon correctly.
289  HICON hIcon;
290  switch (uMsg)
291  {
292  case PSCB_INITIALIZED:
293  {
295  SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
296  break;
297  }
298  }
299  return 0;
300 }
301 
304 {
306  PROPSHEETHEADER psh;
307  HPSXA hpsxa;
308  TCHAR szCaption[256];
309  LONG ret;
310 
315 
316  LoadString(hApplet, IDS_CPLNAME_2, szCaption, sizeof(szCaption) / sizeof(TCHAR));
317 
318  ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
319  psh.dwSize = sizeof(PROPSHEETHEADER);
320  psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
321  psh.hwndParent = hwnd;
322  psh.hInstance = hApplet;
323  psh.pszIcon = MAKEINTRESOURCE(IDC_CPLICON_2);
324  psh.pszCaption = szCaption;
325  psh.nStartPage = 0;
326  psh.phpage = hpsp;
327  psh.pfnCallback = PropSheetProc;
328 
329  /* Load additional pages provided by shell extensions */
331 
332  /* NOTE: The speed page (CPLPAGE_KEYBOARD_SPEED) cannot be replaced by
333  shell extensions since Win2k! */
336 
337  if (hpsxa != NULL)
339 
340  ret = (LONG)(PropertySheet(&psh) != -1);
341 
342  if (hpsxa != NULL)
344 
345  return ret;
346 }
347 
348 /* EOF */
void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
Definition: shellord.c:1755
#define TB_THUMBTRACK
Definition: commctrl.h:2050
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define MAKEINTRESOURCE
Definition: winuser.h:591
#define IN
Definition: typedefs.h:38
static HICON
Definition: imagelist.c:84
DWORD dwOrigKeyboardSpeed
Definition: keyboard.c:35
#define TRUE
Definition: types.h:120
#define TB_PAGEDOWN
Definition: commctrl.h:2048
#define IDC_SLIDER_CURSOR_BLINK
Definition: resource.h:102
#define SPI_GETKEYBOARDSPEED
Definition: winuser.h:1341
HDC WINAPI GetDC(_In_opt_ HWND)
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
Definition: shellord.c:1577
DWORD dwKeyboardSpeed
Definition: keyboard.c:34
#define REGSTR_PATH_CONTROLSFOLDER
Definition: regstr.h:76
#define INT
Definition: polytest.cpp:20
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
#define TBM_SETRANGE
Definition: commctrl.h:2009
#define SystemParametersInfo
Definition: winuser.h:5759
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define TBM_SETPOS
Definition: commctrl.h:2008
HINSTANCE hApplet
Definition: access.c:17
UINT_PTR WPARAM
Definition: windef.h:207
#define SendDlgItemMessage
Definition: winuser.h:5743
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:62
#define PSH_USECALLBACK
Definition: prsht.h:48
int32_t INT
Definition: typedefs.h:56
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
struct tagNMHDR * LPNMHDR
#define IDC_TEXT_CURSOR_BLINK
Definition: resource.h:103
#define TB_PAGEUP
Definition: commctrl.h:2047
BOOL fShowCursor
Definition: keyboard.c:38
struct _SPEED_DATA SPEED_DATA
#define TB_LINEDOWN
Definition: commctrl.h:2046
UINT code
Definition: winuser.h:3133
#define MAX_CPL_PAGES
Definition: main.h:47
#define TB_BOTTOM
Definition: commctrl.h:2052
#define SPI_SETKEYBOARDDELAY
Definition: winuser.h:1354
#define PSH_USEICONID
Definition: prsht.h:42
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define TBM_GETPOS
Definition: commctrl.h:2003
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define MAKELONG(a, b)
Definition: typedefs.h:248
static INT_PTR CALLBACK KeyboardSpeedProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: keyboard.c:44
smooth NULL
Definition: ftsmooth.c:416
#define PROPSHEETHEADER
Definition: prsht.h:374
LONG_PTR LPARAM
Definition: windef.h:208
UINT uOrigCaretBlinkTime
Definition: keyboard.c:37
RECT rcCursor
Definition: keyboard.c:39
#define IDS_CPLNAME_2
Definition: resource.h:36
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
UINT WINAPI GetCaretBlinkTime(void)
Definition: ntwrapper.h:166
#define WM_DESTROY
Definition: winuser.h:1591
UINT uCaretBlinkTime
Definition: keyboard.c:36
#define IDD_KEYBSPEED
Definition: resource.h:29
LONG APIENTRY KeyboardApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
Definition: keyboard.c:303
char TCHAR
Definition: xmlstorage.h:189
#define SPI_GETKEYBOARDDELAY
Definition: winuser.h:1353
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define SPI_SETKEYBOARDSPEED
Definition: winuser.h:1342
#define PSH_PROPTITLE
Definition: prsht.h:40
#define PropSheet_Changed(d, w)
Definition: prsht.h:326
#define WM_TIMER
Definition: winuser.h:1724
#define IDD_HARDWARE
Definition: resource.h:28
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
#define IDC_CPLICON_2
Definition: resource.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95
HWND WINAPI DeviceCreateHardwarePageEx(HWND hWndParent, LPGUID lpGuids, UINT uNumberOfGuids, HWPAGE_DISPLAYMODE DisplayMode)
#define TB_LINEUP
Definition: commctrl.h:2045
#define TB_ENDTRACK
Definition: commctrl.h:2053
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
int ret
#define TB_TOP
Definition: commctrl.h:2051
static VOID InitPropSheetPage(PROPSHEETPAGE *psp, PSERVICEPROPSHEET dlgInfo, WORD idDlg, DLGPROC DlgProc)
Definition: propsheet.c:15
#define DWLP_USER
Definition: winuser.h:866
struct _SPEED_DATA * PSPEED_DATA
static BOOL CALLBACK PropSheetAddPage(HPROPSHEETPAGE hpage, LPARAM lParam)
Definition: advmon.c:13
INT nKeyboardDelay
Definition: keyboard.c:32
static HDC hDC
Definition: 3dtext.c:33
HWND WINAPI GetParent(_In_ HWND)
#define SPIF_UPDATEINIFILE
Definition: winuser.h:1553
#define TEXT(s)
Definition: k32.h:26
#define PSCB_INITIALIZED
Definition: prsht.h:75
#define ID_BLINK_TIMER
Definition: keyboard.c:28
static DWORD
Definition: keyboard.c:34
HICON hIcon
Definition: msconfig.c:44
#define PSN_RESET
Definition: prsht.h:118
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_SLIDER_REPEAT_DELAY
Definition: resource.h:98
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
#define WM_HSCROLL
Definition: winuser.h:1725
#define SPIF_SENDCHANGE
Definition: winuser.h:1554
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
BOOL WINAPI SetCaretBlinkTime(_In_ UINT)
#define PropertySheet
Definition: prsht.h:382
#define HIWORD(l)
Definition: typedefs.h:246
HICON WINAPI LoadIconW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2044
BOOL WINAPI GetWindowRect(_In_ HWND, _Out_ LPRECT)
#define COLOR_BTNTEXT
Definition: winuser.h:923
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDC_SLIDER_REPEAT_RATE
Definition: resource.h:100
HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
Definition: shellord.c:1607
BOOL WINAPI ScreenToClient(_In_ HWND, _Inout_ LPPOINT)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define HeapFree(x, y, z)
Definition: compat.h:394
#define LoadString
Definition: winuser.h:5720
INT nOrigKeyboardDelay
Definition: keyboard.c:33
#define WM_NOTIFY
Definition: richedit.h:61
#define APIENTRY
Definition: api.h:79
static int CALLBACK PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
Definition: keyboard.c:286
#define ICON_BIG
Definition: tnclass.cpp:51
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
static INT_PTR CALLBACK KeybHardwareProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
Definition: keyboard.c:260