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 static int CALLBACK 169 PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam) 170 { 171 // NOTE: This callback is needed to set large icon correctly. 172 HICON hIcon; 173 switch (uMsg) 174 { 175 case PSCB_INITIALIZED: 176 { 177 hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_CPLACCESS)); 178 SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon); 179 break; 180 } 181 } 182 return 0; 183 } 184 185 /* First Applet */ 186 187 LONG CALLBACK 188 SystemApplet(VOID) 189 { 190 PGLOBAL_DATA pGlobalData; 191 PROPSHEETPAGE psp[5]; 192 PROPSHEETHEADER psh; 193 TCHAR Caption[1024]; 194 INT ret; 195 196 LoadString(hApplet, IDS_CPLSYSTEMNAME, Caption, sizeof(Caption) / sizeof(TCHAR)); 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 = hCPLWindow; 212 psh.hInstance = hApplet; 213 psh.pszIcon = MAKEINTRESOURCEW(IDI_CPLACCESS); 214 psh.pszCaption = Caption; 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 ret = PropertySheet(&psh); 227 228 HeapFree(GetProcessHeap(), 0, pGlobalData); 229 230 return (LONG)(ret != -1); 231 } 232 233 /* Control Panel Callback */ 234 LONG CALLBACK 235 CPlApplet(HWND hwndCPl, 236 UINT uMsg, 237 LPARAM lParam1, 238 LPARAM lParam2) 239 { 240 INT i = (INT)lParam1; 241 242 switch (uMsg) 243 { 244 case CPL_INIT: 245 return TRUE; 246 247 case CPL_GETCOUNT: 248 return NUM_APPLETS; 249 250 case CPL_INQUIRE: 251 { 252 CPLINFO *CPlInfo = (CPLINFO*)lParam2; 253 CPlInfo->lData = 0; 254 CPlInfo->idIcon = Applets[i].idIcon; 255 CPlInfo->idName = Applets[i].idName; 256 CPlInfo->idInfo = Applets[i].idDescription; 257 } 258 break; 259 260 case CPL_DBLCLK: 261 hCPLWindow = hwndCPl; 262 Applets[i].AppletProc(); 263 break; 264 } 265 266 return FALSE; 267 } 268 269 270 BOOL WINAPI 271 DllMain(HINSTANCE hinstDLL, 272 DWORD dwReason, 273 LPVOID lpvReserved) 274 { 275 UNREFERENCED_PARAMETER(lpvReserved); 276 277 switch (dwReason) 278 { 279 case DLL_PROCESS_ATTACH: 280 case DLL_THREAD_ATTACH: 281 hApplet = hinstDLL; 282 break; 283 } 284 285 return TRUE; 286 } 287 288