xref: /reactos/dll/cpl/access/access.c (revision 139a3d66)
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     TCHAR Caption[1024];
193     INT nPage = 0;
194     INT ret;
195 
196     if (uMsg == CPL_STARTWPARMSW && lParam != 0)
197         nPage = _wtoi((PWSTR)lParam);
198 
199     LoadString(hApplet, IDS_CPLSYSTEMNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
200 
201     pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA));
202     if (pGlobalData == NULL)
203         return 0;
204 
205     if (!ReadSettings(pGlobalData))
206     {
207         HeapFree(GetProcessHeap(), 0, pGlobalData);
208         return 0;
209     }
210 
211     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
212     psh.dwSize = sizeof(PROPSHEETHEADER);
213     psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_USECALLBACK;
214     psh.hwndParent = hwnd;
215     psh.hInstance = hApplet;
216     psh.pszIcon = MAKEINTRESOURCEW(IDI_CPLACCESS);
217     psh.pszCaption = Caption;
218     psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
219     psh.nStartPage = 0;
220     psh.ppsp = psp;
221     psh.pfnCallback = PropSheetProc;
222 
223     InitPropSheetPage(&psp[0], IDD_PROPPAGEKEYBOARD, KeyboardPageProc, pGlobalData);
224     InitPropSheetPage(&psp[1], IDD_PROPPAGESOUND, SoundPageProc, pGlobalData);
225     InitPropSheetPage(&psp[2], IDD_PROPPAGEDISPLAY, DisplayPageProc, pGlobalData);
226     InitPropSheetPage(&psp[3], IDD_PROPPAGEMOUSE, MousePageProc, pGlobalData);
227     InitPropSheetPage(&psp[4], IDD_PROPPAGEGENERAL, GeneralPageProc, pGlobalData);
228 
229     if (nPage != 0 && nPage <= psh.nPages)
230         psh.nStartPage = nPage;
231 
232     ret = PropertySheet(&psh);
233 
234     HeapFree(GetProcessHeap(), 0, pGlobalData);
235 
236     return (LONG)(ret != -1);
237 }
238 
239 /* Control Panel Callback */
240 LONG CALLBACK
241 CPlApplet(HWND hwndCPl,
242           UINT uMsg,
243           LPARAM lParam1,
244           LPARAM lParam2)
245 {
246     INT i = (INT)lParam1;
247 
248     switch (uMsg)
249     {
250         case CPL_INIT:
251             return TRUE;
252 
253         case CPL_GETCOUNT:
254             return NUM_APPLETS;
255 
256         case CPL_INQUIRE:
257             {
258                 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
259                 CPlInfo->lData = 0;
260                 CPlInfo->idIcon = Applets[i].idIcon;
261                 CPlInfo->idName = Applets[i].idName;
262                 CPlInfo->idInfo = Applets[i].idDescription;
263             }
264             break;
265 
266         case CPL_DBLCLK:
267             Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
268             break;
269 
270         case CPL_STARTWPARMSW:
271             return Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
272     }
273 
274     return FALSE;
275 }
276 
277 
278 BOOL WINAPI
279 DllMain(HINSTANCE hinstDLL,
280         DWORD dwReason,
281         LPVOID lpvReserved)
282 {
283     UNREFERENCED_PARAMETER(lpvReserved);
284 
285     switch (dwReason)
286     {
287         case DLL_PROCESS_ATTACH:
288         case DLL_THREAD_ATTACH:
289             hApplet = hinstDLL;
290             break;
291     }
292 
293   return TRUE;
294 }
295 
296