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