1 /* 2 * PROJECT: ReactOS Accessibility Control Panel 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/cpl/access/general.c 5 * PURPOSE: General accessibility settings 6 * COPYRIGHT: Copyright 2004 Johannes Anderwald (johannes.anderwald@reactos.org) 7 * Copyright 2007 Eric Kohl 8 */ 9 10 #include "access.h" 11 12 #define BAUDTICKS 6 13 static UINT nBaudArray[BAUDTICKS] = {300, 1200, 2400, 4800, 9600, 19200}; 14 15 #define FIVE_MINS_IN_MS (5 * 60 * 1000) 16 17 INT_PTR CALLBACK 18 SerialKeysDlgProc(HWND hwndDlg, 19 UINT uMsg, 20 WPARAM wParam, 21 LPARAM lParam) 22 { 23 PGLOBAL_DATA pGlobalData; 24 INT i, n; 25 26 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 27 28 switch (uMsg) 29 { 30 case WM_INITDIALOG: 31 pGlobalData = (PGLOBAL_DATA)lParam; 32 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData); 33 34 /* Add the COM-Ports 1 - 4 to the list */ 35 for (i = 0; i < 4; i++) 36 { 37 TCHAR szBuffer[256]; 38 39 _stprintf(szBuffer, _T("COM%d"), i + 1); 40 SendDlgItemMessage(hwndDlg, IDC_SERIAL_PORT_COMBO, CB_ADDSTRING, 0, (LPARAM)szBuffer); 41 } 42 43 /* Determine the current port */ 44 if (pGlobalData->serialKeys.lpszActivePort && pGlobalData->serialKeys.lpszActivePort[0]) 45 { 46 i = pGlobalData->serialKeys.lpszActivePort[3] - '1'; 47 if (i < 0 || i > 3) 48 i = 0; 49 } 50 else 51 { 52 /* Make COM1 the default port */ 53 i = 0; 54 _tcscpy(pGlobalData->serialKeys.lpszActivePort, _T("COM1")); 55 } 56 57 /* Set the current port */ 58 SendDlgItemMessage(hwndDlg, IDC_SERIAL_PORT_COMBO, CB_SETCURSEL, i, 0); 59 60 /* Determine the current baud rate */ 61 n = 0; 62 for (i = 0; i < BAUDTICKS; i++) 63 { 64 TCHAR szBuffer[256]; 65 66 _stprintf(szBuffer, _T("%d Baud"), nBaudArray[i]); 67 SendDlgItemMessage(hwndDlg, IDC_SERIAL_BAUD_COMBO, CB_ADDSTRING, 0, (LPARAM)szBuffer); 68 69 if (pGlobalData->serialKeys.iBaudRate == nBaudArray[i]) 70 n = i; 71 } 72 73 /* Set the current baud rate */ 74 SendDlgItemMessage(hwndDlg, IDC_SERIAL_BAUD_COMBO, CB_SETCURSEL, n, 0); 75 break; 76 77 case WM_COMMAND: 78 switch (LOWORD(wParam)) 79 { 80 case IDOK: 81 i = SendDlgItemMessage(hwndDlg, IDC_SERIAL_PORT_COMBO, CB_GETCURSEL, 0, 0) + 1; 82 _stprintf(pGlobalData->serialKeys.lpszActivePort, _T("COM%d"), i); 83 84 i = SendDlgItemMessage(hwndDlg, IDC_SERIAL_BAUD_COMBO, CB_GETCURSEL, 0, 0); 85 pGlobalData->serialKeys.iBaudRate = nBaudArray[i]; 86 87 EndDialog(hwndDlg, TRUE); 88 break; 89 90 case IDCANCEL: 91 EndDialog(hwndDlg, FALSE); 92 break; 93 94 default: 95 break; 96 } 97 break; 98 } 99 100 return FALSE; 101 } 102 103 104 static VOID 105 FillResetComboBox(HWND hwnd) 106 { 107 TCHAR szBuffer[32]; 108 TCHAR szMinutes[20]; 109 INT i; 110 111 if (LoadString(hApplet, IDS_MINUTES, szMinutes, 20) == 0) 112 lstrcpy(szMinutes, L"Minutes"); 113 114 for (i = 0; i < 6; i++) 115 { 116 _stprintf(szBuffer, _T("%u %s"), (i + 1) * 5, szMinutes); 117 SendMessage(hwnd, 118 CB_ADDSTRING, 119 0, 120 (LPARAM)szBuffer); 121 } 122 } 123 124 125 static VOID 126 WriteGlobalData(PGLOBAL_DATA pGlobalData) 127 { 128 DWORD dwDisposition; 129 HKEY hKey; 130 LONG lError; 131 132 SystemParametersInfo(SPI_SETACCESSTIMEOUT, 133 sizeof(ACCESSTIMEOUT), 134 &pGlobalData->accessTimeout, 135 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE /*0*/); 136 137 SystemParametersInfo(SPI_SETSERIALKEYS, 138 sizeof(SERIALKEYS), 139 &pGlobalData->serialKeys, 140 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE /*0*/); 141 142 lError = RegCreateKeyEx(HKEY_CURRENT_USER, 143 _T("Control Panel\\Accessibility"), 144 0, 145 NULL, 146 REG_OPTION_NON_VOLATILE, 147 KEY_SET_VALUE, 148 NULL, 149 &hKey, 150 &dwDisposition); 151 if (lError != ERROR_SUCCESS) 152 return; 153 154 RegSetValueEx(hKey, 155 _T("Warning Sounds"), 156 0, 157 REG_DWORD, 158 (LPBYTE)&pGlobalData->bWarningSounds, 159 sizeof(BOOL)); 160 161 RegSetValueEx(hKey, 162 _T("Sound On Activation"), 163 0, 164 REG_DWORD, 165 (LPBYTE)&pGlobalData->bSoundOnActivation, 166 sizeof(BOOL)); 167 168 RegCloseKey(hKey); 169 } 170 171 172 /* Property page dialog callback */ 173 INT_PTR CALLBACK 174 GeneralPageProc(HWND hwndDlg, 175 UINT uMsg, 176 WPARAM wParam, 177 LPARAM lParam) 178 { 179 PGLOBAL_DATA pGlobalData; 180 LPPSHNOTIFY lppsn; 181 INT iCurSel; 182 183 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 184 185 switch (uMsg) 186 { 187 case WM_INITDIALOG: 188 pGlobalData = (PGLOBAL_DATA)((LPPROPSHEETPAGE)lParam)->lParam; 189 if (pGlobalData == NULL) 190 return FALSE; 191 192 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData); 193 194 /* Set access timeout info */ 195 CheckDlgButton(hwndDlg, 196 IDC_RESET_BOX, 197 pGlobalData->accessTimeout.dwFlags & ATF_TIMEOUTON ? BST_CHECKED : BST_UNCHECKED); 198 FillResetComboBox(GetDlgItem(hwndDlg, IDC_RESET_COMBO)); 199 pGlobalData->accessTimeout.iTimeOutMSec = max(FIVE_MINS_IN_MS, pGlobalData->accessTimeout.iTimeOutMSec); 200 iCurSel = (pGlobalData->accessTimeout.iTimeOutMSec / FIVE_MINS_IN_MS) - 1; 201 SendDlgItemMessage(hwndDlg, IDC_RESET_COMBO, CB_SETCURSEL, iCurSel, 0); 202 EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_COMBO), 203 pGlobalData->accessTimeout.dwFlags & ATF_TIMEOUTON ? TRUE : FALSE); 204 205 CheckDlgButton(hwndDlg, 206 IDC_NOTIFICATION_MESSAGE, 207 pGlobalData->bWarningSounds ? BST_CHECKED : BST_UNCHECKED); 208 209 CheckDlgButton(hwndDlg, 210 IDC_NOTIFICATION_SOUND, 211 pGlobalData->bSoundOnActivation ? BST_CHECKED : BST_UNCHECKED); 212 213 /* Set serial keys info */ 214 CheckDlgButton(hwndDlg, 215 IDC_SERIAL_BOX, 216 pGlobalData->serialKeys.dwFlags & SERKF_SERIALKEYSON ? BST_CHECKED : BST_UNCHECKED); 217 EnableWindow(GetDlgItem(hwndDlg, IDC_SERIAL_BOX), 218 pGlobalData->serialKeys.dwFlags & SERKF_AVAILABLE ? TRUE : FALSE); 219 EnableWindow(GetDlgItem(hwndDlg, IDC_SERIAL_BUTTON), 220 pGlobalData->serialKeys.dwFlags & SERKF_AVAILABLE ? TRUE : FALSE); 221 222 return TRUE; 223 224 case WM_COMMAND: 225 switch (LOWORD(wParam)) 226 { 227 case IDC_RESET_BOX: 228 pGlobalData->accessTimeout.dwFlags ^= ATF_TIMEOUTON; 229 EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_COMBO), 230 pGlobalData->accessTimeout.dwFlags & ATF_TIMEOUTON ? TRUE : FALSE); 231 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 232 break; 233 234 case IDC_RESET_COMBO: 235 if (HIWORD(wParam) == CBN_CLOSEUP) 236 { 237 INT nSel; 238 nSel = SendDlgItemMessage(hwndDlg, IDC_RESET_COMBO, CB_GETCURSEL, 0, 0); 239 pGlobalData->accessTimeout.iTimeOutMSec = (DWORD)((nSel + 1) * FIVE_MINS_IN_MS); 240 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 241 } 242 break; 243 244 case IDC_NOTIFICATION_MESSAGE: 245 pGlobalData->bWarningSounds = !pGlobalData->bWarningSounds; 246 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 247 break; 248 249 case IDC_NOTIFICATION_SOUND: 250 pGlobalData->bSoundOnActivation = !pGlobalData->bSoundOnActivation; 251 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 252 break; 253 254 case IDC_SERIAL_BOX: 255 pGlobalData->serialKeys.dwFlags ^= SERKF_SERIALKEYSON; 256 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 257 break; 258 259 case IDC_SERIAL_BUTTON: 260 if (DialogBoxParam(hApplet, 261 MAKEINTRESOURCE(IDD_SERIALKEYSOPTIONS), 262 hwndDlg, 263 SerialKeysDlgProc, 264 (LPARAM)pGlobalData)) 265 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 266 break; 267 268 case IDC_ADMIN_LOGON_BOX: 269 break; 270 271 case IDC_ADMIN_USERS_BOX: 272 break; 273 274 default: 275 break; 276 } 277 break; 278 279 case WM_NOTIFY: 280 lppsn = (LPPSHNOTIFY)lParam; 281 if (lppsn->hdr.code == PSN_APPLY) 282 { 283 WriteGlobalData(pGlobalData); 284 return TRUE; 285 } 286 break; 287 } 288 289 return FALSE; 290 } 291