[WINHTTP] Sync with Wine Staging 3.9. CORE-14656
[reactos.git] / 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 {
188 HeapFree(GetProcessHeap(), 0, pGlobalData);
189 return 0;
190 }
191
192 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
193 psh.dwSize = sizeof(PROPSHEETHEADER);
194 psh.dwFlags = PSH_PROPSHEETPAGE;
195 psh.hwndParent = hCPLWindow;
196 psh.hInstance = hApplet;
197 psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDI_CPLACCESS));
198 psh.pszCaption = Caption;
199 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
200 psh.nStartPage = 0;
201 psh.ppsp = psp;
202
203 InitPropSheetPage(&psp[0], IDD_PROPPAGEKEYBOARD, KeyboardPageProc, pGlobalData);
204 InitPropSheetPage(&psp[1], IDD_PROPPAGESOUND, SoundPageProc, pGlobalData);
205 InitPropSheetPage(&psp[2], IDD_PROPPAGEDISPLAY, DisplayPageProc, pGlobalData);
206 InitPropSheetPage(&psp[3], IDD_PROPPAGEMOUSE, MousePageProc, pGlobalData);
207 InitPropSheetPage(&psp[4], IDD_PROPPAGEGENERAL, GeneralPageProc, pGlobalData);
208
209 ret = PropertySheet(&psh);
210
211 HeapFree(GetProcessHeap(), 0, pGlobalData);
212
213 return (LONG)(ret != -1);
214 }
215
216 /* Control Panel Callback */
217 LONG CALLBACK
218 CPlApplet(HWND hwndCPl,
219 UINT uMsg,
220 LPARAM lParam1,
221 LPARAM lParam2)
222 {
223 INT i = (INT)lParam1;
224
225 switch (uMsg)
226 {
227 case CPL_INIT:
228 return TRUE;
229
230 case CPL_GETCOUNT:
231 return NUM_APPLETS;
232
233 case CPL_INQUIRE:
234 {
235 CPLINFO *CPlInfo = (CPLINFO*)lParam2;
236 CPlInfo->lData = 0;
237 CPlInfo->idIcon = Applets[i].idIcon;
238 CPlInfo->idName = Applets[i].idName;
239 CPlInfo->idInfo = Applets[i].idDescription;
240 }
241 break;
242
243 case CPL_DBLCLK:
244 hCPLWindow = hwndCPl;
245 Applets[i].AppletProc();
246 break;
247 }
248
249 return FALSE;
250 }
251
252
253 BOOL WINAPI
254 DllMain(HINSTANCE hinstDLL,
255 DWORD dwReason,
256 LPVOID lpvReserved)
257 {
258 UNREFERENCED_PARAMETER(lpvReserved);
259
260 switch (dwReason)
261 {
262 case DLL_PROCESS_ATTACH:
263 case DLL_THREAD_ATTACH:
264 hApplet = hinstDLL;
265 break;
266 }
267
268 return TRUE;
269 }
270