[DINPUT]
[reactos.git] / reactos / dll / cpl / access / access.c
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 LONG CALLBACK SystemApplet(VOID);
17 HINSTANCE hApplet = 0;
18 HWND hCPLWindow;
19
20 /* Applets */
21 APPLET Applets[NUM_APPLETS] =
22 {
23 {IDI_CPLACCESS, IDS_CPLSYSTEMNAME, IDS_CPLSYSTEMDESCRIPTION, SystemApplet}
24 };
25
26
27 static BOOL
28 ReadSettings(PGLOBAL_DATA pGlobalData)
29 {
30 DWORD dwDisposition;
31 DWORD dwLength;
32 HKEY hKey;
33 LONG lError;
34
35 /* Get sticky keys information */
36 pGlobalData->stickyKeys.cbSize = sizeof(STICKYKEYS);
37 if (!SystemParametersInfo(SPI_GETSTICKYKEYS,
38 sizeof(STICKYKEYS),
39 &pGlobalData->stickyKeys,
40 0))
41 return FALSE;
42
43 /* Get filter keys information */
44 pGlobalData->filterKeys.cbSize = sizeof(FILTERKEYS);
45 if (!SystemParametersInfo(SPI_GETFILTERKEYS,
46 sizeof(FILTERKEYS),
47 &pGlobalData->filterKeys,
48 0))
49 return FALSE;
50
51 /* Get toggle keys information */
52 pGlobalData->toggleKeys.cbSize = sizeof(TOGGLEKEYS);
53 if (!SystemParametersInfo(SPI_GETTOGGLEKEYS,
54 sizeof(TOGGLEKEYS),
55 &pGlobalData->toggleKeys,
56 0))
57 return FALSE;
58
59 /* Get keyboard preference information */
60 if (!SystemParametersInfo(SPI_GETKEYBOARDPREF,
61 0,
62 &pGlobalData->bKeyboardPref,
63 0))
64 return FALSE;
65
66 /* Get high contrast information */
67 pGlobalData->highContrast.cbSize = sizeof(HIGHCONTRAST);
68 SystemParametersInfo(SPI_GETHIGHCONTRAST,
69 sizeof(HIGHCONTRAST),
70 &pGlobalData->highContrast,
71 0);
72
73 SystemParametersInfo(SPI_GETCARETWIDTH,
74 0,
75 &pGlobalData->uCaretWidth,
76 0);
77
78 pGlobalData->uCaretBlinkTime = GetCaretBlinkTime();
79
80 /* Get sound settings */
81 pGlobalData->ssSoundSentry.cbSize = sizeof(SOUNDSENTRY);
82 SystemParametersInfo(SPI_GETSOUNDSENTRY,
83 sizeof(SOUNDSENTRY),
84 &pGlobalData->ssSoundSentry,
85 0);
86
87 SystemParametersInfo(SPI_GETSHOWSOUNDS,
88 0,
89 &pGlobalData->bShowSounds,
90 0);
91
92 /* Get mouse keys information */
93 pGlobalData->mouseKeys.cbSize = sizeof(MOUSEKEYS);
94 SystemParametersInfo(SPI_GETMOUSEKEYS,
95 sizeof(MOUSEKEYS),
96 &pGlobalData->mouseKeys,
97 0);
98
99 /* Get access timeout information */
100 pGlobalData->accessTimeout.cbSize = sizeof(ACCESSTIMEOUT);
101 SystemParametersInfo(SPI_GETACCESSTIMEOUT,
102 sizeof(ACCESSTIMEOUT),
103 &pGlobalData->accessTimeout,
104 0);
105
106 /* Get serial keys information */
107 pGlobalData->serialKeys.cbSize = sizeof(SERIALKEYS);
108 pGlobalData->serialKeys.lpszActivePort = pGlobalData->szActivePort;
109 pGlobalData->serialKeys.lpszPort = pGlobalData->szPort;
110 SystemParametersInfo(SPI_GETSERIALKEYS,
111 sizeof(SERIALKEYS),
112 &pGlobalData->serialKeys,
113 0);
114
115 pGlobalData->bWarningSounds = TRUE;
116 pGlobalData->bSoundOnActivation = TRUE;
117
118 lError = RegCreateKeyEx(HKEY_CURRENT_USER,
119 _T("Control Panel\\Accessibility"),
120 0,
121 NULL,
122 REG_OPTION_NON_VOLATILE,
123 KEY_EXECUTE | KEY_QUERY_VALUE,
124 NULL,
125 &hKey,
126 &dwDisposition);
127 if (lError != ERROR_SUCCESS)
128 return TRUE;
129
130 dwLength = sizeof(BOOL);
131 lError = RegQueryValueEx(hKey,
132 _T("Warning Sounds"),
133 NULL,
134 NULL,
135 (LPBYTE)&pGlobalData->bWarningSounds,
136 &dwLength);
137 if (lError != ERROR_SUCCESS)
138 pGlobalData->bWarningSounds = TRUE;
139
140 dwLength = sizeof(BOOL);
141 lError = RegQueryValueEx(hKey,
142 _T("Sound On Activation"),
143 NULL,
144 NULL,
145 (LPBYTE)&pGlobalData->bSoundOnActivation,
146 &dwLength);
147 if (lError != ERROR_SUCCESS)
148 pGlobalData->bSoundOnActivation = TRUE;
149
150 RegCloseKey(hKey);
151
152 return TRUE;
153 }
154
155
156 static VOID
157 InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, PGLOBAL_DATA pGlobalData)
158 {
159 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
160 psp->dwSize = sizeof(PROPSHEETPAGE);
161 psp->dwFlags = PSP_DEFAULT;
162 psp->hInstance = hApplet;
163 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
164 psp->pfnDlgProc = DlgProc;
165 psp->lParam = (LPARAM)pGlobalData;
166 }
167
168
169 /* First Applet */
170
171 LONG CALLBACK
172 SystemApplet(VOID)
173 {
174 PGLOBAL_DATA pGlobalData;
175 PROPSHEETPAGE psp[5];
176 PROPSHEETHEADER psh;
177 TCHAR Caption[1024];
178 INT ret;
179
180 LoadString(hApplet, IDS_CPLSYSTEMNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
181
182 pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA));
183 if (pGlobalData == NULL)
184 return 0;
185
186 if (!ReadSettings(pGlobalData))
187 return 0;
188
189 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
190 psh.dwSize = sizeof(PROPSHEETHEADER);
191 psh.dwFlags = PSH_PROPSHEETPAGE;
192 psh.hwndParent = hCPLWindow;
193 psh.hInstance = hApplet;
194 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLACCESS));
195 psh.pszCaption = Caption;
196 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
197 psh.nStartPage = 0;
198 psh.ppsp = psp;
199
200 InitPropSheetPage(&psp[0], IDD_PROPPAGEKEYBOARD, (DLGPROC)KeyboardPageProc, pGlobalData);
201 InitPropSheetPage(&psp[1], IDD_PROPPAGESOUND, (DLGPROC)SoundPageProc, pGlobalData);
202 InitPropSheetPage(&psp[2], IDD_PROPPAGEDISPLAY, (DLGPROC)DisplayPageProc, pGlobalData);
203 InitPropSheetPage(&psp[3], IDD_PROPPAGEMOUSE, (DLGPROC)MousePageProc, pGlobalData);
204 InitPropSheetPage(&psp[4], IDD_PROPPAGEGENERAL, (DLGPROC)GeneralPageProc, pGlobalData);
205
206 ret = PropertySheet(&psh);
207
208 HeapFree(GetProcessHeap(), 0, pGlobalData);
209
210 return (LONG)(ret != -1);
211 }
212
213 /* Control Panel Callback */
214 LONG CALLBACK
215 CPlApplet(HWND hwndCPl,
216 UINT uMsg,
217 LPARAM lParam1,
218 LPARAM lParam2)
219 {
220 INT i = (INT)lParam1;
221
222 switch (uMsg)
223 {
224 case CPL_INIT:
225 return TRUE;
226
227 case CPL_GETCOUNT:
228 return NUM_APPLETS;
229
230 case CPL_INQUIRE:
231 {
232 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
233 CPlInfo->lData = 0;
234 CPlInfo->idIcon = Applets[i].idIcon;
235 CPlInfo->idName = Applets[i].idName;
236 CPlInfo->idInfo = Applets[i].idDescription;
237 }
238 break;
239
240 case CPL_DBLCLK:
241 hCPLWindow = hwndCPl;
242 Applets[i].AppletProc();
243 break;
244 }
245
246 return FALSE;
247 }
248
249
250 BOOL WINAPI
251 DllMain(HINSTANCE hinstDLL,
252 DWORD dwReason,
253 LPVOID lpvReserved)
254 {
255 UNREFERENCED_PARAMETER(lpvReserved);
256
257 switch (dwReason)
258 {
259 case DLL_PROCESS_ATTACH:
260 case DLL_THREAD_ATTACH:
261 hApplet = hinstDLL;
262 break;
263 }
264
265 return TRUE;
266 }
267