Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenkeyboard.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS 00003 * Copyright (C) 2004, 2007 ReactOS Team 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 */ 00019 /* $Id: keyboard.c 54535 2011-11-29 14:55:58Z dgorbachev $ 00020 * 00021 * PROJECT: ReactOS Main Control Panel 00022 * FILE: dll/cpl/main/keyboard.c 00023 * PURPOSE: Keyboard Control Panel 00024 * PROGRAMMER: Eric Kohl 00025 */ 00026 00027 #include "main.h" 00028 00029 #define ID_BLINK_TIMER 345 00030 00031 typedef struct _SPEED_DATA 00032 { 00033 INT nKeyboardDelay; 00034 INT nOrigKeyboardDelay; 00035 DWORD dwKeyboardSpeed; 00036 DWORD dwOrigKeyboardSpeed; 00037 UINT uCaretBlinkTime; 00038 UINT uOrigCaretBlinkTime; 00039 BOOL fShowCursor; 00040 RECT rcCursor; 00041 } SPEED_DATA, *PSPEED_DATA; 00042 00043 /* Property page dialog callback */ 00044 static INT_PTR CALLBACK 00045 KeyboardSpeedProc(IN HWND hwndDlg, 00046 IN UINT uMsg, 00047 IN WPARAM wParam, 00048 IN LPARAM lParam) 00049 { 00050 PSPEED_DATA pSpeedData; 00051 00052 pSpeedData = (PSPEED_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 00053 00054 switch (uMsg) 00055 { 00056 case WM_INITDIALOG: 00057 pSpeedData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SPEED_DATA)); 00058 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pSpeedData); 00059 00060 /* Get current keyboard delay */ 00061 if (!SystemParametersInfo(SPI_GETKEYBOARDDELAY, 00062 sizeof(INT), 00063 &pSpeedData->nKeyboardDelay, 00064 0)) 00065 { 00066 pSpeedData->nKeyboardDelay = 2; 00067 } 00068 00069 pSpeedData->nOrigKeyboardDelay = pSpeedData->nKeyboardDelay; 00070 00071 /* Get current keyboard delay */ 00072 if (!SystemParametersInfo(SPI_GETKEYBOARDSPEED, 00073 sizeof(DWORD), 00074 &pSpeedData->dwKeyboardSpeed, 00075 0)) 00076 { 00077 pSpeedData->dwKeyboardSpeed = 31; 00078 } 00079 00080 pSpeedData->dwOrigKeyboardSpeed = pSpeedData->dwKeyboardSpeed; 00081 00082 pSpeedData->fShowCursor = TRUE; 00083 GetWindowRect(GetDlgItem(hwndDlg, IDC_TEXT_CURSOR_BLINK), &pSpeedData->rcCursor); 00084 ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.left); 00085 ScreenToClient(hwndDlg, (LPPOINT)&pSpeedData->rcCursor.right); 00086 00087 /* Get the caret blink time and save its original value */ 00088 pSpeedData->uOrigCaretBlinkTime = GetCaretBlinkTime(); 00089 pSpeedData->uCaretBlinkTime = pSpeedData->uOrigCaretBlinkTime; 00090 00091 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 3)); 00092 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(3 - pSpeedData->nKeyboardDelay)); 00093 00094 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 31)); 00095 SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)pSpeedData->dwKeyboardSpeed); 00096 00097 SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 10)); 00098 SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(12 - (pSpeedData->uCaretBlinkTime / 100))); 00099 00100 /* Start the blink timer */ 00101 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL); 00102 break; 00103 00104 case WM_HSCROLL: 00105 if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_REPEAT_DELAY)) 00106 { 00107 switch (LOWORD(wParam)) 00108 { 00109 case TB_LINEUP: 00110 case TB_LINEDOWN: 00111 case TB_PAGEUP: 00112 case TB_PAGEDOWN: 00113 case TB_TOP: 00114 case TB_BOTTOM: 00115 case TB_ENDTRACK: 00116 pSpeedData->nKeyboardDelay = 3 - (INT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_DELAY, TBM_GETPOS, 0, 0); 00117 SystemParametersInfo(SPI_SETKEYBOARDDELAY, 00118 pSpeedData->nKeyboardDelay, 00119 0, 00120 0); 00121 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00122 break; 00123 00124 case TB_THUMBTRACK: 00125 pSpeedData->nKeyboardDelay = 3 - (INT)HIWORD(wParam); 00126 SystemParametersInfo(SPI_SETKEYBOARDDELAY, 00127 pSpeedData->nKeyboardDelay, 00128 0, 00129 0); 00130 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00131 break; 00132 } 00133 } 00134 else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_REPEAT_RATE)) 00135 { 00136 switch (LOWORD(wParam)) 00137 { 00138 case TB_LINEUP: 00139 case TB_LINEDOWN: 00140 case TB_PAGEUP: 00141 case TB_PAGEDOWN: 00142 case TB_TOP: 00143 case TB_BOTTOM: 00144 case TB_ENDTRACK: 00145 pSpeedData->dwKeyboardSpeed = (DWORD)SendDlgItemMessage(hwndDlg, IDC_SLIDER_REPEAT_RATE, TBM_GETPOS, 0, 0); 00146 SystemParametersInfo(SPI_SETKEYBOARDSPEED, 00147 pSpeedData->dwKeyboardSpeed, 00148 0, 00149 0); 00150 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00151 break; 00152 00153 case TB_THUMBTRACK: 00154 pSpeedData->dwKeyboardSpeed = (DWORD)HIWORD(wParam); 00155 SystemParametersInfo(SPI_SETKEYBOARDSPEED, 00156 pSpeedData->dwKeyboardSpeed, 00157 0, 00158 0); 00159 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00160 break; 00161 } 00162 } 00163 else if ((HWND)lParam == GetDlgItem(hwndDlg, IDC_SLIDER_CURSOR_BLINK)) 00164 { 00165 switch (LOWORD(wParam)) 00166 { 00167 case TB_LINEUP: 00168 case TB_LINEDOWN: 00169 case TB_PAGEUP: 00170 case TB_PAGEDOWN: 00171 case TB_TOP: 00172 case TB_BOTTOM: 00173 case TB_ENDTRACK: 00174 pSpeedData->uCaretBlinkTime = (12 - (UINT)SendDlgItemMessage(hwndDlg, IDC_SLIDER_CURSOR_BLINK, TBM_GETPOS, 0, 0)) * 100; 00175 KillTimer(hwndDlg, ID_BLINK_TIMER); 00176 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL); 00177 SetCaretBlinkTime(pSpeedData->uCaretBlinkTime); 00178 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00179 break; 00180 00181 case TB_THUMBTRACK: 00182 pSpeedData->uCaretBlinkTime = (12 - (UINT)HIWORD(wParam)) * 100; 00183 KillTimer(hwndDlg, ID_BLINK_TIMER); 00184 SetTimer(hwndDlg, ID_BLINK_TIMER, pSpeedData->uCaretBlinkTime, NULL); 00185 SetCaretBlinkTime(pSpeedData->uCaretBlinkTime); 00186 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 00187 break; 00188 } 00189 } 00190 break; 00191 00192 case WM_TIMER: 00193 if (wParam == ID_BLINK_TIMER) 00194 { 00195 if (pSpeedData->fShowCursor) 00196 { 00197 HDC hDC = GetDC(hwndDlg); 00198 HBRUSH hBrush = GetSysColorBrush(COLOR_BTNTEXT); 00199 FillRect(hDC, &pSpeedData->rcCursor, hBrush); 00200 DeleteObject(hBrush); 00201 ReleaseDC(hwndDlg, hDC); 00202 } 00203 else 00204 { 00205 InvalidateRect(hwndDlg, &pSpeedData->rcCursor, TRUE); 00206 } 00207 00208 pSpeedData->fShowCursor = !pSpeedData->fShowCursor; 00209 } 00210 break; 00211 00212 case WM_NOTIFY: 00213 { 00214 LPNMHDR lpnm = (LPNMHDR)lParam; 00215 00216 switch(lpnm->code) 00217 { 00218 case PSN_APPLY: 00219 /* Set the new keyboard settings */ 00220 SystemParametersInfo(SPI_SETKEYBOARDDELAY, 00221 pSpeedData->nKeyboardDelay, 00222 0, 00223 0); 00224 SystemParametersInfo(SPI_SETKEYBOARDSPEED, 00225 pSpeedData->dwKeyboardSpeed, 00226 0, 00227 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); 00228 return TRUE; 00229 00230 case PSN_RESET: 00231 /* Restore the original settings */ 00232 SetCaretBlinkTime(pSpeedData->uOrigCaretBlinkTime); 00233 SystemParametersInfo(SPI_SETKEYBOARDDELAY, 00234 pSpeedData->nOrigKeyboardDelay, 00235 0, 00236 0); 00237 SystemParametersInfo(SPI_SETKEYBOARDSPEED, 00238 pSpeedData->dwOrigKeyboardSpeed, 00239 0, 00240 0); 00241 break; 00242 00243 default: 00244 break; 00245 } 00246 } 00247 break; 00248 00249 case WM_DESTROY: 00250 KillTimer(hwndDlg, ID_BLINK_TIMER); 00251 HeapFree(GetProcessHeap(), 0, pSpeedData); 00252 break; 00253 } 00254 00255 return FALSE; 00256 } 00257 00258 00259 /* Property page dialog callback */ 00260 static INT_PTR CALLBACK 00261 KeybHardwareProc(IN HWND hwndDlg, 00262 IN UINT uMsg, 00263 IN WPARAM wParam, 00264 IN LPARAM lParam) 00265 { 00266 GUID Guids[1]; 00267 Guids[0] = GUID_DEVCLASS_KEYBOARD; 00268 00269 UNREFERENCED_PARAMETER(lParam); 00270 UNREFERENCED_PARAMETER(wParam); 00271 00272 switch(uMsg) 00273 { 00274 case WM_INITDIALOG: 00275 /* Create the hardware page */ 00276 DeviceCreateHardwarePageEx(hwndDlg, 00277 Guids, 00278 sizeof(Guids) / sizeof(Guids[0]), 00279 HWPD_STANDARDLIST); 00280 break; 00281 } 00282 00283 return FALSE; 00284 } 00285 00286 00287 LONG APIENTRY 00288 KeyboardApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam) 00289 { 00290 HPROPSHEETPAGE hpsp[MAX_CPL_PAGES]; 00291 PROPSHEETHEADER psh; 00292 HPSXA hpsxa; 00293 TCHAR szCaption[256]; 00294 LONG ret; 00295 00296 UNREFERENCED_PARAMETER(lParam); 00297 UNREFERENCED_PARAMETER(wParam); 00298 UNREFERENCED_PARAMETER(uMsg); 00299 UNREFERENCED_PARAMETER(hwnd); 00300 00301 LoadString(hApplet, IDS_CPLNAME_2, szCaption, sizeof(szCaption) / sizeof(TCHAR)); 00302 00303 ZeroMemory(&psh, sizeof(PROPSHEETHEADER)); 00304 psh.dwSize = sizeof(PROPSHEETHEADER); 00305 psh.dwFlags = PSH_PROPTITLE; 00306 psh.hwndParent = hwnd; 00307 psh.hInstance = hApplet; 00308 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON_2)); 00309 psh.pszCaption = szCaption; 00310 psh.nStartPage = 0; 00311 psh.phpage = hpsp; 00312 00313 /* Load additional pages provided by shell extensions */ 00314 hpsxa = SHCreatePropSheetExtArray(HKEY_LOCAL_MACHINE, REGSTR_PATH_CONTROLSFOLDER TEXT("\\Keyboard"), MAX_CPL_PAGES - psh.nPages); 00315 00316 /* NOTE: The speed page (CPLPAGE_KEYBOARD_SPEED) cannot be replaced by 00317 shell extensions since Win2k! */ 00318 InitPropSheetPage(&psh, IDD_KEYBSPEED, KeyboardSpeedProc); 00319 InitPropSheetPage(&psh, IDD_HARDWARE, KeybHardwareProc); 00320 00321 if (hpsxa != NULL) 00322 SHAddFromPropSheetExtArray(hpsxa, PropSheetAddPage, (LPARAM)&psh); 00323 00324 ret = (LONG)(PropertySheet(&psh) != -1); 00325 00326 if (hpsxa != NULL) 00327 SHDestroyPropSheetExtArray(hpsxa); 00328 00329 return ret; 00330 } 00331 00332 /* EOF */ Generated on Sat May 26 2012 04:17:46 for ReactOS by
1.7.6.1
|