diff options
| author | gingerBill <bill@gingerbill.org> | 2022-04-02 14:38:51 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-04-02 14:38:51 +0100 |
| commit | ec5fc109887fa6054f339f5ce62554b615356830 (patch) | |
| tree | 25dbfd7071ad76b61e94018a1654eae1582817c5 | |
| parent | a232c0888c4b711ceb94563defdeef514eafb28a (diff) | |
| parent | c930a3b4c89498f26e8c707efa1ae076c3c85019 (diff) | |
Merge branch 'master' of https://github.com/odin-lang/Odin
| -rw-r--r-- | core/strings/strings.odin | 2 | ||||
| -rw-r--r-- | core/sys/windows/types.odin | 144 | ||||
| -rw-r--r-- | core/sys/windows/user32.odin | 76 | ||||
| -rw-r--r-- | core/sys/windows/util.odin | 5 |
4 files changed, 207 insertions, 20 deletions
diff --git a/core/strings/strings.odin b/core/strings/strings.odin index d01be7989..8e774b367 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -1804,7 +1804,7 @@ fields_iterator :: proc(s: ^string) -> (field: string, ok: bool) { return "", false } - field = s[:len(s)] + field = s[start:] ok = true s^ = s[len(s):] return diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index 50098a59c..de19cd6cc 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -30,6 +30,7 @@ HBRUSH :: distinct HANDLE HGDIOBJ :: distinct HANDLE HBITMAP :: distinct HANDLE HGLOBAL :: distinct HANDLE +HHOOK :: distinct HANDLE BOOL :: distinct b32 BYTE :: distinct u8 BOOLEAN :: distinct b8 @@ -96,6 +97,7 @@ LPPROCESS_INFORMATION :: ^PROCESS_INFORMATION PSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES LPSECURITY_ATTRIBUTES :: ^SECURITY_ATTRIBUTES LPSTARTUPINFO :: ^STARTUPINFO +LPTRACKMOUSEEVENT :: ^TRACKMOUSEEVENT VOID :: rawptr PVOID :: rawptr LPVOID :: rawptr @@ -198,6 +200,24 @@ TIMERPROC :: #type proc "stdcall" (HWND, UINT, UINT_PTR, DWORD) WNDPROC :: #type proc "stdcall" (HWND, UINT, WPARAM, LPARAM) -> LRESULT +HOOKPROC :: #type proc "stdcall" (code: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT + +CWPRETSTRUCT :: struct { + lResult: LRESULT, + lParam: LPARAM, + wParam: WPARAM, + message: UINT, + hwnd: HWND, +} + +KBDLLHOOKSTRUCT :: struct { + vkCode: DWORD, + scanCode: DWORD, + flags: DWORD, + time: DWORD, + dwExtraInfo: ULONG_PTR, +} + WNDCLASSA :: struct { style: UINT, lpfnWndProc: WNDPROC, @@ -272,6 +292,13 @@ PAINTSTRUCT :: struct { rgbReserved: [32]BYTE, } +TRACKMOUSEEVENT :: struct { + cbSize: DWORD, + dwFlags: DWORD, + hwndTrack: HWND, + dwHoverTime: DWORD, +} + WIN32_FIND_DATAW :: struct { dwFileAttributes: DWORD, ftCreationTime: FILETIME, @@ -387,13 +414,6 @@ CS_BYTEALIGNWINDOW : UINT : 0x2000 CS_GLOBALCLASS : UINT : 0x4000 CS_DROPSHADOW : UINT : 0x0002_0000 -GWL_EXSTYLE : c_int : -20 -GWLP_HINSTANCE : c_int : -6 -GWLP_ID : c_int : -12 -GWL_STYLE : c_int : -16 -GWLP_USERDATA : c_int : -21 -GWLP_WNDPROC : c_int : -4 - WS_BORDER : UINT : 0x0080_0000 WS_CAPTION : UINT : 0x00C0_0000 WS_CHILD : UINT : 0x4000_0000 @@ -485,6 +505,48 @@ HWND_BOTTOM :: HWND( uintptr(1)) // 1 HWND_TOPMOST :: HWND(~uintptr(0)) // -1 HWND_NOTOPMOST :: HWND(~uintptr(0) - 1) // -2 +// Window field offsets for GetWindowLong() +GWL_STYLE :: -16 +GWL_EXSTYLE :: -20 +GWL_ID :: -12 + +when ODIN_ARCH == .i386 { + GWL_WNDPROC :: -4 + GWL_HINSTANCE :: -6 + GWL_HWNDPARENT :: -8 + GWL_USERDATA :: -21 +} + +GWLP_WNDPROC :: -4 +GWLP_HINSTANCE :: -6 +GWLP_HWNDPARENT :: -8 +GWLP_USERDATA :: -21 +GWLP_ID :: -12 + +// Class field offsets for GetClassLong() +GCL_CBWNDEXTRA :: -18 +GCL_CBCLSEXTRA :: -20 +GCL_STYLE :: -26 +GCW_ATOM :: -32 + +when ODIN_ARCH == .i386 { + GCL_MENUNAME :: -8 + GCL_HBRBACKGROUND :: -10 + GCL_HCURSOR :: -12 + GCL_HICON :: -14 + GCL_HMODULE :: -16 + GCL_WNDPROC :: -24 + GCL_HICONSM :: -34 +} + +GCLP_MENUNAME :: -8 +GCLP_HBRBACKGROUND :: -10 +GCLP_HCURSOR :: -12 +GCLP_HICON :: -14 +GCLP_HMODULE :: -16 +GCLP_WNDPROC :: -24 +GCLP_HICONSM :: -34 + // GetSystemMetrics() codes SM_CXSCREEN :: 0 SM_CYSCREEN :: 1 @@ -645,9 +707,77 @@ MK_MBUTTON :: 0x0010 MK_XBUTTON1 :: 0x0020 MK_XBUTTON2 :: 0x0040 +// Value for rolling one detent +WHEEL_DELTA :: 120 + +// Setting to scroll one page for SPI_GET/SETWHEELSCROLLLINES +WHEEL_PAGESCROLL :: max(UINT) + +// XButton values are WORD flags +XBUTTON1 :: 0x0001 +XBUTTON2 :: 0x0002 +// Were there to be an XBUTTON3, its value would be 0x0004 + +MAPVK_VK_TO_VSC :: 0 +MAPVK_VSC_TO_VK :: 1 +MAPVK_VK_TO_CHAR :: 2 +MAPVK_VSC_TO_VK_EX :: 3 +MAPVK_VK_TO_VSC_EX :: 4 + +TME_HOVER :: 0x00000001 +TME_LEAVE :: 0x00000002 +TME_NONCLIENT :: 0x00000010 +TME_QUERY :: 0x40000000 +TME_CANCEL :: 0x80000000 +HOVER_DEFAULT :: 0xFFFFFFFF + USER_TIMER_MAXIMUM :: 0x7FFFFFFF USER_TIMER_MINIMUM :: 0x0000000A + +// SetWindowsHook() codes +WH_MIN :: -1 +WH_MSGFILTER :: -1 +WH_JOURNALRECORD :: 0 +WH_JOURNALPLAYBACK :: 1 +WH_KEYBOARD :: 2 +WH_GETMESSAGE :: 3 +WH_CALLWNDPROC :: 4 +WH_CBT :: 5 +WH_SYSMSGFILTER :: 6 +WH_MOUSE :: 7 +WH_HARDWARE :: 8 +WH_DEBUG :: 9 +WH_SHELL :: 10 +WH_FOREGROUNDIDLE :: 11 +WH_CALLWNDPROCRET :: 12 +WH_KEYBOARD_LL :: 13 +WH_MOUSE_LL :: 14 +WH_MAX :: 14 +WH_MINHOOK :: WH_MIN +WH_MAXHOOK :: WH_MAX + +// Hook Codes +HC_ACTION :: 0 +HC_GETNEXT :: 1 +HC_SKIP :: 2 +HC_NOREMOVE :: 3 +HC_NOREM :: HC_NOREMOVE +HC_SYSMODALON :: 4 +HC_SYSMODALOFF :: 5 + +// CBT Hook Codes +HCBT_MOVESIZE :: 0 +HCBT_MINMAX :: 1 +HCBT_QS :: 2 +HCBT_CREATEWND :: 3 +HCBT_DESTROYWND :: 4 +HCBT_ACTIVATE :: 5 +HCBT_CLICKSKIPPED :: 6 +HCBT_KEYSKIPPED :: 7 +HCBT_SYSCOMMAND :: 8 +HCBT_SETFOCUS :: 9 + _IDC_APPSTARTING := rawptr(uintptr(32650)) _IDC_ARROW := rawptr(uintptr(32512)) _IDC_CROSS := rawptr(uintptr(32515)) diff --git a/core/sys/windows/user32.odin b/core/sys/windows/user32.odin index bdab77e27..2316d3363 100644 --- a/core/sys/windows/user32.odin +++ b/core/sys/windows/user32.odin @@ -10,19 +10,19 @@ foreign user32 { GetClassInfoExA :: proc(hInsatnce: HINSTANCE, lpszClass: LPCSTR, lpwcx: ^WNDCLASSEXA) -> BOOL --- GetClassInfoExW :: proc(hInsatnce: HINSTANCE, lpszClass: LPCWSTR, lpwcx: ^WNDCLASSEXW) -> BOOL --- - GetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- - GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- - SetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- - SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + GetClassLongA :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- + GetClassLongW :: proc(hWnd: HWND, nIndex: c_int) -> DWORD --- + SetClassLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD --- + SetClassLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> DWORD --- + + GetWindowLongA :: proc(hWnd: HWND, nIndex: c_int) -> LONG --- + GetWindowLongW :: proc(hWnd: HWND, nIndex: c_int) -> LONG --- + SetWindowLongA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG --- + SetWindowLongW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG) -> LONG --- GetClassNameA :: proc(hWnd: HWND, lpClassName: LPSTR, nMaxCount: c_int) -> c_int --- GetClassNameW :: proc(hWnd: HWND, lpClassName: LPWSTR, nMaxCount: c_int) -> c_int --- - GetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- - GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- - SetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- - SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- - RegisterClassA :: proc(lpWndClass: ^WNDCLASSA) -> ATOM --- RegisterClassW :: proc(lpWndClass: ^WNDCLASSW) -> ATOM --- RegisterClassExA :: proc(^WNDCLASSEXA) -> ATOM --- @@ -123,9 +123,22 @@ foreign user32 { BeginPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> HDC --- EndPaint :: proc(hWnd: HWND, lpPaint: ^PAINTSTRUCT) -> BOOL --- + GetCapture :: proc() -> HWND --- + SetCapture :: proc(hWnd: HWND) -> HWND --- + ReleaseCapture :: proc() -> BOOL --- + TrackMouseEvent :: proc(lpEventTrack: LPTRACKMOUSEEVENT) -> BOOL --- + GetKeyState :: proc(nVirtKey: c_int) -> SHORT --- GetAsyncKeyState :: proc(vKey: c_int) -> SHORT --- + MapVirtualKeyA :: proc(uCode: UINT, uMapType: UINT) -> UINT --- + MapVirtualKeyW :: proc(uCode: UINT, uMapType: UINT) -> UINT --- + + SetWindowsHookExA :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- + SetWindowsHookExW :: proc(idHook: c_int, lpfn: HOOKPROC, hmod: HINSTANCE, dwThreadId: DWORD) -> HHOOK --- + UnhookWindowsHookEx :: proc(hhk: HHOOK) -> BOOL --- + CallNextHookEx :: proc(hhk: HHOOK, nCode: c_int, wParam: WPARAM, lParam: LPARAM) -> LRESULT --- + SetTimer :: proc(hWnd: HWND, nIDEvent: UINT_PTR, uElapse: UINT, lpTimerFunc: TIMERPROC) -> UINT_PTR --- KillTimer :: proc(hWnd: HWND, uIDEvent: UINT_PTR) -> BOOL --- @@ -193,6 +206,47 @@ CreateWindowW :: #force_inline proc "stdcall" ( ) } -GET_SC_WPARAM :: #force_inline proc(wparam: WPARAM) -> i32 { - return i32(wparam) & 0xFFF0 +when ODIN_ARCH == .amd64 { + @(default_calling_convention="stdcall") + foreign user32 { + GetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR --- + GetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> ULONG_PTR --- + SetClassLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + SetClassLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> ULONG_PTR --- + + GetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- + GetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int) -> LONG_PTR --- + SetWindowLongPtrA :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- + SetWindowLongPtrW :: proc(hWnd: HWND, nIndex: c_int, dwNewLong: LONG_PTR) -> LONG_PTR --- + } +} else when ODIN_ARCH == .i386 { + GetClassLongPtrA :: GetClassLongA + GetClassLongPtrW :: GetClassLongW + SetClassLongPtrA :: SetClassLongA + SetClassLongPtrW :: SetClassLongW + + GetWindowLongPtrA :: GetWindowLongA + GetWindowLongPtrW :: GetWindowLongW + SetWindowLongPtrA :: GetWindowLongA + SetWindowLongPtrW :: GetWindowLongW +} + +GET_SC_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_int { + return c_int(wParam) & 0xFFF0 +} + +GET_WHEEL_DELTA_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short { + return cast(c_short)HIWORD(cast(DWORD)wParam) +} + +GET_KEYSTATE_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD { + return LOWORD(cast(DWORD)wParam) +} + +GET_NCHITTEST_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> c_short { + return cast(c_short)LOWORD(cast(DWORD)wParam) +} + +GET_XBUTTON_WPARAM :: #force_inline proc "contextless" (wParam: WPARAM) -> WORD { + return HIWORD(cast(DWORD)wParam) } diff --git a/core/sys/windows/util.odin b/core/sys/windows/util.odin index 5797216c3..d464007d3 100644 --- a/core/sys/windows/util.odin +++ b/core/sys/windows/util.odin @@ -3,6 +3,9 @@ package sys_windows import "core:strings" import "core:sys/win32" +import "core:intrinsics" + +L :: intrinsics.constant_utf16_cstring LOWORD :: #force_inline proc "contextless" (x: DWORD) -> WORD { return WORD(x & 0xffff) @@ -456,4 +459,4 @@ run_as_user :: proc(username, password, application, commandline: string, pi: ^P } else { return false } -}
\ No newline at end of file +} |