23 #if SDL_VIDEO_DRIVER_WINDOWS
29 #include "../../events/SDL_events_c.h"
30 #include "../../events/SDL_touch_c.h"
31 #include "../../events/scancodes_windows.h"
46 #define REPEATED_KEYMASK (1<<30)
47 #define EXTENDED_KEYMASK (1<<24)
50 #ifndef VK_OEM_NEC_EQUAL
51 #define VK_OEM_NEC_EQUAL 0x92
55 #ifndef WM_XBUTTONDOWN
56 #define WM_XBUTTONDOWN 0x020B
59 #define WM_XBUTTONUP 0x020C
61 #ifndef GET_XBUTTON_WPARAM
62 #define GET_XBUTTON_WPARAM(w) (HIWORD(w))
65 #define WM_INPUT 0x00ff
68 #define WM_TOUCH 0x0240
72 WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
76 int nScanCode = ( lParam >> 16 ) & 0xFF;
79 if ( nScanCode == 0 || nScanCode == 0x45 )
137 if ( nScanCode > 127 )
142 bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
199 if ( bwParamMousePressed && !bSDLMousePressed )
203 else if ( !bwParamMousePressed && bSDLMousePressed )
214 WIN_CheckWParamMouseButtons( WPARAM wParam,
SDL_WindowData *data )
235 if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) )
237 if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) )
239 if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) )
241 if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) )
243 if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) )
245 if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) )
247 if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) )
249 if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) )
251 if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) )
253 if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) )
260 WIN_ConvertUTF32toUTF8(UINT32 codepoint,
char * text)
262 if (codepoint <= 0x7F) {
263 text[0] = (char) codepoint;
265 }
else if (codepoint <= 0x7FF) {
266 text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
267 text[1] = 0x80 | (char) (codepoint & 0x3F);
269 }
else if (codepoint <= 0xFFFF) {
270 text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
271 text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
272 text[2] = 0x80 | (char) (codepoint & 0x3F);
274 }
else if (codepoint <= 0x10FFFF) {
275 text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
276 text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
277 text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
278 text[3] = 0x80 | (char) (codepoint & 0x3F);
290 LRESULT returnCode = -1;
298 wmmsg.
msg.win.hwnd = hwnd;
300 wmmsg.
msg.win.wParam = wParam;
301 wmmsg.
msg.win.lParam = lParam;
308 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
313 FILE *log = fopen(
"wmmsg.txt",
"a");
314 fprintf(log,
"Received windows message: %p ", hwnd);
316 fprintf(log,
"%d", msg);
318 fprintf(log,
"%s",
wmtab[msg]);
320 fprintf(log,
" -- 0x%X, 0x%X\n", wParam, lParam);
344 minimized = HIWORD(wParam);
345 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
352 if (IsZoomed(hwnd)) {
365 keyState = GetAsyncKeyState( VK_LBUTTON );
367 keyState = GetAsyncKeyState( VK_RBUTTON );
369 keyState = GetAsyncKeyState( VK_MBUTTON );
371 keyState = GetAsyncKeyState( VK_XBUTTON1 );
373 keyState = GetAsyncKeyState( VK_XBUTTON2 );
380 GetWindowRect(hwnd, &rect);
382 cx = (rect.left + rect.right) / 2;
383 cy = (rect.top + rect.bottom) / 2;
424 WIN_CheckWParamMouseButtons( wParam, data );
429 HRAWINPUT hRawInput = (HRAWINPUT)lParam;
436 GetRawInputData(hRawInput, RID_INPUT, &inp, &size,
sizeof(RAWINPUTHEADER));
439 if(inp.header.dwType == RIM_TYPEMOUSE)
441 RAWMOUSE* mouse = &inp.data.mouse;
443 if((mouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE)
451 if ( initialMousePoint.
x == 0 && initialMousePoint.
y == 0 )
453 initialMousePoint.
x = mouse->lLastX;
454 initialMousePoint.
y = mouse->lLastY;
459 initialMousePoint.
x = mouse->lLastX;
460 initialMousePoint.
y = mouse->lLastY;
462 WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
470 short motion = GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
480 GetCursorPos(&cursorPos);
481 ScreenToClient(hwnd, &cursorPos);
492 SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
497 if (msg == WM_KEYDOWN) {
498 BYTE keyboardState[256];
502 GetKeyboardState(keyboardState);
503 if (ToUnicode(wParam, (lParam >> 16) & 0xff, keyboardState, (LPWSTR)&utf32, 1, 0) > 0) {
505 for (repitition = lParam & 0xffff; repitition > 0; repitition--) {
506 WIN_ConvertUTF32toUTF8(utf32, text);
517 SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
531 if (wParam == UNICODE_NOCHAR) {
541 WIN_ConvertUTF32toUTF8(wParam, text);
547 #ifdef WM_INPUTLANGCHANGE
548 case WM_INPUTLANGCHANGE:
556 #ifdef WM_GETMINMAXINFO
557 case WM_GETMINMAXINFO:
567 BOOL constrain_max_size;
574 GetWindowRect(hwnd, &size);
587 if (max_w && max_h) {
590 constrain_max_size =
TRUE;
592 constrain_max_size =
FALSE;
600 style = GetWindowLong(hwnd, GWL_STYLE);
606 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
607 AdjustWindowRectEx(&size, style, menu, 0);
608 w = size.right - size.left;
609 h = size.bottom - size.top;
612 info = (MINMAXINFO *) lParam;
614 info->ptMinTrackSize.x = w + min_w;
615 info->ptMinTrackSize.y = h + min_h;
616 if (constrain_max_size) {
617 info->ptMaxTrackSize.x = w + max_w;
618 info->ptMaxTrackSize.y = h + max_h;
621 info->ptMaxSize.x =
w;
622 info->ptMaxSize.y =
h;
623 info->ptMaxPosition.x =
x;
624 info->ptMaxPosition.y =
y;
625 info->ptMinTrackSize.x =
w;
626 info->ptMinTrackSize.y =
h;
627 info->ptMaxTrackSize.x =
w;
628 info->ptMaxTrackSize.y =
h;
635 case WM_WINDOWPOSCHANGED:
642 if (!GetClientRect(hwnd, &rect) ||
643 (rect.right == rect.left && rect.bottom == rect.top)) {
646 ClientToScreen(hwnd, (LPPOINT) & rect);
647 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
659 w = rect.right - rect.left;
660 h = rect.bottom - rect.top;
670 hittest = LOWORD(lParam);
671 if (hittest == HTCLIENT) {
682 if (GetUpdateRect(hwnd, &rect,
FALSE)) {
683 ValidateRect(hwnd,
NULL);
697 #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER)
701 if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
702 (wParam & 0xFFF0) == SC_MONITORPOWER) {
720 UINT i, num_inputs = LOWORD(wParam);
722 if (data->
videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs,
sizeof(TOUCHINPUT))) {
726 if (!GetClientRect(hwnd, &rect) ||
727 (rect.right == rect.left && rect.bottom == rect.top)) {
733 ClientToScreen(hwnd, (LPPOINT) & rect);
734 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
740 for (i = 0; i < num_inputs; ++
i) {
751 x = (float)(input->x - rect.left)/(rect.right - rect.left);
752 y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
754 if (input->dwFlags & TOUCHEVENTF_DOWN) {
757 if (input->dwFlags & TOUCHEVENTF_MOVE) {
760 if (input->dwFlags & TOUCHEVENTF_UP) {
767 data->
videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
775 HDROP drop = (HDROP) wParam;
777 for (i = 0; i <
count; ++
i) {
778 UINT size = DragQueryFile(drop, i,
NULL, 0) + 1;
781 if (DragQueryFile(drop, i, buffer, size)) {
797 return CallWindowProc(data->
wndproc, hwnd, msg, wParam, lParam);
798 }
else if (returnCode >= 0) {
801 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
808 const Uint8 *keystate;
810 while (PeekMessage(&msg,
NULL, 0, 0, PM_REMOVE)) {
811 DispatchMessage(&msg);
827 static int app_registered = 0;
834 SDL_RegisterApp(
char *
name,
Uint32 style,
void *hInst)
839 if (app_registered) {
843 if (!name && !SDL_Appname) {
845 #if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC)
846 SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
848 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
853 SDL_Appstyle = style;
854 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
858 class.hCursor =
NULL;
860 LoadImage(SDL_Instance, SDL_Appname, IMAGE_ICON, 0, 0,
862 class.lpszMenuName =
NULL;
864 class.hbrBackground =
NULL;
868 class.cbWndExtra = 0;
869 class.cbClsExtra = 0;
870 if (!RegisterClass(&
class)) {
871 return SDL_SetError(
"Couldn't register application class");
885 if (!app_registered) {
889 if (app_registered == 0) {
891 if (GetClassInfo(SDL_Instance, SDL_Appname, &
class)) {
892 UnregisterClass(SDL_Appname, SDL_Instance);
DECLSPEC void SDLCALL SDL_GetWindowMaximumSize(SDL_Window *window, int *w, int *h)
Get the maximum size of a window's client area.
#define WIN_UTF8ToString(S)
SDL_Mouse * SDL_GetMouse(void)
GLfloat GLfloat GLfloat GLfloat h
void SDL_SetKeyboardFocus(SDL_Window *window)
int Win32_ResizeWindowShape(SDL_Window *window)
DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w, int *h)
Get the minimum size of a window's client area.
#define SDL_stack_free(data)
#define SDL_BUTTON_X2MASK
LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
DECLSPEC SDL_Window *SDLCALL SDL_GetMouseFocus(void)
Get the window which currently has mouse focus.
The structure that defines a point.
DECLSPEC void SDLCALL SDL_free(void *mem)
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
DECLSPEC const Uint8 *SDLCALL SDL_GetKeyboardState(int *numkeys)
Get a snapshot of the current state of the keyboard.
EGLImageKHR EGLint * name
DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h)
Get the size of a window's client area.
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
typedef UINT(WINAPI *PFNWGLGETCONTEXTGPUIDAMDPROC)(HGLRC hglrc)
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode)
int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid, float x, float y, float pressure)
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
uint32_t Uint32
An unsigned 32-bit integer type.
DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y)
Retrieve the current state of the mouse.
EGLContext EGLenum EGLClientBuffer buffer
DECLSPEC SDL_bool SDLCALL SDL_IsShapedWindow(const SDL_Window *window)
Return whether the given window is a shaped window.
#define SDL_GetEventState(type)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct SDL_VideoData * videodata
int SDL_SendKeyboardText(const char *text)
#define SDL_BUTTON_X1MASK
union SDL_SysWMmsg::@77 msg
#define WIN_StringToUTF8(S)
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
#define SDL_BUTTON_MIDDLE
DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window *window)
Get the window flags.
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
EGLSurface EGLint EGLint y
void WIN_UpdateKeymap(void)
GLenum GLenum GLenum input
void WIN_PumpEvents(_THIS)
static const SDL_Scancode windows_scancode_table[]
uint8_t Uint8
An unsigned 8-bit integer type.
int SDL_SendDropFile(const char *file)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
GLint GLint GLint GLint GLint w
#define SDL_stack_alloc(type, count)
uint16_t Uint16
An unsigned 16-bit integer type.
DECLSPEC SDL_Window *SDLCALL SDL_GetKeyboardFocus(void)
Get the window which currently has keyboard focus.
void WIN_CheckClipboardUpdate(struct SDL_VideoData *data)
WPARAM mouse_button_flags
SDL_Touch * SDL_GetTouch(SDL_TouchID id)
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
SDL_Scancode
The SDL keyboard scancode representation.
SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, struct SDL_VideoData *videodata)
typedef BOOL(WINAPI *PFNWGLSETSTEREOEMITTERSTATE3DLPROC)(HDC hDC