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