src/video/windows/SDL_windowsevents.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 27 Feb 2013 11:39:39 -0800
changeset 6943 ce87e12970f5
parent 6931 843f9c1b16b8
child 6944 e8effbc1a10e
permissions -rw-r--r--
sdl - use the wParam and rawinput data for mouse state rather than just the message type, fixes missing mouse up events when alt-tabing out of the window

CR: SamL
slouken@1895
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@1895
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1895
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1895
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1895
    20
*/
slouken@6044
    21
#include "SDL_config.h"
slouken@2710
    22
slouken@6044
    23
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@1895
    24
slouken@5062
    25
#include "SDL_windowsvideo.h"
slouken@5062
    26
#include "SDL_windowsshape.h"
slouken@1895
    27
#include "SDL_syswm.h"
slouken@1895
    28
#include "SDL_vkeys.h"
slouken@1895
    29
#include "../../events/SDL_events_c.h"
slouken@4919
    30
#include "../../events/SDL_touch_c.h"
slouken@1895
    31
slouken@6523
    32
/* Dropfile support */
slouken@6523
    33
#include <shellapi.h>
slouken@6523
    34
slouken@6523
    35
jimtla@4650
    36
jimtla@4650
    37
slouken@4868
    38
/*#define WMMSG_DEBUG*/
slouken@1895
    39
#ifdef WMMSG_DEBUG
jimtla@4650
    40
#include <stdio.h>	
slouken@1895
    41
#include "wmmsg.h"
slouken@1895
    42
#endif
slouken@1895
    43
slouken@1895
    44
/* Masks for processing the windows KEYDOWN and KEYUP messages */
slouken@2317
    45
#define REPEATED_KEYMASK    (1<<30)
slouken@2317
    46
#define EXTENDED_KEYMASK    (1<<24)
slouken@1895
    47
bob@2324
    48
#define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
slouken@6931
    49
#ifndef VK_OEM_NEC_EQUAL
slouken@6931
    50
#define VK_OEM_NEC_EQUAL 0x92 
slouken@6931
    51
#endif
slouken@2313
    52
icculus@2127
    53
/* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
icculus@2127
    54
#ifndef WM_XBUTTONDOWN
icculus@2127
    55
#define WM_XBUTTONDOWN 0x020B
icculus@2127
    56
#endif
icculus@2127
    57
#ifndef WM_XBUTTONUP
icculus@2127
    58
#define WM_XBUTTONUP 0x020C
icculus@2127
    59
#endif
icculus@2127
    60
#ifndef GET_XBUTTON_WPARAM
icculus@2127
    61
#define GET_XBUTTON_WPARAM(w) (HIWORD(w))
icculus@2127
    62
#endif
bobbens@2733
    63
#ifndef WM_INPUT
bobbens@2733
    64
#define WM_INPUT 0x00ff
bobbens@2733
    65
#endif
slouken@4932
    66
#ifndef WM_TOUCH
slouken@4868
    67
#define WM_TOUCH 0x0240
slouken@4932
    68
#endif
slouken@4919
    69
jorgen@6922
    70
static SDL_Scancode 
jorgen@6922
    71
WindowsScanCodeToSDLScanCode( int lParam, int wParam, const SDL_Scancode *key_map )
jorgen@6922
    72
{
jorgen@6922
    73
	SDL_Scancode code;
jorgen@6922
    74
	char bIsExtended;
jorgen@6922
    75
	int nScanCode = ( lParam >> 16 ) & 0xFF;
jorgen@6922
    76
jorgen@6922
    77
	if ( nScanCode == 0 )
jorgen@6922
    78
	{
jorgen@6922
    79
		switch( wParam )
jorgen@6922
    80
		{
jorgen@6922
    81
		case VK_CLEAR: return SDL_SCANCODE_CLEAR;
jorgen@6922
    82
		case VK_MODECHANGE: return SDL_SCANCODE_MODE;
jorgen@6922
    83
		case VK_SELECT: return SDL_SCANCODE_SELECT;
jorgen@6922
    84
		case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
jorgen@6922
    85
		case VK_HELP: return SDL_SCANCODE_HELP;
jorgen@6922
    86
jorgen@6922
    87
		case VK_F13: return SDL_SCANCODE_F13;
jorgen@6922
    88
		case VK_F14: return SDL_SCANCODE_F14;
jorgen@6922
    89
		case VK_F15: return SDL_SCANCODE_F15;
jorgen@6922
    90
		case VK_F16: return SDL_SCANCODE_F16;
jorgen@6922
    91
		case VK_F17: return SDL_SCANCODE_F17;
jorgen@6922
    92
		case VK_F18: return SDL_SCANCODE_F18;
jorgen@6922
    93
		case VK_F19: return SDL_SCANCODE_F19;
jorgen@6922
    94
		case VK_F20: return SDL_SCANCODE_F20;
jorgen@6922
    95
		case VK_F21: return SDL_SCANCODE_F21;
jorgen@6922
    96
		case VK_F22: return SDL_SCANCODE_F22;
jorgen@6922
    97
		case VK_F23: return SDL_SCANCODE_F23;
jorgen@6922
    98
		case VK_F24: return SDL_SCANCODE_F24;
jorgen@6922
    99
jorgen@6922
   100
		case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
jorgen@6922
   101
		case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
jorgen@6922
   102
		case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
jorgen@6922
   103
		case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
jorgen@6922
   104
		case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
jorgen@6922
   105
		case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
jorgen@6922
   106
		case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
jorgen@6922
   107
		case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
jorgen@6922
   108
		case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
jorgen@6922
   109
		case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
jorgen@6922
   110
		case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
jorgen@6922
   111
	
jorgen@6922
   112
		case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
jorgen@6922
   113
		case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
jorgen@6922
   114
		case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
jorgen@6922
   115
		case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
jorgen@6922
   116
		case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
jorgen@6922
   117
		case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
jorgen@6922
   118
		
jorgen@6922
   119
		case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
jorgen@6922
   120
jorgen@6922
   121
		case VK_ATTN: return SDL_SCANCODE_SYSREQ;
jorgen@6922
   122
		case VK_CRSEL: return SDL_SCANCODE_CRSEL;
jorgen@6922
   123
		case VK_EXSEL: return SDL_SCANCODE_EXSEL;
jorgen@6922
   124
		case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
jorgen@6922
   125
jorgen@6922
   126
		case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
jorgen@6922
   127
		case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
jorgen@6922
   128
jorgen@6922
   129
		default: return SDL_SCANCODE_UNKNOWN;
jorgen@6922
   130
		}
jorgen@6922
   131
	}
jorgen@6922
   132
jorgen@6922
   133
	if ( nScanCode > 127 )
jorgen@6922
   134
		return SDL_SCANCODE_UNKNOWN;
jorgen@6922
   135
jorgen@6922
   136
	code = key_map[nScanCode];
jorgen@6922
   137
jorgen@6922
   138
	bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
jorgen@6922
   139
	if ( !bIsExtended )
jorgen@6922
   140
	{
jorgen@6922
   141
		switch ( code )
jorgen@6922
   142
		{
jorgen@6922
   143
		case SDL_SCANCODE_HOME:
jorgen@6922
   144
			return SDL_SCANCODE_KP_7;
jorgen@6922
   145
		case SDL_SCANCODE_UP:
jorgen@6922
   146
			return SDL_SCANCODE_KP_8;
jorgen@6922
   147
		case SDL_SCANCODE_PAGEUP:
jorgen@6922
   148
			return SDL_SCANCODE_KP_9;
jorgen@6922
   149
		case SDL_SCANCODE_LEFT:
jorgen@6922
   150
			return SDL_SCANCODE_KP_4;
jorgen@6922
   151
		case SDL_SCANCODE_RIGHT:
jorgen@6922
   152
			return SDL_SCANCODE_KP_6;
jorgen@6922
   153
		case SDL_SCANCODE_END:
jorgen@6922
   154
			return SDL_SCANCODE_KP_1;
jorgen@6922
   155
		case SDL_SCANCODE_DOWN:
jorgen@6922
   156
			return SDL_SCANCODE_KP_2;
jorgen@6922
   157
		case SDL_SCANCODE_PAGEDOWN:
jorgen@6922
   158
			return SDL_SCANCODE_KP_3;
jorgen@6922
   159
		case SDL_SCANCODE_INSERT:
jorgen@6922
   160
			return SDL_SCANCODE_KP_0;
jorgen@6922
   161
		case SDL_SCANCODE_DELETE:
jorgen@6922
   162
			return SDL_SCANCODE_KP_DECIMAL;
jorgen@6922
   163
		case SDL_SCANCODE_PRINTSCREEN:
jorgen@6922
   164
			return SDL_SCANCODE_KP_MULTIPLY;
jorgen@6922
   165
		default:
jorgen@6922
   166
			break;
jorgen@6922
   167
		}
jorgen@6922
   168
	}
jorgen@6922
   169
	else
jorgen@6922
   170
	{
jorgen@6922
   171
		switch ( code )
jorgen@6922
   172
		{
jorgen@6922
   173
		case SDL_SCANCODE_RETURN:
jorgen@6922
   174
			return SDL_SCANCODE_KP_ENTER;
jorgen@6922
   175
		case SDL_SCANCODE_LALT:
jorgen@6922
   176
			return SDL_SCANCODE_RALT;
jorgen@6922
   177
		case SDL_SCANCODE_LCTRL:
jorgen@6922
   178
			return SDL_SCANCODE_RCTRL;
jorgen@6922
   179
		case SDL_SCANCODE_SLASH:
jorgen@6922
   180
			return SDL_SCANCODE_KP_DIVIDE;
jorgen@6922
   181
		case SDL_SCANCODE_CAPSLOCK:
jorgen@6922
   182
			return SDL_SCANCODE_KP_PLUS;
jorgen@6922
   183
		}
jorgen@6922
   184
	}
jorgen@6922
   185
jorgen@6922
   186
	return code;
jorgen@6922
   187
}
jorgen@6922
   188
jorgen@6922
   189
slouken@6943
   190
void 
slouken@6943
   191
WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button )
slouken@6943
   192
{
slouken@6943
   193
	if ( bwParamMousePressed && !bSDLMousePressed )
slouken@6943
   194
	{
slouken@6943
   195
		SDL_SendMouseButton(data->window, SDL_PRESSED, button);
slouken@6943
   196
	}
slouken@6943
   197
	else if ( !bwParamMousePressed && bSDLMousePressed )
slouken@6943
   198
	{
slouken@6943
   199
		SDL_SendMouseButton(data->window, SDL_RELEASED, button);
slouken@6943
   200
	}
slouken@6943
   201
}
slouken@6943
   202
slouken@6943
   203
/*
slouken@6943
   204
* Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also
slouken@6943
   205
*  so this funciton reconciles our view of the world with the current buttons reported by windows
slouken@6943
   206
*/
slouken@6943
   207
void 
slouken@6943
   208
WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data )
slouken@6943
   209
{
slouken@6943
   210
	if ( wParam != data->mouse_button_flags )
slouken@6943
   211
	{
slouken@6943
   212
		Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
slouken@6943
   213
		WIN_CheckWParamMouseButton(  (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
slouken@6943
   214
		WIN_CheckWParamMouseButton(  (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
slouken@6943
   215
		WIN_CheckWParamMouseButton(  (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
slouken@6943
   216
		WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
slouken@6943
   217
		WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
slouken@6943
   218
		data->mouse_button_flags = wParam;
slouken@6943
   219
	}
slouken@6943
   220
}
slouken@6943
   221
slouken@6943
   222
slouken@6943
   223
void 
slouken@6943
   224
WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data )
slouken@6943
   225
{
slouken@6943
   226
	if ( rawButtons != data->mouse_button_flags )
slouken@6943
   227
	{
slouken@6943
   228
		Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
slouken@6943
   229
		WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
slouken@6943
   230
		WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_RIGHT );
slouken@6943
   231
		WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_MIDDLE );
slouken@6943
   232
		WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
slouken@6943
   233
		WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
slouken@6943
   234
		data->mouse_button_flags = rawButtons;
slouken@6943
   235
	}
slouken@6943
   236
}
slouken@6943
   237
slouken@1895
   238
LRESULT CALLBACK
slouken@1895
   239
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@1895
   240
{
slouken@1895
   241
    SDL_WindowData *data;
slouken@3566
   242
    LRESULT returnCode = -1;
slouken@1895
   243
slouken@1951
   244
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@4429
   245
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1951
   246
        SDL_SysWMmsg wmmsg;
slouken@1951
   247
slouken@1951
   248
        SDL_VERSION(&wmmsg.version);
slouken@4900
   249
        wmmsg.subsystem = SDL_SYSWM_WINDOWS;
slouken@5056
   250
        wmmsg.msg.win.hwnd = hwnd;
slouken@5056
   251
        wmmsg.msg.win.msg = msg;
slouken@5056
   252
        wmmsg.msg.win.wParam = wParam;
slouken@5056
   253
        wmmsg.msg.win.lParam = lParam;
slouken@1951
   254
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
   255
    }
slouken@1951
   256
slouken@1895
   257
    /* Get the window data for the window */
slouken@1895
   258
    data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
slouken@1895
   259
    if (!data) {
slouken@1895
   260
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@1895
   261
    }
jimtla@4650
   262
slouken@1895
   263
#ifdef WMMSG_DEBUG
jimtla@4650
   264
    {		
jimtla@4650
   265
        FILE *log = fopen("wmmsg.txt", "a");		
slouken@1913
   266
        fprintf(log, "Received windows message: %p ", hwnd);
slouken@1913
   267
        if (msg > MAX_WMMSG) {
slouken@1913
   268
            fprintf(log, "%d", msg);
slouken@1913
   269
        } else {
slouken@1913
   270
            fprintf(log, "%s", wmtab[msg]);
slouken@1913
   271
        }
slouken@1913
   272
        fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
slouken@1913
   273
        fclose(log);
slouken@1895
   274
    }
slouken@4868
   275
#endif
slouken@2710
   276
dewyatt@4752
   277
    if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
dewyatt@4752
   278
        return 0;
slouken@1895
   279
slouken@1895
   280
    switch (msg) {
slouken@1895
   281
slouken@1895
   282
    case WM_SHOWWINDOW:
slouken@1895
   283
        {
slouken@1895
   284
            if (wParam) {
slouken@3685
   285
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1895
   286
            } else {
slouken@3685
   287
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1895
   288
            }
slouken@1895
   289
        }
slouken@1895
   290
        break;
slouken@1895
   291
slouken@1895
   292
    case WM_ACTIVATE:
slouken@1895
   293
        {
slouken@1895
   294
            BOOL minimized;
slouken@1895
   295
slouken@1895
   296
            minimized = HIWORD(wParam);
slouken@1895
   297
            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
slouken@3685
   298
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   299
                SDL_SendWindowEvent(data->window,
slouken@1895
   300
                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1895
   301
                if (IsZoomed(hwnd)) {
slouken@3685
   302
                    SDL_SendWindowEvent(data->window,
slouken@1895
   303
                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
slouken@1895
   304
                }
slouken@4465
   305
                if (SDL_GetKeyboardFocus() != data->window) {
slouken@4465
   306
                    SDL_SetKeyboardFocus(data->window);
slouken@1895
   307
                }
slouken@6943
   308
				/* mouse buttons may have changed state here, in theory we would need
slouken@6943
   309
				to resync them, but we will get a WM_MOUSEMOVE right away which will fix 
slouken@6943
   310
				things up
slouken@6943
   311
				*/
slouken@6350
   312
slouken@6350
   313
				if(SDL_GetMouse()->relative_mode) {
slouken@6350
   314
					LONG cx, cy;
slouken@6350
   315
					RECT rect;
slouken@6350
   316
					GetWindowRect(hwnd, &rect);
slouken@6350
   317
slouken@6350
   318
					cx = (rect.left + rect.right) / 2;
slouken@6350
   319
					cy = (rect.top + rect.bottom) / 2;
slouken@6350
   320
slouken@6350
   321
					/* Make an absurdly small clip rect */
slouken@6350
   322
					rect.left = cx-1;
slouken@6350
   323
					rect.right = cx+1;
slouken@6350
   324
					rect.top = cy-1;
slouken@6350
   325
					rect.bottom = cy+1;
slouken@6350
   326
slouken@6350
   327
					ClipCursor(&rect);
slouken@6350
   328
				}
slouken@6350
   329
slouken@4504
   330
                /*
slouken@4504
   331
                 * FIXME: Update keyboard state
slouken@4504
   332
                 */
slouken@4504
   333
                WIN_CheckClipboardUpdate(data->videodata);
slouken@1895
   334
            } else {
slouken@4465
   335
                if (SDL_GetKeyboardFocus() == data->window) {
slouken@4465
   336
                    SDL_SetKeyboardFocus(NULL);
slouken@1895
   337
                }
slouken@1895
   338
                if (minimized) {
slouken@3685
   339
                    SDL_SendWindowEvent(data->window,
slouken@1895
   340
                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1895
   341
                }
slouken@1895
   342
            }
slouken@1895
   343
        }
slouken@3566
   344
        returnCode = 0;
slouken@3566
   345
        break;
slouken@1895
   346
slouken@4470
   347
	case WM_MOUSEMOVE:
slouken@6943
   348
		if( !SDL_GetMouse()->relative_mode )
slouken@6943
   349
	        SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
slouken@6943
   350
		/* don't break here, fall through to check the wParam like the button presses */
slouken@6943
   351
	case WM_LBUTTONDOWN:
slouken@6943
   352
	case WM_LBUTTONUP:
slouken@6943
   353
	case WM_RBUTTONDOWN:
slouken@6943
   354
	case WM_RBUTTONUP:
slouken@6943
   355
	case WM_MBUTTONDOWN:
slouken@6943
   356
	case WM_MBUTTONUP:
slouken@6943
   357
	case WM_XBUTTONDOWN:
slouken@6943
   358
	case WM_XBUTTONUP:
slouken@6943
   359
		if(!SDL_GetMouse()->relative_mode)
slouken@6943
   360
			WIN_CheckWParamMouseButtons( wParam, data );
slouken@6943
   361
		break;
slouken@3139
   362
slouken@6350
   363
	case WM_INPUT:
slouken@6350
   364
	{
slouken@6350
   365
		HRAWINPUT hRawInput = (HRAWINPUT)lParam;
slouken@6350
   366
		RAWINPUT inp;
slouken@6350
   367
		UINT size = sizeof(inp);
slouken@6782
   368
slouken@6782
   369
		if(!SDL_GetMouse()->relative_mode)
slouken@6782
   370
			break;
slouken@6782
   371
slouken@6350
   372
		GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
slouken@6350
   373
slouken@6350
   374
		/* Mouse data */
slouken@6350
   375
		if(inp.header.dwType == RIM_TYPEMOUSE)
slouken@6350
   376
		{
slouken@6350
   377
			RAWMOUSE* mouse = &inp.data.mouse;
slouken@6350
   378
slouken@6350
   379
			if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
slouken@6782
   380
			{
slouken@6350
   381
				SDL_SendMouseMotion(data->window, 1, (int)mouse->lLastX, (int)mouse->lLastY);
slouken@6782
   382
			}
slouken@6782
   383
			else
slouken@6782
   384
			{
slouken@6782
   385
				// synthesize relative moves from the abs position
slouken@6782
   386
				static SDL_Point initialMousePoint;
slouken@6782
   387
				if ( initialMousePoint.x == 0 && initialMousePoint.y == 0 )
slouken@6782
   388
				{
slouken@6782
   389
					initialMousePoint.x = mouse->lLastX;
slouken@6782
   390
					initialMousePoint.y = mouse->lLastY;
slouken@6782
   391
				}
slouken@6350
   392
slouken@6782
   393
				SDL_SendMouseMotion(data->window, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
slouken@6782
   394
slouken@6782
   395
				initialMousePoint.x = mouse->lLastX;
slouken@6782
   396
				initialMousePoint.y = mouse->lLastY;
slouken@6782
   397
			}
slouken@6943
   398
			WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
slouken@6350
   399
		}
slouken@6350
   400
		break;
slouken@6350
   401
	}
slouken@6350
   402
slouken@5049
   403
    case WM_MOUSEWHEEL:
slouken@5049
   404
        {
slouken@6861
   405
            // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
slouken@6861
   406
            short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
slouken@5049
   407
slouken@5049
   408
            SDL_SendMouseWheel(data->window, 0, motion);
slouken@5049
   409
            break;
slouken@5049
   410
        }
slouken@5049
   411
slouken@5086
   412
#ifdef WM_MOUSELEAVE
slouken@5086
   413
    /* FIXME: Do we need the SDL 1.2 hack to generate WM_MOUSELEAVE now? */
slouken@1895
   414
    case WM_MOUSELEAVE:
slouken@4470
   415
        if (SDL_GetMouseFocus() == data->window) {
slouken@4470
   416
            SDL_SetMouseFocus(NULL);
slouken@1895
   417
        }
slouken@3566
   418
        returnCode = 0;
slouken@3566
   419
        break;
slouken@5086
   420
#endif /* WM_MOUSELEAVE */
slouken@1895
   421
slouken@1895
   422
    case WM_SYSKEYDOWN:
slouken@1895
   423
    case WM_KEYDOWN:
slouken@1895
   424
        {
jorgen@6925
   425
			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
jorgen@6922
   426
			if ( code != SDL_SCANCODE_UNKNOWN ) {
jorgen@6922
   427
                SDL_SendKeyboardKey(SDL_PRESSED, code );
slouken@2308
   428
            }
slouken@1895
   429
        }
slouken@3566
   430
        returnCode = 0;
slouken@3566
   431
        break;
slouken@1895
   432
slouken@1895
   433
    case WM_SYSKEYUP:
slouken@1895
   434
    case WM_KEYUP:
slouken@1895
   435
        {
jorgen@6925
   436
			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
jorgen@6922
   437
			if ( code != SDL_SCANCODE_UNKNOWN ) {
jorgen@6922
   438
				if (wParam == VK_SNAPSHOT
jorgen@6922
   439
				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
jorgen@6922
   440
				    SDL_RELEASED) {
jorgen@6922
   441
				    SDL_SendKeyboardKey(SDL_PRESSED,
jorgen@6922
   442
				                         code);
jorgen@6922
   443
				}
jorgen@6922
   444
                SDL_SendKeyboardKey(SDL_RELEASED, code );
slouken@2308
   445
            }
slouken@1895
   446
        }
slouken@3566
   447
        returnCode = 0;
slouken@3566
   448
        break;
slouken@1895
   449
slouken@2309
   450
    case WM_CHAR:
slouken@2309
   451
        {
slouken@2309
   452
            char text[4];
slouken@2309
   453
slouken@2309
   454
            /* Convert to UTF-8 and send it on... */
slouken@2309
   455
            if (wParam <= 0x7F) {
slouken@2309
   456
                text[0] = (char) wParam;
slouken@2309
   457
                text[1] = '\0';
slouken@2309
   458
            } else if (wParam <= 0x7FF) {
slouken@2309
   459
                text[0] = 0xC0 | (char) ((wParam >> 6) & 0x1F);
slouken@2309
   460
                text[1] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   461
                text[2] = '\0';
slouken@2309
   462
            } else {
slouken@2309
   463
                text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
slouken@2309
   464
                text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
slouken@2309
   465
                text[2] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   466
                text[3] = '\0';
slouken@2309
   467
            }
slouken@4465
   468
            SDL_SendKeyboardText(text);
slouken@2309
   469
        }
slouken@3566
   470
        returnCode = 0;
slouken@3566
   471
        break;
slouken@2309
   472
slouken@5086
   473
#ifdef WM_INPUTLANGCHANGE
slouken@2311
   474
    case WM_INPUTLANGCHANGE:
slouken@2311
   475
        {
slouken@4465
   476
            WIN_UpdateKeymap();
slouken@2311
   477
        }
slouken@3566
   478
        returnCode = 1;
slouken@3566
   479
        break;
slouken@5086
   480
#endif /* WM_INPUTLANGCHANGE */
slouken@2311
   481
slouken@5086
   482
#ifdef WM_GETMINMAXINFO
slouken@1895
   483
    case WM_GETMINMAXINFO:
slouken@1895
   484
        {
slouken@1895
   485
            MINMAXINFO *info;
slouken@1895
   486
            RECT size;
slouken@1895
   487
            int x, y;
slouken@1895
   488
            int w, h;
stopiccot@6682
   489
            int min_w, min_h;
slouken@6788
   490
            int max_w, max_h;
slouken@1895
   491
            int style;
slouken@3168
   492
            BOOL menu;
slouken@6862
   493
			BOOL constrain_max_size;
slouken@1895
   494
slouken@1895
   495
            /* If we allow resizing, let the resize happen naturally */
stopiccot@6682
   496
            if (SDL_IsShapedWindow(data->window))
eligottlieb@4815
   497
                Win32_ResizeWindowShape(data->window);
slouken@1895
   498
slouken@1895
   499
            /* Get the current position of our window */
slouken@1895
   500
            GetWindowRect(hwnd, &size);
slouken@1895
   501
            x = size.left;
slouken@1895
   502
            y = size.top;
slouken@1895
   503
slouken@1895
   504
            /* Calculate current size of our window */
slouken@3685
   505
            SDL_GetWindowSize(data->window, &w, &h);
stopiccot@6682
   506
            SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
slouken@6788
   507
            SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
stopiccot@6682
   508
stopiccot@6682
   509
            /* Store in min_w and min_h difference between current size and minimal 
stopiccot@6682
   510
               size so we don't need to call AdjustWindowRectEx twice */
stopiccot@6682
   511
            min_w -= w;
stopiccot@6682
   512
            min_h -= h;
slouken@6837
   513
            if (max_w && max_h) {
slouken@6837
   514
                max_w -= w;
slouken@6837
   515
                max_h -= h;
slouken@6862
   516
                constrain_max_size = TRUE;
slouken@6862
   517
            } else {
slouken@6862
   518
                constrain_max_size = FALSE;
slouken@6837
   519
            }
stopiccot@6682
   520
slouken@1895
   521
            size.top = 0;
slouken@1895
   522
            size.left = 0;
slouken@1895
   523
            size.bottom = h;
slouken@1895
   524
            size.right = w;
slouken@1895
   525
slouken@3168
   526
            style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   527
            /* DJM - according to the docs for GetMenu(), the
slouken@1895
   528
               return value is undefined if hwnd is a child window.
slouken@1895
   529
               Aparently it's too difficult for MS to check
slouken@1895
   530
               inside their function, so I have to do it here.
slouken@1895
   531
             */
slouken@3168
   532
            menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@3168
   533
            AdjustWindowRectEx(&size, style, menu, 0);
slouken@1895
   534
            w = size.right - size.left;
slouken@1895
   535
            h = size.bottom - size.top;
slouken@1895
   536
slouken@1895
   537
            /* Fix our size to the current size */
slouken@1895
   538
            info = (MINMAXINFO *) lParam;
stopiccot@6682
   539
            if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
stopiccot@6682
   540
                info->ptMinTrackSize.x = w + min_w;
stopiccot@6682
   541
                info->ptMinTrackSize.y = h + min_h;
slouken@6862
   542
                if (constrain_max_size) {
slouken@6862
   543
                    info->ptMaxTrackSize.x = w + max_w;
slouken@6862
   544
                    info->ptMaxTrackSize.y = h + max_h;
slouken@6862
   545
                }
stopiccot@6682
   546
            } else {
stopiccot@6682
   547
                info->ptMaxSize.x = w;
stopiccot@6682
   548
                info->ptMaxSize.y = h;
stopiccot@6682
   549
                info->ptMaxPosition.x = x;
stopiccot@6682
   550
                info->ptMaxPosition.y = y;
stopiccot@6682
   551
                info->ptMinTrackSize.x = w;
stopiccot@6682
   552
                info->ptMinTrackSize.y = h;
stopiccot@6682
   553
                info->ptMaxTrackSize.x = w;
stopiccot@6682
   554
                info->ptMaxTrackSize.y = h;
stopiccot@6682
   555
            }
slouken@1895
   556
        }
slouken@3566
   557
        returnCode = 0;
slouken@3566
   558
        break;
slouken@5086
   559
#endif /* WM_GETMINMAXINFO */
slouken@1895
   560
slouken@1895
   561
    case WM_WINDOWPOSCHANGED:
slouken@1895
   562
        {
slouken@1895
   563
            RECT rect;
slouken@1895
   564
            int x, y;
slouken@1895
   565
            int w, h;
slouken@1895
   566
            Uint32 window_flags;
slouken@1895
   567
slouken@3256
   568
            if (!GetClientRect(hwnd, &rect) ||
slouken@3256
   569
                (rect.right == rect.left && rect.bottom == rect.top)) {
slouken@3256
   570
                break;
slouken@3256
   571
            }
slouken@1895
   572
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   573
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   574
slouken@3685
   575
            window_flags = SDL_GetWindowFlags(data->window);
slouken@1895
   576
            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1895
   577
                (window_flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@1895
   578
                ClipCursor(&rect);
slouken@1895
   579
            }
slouken@1895
   580
slouken@1895
   581
            x = rect.left;
slouken@1895
   582
            y = rect.top;
slouken@3685
   583
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1895
   584
slouken@1895
   585
            w = rect.right - rect.left;
slouken@1895
   586
            h = rect.bottom - rect.top;
slouken@3685
   587
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, w,
slouken@1895
   588
                                h);
slouken@1895
   589
        }
slouken@1895
   590
        break;
slouken@1895
   591
slouken@1895
   592
    case WM_SETCURSOR:
slouken@1895
   593
        {
slouken@3076
   594
            Uint16 hittest;
slouken@1895
   595
slouken@3076
   596
            hittest = LOWORD(lParam);
slouken@3076
   597
            if (hittest == HTCLIENT) {
slouken@5421
   598
                SetCursor(SDL_cursor);
slouken@3566
   599
                returnCode = TRUE;
slouken@3076
   600
            }
slouken@1895
   601
        }
slouken@1895
   602
        break;
slouken@1895
   603
slouken@1895
   604
        /* We were occluded, refresh our display */
slouken@1895
   605
    case WM_PAINT:
slouken@1895
   606
        {
slouken@1895
   607
            RECT rect;
slouken@1895
   608
            if (GetUpdateRect(hwnd, &rect, FALSE)) {
slouken@1895
   609
                ValidateRect(hwnd, &rect);
slouken@3685
   610
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED,
slouken@1895
   611
                                    0, 0);
slouken@1895
   612
            }
slouken@1895
   613
        }
slouken@3566
   614
        returnCode = 0;
slouken@3566
   615
        break;
slouken@3095
   616
slouken@1895
   617
        /* We'll do our own drawing, prevent flicker */
slouken@1895
   618
    case WM_ERASEBKGND:
slouken@1895
   619
        {
slouken@1895
   620
        }
slouken@1895
   621
        return (1);
slouken@1895
   622
slouken@5086
   623
#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)
slouken@1895
   624
    case WM_SYSCOMMAND:
slouken@1895
   625
        {
slouken@1895
   626
            /* Don't start the screensaver or blank the monitor in fullscreen apps */
slouken@1895
   627
            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
slouken@1895
   628
                (wParam & 0xFFF0) == SC_MONITORPOWER) {
slouken@3032
   629
                if (SDL_GetVideoDevice()->suspend_screensaver) {
slouken@1895
   630
                    return (0);
slouken@1895
   631
                }
slouken@1895
   632
            }
slouken@1895
   633
        }
slouken@1895
   634
        break;
slouken@5086
   635
#endif /* System has screensaver support */
slouken@1895
   636
slouken@1895
   637
    case WM_CLOSE:
slouken@1895
   638
        {
slouken@3685
   639
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1895
   640
        }
slouken@3566
   641
        returnCode = 0;
slouken@3566
   642
        break;
slouken@4919
   643
jimtla@4650
   644
	case WM_TOUCH:
slouken@4932
   645
		{
slouken@4932
   646
			UINT i, num_inputs = LOWORD(wParam);
slouken@4932
   647
			PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
slouken@4919
   648
			if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
slouken@4932
   649
				RECT rect;
slouken@4919
   650
				float x, y;
slouken@4919
   651
slouken@4919
   652
				if (!GetClientRect(hwnd, &rect) ||
slouken@4919
   653
				    (rect.right == rect.left && rect.bottom == rect.top)) {
slouken@4919
   654
					break;
slouken@4919
   655
				}
slouken@4919
   656
				ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@4932
   657
				ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@4932
   658
				rect.top *= 100;
slouken@4932
   659
				rect.left *= 100;
slouken@4932
   660
				rect.bottom *= 100;
slouken@4932
   661
				rect.right *= 100;
slouken@4932
   662
slouken@4932
   663
				for (i = 0; i < num_inputs; ++i) {
slouken@4932
   664
					PTOUCHINPUT input = &inputs[i];
slouken@4919
   665
icculus@5889
   666
					const SDL_TouchID touchId = (SDL_TouchID)
icculus@5889
   667
												((size_t)input->hSource);
slouken@4919
   668
					if (!SDL_GetTouch(touchId)) {
slouken@4919
   669
						SDL_Touch touch;
slouken@4919
   670
slouken@4919
   671
						touch.id = touchId;
slouken@4919
   672
						touch.x_min = 0;
slouken@4919
   673
						touch.x_max = 1;
slouken@4919
   674
						touch.native_xres = touch.x_max - touch.x_min;
slouken@4919
   675
						touch.y_min = 0;
slouken@4919
   676
						touch.y_max = 1;
slouken@4919
   677
						touch.native_yres = touch.y_max - touch.y_min;
slouken@4919
   678
						touch.pressure_min = 0;
slouken@4919
   679
						touch.pressure_max = 1;
slouken@4919
   680
						touch.native_pressureres = touch.pressure_max - touch.pressure_min;
slouken@4919
   681
slouken@4919
   682
						if (SDL_AddTouch(&touch, "") < 0) {
slouken@4919
   683
							continue;
slouken@4919
   684
						}
slouken@4932
   685
					}
slouken@4932
   686
slouken@4932
   687
					// Get the normalized coordinates for the window
slouken@4932
   688
					x = (float)(input->x - rect.left)/(rect.right - rect.left);
slouken@4932
   689
					y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
slouken@4932
   690
slouken@4919
   691
					if (input->dwFlags & TOUCHEVENTF_DOWN) {
slouken@4932
   692
						SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
slouken@4932
   693
					}
slouken@4919
   694
					if (input->dwFlags & TOUCHEVENTF_MOVE) {
slouken@4932
   695
						SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
slouken@4932
   696
					}
slouken@4919
   697
					if (input->dwFlags & TOUCHEVENTF_UP) {
slouken@4932
   698
						SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
slouken@4932
   699
					}
slouken@4932
   700
				}
slouken@4932
   701
			}
slouken@4932
   702
			SDL_stack_free(inputs);
slouken@4932
   703
slouken@4932
   704
			data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
slouken@4919
   705
			return 0;
jimtla@4650
   706
		}
jimtla@4650
   707
		break;
slouken@6523
   708
slouken@6523
   709
    case WM_DROPFILES:
slouken@6523
   710
        {
slouken@6523
   711
            UINT i;
slouken@6523
   712
            HDROP drop = (HDROP) wParam;
slouken@6523
   713
            UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
slouken@6523
   714
            for (i = 0; i < count; ++i) {
slouken@6523
   715
                UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
slouken@6523
   716
                LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
slouken@6523
   717
                if (buffer) {
slouken@6523
   718
                    if (DragQueryFile(drop, i, buffer, size)) {
slouken@6523
   719
                        char *file = WIN_StringToUTF8(buffer);
slouken@6523
   720
                        SDL_SendDropFile(file);
slouken@6523
   721
                        SDL_free(file);
slouken@6523
   722
                    }
slouken@6523
   723
                    SDL_stack_free(buffer);
slouken@6523
   724
                }
slouken@6523
   725
            }
slouken@6523
   726
            DragFinish(drop);
slouken@6523
   727
            return 0;
slouken@6523
   728
        }
slouken@6523
   729
        break;
slouken@6523
   730
    }
slouken@3566
   731
slouken@3566
   732
    /* If there's a window proc, assume it's going to handle messages */
slouken@3566
   733
    if (data->wndproc) {
slouken@3566
   734
        return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
slouken@3566
   735
    } else if (returnCode >= 0) {
slouken@3566
   736
        return returnCode;
slouken@3566
   737
    } else {
slouken@3566
   738
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@3566
   739
    }
slouken@1895
   740
}
slouken@1895
   741
slouken@1895
   742
void
slouken@1895
   743
WIN_PumpEvents(_THIS)
slouken@1895
   744
{
slouken@1895
   745
    MSG msg;
slouken@1895
   746
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
slouken@1895
   747
        TranslateMessage(&msg);
slouken@1895
   748
        DispatchMessage(&msg);
slouken@1895
   749
    }
slouken@1895
   750
}
slouken@1895
   751
slouken@1895
   752
static int app_registered = 0;
slouken@1895
   753
LPTSTR SDL_Appname = NULL;
slouken@1895
   754
Uint32 SDL_Appstyle = 0;
slouken@1895
   755
HINSTANCE SDL_Instance = NULL;
slouken@1895
   756
slouken@1895
   757
/* Register the class for this application */
slouken@1895
   758
int
slouken@1895
   759
SDL_RegisterApp(char *name, Uint32 style, void *hInst)
slouken@1895
   760
{
slouken@1895
   761
    WNDCLASS class;
slouken@1895
   762
slouken@1895
   763
    /* Only do this once... */
slouken@1895
   764
    if (app_registered) {
slouken@1895
   765
        ++app_registered;
slouken@1895
   766
        return (0);
slouken@1895
   767
    }
slouken@1895
   768
    if (!name && !SDL_Appname) {
slouken@1895
   769
        name = "SDL_app";
slouken@5086
   770
#if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC)
slouken@1895
   771
        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
slouken@5086
   772
#endif
slouken@1895
   773
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   774
    }
slouken@1895
   775
slouken@1895
   776
    if (name) {
slouken@1895
   777
        SDL_Appname = WIN_UTF8ToString(name);
slouken@1895
   778
        SDL_Appstyle = style;
slouken@1895
   779
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   780
    }
slouken@1895
   781
slouken@1895
   782
    /* Register the application class */
slouken@1895
   783
    class.hCursor = NULL;
slouken@2710
   784
    class.hIcon =
slouken@2710
   785
        LoadImage(SDL_Instance, SDL_Appname, IMAGE_ICON, 0, 0,
slouken@2710
   786
                  LR_DEFAULTCOLOR);
slouken@1895
   787
    class.lpszMenuName = NULL;
slouken@1895
   788
    class.lpszClassName = SDL_Appname;
slouken@1895
   789
    class.hbrBackground = NULL;
slouken@1895
   790
    class.hInstance = SDL_Instance;
slouken@1895
   791
    class.style = SDL_Appstyle;
dewyatt@4733
   792
    class.lpfnWndProc = WIN_WindowProc;
slouken@1895
   793
    class.cbWndExtra = 0;
slouken@1895
   794
    class.cbClsExtra = 0;
slouken@1895
   795
    if (!RegisterClass(&class)) {
slouken@1895
   796
        SDL_SetError("Couldn't register application class");
slouken@1895
   797
        return (-1);
slouken@1895
   798
    }
slouken@1895
   799
slouken@1895
   800
    app_registered = 1;
slouken@1895
   801
    return (0);
slouken@1895
   802
}
slouken@1895
   803
slouken@1895
   804
/* Unregisters the windowclass registered in SDL_RegisterApp above. */
slouken@1895
   805
void
slouken@1895
   806
SDL_UnregisterApp()
slouken@1895
   807
{
slouken@1895
   808
    WNDCLASS class;
slouken@1895
   809
slouken@1895
   810
    /* SDL_RegisterApp might not have been called before */
slouken@1895
   811
    if (!app_registered) {
slouken@1895
   812
        return;
slouken@1895
   813
    }
slouken@1895
   814
    --app_registered;
slouken@1895
   815
    if (app_registered == 0) {
slouken@1895
   816
        /* Check for any registered window classes. */
slouken@1895
   817
        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
slouken@1895
   818
            UnregisterClass(SDL_Appname, SDL_Instance);
slouken@1895
   819
        }
slouken@1895
   820
        SDL_free(SDL_Appname);
slouken@1895
   821
        SDL_Appname = NULL;
slouken@1895
   822
    }
slouken@1895
   823
}
slouken@1895
   824
slouken@6044
   825
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
slouken@6044
   826
slouken@1895
   827
/* vi: set ts=4 sw=4 expandtab: */