comparison src/video/wincommon/SDL_sysevents.c @ 1895:c121d94672cb

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