diff options
author | Javier <dev.git@javispedro.com> | 2024-05-19 22:25:01 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2024-05-19 22:25:01 +0200 |
commit | cc1d9b4f7b48f275b99afd313b47c1c650dc60f3 (patch) | |
tree | 25e9d0c1646cccea15cc915a04b9d32ed2631cbf /mousew16.c | |
parent | 4a8fe8127c57b0953e2ba2ad4da5e45a20300645 (diff) | |
download | vbados-cc1d9b4f7b48f275b99afd313b47c1c650dc60f3.tar.gz vbados-cc1d9b4f7b48f275b99afd313b47c1c650dc60f3.zip |
add horizontal wheel scroll support to w16 driver
Diffstat (limited to 'mousew16.c')
-rw-r--r-- | mousew16.c | 120 |
1 files changed, 70 insertions, 50 deletions
@@ -35,7 +35,7 @@ #define TRACE_EVENTS 0 /** Verbosely trace scroll wheel code. */ #define TRACE_WHEEL 0 -/** Number of lines to scroll per wheel event. */ +/** Number of lines to scroll per (vertical) wheel event. */ #define WHEEL_SCROLL_LINES 2 /** Windows 3.x only supports 1-2 mouse buttons anyway. */ @@ -117,7 +117,7 @@ static void print_window_name(HWND hWnd) #endif /** Helper function to traverse a window hierarchy and find a candidate scrollbar. */ -static BOOL CALLBACK __loadds find_scrollbar(HWND hWnd, LPARAM lParam) +static BOOL CALLBACK __loadds find_scrollbar_enum_proc(HWND hWnd, LPARAM lParam) { LPFINDSCROLLBARDATA data = (LPFINDSCROLLBARDATA) lParam; char buffer[16]; @@ -149,6 +149,22 @@ static BOOL CALLBACK __loadds find_scrollbar(HWND hWnd, LPARAM lParam) return ENUM_CHILD_WINDOW_CONTINUE; } +/** Finds a scrollbar in the given window. */ +static HWND find_scrollbar(HWND hWnd, BOOL vertical) +{ + FINDSCROLLBARDATA data; + data.vertical = vertical; + data.scrollbar = 0; + +#if TRACE_WHEEL + dprintf(DPREFIX "find scrollbar on hWnd=0x%x...\n", hWnd); +#endif + + userapi.EnumChildWindows(hWnd, find_scrollbar_enum_proc, (LONG) (LPVOID) &data); + + return data.scrollbar; +} + /** Send scrolling messages to given window. * @param hWnd window to scroll. * @param vertical true if vertical, false if horizontal. @@ -160,7 +176,9 @@ static void post_scroll_msg(HWND hWnd, BOOL vertical, int z, HWND hScrollBar) UINT msg = vertical ? WM_VSCROLL : WM_HSCROLL; WPARAM wParam = z < 0 ? SB_LINEUP : SB_LINEDOWN; LPARAM lParam = MAKELPARAM(0, hScrollBar); - UINT i, lines = (z < 0 ? -z : z) * WHEEL_SCROLL_LINES; + UINT i, lines = (z < 0 ? -z : z); + + if (!vertical) lines *= WHEEL_SCROLL_LINES; #if TRACE_WHEEL dprintf(DPREFIX "sending scroll msg to hWnd=0x%x from=0x%x vert=%d lines=%u\n", hWnd, hScrollBar, vertical, lines); @@ -173,7 +191,7 @@ static void post_scroll_msg(HWND hWnd, BOOL vertical, int z, HWND hScrollBar) } /** Send wheel scrolling events to the most likely candidate window. */ -static void send_wheel_movement(int8_t z) +static void send_wheel_movement(int8_t z, BOOL vertical) { POINT point; HWND hWnd; @@ -202,54 +220,55 @@ static void send_wheel_movement(int8_t z) dprintf(DPREFIX "hWnd=0x%x style=0x%lx\n", hWnd, style); #endif - if (style & WS_VSCROLL) { -#if TRACE_WHEEL - dprintf(DPREFIX "found WS_VSCROLL\n"); -#endif - post_scroll_msg(hWnd, TRUE, z, 0); - break; - } else if (style & WS_HSCROLL) { -#if TRACE_WHEEL - dprintf(DPREFIX "found WS_HSCROLL\n"); -#endif - post_scroll_msg(hWnd, FALSE, z, 0); - break; - } else { - FINDSCROLLBARDATA data; - - // Let's check if we can find a vertical scroll bar in this window.. -#if TRACE_WHEEL - dprintf(DPREFIX "find vertical scrollbar...\n"); -#endif - data.vertical = TRUE; - data.scrollbar = 0; - userapi.EnumChildWindows(hWnd, find_scrollbar, (LONG) (LPVOID) &data); - if (data.scrollbar) { - post_scroll_msg(hWnd, TRUE, z, data.scrollbar); + if (vertical) { + // Check if this window is scrollable... + if (style & WS_VSCROLL) { + post_scroll_msg(hWnd, TRUE, z, 0); break; - } - - // Try a horizontal scrollbar now -#if TRACE_WHEEL - dprintf(DPREFIX "find horizontal scrollbar...\n"); -#endif - data.vertical = FALSE; - data.scrollbar = 0; - userapi.EnumChildWindows(hWnd, find_scrollbar, (LONG) (LPVOID) &data); - if (data.scrollbar) { - post_scroll_msg(hWnd, FALSE, z, data.scrollbar); + } else if (style & WS_HSCROLL) { + post_scroll_msg(hWnd, FALSE, z, 0); break; - } - - // Otherwise, try again on the parent window - if (style & WS_CHILD) { -#if TRACE_WHEEL - dprintf(DPREFIX "go into parent...\n"); -#endif - hWnd = userapi.GetParent(hWnd); } else { - // This was already a topmost window + // Otherwise, let's see if we can find a vertical scroll bar in this window.. + HWND scrollbar = find_scrollbar(hWnd, TRUE); + if (scrollbar) { + post_scroll_msg(hWnd, TRUE, z, scrollbar); + break; + } + + // Try a horizontal scrollbar second + scrollbar = find_scrollbar(hWnd, FALSE); + if (scrollbar) { + post_scroll_msg(hWnd, FALSE, z, scrollbar); + break; + } + + // Otherwise, continue search on the parent window + if (style & WS_CHILD) { + hWnd = userapi.GetParent(hWnd); + } else { + // This was already a topmost window + break; + } + } + } else { + // Similar to above except we try only horizontal scrollbars + if (style & WS_HSCROLL) { + post_scroll_msg(hWnd, FALSE, z, 0); break; + } else { + HWND scrollbar = find_scrollbar(hWnd, FALSE); + if (scrollbar) { + post_scroll_msg(hWnd, FALSE, z, scrollbar); + break; + } + + if (style & WS_CHILD) { + hWnd = userapi.GetParent(hWnd); + } else { + // This was already a topmost window + break; + } } } } @@ -281,11 +300,12 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t } #if USE_WHEEL - if (flags.wheel && (events & INT33_EVENT_MASK_WHEEL_MOVEMENT)) { + if (flags.wheel && (events & INT33_EVENT_MASK_WHEEL_MOVEMENT|INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT)) { // If wheel API is enabled, higher byte of buttons contains wheel movement int8_t z = (buttons & 0xFF00) >> 8; + BOOL vertical = !(events & INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT); if (z) { - send_wheel_movement(z); + send_wheel_movement(z, vertical); } } #endif |