comparison src/video/win32/SDL_win32events.c @ 4465:3e69e077cb95

Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API. Plus, this lets me start implementing cursor support.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 09 May 2010 20:47:22 -0700
parents faa9fc8e7f67
children a5878b271b74
comparison
equal deleted inserted replaced
4464:fa77a6429698 4465:3e69e077cb95
55 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) 55 #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
56 #endif 56 #endif
57 #ifndef WM_INPUT 57 #ifndef WM_INPUT
58 #define WM_INPUT 0x00ff 58 #define WM_INPUT 0x00ff
59 #endif 59 #endif
60
61 extern HCTX *g_hCtx;
62 extern HANDLE *mice;
63 extern int total_mice;
64 extern int tablet;
65 int pressure = 0; /* the pressure reported by the tablet */
66 60
67 static WPARAM 61 static WPARAM
68 RemapVKEY(WPARAM wParam, LPARAM lParam) 62 RemapVKEY(WPARAM wParam, LPARAM lParam)
69 { 63 {
70 int i; 64 int i;
102 96
103 LRESULT CALLBACK 97 LRESULT CALLBACK
104 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 98 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
105 { 99 {
106 SDL_WindowData *data; 100 SDL_WindowData *data;
107 RAWINPUT *raw;
108 PACKET packet;
109 LRESULT returnCode = -1; 101 LRESULT returnCode = -1;
110 102
111 /* Send a SDL_SYSWMEVENT if the application wants them */ 103 /* Send a SDL_SYSWMEVENT if the application wants them */
112 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { 104 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
113 SDL_SysWMmsg wmmsg; 105 SDL_SysWMmsg wmmsg;
140 132
141 #endif 133 #endif
142 134
143 switch (msg) { 135 switch (msg) {
144 136
145 case WT_PACKET:
146 {
147 /* if we receive such data we need to update the pressure */
148 SDL_VideoData *videodata = data->videodata;
149 if (videodata->wintabDLL
150 && videodata->WTPacket((HCTX) lParam, (UINT) wParam, &packet)) {
151 SDL_ChangeEnd(tablet, (int) packet.pkCursor);
152 pressure = (int) packet.pkNormalPressure;
153 }
154 }
155 break;
156
157 case WT_PROXIMITY:
158 {
159 /* checking where the proximity message showed up */
160 int h_context = LOWORD(lParam);
161 POINT point;
162 GetCursorPos(&point);
163 ScreenToClient(hwnd, &point);
164
165 /* are we in proximity or out of proximity */
166 if (h_context == 0) {
167 SDL_SendProximity(tablet, point.x, point.y, SDL_PROXIMITYOUT);
168 } else {
169 SDL_SendProximity(tablet, point.x, point.y, SDL_PROXIMITYIN);
170 }
171 }
172 break;
173
174 case WM_SHOWWINDOW: 137 case WM_SHOWWINDOW:
175 { 138 {
176 if (wParam) { 139 if (wParam) {
177 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); 140 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
178 } else { 141 } else {
181 } 144 }
182 break; 145 break;
183 146
184 case WM_ACTIVATE: 147 case WM_ACTIVATE:
185 { 148 {
186 int index;
187 SDL_Keyboard *keyboard;
188 BOOL minimized; 149 BOOL minimized;
189 150
190 minimized = HIWORD(wParam); 151 minimized = HIWORD(wParam);
191 index = data->videodata->keyboard;
192 keyboard = SDL_GetKeyboard(index);
193 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { 152 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
194 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); 153 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
195 SDL_SendWindowEvent(data->window, 154 SDL_SendWindowEvent(data->window,
196 SDL_WINDOWEVENT_RESTORED, 0, 0); 155 SDL_WINDOWEVENT_RESTORED, 0, 0);
197 #ifndef _WIN32_WCE /* WinCE misses IsZoomed() */ 156 #ifndef _WIN32_WCE /* WinCE misses IsZoomed() */
198 if (IsZoomed(hwnd)) { 157 if (IsZoomed(hwnd)) {
199 SDL_SendWindowEvent(data->window, 158 SDL_SendWindowEvent(data->window,
200 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); 159 SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
201 } 160 }
202 #endif 161 #endif
203 if (keyboard && keyboard->focus != data->window) { 162 if (SDL_GetKeyboardFocus() != data->window) {
204 SDL_SetKeyboardFocus(index, data->window); 163 SDL_SetKeyboardFocus(data->window);
205 } 164 }
206 /* FIXME: Update keyboard state */ 165 /* FIXME: Update keyboard state */
207 } else { 166 } else {
208 if (keyboard && keyboard->focus == data->window) { 167 if (SDL_GetKeyboardFocus() == data->window) {
209 SDL_SetKeyboardFocus(index, 0); 168 SDL_SetKeyboardFocus(NULL);
210 } 169 }
211 if (minimized) { 170 if (minimized) {
212 SDL_SendWindowEvent(data->window, 171 SDL_SendWindowEvent(data->window,
213 SDL_WINDOWEVENT_MINIMIZED, 0, 0); 172 SDL_WINDOWEVENT_MINIMIZED, 0, 0);
214 } 173 }
215 } 174 }
216 } 175 }
217 returnCode = 0; 176 returnCode = 0;
218 break; 177 break;
219 178
220 /* WinCE has no RawInput, so we use the classic mouse events.
221 In classic Win32 this is done by WM_INPUT
222 */
223 #ifdef _WIN32_WCE
224 case WM_MOUSEMOVE: 179 case WM_MOUSEMOVE:
225 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); 180 SDL_SendMouseMotion(0, LOWORD(lParam), HIWORD(lParam));
226 break; 181 break;
227 182
228 case WM_LBUTTONDOWN: 183 case WM_LBUTTONDOWN:
229 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); 184 SDL_SendMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT);
230 SDL_SendMouseButton(0, SDL_PRESSED, SDL_BUTTON_LEFT);
231 break; 185 break;
232 186
233 case WM_LBUTTONUP: 187 case WM_LBUTTONUP:
234 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); 188 SDL_SendMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT);
235 SDL_SendMouseButton(0, SDL_RELEASED, SDL_BUTTON_LEFT); 189 break;
236 break;
237 #else /* _WIN32_WCE */
238
239 case WM_INPUT: /* mouse events */
240 {
241 LPBYTE lpb;
242 const RAWINPUTHEADER *header;
243 int index = -1;
244 int i;
245 int size = 0;
246 const RAWMOUSE *raw_mouse = NULL;
247 POINT point;
248 USHORT flags;
249 int w, h;
250
251 /* we're collecting raw data to be able to identify the mouse (if there are several) */
252 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size,
253 sizeof(RAWINPUTHEADER));
254 lpb = SDL_stack_alloc(BYTE, size);
255 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size,
256 sizeof(RAWINPUTHEADER));
257 raw = (RAWINPUT *) lpb;
258 header = &raw->header;
259 flags = raw->data.mouse.usButtonFlags;
260
261 /* we're checking which mouse generated the event */
262 for (i = 0; i < total_mice; ++i) {
263 if (mice[i] == header->hDevice) {
264 index = i;
265 break;
266 }
267 }
268 if (index < 0) {
269 /* New mouse? Should we dynamically update mouse list? */
270 returnCode = 0;
271 break;
272 }
273
274 GetCursorPos(&point);
275 ScreenToClient(hwnd, &point);
276
277 SDL_GetWindowSize(data->window, &w, &h);
278 if (point.x >= 0 && point.y >= 0 && point.x < w && point.y < h) {
279 SDL_SetMouseFocus(index, data->window);
280 } else {
281 SDL_SetMouseFocus(index, 0);
282 /* FIXME: Should we be doing anything else here? */
283 break;
284 }
285
286 /* if the message was sent by a tablet we have to send also pressure */
287 if (index == tablet) {
288 SDL_SendMouseMotion(index, 0, point.x, point.y, pressure);
289 } else {
290 SDL_SendMouseMotion(index, 0, point.x, point.y, 0);
291 }
292 /* we're sending mouse buttons messages to check up if sth changed */
293 if (flags & RI_MOUSE_LEFT_BUTTON_DOWN) {
294 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_LEFT);
295 } else if (flags & RI_MOUSE_LEFT_BUTTON_UP) {
296 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_LEFT);
297 }
298 if (flags & RI_MOUSE_MIDDLE_BUTTON_DOWN) {
299 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_MIDDLE);
300 } else if (flags & RI_MOUSE_MIDDLE_BUTTON_UP) {
301 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE);
302 }
303 if (flags & RI_MOUSE_RIGHT_BUTTON_DOWN) {
304 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_RIGHT);
305 } else if (flags & RI_MOUSE_RIGHT_BUTTON_UP) {
306 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_RIGHT);
307 }
308 if (flags & RI_MOUSE_BUTTON_4_DOWN) {
309 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_X1);
310 } else if (flags & RI_MOUSE_BUTTON_4_UP) {
311 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_X1);
312 }
313 if (flags & RI_MOUSE_BUTTON_5_DOWN) {
314 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_X2);
315 } else if (flags & RI_MOUSE_BUTTON_5_UP) {
316 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_X2);
317 }
318 if (flags & RI_MOUSE_WHEEL) {
319 SDL_SendMouseWheel(index, 0,
320 (short) raw->data.mouse.usButtonData);
321 }
322 SDL_stack_free(lpb);
323 }
324 returnCode = 0;
325 break;
326 #endif /* _WIN32_WCE */
327 190
328 case WM_MOUSELEAVE: 191 case WM_MOUSELEAVE:
329 { 192 {
330 int i; 193 if (SDL_GetMouseFocus() == data->window) {
331 194 SDL_SetMouseFocus(NULL);
332 for (i = 0; i < SDL_GetNumMice(); ++i) {
333 SDL_Mouse *mouse = SDL_GetMouse(i);
334
335 if (mouse->focus == data->window) {
336 SDL_SetMouseFocus(i, 0);
337 }
338 } 195 }
339 } 196 }
340 returnCode = 0; 197 returnCode = 0;
341 break; 198 break;
342 199
343 case WM_SYSKEYDOWN: 200 case WM_SYSKEYDOWN:
344 case WM_KEYDOWN: 201 case WM_KEYDOWN:
345 { 202 {
346 int index;
347
348 /* Ignore repeated keys */ 203 /* Ignore repeated keys */
349 if (lParam & REPEATED_KEYMASK) { 204 if (lParam & REPEATED_KEYMASK) {
350 returnCode = 0; 205 returnCode = 0;
351 break; 206 break;
352 } 207 }
353 208
354 index = data->videodata->keyboard;
355 wParam = RemapVKEY(wParam, lParam); 209 wParam = RemapVKEY(wParam, lParam);
356 switch (wParam) { 210 switch (wParam) {
357 case VK_CONTROL: 211 case VK_CONTROL:
358 if (lParam & EXTENDED_KEYMASK) 212 if (lParam & EXTENDED_KEYMASK)
359 wParam = VK_RCONTROL; 213 wParam = VK_RCONTROL;
386 if (lParam & EXTENDED_KEYMASK) 240 if (lParam & EXTENDED_KEYMASK)
387 wParam = VK_ENTER; 241 wParam = VK_ENTER;
388 break; 242 break;
389 } 243 }
390 if (wParam < 256) { 244 if (wParam < 256) {
391 SDL_SendKeyboardKey(index, SDL_PRESSED, 245 SDL_SendKeyboardKey(SDL_PRESSED,
392 data->videodata->key_layout[wParam]); 246 data->videodata->key_layout[wParam]);
393 } 247 }
394 } 248 }
395 returnCode = 0; 249 returnCode = 0;
396 break; 250 break;
397 251
398 case WM_SYSKEYUP: 252 case WM_SYSKEYUP:
399 case WM_KEYUP: 253 case WM_KEYUP:
400 { 254 {
401 int index;
402
403 index = data->videodata->keyboard;
404 wParam = RemapVKEY(wParam, lParam); 255 wParam = RemapVKEY(wParam, lParam);
405 switch (wParam) { 256 switch (wParam) {
406 case VK_CONTROL: 257 case VK_CONTROL:
407 if (lParam & EXTENDED_KEYMASK) 258 if (lParam & EXTENDED_KEYMASK)
408 wParam = VK_RCONTROL; 259 wParam = VK_RCONTROL;
439 290
440 /* Windows only reports keyup for print screen */ 291 /* Windows only reports keyup for print screen */
441 if (wParam == VK_SNAPSHOT 292 if (wParam == VK_SNAPSHOT
442 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == 293 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
443 SDL_RELEASED) { 294 SDL_RELEASED) {
444 SDL_SendKeyboardKey(index, SDL_PRESSED, 295 SDL_SendKeyboardKey(SDL_PRESSED,
445 data->videodata->key_layout[wParam]); 296 data->videodata->key_layout[wParam]);
446 } 297 }
447 if (wParam < 256) { 298 if (wParam < 256) {
448 SDL_SendKeyboardKey(index, SDL_RELEASED, 299 SDL_SendKeyboardKey(SDL_RELEASED,
449 data->videodata->key_layout[wParam]); 300 data->videodata->key_layout[wParam]);
450 } 301 }
451 } 302 }
452 returnCode = 0; 303 returnCode = 0;
453 break; 304 break;
468 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F); 319 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
469 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F); 320 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
470 text[2] = 0x80 | (char) (wParam & 0x3F); 321 text[2] = 0x80 | (char) (wParam & 0x3F);
471 text[3] = '\0'; 322 text[3] = '\0';
472 } 323 }
473 SDL_SendKeyboardText(data->videodata->keyboard, text); 324 SDL_SendKeyboardText(text);
474 } 325 }
475 returnCode = 0; 326 returnCode = 0;
476 break; 327 break;
477 328
478 case WM_INPUTLANGCHANGE: 329 case WM_INPUTLANGCHANGE:
479 { 330 {
480 WIN_UpdateKeymap(data->videodata->keyboard); 331 WIN_UpdateKeymap();
481 } 332 }
482 returnCode = 1; 333 returnCode = 1;
483 break; 334 break;
484 335
485 case WM_GETMINMAXINFO: 336 case WM_GETMINMAXINFO: