src/video/windows/SDL_windowsevents.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 27 Feb 2013 11:39:43 -0800
changeset 6945 d97f9251ac3a
parent 6944 e8effbc1a10e
child 6947 18ccf3e4921d
permissions -rw-r--r--
sdl - check for both the up and down flags being set in the raw input calls. Also use WM_ACTIVE to resync mouse buttons on activate
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@6945
   229
		if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) )
slouken@6945
   230
			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
slouken@6945
   231
		if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) )
slouken@6945
   232
			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
slouken@6945
   233
		if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) )
slouken@6945
   234
			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
slouken@6945
   235
		if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) )
slouken@6945
   236
			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
slouken@6945
   237
		if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) )
slouken@6945
   238
			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
slouken@6945
   239
		if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) )
slouken@6945
   240
			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
slouken@6945
   241
		if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) )
slouken@6945
   242
			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
slouken@6945
   243
		if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) )
slouken@6945
   244
			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
slouken@6945
   245
		if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) )
slouken@6945
   246
			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
slouken@6945
   247
		if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) )
slouken@6945
   248
			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
slouken@6943
   249
		data->mouse_button_flags = rawButtons;
slouken@6943
   250
	}
slouken@6943
   251
}
slouken@6943
   252
slouken@1895
   253
LRESULT CALLBACK
slouken@1895
   254
WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
slouken@1895
   255
{
slouken@1895
   256
    SDL_WindowData *data;
slouken@3566
   257
    LRESULT returnCode = -1;
slouken@1895
   258
slouken@1951
   259
    /* Send a SDL_SYSWMEVENT if the application wants them */
slouken@4429
   260
    if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
slouken@1951
   261
        SDL_SysWMmsg wmmsg;
slouken@1951
   262
slouken@1951
   263
        SDL_VERSION(&wmmsg.version);
slouken@4900
   264
        wmmsg.subsystem = SDL_SYSWM_WINDOWS;
slouken@5056
   265
        wmmsg.msg.win.hwnd = hwnd;
slouken@5056
   266
        wmmsg.msg.win.msg = msg;
slouken@5056
   267
        wmmsg.msg.win.wParam = wParam;
slouken@5056
   268
        wmmsg.msg.win.lParam = lParam;
slouken@1951
   269
        SDL_SendSysWMEvent(&wmmsg);
slouken@1951
   270
    }
slouken@1951
   271
slouken@1895
   272
    /* Get the window data for the window */
slouken@1895
   273
    data = (SDL_WindowData *) GetProp(hwnd, TEXT("SDL_WindowData"));
slouken@1895
   274
    if (!data) {
slouken@1895
   275
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@1895
   276
    }
jimtla@4650
   277
slouken@1895
   278
#ifdef WMMSG_DEBUG
jimtla@4650
   279
    {		
jimtla@4650
   280
        FILE *log = fopen("wmmsg.txt", "a");		
slouken@1913
   281
        fprintf(log, "Received windows message: %p ", hwnd);
slouken@1913
   282
        if (msg > MAX_WMMSG) {
slouken@1913
   283
            fprintf(log, "%d", msg);
slouken@1913
   284
        } else {
slouken@1913
   285
            fprintf(log, "%s", wmtab[msg]);
slouken@1913
   286
        }
slouken@1913
   287
        fprintf(log, " -- 0x%X, 0x%X\n", wParam, lParam);
slouken@1913
   288
        fclose(log);
slouken@1895
   289
    }
slouken@4868
   290
#endif
slouken@2710
   291
dewyatt@4752
   292
    if (IME_HandleMessage(hwnd, msg, wParam, &lParam, data->videodata))
dewyatt@4752
   293
        return 0;
slouken@1895
   294
slouken@1895
   295
    switch (msg) {
slouken@1895
   296
slouken@1895
   297
    case WM_SHOWWINDOW:
slouken@1895
   298
        {
slouken@1895
   299
            if (wParam) {
slouken@3685
   300
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@1895
   301
            } else {
slouken@3685
   302
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
slouken@1895
   303
            }
slouken@1895
   304
        }
slouken@1895
   305
        break;
slouken@1895
   306
slouken@1895
   307
    case WM_ACTIVATE:
slouken@1895
   308
        {
slouken@1895
   309
            BOOL minimized;
slouken@1895
   310
slouken@1895
   311
            minimized = HIWORD(wParam);
slouken@1895
   312
            if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
slouken@6945
   313
				Uint32 mouseFlags;
slouken@6945
   314
				SHORT keyState;
slouken@6945
   315
slouken@3685
   316
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
slouken@3685
   317
                SDL_SendWindowEvent(data->window,
slouken@1895
   318
                                    SDL_WINDOWEVENT_RESTORED, 0, 0);
slouken@1895
   319
                if (IsZoomed(hwnd)) {
slouken@3685
   320
                    SDL_SendWindowEvent(data->window,
slouken@1895
   321
                                        SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
slouken@1895
   322
                }
slouken@4465
   323
                if (SDL_GetKeyboardFocus() != data->window) {
slouken@4465
   324
                    SDL_SetKeyboardFocus(data->window);
slouken@1895
   325
                }
slouken@6945
   326
				/* mouse buttons may have changed state here, we need
slouken@6943
   327
				to resync them, but we will get a WM_MOUSEMOVE right away which will fix 
slouken@6945
   328
				things up if in non raw mode also
slouken@6943
   329
				*/
slouken@6945
   330
				mouseFlags = SDL_GetMouseState( NULL, NULL );
slouken@6945
   331
slouken@6945
   332
				keyState = GetAsyncKeyState( VK_LBUTTON );
slouken@6945
   333
				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
slouken@6945
   334
				keyState = GetAsyncKeyState( VK_RBUTTON );
slouken@6945
   335
				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
slouken@6945
   336
				keyState = GetAsyncKeyState( VK_MBUTTON );
slouken@6945
   337
				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
slouken@6945
   338
				keyState = GetAsyncKeyState( VK_XBUTTON1 );
slouken@6945
   339
				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
slouken@6945
   340
				keyState = GetAsyncKeyState( VK_XBUTTON2 );
slouken@6945
   341
				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
slouken@6945
   342
				data->mouse_button_flags = 0;
slouken@6350
   343
slouken@6350
   344
				if(SDL_GetMouse()->relative_mode) {
slouken@6350
   345
					LONG cx, cy;
slouken@6350
   346
					RECT rect;
slouken@6350
   347
					GetWindowRect(hwnd, &rect);
slouken@6350
   348
slouken@6350
   349
					cx = (rect.left + rect.right) / 2;
slouken@6350
   350
					cy = (rect.top + rect.bottom) / 2;
slouken@6350
   351
slouken@6350
   352
					/* Make an absurdly small clip rect */
slouken@6350
   353
					rect.left = cx-1;
slouken@6350
   354
					rect.right = cx+1;
slouken@6350
   355
					rect.top = cy-1;
slouken@6350
   356
					rect.bottom = cy+1;
slouken@6350
   357
slouken@6350
   358
					ClipCursor(&rect);
slouken@6350
   359
				}
slouken@6350
   360
slouken@4504
   361
                /*
slouken@4504
   362
                 * FIXME: Update keyboard state
slouken@4504
   363
                 */
slouken@4504
   364
                WIN_CheckClipboardUpdate(data->videodata);
slouken@1895
   365
            } else {
slouken@4465
   366
                if (SDL_GetKeyboardFocus() == data->window) {
slouken@4465
   367
                    SDL_SetKeyboardFocus(NULL);
slouken@1895
   368
                }
slouken@1895
   369
                if (minimized) {
slouken@3685
   370
                    SDL_SendWindowEvent(data->window,
slouken@1895
   371
                                        SDL_WINDOWEVENT_MINIMIZED, 0, 0);
slouken@1895
   372
                }
slouken@1895
   373
            }
slouken@1895
   374
        }
slouken@3566
   375
        returnCode = 0;
slouken@3566
   376
        break;
slouken@1895
   377
slouken@4470
   378
	case WM_MOUSEMOVE:
slouken@6943
   379
		if( !SDL_GetMouse()->relative_mode )
slouken@6943
   380
	        SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));
slouken@6943
   381
		/* don't break here, fall through to check the wParam like the button presses */
slouken@6945
   382
	case WM_LBUTTONUP:
slouken@6945
   383
	case WM_RBUTTONUP:
slouken@6945
   384
	case WM_MBUTTONUP:
slouken@6945
   385
	case WM_XBUTTONUP:
slouken@6943
   386
	case WM_LBUTTONDOWN:
slouken@6943
   387
	case WM_RBUTTONDOWN:
slouken@6943
   388
	case WM_MBUTTONDOWN:
slouken@6943
   389
	case WM_XBUTTONDOWN:
slouken@6945
   390
		if( !SDL_GetMouse()->relative_mode )
slouken@6945
   391
			WIN_CheckWParamMouseButtons( wParam, data );
slouken@6943
   392
		break;
slouken@3139
   393
slouken@6350
   394
	case WM_INPUT:
slouken@6350
   395
	{
slouken@6350
   396
		HRAWINPUT hRawInput = (HRAWINPUT)lParam;
slouken@6350
   397
		RAWINPUT inp;
slouken@6350
   398
		UINT size = sizeof(inp);
slouken@6782
   399
slouken@6782
   400
		if(!SDL_GetMouse()->relative_mode)
slouken@6782
   401
			break;
slouken@6782
   402
slouken@6350
   403
		GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
slouken@6350
   404
slouken@6350
   405
		/* Mouse data */
slouken@6350
   406
		if(inp.header.dwType == RIM_TYPEMOUSE)
slouken@6350
   407
		{
slouken@6350
   408
			RAWMOUSE* mouse = &inp.data.mouse;
slouken@6350
   409
slouken@6350
   410
			if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
slouken@6782
   411
			{
slouken@6350
   412
				SDL_SendMouseMotion(data->window, 1, (int)mouse->lLastX, (int)mouse->lLastY);
slouken@6782
   413
			}
slouken@6782
   414
			else
slouken@6782
   415
			{
slouken@6782
   416
				// synthesize relative moves from the abs position
slouken@6782
   417
				static SDL_Point initialMousePoint;
slouken@6782
   418
				if ( initialMousePoint.x == 0 && initialMousePoint.y == 0 )
slouken@6782
   419
				{
slouken@6782
   420
					initialMousePoint.x = mouse->lLastX;
slouken@6782
   421
					initialMousePoint.y = mouse->lLastY;
slouken@6782
   422
				}
slouken@6350
   423
slouken@6782
   424
				SDL_SendMouseMotion(data->window, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
slouken@6782
   425
slouken@6782
   426
				initialMousePoint.x = mouse->lLastX;
slouken@6782
   427
				initialMousePoint.y = mouse->lLastY;
slouken@6782
   428
			}
slouken@6945
   429
			WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); 
slouken@6350
   430
		}
slouken@6350
   431
		break;
slouken@6350
   432
	}
slouken@6350
   433
slouken@5049
   434
    case WM_MOUSEWHEEL:
slouken@5049
   435
        {
slouken@6861
   436
            // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
slouken@6861
   437
            short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
slouken@5049
   438
slouken@5049
   439
            SDL_SendMouseWheel(data->window, 0, motion);
slouken@5049
   440
            break;
slouken@5049
   441
        }
slouken@5049
   442
slouken@5086
   443
#ifdef WM_MOUSELEAVE
slouken@5086
   444
    /* FIXME: Do we need the SDL 1.2 hack to generate WM_MOUSELEAVE now? */
slouken@1895
   445
    case WM_MOUSELEAVE:
slouken@4470
   446
        if (SDL_GetMouseFocus() == data->window) {
slouken@4470
   447
            SDL_SetMouseFocus(NULL);
slouken@1895
   448
        }
slouken@3566
   449
        returnCode = 0;
slouken@3566
   450
        break;
slouken@5086
   451
#endif /* WM_MOUSELEAVE */
slouken@1895
   452
slouken@1895
   453
    case WM_SYSKEYDOWN:
slouken@1895
   454
    case WM_KEYDOWN:
slouken@1895
   455
        {
jorgen@6925
   456
			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
jorgen@6922
   457
			if ( code != SDL_SCANCODE_UNKNOWN ) {
jorgen@6922
   458
                SDL_SendKeyboardKey(SDL_PRESSED, code );
slouken@2308
   459
            }
slouken@1895
   460
        }
slouken@3566
   461
        returnCode = 0;
slouken@3566
   462
        break;
slouken@1895
   463
slouken@1895
   464
    case WM_SYSKEYUP:
slouken@1895
   465
    case WM_KEYUP:
slouken@1895
   466
        {
jorgen@6925
   467
			SDL_Scancode code =  WindowsScanCodeToSDLScanCode( lParam, wParam, data->videodata->key_layout );
jorgen@6922
   468
			if ( code != SDL_SCANCODE_UNKNOWN ) {
jorgen@6922
   469
				if (wParam == VK_SNAPSHOT
jorgen@6922
   470
				    && SDL_GetKeyboardState(NULL)[SDL_SCANCODE_PRINTSCREEN] ==
jorgen@6922
   471
				    SDL_RELEASED) {
jorgen@6922
   472
				    SDL_SendKeyboardKey(SDL_PRESSED,
jorgen@6922
   473
				                         code);
jorgen@6922
   474
				}
jorgen@6922
   475
                SDL_SendKeyboardKey(SDL_RELEASED, code );
slouken@2308
   476
            }
slouken@1895
   477
        }
slouken@3566
   478
        returnCode = 0;
slouken@3566
   479
        break;
slouken@1895
   480
slouken@2309
   481
    case WM_CHAR:
slouken@2309
   482
        {
slouken@2309
   483
            char text[4];
slouken@2309
   484
slouken@2309
   485
            /* Convert to UTF-8 and send it on... */
slouken@2309
   486
            if (wParam <= 0x7F) {
slouken@2309
   487
                text[0] = (char) wParam;
slouken@2309
   488
                text[1] = '\0';
slouken@2309
   489
            } else if (wParam <= 0x7FF) {
slouken@2309
   490
                text[0] = 0xC0 | (char) ((wParam >> 6) & 0x1F);
slouken@2309
   491
                text[1] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   492
                text[2] = '\0';
slouken@2309
   493
            } else {
slouken@2309
   494
                text[0] = 0xE0 | (char) ((wParam >> 12) & 0x0F);
slouken@2309
   495
                text[1] = 0x80 | (char) ((wParam >> 6) & 0x3F);
slouken@2309
   496
                text[2] = 0x80 | (char) (wParam & 0x3F);
slouken@2309
   497
                text[3] = '\0';
slouken@2309
   498
            }
slouken@4465
   499
            SDL_SendKeyboardText(text);
slouken@2309
   500
        }
slouken@3566
   501
        returnCode = 0;
slouken@3566
   502
        break;
slouken@2309
   503
slouken@5086
   504
#ifdef WM_INPUTLANGCHANGE
slouken@2311
   505
    case WM_INPUTLANGCHANGE:
slouken@2311
   506
        {
slouken@4465
   507
            WIN_UpdateKeymap();
slouken@2311
   508
        }
slouken@3566
   509
        returnCode = 1;
slouken@3566
   510
        break;
slouken@5086
   511
#endif /* WM_INPUTLANGCHANGE */
slouken@2311
   512
slouken@5086
   513
#ifdef WM_GETMINMAXINFO
slouken@1895
   514
    case WM_GETMINMAXINFO:
slouken@1895
   515
        {
slouken@1895
   516
            MINMAXINFO *info;
slouken@1895
   517
            RECT size;
slouken@1895
   518
            int x, y;
slouken@1895
   519
            int w, h;
stopiccot@6682
   520
            int min_w, min_h;
slouken@6788
   521
            int max_w, max_h;
slouken@1895
   522
            int style;
slouken@3168
   523
            BOOL menu;
slouken@6862
   524
			BOOL constrain_max_size;
slouken@1895
   525
slouken@1895
   526
            /* If we allow resizing, let the resize happen naturally */
stopiccot@6682
   527
            if (SDL_IsShapedWindow(data->window))
eligottlieb@4815
   528
                Win32_ResizeWindowShape(data->window);
slouken@1895
   529
slouken@1895
   530
            /* Get the current position of our window */
slouken@1895
   531
            GetWindowRect(hwnd, &size);
slouken@1895
   532
            x = size.left;
slouken@1895
   533
            y = size.top;
slouken@1895
   534
slouken@1895
   535
            /* Calculate current size of our window */
slouken@3685
   536
            SDL_GetWindowSize(data->window, &w, &h);
stopiccot@6682
   537
            SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
slouken@6788
   538
            SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
stopiccot@6682
   539
stopiccot@6682
   540
            /* Store in min_w and min_h difference between current size and minimal 
stopiccot@6682
   541
               size so we don't need to call AdjustWindowRectEx twice */
stopiccot@6682
   542
            min_w -= w;
stopiccot@6682
   543
            min_h -= h;
slouken@6837
   544
            if (max_w && max_h) {
slouken@6837
   545
                max_w -= w;
slouken@6837
   546
                max_h -= h;
slouken@6862
   547
                constrain_max_size = TRUE;
slouken@6862
   548
            } else {
slouken@6862
   549
                constrain_max_size = FALSE;
slouken@6837
   550
            }
stopiccot@6682
   551
slouken@1895
   552
            size.top = 0;
slouken@1895
   553
            size.left = 0;
slouken@1895
   554
            size.bottom = h;
slouken@1895
   555
            size.right = w;
slouken@1895
   556
slouken@3168
   557
            style = GetWindowLong(hwnd, GWL_STYLE);
slouken@1895
   558
            /* DJM - according to the docs for GetMenu(), the
slouken@1895
   559
               return value is undefined if hwnd is a child window.
slouken@1895
   560
               Aparently it's too difficult for MS to check
slouken@1895
   561
               inside their function, so I have to do it here.
slouken@1895
   562
             */
slouken@3168
   563
            menu = (style & WS_CHILDWINDOW) ? FALSE : (GetMenu(hwnd) != NULL);
slouken@3168
   564
            AdjustWindowRectEx(&size, style, menu, 0);
slouken@1895
   565
            w = size.right - size.left;
slouken@1895
   566
            h = size.bottom - size.top;
slouken@1895
   567
slouken@1895
   568
            /* Fix our size to the current size */
slouken@1895
   569
            info = (MINMAXINFO *) lParam;
stopiccot@6682
   570
            if (SDL_GetWindowFlags(data->window) & SDL_WINDOW_RESIZABLE) {
stopiccot@6682
   571
                info->ptMinTrackSize.x = w + min_w;
stopiccot@6682
   572
                info->ptMinTrackSize.y = h + min_h;
slouken@6862
   573
                if (constrain_max_size) {
slouken@6862
   574
                    info->ptMaxTrackSize.x = w + max_w;
slouken@6862
   575
                    info->ptMaxTrackSize.y = h + max_h;
slouken@6862
   576
                }
stopiccot@6682
   577
            } else {
stopiccot@6682
   578
                info->ptMaxSize.x = w;
stopiccot@6682
   579
                info->ptMaxSize.y = h;
stopiccot@6682
   580
                info->ptMaxPosition.x = x;
stopiccot@6682
   581
                info->ptMaxPosition.y = y;
stopiccot@6682
   582
                info->ptMinTrackSize.x = w;
stopiccot@6682
   583
                info->ptMinTrackSize.y = h;
stopiccot@6682
   584
                info->ptMaxTrackSize.x = w;
stopiccot@6682
   585
                info->ptMaxTrackSize.y = h;
stopiccot@6682
   586
            }
slouken@1895
   587
        }
slouken@3566
   588
        returnCode = 0;
slouken@3566
   589
        break;
slouken@5086
   590
#endif /* WM_GETMINMAXINFO */
slouken@1895
   591
slouken@1895
   592
    case WM_WINDOWPOSCHANGED:
slouken@1895
   593
        {
slouken@1895
   594
            RECT rect;
slouken@1895
   595
            int x, y;
slouken@1895
   596
            int w, h;
slouken@1895
   597
            Uint32 window_flags;
slouken@1895
   598
slouken@3256
   599
            if (!GetClientRect(hwnd, &rect) ||
slouken@3256
   600
                (rect.right == rect.left && rect.bottom == rect.top)) {
slouken@3256
   601
                break;
slouken@3256
   602
            }
slouken@1895
   603
            ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@1895
   604
            ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@1895
   605
slouken@3685
   606
            window_flags = SDL_GetWindowFlags(data->window);
slouken@1895
   607
            if ((window_flags & SDL_WINDOW_INPUT_GRABBED) &&
slouken@1895
   608
                (window_flags & SDL_WINDOW_INPUT_FOCUS)) {
slouken@1895
   609
                ClipCursor(&rect);
slouken@1895
   610
            }
slouken@1895
   611
slouken@1895
   612
            x = rect.left;
slouken@1895
   613
            y = rect.top;
slouken@3685
   614
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED, x, y);
slouken@1895
   615
slouken@1895
   616
            w = rect.right - rect.left;
slouken@1895
   617
            h = rect.bottom - rect.top;
slouken@3685
   618
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED, w,
slouken@1895
   619
                                h);
slouken@1895
   620
        }
slouken@1895
   621
        break;
slouken@1895
   622
slouken@1895
   623
    case WM_SETCURSOR:
slouken@1895
   624
        {
slouken@3076
   625
            Uint16 hittest;
slouken@1895
   626
slouken@3076
   627
            hittest = LOWORD(lParam);
slouken@3076
   628
            if (hittest == HTCLIENT) {
slouken@5421
   629
                SetCursor(SDL_cursor);
slouken@3566
   630
                returnCode = TRUE;
slouken@3076
   631
            }
slouken@1895
   632
        }
slouken@1895
   633
        break;
slouken@1895
   634
slouken@1895
   635
        /* We were occluded, refresh our display */
slouken@1895
   636
    case WM_PAINT:
slouken@1895
   637
        {
slouken@1895
   638
            RECT rect;
slouken@1895
   639
            if (GetUpdateRect(hwnd, &rect, FALSE)) {
slouken@1895
   640
                ValidateRect(hwnd, &rect);
slouken@3685
   641
                SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED,
slouken@1895
   642
                                    0, 0);
slouken@1895
   643
            }
slouken@1895
   644
        }
slouken@3566
   645
        returnCode = 0;
slouken@3566
   646
        break;
slouken@3095
   647
slouken@1895
   648
        /* We'll do our own drawing, prevent flicker */
slouken@1895
   649
    case WM_ERASEBKGND:
slouken@1895
   650
        {
slouken@1895
   651
        }
slouken@1895
   652
        return (1);
slouken@1895
   653
slouken@5086
   654
#if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)
slouken@1895
   655
    case WM_SYSCOMMAND:
slouken@1895
   656
        {
slouken@1895
   657
            /* Don't start the screensaver or blank the monitor in fullscreen apps */
slouken@1895
   658
            if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
slouken@1895
   659
                (wParam & 0xFFF0) == SC_MONITORPOWER) {
slouken@3032
   660
                if (SDL_GetVideoDevice()->suspend_screensaver) {
slouken@1895
   661
                    return (0);
slouken@1895
   662
                }
slouken@1895
   663
            }
slouken@1895
   664
        }
slouken@1895
   665
        break;
slouken@5086
   666
#endif /* System has screensaver support */
slouken@1895
   667
slouken@1895
   668
    case WM_CLOSE:
slouken@1895
   669
        {
slouken@3685
   670
            SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
slouken@1895
   671
        }
slouken@3566
   672
        returnCode = 0;
slouken@3566
   673
        break;
slouken@4919
   674
jimtla@4650
   675
	case WM_TOUCH:
slouken@4932
   676
		{
slouken@4932
   677
			UINT i, num_inputs = LOWORD(wParam);
slouken@4932
   678
			PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
slouken@4919
   679
			if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
slouken@4932
   680
				RECT rect;
slouken@4919
   681
				float x, y;
slouken@4919
   682
slouken@4919
   683
				if (!GetClientRect(hwnd, &rect) ||
slouken@4919
   684
				    (rect.right == rect.left && rect.bottom == rect.top)) {
slouken@4919
   685
					break;
slouken@4919
   686
				}
slouken@4919
   687
				ClientToScreen(hwnd, (LPPOINT) & rect);
slouken@4932
   688
				ClientToScreen(hwnd, (LPPOINT) & rect + 1);
slouken@4932
   689
				rect.top *= 100;
slouken@4932
   690
				rect.left *= 100;
slouken@4932
   691
				rect.bottom *= 100;
slouken@4932
   692
				rect.right *= 100;
slouken@4932
   693
slouken@4932
   694
				for (i = 0; i < num_inputs; ++i) {
slouken@4932
   695
					PTOUCHINPUT input = &inputs[i];
slouken@4919
   696
icculus@5889
   697
					const SDL_TouchID touchId = (SDL_TouchID)
icculus@5889
   698
												((size_t)input->hSource);
slouken@4919
   699
					if (!SDL_GetTouch(touchId)) {
slouken@4919
   700
						SDL_Touch touch;
slouken@4919
   701
slouken@4919
   702
						touch.id = touchId;
slouken@4919
   703
						touch.x_min = 0;
slouken@4919
   704
						touch.x_max = 1;
slouken@4919
   705
						touch.native_xres = touch.x_max - touch.x_min;
slouken@4919
   706
						touch.y_min = 0;
slouken@4919
   707
						touch.y_max = 1;
slouken@4919
   708
						touch.native_yres = touch.y_max - touch.y_min;
slouken@4919
   709
						touch.pressure_min = 0;
slouken@4919
   710
						touch.pressure_max = 1;
slouken@4919
   711
						touch.native_pressureres = touch.pressure_max - touch.pressure_min;
slouken@4919
   712
slouken@4919
   713
						if (SDL_AddTouch(&touch, "") < 0) {
slouken@4919
   714
							continue;
slouken@4919
   715
						}
slouken@4932
   716
					}
slouken@4932
   717
slouken@4932
   718
					// Get the normalized coordinates for the window
slouken@4932
   719
					x = (float)(input->x - rect.left)/(rect.right - rect.left);
slouken@4932
   720
					y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
slouken@4932
   721
slouken@4919
   722
					if (input->dwFlags & TOUCHEVENTF_DOWN) {
slouken@4932
   723
						SDL_SendFingerDown(touchId, input->dwID, SDL_TRUE, x, y, 1);
slouken@4932
   724
					}
slouken@4919
   725
					if (input->dwFlags & TOUCHEVENTF_MOVE) {
slouken@4932
   726
						SDL_SendTouchMotion(touchId, input->dwID, SDL_FALSE, x, y, 1);
slouken@4932
   727
					}
slouken@4919
   728
					if (input->dwFlags & TOUCHEVENTF_UP) {
slouken@4932
   729
						SDL_SendFingerDown(touchId, input->dwID, SDL_FALSE, x, y, 1);
slouken@4932
   730
					}
slouken@4932
   731
				}
slouken@4932
   732
			}
slouken@4932
   733
			SDL_stack_free(inputs);
slouken@4932
   734
slouken@4932
   735
			data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
slouken@4919
   736
			return 0;
jimtla@4650
   737
		}
jimtla@4650
   738
		break;
slouken@6523
   739
slouken@6523
   740
    case WM_DROPFILES:
slouken@6523
   741
        {
slouken@6523
   742
            UINT i;
slouken@6523
   743
            HDROP drop = (HDROP) wParam;
slouken@6523
   744
            UINT count = DragQueryFile(drop, 0xFFFFFFFF, NULL, 0);
slouken@6523
   745
            for (i = 0; i < count; ++i) {
slouken@6523
   746
                UINT size = DragQueryFile(drop, i, NULL, 0) + 1;
slouken@6523
   747
                LPTSTR buffer = SDL_stack_alloc(TCHAR, size);
slouken@6523
   748
                if (buffer) {
slouken@6523
   749
                    if (DragQueryFile(drop, i, buffer, size)) {
slouken@6523
   750
                        char *file = WIN_StringToUTF8(buffer);
slouken@6523
   751
                        SDL_SendDropFile(file);
slouken@6523
   752
                        SDL_free(file);
slouken@6523
   753
                    }
slouken@6523
   754
                    SDL_stack_free(buffer);
slouken@6523
   755
                }
slouken@6523
   756
            }
slouken@6523
   757
            DragFinish(drop);
slouken@6523
   758
            return 0;
slouken@6523
   759
        }
slouken@6523
   760
        break;
slouken@6523
   761
    }
slouken@3566
   762
slouken@3566
   763
    /* If there's a window proc, assume it's going to handle messages */
slouken@3566
   764
    if (data->wndproc) {
slouken@3566
   765
        return CallWindowProc(data->wndproc, hwnd, msg, wParam, lParam);
slouken@3566
   766
    } else if (returnCode >= 0) {
slouken@3566
   767
        return returnCode;
slouken@3566
   768
    } else {
slouken@3566
   769
        return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
slouken@3566
   770
    }
slouken@1895
   771
}
slouken@1895
   772
slouken@1895
   773
void
slouken@1895
   774
WIN_PumpEvents(_THIS)
slouken@1895
   775
{
slouken@1895
   776
    MSG msg;
slouken@1895
   777
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
slouken@1895
   778
        TranslateMessage(&msg);
slouken@1895
   779
        DispatchMessage(&msg);
slouken@1895
   780
    }
slouken@1895
   781
}
slouken@1895
   782
slouken@1895
   783
static int app_registered = 0;
slouken@1895
   784
LPTSTR SDL_Appname = NULL;
slouken@1895
   785
Uint32 SDL_Appstyle = 0;
slouken@1895
   786
HINSTANCE SDL_Instance = NULL;
slouken@1895
   787
slouken@1895
   788
/* Register the class for this application */
slouken@1895
   789
int
slouken@1895
   790
SDL_RegisterApp(char *name, Uint32 style, void *hInst)
slouken@1895
   791
{
slouken@1895
   792
    WNDCLASS class;
slouken@1895
   793
slouken@1895
   794
    /* Only do this once... */
slouken@1895
   795
    if (app_registered) {
slouken@1895
   796
        ++app_registered;
slouken@1895
   797
        return (0);
slouken@1895
   798
    }
slouken@1895
   799
    if (!name && !SDL_Appname) {
slouken@1895
   800
        name = "SDL_app";
slouken@5086
   801
#if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC)
slouken@1895
   802
        SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
slouken@5086
   803
#endif
slouken@1895
   804
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   805
    }
slouken@1895
   806
slouken@1895
   807
    if (name) {
slouken@1895
   808
        SDL_Appname = WIN_UTF8ToString(name);
slouken@1895
   809
        SDL_Appstyle = style;
slouken@1895
   810
        SDL_Instance = hInst ? hInst : GetModuleHandle(NULL);
slouken@1895
   811
    }
slouken@1895
   812
slouken@1895
   813
    /* Register the application class */
slouken@1895
   814
    class.hCursor = NULL;
slouken@2710
   815
    class.hIcon =
slouken@2710
   816
        LoadImage(SDL_Instance, SDL_Appname, IMAGE_ICON, 0, 0,
slouken@2710
   817
                  LR_DEFAULTCOLOR);
slouken@1895
   818
    class.lpszMenuName = NULL;
slouken@1895
   819
    class.lpszClassName = SDL_Appname;
slouken@1895
   820
    class.hbrBackground = NULL;
slouken@1895
   821
    class.hInstance = SDL_Instance;
slouken@1895
   822
    class.style = SDL_Appstyle;
dewyatt@4733
   823
    class.lpfnWndProc = WIN_WindowProc;
slouken@1895
   824
    class.cbWndExtra = 0;
slouken@1895
   825
    class.cbClsExtra = 0;
slouken@1895
   826
    if (!RegisterClass(&class)) {
slouken@1895
   827
        SDL_SetError("Couldn't register application class");
slouken@1895
   828
        return (-1);
slouken@1895
   829
    }
slouken@1895
   830
slouken@1895
   831
    app_registered = 1;
slouken@1895
   832
    return (0);
slouken@1895
   833
}
slouken@1895
   834
slouken@1895
   835
/* Unregisters the windowclass registered in SDL_RegisterApp above. */
slouken@1895
   836
void
slouken@1895
   837
SDL_UnregisterApp()
slouken@1895
   838
{
slouken@1895
   839
    WNDCLASS class;
slouken@1895
   840
slouken@1895
   841
    /* SDL_RegisterApp might not have been called before */
slouken@1895
   842
    if (!app_registered) {
slouken@1895
   843
        return;
slouken@1895
   844
    }
slouken@1895
   845
    --app_registered;
slouken@1895
   846
    if (app_registered == 0) {
slouken@1895
   847
        /* Check for any registered window classes. */
slouken@1895
   848
        if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) {
slouken@1895
   849
            UnregisterClass(SDL_Appname, SDL_Instance);
slouken@1895
   850
        }
slouken@1895
   851
        SDL_free(SDL_Appname);
slouken@1895
   852
        SDL_Appname = NULL;
slouken@1895
   853
    }
slouken@1895
   854
}
slouken@1895
   855
slouken@6044
   856
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
slouken@6044
   857
slouken@1895
   858
/* vi: set ts=4 sw=4 expandtab: */