xref: /reactos/dll/cpl/access/access.c (revision ccef43f3)
1 /*
2  * PROJECT:         ReactOS Accessibility Control Panel
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            dll/cpl/access/access.c
5  * PURPOSE:         Main control panel code
6  * COPYRIGHT:       Copyright 2004 Johannes Anderwald (johannes.anderwald@reactos.org)
7  *                  Copyright 2007 Eric Kohl
8  */
9 
10 #include "access.h"
11 
12 #include <cpl.h>
13 
14 #define NUM_APPLETS	(1)
15 
16 static LONG CALLBACK SystemApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
17 HINSTANCE hApplet = 0;
18 
19 /* Applets */
20 APPLET Applets[NUM_APPLETS] =
21 {
22     {IDI_CPLACCESS, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet}
23 };
24 
25 
26 static BOOL
27 ReadSettings(PGLOBAL_DATA pGlobalData)
28 {
29     DWORD dwDisposition;
30     DWORD dwLength;
31     HKEY hKey;
32     LONG lError;
33 
34     /* Get sticky keys information */
35     pGlobalData->stickyKeys.cbSize = sizeof(STICKYKEYS);
36     if (!SystemParametersInfo(SPI_GETSTICKYKEYS,
37                               sizeof(STICKYKEYS),
38                               &pGlobalData->stickyKeys,
39                               0))
40         return FALSE;
41 
42     /* Get filter keys information */
43     pGlobalData->filterKeys.cbSize = sizeof(FILTERKEYS);
44     if (!SystemParametersInfo(SPI_GETFILTERKEYS,
45                               sizeof(FILTERKEYS),
46                               &pGlobalData->filterKeys,
47                               0))
48         return FALSE;
49 
50     /* Get toggle keys information */
51     pGlobalData->toggleKeys.cbSize = sizeof(TOGGLEKEYS);
52     if (!SystemParametersInfo(SPI_GETTOGGLEKEYS,
53                               sizeof(TOGGLEKEYS),
54                               &pGlobalData->toggleKeys,
55                               0))
56         return FALSE;
57 
58     /* Get keyboard preference information */
59     if (!SystemParametersInfo(SPI_GETKEYBOARDPREF,
60                               0,
61                               &pGlobalData->bKeyboardPref,
62                               0))
63         return FALSE;
64 
65     /* Get high contrast information */
66     pGlobalData->highContrast.cbSize = sizeof(HIGHCONTRAST);
67     SystemParametersInfo(SPI_GETHIGHCONTRAST,
68                          sizeof(HIGHCONTRAST),
69                          &pGlobalData->highContrast,
70                          0);
71 
72     SystemParametersInfo(SPI_GETCARETWIDTH,
73                          0,
74                          &pGlobalData->uCaretWidth,
75                          0);
76 
77     pGlobalData->uCaretBlinkTime = GetCaretBlinkTime();
78 
79     /* Get sound settings */
80     pGlobalData->ssSoundSentry.cbSize = sizeof(SOUNDSENTRY);
81     SystemParametersInfo(SPI_GETSOUNDSENTRY,
82                          sizeof(SOUNDSENTRY),
83                          &pGlobalData->ssSoundSentry,
84                          0);
85 
86     SystemParametersInfo(SPI_GETSHOWSOUNDS,
87                          0,
88                          &pGlobalData->bShowSounds,
89                          0);
90 
91     /* Get mouse keys information */
92     pGlobalData->mouseKeys.cbSize = sizeof(MOUSEKEYS);
93     SystemParametersInfo(SPI_GETMOUSEKEYS,
94                          sizeof(MOUSEKEYS),
95                          &pGlobalData->mouseKeys,
96                          0);
97 
98     /* Get access timeout information */
99     pGlobalData->accessTimeout.cbSize = sizeof(ACCESSTIMEOUT);
100     SystemParametersInfo(SPI_GETACCESSTIMEOUT,
101                          sizeof(ACCESSTIMEOUT),
102                          &pGlobalData->accessTimeout,
103                          0);
104 
105     /* Get serial keys information */
106     pGlobalData->serialKeys.cbSize = sizeof(SERIALKEYS);
107     pGlobalData->serialKeys.lpszActivePort = pGlobalData->szActivePort;
108     pGlobalData->serialKeys.lpszPort = pGlobalData->szPort;
109     SystemParametersInfo(SPI_GETSERIALKEYS,
110                          sizeof(SERIALKEYS),
111                          &pGlobalData->serialKeys,
112                          0);
113 
114     pGlobalData->bWarningSounds = TRUE;
115     pGlobalData->bSoundOnActivation = TRUE;
116 
117     lError = RegCreateKeyEx(HKEY_CURRENT_USER,
118                             _T("Control Panel\\Accessibility"),
119                             0,
120                             NULL,
121                             REG_OPTION_NON_VOLATILE,
122                             KEY_EXECUTE | KEY_QUERY_VALUE,
123                             NULL,
124                             &hKey,
125                             &dwDisposition);
126     if (lError != ERROR_SUCCESS)
127         return TRUE;
128 
129     dwLength = sizeof(BOOL);
130     lError = RegQueryValueEx(hKey,
131                              _T("Warning Sounds"),
132                              NULL,
133                              NULL,
134                              (LPBYTE)&pGlobalData->bWarningSounds,
135                              &dwLength);
136     if (lError != ERROR_SUCCESS)
137         pGlobalData->bWarningSounds = TRUE;
138 
139     dwLength = sizeof(BOOL);
140     lError = RegQueryValueEx(hKey,
141                              _T("Sound On Activation"),
142                              NULL,
143                              NULL,
144                              (LPBYTE)&pGlobalData->bSoundOnActivation,
145                              &dwLength);
146     if (lError != ERROR_SUCCESS)
147         pGlobalData->bSoundOnActivation = TRUE;
148 
149     RegCloseKey(hKey);
150 
151     return TRUE;
152 }
153 
154 
155 static VOID
156 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, PGLOBAL_DATA pGlobalData)
157 {
158     ZeroMemory(psp, sizeof(PROPSHEETPAGE));
159     psp->dwSize = sizeof(PROPSHEETPAGE);
160     psp->dwFlags = PSP_DEFAULT;
161     psp->hInstance = hApplet;
162     psp->pszTemplate = MAKEINTRESOURCE(idDlg);
163     psp->pfnDlgProc = DlgProc;
164     psp->lParam = (LPARAM)pGlobalData;
165 }
166 
167 static int CALLBACK
168 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
169 {
170     // NOTE: This callback is needed to set large icon correctly.
171     HICON hIcon;
172     switch (uMsg)
173     {
174         case PSCB_INITIALIZED:
175         {
176             hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_CPLACCESS));
177             SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
178             break;
179         }
180     }
181     return 0;
182 }
183 
184 /* First Applet */
185 
186 LONG CALLBACK
187 SystemApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
188 {
189     PGLOBAL_DATA pGlobalData;
190     PROPSHEETPAGE psp[5];
191     PROPSHEETHEADER psh;
192     INT nPage = 0;
193     INT ret;
194 
195     if (uMsg == CPL_STARTWPARMSW && lParam != 0)
196         nPage = _wtoi((PWSTR)lParam);
197 
198     pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA));
199     if (pGlobalData == NULL)
200         return 0;
201 
202     if (!ReadSettings(pGlobalData))
203     {
204         HeapFree(GetProcessHeap(), 0, pGlobalData);
205         return 0;
206     }
207 
208     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
209     psh.dwSize = sizeof(PROPSHEETHEADER);
210     psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
211     psh.hwndParent = hwnd;
212     psh.hInstance = hApplet;
213     psh.pszIcon = MAKEINTRESOURCEW(IDI_CPLACCESS);
214     psh.pszCaption = MAKEINTRESOURCEW(IDS_CPLSYSTEMNAME);
215     psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
216     psh.nStartPage = 0;
217     psh.ppsp = psp;
218     psh.pfnCallback = PropSheetProc;
219 
220     InitPropSheetPage(&psp[0], IDD_PROPPAGEKEYBOARD, KeyboardPageProc, pGlobalData);
221     InitPropSheetPage(&psp[1], IDD_PROPPAGESOUND, SoundPageProc, pGlobalData);
222     InitPropSheetPage(&psp[2], IDD_PROPPAGEDISPLAY, DisplayPageProc, pGlobalData);
223     InitPropSheetPage(&psp[3], IDD_PROPPAGEMOUSE, MousePageProc, pGlobalData);
224     InitPropSheetPage(&psp[4], IDD_PROPPAGEGENERAL, GeneralPageProc, pGlobalData);
225 
226     if (nPage != 0 && nPage <= psh.nPages)
227         psh.nStartPage = nPage;
228 
229     ret = PropertySheet(&psh);
230 
231     HeapFree(GetProcessHeap(), 0, pGlobalData);
232 
233     return (LONG)(ret != -1);
234 }
235 
236 /* Control Panel Callback */
237 LONG CALLBACK
238 CPlApplet(HWND hwndCPl,
239           UINT uMsg,
240           LPARAM lParam1,
241           LPARAM lParam2)
242 {
243     UINT i = (UINT)lParam1;
244 
245     switch (uMsg)
246     {
247         case CPL_INIT:
248             return TRUE;
249 
250         case CPL_GETCOUNT:
251             return NUM_APPLETS;
252 
253         case CPL_INQUIRE:
254             if (i < NUM_APPLETS)
255             {
256                 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
257                 CPlInfo->lData = 0;
258                 CPlInfo->idIcon = Applets[i].idIcon;
259                 CPlInfo->idName = Applets[i].idName;
260                 CPlInfo->idInfo = Applets[i].idDescription;
261             }
262             else
263             {
264                 return TRUE;
265             }
266             break;
267 
268         case CPL_DBLCLK:
269             if (i < NUM_APPLETS)
270                 Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
271             else
272                 return TRUE;
273             break;
274 
275         case CPL_STARTWPARMSW:
276             if (i < NUM_APPLETS)
277                 return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
278             break;
279     }
280 
281     return FALSE;
282 }
283 
284 
285 BOOL WINAPI
286 DllMain(HINSTANCE hinstDLL,
287         DWORD dwReason,
288         LPVOID lpvReserved)
289 {
290     UNREFERENCED_PARAMETER(lpvReserved);
291 
292     switch (dwReason)
293     {
294         case DLL_PROCESS_ATTACH:
295         case DLL_THREAD_ATTACH:
296             hApplet = hinstDLL;
297             break;
298     }
299 
300   return TRUE;
301 }
302 
303