- Update to r53061
[reactos.git] / dll / cpl / access / mouse.c
1 /* $Id: mouse.c 29112 2007-09-19 21:31:49Z ekohl $
2 *
3 * PROJECT: ReactOS Accessibility Control Panel
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: dll/cpl/access/mouse.c
6 * PURPOSE: Mouse-related accessibility settings
7 * COPYRIGHT: Copyright 2004 Johannes Anderwald (j_anderw@sbox.tugraz.at)
8 * Copyright 2007 Eric Kohl
9 */
10
11 #include "access.h"
12
13
14 #define SPEEDTICKS 9
15 #define ACCELTICKS 9
16
17 static UINT nSpeedArray[SPEEDTICKS] = {10, 20, 30, 40, 60, 80, 120, 180, 360};
18
19
20 INT_PTR CALLBACK
21 MouseKeysDlgProc(HWND hwndDlg,
22 UINT uMsg,
23 WPARAM wParam,
24 LPARAM lParam)
25 {
26 PGLOBAL_DATA pGlobalData;
27 INT i;
28
29 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
30
31 switch (uMsg)
32 {
33 case WM_INITDIALOG:
34 pGlobalData = (PGLOBAL_DATA)lParam;
35 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
36
37 CheckDlgButton(hwndDlg,
38 IDC_MOUSEKEYS_ACTIVATE_CHECK,
39 pGlobalData->mouseKeys.dwFlags & MKF_HOTKEYACTIVE ? BST_CHECKED : BST_UNCHECKED);
40
41 /* Set the number of ticks for the speed trackbar */
42 SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_SPEED_TRACK, TBM_SETRANGE,
43 TRUE, MAKELONG(0, SPEEDTICKS - 1));
44
45 /* Calculate the matching tick */
46 for (i = 0; i < SPEEDTICKS; i++)
47 {
48 if (pGlobalData->mouseKeys.iMaxSpeed <= nSpeedArray[i])
49 break;
50 }
51
52 /* Set the thumb */
53 SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_SPEED_TRACK, TBM_SETPOS, TRUE, i);
54
55 /* Set the number of ticks for the accelleration trackbar */
56 SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_ACCEL_TRACK, TBM_SETRANGE,
57 TRUE, MAKELONG(0, ACCELTICKS - 1));
58
59 /* Calculate the matching tick */
60 i = (ACCELTICKS + 1) - pGlobalData->mouseKeys.iTimeToMaxSpeed / 500;
61 if (i > ACCELTICKS - 1)
62 i = ACCELTICKS - 1;
63
64 if (i < 0)
65 i = 0;
66
67 /* Set the thumb */
68 SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_ACCEL_TRACK, TBM_SETPOS, TRUE, i);
69
70 CheckDlgButton(hwndDlg,
71 IDC_MOUSEKEYS_SPEED_CHECK,
72 pGlobalData->mouseKeys.dwFlags & MKF_MODIFIERS ? BST_CHECKED : BST_UNCHECKED);
73
74 CheckRadioButton(hwndDlg,
75 IDC_MOUSEKEYS_ON_RADIO,
76 IDC_MOUSEKEYS_OFF_RADIO,
77 pGlobalData->mouseKeys.dwFlags & MKF_REPLACENUMBERS ? IDC_MOUSEKEYS_ON_RADIO : IDC_MOUSEKEYS_OFF_RADIO);
78
79 CheckDlgButton(hwndDlg,
80 IDC_MOUSEKEYS_STATUS_CHECK,
81 pGlobalData->mouseKeys.dwFlags & MKF_INDICATOR ? BST_CHECKED : BST_UNCHECKED);
82 break;
83
84 case WM_HSCROLL:
85 switch (GetWindowLongPtr((HWND) lParam, GWL_ID))
86 {
87 case IDC_MOUSEKEYS_SPEED_TRACK:
88 i = SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_SPEED_TRACK, TBM_GETPOS, 0, 0);
89 if (i >= 0 && i < SPEEDTICKS)
90 pGlobalData->mouseKeys.iMaxSpeed = nSpeedArray[i];
91 break;
92
93 case IDC_MOUSEKEYS_ACCEL_TRACK:
94 i = SendDlgItemMessage(hwndDlg, IDC_MOUSEKEYS_ACCEL_TRACK, TBM_GETPOS, 0, 0);
95 if (i >= 0 && i < ACCELTICKS)
96 pGlobalData->mouseKeys.iTimeToMaxSpeed = (ACCELTICKS + 1 - i) * 500;
97 break;
98 }
99 break;
100
101 case WM_COMMAND:
102 switch (LOWORD(wParam))
103 {
104 case IDC_MOUSEKEYS_ACTIVATE_CHECK:
105 pGlobalData->mouseKeys.dwFlags ^= MKF_HOTKEYACTIVE;
106 break;
107
108 case IDC_MOUSEKEYS_SPEED_CHECK:
109 pGlobalData->mouseKeys.dwFlags ^= MKF_MODIFIERS;
110 break;
111
112 case IDC_MOUSEKEYS_ON_RADIO:
113 pGlobalData->mouseKeys.dwFlags |= MKF_REPLACENUMBERS;
114 break;
115
116 case IDC_MOUSEKEYS_OFF_RADIO:
117 pGlobalData->mouseKeys.dwFlags &= ~MKF_REPLACENUMBERS;
118 break;
119
120 case IDC_MOUSEKEYS_STATUS_CHECK:
121 pGlobalData->mouseKeys.dwFlags ^= MKF_INDICATOR;
122 break;
123
124 case IDOK:
125 EndDialog(hwndDlg, TRUE);
126 break;
127
128 case IDCANCEL:
129 EndDialog(hwndDlg, FALSE);
130 break;
131
132 default:
133 break;
134 }
135 break;
136 }
137
138 return FALSE;
139 }
140
141
142 /* Property page dialog callback */
143 INT_PTR CALLBACK
144 MousePageProc(HWND hwndDlg,
145 UINT uMsg,
146 WPARAM wParam,
147 LPARAM lParam)
148 {
149 PGLOBAL_DATA pGlobalData;
150 LPPSHNOTIFY lppsn;
151
152 pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
153
154 switch (uMsg)
155 {
156 case WM_INITDIALOG:
157 pGlobalData = (PGLOBAL_DATA)((LPPROPSHEETPAGE)lParam)->lParam;
158 if (pGlobalData == NULL)
159 return FALSE;
160
161 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
162
163 /* Set the checkbox */
164 CheckDlgButton(hwndDlg,
165 IDC_MOUSE_BOX,
166 pGlobalData->mouseKeys.dwFlags & MKF_MOUSEKEYSON ? BST_CHECKED : BST_UNCHECKED);
167 return TRUE;
168
169
170 case WM_COMMAND:
171 switch (LOWORD(wParam))
172 {
173 case IDC_MOUSE_BOX:
174 pGlobalData->mouseKeys.dwFlags ^= MKF_MOUSEKEYSON;
175 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
176 break;
177
178 case IDC_MOUSE_BUTTON:
179 if (DialogBoxParam(hApplet,
180 MAKEINTRESOURCE(IDD_MOUSEKEYSOPTIONS),
181 hwndDlg,
182 (DLGPROC)MouseKeysDlgProc,
183 (LPARAM)pGlobalData))
184 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
185 break;
186
187 default:
188 break;
189 }
190 break;
191
192 case WM_NOTIFY:
193 lppsn = (LPPSHNOTIFY)lParam;
194 if (lppsn->hdr.code == PSN_APPLY)
195 {
196 SystemParametersInfo(SPI_SETMOUSEKEYS,
197 sizeof(MOUSEKEYS),
198 &pGlobalData->mouseKeys,
199 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE /*0*/);
200 return TRUE;
201 }
202 break;
203 }
204
205 return FALSE;
206 }