21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_WINDOWS 32 #include "../../events/SDL_events_c.h" 33 #include "../../events/SDL_touch_c.h" 34 #include "../../events/scancodes_windows.h" 51 #define MOUSEEVENTF_FROMTOUCH 0xFF515700 54 #define REPEATED_KEYMASK (1<<30) 55 #define EXTENDED_KEYMASK (1<<24) 58 #ifndef VK_OEM_NEC_EQUAL 59 #define VK_OEM_NEC_EQUAL 0x92 63 #ifndef WM_XBUTTONDOWN 64 #define WM_XBUTTONDOWN 0x020B 67 #define WM_XBUTTONUP 0x020C 69 #ifndef GET_XBUTTON_WPARAM 70 #define GET_XBUTTON_WPARAM(w) (HIWORD(w)) 73 #define WM_INPUT 0x00ff 76 #define WM_TOUCH 0x0240 78 #ifndef WM_MOUSEHWHEEL 79 #define WM_MOUSEHWHEEL 0x020E 82 #define WM_UNICHAR 0x0109 86 VKeytoScancode(WPARAM vkey)
144 WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
147 int nScanCode = (lParam >> 16) & 0xFF;
148 SDL_bool bIsExtended = (lParam & (1 << 24)) != 0;
150 code = VKeytoScancode(wParam);
219 WIN_ShouldIgnoreFocusClick()
229 if (!bwParamMousePressed) {
235 if (WIN_ShouldIgnoreFocusClick()) {
240 if (bwParamMousePressed && !bSDLMousePressed) {
242 }
else if (!bwParamMousePressed && bSDLMousePressed) {
271 if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN))
273 if ((rawButtons & RI_MOUSE_BUTTON_1_UP))
275 if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN))
277 if ((rawButtons & RI_MOUSE_BUTTON_2_UP))
279 if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN))
281 if ((rawButtons & RI_MOUSE_BUTTON_3_UP))
283 if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN))
285 if ((rawButtons & RI_MOUSE_BUTTON_4_UP))
287 if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN))
289 if ((rawButtons & RI_MOUSE_BUTTON_5_UP))
306 keyState = GetAsyncKeyState(VK_LBUTTON);
307 if (!(keyState & 0x8000)) {
310 keyState = GetAsyncKeyState(VK_RBUTTON);
311 if (!(keyState & 0x8000)) {
314 keyState = GetAsyncKeyState(VK_MBUTTON);
315 if (!(keyState & 0x8000)) {
318 keyState = GetAsyncKeyState(VK_XBUTTON1);
319 if (!(keyState & 0x8000)) {
322 keyState = GetAsyncKeyState(VK_XBUTTON2);
323 if (!(keyState & 0x8000)) {
330 WIN_ConvertUTF32toUTF8(UINT32 codepoint,
char *
text)
332 if (codepoint <= 0x7F) {
333 text[0] = (char) codepoint;
335 }
else if (codepoint <= 0x7FF) {
336 text[0] = 0xC0 | (char) ((codepoint >> 6) & 0x1F);
337 text[1] = 0x80 | (char) (codepoint & 0x3F);
339 }
else if (codepoint <= 0xFFFF) {
340 text[0] = 0xE0 | (char) ((codepoint >> 12) & 0x0F);
341 text[1] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
342 text[2] = 0x80 | (char) (codepoint & 0x3F);
344 }
else if (codepoint <= 0x10FFFF) {
345 text[0] = 0xF0 | (char) ((codepoint >> 18) & 0x0F);
346 text[1] = 0x80 | (char) ((codepoint >> 12) & 0x3F);
347 text[2] = 0x80 | (char) ((codepoint >> 6) & 0x3F);
348 text[3] = 0x80 | (char) (codepoint & 0x3F);
357 ShouldGenerateWindowCloseOnAltF4(
void)
366 LRESULT returnCode = -1;
374 wmmsg.
msg.win.hwnd = hwnd;
376 wmmsg.
msg.win.wParam = wParam;
377 wmmsg.
msg.win.lParam = lParam;
384 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
391 SDL_snprintf(message,
sizeof(message),
"Received windows message: %p UNKNOWN (%d) -- 0x%X, 0x%X\n", hwnd, msg, wParam, lParam);
393 SDL_snprintf(message,
sizeof(message),
"Received windows message: %p %s -- 0x%X, 0x%X\n", hwnd,
wmtab[msg], wParam, lParam);
395 OutputDebugStringA(message);
419 minimized = HIWORD(wParam);
420 if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
421 if (LOWORD(wParam) == WA_CLICKACTIVE) {
422 if (GetAsyncKeyState(VK_LBUTTON)) {
425 if (GetAsyncKeyState(VK_RBUTTON)) {
428 if (GetAsyncKeyState(VK_MBUTTON)) {
431 if (GetAsyncKeyState(VK_XBUTTON1)) {
434 if (GetAsyncKeyState(VK_XBUTTON2)) {
444 GetCursorPos(&cursorPos);
445 ScreenToClient(hwnd, &cursorPos);
448 WIN_CheckAsyncMouseRelease(data);
487 case WM_LBUTTONDBLCLK:
489 case WM_RBUTTONDBLCLK:
491 case WM_MBUTTONDBLCLK:
493 case WM_XBUTTONDBLCLK:
498 WIN_CheckWParamMouseButtons(wParam, data, mouseID);
506 HRAWINPUT hRawInput = (HRAWINPUT)lParam;
518 GetRawInputData(hRawInput, RID_INPUT, &inp, &size,
sizeof(RAWINPUTHEADER));
521 if (inp.header.dwType == RIM_TYPEMOUSE) {
523 RAWMOUSE* rawmouse = &inp.data.mouse;
525 if ((rawmouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
530 if (initialMousePoint.
x == 0 && initialMousePoint.
y == 0) {
531 initialMousePoint.
x = rawmouse->lLastX;
532 initialMousePoint.
y = rawmouse->lLastY;
537 initialMousePoint.
x = rawmouse->lLastX;
538 initialMousePoint.
y = rawmouse->lLastY;
540 WIN_CheckRawMouseButtons(rawmouse->usButtonFlags, data);
541 }
else if (isCapture) {
548 currentHnd = WindowFromPoint(pt);
549 ScreenToClient(hwnd, &pt);
550 GetClientRect(hwnd, &hwndRect);
553 if(currentHnd != hwnd || pt.x < 0 || pt.y < 0 || pt.x > hwndRect.right || pt.y > hwndRect.right) {
571 short amount = GET_WHEEL_DELTA_WPARAM(wParam);
572 float fAmount = (float) amount / WHEEL_DELTA;
573 if (msg == WM_MOUSEWHEEL)
583 if (!IsIconic(hwnd)) {
585 GetCursorPos(&cursorPos);
586 ScreenToClient(hwnd, &cursorPos);
598 SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
620 SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
635 if ( wParam == UNICODE_NOCHAR ) {
643 if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
650 #ifdef WM_INPUTLANGCHANGE 651 case WM_INPUTLANGCHANGE:
660 case WM_NCLBUTTONDOWN:
666 case WM_CAPTURECHANGED:
671 WIN_CheckAsyncMouseRelease(data);
675 #ifdef WM_GETMINMAXINFO 676 case WM_GETMINMAXINFO:
686 BOOL constrain_max_size;
697 GetWindowRect(hwnd, &size);
710 if (max_w && max_h) {
713 constrain_max_size =
TRUE;
715 constrain_max_size =
FALSE;
723 style = GetWindowLong(hwnd, GWL_STYLE);
729 menu = (style & WS_CHILDWINDOW) ?
FALSE : (GetMenu(hwnd) !=
NULL);
730 AdjustWindowRectEx(&size, style, menu, 0);
731 w = size.right - size.left;
732 h = size.bottom - size.top;
735 info = (MINMAXINFO *) lParam;
737 info->ptMinTrackSize.x = w + min_w;
738 info->ptMinTrackSize.y = h + min_h;
739 if (constrain_max_size) {
740 info->ptMaxTrackSize.x = w + max_w;
741 info->ptMaxTrackSize.y = h + max_h;
744 info->ptMaxSize.x =
w;
745 info->ptMaxSize.y =
h;
746 info->ptMaxPosition.x =
x;
747 info->ptMaxPosition.y =
y;
748 info->ptMinTrackSize.x =
w;
749 info->ptMinTrackSize.y =
h;
750 info->ptMaxTrackSize.x =
w;
751 info->ptMaxTrackSize.y =
h;
758 case WM_WINDOWPOSCHANGING:
765 case WM_WINDOWPOSCHANGED:
775 if (!GetClientRect(hwnd, &rect) || IsRectEmpty(&rect)) {
778 ClientToScreen(hwnd, (LPPOINT) & rect);
779 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
787 w = rect.right - rect.left;
788 h = rect.bottom - rect.top;
822 hittest = LOWORD(lParam);
823 if (hittest == HTCLIENT) {
837 if (GetUpdateRect(hwnd, &rect,
FALSE)) {
838 ValidateRect(hwnd,
NULL);
854 if ((wParam & 0xFFF0) == SC_KEYMENU) {
858 #if defined(SC_SCREENSAVE) || defined(SC_MONITORPOWER) 860 if ((wParam & 0xFFF0) == SC_SCREENSAVE ||
861 (wParam & 0xFFF0) == SC_MONITORPOWER) {
879 UINT i, num_inputs = LOWORD(wParam);
881 if (data->
videodata->GetTouchInputInfo((HTOUCHINPUT)lParam, num_inputs, inputs,
sizeof(
TOUCHINPUT))) {
885 if (!GetClientRect(hwnd, &rect) ||
886 (rect.right == rect.left && rect.bottom == rect.top)) {
892 ClientToScreen(hwnd, (LPPOINT) & rect);
893 ClientToScreen(hwnd, (LPPOINT) & rect + 1);
899 for (i = 0; i < num_inputs; ++
i) {
908 x = (float)(input->x - rect.left)/(rect.right - rect.left);
909 y = (float)(input->y - rect.top)/(rect.bottom - rect.top);
924 data->
videodata->CloseTouchInputHandle((HTOUCHINPUT)lParam);
932 HDROP drop = (HDROP) wParam;
934 for (i = 0; i <
count; ++
i) {
935 UINT size = DragQueryFile(drop, i,
NULL, 0) + 1;
938 if (DragQueryFile(drop, i, buffer, size)) {
964 POINT winpoint = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
965 if (ScreenToClient(hwnd, &winpoint)) {
966 const SDL_Point point = { (
int) winpoint.
x, (
int) winpoint.y };
969 #define POST_HIT_TEST(ret) { SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIT_TEST, 0, 0); return ret; } 991 return CallWindowProc(data->
wndproc, hwnd, msg, wParam, lParam);
992 }
else if (returnCode >= 0) {
995 return CallWindowProc(DefWindowProc, hwnd, msg, wParam, lParam);
1001 static void *g_WindowsMessageHookData =
NULL;
1006 g_WindowsMessageHookData = userdata;
1012 const Uint8 *keystate;
1014 DWORD start_ticks = GetTickCount();
1017 while (PeekMessage(&msg,
NULL, 0, 0, PM_REMOVE)) {
1018 if (g_WindowsMessageHook) {
1019 g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
1023 TranslateMessage(&msg);
1024 DispatchMessage(&msg);
1046 static int app_registered = 0;
1057 TCHAR
path[MAX_PATH];
1060 if (app_registered) {
1064 if (!name && !SDL_Appname) {
1066 #if defined(CS_BYTEALIGNCLIENT) || defined(CS_OWNDC) 1067 SDL_Appstyle = (CS_BYTEALIGNCLIENT | CS_OWNDC);
1069 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
1074 SDL_Appstyle = style;
1075 SDL_Instance = hInst ? hInst : GetModuleHandle(
NULL);
1079 wcex.cbSize =
sizeof(WNDCLASSEX);
1080 wcex.hCursor =
NULL;
1082 wcex.hIconSm =
NULL;
1083 wcex.lpszMenuName =
NULL;
1086 wcex.hbrBackground =
NULL;
1089 wcex.cbClsExtra = 0;
1090 wcex.cbWndExtra = 0;
1093 if (hint && *hint) {
1094 wcex.hIcon = LoadIcon(SDL_Instance, MAKEINTRESOURCE(
SDL_atoi(hint)));
1097 if (hint && *hint) {
1098 wcex.hIconSm = LoadIcon(SDL_Instance, MAKEINTRESOURCE(
SDL_atoi(hint)));
1102 GetModuleFileName(SDL_Instance, path, MAX_PATH);
1103 ExtractIconEx(path, 0, &wcex.hIcon, &wcex.hIconSm, 1);
1106 if (!RegisterClassEx(&wcex)) {
1107 return SDL_SetError(
"Couldn't register application class");
1121 if (!app_registered) {
1125 if (app_registered == 0) {
1127 if (GetClassInfoEx(SDL_Instance, SDL_Appname, &wcex)) {
1128 UnregisterClass(SDL_Appname, SDL_Instance);
1129 if (wcex.hIcon) DestroyIcon(wcex.hIcon);
1130 if (wcex.hIconSm) DestroyIcon(wcex.hIconSm);
#define WIN_UTF8ToString(S)
SDL_Mouse * SDL_GetMouse(void)
SDL_bool g_WindowFrameUsableWhileCursorHidden
#define SDL_HINT_WINDOWS_INTRESOURCE_ICON
A variable to specify custom icon resource id from RC file on Windows platform.
#define SDL_IsShapedWindow
void SDL_SetKeyboardFocus(SDL_Window *window)
int Win32_ResizeWindowShape(SDL_Window *window)
GLint GLint GLint GLint GLint x
GLuint GLsizei const GLchar * message
SDL_bool relative_mode_warp
GLuint GLuint GLsizei count
int SDL_SendDropFile(SDL_Window *window, const char *file)
#define SDL_BUTTON_X2MASK
LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
GLfloat GLfloat GLfloat GLfloat h
The structure that defines a point.
void WIN_ResetDeadKeys(void)
#define SDL_GetWindowFlags
int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid, SDL_bool down, float x, float y, float pressure)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
void SDL_SetMouseFocus(SDL_Window *window)
#define SDL_GetKeyboardFocus
#define SDL_TOUCH_MOUSEID
union SDL_SysWMmsg::@16 msg
SDL_bool g_WindowsEnableMessageLoop
int SDL_SendDropComplete(SDL_Window *window)
int SDL_SendSysWMEvent(SDL_SysWMmsg *message)
GLuint const GLchar * name
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_GetHintBoolean
#define SDL_VERSION(x)
Macro to determine SDL version program was compiled against.
SDL_HitTestResult
Possible return values from the SDL_HitTest callback.
void SDL_UnregisterApp(void)
#define SDL_GetWindowSize
SDL_bool in_border_change
GLenum GLenum GLenum input
#define SDL_GetEventState(type)
#define SDL_GetKeyboardState
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
struct SDL_VideoData * videodata
int SDL_SendKeyboardText(const char *text)
#define SDL_stack_alloc(type, count)
#define SDL_BUTTON_X1MASK
GLubyte GLubyte GLubyte GLubyte w
void WIN_UpdateClipCursor(SDL_Window *window)
#define WIN_StringToUTF8(S)
static Uint32 callback(Uint32 interval, void *param)
#define SDL_BUTTON_MIDDLE
GLint GLint GLint GLint GLint GLint y
#define SDL_GetWindowMinimumSize
int SDL_AddTouch(SDL_TouchID touchID, const char *name)
BOOL(WINAPI *CloseTouchInputHandle)(HTOUCHINPUT)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void SDL_ToggleModState(const SDL_Keymod modstate, const SDL_bool toggle)
#define SDL_assert(condition)
int SDL_SendMouseWheel(SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction)
#define SDL_GetMouseFocus
#define SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL
void WIN_UpdateKeymap(void)
static char text[MAX_TEXT_LENGTH]
void WIN_PumpEvents(_THIS)
int SDL_SendKeymapChangedEvent(void)
EGLSurface EGLNativeWindowType * window
static const SDL_Scancode windows_scancode_table[]
The type used to identify a window.
void(* SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam)
Set a function that is called for every windows message, before TranslateMessage() ...
SDL_VideoDevice * SDL_GetVideoDevice(void)
#define SDL_GetWindowMaximumSize
SDL_bool in_window_deactivation
GLsizei const GLchar *const * path
void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
#define SDL_stack_free(data)
void WIN_CheckClipboardUpdate(struct SDL_VideoData *data)
WPARAM mouse_button_flags
#define SDL_TICKS_PASSED(A, B)
Compare SDL ticks values, and return true if A has passed B.
#define SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH
Allow mouse click events when clicking to focus an SDL window.
int SDL_SendMouseButton(SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
SDL_Scancode
The SDL keyboard scancode representation.
#define SDL_GetMouseState
int SDL_RegisterApp(char *name, Uint32 style, void *hInst)
#define SDL_HINT_WINDOWS_NO_CLOSE_ON_ALT_F4
Tell SDL not to generate window-close events for Alt+F4 on Windows.
Uint8 focus_click_pending
SDL_bool IME_HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, struct SDL_VideoData *videodata)