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