comparison src/video/win32/SDL_win32events.c @ 4746:0c39b36dd104

Merge
author dewyatt
date Tue, 06 Jul 2010 02:07:42 -0400
parents 983eb9d5ed31 9322f7db8603
children dc7bdcf06367
comparison
equal deleted inserted replaced
4745:0aaa54fbd2bc 4746:0c39b36dd104
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. 179 case WM_MOUSEMOVE:
221 In classic Win32 this is done by WM_INPUT 180 SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
222 */
223 #ifdef _WIN32_WCE
224 case WM_MOUSEMOVE:
225 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0);
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(data->window, 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(data->window, 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 if (SDL_GetMouseFocus() == data->window) {
330 int i; 193 SDL_SetMouseFocus(NULL);
331
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 }
339 } 194 }
340 returnCode = 0; 195 returnCode = 0;
341 break; 196 break;
342 197
343 case WM_SYSKEYDOWN: 198 case WM_SYSKEYDOWN:
344 case WM_KEYDOWN: 199 case WM_KEYDOWN:
345 { 200 {
346 int index;
347
348 /* Ignore repeated keys */ 201 /* Ignore repeated keys */
349 if (lParam & REPEATED_KEYMASK) { 202 if (lParam & REPEATED_KEYMASK) {
350 returnCode = 0; 203 returnCode = 0;
351 break; 204 break;
352 } 205 }
353 206
354 index = data->videodata->keyboard;
355 wParam = RemapVKEY(wParam, lParam); 207 wParam = RemapVKEY(wParam, lParam);
356 switch (wParam) { 208 switch (wParam) {
357 case VK_CONTROL: 209 case VK_CONTROL:
358 if (lParam & EXTENDED_KEYMASK) 210 if (lParam & EXTENDED_KEYMASK)
359 wParam = VK_RCONTROL; 211 wParam = VK_RCONTROL;
386 if (lParam & EXTENDED_KEYMASK) 238 if (lParam & EXTENDED_KEYMASK)
387 wParam = VK_ENTER; 239 wParam = VK_ENTER;
388 break; 240 break;
389 } 241 }
390 if (wParam < 256) { 242 if (wParam < 256) {
391 SDL_SendKeyboardKey(index, SDL_PRESSED, 243 SDL_SendKeyboardKey(SDL_PRESSED,
392 data->videodata->key_layout[wParam]); 244 data->videodata->key_layout[wParam]);
393 } 245 }
394 } 246 }
395 returnCode = 0; 247 returnCode = 0;
396 break; 248 break;
397 249
398 case WM_SYSKEYUP: 250 case WM_SYSKEYUP:
399 case WM_KEYUP: 251 case WM_KEYUP:
400 { 252 {
401 int index;
402
403 index = data->videodata->keyboard;
404 wParam = RemapVKEY(wParam, lParam); 253 wParam = RemapVKEY(wParam, lParam);
405 switch (wParam) { 254 switch (wParam) {
406 case VK_CONTROL: 255 case VK_CONTROL:
407 if (lParam & EXTENDED_KEYMASK) 256 if (lParam & EXTENDED_KEYMASK)
408 wParam = VK_RCONTROL; 257 wParam = VK_RCONTROL;
439 288
440 /* Windows only reports keyup for print screen */ 289 /* Windows only reports keyup for print screen */
441 if (wParam == VK_SNAPSHOT 290 if (wParam == VK_SNAPSHOT
442 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == 291 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
443 SDL_RELEASED) { 292 SDL_RELEASED) {
444 SDL_SendKeyboardKey(index, SDL_PRESSED, 293 SDL_SendKeyboardKey(SDL_PRESSED,
445 data->videodata->key_layout[wParam]); 294 data->videodata->key_layout[wParam]);
446 } 295 }
447 if (wParam < 256) { 296 if (wParam < 256) {
448 SDL_SendKeyboardKey(index, SDL_RELEASED, 297 SDL_SendKeyboardKey(SDL_RELEASED,
449 data->videodata->key_layout[wParam]); 298 data->videodata->key_layout[wParam]);
450 } 299 }
451 } 300 }
452 returnCode = 0; 301 returnCode = 0;
453 break; 302 break;
468 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F); 317 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
469 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F); 318 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
470 text[2] = 0x80 | (char) (wParam & 0x3F); 319 text[2] = 0x80 | (char) (wParam & 0x3F);
471 text[3] = '\0'; 320 text[3] = '\0';
472 } 321 }
473 SDL_SendKeyboardText(data->videodata->keyboard, text); 322 SDL_SendKeyboardText(text);
474 } 323 }
475 returnCode = 0; 324 returnCode = 0;
476 break; 325 break;
477 326
478 case WM_INPUTLANGCHANGE: 327 case WM_INPUTLANGCHANGE:
479 { 328 {
480 WIN_UpdateKeymap(data->videodata->keyboard); 329 WIN_UpdateKeymap();
481 } 330 }
482 returnCode = 1; 331 returnCode = 1;
483 break; 332 break;
484 333
485 case WM_GETMINMAXINFO: 334 case WM_GETMINMAXINFO: