diff options
author | Javier <dev.git@javispedro.com> | 2024-09-05 00:31:53 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2024-09-05 00:31:53 +0200 |
commit | 30c7e4b90d4944311d1e5df23482178cc5af102f (patch) | |
tree | 52d7ca37af9feecd96b5c26258e1b4d907fb4e8d /mousew16.c | |
parent | f4e51d0e9e21a6938e29b4af78f1dcca7f85e925 (diff) | |
download | vbados-30c7e4b90d4944311d1e5df23482178cc5af102f.tar.gz vbados-30c7e4b90d4944311d1e5df23482178cc5af102f.zip |
mousew16: fix regression: vertical wheel scrolling was not scaled by 2x since dual wheel support
Diffstat (limited to 'mousew16.c')
-rw-r--r-- | mousew16.c | 76 |
1 files changed, 42 insertions, 34 deletions
@@ -18,6 +18,7 @@ */ #include <string.h> +#include <stdlib.h> #include <windows.h> #include "utils.h" @@ -97,9 +98,9 @@ static void send_event(unsigned short Status, short deltaX, short deltaY, short #if USE_WHEEL typedef struct { - /** Input: whether to find vertical scrollbars. */ - BOOL vertical; - /** Output: found scrollbar handle, or 0. */ + /** Input param: select scrollbars of either SBS_VERT or SBS_HORZ. */ + WORD style; + /** Output param: found scrollbar handle, or 0 if none found. */ HWND scrollbar; } FINDSCROLLBARDATA, FAR * LPFINDSCROLLBARDATA; @@ -137,10 +138,11 @@ static BOOL CALLBACK __loadds find_scrollbar_enum_proc(HWND hWnd, LPARAM lParam) if (_fstrcmp(buffer, "ScrollBar") == 0) { LONG style = userapi.GetWindowLong(hWnd, GWL_STYLE); - if (data->vertical && (style & SBS_VERT)) { - data->scrollbar = hWnd; - return ENUM_CHILD_WINDOW_STOP; - } else if (!data->vertical && !(style & SBS_VERT)) { +#if TRACE_WHEEL + dprintf(DPREFIX "hWnd=0x%x is ScrollBar style=0x%lx\n", hWnd, style); +#endif + + if (data->style == (style & (SBS_HORZ|SBS_VERT))) { data->scrollbar = hWnd; return ENUM_CHILD_WINDOW_STOP; } @@ -149,39 +151,45 @@ static BOOL CALLBACK __loadds find_scrollbar_enum_proc(HWND hWnd, LPARAM lParam) return ENUM_CHILD_WINDOW_CONTINUE; } -/** Finds a scrollbar in the given window. */ -static HWND find_scrollbar(HWND hWnd, BOOL vertical) +/** Finds a scrollbar in the given window with the given style. + * @param style either SBS_HORZ or SBS_VERT. */ +static HWND find_scrollbar(HWND hWnd, WORD style) { FINDSCROLLBARDATA data; - data.vertical = vertical; + data.style = style; data.scrollbar = 0; #if TRACE_WHEEL - dprintf(DPREFIX "find scrollbar on hWnd=0x%x...\n", hWnd); + dprintf(DPREFIX "find scrollbar on hWnd=0x%x with style=0x%x...\n", hWnd, style); #endif userapi.EnumChildWindows(hWnd, find_scrollbar_enum_proc, (LONG) (LPVOID) &data); +#if TRACE_WHEEL + dprintf(DPREFIX " found scrollbar 0x%x\n", data.scrollbar); +#endif + return data.scrollbar; } /** Send scrolling messages to given window. * @param hWnd window to scroll. - * @param vertical true if vertical, false if horizontal. + * @param msg either WM_HSCROLL or WM_VSCROLL + * @param horizontal true if horizontal, false if vertical movement. * @param z number of lines to scroll. * @param hScrollBar corresponding scrollbar handle. */ -static void post_scroll_msg(HWND hWnd, BOOL vertical, int z, HWND hScrollBar) +static void post_scroll_msg(HWND hWnd, UINT msg, int z, HWND hScrollBar) { - UINT msg = vertical ? WM_VSCROLL : WM_HSCROLL; - WPARAM wParam = z < 0 ? SB_LINEUP : SB_LINEDOWN; + WPARAM wParam = z < 0 ? SB_LINEUP : SB_LINEDOWN; // Same value as z < 0 ? SB_LINELEFT : SB_LINERIGHT LPARAM lParam = MAKELPARAM(0, hScrollBar); - UINT i, lines = (z < 0 ? -z : z); + UINT i, lines = abs(z); - if (!vertical) lines *= WHEEL_SCROLL_LINES; + // Only vertical scroll gets multipled by speed factor + if (msg == WM_VSCROLL) 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); + dprintf(DPREFIX "sending scroll msg 0x%x to hWnd=0x%x from=0x%x dir=%u lines=%u\n", msg, hWnd, hScrollBar, wParam, lines); #endif for (i = 0; i < lines; i++) { @@ -191,13 +199,13 @@ 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, BOOL vertical) +static void send_wheel_movement(int8_t z, BOOL horizontal) { POINT point; HWND hWnd; #if TRACE_WHEEL - dprintf(DPREFIX "wheel=%d\n", z); + dprintf(DPREFIX "wheel=%d %s\n", z, horizontal ? "horiz" : "vert"); #endif // TODO It's highly unlikely that we can call this many functions from @@ -220,26 +228,26 @@ static void send_wheel_movement(int8_t z, BOOL vertical) dprintf(DPREFIX "hWnd=0x%x style=0x%lx\n", hWnd, style); #endif - if (vertical) { - // Check if this window is scrollable... + if (!horizontal) { + // Check if this window is vertically scrollable... if (style & WS_VSCROLL) { - post_scroll_msg(hWnd, TRUE, z, 0); + post_scroll_msg(hWnd, WM_VSCROLL, z, 0); break; } else if (style & WS_HSCROLL) { - post_scroll_msg(hWnd, FALSE, z, 0); + post_scroll_msg(hWnd, WM_HSCROLL, z, 0); break; } else { // Otherwise, let's see if we can find a vertical scroll bar in this window.. - HWND scrollbar = find_scrollbar(hWnd, TRUE); + HWND scrollbar = find_scrollbar(hWnd, SBS_VERT); if (scrollbar) { - post_scroll_msg(hWnd, TRUE, z, scrollbar); + post_scroll_msg(hWnd, WM_VSCROLL, z, scrollbar); break; } - // Try a horizontal scrollbar second - scrollbar = find_scrollbar(hWnd, FALSE); + // If no vertical scrollbar... try a horizontal scrollbar second + scrollbar = find_scrollbar(hWnd, SBS_HORZ); if (scrollbar) { - post_scroll_msg(hWnd, FALSE, z, scrollbar); + post_scroll_msg(hWnd, WM_HSCROLL, z, scrollbar); break; } @@ -254,12 +262,12 @@ static void send_wheel_movement(int8_t z, BOOL vertical) } else { // Similar to above except we try only horizontal scrollbars if (style & WS_HSCROLL) { - post_scroll_msg(hWnd, FALSE, z, 0); + post_scroll_msg(hWnd, WM_HSCROLL, z, 0); break; } else { - HWND scrollbar = find_scrollbar(hWnd, FALSE); + HWND scrollbar = find_scrollbar(hWnd, SBS_HORZ); if (scrollbar) { - post_scroll_msg(hWnd, FALSE, z, scrollbar); + post_scroll_msg(hWnd, WM_HSCROLL, z, scrollbar); break; } @@ -303,9 +311,9 @@ static void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t if (flags.wheel && (events & INT33_EVENT_MASK_ANY_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); + BOOL horizontal = !!(events & INT33_EVENT_MASK_HORIZ_WHEEL_MOVEMENT); if (z) { - send_wheel_movement(z, vertical); + send_wheel_movement(z, horizontal); } } #endif |