Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32events.c @ 4661:03dcb795c583
Merged changes from the main SDL codebase
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 12 Jul 2010 21:09:23 -0700 |
parents | 7ad7a473b086 9faebccfefb3 |
children | c24ba2cc9583 |
comparison
equal
deleted
inserted
replaced
4660:b15e7017409b | 4661:03dcb795c583 |
---|---|
58 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) | 58 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) |
59 #endif | 59 #endif |
60 #ifndef WM_INPUT | 60 #ifndef WM_INPUT |
61 #define WM_INPUT 0x00ff | 61 #define WM_INPUT 0x00ff |
62 #endif | 62 #endif |
63 | |
64 extern HCTX *g_hCtx; | |
65 extern HANDLE *mice; | |
66 extern int total_mice; | |
67 extern int tablet; | |
68 int pressure = 0; /* the pressure reported by the tablet */ | |
69 | 63 |
70 static WPARAM | 64 static WPARAM |
71 RemapVKEY(WPARAM wParam, LPARAM lParam) | 65 RemapVKEY(WPARAM wParam, LPARAM lParam) |
72 { | 66 { |
73 int i; | 67 int i; |
105 | 99 |
106 LRESULT CALLBACK | 100 LRESULT CALLBACK |
107 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 101 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
108 { | 102 { |
109 SDL_WindowData *data; | 103 SDL_WindowData *data; |
110 RAWINPUT *raw; | |
111 PACKET packet; | |
112 LRESULT returnCode = -1; | 104 LRESULT returnCode = -1; |
113 | 105 |
114 /* Send a SDL_SYSWMEVENT if the application wants them */ | 106 /* Send a SDL_SYSWMEVENT if the application wants them */ |
115 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { | 107 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) { |
116 SDL_SysWMmsg wmmsg; | 108 SDL_SysWMmsg wmmsg; |
144 | 136 |
145 #endif | 137 #endif |
146 | 138 |
147 switch (msg) { | 139 switch (msg) { |
148 | 140 |
149 case WT_PACKET: | |
150 { | |
151 /* if we receive such data we need to update the pressure */ | |
152 SDL_VideoData *videodata = data->videodata; | |
153 if (videodata->wintabDLL | |
154 && videodata->WTPacket((HCTX) lParam, (UINT) wParam, &packet)) { | |
155 SDL_ChangeEnd(tablet, (int) packet.pkCursor); | |
156 pressure = (int) packet.pkNormalPressure; | |
157 } | |
158 } | |
159 break; | |
160 | |
161 case WT_PROXIMITY: | |
162 { | |
163 /* checking where the proximity message showed up */ | |
164 int h_context = LOWORD(lParam); | |
165 POINT point; | |
166 GetCursorPos(&point); | |
167 ScreenToClient(hwnd, &point); | |
168 | |
169 /* are we in proximity or out of proximity */ | |
170 if (h_context == 0) { | |
171 SDL_SendProximity(tablet, point.x, point.y, SDL_PROXIMITYOUT); | |
172 } else { | |
173 SDL_SendProximity(tablet, point.x, point.y, SDL_PROXIMITYIN); | |
174 } | |
175 } | |
176 break; | |
177 | |
178 case WM_SHOWWINDOW: | 141 case WM_SHOWWINDOW: |
179 { | 142 { |
180 if (wParam) { | 143 if (wParam) { |
181 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); | 144 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); |
182 } else { | 145 } else { |
185 } | 148 } |
186 break; | 149 break; |
187 | 150 |
188 case WM_ACTIVATE: | 151 case WM_ACTIVATE: |
189 { | 152 { |
190 int index; | |
191 SDL_Keyboard *keyboard; | |
192 BOOL minimized; | 153 BOOL minimized; |
193 | 154 |
194 minimized = HIWORD(wParam); | 155 minimized = HIWORD(wParam); |
195 index = data->videodata->keyboard; | |
196 keyboard = SDL_GetKeyboard(index); | |
197 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { | 156 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { |
198 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); | 157 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0); |
199 SDL_SendWindowEvent(data->window, | 158 SDL_SendWindowEvent(data->window, |
200 SDL_WINDOWEVENT_RESTORED, 0, 0); | 159 SDL_WINDOWEVENT_RESTORED, 0, 0); |
201 #ifndef _WIN32_WCE /* WinCE misses IsZoomed() */ | 160 #ifndef _WIN32_WCE /* WinCE misses IsZoomed() */ |
202 if (IsZoomed(hwnd)) { | 161 if (IsZoomed(hwnd)) { |
203 SDL_SendWindowEvent(data->window, | 162 SDL_SendWindowEvent(data->window, |
204 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | 163 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); |
205 } | 164 } |
206 #endif | 165 #endif |
207 if (keyboard && keyboard->focus != data->window) { | 166 if (SDL_GetKeyboardFocus() != data->window) { |
208 SDL_SetKeyboardFocus(index, data->window); | 167 SDL_SetKeyboardFocus(data->window); |
209 } | 168 } |
210 /* FIXME: Update keyboard state */ | 169 /* |
170 * FIXME: Update keyboard state | |
171 */ | |
172 WIN_CheckClipboardUpdate(data->videodata); | |
211 } else { | 173 } else { |
212 if (keyboard && keyboard->focus == data->window) { | 174 if (SDL_GetKeyboardFocus() == data->window) { |
213 SDL_SetKeyboardFocus(index, 0); | 175 SDL_SetKeyboardFocus(NULL); |
214 } | 176 } |
215 if (minimized) { | 177 if (minimized) { |
216 SDL_SendWindowEvent(data->window, | 178 SDL_SendWindowEvent(data->window, |
217 SDL_WINDOWEVENT_MINIMIZED, 0, 0); | 179 SDL_WINDOWEVENT_MINIMIZED, 0, 0); |
218 } | 180 } |
219 } | 181 } |
220 } | 182 } |
221 returnCode = 0; | 183 returnCode = 0; |
222 break; | 184 break; |
223 | 185 |
224 /* WinCE has no RawInput, so we use the classic mouse events. | 186 case WM_MOUSEMOVE: |
225 In classic Win32 this is done by WM_INPUT | 187 SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); |
226 */ | |
227 #ifdef _WIN32_WCE | |
228 case WM_MOUSEMOVE: | |
229 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); | |
230 break; | 188 break; |
231 | 189 |
232 case WM_LBUTTONDOWN: | 190 case WM_LBUTTONDOWN: |
233 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); | 191 SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT); |
234 SDL_SendMouseButton(0, SDL_PRESSED, SDL_BUTTON_LEFT); | |
235 break; | 192 break; |
236 | 193 |
237 case WM_LBUTTONUP: | 194 case WM_LBUTTONUP: |
238 SDL_SendMouseMotion(0, 0, LOWORD(lParam), HIWORD(lParam), 0); | 195 SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT); |
239 SDL_SendMouseButton(0, SDL_RELEASED, SDL_BUTTON_LEFT); | 196 break; |
240 break; | |
241 #else /* _WIN32_WCE */ | |
242 | |
243 case WM_INPUT: /* mouse events */ | |
244 { | |
245 LPBYTE lpb; | |
246 const RAWINPUTHEADER *header; | |
247 int index = -1; | |
248 int i; | |
249 int size = 0; | |
250 const RAWMOUSE *raw_mouse = NULL; | |
251 POINT point; | |
252 USHORT flags; | |
253 int w, h; | |
254 | |
255 /* we're collecting raw data to be able to identify the mouse (if there are several) */ | |
256 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size, | |
257 sizeof(RAWINPUTHEADER)); | |
258 lpb = SDL_stack_alloc(BYTE, size); | |
259 GetRawInputData((HRAWINPUT) lParam, RID_INPUT, lpb, &size, | |
260 sizeof(RAWINPUTHEADER)); | |
261 raw = (RAWINPUT *) lpb; | |
262 header = &raw->header; | |
263 flags = raw->data.mouse.usButtonFlags; | |
264 | |
265 /* we're checking which mouse generated the event */ | |
266 for (i = 0; i < total_mice; ++i) { | |
267 if (mice[i] == header->hDevice) { | |
268 index = i; | |
269 break; | |
270 } | |
271 } | |
272 if (index < 0) { | |
273 /* New mouse? Should we dynamically update mouse list? */ | |
274 returnCode = 0; | |
275 break; | |
276 } | |
277 | |
278 GetCursorPos(&point); | |
279 ScreenToClient(hwnd, &point); | |
280 | |
281 SDL_GetWindowSize(data->window, &w, &h); | |
282 if (point.x >= 0 && point.y >= 0 && point.x < w && point.y < h) { | |
283 SDL_SetMouseFocus(index, data->window); | |
284 } else { | |
285 SDL_SetMouseFocus(index, 0); | |
286 /* FIXME: Should we be doing anything else here? */ | |
287 break; | |
288 } | |
289 | |
290 /* if the message was sent by a tablet we have to send also pressure */ | |
291 if (index == tablet) { | |
292 SDL_SendMouseMotion(index, 0, point.x, point.y, pressure); | |
293 } else { | |
294 SDL_SendMouseMotion(index, 0, point.x, point.y, 0); | |
295 } | |
296 /* we're sending mouse buttons messages to check up if sth changed */ | |
297 if (flags & RI_MOUSE_LEFT_BUTTON_DOWN) { | |
298 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_LEFT); | |
299 } else if (flags & RI_MOUSE_LEFT_BUTTON_UP) { | |
300 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_LEFT); | |
301 } | |
302 if (flags & RI_MOUSE_MIDDLE_BUTTON_DOWN) { | |
303 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_MIDDLE); | |
304 } else if (flags & RI_MOUSE_MIDDLE_BUTTON_UP) { | |
305 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_MIDDLE); | |
306 } | |
307 if (flags & RI_MOUSE_RIGHT_BUTTON_DOWN) { | |
308 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_RIGHT); | |
309 } else if (flags & RI_MOUSE_RIGHT_BUTTON_UP) { | |
310 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_RIGHT); | |
311 } | |
312 if (flags & RI_MOUSE_BUTTON_4_DOWN) { | |
313 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_X1); | |
314 } else if (flags & RI_MOUSE_BUTTON_4_UP) { | |
315 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_X1); | |
316 } | |
317 if (flags & RI_MOUSE_BUTTON_5_DOWN) { | |
318 SDL_SendMouseButton(index, SDL_PRESSED, SDL_BUTTON_X2); | |
319 } else if (flags & RI_MOUSE_BUTTON_5_UP) { | |
320 SDL_SendMouseButton(index, SDL_RELEASED, SDL_BUTTON_X2); | |
321 } | |
322 if (flags & RI_MOUSE_WHEEL) { | |
323 SDL_SendMouseWheel(index, 0, | |
324 (short) raw->data.mouse.usButtonData); | |
325 } | |
326 SDL_stack_free(lpb); | |
327 } | |
328 returnCode = 0; | |
329 break; | |
330 #endif /* _WIN32_WCE */ | |
331 | 197 |
332 case WM_MOUSELEAVE: | 198 case WM_MOUSELEAVE: |
333 { | 199 if (SDL_GetMouseFocus() == data->window) { |
334 int i; | 200 SDL_SetMouseFocus(NULL); |
335 | |
336 for (i = 0; i < SDL_GetNumMice(); ++i) { | |
337 SDL_Mouse *mouse = SDL_GetMouse(i); | |
338 | |
339 if (mouse->focus == data->window) { | |
340 SDL_SetMouseFocus(i, 0); | |
341 } | |
342 } | |
343 } | 201 } |
344 returnCode = 0; | 202 returnCode = 0; |
345 break; | 203 break; |
346 | 204 |
347 case WM_SYSKEYDOWN: | 205 case WM_SYSKEYDOWN: |
348 case WM_KEYDOWN: | 206 case WM_KEYDOWN: |
349 { | 207 { |
350 int index; | |
351 | |
352 /* Ignore repeated keys */ | 208 /* Ignore repeated keys */ |
353 if (lParam & REPEATED_KEYMASK) { | 209 if (lParam & REPEATED_KEYMASK) { |
354 returnCode = 0; | 210 returnCode = 0; |
355 break; | 211 break; |
356 } | 212 } |
357 | 213 |
358 index = data->videodata->keyboard; | |
359 wParam = RemapVKEY(wParam, lParam); | 214 wParam = RemapVKEY(wParam, lParam); |
360 switch (wParam) { | 215 switch (wParam) { |
361 case VK_CONTROL: | 216 case VK_CONTROL: |
362 if (lParam & EXTENDED_KEYMASK) | 217 if (lParam & EXTENDED_KEYMASK) |
363 wParam = VK_RCONTROL; | 218 wParam = VK_RCONTROL; |
390 if (lParam & EXTENDED_KEYMASK) | 245 if (lParam & EXTENDED_KEYMASK) |
391 wParam = VK_ENTER; | 246 wParam = VK_ENTER; |
392 break; | 247 break; |
393 } | 248 } |
394 if (wParam < 256) { | 249 if (wParam < 256) { |
395 SDL_SendKeyboardKey(index, SDL_PRESSED, | 250 SDL_SendKeyboardKey(SDL_PRESSED, |
396 data->videodata->key_layout[wParam]); | 251 data->videodata->key_layout[wParam]); |
397 } | 252 } |
398 } | 253 } |
399 returnCode = 0; | 254 returnCode = 0; |
400 break; | 255 break; |
401 | 256 |
402 case WM_SYSKEYUP: | 257 case WM_SYSKEYUP: |
403 case WM_KEYUP: | 258 case WM_KEYUP: |
404 { | 259 { |
405 int index; | |
406 | |
407 index = data->videodata->keyboard; | |
408 wParam = RemapVKEY(wParam, lParam); | 260 wParam = RemapVKEY(wParam, lParam); |
409 switch (wParam) { | 261 switch (wParam) { |
410 case VK_CONTROL: | 262 case VK_CONTROL: |
411 if (lParam & EXTENDED_KEYMASK) | 263 if (lParam & EXTENDED_KEYMASK) |
412 wParam = VK_RCONTROL; | 264 wParam = VK_RCONTROL; |
443 | 295 |
444 /* Windows only reports keyup for print screen */ | 296 /* Windows only reports keyup for print screen */ |
445 if (wParam == VK_SNAPSHOT | 297 if (wParam == VK_SNAPSHOT |
446 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == | 298 && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] == |
447 SDL_RELEASED) { | 299 SDL_RELEASED) { |
448 SDL_SendKeyboardKey(index, SDL_PRESSED, | 300 SDL_SendKeyboardKey(SDL_PRESSED, |
449 data->videodata->key_layout[wParam]); | 301 data->videodata->key_layout[wParam]); |
450 } | 302 } |
451 if (wParam < 256) { | 303 if (wParam < 256) { |
452 SDL_SendKeyboardKey(index, SDL_RELEASED, | 304 SDL_SendKeyboardKey(SDL_RELEASED, |
453 data->videodata->key_layout[wParam]); | 305 data->videodata->key_layout[wParam]); |
454 } | 306 } |
455 } | 307 } |
456 returnCode = 0; | 308 returnCode = 0; |
457 break; | 309 break; |
472 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F); | 324 text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F); |
473 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F); | 325 text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F); |
474 text[2] = 0x80 | (char) (wParam & 0x3F); | 326 text[2] = 0x80 | (char) (wParam & 0x3F); |
475 text[3] = '\0'; | 327 text[3] = '\0'; |
476 } | 328 } |
477 SDL_SendKeyboardText(data->videodata->keyboard, text); | 329 SDL_SendKeyboardText(text); |
478 } | 330 } |
479 returnCode = 0; | 331 returnCode = 0; |
480 break; | 332 break; |
481 | 333 |
482 case WM_INPUTLANGCHANGE: | 334 case WM_INPUTLANGCHANGE: |
483 { | 335 { |
484 WIN_UpdateKeymap(data->videodata->keyboard); | 336 WIN_UpdateKeymap(); |
485 } | 337 } |
486 returnCode = 1; | 338 returnCode = 1; |
487 break; | 339 break; |
488 | 340 |
489 case WM_GETMINMAXINFO: | 341 case WM_GETMINMAXINFO: |
770 SDL_free(SDL_Appname); | 622 SDL_free(SDL_Appname); |
771 SDL_Appname = NULL; | 623 SDL_Appname = NULL; |
772 } | 624 } |
773 } | 625 } |
774 | 626 |
775 /* Sets an error message based on GetLastError() */ | |
776 void | |
777 WIN_SetError(const char *prefix) | |
778 { | |
779 TCHAR buffer[1024]; | |
780 char *message; | |
781 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | |
782 buffer, SDL_arraysize(buffer), NULL); | |
783 message = WIN_StringToUTF8(buffer); | |
784 SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); | |
785 SDL_free(message); | |
786 } | |
787 | |
788 /* vi: set ts=4 sw=4 expandtab: */ | 627 /* vi: set ts=4 sw=4 expandtab: */ |