Mercurial > sdl-ios-xcode
comparison src/video/win32/SDL_win32window.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 eff4e88cc1e8 |
children | c24ba2cc9583 |
comparison
equal
deleted
inserted
replaced
4660:b15e7017409b | 4661:03dcb795c583 |
---|---|
70 //printf("SHFullscreen(%i)\n",dwState); | 70 //printf("SHFullscreen(%i)\n",dwState); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 #endif | 74 #endif |
75 | |
76 extern HCTX *g_hCtx; /* the table of tablet event contexts, each windows has to have it's own tablet context */ | |
77 static Uint32 highestId = 0; /* the highest id of the tablet context */ | |
78 | 75 |
79 /* Fake window to help with DirectInput events. */ | 76 /* Fake window to help with DirectInput events. */ |
80 HWND SDL_HelperWindow = NULL; | 77 HWND SDL_HelperWindow = NULL; |
81 static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher"); | 78 static WCHAR *SDL_HelperWindowClassName = TEXT("SDLHelperWindowInputCatcher"); |
82 static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow"); | 79 static WCHAR *SDL_HelperWindowName = TEXT("SDLHelperWindowInputMsgWindow"); |
163 } else { | 160 } else { |
164 window->flags &= ~SDL_WINDOW_MINIMIZED; | 161 window->flags &= ~SDL_WINDOW_MINIMIZED; |
165 } | 162 } |
166 } | 163 } |
167 if (GetFocus() == hwnd) { | 164 if (GetFocus() == hwnd) { |
168 int index = data->videodata->keyboard; | |
169 window->flags |= SDL_WINDOW_INPUT_FOCUS; | 165 window->flags |= SDL_WINDOW_INPUT_FOCUS; |
170 SDL_SetKeyboardFocus(index, data->window); | 166 SDL_SetKeyboardFocus(data->window); |
171 | 167 |
172 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { | 168 if (window->flags & SDL_WINDOW_INPUT_GRABBED) { |
173 RECT rect; | 169 RECT rect; |
174 GetClientRect(hwnd, &rect); | 170 GetClientRect(hwnd, &rect); |
175 ClientToScreen(hwnd, (LPPOINT) & rect); | 171 ClientToScreen(hwnd, (LPPOINT) & rect); |
184 } | 180 } |
185 | 181 |
186 int | 182 int |
187 WIN_CreateWindow(_THIS, SDL_Window * window) | 183 WIN_CreateWindow(_THIS, SDL_Window * window) |
188 { | 184 { |
189 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; | |
190 SDL_VideoDisplay *display = window->display; | 185 SDL_VideoDisplay *display = window->display; |
191 RAWINPUTDEVICE Rid; | |
192 AXIS TabX, TabY; | |
193 LOGCONTEXTA lc; | |
194 HWND hwnd; | 186 HWND hwnd; |
195 HWND top; | |
196 RECT rect; | 187 RECT rect; |
197 SDL_Rect bounds; | 188 SDL_Rect bounds; |
198 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); | 189 DWORD style = (WS_CLIPSIBLINGS | WS_CLIPCHILDREN); |
199 int x, y; | 190 int x, y; |
200 int w, h; | 191 int w, h; |
208 && !(window->flags & SDL_WINDOW_FULLSCREEN)) { | 199 && !(window->flags & SDL_WINDOW_FULLSCREEN)) { |
209 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); | 200 style |= (WS_THICKFRAME | WS_MAXIMIZEBOX); |
210 } | 201 } |
211 | 202 |
212 /* Figure out what the window area will be */ | 203 /* Figure out what the window area will be */ |
213 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
214 top = HWND_TOPMOST; | |
215 } else { | |
216 top = HWND_NOTOPMOST; | |
217 } | |
218 rect.left = 0; | 204 rect.left = 0; |
219 rect.top = 0; | 205 rect.top = 0; |
220 rect.right = window->w; | 206 rect.right = window->w; |
221 rect.bottom = window->h; | 207 rect.bottom = window->h; |
222 AdjustWindowRectEx(&rect, style, FALSE, 0); | 208 AdjustWindowRectEx(&rect, style, FALSE, 0); |
223 w = (rect.right - rect.left); | 209 w = (rect.right - rect.left); |
224 h = (rect.bottom - rect.top); | 210 h = (rect.bottom - rect.top); |
225 | 211 |
226 WIN_GetDisplayBounds(_this, display, &bounds); | 212 WIN_GetDisplayBounds(_this, display, &bounds); |
213 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
214 /* The bounds when this window is visible is the fullscreen mode */ | |
215 SDL_DisplayMode fullscreen_mode; | |
216 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { | |
217 bounds.w = fullscreen_mode.w; | |
218 bounds.h = fullscreen_mode.h; | |
219 } | |
220 } | |
227 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 221 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
228 || window->x == SDL_WINDOWPOS_CENTERED) { | 222 || window->x == SDL_WINDOWPOS_CENTERED) { |
229 x = bounds.x + (bounds.w - window->w) / 2; | 223 x = bounds.x + (bounds.w - w) / 2; |
230 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | 224 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
231 if (bounds.x == 0) { | 225 if (bounds.x == 0) { |
232 x = CW_USEDEFAULT; | 226 x = CW_USEDEFAULT; |
233 } else { | 227 } else { |
234 x = bounds.x; | 228 x = bounds.x; |
236 } else { | 230 } else { |
237 x = bounds.x + window->x + rect.left; | 231 x = bounds.x + window->x + rect.left; |
238 } | 232 } |
239 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 233 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
240 || window->y == SDL_WINDOWPOS_CENTERED) { | 234 || window->y == SDL_WINDOWPOS_CENTERED) { |
241 y = bounds.y + (bounds.h - window->h) / 2; | 235 y = bounds.y + (bounds.h - h) / 2; |
242 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { | 236 } else if (window->x == SDL_WINDOWPOS_UNDEFINED) { |
243 if (bounds.x == 0) { | 237 if (bounds.x == 0) { |
244 y = CW_USEDEFAULT; | 238 y = CW_USEDEFAULT; |
245 } else { | 239 } else { |
246 y = bounds.y; | 240 y = bounds.y; |
254 SDL_Instance, NULL); | 248 SDL_Instance, NULL); |
255 if (!hwnd) { | 249 if (!hwnd) { |
256 WIN_SetError("Couldn't create window"); | 250 WIN_SetError("Couldn't create window"); |
257 return -1; | 251 return -1; |
258 } | 252 } |
259 /*Disable Tablet support, replace with multi-touch.*/ | |
260 #if 0 | |
261 /* we're configuring the tablet data. See Wintab reference for more info */ | |
262 if (videodata->wintabDLL | |
263 && videodata->WTInfoA(WTI_DEFSYSCTX, 0, &lc) != 0) { | |
264 lc.lcPktData = PACKETDATA; | |
265 lc.lcPktMode = PACKETMODE; | |
266 lc.lcOptions |= CXO_MESSAGES; | |
267 lc.lcOptions |= CXO_SYSTEM; | |
268 lc.lcMoveMask = PACKETDATA; | |
269 lc.lcBtnDnMask = lc.lcBtnUpMask = PACKETDATA; | |
270 videodata->WTInfoA(WTI_DEVICES, DVC_X, &TabX); | |
271 videodata->WTInfoA(WTI_DEVICES, DVC_Y, &TabY); | |
272 lc.lcInOrgX = 0; | |
273 lc.lcInOrgY = 0; | |
274 lc.lcInExtX = TabX.axMax; | |
275 lc.lcInExtY = TabY.axMax; | |
276 lc.lcOutOrgX = 0; | |
277 lc.lcOutOrgY = 0; | |
278 lc.lcOutExtX = GetSystemMetrics(SM_CXSCREEN); | |
279 lc.lcOutExtY = -GetSystemMetrics(SM_CYSCREEN); | |
280 if (window->id > highestId) { | |
281 HCTX *tmp_hctx; | |
282 highestId = window->id; | |
283 tmp_hctx = | |
284 (HCTX *) SDL_realloc(g_hCtx, (highestId + 1) * sizeof(HCTX)); | |
285 if (!tmp_hctx) { | |
286 SDL_OutOfMemory(); | |
287 DestroyWindow(hwnd); | |
288 return -1; | |
289 } | |
290 g_hCtx = tmp_hctx; | |
291 } | |
292 g_hCtx[window->id] = videodata->WTOpenA(hwnd, &lc, TRUE); | |
293 } | |
294 #else | |
295 //RegisterTouchWindow(hwnd, 0); | 253 //RegisterTouchWindow(hwnd, 0); |
296 #endif | |
297 #ifndef _WIN32_WCE /* has no RawInput */ | |
298 /* we're telling the window, we want it to report raw input events from mice */ | |
299 Rid.usUsagePage = 0x01; | |
300 Rid.usUsage = 0x02; | |
301 Rid.dwFlags = RIDEV_INPUTSINK; | |
302 Rid.hwndTarget = hwnd; | |
303 RegisterRawInputDevices(&Rid, 1, sizeof(Rid)); | |
304 #endif | |
305 | 254 |
306 WIN_PumpEvents(_this); | 255 WIN_PumpEvents(_this); |
307 | 256 |
308 if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) { | 257 if (SetupWindowData(_this, window, hwnd, SDL_TRUE) < 0) { |
309 DestroyWindow(hwnd); | 258 DestroyWindow(hwnd); |
439 SDL_Rect bounds; | 388 SDL_Rect bounds; |
440 DWORD style; | 389 DWORD style; |
441 HWND top; | 390 HWND top; |
442 BOOL menu; | 391 BOOL menu; |
443 int x, y; | 392 int x, y; |
393 int w, h; | |
444 | 394 |
445 /* Figure out what the window area will be */ | 395 /* Figure out what the window area will be */ |
446 if (window->flags & SDL_WINDOW_FULLSCREEN) { | 396 if (window->flags & SDL_WINDOW_FULLSCREEN) { |
447 top = HWND_TOPMOST; | 397 top = HWND_TOPMOST; |
448 } else { | 398 } else { |
457 menu = FALSE; | 407 menu = FALSE; |
458 #else | 408 #else |
459 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); | 409 menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL); |
460 #endif | 410 #endif |
461 AdjustWindowRectEx(&rect, style, menu, 0); | 411 AdjustWindowRectEx(&rect, style, menu, 0); |
412 w = (rect.right - rect.left); | |
413 h = (rect.bottom - rect.top); | |
462 | 414 |
463 WIN_GetDisplayBounds(_this, display, &bounds); | 415 WIN_GetDisplayBounds(_this, display, &bounds); |
416 if (window->flags & SDL_WINDOW_FULLSCREEN) { | |
417 /* The bounds when this window is visible is the fullscreen mode */ | |
418 SDL_DisplayMode fullscreen_mode; | |
419 if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { | |
420 bounds.w = fullscreen_mode.w; | |
421 bounds.h = fullscreen_mode.h; | |
422 } | |
423 } | |
464 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 424 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
465 || window->x == SDL_WINDOWPOS_CENTERED) { | 425 || window->x == SDL_WINDOWPOS_CENTERED) { |
466 x = bounds.x + (bounds.w - window->w) / 2; | 426 x = bounds.x + (bounds.w - w) / 2; |
467 } else { | 427 } else { |
468 x = bounds.x + window->x + rect.left; | 428 x = bounds.x + window->x + rect.left; |
469 } | 429 } |
470 if ((window->flags & SDL_WINDOW_FULLSCREEN) | 430 if ((window->flags & SDL_WINDOW_FULLSCREEN) |
471 || window->y == SDL_WINDOWPOS_CENTERED) { | 431 || window->y == SDL_WINDOWPOS_CENTERED) { |
472 y = bounds.y + (bounds.h - window->h) / 2; | 432 y = bounds.y + (bounds.h - h) / 2; |
473 } else { | 433 } else { |
474 y = bounds.y + window->y + rect.top; | 434 y = bounds.y + window->y + rect.top; |
475 } | 435 } |
476 | 436 |
477 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); | 437 SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE)); |
622 } | 582 } |
623 | 583 |
624 void | 584 void |
625 WIN_DestroyWindow(_THIS, SDL_Window * window) | 585 WIN_DestroyWindow(_THIS, SDL_Window * window) |
626 { | 586 { |
627 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata; | |
628 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; | 587 SDL_WindowData *data = (SDL_WindowData *) window->driverdata; |
629 | 588 |
630 if (data) { | 589 if (data) { |
631 ReleaseDC(data->hwnd, data->hdc); | 590 ReleaseDC(data->hwnd, data->hdc); |
632 if (data->created) { | 591 if (data->created) { |
633 if (videodata->wintabDLL) { | |
634 videodata->WTClose(g_hCtx[window->id]); | |
635 } | |
636 DestroyWindow(data->hwnd); | 592 DestroyWindow(data->hwnd); |
637 } | 593 } |
638 SDL_free(data); | 594 SDL_free(data); |
639 } | 595 } |
640 } | 596 } |
676 wce.hInstance = hInstance; | 632 wce.hInstance = hInstance; |
677 | 633 |
678 /* Register the class. */ | 634 /* Register the class. */ |
679 SDL_HelperWindowClass = RegisterClass(&wce); | 635 SDL_HelperWindowClass = RegisterClass(&wce); |
680 if (SDL_HelperWindowClass == 0) { | 636 if (SDL_HelperWindowClass == 0) { |
681 SDL_SetError("Unable to create Helper Window Class: error %d.", | 637 WIN_SetError("Unable to create Helper Window Class"); |
682 GetLastError()); | |
683 return -1; | 638 return -1; |
684 } | 639 } |
685 | 640 |
686 #ifndef _WIN32_WCE | 641 #ifndef _WIN32_WCE |
687 /* WinCE doesn't have HWND_MESSAGE */ | 642 /* WinCE doesn't have HWND_MESSAGE */ |
695 CW_USEDEFAULT, CW_USEDEFAULT, | 650 CW_USEDEFAULT, CW_USEDEFAULT, |
696 CW_USEDEFAULT, hWndParent, NULL, | 651 CW_USEDEFAULT, hWndParent, NULL, |
697 hInstance, NULL); | 652 hInstance, NULL); |
698 if (SDL_HelperWindow == NULL) { | 653 if (SDL_HelperWindow == NULL) { |
699 UnregisterClass(SDL_HelperWindowClassName, hInstance); | 654 UnregisterClass(SDL_HelperWindowClassName, hInstance); |
700 SDL_SetError("Unable to create Helper Window: error %d.", | 655 WIN_SetError("Unable to create Helper Window"); |
701 GetLastError()); | |
702 return -1; | 656 return -1; |
703 } | 657 } |
704 | 658 |
705 return 0; | 659 return 0; |
706 } | 660 } |
715 HINSTANCE hInstance = GetModuleHandle(NULL); | 669 HINSTANCE hInstance = GetModuleHandle(NULL); |
716 | 670 |
717 /* Destroy the window. */ | 671 /* Destroy the window. */ |
718 if (SDL_HelperWindow != NULL) { | 672 if (SDL_HelperWindow != NULL) { |
719 if (DestroyWindow(SDL_HelperWindow) == 0) { | 673 if (DestroyWindow(SDL_HelperWindow) == 0) { |
720 SDL_SetError("Unable to destroy Helper Window: error %d.", | 674 WIN_SetError("Unable to destroy Helper Window"); |
721 GetLastError()); | |
722 return; | 675 return; |
723 } | 676 } |
724 SDL_HelperWindow = NULL; | 677 SDL_HelperWindow = NULL; |
725 } | 678 } |
726 | 679 |
727 /* Unregister the class. */ | 680 /* Unregister the class. */ |
728 if (SDL_HelperWindowClass != 0) { | 681 if (SDL_HelperWindowClass != 0) { |
729 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) { | 682 if ((UnregisterClass(SDL_HelperWindowClassName, hInstance)) == 0) { |
730 SDL_SetError("Unable to destroy Helper Window Class: error %d.", | 683 WIN_SetError("Unable to destroy Helper Window Class"); |
731 GetLastError()); | |
732 return; | 684 return; |
733 } | 685 } |
734 SDL_HelperWindowClass = 0; | 686 SDL_HelperWindowClass = 0; |
735 } | 687 } |
736 } | 688 } |