Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32events.c @ 1724:6c63fc2bd986 SDL-1.3
Proof of concept done - Win32 GDI implementation mostly complete.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 06 Jul 2006 07:17:11 +0000 |
parents | 5daa04d862f1 |
children | 90a3e0fccb88 |
comparison
equal
deleted
inserted
replaced
1723:4bdbb9b2bd0a | 1724:6c63fc2bd986 |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #include "SDL_win32video.h" | 24 #include "SDL_win32video.h" |
25 #include "SDL_version.h" | |
26 #include "SDL_syswm.h" | |
27 #include "SDL_vkeys.h" | |
25 #include "../../events/SDL_events_c.h" | 28 #include "../../events/SDL_events_c.h" |
26 | 29 |
30 /*#define WMMSG_DEBUG*/ | |
31 #ifdef WMMSG_DEBUG | |
32 #include "wmmsg.h" | |
33 #endif | |
34 | |
35 /* Masks for processing the windows KEYDOWN and KEYUP messages */ | |
36 #define REPEATED_KEYMASK (1<<30) | |
37 #define EXTENDED_KEYMASK (1<<24) | |
38 | |
39 | |
40 static SDLKey | |
41 TranslateKey(WPARAM vkey) | |
42 { | |
43 SDLKey key; | |
44 | |
45 /* FIXME: Assign vkey directly to key if in ASCII range */ | |
46 switch (vkey) { | |
47 case VK_BACK: | |
48 key = SDLK_BACKSPACE; | |
49 break; | |
50 case VK_TAB: | |
51 key = SDLK_TAB; | |
52 break; | |
53 case VK_CLEAR: | |
54 key = SDLK_CLEAR; | |
55 break; | |
56 case VK_RETURN: | |
57 key = SDLK_RETURN; | |
58 break; | |
59 case VK_PAUSE: | |
60 key = SDLK_PAUSE; | |
61 break; | |
62 case VK_ESCAPE: | |
63 key = SDLK_ESCAPE; | |
64 break; | |
65 case VK_SPACE: | |
66 key = SDLK_SPACE; | |
67 break; | |
68 case VK_APOSTROPHE: | |
69 key = SDLK_QUOTE; | |
70 break; | |
71 case VK_COMMA: | |
72 key = SDLK_COMMA; | |
73 break; | |
74 case VK_MINUS: | |
75 key = SDLK_MINUS; | |
76 break; | |
77 case VK_PERIOD: | |
78 key = SDLK_PERIOD; | |
79 break; | |
80 case VK_SLASH: | |
81 key = SDLK_SLASH; | |
82 break; | |
83 case VK_0: | |
84 key = SDLK_0; | |
85 break; | |
86 case VK_1: | |
87 key = SDLK_1; | |
88 break; | |
89 case VK_2: | |
90 key = SDLK_2; | |
91 break; | |
92 case VK_3: | |
93 key = SDLK_3; | |
94 break; | |
95 case VK_4: | |
96 key = SDLK_4; | |
97 break; | |
98 case VK_5: | |
99 key = SDLK_5; | |
100 break; | |
101 case VK_6: | |
102 key = SDLK_6; | |
103 break; | |
104 case VK_7: | |
105 key = SDLK_7; | |
106 break; | |
107 case VK_8: | |
108 key = SDLK_8; | |
109 break; | |
110 case VK_9: | |
111 key = SDLK_9; | |
112 break; | |
113 case VK_SEMICOLON: | |
114 key = SDLK_SEMICOLON; | |
115 break; | |
116 case VK_EQUALS: | |
117 key = SDLK_EQUALS; | |
118 break; | |
119 case VK_LBRACKET: | |
120 key = SDLK_LEFTBRACKET; | |
121 break; | |
122 case VK_BACKSLASH: | |
123 key = SDLK_BACKSLASH; | |
124 break; | |
125 case VK_OEM_102: | |
126 key = SDLK_LESS; | |
127 break; | |
128 case VK_RBRACKET: | |
129 key = SDLK_RIGHTBRACKET; | |
130 break; | |
131 case VK_GRAVE: | |
132 key = SDLK_BACKQUOTE; | |
133 break; | |
134 case VK_BACKTICK: | |
135 key = SDLK_BACKQUOTE; | |
136 break; | |
137 case VK_A: | |
138 key = SDLK_a; | |
139 break; | |
140 case VK_B: | |
141 key = SDLK_b; | |
142 break; | |
143 case VK_C: | |
144 key = SDLK_c; | |
145 break; | |
146 case VK_D: | |
147 key = SDLK_d; | |
148 break; | |
149 case VK_E: | |
150 key = SDLK_e; | |
151 break; | |
152 case VK_F: | |
153 key = SDLK_f; | |
154 break; | |
155 case VK_G: | |
156 key = SDLK_g; | |
157 break; | |
158 case VK_H: | |
159 key = SDLK_h; | |
160 break; | |
161 case VK_I: | |
162 key = SDLK_i; | |
163 break; | |
164 case VK_J: | |
165 key = SDLK_j; | |
166 break; | |
167 case VK_K: | |
168 key = SDLK_k; | |
169 break; | |
170 case VK_L: | |
171 key = SDLK_l; | |
172 break; | |
173 case VK_M: | |
174 key = SDLK_m; | |
175 break; | |
176 case VK_N: | |
177 key = SDLK_n; | |
178 break; | |
179 case VK_O: | |
180 key = SDLK_o; | |
181 break; | |
182 case VK_P: | |
183 key = SDLK_p; | |
184 break; | |
185 case VK_Q: | |
186 key = SDLK_q; | |
187 break; | |
188 case VK_R: | |
189 key = SDLK_r; | |
190 break; | |
191 case VK_S: | |
192 key = SDLK_s; | |
193 break; | |
194 case VK_T: | |
195 key = SDLK_t; | |
196 break; | |
197 case VK_U: | |
198 key = SDLK_u; | |
199 break; | |
200 case VK_V: | |
201 key = SDLK_v; | |
202 break; | |
203 case VK_W: | |
204 key = SDLK_w; | |
205 break; | |
206 case VK_X: | |
207 key = SDLK_x; | |
208 break; | |
209 case VK_Y: | |
210 key = SDLK_y; | |
211 break; | |
212 case VK_Z: | |
213 key = SDLK_z; | |
214 break; | |
215 case VK_DELETE: | |
216 key = SDLK_DELETE; | |
217 break; | |
218 case VK_NUMPAD0: | |
219 key = SDLK_KP0; | |
220 break; | |
221 case VK_NUMPAD1: | |
222 key = SDLK_KP1; | |
223 break; | |
224 case VK_NUMPAD2: | |
225 key = SDLK_KP2; | |
226 break; | |
227 case VK_NUMPAD3: | |
228 key = SDLK_KP3; | |
229 break; | |
230 case VK_NUMPAD4: | |
231 key = SDLK_KP4; | |
232 break; | |
233 case VK_NUMPAD5: | |
234 key = SDLK_KP5; | |
235 break; | |
236 case VK_NUMPAD6: | |
237 key = SDLK_KP6; | |
238 break; | |
239 case VK_NUMPAD7: | |
240 key = SDLK_KP7; | |
241 break; | |
242 case VK_NUMPAD8: | |
243 key = SDLK_KP8; | |
244 break; | |
245 case VK_NUMPAD9: | |
246 key = SDLK_KP9; | |
247 break; | |
248 case VK_DECIMAL: | |
249 key = SDLK_KP_PERIOD; | |
250 break; | |
251 case VK_DIVIDE: | |
252 key = SDLK_KP_DIVIDE; | |
253 break; | |
254 case VK_MULTIPLY: | |
255 key = SDLK_KP_MULTIPLY; | |
256 break; | |
257 case VK_SUBTRACT: | |
258 key = SDLK_KP_MINUS; | |
259 break; | |
260 case VK_ADD: | |
261 key = SDLK_KP_PLUS; | |
262 break; | |
263 case VK_UP: | |
264 key = SDLK_UP; | |
265 break; | |
266 case VK_DOWN: | |
267 key = SDLK_DOWN; | |
268 break; | |
269 case VK_RIGHT: | |
270 key = SDLK_RIGHT; | |
271 break; | |
272 case VK_LEFT: | |
273 key = SDLK_LEFT; | |
274 break; | |
275 case VK_INSERT: | |
276 key = SDLK_INSERT; | |
277 break; | |
278 case VK_HOME: | |
279 key = SDLK_HOME; | |
280 break; | |
281 case VK_END: | |
282 key = SDLK_END; | |
283 break; | |
284 case VK_PRIOR: | |
285 key = SDLK_PAGEUP; | |
286 break; | |
287 case VK_NEXT: | |
288 key = SDLK_PAGEDOWN; | |
289 break; | |
290 case VK_F1: | |
291 key = SDLK_F1; | |
292 break; | |
293 case VK_F2: | |
294 key = SDLK_F2; | |
295 break; | |
296 case VK_F3: | |
297 key = SDLK_F3; | |
298 break; | |
299 case VK_F4: | |
300 key = SDLK_F4; | |
301 break; | |
302 case VK_F5: | |
303 key = SDLK_F5; | |
304 break; | |
305 case VK_F6: | |
306 key = SDLK_F6; | |
307 break; | |
308 case VK_F7: | |
309 key = SDLK_F7; | |
310 break; | |
311 case VK_F8: | |
312 key = SDLK_F8; | |
313 break; | |
314 case VK_F9: | |
315 key = SDLK_F9; | |
316 break; | |
317 case VK_F10: | |
318 key = SDLK_F10; | |
319 break; | |
320 case VK_F11: | |
321 key = SDLK_F11; | |
322 break; | |
323 case VK_F12: | |
324 key = SDLK_F12; | |
325 break; | |
326 case VK_F13: | |
327 key = SDLK_F13; | |
328 break; | |
329 case VK_F14: | |
330 key = SDLK_F14; | |
331 break; | |
332 case VK_F15: | |
333 key = SDLK_F15; | |
334 break; | |
335 case VK_NUMLOCK: | |
336 key = SDLK_NUMLOCK; | |
337 break; | |
338 case VK_CAPITAL: | |
339 key = SDLK_CAPSLOCK; | |
340 break; | |
341 case VK_SCROLL: | |
342 key = SDLK_SCROLLOCK; | |
343 break; | |
344 case VK_RSHIFT: | |
345 key = SDLK_RSHIFT; | |
346 break; | |
347 case VK_LSHIFT: | |
348 key = SDLK_LSHIFT; | |
349 break; | |
350 case VK_RCONTROL: | |
351 key = SDLK_RCTRL; | |
352 break; | |
353 case VK_LCONTROL: | |
354 key = SDLK_LCTRL; | |
355 break; | |
356 case VK_RMENU: | |
357 key = SDLK_RALT; | |
358 break; | |
359 case VK_LMENU: | |
360 key = SDLK_LALT; | |
361 break; | |
362 case VK_RWIN: | |
363 key = SDLK_RSUPER; | |
364 break; | |
365 case VK_LWIN: | |
366 key = SDLK_LSUPER; | |
367 break; | |
368 case VK_HELP: | |
369 key = SDLK_HELP; | |
370 break; | |
371 case VK_PRINT: | |
372 key = SDLK_PRINT; | |
373 break; | |
374 case VK_SNAPSHOT: | |
375 key = SDLK_PRINT; | |
376 break; | |
377 case VK_CANCEL: | |
378 key = SDLK_BREAK; | |
379 break; | |
380 case VK_APPS: | |
381 key = SDLK_MENU; | |
382 break; | |
383 default: | |
384 key = SDLK_UNKNOWN; | |
385 break; | |
386 } | |
387 return key; | |
388 } | |
27 | 389 |
28 LRESULT CALLBACK | 390 LRESULT CALLBACK |
29 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 391 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
30 { | 392 { |
31 SDL_WindowData *data; | 393 SDL_WindowData *data; |
33 /* Get the window data for the window */ | 395 /* Get the window data for the window */ |
34 data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); | 396 data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); |
35 if (!data) { | 397 if (!data) { |
36 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); | 398 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); |
37 } | 399 } |
38 #if 0 | 400 #ifdef WMMSG_DEBUG |
401 fprintf(stderr, "Received windows message: "); | |
402 if (msg > MAX_WMMSG) { | |
403 fprintf(stderr, "%d", msg); | |
404 } else { | |
405 fprintf(stderr, "%s", wmtab[msg]); | |
406 } | |
407 fprintf(stderr, " -- 0x%X, 0x%X\n", wParam, lParam); | |
408 #endif | |
409 | |
410 /* Send a SDL_SYSWMEVENT if the application wants them */ | |
411 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) { | |
412 SDL_SysWMmsg wmmsg; | |
413 | |
414 SDL_VERSION(&wmmsg.version); | |
415 wmmsg.hwnd = hwnd; | |
416 wmmsg.msg = msg; | |
417 wmmsg.wParam = wParam; | |
418 wmmsg.lParam = lParam; | |
419 SDL_SendSysWMEvent(&wmmsg); | |
420 } | |
421 | |
39 switch (msg) { | 422 switch (msg) { |
40 | 423 |
41 case WM_ACTIVATE: | 424 case WM_ACTIVATE: |
42 { | 425 { |
426 int index; | |
427 SDL_Keyboard *keyboard; | |
43 BOOL minimized; | 428 BOOL minimized; |
44 | 429 |
45 minimized = HIWORD(wParam); | 430 minimized = HIWORD(wParam); |
431 index = data->videodata->keyboard; | |
432 keyboard = SDL_GetKeyboard(index); | |
46 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { | 433 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { |
47 SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, | 434 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, |
48 0, 0); | 435 0, 0); |
49 SDL_PrivateWindowEvent(data->windowID, | 436 SDL_SendWindowEvent(data->windowID, |
50 SDL_WINDOWEVENT_RESTORED, 0, 0); | 437 SDL_WINDOWEVENT_RESTORED, 0, 0); |
51 if (IsZoomed(hwnd)) { | 438 if (IsZoomed(hwnd)) { |
52 SDL_PrivateWindowEvent(data->windowID, | 439 SDL_SendWindowEvent(data->windowID, |
53 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | 440 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); |
54 } | 441 } |
55 SDL_PrivateWindowEvent(data->windowID, | 442 if (keyboard && keyboard->focus != data->windowID) { |
56 SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); | 443 SDL_SetKeyboardFocus(index, data->windowID); |
444 } | |
57 /* FIXME: Restore mode state (mode, gamma, grab) */ | 445 /* FIXME: Restore mode state (mode, gamma, grab) */ |
58 /* FIXME: Update keyboard state */ | 446 /* FIXME: Update keyboard state */ |
59 } else { | 447 } else { |
60 SDL_PrivateWindowEvent(data->windowID, | 448 if (keyboard && keyboard->focus == data->windowID) { |
61 SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | 449 SDL_SetKeyboardFocus(index, 0); |
450 } | |
62 if (minimized) { | 451 if (minimized) { |
63 SDL_PrivateWindowEvent(data->windowID, | 452 SDL_SendWindowEvent(data->windowID, |
64 SDL_WINDOWEVENT_MINIMIZED, 0, 0); | 453 SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
65 } | 454 } |
66 /* FIXME: Restore desktop state (mode, gamma, grab) */ | 455 /* FIXME: Restore desktop state (mode, gamma, grab) */ |
67 } | 456 } |
68 return (0); | 457 return (0); |
69 } | 458 } |
71 | 460 |
72 case WM_MOUSEMOVE: | 461 case WM_MOUSEMOVE: |
73 { | 462 { |
74 int index; | 463 int index; |
75 SDL_Mouse *mouse; | 464 SDL_Mouse *mouse; |
76 | 465 int x, y; |
77 if (! | 466 |
78 (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_MOUSE_FOCUS)) | 467 index = data->videodata->mouse; |
79 { | 468 mouse = SDL_GetMouse(index); |
80 /* mouse has entered the window */ | 469 |
470 if (mouse->focus != data->windowID) { | |
81 TRACKMOUSEEVENT tme; | 471 TRACKMOUSEEVENT tme; |
82 | 472 |
83 tme.cbSize = sizeof(tme); | 473 tme.cbSize = sizeof(tme); |
84 tme.dwFlags = TME_LEAVE; | 474 tme.dwFlags = TME_LEAVE; |
85 tme.hwndTrack = hwnd; | 475 tme.hwndTrack = hwnd; |
86 TrackMouseEvent(&tme); | 476 TrackMouseEvent(&tme); |
87 | 477 |
88 SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_ENTER, | 478 SDL_SetMouseFocus(index, data->windowID); |
89 0, 0); | 479 } |
90 } | 480 |
481 /* mouse has moved within the window */ | |
482 x = LOWORD(lParam); | |
483 y = HIWORD(lParam); | |
484 if (mouse->relative_mode) { | |
485 int w, h; | |
486 POINT center; | |
487 SDL_GetWindowSize(data->windowID, &w, &h); | |
488 center.x = (w / 2); | |
489 center.y = (h / 2); | |
490 x -= center.x; | |
491 y -= center.y; | |
492 if (x || y) { | |
493 ClientToScreen(hwnd, ¢er); | |
494 SetCursorPos(center.x, center.y); | |
495 SDL_SendMouseMotion(index, 1, x, y); | |
496 } | |
497 } else { | |
498 SDL_SendMouseMotion(index, 0, x, y); | |
499 } | |
500 } | |
501 return (0); | |
502 | |
503 case WM_MOUSELEAVE: | |
504 { | |
505 int index; | |
506 SDL_Mouse *mouse; | |
91 | 507 |
92 index = data->videodata->mouse; | 508 index = data->videodata->mouse; |
93 mouse = SDL_GetMouse(index); | 509 mouse = SDL_GetMouse(index); |
94 if (mouse) { | 510 |
95 int x, y; | 511 if (mouse->focus == data->windowID) { |
96 /* mouse has moved within the window */ | 512 SDL_SetMouseFocus(index, 0); |
97 x = LOWORD(lParam); | 513 } |
98 y = HIWORD(lParam); | |
99 if (mouse->relative_mode) { | |
100 int w, h; | |
101 POINT center; | |
102 SDL_GetWindowSize(data->windowID, &w, &h); | |
103 center.x = (w / 2); | |
104 center.y = (h / 2); | |
105 x -= center.x; | |
106 y -= center.y; | |
107 if (x || y) { | |
108 ClientToScreen(SDL_Window, ¢er); | |
109 SetCursorPos(center.x, center.y); | |
110 SDL_SendMouseMotion(index, data->windowID, 1, x, y); | |
111 } | |
112 } else { | |
113 SDL_SendMouseMotion(index, data->windowID, 0, x, y); | |
114 } | |
115 } | |
116 } | |
117 return (0); | |
118 | |
119 case WM_MOUSELEAVE: | |
120 { | |
121 SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_LEAVE, 0, | |
122 0); | |
123 } | 514 } |
124 return (0); | 515 return (0); |
125 | 516 |
126 case WM_LBUTTONDOWN: | 517 case WM_LBUTTONDOWN: |
127 case WM_LBUTTONUP: | 518 case WM_LBUTTONUP: |
128 case WM_MBUTTONDOWN: | 519 case WM_MBUTTONDOWN: |
129 case WM_MBUTTONUP: | 520 case WM_MBUTTONUP: |
130 case WM_RBUTTONDOWN: | 521 case WM_RBUTTONDOWN: |
131 case WM_RBUTTONUP: | 522 case WM_RBUTTONUP: |
132 { | 523 { |
133 int x, y; | 524 int index; |
525 SDL_Mouse *mouse; | |
134 Uint8 button, state; | 526 Uint8 button, state; |
135 | 527 |
136 /* DJM: | 528 /* DJM: |
137 We want the SDL window to take focus so that | 529 We want the SDL window to take focus so that |
138 it acts like a normal windows "component" | 530 it acts like a normal windows "component" |
139 (e.g. gains keyboard focus on a mouse click). | 531 (e.g. gains keyboard focus on a mouse click). |
140 */ | 532 */ |
141 SetFocus(SDL_Window); | 533 SetFocus(hwnd); |
534 | |
535 index = data->videodata->mouse; | |
536 mouse = SDL_GetMouse(index); | |
142 | 537 |
143 /* Figure out which button to use */ | 538 /* Figure out which button to use */ |
144 switch (msg) { | 539 switch (msg) { |
145 case WM_LBUTTONDOWN: | 540 case WM_LBUTTONDOWN: |
146 button = SDL_BUTTON_LEFT; | 541 button = SDL_BUTTON_LEFT; |
170 /* Eh? Unknown button? */ | 565 /* Eh? Unknown button? */ |
171 return (0); | 566 return (0); |
172 } | 567 } |
173 if (state == SDL_PRESSED) { | 568 if (state == SDL_PRESSED) { |
174 /* Grab mouse so we get up events */ | 569 /* Grab mouse so we get up events */ |
175 if (++mouse_pressed > 0) { | 570 if (++data->mouse_pressed > 0) { |
176 SetCapture(hwnd); | 571 SetCapture(hwnd); |
177 } | 572 } |
178 } else { | 573 } else { |
179 /* Release mouse after all up events */ | 574 /* Release mouse after all up events */ |
180 if (--mouse_pressed <= 0) { | 575 if (--data->mouse_pressed <= 0) { |
181 ReleaseCapture(); | 576 ReleaseCapture(); |
182 mouse_pressed = 0; | 577 data->mouse_pressed = 0; |
183 } | 578 } |
184 } | 579 } |
185 x = LOWORD(lParam); | 580 |
186 y = HIWORD(lParam); | 581 if (!mouse->relative_mode) { |
187 #ifdef _WIN32_WCE | 582 int x, y; |
188 if (SDL_VideoSurface) | 583 x = LOWORD(lParam); |
189 GapiTransform(this->hidden->userOrientation, | 584 y = HIWORD(lParam); |
190 this->hidden->hiresFix, &x, &y); | 585 SDL_SendMouseMotion(index, 0, x, y); |
191 #endif | 586 } |
192 posted = SDL_PrivateMouseButton(state, button, x, y); | 587 SDL_SendMouseButton(index, state, button); |
193 } | 588 } |
194 | |
195 return (0); | 589 return (0); |
196 | 590 |
197 | |
198 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400) | |
199 case WM_MOUSEWHEEL: | 591 case WM_MOUSEWHEEL: |
200 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) { | 592 { |
201 int move = (short) HIWORD(wParam); | 593 int index; |
202 if (move) { | 594 int motion = (short) HIWORD(wParam); |
203 Uint8 button; | 595 |
204 if (move > 0) | 596 index = data->videodata->mouse; |
205 button = SDL_BUTTON_WHEELUP; | 597 SDL_SendMouseWheel(index, motion); |
598 } | |
599 return (0); | |
600 | |
601 case WM_SYSKEYDOWN: | |
602 case WM_KEYDOWN: | |
603 { | |
604 int index; | |
605 | |
606 /* Ignore repeated keys */ | |
607 if (lParam & REPEATED_KEYMASK) { | |
608 return (0); | |
609 } | |
610 | |
611 index = data->videodata->keyboard; | |
612 switch (wParam) { | |
613 case VK_CONTROL: | |
614 if (lParam & EXTENDED_KEYMASK) | |
615 wParam = VK_RCONTROL; | |
206 else | 616 else |
207 button = SDL_BUTTON_WHEELDOWN; | 617 wParam = VK_LCONTROL; |
208 posted = SDL_PrivateMouseButton(SDL_PRESSED, button, 0, 0); | 618 break; |
209 posted |= SDL_PrivateMouseButton(SDL_RELEASED, button, 0, 0); | 619 case VK_SHIFT: |
210 } | 620 /* EXTENDED trick doesn't work here */ |
621 { | |
622 Uint8 *state = SDL_GetKeyState(NULL); | |
623 if (state[SDLK_LSHIFT] == SDL_RELEASED | |
624 && (GetKeyState(VK_LSHIFT) & 0x8000)) { | |
625 wParam = VK_LSHIFT; | |
626 } else if (state[SDLK_RSHIFT] == SDL_RELEASED | |
627 && (GetKeyState(VK_RSHIFT) & 0x8000)) { | |
628 wParam = VK_RSHIFT; | |
629 } else { | |
630 /* Probably a key repeat */ | |
631 return (0); | |
632 } | |
633 } | |
634 break; | |
635 case VK_MENU: | |
636 if (lParam & EXTENDED_KEYMASK) | |
637 wParam = VK_RMENU; | |
638 else | |
639 wParam = VK_LMENU; | |
640 break; | |
641 } | |
642 SDL_SendKeyboardKey(index, SDL_PRESSED, (Uint8) HIWORD(lParam), | |
643 TranslateKey(wParam)); | |
211 } | 644 } |
212 return (0); | 645 return (0); |
213 #endif | 646 |
214 | 647 case WM_SYSKEYUP: |
215 #ifdef WM_GETMINMAXINFO | 648 case WM_KEYUP: |
216 /* This message is sent as a way for us to "check" the values | 649 { |
217 * of a position change. If we don't like it, we can adjust | 650 int index; |
218 * the values before they are changed. | 651 |
219 */ | 652 index = data->videodata->keyboard; |
653 switch (wParam) { | |
654 case VK_CONTROL: | |
655 if (lParam & EXTENDED_KEYMASK) | |
656 wParam = VK_RCONTROL; | |
657 else | |
658 wParam = VK_LCONTROL; | |
659 break; | |
660 case VK_SHIFT: | |
661 /* EXTENDED trick doesn't work here */ | |
662 { | |
663 Uint8 *state = SDL_GetKeyState(NULL); | |
664 if (state[SDLK_LSHIFT] == SDL_PRESSED | |
665 && !(GetKeyState(VK_LSHIFT) & 0x8000)) { | |
666 wParam = VK_LSHIFT; | |
667 } else if (state[SDLK_RSHIFT] == SDL_PRESSED | |
668 && !(GetKeyState(VK_RSHIFT) & 0x8000)) { | |
669 wParam = VK_RSHIFT; | |
670 } else { | |
671 /* Probably a key repeat */ | |
672 return (0); | |
673 } | |
674 } | |
675 break; | |
676 case VK_MENU: | |
677 if (lParam & EXTENDED_KEYMASK) | |
678 wParam = VK_RMENU; | |
679 else | |
680 wParam = VK_LMENU; | |
681 break; | |
682 } | |
683 /* Windows only reports keyup for print screen */ | |
684 if (wParam == VK_SNAPSHOT | |
685 && SDL_GetKeyState(NULL)[SDLK_PRINT] == SDL_RELEASED) { | |
686 SDL_SendKeyboardKey(index, SDL_PRESSED, | |
687 (Uint8) HIWORD(lParam), | |
688 TranslateKey(wParam)); | |
689 } | |
690 SDL_SendKeyboardKey(index, SDL_RELEASED, (Uint8) HIWORD(lParam), | |
691 TranslateKey(wParam)); | |
692 } | |
693 return (0); | |
694 | |
220 case WM_GETMINMAXINFO: | 695 case WM_GETMINMAXINFO: |
221 { | 696 { |
222 MINMAXINFO *info; | 697 MINMAXINFO *info; |
223 RECT size; | 698 RECT size; |
224 int x, y; | 699 int x, y; |
700 int w, h; | |
225 int style; | 701 int style; |
226 int width; | 702 |
227 int height; | 703 /* If we allow resizing, let the resize happen naturally */ |
228 | 704 if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_RESIZABLE) { |
229 /* We don't want to clobber an internal resize */ | |
230 if (SDL_resizing) | |
231 return (0); | 705 return (0); |
232 | |
233 /* We allow resizing with the SDL_RESIZABLE flag */ | |
234 if (SDL_PublicSurface | |
235 && (SDL_PublicSurface->flags & SDL_RESIZABLE)) { | |
236 return (0); | |
237 } | 706 } |
238 | 707 |
239 /* Get the current position of our window */ | 708 /* Get the current position of our window */ |
240 GetWindowRect(SDL_Window, &size); | 709 GetWindowRect(hwnd, &size); |
241 x = size.left; | 710 x = size.left; |
242 y = size.top; | 711 y = size.top; |
243 | 712 |
244 /* Calculate current width and height of our window */ | 713 /* Calculate current size of our window */ |
714 SDL_GetWindowSize(data->windowID, &w, &h); | |
245 size.top = 0; | 715 size.top = 0; |
246 size.left = 0; | 716 size.left = 0; |
247 if (SDL_PublicSurface != NULL) { | 717 size.bottom = h; |
248 size.bottom = SDL_PublicSurface->h; | 718 size.right = w; |
249 size.right = SDL_PublicSurface->w; | |
250 } else { | |
251 size.bottom = 0; | |
252 size.right = 0; | |
253 } | |
254 | 719 |
255 /* DJM - according to the docs for GetMenu(), the | 720 /* DJM - according to the docs for GetMenu(), the |
256 return value is undefined if hwnd is a child window. | 721 return value is undefined if hwnd is a child window. |
257 Aparently it's too difficult for MS to check | 722 Aparently it's too difficult for MS to check |
258 inside their function, so I have to do it here. | 723 inside their function, so I have to do it here. |
261 AdjustWindowRect(&size, | 726 AdjustWindowRect(&size, |
262 style, | 727 style, |
263 style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) != | 728 style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) != |
264 NULL); | 729 NULL); |
265 | 730 |
266 width = size.right - size.left; | 731 w = size.right - size.left; |
267 height = size.bottom - size.top; | 732 h = size.bottom - size.top; |
268 | 733 |
269 /* Fix our size to the current size */ | 734 /* Fix our size to the current size */ |
270 info = (MINMAXINFO *) lParam; | 735 info = (MINMAXINFO *) lParam; |
271 info->ptMaxSize.x = width; | 736 info->ptMaxSize.x = w; |
272 info->ptMaxSize.y = height; | 737 info->ptMaxSize.y = h; |
273 info->ptMaxPosition.x = x; | 738 info->ptMaxPosition.x = x; |
274 info->ptMaxPosition.y = y; | 739 info->ptMaxPosition.y = y; |
275 info->ptMinTrackSize.x = width; | 740 info->ptMinTrackSize.x = w; |
276 info->ptMinTrackSize.y = height; | 741 info->ptMinTrackSize.y = h; |
277 info->ptMaxTrackSize.x = width; | 742 info->ptMaxTrackSize.x = w; |
278 info->ptMaxTrackSize.y = height; | 743 info->ptMaxTrackSize.y = h; |
279 } | 744 } |
280 | |
281 return (0); | 745 return (0); |
282 #endif /* WM_GETMINMAXINFO */ | |
283 | 746 |
284 case WM_WINDOWPOSCHANGED: | 747 case WM_WINDOWPOSCHANGED: |
285 { | 748 { |
286 SDL_VideoDevice *this = current_video; | 749 RECT rect; |
750 int x, y; | |
287 int w, h; | 751 int w, h; |
288 | 752 |
289 GetClientRect(SDL_Window, &SDL_bounds); | 753 GetClientRect(hwnd, &rect); |
290 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds); | 754 ClientToScreen(hwnd, (LPPOINT) & rect); |
291 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds + 1); | 755 ClientToScreen(hwnd, (LPPOINT) & rect + 1); |
292 if (!SDL_resizing && !IsZoomed(SDL_Window) && | 756 |
293 SDL_PublicSurface | 757 if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_INPUT_GRABBED) { |
294 && !(SDL_PublicSurface->flags & SDL_FULLSCREEN)) { | 758 ClipCursor(&rect); |
295 SDL_windowX = SDL_bounds.left; | 759 } |
296 SDL_windowY = SDL_bounds.top; | 760 |
297 } | 761 x = rect.left; |
298 w = SDL_bounds.right - SDL_bounds.left; | 762 y = rect.top; |
299 h = SDL_bounds.bottom - SDL_bounds.top; | 763 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MOVED, x, y); |
300 if (this->input_grab != SDL_GRAB_OFF) { | 764 |
301 ClipCursor(&SDL_bounds); | 765 w = rect.right - rect.left; |
302 } | 766 h = rect.bottom - rect.top; |
303 if (SDL_PublicSurface | 767 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESIZED, w, |
304 && (SDL_PublicSurface->flags & SDL_RESIZABLE)) { | 768 h); |
305 SDL_PrivateResize(w, h); | 769 } |
306 } | 770 break; |
307 } | 771 |
308 | |
309 break; | |
310 | |
311 /* We need to set the cursor */ | |
312 case WM_SETCURSOR: | 772 case WM_SETCURSOR: |
313 { | 773 { |
314 Uint16 hittest; | 774 /* |
315 | 775 Uint16 hittest; |
316 hittest = LOWORD(lParam); | 776 |
317 if (hittest == HTCLIENT) { | 777 hittest = LOWORD(lParam); |
318 SetCursor(SDL_hcursor); | 778 if (hittest == HTCLIENT) { |
319 return (TRUE); | 779 SetCursor(SDL_hcursor); |
320 } | 780 return (TRUE); |
321 } | 781 } |
322 | 782 */ |
783 } | |
323 break; | 784 break; |
324 | 785 |
325 /* We are about to get palette focus! */ | 786 /* We are about to get palette focus! */ |
326 case WM_QUERYNEWPALETTE: | 787 case WM_QUERYNEWPALETTE: |
327 { | 788 { |
328 WIN_RealizePalette(current_video); | 789 /* |
329 return (TRUE); | 790 WIN_RealizePalette(current_video); |
330 } | 791 return (TRUE); |
331 | 792 */ |
793 } | |
332 break; | 794 break; |
333 | 795 |
334 /* Another application changed the palette */ | 796 /* Another application changed the palette */ |
335 case WM_PALETTECHANGED: | 797 case WM_PALETTECHANGED: |
336 { | 798 { |
337 WIN_PaletteChanged(current_video, (HWND) wParam); | 799 /* |
338 } | 800 WIN_PaletteChanged(current_video, (HWND) wParam); |
339 | 801 */ |
802 } | |
340 break; | 803 break; |
341 | 804 |
342 /* We were occluded, refresh our display */ | 805 /* We were occluded, refresh our display */ |
343 case WM_PAINT: | 806 case WM_PAINT: |
344 { | 807 { |
345 HDC hdc; | 808 RECT rect; |
346 PAINTSTRUCT ps; | 809 if (GetUpdateRect(hwnd, &rect, FALSE)) { |
347 | 810 ValidateRect(hwnd, &rect); |
348 hdc = BeginPaint(SDL_Window, &ps); | 811 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED, |
349 if (current_video->screen && | 812 0, 0); |
350 !(current_video->screen->flags & SDL_INTERNALOPENGL)) { | 813 } |
351 WIN_WinPAINT(current_video, hdc); | 814 } |
352 } | |
353 EndPaint(SDL_Window, &ps); | |
354 } | |
355 | |
356 return (0); | 815 return (0); |
357 | 816 |
358 /* DJM: Send an expose event in this case */ | 817 case WM_SYSCOMMAND: |
359 case WM_ERASEBKGND: | 818 { |
360 { | 819 /* Don't start the screensaver or blank the monitor in fullscreen apps */ |
361 posted = SDL_PrivateExpose(); | 820 if ((wParam & 0xFFF0) == SC_SCREENSAVE || |
362 } | 821 (wParam & 0xFFF0) == SC_MONITORPOWER) { |
363 | 822 if (SDL_GetWindowFlags(data->windowID) & |
823 SDL_WINDOW_FULLSCREEN) { | |
824 return (0); | |
825 } | |
826 } | |
827 } | |
828 break; | |
829 | |
830 case WM_CLOSE: | |
831 { | |
832 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0, 0); | |
833 } | |
364 return (0); | 834 return (0); |
365 | 835 } |
366 case WM_CLOSE: | |
367 { | |
368 if ((posted = SDL_PrivateQuit())) | |
369 PostQuitMessage(0); | |
370 } | |
371 | |
372 return (0); | |
373 | |
374 case WM_DESTROY: | |
375 { | |
376 PostQuitMessage(0); | |
377 } | |
378 | |
379 return (0); | |
380 } | |
381 #endif | |
382 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); | 836 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); |
383 } | 837 } |
384 | 838 |
385 void | 839 void |
386 WIN_PumpEvents(_THIS) | 840 WIN_PumpEvents(_THIS) |