src/video/windows/SDL_windowsevents.c
changeset 7191 75360622e65f
parent 7089 257fc4e541e1
child 7275 0a6b3b998814
     1.1 --- a/src/video/windows/SDL_windowsevents.c	Sat May 18 12:48:50 2013 -0700
     1.2 +++ b/src/video/windows/SDL_windowsevents.c	Sat May 18 14:17:52 2013 -0700
     1.3 @@ -36,7 +36,7 @@
     1.4  
     1.5  /*#define WMMSG_DEBUG*/
     1.6  #ifdef WMMSG_DEBUG
     1.7 -#include <stdio.h>	
     1.8 +#include <stdio.h>
     1.9  #include "wmmsg.h"
    1.10  #endif
    1.11  
    1.12 @@ -46,7 +46,7 @@
    1.13  
    1.14  #define VK_ENTER    10          /* Keypad Enter ... no VKEY defined? */
    1.15  #ifndef VK_OEM_NEC_EQUAL
    1.16 -#define VK_OEM_NEC_EQUAL 0x92 
    1.17 +#define VK_OEM_NEC_EQUAL 0x92
    1.18  #endif
    1.19  
    1.20  /* Make sure XBUTTON stuff is defined that isn't in older Platform SDKs... */
    1.21 @@ -66,192 +66,192 @@
    1.22  #define WM_TOUCH 0x0240
    1.23  #endif
    1.24  
    1.25 -static SDL_Scancode 
    1.26 +static SDL_Scancode
    1.27  WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
    1.28  {
    1.29 -	SDL_Scancode code;
    1.30 -	char bIsExtended;
    1.31 -	int nScanCode = ( lParam >> 16 ) & 0xFF;
    1.32 +    SDL_Scancode code;
    1.33 +    char bIsExtended;
    1.34 +    int nScanCode = ( lParam >> 16 ) & 0xFF;
    1.35  
    1.36 -	/* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
    1.37 -	if ( nScanCode == 0 || nScanCode == 0x45 )
    1.38 -	{
    1.39 -		switch( wParam )
    1.40 -		{
    1.41 -		case VK_CLEAR: return SDL_SCANCODE_CLEAR;
    1.42 -		case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    1.43 -		case VK_SELECT: return SDL_SCANCODE_SELECT;
    1.44 -		case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
    1.45 -		case VK_HELP: return SDL_SCANCODE_HELP;
    1.46 -		case VK_PAUSE: return SDL_SCANCODE_PAUSE;
    1.47 -		case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR;
    1.48 +    /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
    1.49 +    if ( nScanCode == 0 || nScanCode == 0x45 )
    1.50 +    {
    1.51 +        switch( wParam )
    1.52 +        {
    1.53 +        case VK_CLEAR: return SDL_SCANCODE_CLEAR;
    1.54 +        case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    1.55 +        case VK_SELECT: return SDL_SCANCODE_SELECT;
    1.56 +        case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
    1.57 +        case VK_HELP: return SDL_SCANCODE_HELP;
    1.58 +        case VK_PAUSE: return SDL_SCANCODE_PAUSE;
    1.59 +        case VK_NUMLOCK: return SDL_SCANCODE_NUMLOCKCLEAR;
    1.60  
    1.61 -		case VK_F13: return SDL_SCANCODE_F13;
    1.62 -		case VK_F14: return SDL_SCANCODE_F14;
    1.63 -		case VK_F15: return SDL_SCANCODE_F15;
    1.64 -		case VK_F16: return SDL_SCANCODE_F16;
    1.65 -		case VK_F17: return SDL_SCANCODE_F17;
    1.66 -		case VK_F18: return SDL_SCANCODE_F18;
    1.67 -		case VK_F19: return SDL_SCANCODE_F19;
    1.68 -		case VK_F20: return SDL_SCANCODE_F20;
    1.69 -		case VK_F21: return SDL_SCANCODE_F21;
    1.70 -		case VK_F22: return SDL_SCANCODE_F22;
    1.71 -		case VK_F23: return SDL_SCANCODE_F23;
    1.72 -		case VK_F24: return SDL_SCANCODE_F24;
    1.73 +        case VK_F13: return SDL_SCANCODE_F13;
    1.74 +        case VK_F14: return SDL_SCANCODE_F14;
    1.75 +        case VK_F15: return SDL_SCANCODE_F15;
    1.76 +        case VK_F16: return SDL_SCANCODE_F16;
    1.77 +        case VK_F17: return SDL_SCANCODE_F17;
    1.78 +        case VK_F18: return SDL_SCANCODE_F18;
    1.79 +        case VK_F19: return SDL_SCANCODE_F19;
    1.80 +        case VK_F20: return SDL_SCANCODE_F20;
    1.81 +        case VK_F21: return SDL_SCANCODE_F21;
    1.82 +        case VK_F22: return SDL_SCANCODE_F22;
    1.83 +        case VK_F23: return SDL_SCANCODE_F23;
    1.84 +        case VK_F24: return SDL_SCANCODE_F24;
    1.85  
    1.86 -		case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
    1.87 -		case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
    1.88 -		case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
    1.89 -		case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
    1.90 -		case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
    1.91 -		case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
    1.92 -		case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
    1.93 -		case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
    1.94 -		case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
    1.95 -		case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
    1.96 -		case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
    1.97 -	
    1.98 -		case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
    1.99 -		case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
   1.100 -		case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
   1.101 -		case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
   1.102 -		case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
   1.103 -		case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
   1.104 -		
   1.105 -		case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
   1.106 +        case VK_OEM_NEC_EQUAL: return SDL_SCANCODE_KP_EQUALS;
   1.107 +        case VK_BROWSER_BACK: return SDL_SCANCODE_AC_BACK;
   1.108 +        case VK_BROWSER_FORWARD: return SDL_SCANCODE_AC_FORWARD;
   1.109 +        case VK_BROWSER_REFRESH: return SDL_SCANCODE_AC_REFRESH;
   1.110 +        case VK_BROWSER_STOP: return SDL_SCANCODE_AC_STOP;
   1.111 +        case VK_BROWSER_SEARCH: return SDL_SCANCODE_AC_SEARCH;
   1.112 +        case VK_BROWSER_FAVORITES: return SDL_SCANCODE_AC_BOOKMARKS;
   1.113 +        case VK_BROWSER_HOME: return SDL_SCANCODE_AC_HOME;
   1.114 +        case VK_VOLUME_MUTE: return SDL_SCANCODE_AUDIOMUTE;
   1.115 +        case VK_VOLUME_DOWN: return SDL_SCANCODE_VOLUMEDOWN;
   1.116 +        case VK_VOLUME_UP: return SDL_SCANCODE_VOLUMEUP;
   1.117  
   1.118 -		case VK_ATTN: return SDL_SCANCODE_SYSREQ;
   1.119 -		case VK_CRSEL: return SDL_SCANCODE_CRSEL;
   1.120 -		case VK_EXSEL: return SDL_SCANCODE_EXSEL;
   1.121 -		case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
   1.122 +        case VK_MEDIA_NEXT_TRACK: return SDL_SCANCODE_AUDIONEXT;
   1.123 +        case VK_MEDIA_PREV_TRACK: return SDL_SCANCODE_AUDIOPREV;
   1.124 +        case VK_MEDIA_STOP: return SDL_SCANCODE_AUDIOSTOP;
   1.125 +        case VK_MEDIA_PLAY_PAUSE: return SDL_SCANCODE_AUDIOPLAY;
   1.126 +        case VK_LAUNCH_MAIL: return SDL_SCANCODE_MAIL;
   1.127 +        case VK_LAUNCH_MEDIA_SELECT: return SDL_SCANCODE_MEDIASELECT;
   1.128  
   1.129 -		case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
   1.130 -		case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
   1.131 +        case VK_OEM_102: return SDL_SCANCODE_NONUSBACKSLASH;
   1.132  
   1.133 -		default: return SDL_SCANCODE_UNKNOWN;
   1.134 -		}
   1.135 -	}
   1.136 +        case VK_ATTN: return SDL_SCANCODE_SYSREQ;
   1.137 +        case VK_CRSEL: return SDL_SCANCODE_CRSEL;
   1.138 +        case VK_EXSEL: return SDL_SCANCODE_EXSEL;
   1.139 +        case VK_OEM_CLEAR: return SDL_SCANCODE_CLEAR;
   1.140  
   1.141 -	if ( nScanCode > 127 )
   1.142 -		return SDL_SCANCODE_UNKNOWN;
   1.143 +        case VK_LAUNCH_APP1: return SDL_SCANCODE_APP1;
   1.144 +        case VK_LAUNCH_APP2: return SDL_SCANCODE_APP2;
   1.145  
   1.146 -	code = windows_scancode_table[nScanCode];
   1.147 +        default: return SDL_SCANCODE_UNKNOWN;
   1.148 +        }
   1.149 +    }
   1.150  
   1.151 -	bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
   1.152 -	if ( !bIsExtended )
   1.153 -	{
   1.154 -		switch ( code )
   1.155 -		{
   1.156 -		case SDL_SCANCODE_HOME:
   1.157 -			return SDL_SCANCODE_KP_7;
   1.158 -		case SDL_SCANCODE_UP:
   1.159 -			return SDL_SCANCODE_KP_8;
   1.160 -		case SDL_SCANCODE_PAGEUP:
   1.161 -			return SDL_SCANCODE_KP_9;
   1.162 -		case SDL_SCANCODE_LEFT:
   1.163 -			return SDL_SCANCODE_KP_4;
   1.164 -		case SDL_SCANCODE_RIGHT:
   1.165 -			return SDL_SCANCODE_KP_6;
   1.166 -		case SDL_SCANCODE_END:
   1.167 -			return SDL_SCANCODE_KP_1;
   1.168 -		case SDL_SCANCODE_DOWN:
   1.169 -			return SDL_SCANCODE_KP_2;
   1.170 -		case SDL_SCANCODE_PAGEDOWN:
   1.171 -			return SDL_SCANCODE_KP_3;
   1.172 -		case SDL_SCANCODE_INSERT:
   1.173 -			return SDL_SCANCODE_KP_0;
   1.174 -		case SDL_SCANCODE_DELETE:
   1.175 -			return SDL_SCANCODE_KP_PERIOD;
   1.176 -		case SDL_SCANCODE_PRINTSCREEN:
   1.177 -			return SDL_SCANCODE_KP_MULTIPLY;
   1.178 -		default:
   1.179 -			break;
   1.180 -		}
   1.181 -	}
   1.182 -	else
   1.183 -	{
   1.184 -		switch ( code )
   1.185 -		{
   1.186 -		case SDL_SCANCODE_RETURN:
   1.187 -			return SDL_SCANCODE_KP_ENTER;
   1.188 -		case SDL_SCANCODE_LALT:
   1.189 -			return SDL_SCANCODE_RALT;
   1.190 -		case SDL_SCANCODE_LCTRL:
   1.191 -			return SDL_SCANCODE_RCTRL;
   1.192 -		case SDL_SCANCODE_SLASH:
   1.193 -			return SDL_SCANCODE_KP_DIVIDE;
   1.194 -		case SDL_SCANCODE_CAPSLOCK:
   1.195 -			return SDL_SCANCODE_KP_PLUS;
   1.196 +    if ( nScanCode > 127 )
   1.197 +        return SDL_SCANCODE_UNKNOWN;
   1.198 +
   1.199 +    code = windows_scancode_table[nScanCode];
   1.200 +
   1.201 +    bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
   1.202 +    if ( !bIsExtended )
   1.203 +    {
   1.204 +        switch ( code )
   1.205 +        {
   1.206 +        case SDL_SCANCODE_HOME:
   1.207 +            return SDL_SCANCODE_KP_7;
   1.208 +        case SDL_SCANCODE_UP:
   1.209 +            return SDL_SCANCODE_KP_8;
   1.210 +        case SDL_SCANCODE_PAGEUP:
   1.211 +            return SDL_SCANCODE_KP_9;
   1.212 +        case SDL_SCANCODE_LEFT:
   1.213 +            return SDL_SCANCODE_KP_4;
   1.214 +        case SDL_SCANCODE_RIGHT:
   1.215 +            return SDL_SCANCODE_KP_6;
   1.216 +        case SDL_SCANCODE_END:
   1.217 +            return SDL_SCANCODE_KP_1;
   1.218 +        case SDL_SCANCODE_DOWN:
   1.219 +            return SDL_SCANCODE_KP_2;
   1.220 +        case SDL_SCANCODE_PAGEDOWN:
   1.221 +            return SDL_SCANCODE_KP_3;
   1.222 +        case SDL_SCANCODE_INSERT:
   1.223 +            return SDL_SCANCODE_KP_0;
   1.224 +        case SDL_SCANCODE_DELETE:
   1.225 +            return SDL_SCANCODE_KP_PERIOD;
   1.226 +        case SDL_SCANCODE_PRINTSCREEN:
   1.227 +            return SDL_SCANCODE_KP_MULTIPLY;
   1.228          default:
   1.229              break;
   1.230 -		}
   1.231 -	}
   1.232 +        }
   1.233 +    }
   1.234 +    else
   1.235 +    {
   1.236 +        switch ( code )
   1.237 +        {
   1.238 +        case SDL_SCANCODE_RETURN:
   1.239 +            return SDL_SCANCODE_KP_ENTER;
   1.240 +        case SDL_SCANCODE_LALT:
   1.241 +            return SDL_SCANCODE_RALT;
   1.242 +        case SDL_SCANCODE_LCTRL:
   1.243 +            return SDL_SCANCODE_RCTRL;
   1.244 +        case SDL_SCANCODE_SLASH:
   1.245 +            return SDL_SCANCODE_KP_DIVIDE;
   1.246 +        case SDL_SCANCODE_CAPSLOCK:
   1.247 +            return SDL_SCANCODE_KP_PLUS;
   1.248 +        default:
   1.249 +            break;
   1.250 +        }
   1.251 +    }
   1.252  
   1.253 -	return code;
   1.254 +    return code;
   1.255  }
   1.256  
   1.257  
   1.258 -void 
   1.259 +void
   1.260  WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button )
   1.261  {
   1.262 -	if ( bwParamMousePressed && !bSDLMousePressed )
   1.263 -	{
   1.264 -		SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
   1.265 -	}
   1.266 -	else if ( !bwParamMousePressed && bSDLMousePressed )
   1.267 -	{
   1.268 -		SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
   1.269 -	}
   1.270 +    if ( bwParamMousePressed && !bSDLMousePressed )
   1.271 +    {
   1.272 +        SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
   1.273 +    }
   1.274 +    else if ( !bwParamMousePressed && bSDLMousePressed )
   1.275 +    {
   1.276 +        SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
   1.277 +    }
   1.278  }
   1.279  
   1.280  /*
   1.281  * Some windows systems fail to send a WM_LBUTTONDOWN sometimes, but each mouse move contains the current button state also
   1.282  *  so this funciton reconciles our view of the world with the current buttons reported by windows
   1.283  */
   1.284 -void 
   1.285 +void
   1.286  WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data )
   1.287  {
   1.288 -	if ( wParam != data->mouse_button_flags )
   1.289 -	{
   1.290 -		Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.291 -		WIN_CheckWParamMouseButton(  (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.292 -		WIN_CheckWParamMouseButton(  (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.293 -		WIN_CheckWParamMouseButton(  (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.294 -		WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.295 -		WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.296 -		data->mouse_button_flags = wParam;
   1.297 -	}
   1.298 +    if ( wParam != data->mouse_button_flags )
   1.299 +    {
   1.300 +        Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.301 +        WIN_CheckWParamMouseButton(  (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.302 +        WIN_CheckWParamMouseButton(  (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.303 +        WIN_CheckWParamMouseButton(  (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.304 +        WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.305 +        WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.306 +        data->mouse_button_flags = wParam;
   1.307 +    }
   1.308  }
   1.309  
   1.310  
   1.311 -void 
   1.312 +void
   1.313  WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data )
   1.314  {
   1.315 -	if ( rawButtons != data->mouse_button_flags )
   1.316 -	{
   1.317 -		Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.318 -		if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) )
   1.319 -			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.320 -		if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) )
   1.321 -			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.322 -		if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) )
   1.323 -			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.324 -		if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) )
   1.325 -			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.326 -		if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) )
   1.327 -			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.328 -		if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) )
   1.329 -			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.330 -		if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) )
   1.331 -			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.332 -		if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) )
   1.333 -			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.334 -		if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) )
   1.335 -			WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.336 -		if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) )
   1.337 -			WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.338 -		data->mouse_button_flags = rawButtons;
   1.339 -	}
   1.340 +    if ( rawButtons != data->mouse_button_flags )
   1.341 +    {
   1.342 +        Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.343 +        if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) )
   1.344 +            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.345 +        if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) )
   1.346 +            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.347 +        if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) )
   1.348 +            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.349 +        if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) )
   1.350 +            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.351 +        if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) )
   1.352 +            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.353 +        if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) )
   1.354 +            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.355 +        if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) )
   1.356 +            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.357 +        if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) )
   1.358 +            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.359 +        if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) )
   1.360 +            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.361 +        if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) )
   1.362 +            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.363 +        data->mouse_button_flags = rawButtons;
   1.364 +    }
   1.365  }
   1.366  
   1.367  LRESULT CALLBACK
   1.368 @@ -280,8 +280,8 @@
   1.369      }
   1.370  
   1.371  #ifdef WMMSG_DEBUG
   1.372 -    {		
   1.373 -        FILE *log = fopen("wmmsg.txt", "a");		
   1.374 +    {
   1.375 +        FILE *log = fopen("wmmsg.txt", "a");
   1.376          fprintf(log, "Received windows message: %p ", hwnd);
   1.377          if (msg > MAX_WMMSG) {
   1.378              fprintf(log, "%d", msg);
   1.379 @@ -314,8 +314,8 @@
   1.380  
   1.381              minimized = HIWORD(wParam);
   1.382              if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
   1.383 -				Uint32 mouseFlags;
   1.384 -				SHORT keyState;
   1.385 +                Uint32 mouseFlags;
   1.386 +                SHORT keyState;
   1.387  
   1.388                  SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
   1.389                  SDL_SendWindowEvent(data->window,
   1.390 @@ -327,40 +327,40 @@
   1.391                  if (SDL_GetKeyboardFocus() != data->window) {
   1.392                      SDL_SetKeyboardFocus(data->window);
   1.393                  }
   1.394 -				/* mouse buttons may have changed state here, we need
   1.395 -				to resync them, but we will get a WM_MOUSEMOVE right away which will fix 
   1.396 -				things up if in non raw mode also
   1.397 -				*/
   1.398 -				mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.399 +                /* mouse buttons may have changed state here, we need
   1.400 +                to resync them, but we will get a WM_MOUSEMOVE right away which will fix
   1.401 +                things up if in non raw mode also
   1.402 +                */
   1.403 +                mouseFlags = SDL_GetMouseState( NULL, NULL );
   1.404  
   1.405 -				keyState = GetAsyncKeyState( VK_LBUTTON );
   1.406 -				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.407 -				keyState = GetAsyncKeyState( VK_RBUTTON );
   1.408 -				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.409 -				keyState = GetAsyncKeyState( VK_MBUTTON );
   1.410 -				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.411 -				keyState = GetAsyncKeyState( VK_XBUTTON1 );
   1.412 -				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.413 -				keyState = GetAsyncKeyState( VK_XBUTTON2 );
   1.414 -				WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.415 -				data->mouse_button_flags = 0;
   1.416 +                keyState = GetAsyncKeyState( VK_LBUTTON );
   1.417 +                WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   1.418 +                keyState = GetAsyncKeyState( VK_RBUTTON );
   1.419 +                WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   1.420 +                keyState = GetAsyncKeyState( VK_MBUTTON );
   1.421 +                WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   1.422 +                keyState = GetAsyncKeyState( VK_XBUTTON1 );
   1.423 +                WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   1.424 +                keyState = GetAsyncKeyState( VK_XBUTTON2 );
   1.425 +                WIN_CheckWParamMouseButton( ( keyState & 0x8000 ), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   1.426 +                data->mouse_button_flags = 0;
   1.427  
   1.428 -				if(SDL_GetMouse()->relative_mode) {
   1.429 -					LONG cx, cy;
   1.430 -					RECT rect;
   1.431 -					GetWindowRect(hwnd, &rect);
   1.432 +                if(SDL_GetMouse()->relative_mode) {
   1.433 +                    LONG cx, cy;
   1.434 +                    RECT rect;
   1.435 +                    GetWindowRect(hwnd, &rect);
   1.436  
   1.437 -					cx = (rect.left + rect.right) / 2;
   1.438 -					cy = (rect.top + rect.bottom) / 2;
   1.439 +                    cx = (rect.left + rect.right) / 2;
   1.440 +                    cy = (rect.top + rect.bottom) / 2;
   1.441  
   1.442 -					/* Make an absurdly small clip rect */
   1.443 -					rect.left = cx-1;
   1.444 -					rect.right = cx+1;
   1.445 -					rect.top = cy-1;
   1.446 -					rect.bottom = cy+1;
   1.447 +                    /* Make an absurdly small clip rect */
   1.448 +                    rect.left = cx-1;
   1.449 +                    rect.right = cx+1;
   1.450 +                    rect.top = cy-1;
   1.451 +                    rect.bottom = cy+1;
   1.452  
   1.453 -					ClipCursor(&rect);
   1.454 -				}
   1.455 +                    ClipCursor(&rect);
   1.456 +                }
   1.457  
   1.458                  /*
   1.459                   * FIXME: Update keyboard state
   1.460 @@ -379,65 +379,65 @@
   1.461          returnCode = 0;
   1.462          break;
   1.463  
   1.464 -	case WM_MOUSEMOVE:
   1.465 -		if( !SDL_GetMouse()->relative_mode )
   1.466 -	        SDL_SendMouseMotion(data->window, 0, 0, LOWORD(lParam), HIWORD(lParam));
   1.467 -		/* don't break here, fall through to check the wParam like the button presses */
   1.468 -	case WM_LBUTTONUP:
   1.469 -	case WM_RBUTTONUP:
   1.470 -	case WM_MBUTTONUP:
   1.471 -	case WM_XBUTTONUP:
   1.472 -	case WM_LBUTTONDOWN:
   1.473 -	case WM_RBUTTONDOWN:
   1.474 -	case WM_MBUTTONDOWN:
   1.475 -	case WM_XBUTTONDOWN:
   1.476 -		if( !SDL_GetMouse()->relative_mode )
   1.477 -			WIN_CheckWParamMouseButtons( wParam, data );
   1.478 -		break;
   1.479 +    case WM_MOUSEMOVE:
   1.480 +        if( !SDL_GetMouse()->relative_mode )
   1.481 +            SDL_SendMouseMotion(data->window, 0, 0, LOWORD(lParam), HIWORD(lParam));
   1.482 +        /* don't break here, fall through to check the wParam like the button presses */
   1.483 +    case WM_LBUTTONUP:
   1.484 +    case WM_RBUTTONUP:
   1.485 +    case WM_MBUTTONUP:
   1.486 +    case WM_XBUTTONUP:
   1.487 +    case WM_LBUTTONDOWN:
   1.488 +    case WM_RBUTTONDOWN:
   1.489 +    case WM_MBUTTONDOWN:
   1.490 +    case WM_XBUTTONDOWN:
   1.491 +        if( !SDL_GetMouse()->relative_mode )
   1.492 +            WIN_CheckWParamMouseButtons( wParam, data );
   1.493 +        break;
   1.494  
   1.495 -	case WM_INPUT:
   1.496 -	{
   1.497 -		HRAWINPUT hRawInput = (HRAWINPUT)lParam;
   1.498 -		RAWINPUT inp;
   1.499 -		UINT size = sizeof(inp);
   1.500 +    case WM_INPUT:
   1.501 +    {
   1.502 +        HRAWINPUT hRawInput = (HRAWINPUT)lParam;
   1.503 +        RAWINPUT inp;
   1.504 +        UINT size = sizeof(inp);
   1.505  
   1.506 -		if(!SDL_GetMouse()->relative_mode)
   1.507 -			break;
   1.508 +        if(!SDL_GetMouse()->relative_mode)
   1.509 +            break;
   1.510  
   1.511 -		GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
   1.512 +        GetRawInputData(hRawInput, RID_INPUT, &inp, &size, sizeof(RAWINPUTHEADER));
   1.513  
   1.514 -		/* Mouse data */
   1.515 -		if(inp.header.dwType == RIM_TYPEMOUSE)
   1.516 -		{
   1.517 -			RAWMOUSE* mouse = &inp.data.mouse;
   1.518 +        /* Mouse data */
   1.519 +        if(inp.header.dwType == RIM_TYPEMOUSE)
   1.520 +        {
   1.521 +            RAWMOUSE* mouse = &inp.data.mouse;
   1.522  
   1.523 -			if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
   1.524 -			{
   1.525 -				SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY);
   1.526 -			}
   1.527 -			else
   1.528 -			{
   1.529 -				// synthesize relative moves from the abs position
   1.530 -				static SDL_Point initialMousePoint;
   1.531 -				if ( initialMousePoint.x == 0 && initialMousePoint.y == 0 )
   1.532 -				{
   1.533 -					initialMousePoint.x = mouse->lLastX;
   1.534 -					initialMousePoint.y = mouse->lLastY;
   1.535 -				}
   1.536 +            if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
   1.537 +            {
   1.538 +                SDL_SendMouseMotion(data->window, 0, 1, (int)mouse->lLastX, (int)mouse->lLastY);
   1.539 +            }
   1.540 +            else
   1.541 +            {
   1.542 +                /* synthesize relative moves from the abs position */
   1.543 +                static SDL_Point initialMousePoint;
   1.544 +                if ( initialMousePoint.x == 0 && initialMousePoint.y == 0 )
   1.545 +                {
   1.546 +                    initialMousePoint.x = mouse->lLastX;
   1.547 +                    initialMousePoint.y = mouse->lLastY;
   1.548 +                }
   1.549  
   1.550 -				SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
   1.551 +                SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
   1.552  
   1.553 -				initialMousePoint.x = mouse->lLastX;
   1.554 -				initialMousePoint.y = mouse->lLastY;
   1.555 -			}
   1.556 -			WIN_CheckRawMouseButtons( mouse->usButtonFlags, data ); 
   1.557 -		}
   1.558 -		break;
   1.559 -	}
   1.560 +                initialMousePoint.x = mouse->lLastX;
   1.561 +                initialMousePoint.y = mouse->lLastY;
   1.562 +            }
   1.563 +            WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
   1.564 +        }
   1.565 +        break;
   1.566 +    }
   1.567  
   1.568      case WM_MOUSEWHEEL:
   1.569          {
   1.570 -            // FIXME: This may need to accumulate deltas up to WHEEL_DELTA
   1.571 +            /* FIXME: This may need to accumulate deltas up to WHEEL_DELTA */
   1.572              short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
   1.573  
   1.574              SDL_SendMouseWheel(data->window, 0, 0, motion);
   1.575 @@ -447,14 +447,14 @@
   1.576  #ifdef WM_MOUSELEAVE
   1.577      case WM_MOUSELEAVE:
   1.578          if (SDL_GetMouseFocus() == data->window) {
   1.579 -			if (!SDL_GetMouse()->relative_mode) {
   1.580 -				POINT cursorPos;
   1.581 -				GetCursorPos(&cursorPos);
   1.582 -				ScreenToClient(hwnd, &cursorPos);
   1.583 -				SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
   1.584 -			}
   1.585 +            if (!SDL_GetMouse()->relative_mode) {
   1.586 +                POINT cursorPos;
   1.587 +                GetCursorPos(&cursorPos);
   1.588 +                ScreenToClient(hwnd, &cursorPos);
   1.589 +                SDL_SendMouseMotion(data->window, 0, 0, cursorPos.x, cursorPos.y);
   1.590 +            }
   1.591  
   1.592 -			SDL_SetMouseFocus(NULL);
   1.593 +            SDL_SetMouseFocus(NULL);
   1.594          }
   1.595          returnCode = 0;
   1.596          break;
   1.597 @@ -463,8 +463,8 @@
   1.598      case WM_SYSKEYDOWN:
   1.599      case WM_KEYDOWN:
   1.600          {
   1.601 -			SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
   1.602 -			if ( code != SDL_SCANCODE_UNKNOWN ) {
   1.603 +            SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
   1.604 +            if ( code != SDL_SCANCODE_UNKNOWN ) {
   1.605                  SDL_SendKeyboardKey(SDL_PRESSED, code );
   1.606              }
   1.607          }
   1.608 @@ -529,7 +529,7 @@
   1.609              int max_w, max_h;
   1.610              int style;
   1.611              BOOL menu;
   1.612 -			BOOL constrain_max_size;
   1.613 +            BOOL constrain_max_size;
   1.614  
   1.615              /* If we allow resizing, let the resize happen naturally */
   1.616              if (SDL_IsShapedWindow(data->window))
   1.617 @@ -545,7 +545,7 @@
   1.618              SDL_GetWindowMinimumSize(data->window, &min_w, &min_h);
   1.619              SDL_GetWindowMaximumSize(data->window, &max_w, &max_h);
   1.620  
   1.621 -            /* Store in min_w and min_h difference between current size and minimal 
   1.622 +            /* Store in min_w and min_h difference between current size and minimal
   1.623                 size so we don't need to call AdjustWindowRectEx twice */
   1.624              min_w -= w;
   1.625              min_h -= h;
   1.626 @@ -680,56 +680,56 @@
   1.627          returnCode = 0;
   1.628          break;
   1.629  
   1.630 -	case WM_TOUCH:
   1.631 -		{
   1.632 -			UINT i, num_inputs = LOWORD(wParam);
   1.633 -			PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
   1.634 -			if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
   1.635 -				RECT rect;
   1.636 -				float x, y;
   1.637 +    case WM_TOUCH:
   1.638 +        {
   1.639 +            UINT i, num_inputs = LOWORD(wParam);
   1.640 +            PTOUCHINPUT inputs = SDL_stack_alloc(TOUCHINPUT, num_inputs);
   1.641 +            if (data->videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs, sizeof(TOUCHINPUT))) {
   1.642 +                RECT rect;
   1.643 +                float x, y;
   1.644  
   1.645 -				if (!GetClientRect(hwnd, &rect) ||
   1.646 -				    (rect.right == rect.left && rect.bottom == rect.top)) {
   1.647 -					break;
   1.648 -				}
   1.649 -				ClientToScreen(hwnd, (LPPOINT) & rect);
   1.650 -				ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   1.651 -				rect.top *= 100;
   1.652 -				rect.left *= 100;
   1.653 -				rect.bottom *= 100;
   1.654 -				rect.right *= 100;
   1.655 +                if (!GetClientRect(hwnd, &rect) ||
   1.656 +                    (rect.right == rect.left && rect.bottom == rect.top)) {
   1.657 +                    break;
   1.658 +                }
   1.659 +                ClientToScreen(hwnd, (LPPOINT) & rect);
   1.660 +                ClientToScreen(hwnd, (LPPOINT) & rect + 1);
   1.661 +                rect.top *= 100;
   1.662 +                rect.left *= 100;
   1.663 +                rect.bottom *= 100;
   1.664 +                rect.right *= 100;
   1.665  
   1.666 -				for (i = 0; i < num_inputs; ++i) {
   1.667 -					PTOUCHINPUT input = &inputs[i];
   1.668 +                for (i = 0; i < num_inputs; ++i) {
   1.669 +                    PTOUCHINPUT input = &inputs[i];
   1.670  
   1.671 -					const SDL_TouchID touchId = (SDL_TouchID)input->hSource;
   1.672 -					if (!SDL_GetTouch(touchId)) {
   1.673 -						if (SDL_AddTouch(touchId, "") < 0) {
   1.674 -							continue;
   1.675 -						}
   1.676 -					}
   1.677 +                    const SDL_TouchID touchId = (SDL_TouchID)input->hSource;
   1.678 +                    if (!SDL_GetTouch(touchId)) {
   1.679 +                        if (SDL_AddTouch(touchId, "") < 0) {
   1.680 +                            continue;
   1.681 +                        }
   1.682 +                    }
   1.683  
   1.684 -					// Get the normalized coordinates for the window
   1.685 -					x = (float)(input->x - rect.left)/(rect.right - rect.left);
   1.686 -					y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
   1.687 +                    /* Get the normalized coordinates for the window */
   1.688 +                    x = (float)(input->x - rect.left)/(rect.right - rect.left);
   1.689 +                    y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
   1.690  
   1.691 -					if (input->dwFlags & TOUCHEVENTF_DOWN) {
   1.692 -						SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f);
   1.693 -					}
   1.694 -					if (input->dwFlags & TOUCHEVENTF_MOVE) {
   1.695 -						SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f);
   1.696 -					}
   1.697 -					if (input->dwFlags & TOUCHEVENTF_UP) {
   1.698 -						SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f);
   1.699 -					}
   1.700 -				}
   1.701 -			}
   1.702 -			SDL_stack_free(inputs);
   1.703 +                    if (input->dwFlags & TOUCHEVENTF_DOWN) {
   1.704 +                        SDL_SendTouch(touchId, input->dwID, SDL_TRUE, x, y, 1.0f);
   1.705 +                    }
   1.706 +                    if (input->dwFlags & TOUCHEVENTF_MOVE) {
   1.707 +                        SDL_SendTouchMotion(touchId, input->dwID, x, y, 1.0f);
   1.708 +                    }
   1.709 +                    if (input->dwFlags & TOUCHEVENTF_UP) {
   1.710 +                        SDL_SendTouch(touchId, input->dwID, SDL_FALSE, x, y, 1.0f);
   1.711 +                    }
   1.712 +                }
   1.713 +            }
   1.714 +            SDL_stack_free(inputs);
   1.715  
   1.716 -			data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
   1.717 -			return 0;
   1.718 -		}
   1.719 -		break;
   1.720 +            data->videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
   1.721 +            return 0;
   1.722 +        }
   1.723 +        break;
   1.724  
   1.725      case WM_DROPFILES:
   1.726          {