comparison src/video/wincommon/SDL_sysevents.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
70 #endif 70 #endif
71 WORD *gamma_saved = NULL; 71 WORD *gamma_saved = NULL;
72 72
73 73
74 /* Functions called by the message processing function */ 74 /* Functions called by the message processing function */
75 LONG (*HandleMessage) (_THIS, HWND hwnd, UINT msg, WPARAM wParam, 75 LONG(*HandleMessage) (_THIS, HWND hwnd, UINT msg, WPARAM wParam,
76 LPARAM lParam) = NULL; 76 LPARAM lParam) = NULL;
77 void (*WIN_RealizePalette) (_THIS); 77 void (*WIN_RealizePalette) (_THIS);
78 void (*WIN_PaletteChanged) (_THIS, HWND window); 78 void (*WIN_PaletteChanged) (_THIS, HWND window);
79 void (*WIN_WinPAINT) (_THIS, HDC hdc); 79 void (*WIN_WinPAINT) (_THIS, HDC hdc);
80 extern void DIB_SwapGamma (_THIS); 80 extern void DIB_SwapGamma(_THIS);
81 81
82 #ifndef NO_GETKEYBOARDSTATE 82 #ifndef NO_GETKEYBOARDSTATE
83 /* Variables and support functions for SDL_ToUnicode() */ 83 /* Variables and support functions for SDL_ToUnicode() */
84 static int codepage; 84 static int codepage;
85 static int Is9xME (); 85 static int Is9xME();
86 static int GetCodePage (); 86 static int GetCodePage();
87 static int WINAPI ToUnicode9xME (UINT vkey, UINT scancode, BYTE * keystate, 87 static int WINAPI ToUnicode9xME(UINT vkey, UINT scancode, BYTE * keystate,
88 LPWSTR wchars, int wsize, UINT flags); 88 LPWSTR wchars, int wsize, UINT flags);
89 89
90 ToUnicodeFN SDL_ToUnicode = ToUnicode9xME; 90 ToUnicodeFN SDL_ToUnicode = ToUnicode9xME;
91 #endif /* !NO_GETKEYBOARDSTATE */ 91 #endif /* !NO_GETKEYBOARDSTATE */
92 92
93 93
94 #if defined(_WIN32_WCE) 94 #if defined(_WIN32_WCE)
95 95
96 // dynamically load aygshell dll because we want SDL to work on HPC and be300 96 // dynamically load aygshell dll because we want SDL to work on HPC and be300
97 HINSTANCE aygshell = NULL; 97 HINSTANCE aygshell = NULL;
98 BOOL (WINAPI * SHFullScreen) (HWND hwndRequester, DWORD dwState) = 0; 98 BOOL(WINAPI * SHFullScreen) (HWND hwndRequester, DWORD dwState) = 0;
99 99
100 #define SHFS_SHOWTASKBAR 0x0001 100 #define SHFS_SHOWTASKBAR 0x0001
101 #define SHFS_HIDETASKBAR 0x0002 101 #define SHFS_HIDETASKBAR 0x0002
102 #define SHFS_SHOWSIPBUTTON 0x0004 102 #define SHFS_SHOWSIPBUTTON 0x0004
103 #define SHFS_HIDESIPBUTTON 0x0008 103 #define SHFS_HIDESIPBUTTON 0x0008
104 #define SHFS_SHOWSTARTICON 0x0010 104 #define SHFS_SHOWSTARTICON 0x0010
105 #define SHFS_HIDESTARTICON 0x0020 105 #define SHFS_HIDESTARTICON 0x0020
106 106
107 static void 107 static void
108 LoadAygshell (void) 108 LoadAygshell(void)
109 { 109 {
110 if (!aygshell) 110 if (!aygshell)
111 aygshell = SDL_LoadObject ("aygshell.dll"); 111 aygshell = SDL_LoadObject("aygshell.dll");
112 if ((aygshell != 0) && (SHFullScreen == 0)) { 112 if ((aygshell != 0) && (SHFullScreen == 0)) {
113 SHFullScreen = (int (WINAPI *) (struct HWND__ *, unsigned long)) 113 SHFullScreen = (int (WINAPI *) (struct HWND__ *, unsigned long))
114 SDL_LoadFunction (aygshell, "SHFullScreen"); 114 SDL_LoadFunction(aygshell, "SHFullScreen");
115 } 115 }
116 } 116 }
117 117
118 /* for gapi landscape mode */ 118 /* for gapi landscape mode */
119 static void 119 static void
120 GapiTransform (SDL_ScreenOrientation rotate, char hires, Sint16 * x, 120 GapiTransform(SDL_ScreenOrientation rotate, char hires, Sint16 * x,
121 Sint16 * y) 121 Sint16 * y)
122 { 122 {
123 Sint16 rotatedX; 123 Sint16 rotatedX;
124 Sint16 rotatedY; 124 Sint16 rotatedY;
125 125
126 if (hires) { 126 if (hires) {
179 This is used all over the place, in the windib driver and in the dx5 driver 179 This is used all over the place, in the windib driver and in the dx5 driver
180 So we may as well stick it here instead of having multiple copies scattered 180 So we may as well stick it here instead of having multiple copies scattered
181 about 181 about
182 */ 182 */
183 void 183 void
184 WIN_FlushMessageQueue () 184 WIN_FlushMessageQueue()
185 { 185 {
186 MSG msg; 186 MSG msg;
187 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { 187 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
188 if (msg.message == WM_QUIT) 188 if (msg.message == WM_QUIT)
189 break; 189 break;
190 TranslateMessage (&msg); 190 TranslateMessage(&msg);
191 DispatchMessage (&msg); 191 DispatchMessage(&msg);
192 } 192 }
193 } 193 }
194 194
195 static void 195 static void
196 SDL_RestoreGameMode (void) 196 SDL_RestoreGameMode(void)
197 { 197 {
198 #ifdef _WIN32_WCE 198 #ifdef _WIN32_WCE
199 SDL_VideoDevice *this = current_video; 199 SDL_VideoDevice *this = current_video;
200 if (SDL_strcmp (this->name, "gapi") == 0) { 200 if (SDL_strcmp(this->name, "gapi") == 0) {
201 if (this->hidden->suspended) { 201 if (this->hidden->suspended) {
202 this->hidden->suspended = 0; 202 this->hidden->suspended = 0;
203 } 203 }
204 } 204 }
205 #else 205 #else
206 ShowWindow (SDL_Window, SW_RESTORE); 206 ShowWindow(SDL_Window, SW_RESTORE);
207 #endif 207 #endif
208 208
209 #ifndef NO_CHANGEDISPLAYSETTINGS 209 #ifndef NO_CHANGEDISPLAYSETTINGS
210 #ifndef _WIN32_WCE 210 #ifndef _WIN32_WCE
211 ChangeDisplaySettings (&SDL_fullscreen_mode, CDS_FULLSCREEN); 211 ChangeDisplaySettings(&SDL_fullscreen_mode, CDS_FULLSCREEN);
212 #endif 212 #endif
213 #endif /* NO_CHANGEDISPLAYSETTINGS */ 213 #endif /* NO_CHANGEDISPLAYSETTINGS */
214 } 214 }
215 static void 215 static void
216 SDL_RestoreDesktopMode (void) 216 SDL_RestoreDesktopMode(void)
217 { 217 {
218 218
219 #ifdef _WIN32_WCE 219 #ifdef _WIN32_WCE
220 SDL_VideoDevice *this = current_video; 220 SDL_VideoDevice *this = current_video;
221 if (SDL_strcmp (this->name, "gapi") == 0) { 221 if (SDL_strcmp(this->name, "gapi") == 0) {
222 if (!this->hidden->suspended) { 222 if (!this->hidden->suspended) {
223 this->hidden->suspended = 1; 223 this->hidden->suspended = 1;
224 } 224 }
225 } 225 }
226 #else 226 #else
227 /* WinCE does not have a taskbar, so minimizing is not convenient */ 227 /* WinCE does not have a taskbar, so minimizing is not convenient */
228 ShowWindow (SDL_Window, SW_MINIMIZE); 228 ShowWindow(SDL_Window, SW_MINIMIZE);
229 #endif 229 #endif
230 230
231 #ifndef NO_CHANGEDISPLAYSETTINGS 231 #ifndef NO_CHANGEDISPLAYSETTINGS
232 #ifndef _WIN32_WCE 232 #ifndef _WIN32_WCE
233 ChangeDisplaySettings (NULL, 0); 233 ChangeDisplaySettings(NULL, 0);
234 #endif 234 #endif
235 #endif /* NO_CHANGEDISPLAYSETTINGS */ 235 #endif /* NO_CHANGEDISPLAYSETTINGS */
236 } 236 }
237 237
238 #ifdef WM_MOUSELEAVE 238 #ifdef WM_MOUSELEAVE
245 development environment, and only works on systems that have had IE 3.0 245 development environment, and only works on systems that have had IE 3.0
246 or newer installed on them (which is not the case with the base Win95). 246 or newer installed on them (which is not the case with the base Win95).
247 Therefore, we implement our own version of _TrackMouseEvent() which 247 Therefore, we implement our own version of _TrackMouseEvent() which
248 uses our own implementation if TrackMouseEvent() is not available. 248 uses our own implementation if TrackMouseEvent() is not available.
249 */ 249 */
250 static BOOL (WINAPI * _TrackMouseEvent) (TRACKMOUSEEVENT * ptme) = NULL; 250 static BOOL(WINAPI * _TrackMouseEvent) (TRACKMOUSEEVENT * ptme) = NULL;
251 251
252 static VOID CALLBACK 252 static VOID CALLBACK
253 TrackMouseTimerProc (HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime) 253 TrackMouseTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime)
254 { 254 {
255 RECT rect; 255 RECT rect;
256 POINT pt; 256 POINT pt;
257 257
258 GetClientRect (hWnd, &rect); 258 GetClientRect(hWnd, &rect);
259 MapWindowPoints (hWnd, NULL, (LPPOINT) & rect, 2); 259 MapWindowPoints(hWnd, NULL, (LPPOINT) & rect, 2);
260 GetCursorPos (&pt); 260 GetCursorPos(&pt);
261 if (!PtInRect (&rect, pt) || (WindowFromPoint (pt) != hWnd)) { 261 if (!PtInRect(&rect, pt) || (WindowFromPoint(pt) != hWnd)) {
262 if (!KillTimer (hWnd, idEvent)) { 262 if (!KillTimer(hWnd, idEvent)) {
263 /* Error killing the timer! */ 263 /* Error killing the timer! */
264 } 264 }
265 PostMessage (hWnd, WM_MOUSELEAVE, 0, 0); 265 PostMessage(hWnd, WM_MOUSELEAVE, 0, 0);
266 } 266 }
267 } 267 }
268 static BOOL WINAPI 268 static BOOL WINAPI
269 WIN_TrackMouseEvent (TRACKMOUSEEVENT * ptme) 269 WIN_TrackMouseEvent(TRACKMOUSEEVENT * ptme)
270 { 270 {
271 if (ptme->dwFlags == TME_LEAVE) { 271 if (ptme->dwFlags == TME_LEAVE) {
272 return SetTimer (ptme->hwndTrack, ptme->dwFlags, 100, 272 return SetTimer(ptme->hwndTrack, ptme->dwFlags, 100,
273 (TIMERPROC) TrackMouseTimerProc) != 0; 273 (TIMERPROC) TrackMouseTimerProc) != 0;
274 } 274 }
275 return FALSE; 275 return FALSE;
276 } 276 }
277 #endif /* WM_MOUSELEAVE */ 277 #endif /* WM_MOUSELEAVE */
278 278
279 /* Function to retrieve the current keyboard modifiers */ 279 /* Function to retrieve the current keyboard modifiers */
280 static void 280 static void
281 WIN_GetKeyboardState (void) 281 WIN_GetKeyboardState(void)
282 { 282 {
283 #ifndef NO_GETKEYBOARDSTATE 283 #ifndef NO_GETKEYBOARDSTATE
284 SDLMod state; 284 SDLMod state;
285 BYTE keyboard[256]; 285 BYTE keyboard[256];
286 Uint8 *kstate = SDL_GetKeyState (NULL); 286 Uint8 *kstate = SDL_GetKeyState(NULL);
287 287
288 state = KMOD_NONE; 288 state = KMOD_NONE;
289 if (GetKeyboardState (keyboard)) { 289 if (GetKeyboardState(keyboard)) {
290 if (keyboard[VK_LSHIFT] & 0x80) { 290 if (keyboard[VK_LSHIFT] & 0x80) {
291 state |= KMOD_LSHIFT; 291 state |= KMOD_LSHIFT;
292 kstate[SDLK_LSHIFT] = SDL_PRESSED; 292 kstate[SDLK_LSHIFT] = SDL_PRESSED;
293 } 293 }
294 if (keyboard[VK_RSHIFT] & 0x80) { 294 if (keyboard[VK_RSHIFT] & 0x80) {
318 if (keyboard[VK_CAPITAL] & 0x01) { 318 if (keyboard[VK_CAPITAL] & 0x01) {
319 state |= KMOD_CAPS; 319 state |= KMOD_CAPS;
320 kstate[SDLK_CAPSLOCK] = SDL_PRESSED; 320 kstate[SDLK_CAPSLOCK] = SDL_PRESSED;
321 } 321 }
322 } 322 }
323 SDL_SetModState (state); 323 SDL_SetModState(state);
324 #endif /* !NO_GETKEYBOARDSTATE */ 324 #endif /* !NO_GETKEYBOARDSTATE */
325 } 325 }
326 326
327 /* The main Win32 event handler 327 /* The main Win32 event handler
328 DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it 328 DJM: This is no longer static as (DX5/DIB)_CreateWindow needs it
329 */ 329 */
330 LRESULT CALLBACK 330 LRESULT CALLBACK
331 WinMessage (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 331 WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
332 { 332 {
333 SDL_VideoDevice *this = current_video; 333 SDL_VideoDevice *this = current_video;
334 static int mouse_pressed = 0; 334 static int mouse_pressed = 0;
335 static int in_window = 0; 335 static int in_window = 0;
336 #ifdef WMMSG_DEBUG 336 #ifdef WMMSG_DEBUG
337 fprintf (stderr, "Received windows message: "); 337 fprintf(stderr, "Received windows message: ");
338 if (msg > MAX_WMMSG) { 338 if (msg > MAX_WMMSG) {
339 fprintf (stderr, "%d", msg); 339 fprintf(stderr, "%d", msg);
340 } else { 340 } else {
341 fprintf (stderr, "%s", wmtab[msg]); 341 fprintf(stderr, "%s", wmtab[msg]);
342 } 342 }
343 fprintf (stderr, " -- 0x%X, 0x%X\n", wParam, lParam); 343 fprintf(stderr, " -- 0x%X, 0x%X\n", wParam, lParam);
344 #endif 344 #endif
345 switch (msg) { 345 switch (msg) {
346 346
347 case WM_ACTIVATE: 347 case WM_ACTIVATE:
348 { 348 {
349 SDL_VideoDevice *this = current_video; 349 SDL_VideoDevice *this = current_video;
350 BOOL minimized; 350 BOOL minimized;
351 Uint8 appstate; 351 Uint8 appstate;
352 352
353 minimized = HIWORD (wParam); 353 minimized = HIWORD(wParam);
354 if (!minimized && (LOWORD (wParam) != WA_INACTIVE)) { 354 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
355 /* Gain the following states */ 355 /* Gain the following states */
356 appstate = SDL_APPACTIVE | SDL_APPINPUTFOCUS; 356 appstate = SDL_APPACTIVE | SDL_APPINPUTFOCUS;
357 if (this->input_grab != SDL_GRAB_OFF) { 357 if (this->input_grab != SDL_GRAB_OFF) {
358 WIN_GrabInput (this, SDL_GRAB_ON); 358 WIN_GrabInput(this, SDL_GRAB_ON);
359 } 359 }
360 if (!(SDL_GetAppState () & SDL_APPINPUTFOCUS)) { 360 if (!(SDL_GetAppState() & SDL_APPINPUTFOCUS)) {
361 if (!DDRAW_FULLSCREEN ()) { 361 if (!DDRAW_FULLSCREEN()) {
362 DIB_SwapGamma (this); 362 DIB_SwapGamma(this);
363 } 363 }
364 if (WINDIB_FULLSCREEN ()) { 364 if (WINDIB_FULLSCREEN()) {
365 SDL_RestoreGameMode (); 365 SDL_RestoreGameMode();
366 } 366 }
367 } 367 }
368 #if defined(_WIN32_WCE) 368 #if defined(_WIN32_WCE)
369 if (WINDIB_FULLSCREEN ()) { 369 if (WINDIB_FULLSCREEN()) {
370 LoadAygshell (); 370 LoadAygshell();
371 if (SHFullScreen) 371 if (SHFullScreen)
372 SHFullScreen (SDL_Window, 372 SHFullScreen(SDL_Window,
373 SHFS_HIDESTARTICON | 373 SHFS_HIDESTARTICON |
374 SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); 374 SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
375 else 375 else
376 ShowWindow (FindWindow 376 ShowWindow(FindWindow
377 (TEXT ("HHTaskBar"), NULL), SW_HIDE); 377 (TEXT("HHTaskBar"), NULL), SW_HIDE);
378 378
379 } 379 }
380 #endif 380 #endif
381 381
382 posted = SDL_PrivateAppActive (1, appstate); 382 posted = SDL_PrivateAppActive(1, appstate);
383 WIN_GetKeyboardState (); 383 WIN_GetKeyboardState();
384 } else { 384 } else {
385 /* Lose the following states */ 385 /* Lose the following states */
386 appstate = SDL_APPINPUTFOCUS; 386 appstate = SDL_APPINPUTFOCUS;
387 if (minimized) { 387 if (minimized) {
388 appstate |= SDL_APPACTIVE; 388 appstate |= SDL_APPACTIVE;
389 } 389 }
390 if (this->input_grab != SDL_GRAB_OFF) { 390 if (this->input_grab != SDL_GRAB_OFF) {
391 WIN_GrabInput (this, SDL_GRAB_OFF); 391 WIN_GrabInput(this, SDL_GRAB_OFF);
392 } 392 }
393 if (SDL_GetAppState () & SDL_APPINPUTFOCUS) { 393 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
394 if (!DDRAW_FULLSCREEN ()) { 394 if (!DDRAW_FULLSCREEN()) {
395 DIB_SwapGamma (this); 395 DIB_SwapGamma(this);
396 } 396 }
397 if (WINDIB_FULLSCREEN ()) { 397 if (WINDIB_FULLSCREEN()) {
398 SDL_RestoreDesktopMode (); 398 SDL_RestoreDesktopMode();
399 #if defined(_WIN32_WCE) 399 #if defined(_WIN32_WCE)
400 LoadAygshell (); 400 LoadAygshell();
401 if (SHFullScreen) 401 if (SHFullScreen)
402 SHFullScreen (SDL_Window, 402 SHFullScreen(SDL_Window,
403 SHFS_SHOWSTARTICON | 403 SHFS_SHOWSTARTICON |
404 SHFS_SHOWTASKBAR | 404 SHFS_SHOWTASKBAR |
405 SHFS_SHOWSIPBUTTON); 405 SHFS_SHOWSIPBUTTON);
406 else 406 else
407 ShowWindow (FindWindow 407 ShowWindow(FindWindow
408 (TEXT ("HHTaskBar"), NULL), SW_SHOW); 408 (TEXT("HHTaskBar"), NULL), SW_SHOW);
409 409
410 #endif 410 #endif
411 } 411 }
412 } 412 }
413 posted = SDL_PrivateAppActive (0, appstate); 413 posted = SDL_PrivateAppActive(0, appstate);
414 } 414 }
415 return (0); 415 return (0);
416 } 416 }
417 break; 417 break;
418 418
419 case WM_MOUSEMOVE: 419 case WM_MOUSEMOVE:
420 { 420 {
421 421
422 /* Mouse is handled by DirectInput when fullscreen */ 422 /* Mouse is handled by DirectInput when fullscreen */
423 if (SDL_VideoSurface && !DINPUT_FULLSCREEN ()) { 423 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) {
424 Sint16 x, y; 424 Sint16 x, y;
425 425
426 /* mouse has entered the window */ 426 /* mouse has entered the window */
427 if (!in_window) { 427 if (!in_window) {
428 #ifdef WM_MOUSELEAVE 428 #ifdef WM_MOUSELEAVE
429 TRACKMOUSEEVENT tme; 429 TRACKMOUSEEVENT tme;
430 430
431 tme.cbSize = sizeof (tme); 431 tme.cbSize = sizeof(tme);
432 tme.dwFlags = TME_LEAVE; 432 tme.dwFlags = TME_LEAVE;
433 tme.hwndTrack = SDL_Window; 433 tme.hwndTrack = SDL_Window;
434 _TrackMouseEvent (&tme); 434 _TrackMouseEvent(&tme);
435 #endif /* WM_MOUSELEAVE */ 435 #endif /* WM_MOUSELEAVE */
436 in_window = TRUE; 436 in_window = TRUE;
437 437
438 posted = SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS); 438 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
439 } 439 }
440 440
441 /* mouse has moved within the window */ 441 /* mouse has moved within the window */
442 x = LOWORD (lParam); 442 x = LOWORD(lParam);
443 y = HIWORD (lParam); 443 y = HIWORD(lParam);
444 if (mouse_relative) { 444 if (mouse_relative) {
445 POINT center; 445 POINT center;
446 center.x = (SDL_VideoSurface->w / 2); 446 center.x = (SDL_VideoSurface->w / 2);
447 center.y = (SDL_VideoSurface->h / 2); 447 center.y = (SDL_VideoSurface->h / 2);
448 x -= (Sint16) center.x; 448 x -= (Sint16) center.x;
449 y -= (Sint16) center.y; 449 y -= (Sint16) center.y;
450 if (x || y) { 450 if (x || y) {
451 ClientToScreen (SDL_Window, &center); 451 ClientToScreen(SDL_Window, &center);
452 SetCursorPos (center.x, center.y); 452 SetCursorPos(center.x, center.y);
453 posted = SDL_PrivateMouseMotion (0, 1, x, y); 453 posted = SDL_PrivateMouseMotion(0, 1, x, y);
454 } 454 }
455 } else { 455 } else {
456 #ifdef _WIN32_WCE 456 #ifdef _WIN32_WCE
457 if (SDL_VideoSurface) 457 if (SDL_VideoSurface)
458 GapiTransform (this->hidden->userOrientation, 458 GapiTransform(this->hidden->userOrientation,
459 this->hidden->hiresFix, &x, &y); 459 this->hidden->hiresFix, &x, &y);
460 #endif 460 #endif
461 posted = SDL_PrivateMouseMotion (0, 0, x, y); 461 posted = SDL_PrivateMouseMotion(0, 0, x, y);
462 } 462 }
463 } 463 }
464 } 464 }
465 return (0); 465 return (0);
466 466
467 #ifdef WM_MOUSELEAVE 467 #ifdef WM_MOUSELEAVE
468 case WM_MOUSELEAVE: 468 case WM_MOUSELEAVE:
469 { 469 {
470 470
471 /* Mouse is handled by DirectInput when fullscreen */ 471 /* Mouse is handled by DirectInput when fullscreen */
472 if (SDL_VideoSurface && !DINPUT_FULLSCREEN ()) { 472 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) {
473 /* mouse has left the window */ 473 /* mouse has left the window */
474 /* or */ 474 /* or */
475 /* Elvis has left the building! */ 475 /* Elvis has left the building! */
476 posted = SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS); 476 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
477 } 477 }
478 in_window = FALSE; 478 in_window = FALSE;
479 } 479 }
480 return (0); 480 return (0);
481 #endif /* WM_MOUSELEAVE */ 481 #endif /* WM_MOUSELEAVE */
486 case WM_MBUTTONUP: 486 case WM_MBUTTONUP:
487 case WM_RBUTTONDOWN: 487 case WM_RBUTTONDOWN:
488 case WM_RBUTTONUP: 488 case WM_RBUTTONUP:
489 { 489 {
490 /* Mouse is handled by DirectInput when fullscreen */ 490 /* Mouse is handled by DirectInput when fullscreen */
491 if (SDL_VideoSurface && !DINPUT_FULLSCREEN ()) { 491 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) {
492 Sint16 x, y; 492 Sint16 x, y;
493 Uint8 button, state; 493 Uint8 button, state;
494 494
495 /* DJM: 495 /* DJM:
496 We want the SDL window to take focus so that 496 We want the SDL window to take focus so that
497 it acts like a normal windows "component" 497 it acts like a normal windows "component"
498 (e.g. gains keyboard focus on a mouse click). 498 (e.g. gains keyboard focus on a mouse click).
499 */ 499 */
500 SetFocus (SDL_Window); 500 SetFocus(SDL_Window);
501 501
502 /* Figure out which button to use */ 502 /* Figure out which button to use */
503 switch (msg) { 503 switch (msg) {
504 case WM_LBUTTONDOWN: 504 case WM_LBUTTONDOWN:
505 button = SDL_BUTTON_LEFT; 505 button = SDL_BUTTON_LEFT;
530 return (0); 530 return (0);
531 } 531 }
532 if (state == SDL_PRESSED) { 532 if (state == SDL_PRESSED) {
533 /* Grab mouse so we get up events */ 533 /* Grab mouse so we get up events */
534 if (++mouse_pressed > 0) { 534 if (++mouse_pressed > 0) {
535 SetCapture (hwnd); 535 SetCapture(hwnd);
536 } 536 }
537 } else { 537 } else {
538 /* Release mouse after all up events */ 538 /* Release mouse after all up events */
539 if (--mouse_pressed <= 0) { 539 if (--mouse_pressed <= 0) {
540 ReleaseCapture (); 540 ReleaseCapture();
541 mouse_pressed = 0; 541 mouse_pressed = 0;
542 } 542 }
543 } 543 }
544 if (mouse_relative) { 544 if (mouse_relative) {
545 /* RJR: March 28, 2000 545 /* RJR: March 28, 2000
546 report internal mouse position if in relative mode */ 546 report internal mouse position if in relative mode */
547 x = 0; 547 x = 0;
548 y = 0; 548 y = 0;
549 } else { 549 } else {
550 x = (Sint16) LOWORD (lParam); 550 x = (Sint16) LOWORD(lParam);
551 y = (Sint16) HIWORD (lParam); 551 y = (Sint16) HIWORD(lParam);
552 #ifdef _WIN32_WCE 552 #ifdef _WIN32_WCE
553 if (SDL_VideoSurface) 553 if (SDL_VideoSurface)
554 GapiTransform (this->hidden->userOrientation, 554 GapiTransform(this->hidden->userOrientation,
555 this->hidden->hiresFix, &x, &y); 555 this->hidden->hiresFix, &x, &y);
556 #endif 556 #endif
557 } 557 }
558 posted = SDL_PrivateMouseButton (state, button, x, y); 558 posted = SDL_PrivateMouseButton(state, button, x, y);
559 } 559 }
560 } 560 }
561 return (0); 561 return (0);
562 562
563 563
564 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400) 564 #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
565 case WM_MOUSEWHEEL: 565 case WM_MOUSEWHEEL:
566 if (SDL_VideoSurface && !DINPUT_FULLSCREEN ()) { 566 if (SDL_VideoSurface && !DINPUT_FULLSCREEN()) {
567 int move = (short) HIWORD (wParam); 567 int move = (short) HIWORD(wParam);
568 if (move) { 568 if (move) {
569 Uint8 button; 569 Uint8 button;
570 if (move > 0) 570 if (move > 0)
571 button = SDL_BUTTON_WHEELUP; 571 button = SDL_BUTTON_WHEELUP;
572 else 572 else
573 button = SDL_BUTTON_WHEELDOWN; 573 button = SDL_BUTTON_WHEELDOWN;
574 posted = SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); 574 posted = SDL_PrivateMouseButton(SDL_PRESSED, button, 0, 0);
575 posted |= SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); 575 posted |= SDL_PrivateMouseButton(SDL_RELEASED, button, 0, 0);
576 } 576 }
577 } 577 }
578 return (0); 578 return (0);
579 #endif 579 #endif
580 580
601 (SDL_PublicSurface->flags & SDL_RESIZABLE)) { 601 (SDL_PublicSurface->flags & SDL_RESIZABLE)) {
602 return (0); 602 return (0);
603 } 603 }
604 604
605 /* Get the current position of our window */ 605 /* Get the current position of our window */
606 GetWindowRect (SDL_Window, &size); 606 GetWindowRect(SDL_Window, &size);
607 x = size.left; 607 x = size.left;
608 y = size.top; 608 y = size.top;
609 609
610 /* Calculate current width and height of our window */ 610 /* Calculate current width and height of our window */
611 size.top = 0; 611 size.top = 0;
621 /* DJM - according to the docs for GetMenu(), the 621 /* DJM - according to the docs for GetMenu(), the
622 return value is undefined if hwnd is a child window. 622 return value is undefined if hwnd is a child window.
623 Aparently it's too difficult for MS to check 623 Aparently it's too difficult for MS to check
624 inside their function, so I have to do it here. 624 inside their function, so I have to do it here.
625 */ 625 */
626 style = GetWindowLong (hwnd, GWL_STYLE); 626 style = GetWindowLong(hwnd, GWL_STYLE);
627 AdjustWindowRect (&size, 627 AdjustWindowRect(&size,
628 style, 628 style,
629 style & WS_CHILDWINDOW ? FALSE 629 style & WS_CHILDWINDOW ? FALSE
630 : GetMenu (hwnd) != NULL); 630 : GetMenu(hwnd) != NULL);
631 631
632 width = size.right - size.left; 632 width = size.right - size.left;
633 height = size.bottom - size.top; 633 height = size.bottom - size.top;
634 634
635 /* Fix our size to the current size */ 635 /* Fix our size to the current size */
649 case WM_WINDOWPOSCHANGED: 649 case WM_WINDOWPOSCHANGED:
650 { 650 {
651 SDL_VideoDevice *this = current_video; 651 SDL_VideoDevice *this = current_video;
652 int w, h; 652 int w, h;
653 653
654 GetClientRect (SDL_Window, &SDL_bounds); 654 GetClientRect(SDL_Window, &SDL_bounds);
655 ClientToScreen (SDL_Window, (LPPOINT) & SDL_bounds); 655 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds);
656 ClientToScreen (SDL_Window, (LPPOINT) & SDL_bounds + 1); 656 ClientToScreen(SDL_Window, (LPPOINT) & SDL_bounds + 1);
657 if (!SDL_resizing && !IsZoomed (SDL_Window) && 657 if (!SDL_resizing && !IsZoomed(SDL_Window) &&
658 SDL_PublicSurface && 658 SDL_PublicSurface &&
659 !(SDL_PublicSurface->flags & SDL_FULLSCREEN)) { 659 !(SDL_PublicSurface->flags & SDL_FULLSCREEN)) {
660 SDL_windowX = SDL_bounds.left; 660 SDL_windowX = SDL_bounds.left;
661 SDL_windowY = SDL_bounds.top; 661 SDL_windowY = SDL_bounds.top;
662 } 662 }
663 w = SDL_bounds.right - SDL_bounds.left; 663 w = SDL_bounds.right - SDL_bounds.left;
664 h = SDL_bounds.bottom - SDL_bounds.top; 664 h = SDL_bounds.bottom - SDL_bounds.top;
665 if (this->input_grab != SDL_GRAB_OFF) { 665 if (this->input_grab != SDL_GRAB_OFF) {
666 ClipCursor (&SDL_bounds); 666 ClipCursor(&SDL_bounds);
667 } 667 }
668 if (SDL_PublicSurface && 668 if (SDL_PublicSurface &&
669 (SDL_PublicSurface->flags & SDL_RESIZABLE)) { 669 (SDL_PublicSurface->flags & SDL_RESIZABLE)) {
670 SDL_PrivateResize (w, h); 670 SDL_PrivateResize(w, h);
671 } 671 }
672 } 672 }
673 break; 673 break;
674 674
675 /* We need to set the cursor */ 675 /* We need to set the cursor */
676 case WM_SETCURSOR: 676 case WM_SETCURSOR:
677 { 677 {
678 Uint16 hittest; 678 Uint16 hittest;
679 679
680 hittest = LOWORD (lParam); 680 hittest = LOWORD(lParam);
681 if (hittest == HTCLIENT) { 681 if (hittest == HTCLIENT) {
682 SetCursor (SDL_hcursor); 682 SetCursor(SDL_hcursor);
683 return (TRUE); 683 return (TRUE);
684 } 684 }
685 } 685 }
686 break; 686 break;
687 687
688 /* We are about to get palette focus! */ 688 /* We are about to get palette focus! */
689 case WM_QUERYNEWPALETTE: 689 case WM_QUERYNEWPALETTE:
690 { 690 {
691 WIN_RealizePalette (current_video); 691 WIN_RealizePalette(current_video);
692 return (TRUE); 692 return (TRUE);
693 } 693 }
694 break; 694 break;
695 695
696 /* Another application changed the palette */ 696 /* Another application changed the palette */
697 case WM_PALETTECHANGED: 697 case WM_PALETTECHANGED:
698 { 698 {
699 WIN_PaletteChanged (current_video, (HWND) wParam); 699 WIN_PaletteChanged(current_video, (HWND) wParam);
700 } 700 }
701 break; 701 break;
702 702
703 /* We were occluded, refresh our display */ 703 /* We were occluded, refresh our display */
704 case WM_PAINT: 704 case WM_PAINT:
705 { 705 {
706 HDC hdc; 706 HDC hdc;
707 PAINTSTRUCT ps; 707 PAINTSTRUCT ps;
708 708
709 hdc = BeginPaint (SDL_Window, &ps); 709 hdc = BeginPaint(SDL_Window, &ps);
710 if (current_video->screen && 710 if (current_video->screen &&
711 !(current_video->screen->flags & SDL_INTERNALOPENGL)) { 711 !(current_video->screen->flags & SDL_INTERNALOPENGL)) {
712 WIN_WinPAINT (current_video, hdc); 712 WIN_WinPAINT(current_video, hdc);
713 } 713 }
714 EndPaint (SDL_Window, &ps); 714 EndPaint(SDL_Window, &ps);
715 } 715 }
716 return (0); 716 return (0);
717 717
718 /* DJM: Send an expose event in this case */ 718 /* DJM: Send an expose event in this case */
719 case WM_ERASEBKGND: 719 case WM_ERASEBKGND:
720 { 720 {
721 posted = SDL_PrivateExpose (); 721 posted = SDL_PrivateExpose();
722 } 722 }
723 return (0); 723 return (0);
724 724
725 case WM_CLOSE: 725 case WM_CLOSE:
726 { 726 {
727 if ((posted = SDL_PrivateQuit ())) 727 if ((posted = SDL_PrivateQuit()))
728 PostQuitMessage (0); 728 PostQuitMessage(0);
729 } 729 }
730 return (0); 730 return (0);
731 731
732 case WM_DESTROY: 732 case WM_DESTROY:
733 { 733 {
734 PostQuitMessage (0); 734 PostQuitMessage(0);
735 } 735 }
736 return (0); 736 return (0);
737 737
738 #ifndef NO_GETKEYBOARDSTATE 738 #ifndef NO_GETKEYBOARDSTATE
739 case WM_INPUTLANGCHANGE: 739 case WM_INPUTLANGCHANGE:
740 { 740 {
741 codepage = GetCodePage (); 741 codepage = GetCodePage();
742 } 742 }
743 return (TRUE); 743 return (TRUE);
744 #endif 744 #endif
745 745
746 default: 746 default:
747 { 747 {
748 /* Special handling by the video driver */ 748 /* Special handling by the video driver */
749 if (HandleMessage) { 749 if (HandleMessage) {
750 return (HandleMessage (current_video, 750 return (HandleMessage(current_video,
751 hwnd, msg, wParam, lParam)); 751 hwnd, msg, wParam, lParam));
752 } 752 }
753 } 753 }
754 break; 754 break;
755 } 755 }
756 return (DefWindowProc (hwnd, msg, wParam, lParam)); 756 return (DefWindowProc(hwnd, msg, wParam, lParam));
757 } 757 }
758 758
759 /* Allow the application handle to be stored and retrieved later */ 759 /* Allow the application handle to be stored and retrieved later */
760 static void *SDL_handle = NULL; 760 static void *SDL_handle = NULL;
761 761
762 void 762 void
763 SDL_SetModuleHandle (void *handle) 763 SDL_SetModuleHandle(void *handle)
764 { 764 {
765 SDL_handle = handle; 765 SDL_handle = handle;
766 } 766 }
767 767
768 void * 768 void *
769 SDL_GetModuleHandle (void) 769 SDL_GetModuleHandle(void)
770 { 770 {
771 void *handle; 771 void *handle;
772 772
773 if (SDL_handle) { 773 if (SDL_handle) {
774 handle = SDL_handle; 774 handle = SDL_handle;
775 } else { 775 } else {
776 handle = GetModuleHandle (NULL); 776 handle = GetModuleHandle(NULL);
777 } 777 }
778 return (handle); 778 return (handle);
779 } 779 }
780 780
781 /* This allows the SDL_WINDOWID hack */ 781 /* This allows the SDL_WINDOWID hack */
783 783
784 static int app_registered = 0; 784 static int app_registered = 0;
785 785
786 /* Register the class for this application -- exported for winmain.c */ 786 /* Register the class for this application -- exported for winmain.c */
787 int 787 int
788 SDL_RegisterApp (char *name, Uint32 style, void *hInst) 788 SDL_RegisterApp(char *name, Uint32 style, void *hInst)
789 { 789 {
790 WNDCLASS class; 790 WNDCLASS class;
791 #ifdef WM_MOUSELEAVE 791 #ifdef WM_MOUSELEAVE
792 HMODULE handle; 792 HMODULE handle;
793 #endif 793 #endif
801 #define CS_BYTEALIGNCLIENT 0 801 #define CS_BYTEALIGNCLIENT 0
802 #endif 802 #endif
803 if (!name && !SDL_Appname) { 803 if (!name && !SDL_Appname) {
804 name = "SDL_app"; 804 name = "SDL_app";
805 SDL_Appstyle = CS_BYTEALIGNCLIENT; 805 SDL_Appstyle = CS_BYTEALIGNCLIENT;
806 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle (); 806 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
807 } 807 }
808 808
809 if (name) { 809 if (name) {
810 #ifdef _WIN32_WCE 810 #ifdef _WIN32_WCE
811 /* WinCE uses the UNICODE version */ 811 /* WinCE uses the UNICODE version */
812 SDL_Appname = SDL_iconv_utf8_ucs2 (name); 812 SDL_Appname = SDL_iconv_utf8_ucs2(name);
813 #else 813 #else
814 SDL_Appname = SDL_iconv_utf8_latin1 (name); 814 SDL_Appname = SDL_iconv_utf8_latin1(name);
815 #endif /* _WIN32_WCE */ 815 #endif /* _WIN32_WCE */
816 SDL_Appstyle = style; 816 SDL_Appstyle = style;
817 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle (); 817 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle();
818 } 818 }
819 819
820 /* Register the application class */ 820 /* Register the application class */
821 class.hCursor = NULL; 821 class.hCursor = NULL;
822 class.hIcon = LoadImage (SDL_Instance, SDL_Appname, 822 class.hIcon = LoadImage(SDL_Instance, SDL_Appname,
823 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); 823 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
824 class.lpszMenuName = NULL; 824 class.lpszMenuName = NULL;
825 class.lpszClassName = SDL_Appname; 825 class.lpszClassName = SDL_Appname;
826 class.hbrBackground = NULL; 826 class.hbrBackground = NULL;
827 class.hInstance = SDL_Instance; 827 class.hInstance = SDL_Instance;
828 class.style = SDL_Appstyle; 828 class.style = SDL_Appstyle;
830 class.style |= CS_OWNDC; 830 class.style |= CS_OWNDC;
831 #endif 831 #endif
832 class.lpfnWndProc = WinMessage; 832 class.lpfnWndProc = WinMessage;
833 class.cbWndExtra = 0; 833 class.cbWndExtra = 0;
834 class.cbClsExtra = 0; 834 class.cbClsExtra = 0;
835 if (!RegisterClass (&class)) { 835 if (!RegisterClass(&class)) {
836 SDL_SetError ("Couldn't register application class"); 836 SDL_SetError("Couldn't register application class");
837 return (-1); 837 return (-1);
838 } 838 }
839 #ifdef WM_MOUSELEAVE 839 #ifdef WM_MOUSELEAVE
840 /* Get the version of TrackMouseEvent() we use */ 840 /* Get the version of TrackMouseEvent() we use */
841 _TrackMouseEvent = NULL; 841 _TrackMouseEvent = NULL;
842 handle = GetModuleHandle ("USER32.DLL"); 842 handle = GetModuleHandle("USER32.DLL");
843 if (handle) { 843 if (handle) {
844 _TrackMouseEvent = 844 _TrackMouseEvent =
845 (BOOL (WINAPI *) (TRACKMOUSEEVENT *)) GetProcAddress (handle, 845 (BOOL(WINAPI *) (TRACKMOUSEEVENT *)) GetProcAddress(handle,
846 "TrackMouseEvent"); 846 "TrackMouseEvent");
847 } 847 }
848 if (_TrackMouseEvent == NULL) { 848 if (_TrackMouseEvent == NULL) {
849 _TrackMouseEvent = WIN_TrackMouseEvent; 849 _TrackMouseEvent = WIN_TrackMouseEvent;
850 } 850 }
851 #endif /* WM_MOUSELEAVE */ 851 #endif /* WM_MOUSELEAVE */
852 852
853 #ifndef NO_GETKEYBOARDSTATE 853 #ifndef NO_GETKEYBOARDSTATE
854 /* Initialise variables for SDL_ToUnicode() */ 854 /* Initialise variables for SDL_ToUnicode() */
855 codepage = GetCodePage (); 855 codepage = GetCodePage();
856 SDL_ToUnicode = Is9xME ()? ToUnicode9xME : ToUnicode; 856 SDL_ToUnicode = Is9xME()? ToUnicode9xME : ToUnicode;
857 #endif 857 #endif
858 858
859 app_registered = 1; 859 app_registered = 1;
860 return (0); 860 return (0);
861 } 861 }
862 862
863 /* Unregisters the windowclass registered in SDL_RegisterApp above. */ 863 /* Unregisters the windowclass registered in SDL_RegisterApp above. */
864 void 864 void
865 SDL_UnregisterApp () 865 SDL_UnregisterApp()
866 { 866 {
867 WNDCLASS class; 867 WNDCLASS class;
868 868
869 /* SDL_RegisterApp might not have been called before */ 869 /* SDL_RegisterApp might not have been called before */
870 if (!app_registered) { 870 if (!app_registered) {
871 return; 871 return;
872 } 872 }
873 --app_registered; 873 --app_registered;
874 if (app_registered == 0) { 874 if (app_registered == 0) {
875 /* Check for any registered window classes. */ 875 /* Check for any registered window classes. */
876 if (GetClassInfo (SDL_Instance, SDL_Appname, &class)) { 876 if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
877 UnregisterClass (SDL_Appname, SDL_Instance); 877 UnregisterClass(SDL_Appname, SDL_Instance);
878 } 878 }
879 SDL_free (SDL_Appname); 879 SDL_free(SDL_Appname);
880 SDL_Appname = NULL; 880 SDL_Appname = NULL;
881 } 881 }
882 } 882 }
883 883
884 #ifndef NO_GETKEYBOARDSTATE 884 #ifndef NO_GETKEYBOARDSTATE
885 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */ 885 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
886 886
887 static int 887 static int
888 Is9xME () 888 Is9xME()
889 { 889 {
890 OSVERSIONINFO info; 890 OSVERSIONINFO info;
891 891
892 SDL_memset (&info, 0, sizeof (info)); 892 SDL_memset(&info, 0, sizeof(info));
893 info.dwOSVersionInfoSize = sizeof (info); 893 info.dwOSVersionInfoSize = sizeof(info);
894 if (!GetVersionEx (&info)) { 894 if (!GetVersionEx(&info)) {
895 return 0; 895 return 0;
896 } 896 }
897 return (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); 897 return (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
898 } 898 }
899 899
900 static int 900 static int
901 GetCodePage () 901 GetCodePage()
902 { 902 {
903 char buff[8]; 903 char buff[8];
904 int lcid = MAKELCID (LOWORD (GetKeyboardLayout (0)), SORT_DEFAULT); 904 int lcid = MAKELCID(LOWORD(GetKeyboardLayout(0)), SORT_DEFAULT);
905 int cp = GetACP (); 905 int cp = GetACP();
906 906
907 if (GetLocaleInfo 907 if (GetLocaleInfo(lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof(buff))) {
908 (lcid, LOCALE_IDEFAULTANSICODEPAGE, buff, sizeof (buff))) { 908 cp = SDL_atoi(buff);
909 cp = SDL_atoi (buff);
910 } 909 }
911 return cp; 910 return cp;
912 } 911 }
913 912
914 static int WINAPI 913 static int WINAPI
915 ToUnicode9xME (UINT vkey, UINT scancode, PBYTE keystate, LPWSTR wchars, 914 ToUnicode9xME(UINT vkey, UINT scancode, PBYTE keystate, LPWSTR wchars,
916 int wsize, UINT flags) 915 int wsize, UINT flags)
917 { 916 {
918 BYTE chars[2]; 917 BYTE chars[2];
919 918
920 if (ToAsciiEx 919 if (ToAsciiEx
921 (vkey, scancode, keystate, (WORD *) chars, 0, 920 (vkey, scancode, keystate, (WORD *) chars, 0,
922 GetKeyboardLayout (0)) == 1) { 921 GetKeyboardLayout(0)) == 1) {
923 return MultiByteToWideChar (codepage, 0, chars, 1, wchars, wsize); 922 return MultiByteToWideChar(codepage, 0, chars, 1, wchars, wsize);
924 } 923 }
925 return 0; 924 return 0;
926 } 925 }
927 926
928 #endif /* !NO_GETKEYBOARDSTATE */ 927 #endif /* !NO_GETKEYBOARDSTATE */