Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32events.c @ 1722:5daa04d862f1 SDL-1.3
Added a userdata parameter for event filters.
Added a function to filter the existing queued events.
Added explicit support for relative mouse mode to the API.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 30 Jun 2006 08:18:44 +0000 |
parents | 5b9f50c957ed |
children | 6c63fc2bd986 |
comparison
equal
deleted
inserted
replaced
1721:1cc762cafff8 | 1722:5daa04d862f1 |
---|---|
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 "../../events/SDL_events_c.h" | |
25 | 26 |
26 | 27 |
27 LRESULT CALLBACK | 28 LRESULT CALLBACK |
28 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 29 WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
29 { | 30 { |
30 SDL_WindowData *data; | 31 SDL_WindowData *data; |
31 SDL_Window *window; | |
32 | 32 |
33 /* Get the window data for the window */ | 33 /* Get the window data for the window */ |
34 data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); | 34 data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData")); |
35 if (!data) { | 35 if (!data) { |
36 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); | 36 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam); |
37 } | 37 } |
38 window = data->window; | 38 #if 0 |
39 | 39 switch (msg) { |
40 | |
41 case WM_ACTIVATE: | |
42 { | |
43 BOOL minimized; | |
44 | |
45 minimized = HIWORD(wParam); | |
46 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) { | |
47 SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, | |
48 0, 0); | |
49 SDL_PrivateWindowEvent(data->windowID, | |
50 SDL_WINDOWEVENT_RESTORED, 0, 0); | |
51 if (IsZoomed(hwnd)) { | |
52 SDL_PrivateWindowEvent(data->windowID, | |
53 SDL_WINDOWEVENT_MAXIMIZED, 0, 0); | |
54 } | |
55 SDL_PrivateWindowEvent(data->windowID, | |
56 SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); | |
57 /* FIXME: Restore mode state (mode, gamma, grab) */ | |
58 /* FIXME: Update keyboard state */ | |
59 } else { | |
60 SDL_PrivateWindowEvent(data->windowID, | |
61 SDL_WINDOWEVENT_FOCUS_LOST, 0, 0); | |
62 if (minimized) { | |
63 SDL_PrivateWindowEvent(data->windowID, | |
64 SDL_WINDOWEVENT_MINIMIZED, 0, 0); | |
65 } | |
66 /* FIXME: Restore desktop state (mode, gamma, grab) */ | |
67 } | |
68 return (0); | |
69 } | |
70 break; | |
71 | |
72 case WM_MOUSEMOVE: | |
73 { | |
74 int index; | |
75 SDL_Mouse *mouse; | |
76 | |
77 if (! | |
78 (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_MOUSE_FOCUS)) | |
79 { | |
80 /* mouse has entered the window */ | |
81 TRACKMOUSEEVENT tme; | |
82 | |
83 tme.cbSize = sizeof(tme); | |
84 tme.dwFlags = TME_LEAVE; | |
85 tme.hwndTrack = hwnd; | |
86 TrackMouseEvent(&tme); | |
87 | |
88 SDL_PrivateWindowEvent(data->windowID, SDL_WINDOWEVENT_ENTER, | |
89 0, 0); | |
90 } | |
91 | |
92 index = data->videodata->mouse; | |
93 mouse = SDL_GetMouse(index); | |
94 if (mouse) { | |
95 int x, y; | |
96 /* mouse has moved within the window */ | |
97 x = LOWORD(lParam); | |
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 } | |
124 return (0); | |
125 | |
126 case WM_LBUTTONDOWN: | |
127 case WM_LBUTTONUP: | |
128 case WM_MBUTTONDOWN: | |
129 case WM_MBUTTONUP: | |
130 case WM_RBUTTONDOWN: | |
131 case WM_RBUTTONUP: | |
132 { | |
133 int x, y; | |
134 Uint8 button, state; | |
135 | |
136 /* DJM: | |
137 We want the SDL window to take focus so that | |
138 it acts like a normal windows "component" | |
139 (e.g. gains keyboard focus on a mouse click). | |
140 */ | |
141 SetFocus(SDL_Window); | |
142 | |
143 /* Figure out which button to use */ | |
144 switch (msg) { | |
145 case WM_LBUTTONDOWN: | |
146 button = SDL_BUTTON_LEFT; | |
147 state = SDL_PRESSED; | |
148 break; | |
149 case WM_LBUTTONUP: | |
150 button = SDL_BUTTON_LEFT; | |
151 state = SDL_RELEASED; | |
152 break; | |
153 case WM_MBUTTONDOWN: | |
154 button = SDL_BUTTON_MIDDLE; | |
155 state = SDL_PRESSED; | |
156 break; | |
157 case WM_MBUTTONUP: | |
158 button = SDL_BUTTON_MIDDLE; | |
159 state = SDL_RELEASED; | |
160 break; | |
161 case WM_RBUTTONDOWN: | |
162 button = SDL_BUTTON_RIGHT; | |
163 state = SDL_PRESSED; | |
164 break; | |
165 case WM_RBUTTONUP: | |
166 button = SDL_BUTTON_RIGHT; | |
167 state = SDL_RELEASED; | |
168 break; | |
169 default: | |
170 /* Eh? Unknown button? */ | |
171 return (0); | |
172 } | |
173 if (state == SDL_PRESSED) { | |
174 /* Grab mouse so we get up events */ | |
175 if (++mouse_pressed > 0) { | |
176 SetCapture(hwnd); | |
177 } | |
178 } else { | |
179 /* Release mouse after all up events */ | |
180 if (--mouse_pressed <= 0) { | |
181 ReleaseCapture(); | |
182 mouse_pressed = 0; | |
183 } | |
184 } | |
185 x = LOWORD(lParam); | |
186 y = HIWORD(lParam); | |
187 #ifdef _WIN32_WCE | |
188 if (SDL_VideoSurface) | |
189 GapiTransform(this->hidden->userOrientation, | |
190 this->hidden->hiresFix, &x, &y); | |
191 #endif | |
192 posted = SDL_PrivateMouseButton(state, button, x, y); | |
193 } | |
194 | |
195 return (0); | |
196 | |
197 | |
198 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400) | |
199 case WM_MOUSEWHEEL: | |
200 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) { | |
201 int move = (short) HIWORD(wParam); | |
202 if (move) { | |
203 Uint8 button; | |
204 if (move > 0) | |
205 button = SDL_BUTTON_WHEELUP; | |
206 else | |
207 button = SDL_BUTTON_WHEELDOWN; | |
208 posted = SDL_PrivateMouseButton(SDL_PRESSED, button, 0, 0); | |
209 posted |= SDL_PrivateMouseButton(SDL_RELEASED, button, 0, 0); | |
210 } | |
211 } | |
212 return (0); | |
213 #endif | |
214 | |
215 #ifdef WM_GETMINMAXINFO | |
216 /* This message is sent as a way for us to "check" the values | |
217 * of a position change. If we don't like it, we can adjust | |
218 * the values before they are changed. | |
219 */ | |
220 case WM_GETMINMAXINFO: | |
221 { | |
222 MINMAXINFO *info; | |
223 RECT size; | |
224 int x, y; | |
225 int style; | |
226 int width; | |
227 int height; | |
228 | |
229 /* We don't want to clobber an internal resize */ | |
230 if (SDL_resizing) | |
231 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 } | |
238 | |
239 /* Get the current position of our window */ | |
240 GetWindowRect(SDL_Window, &size); | |
241 x = size.left; | |
242 y = size.top; | |
243 | |
244 /* Calculate current width and height of our window */ | |
245 size.top = 0; | |
246 size.left = 0; | |
247 if (SDL_PublicSurface != NULL) { | |
248 size.bottom = SDL_PublicSurface->h; | |
249 size.right = SDL_PublicSurface->w; | |
250 } else { | |
251 size.bottom = 0; | |
252 size.right = 0; | |
253 } | |
254 | |
255 /* DJM - according to the docs for GetMenu(), the | |
256 return value is undefined if hwnd is a child window. | |
257 Aparently it's too difficult for MS to check | |
258 inside their function, so I have to do it here. | |
259 */ | |
260 style = GetWindowLong(hwnd, GWL_STYLE); | |
261 AdjustWindowRect(&size, | |
262 style, | |
263 style & WS_CHILDWINDOW ? FALSE : GetMenu(hwnd) != | |
264 NULL); | |
265 | |
266 width = size.right - size.left; | |
267 height = size.bottom - size.top; | |
268 | |
269 /* Fix our size to the current size */ | |
270 info = (MINMAXINFO *) lParam; | |
271 info->ptMaxSize.x = width; | |
272 info->ptMaxSize.y = height; | |
273 info->ptMaxPosition.x = x; | |
274 info->ptMaxPosition.y = y; | |
275 info->ptMinTrackSize.x = width; | |
276 info->ptMinTrackSize.y = height; | |
277 info->ptMaxTrackSize.x = width; | |
278 info->ptMaxTrackSize.y = height; | |
279 } | |
280 | |
281 return (0); | |
282 #endif /* WM_GETMINMAXINFO */ | |
283 | |
284 case WM_WINDOWPOSCHANGED: | |
285 { | |
286 SDL_VideoDevice *this = current_video; | |
287 int w, h; | |
288 | |
289 GetClientRect(SDL_Window, &SDL_bounds); | |
290 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds); | |
291 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds + 1); | |
292 if (!SDL_resizing && !IsZoomed(SDL_Window) && | |
293 SDL_PublicSurface | |
294 && !(SDL_PublicSurface->flags & SDL_FULLSCREEN)) { | |
295 SDL_windowX = SDL_bounds.left; | |
296 SDL_windowY = SDL_bounds.top; | |
297 } | |
298 w = SDL_bounds.right - SDL_bounds.left; | |
299 h = SDL_bounds.bottom - SDL_bounds.top; | |
300 if (this->input_grab != SDL_GRAB_OFF) { | |
301 ClipCursor(&SDL_bounds); | |
302 } | |
303 if (SDL_PublicSurface | |
304 && (SDL_PublicSurface->flags & SDL_RESIZABLE)) { | |
305 SDL_PrivateResize(w, h); | |
306 } | |
307 } | |
308 | |
309 break; | |
310 | |
311 /* We need to set the cursor */ | |
312 case WM_SETCURSOR: | |
313 { | |
314 Uint16 hittest; | |
315 | |
316 hittest = LOWORD(lParam); | |
317 if (hittest == HTCLIENT) { | |
318 SetCursor(SDL_hcursor); | |
319 return (TRUE); | |
320 } | |
321 } | |
322 | |
323 break; | |
324 | |
325 /* We are about to get palette focus! */ | |
326 case WM_QUERYNEWPALETTE: | |
327 { | |
328 WIN_RealizePalette(current_video); | |
329 return (TRUE); | |
330 } | |
331 | |
332 break; | |
333 | |
334 /* Another application changed the palette */ | |
335 case WM_PALETTECHANGED: | |
336 { | |
337 WIN_PaletteChanged(current_video, (HWND) wParam); | |
338 } | |
339 | |
340 break; | |
341 | |
342 /* We were occluded, refresh our display */ | |
343 case WM_PAINT: | |
344 { | |
345 HDC hdc; | |
346 PAINTSTRUCT ps; | |
347 | |
348 hdc = BeginPaint(SDL_Window, &ps); | |
349 if (current_video->screen && | |
350 !(current_video->screen->flags & SDL_INTERNALOPENGL)) { | |
351 WIN_WinPAINT(current_video, hdc); | |
352 } | |
353 EndPaint(SDL_Window, &ps); | |
354 } | |
355 | |
356 return (0); | |
357 | |
358 /* DJM: Send an expose event in this case */ | |
359 case WM_ERASEBKGND: | |
360 { | |
361 posted = SDL_PrivateExpose(); | |
362 } | |
363 | |
364 return (0); | |
365 | |
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 | |
40 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); | 382 return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam); |
41 } | 383 } |
42 | 384 |
43 void | 385 void |
44 WIN_PumpEvents(_THIS) | 386 WIN_PumpEvents(_THIS) |