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