1 /* 2 * PROJECT: ReactOS Accessibility Control Panel 3 * LICENSE: GPL - See COPYING in the top level directory 4 * FILE: dll/cpl/access/display.c 5 * PURPOSE: Display-related accessibility settings 6 * COPYRIGHT: Copyright 2004 Johannes Anderwald (johannes.anderwald@reactos.org) 7 * Copyright 2007 Eric Kohl 8 */ 9 10 #include "access.h" 11 12 #include <wingdi.h> 13 14 #define ID_BLINK_TIMER 346 15 16 static VOID 17 FillColorSchemeComboBox(HWND hwnd) 18 { 19 TCHAR szValue[128]; 20 DWORD dwDisposition; 21 DWORD dwLength; 22 HKEY hKey; 23 LONG lError; 24 INT i; 25 26 lError = RegCreateKeyEx(HKEY_CURRENT_USER, 27 _T("Control Panel\\Appearance\\Schemes"), 28 0, 29 NULL, 30 REG_OPTION_NON_VOLATILE, 31 KEY_ENUMERATE_SUB_KEYS | KEY_EXECUTE | KEY_QUERY_VALUE, 32 NULL, 33 &hKey, 34 &dwDisposition); 35 if (lError != ERROR_SUCCESS) 36 return; 37 38 for (i = 0; ; i++) 39 { 40 dwLength = 128; 41 lError = RegEnumValue(hKey, 42 i, 43 szValue, 44 &dwLength, NULL, NULL, NULL, NULL); 45 if (lError == ERROR_NO_MORE_ITEMS) 46 break; 47 48 SendMessage(hwnd, 49 CB_ADDSTRING, 50 0, 51 (LPARAM)szValue); 52 } 53 54 RegCloseKey(hKey); 55 } 56 57 58 INT_PTR CALLBACK 59 HighContrastDlgProc(HWND hwndDlg, 60 UINT uMsg, 61 WPARAM wParam, 62 LPARAM lParam) 63 { 64 PGLOBAL_DATA pGlobalData; 65 66 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 67 68 switch (uMsg) 69 { 70 case WM_INITDIALOG: 71 pGlobalData = (PGLOBAL_DATA)lParam; 72 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData); 73 74 CheckDlgButton(hwndDlg, 75 IDC_CONTRAST_ACTIVATE_CHECK, 76 pGlobalData->highContrast.dwFlags & HCF_HOTKEYACTIVE ? BST_CHECKED : BST_UNCHECKED); 77 78 FillColorSchemeComboBox(GetDlgItem(hwndDlg, IDC_CONTRAST_COMBO)); 79 80 SendDlgItemMessage(hwndDlg, 81 IDC_CONTRAST_COMBO, 82 CB_SELECTSTRING, 83 (WPARAM)-1, 84 (LPARAM)pGlobalData->highContrast.lpszDefaultScheme); 85 break; 86 87 case WM_COMMAND: 88 switch (LOWORD(wParam)) 89 { 90 case IDC_CONTRAST_ACTIVATE_CHECK: 91 pGlobalData->highContrast.dwFlags ^= HCF_HOTKEYACTIVE; 92 break; 93 94 case IDC_CONTRAST_COMBO: 95 if (HIWORD(wParam) == CBN_SELCHANGE) 96 { 97 INT nSel; 98 99 nSel = SendDlgItemMessage(hwndDlg, IDC_CONTRAST_COMBO, 100 CB_GETCURSEL, 0, 0); 101 SendDlgItemMessage(hwndDlg, IDC_CONTRAST_COMBO, 102 CB_GETLBTEXT, nSel, 103 (LPARAM)pGlobalData->highContrast.lpszDefaultScheme); 104 } 105 break; 106 107 case IDOK: 108 EndDialog(hwndDlg, TRUE); 109 break; 110 111 case IDCANCEL: 112 EndDialog(hwndDlg, FALSE); 113 break; 114 115 default: 116 break; 117 } 118 break; 119 } 120 121 return FALSE; 122 } 123 124 125 /* Property page dialog callback */ 126 INT_PTR CALLBACK 127 DisplayPageProc(HWND hwndDlg, 128 UINT uMsg, 129 WPARAM wParam, 130 LPARAM lParam) 131 { 132 PGLOBAL_DATA pGlobalData; 133 LPPSHNOTIFY lppsn; 134 INT i; 135 136 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 137 138 switch (uMsg) 139 { 140 case WM_INITDIALOG: 141 pGlobalData = (PGLOBAL_DATA)((LPPROPSHEETPAGE)lParam)->lParam; 142 if (pGlobalData == NULL) 143 return FALSE; 144 145 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData); 146 147 pGlobalData->fShowCaret = TRUE; 148 GetWindowRect(GetDlgItem(hwndDlg, IDC_CURSOR_WIDTH_TEXT), &pGlobalData->rcCaret); 149 ScreenToClient(hwndDlg, (LPPOINT)&pGlobalData->rcCaret.left); 150 ScreenToClient(hwndDlg, (LPPOINT)&pGlobalData->rcCaret.right); 151 CopyRect(&pGlobalData->rcOldCaret, &pGlobalData->rcCaret); 152 153 pGlobalData->rcCaret.right = pGlobalData->rcCaret.left + pGlobalData->uCaretWidth; 154 155 /* Set the checkbox */ 156 CheckDlgButton(hwndDlg, 157 IDC_CONTRAST_BOX, 158 pGlobalData->highContrast.dwFlags & HCF_HIGHCONTRASTON ? BST_CHECKED : BST_UNCHECKED); 159 160 SendDlgItemMessage(hwndDlg, IDC_CURSOR_BLINK_TRACK, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 10)); 161 SendDlgItemMessage(hwndDlg, IDC_CURSOR_BLINK_TRACK, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(12 - (pGlobalData->uCaretBlinkTime / 100))); 162 163 SendDlgItemMessage(hwndDlg, IDC_CURSOR_WIDTH_TRACK, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 19)); 164 SendDlgItemMessage(hwndDlg, IDC_CURSOR_WIDTH_TRACK, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)(pGlobalData->uCaretWidth - 1)); 165 166 /* Start the blink timer */ 167 SetTimer(hwndDlg, ID_BLINK_TIMER, pGlobalData->uCaretBlinkTime, NULL); 168 return TRUE; 169 170 case WM_COMMAND: 171 switch (LOWORD(wParam)) 172 { 173 case IDC_CONTRAST_BOX: 174 pGlobalData->highContrast.dwFlags ^= HCF_HIGHCONTRASTON; 175 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 176 break; 177 178 case IDC_CONTRAST_BUTTON: 179 if (DialogBoxParam(hApplet, 180 MAKEINTRESOURCE(IDD_CONTRASTOPTIONS), 181 hwndDlg, 182 HighContrastDlgProc, 183 (LPARAM)pGlobalData)) 184 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 185 break; 186 187 default: 188 break; 189 } 190 break; 191 192 case WM_HSCROLL: 193 switch (GetWindowLongPtr((HWND) lParam, GWL_ID)) 194 { 195 case IDC_CURSOR_BLINK_TRACK: 196 i = SendDlgItemMessage(hwndDlg, IDC_CURSOR_BLINK_TRACK, TBM_GETPOS, 0, 0); 197 pGlobalData->uCaretBlinkTime = (12 - (UINT)i) * 100; 198 KillTimer(hwndDlg, ID_BLINK_TIMER); 199 SetTimer(hwndDlg, ID_BLINK_TIMER, pGlobalData->uCaretBlinkTime, NULL); 200 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 201 break; 202 203 case IDC_CURSOR_WIDTH_TRACK: 204 i = SendDlgItemMessage(hwndDlg, IDC_CURSOR_WIDTH_TRACK, TBM_GETPOS, 0, 0); 205 pGlobalData->uCaretWidth = (UINT)i + 1; 206 pGlobalData->rcCaret.right = pGlobalData->rcCaret.left + pGlobalData->uCaretWidth; 207 if (pGlobalData->fShowCaret) 208 { 209 HDC hDC = GetDC(hwndDlg); 210 HBRUSH hBrush = GetSysColorBrush(COLOR_BTNTEXT); 211 FillRect(hDC, &pGlobalData->rcCaret, hBrush); 212 DeleteObject(hBrush); 213 ReleaseDC(hwndDlg, hDC); 214 } 215 else 216 { 217 InvalidateRect(hwndDlg, &pGlobalData->rcOldCaret, TRUE); 218 } 219 PropSheet_Changed(GetParent(hwndDlg), hwndDlg); 220 break; 221 } 222 break; 223 224 case WM_TIMER: 225 if (wParam == ID_BLINK_TIMER) 226 { 227 if (pGlobalData->fShowCaret) 228 { 229 HDC hDC = GetDC(hwndDlg); 230 HBRUSH hBrush = GetSysColorBrush(COLOR_BTNTEXT); 231 FillRect(hDC, &pGlobalData->rcCaret, hBrush); 232 DeleteObject(hBrush); 233 ReleaseDC(hwndDlg, hDC); 234 } 235 else 236 { 237 InvalidateRect(hwndDlg, &pGlobalData->rcOldCaret, TRUE); 238 } 239 240 pGlobalData->fShowCaret = !pGlobalData->fShowCaret; 241 } 242 break; 243 244 case WM_NOTIFY: 245 lppsn = (LPPSHNOTIFY)lParam; 246 if (lppsn->hdr.code == PSN_APPLY) 247 { 248 SetCaretBlinkTime(pGlobalData->uCaretBlinkTime); 249 SystemParametersInfo(SPI_SETCARETWIDTH, 250 0, 251 IntToPtr(pGlobalData->uCaretWidth), 252 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE /*0*/); 253 SystemParametersInfo(SPI_SETHIGHCONTRAST, 254 sizeof(HIGHCONTRAST), 255 &pGlobalData->highContrast, 256 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE /*0*/); 257 return TRUE; 258 } 259 break; 260 261 case WM_DESTROY: 262 KillTimer(hwndDlg, ID_BLINK_TIMER); 263 break; 264 } 265 266 return FALSE; 267 } 268