aboutsummaryrefslogtreecommitdiff
path: root/mousew16.c
diff options
context:
space:
mode:
Diffstat (limited to 'mousew16.c')
-rw-r--r--mousew16.c73
1 files changed, 36 insertions, 37 deletions
diff --git a/mousew16.c b/mousew16.c
index 5b8b0cf..ee940d1 100644
--- a/mousew16.c
+++ b/mousew16.c
@@ -39,8 +39,8 @@
/** Number of lines to scroll per (vertical) wheel event. */
#define WHEEL_SCROLL_LINES 2
-/** Windows 3.x only supports 1-2 mouse buttons anyway. */
-#define MOUSE_NUM_BUTTONS 2
+/** Max number of mouse buttons supported. */
+#define MOUSE_MAX_BUTTONS 3
/** Prefix for debug messages. */
#define DPREFIX "mousew16: "
@@ -60,6 +60,8 @@ static struct {
bool has_win386 : 1;
#endif
} flags;
+/** Current mouse number of buttons. */
+static unsigned short num_buttons;
/** Previous deltaX, deltaY from the int33 mouse callback (for relative motion) */
static short prev_delta_x, prev_delta_y;
/** Maximum X and Y coordinates expected from the int33 driver. */
@@ -73,22 +75,22 @@ static struct {
LRESULT WINAPI (*DefHookProc)( int, WPARAM, LPARAM, HOOKPROC FAR * );
HWND WINAPI (*GetActiveWindow)( void );
int WINAPI (*GetClassName)( HWND, LPSTR, int );
- void WINAPI (*GetCursorPos)( POINT FAR * );
HWND WINAPI (*GetParent)( HWND );
LONG WINAPI (*GetWindowLong)( HWND, int );
int WINAPI (*GetWindowText)( HWND, LPSTR, int );
BOOL WINAPI (*IsWindowEnabled)( HWND );
BOOL WINAPI (*PostMessage)( HWND, UINT, WPARAM, LPARAM );
UINT WINAPI (*RegisterWindowMessage)( LPCSTR );
- LRESULT WINAPI (*SendMessage)( HWND, UINT, WPARAM, LPARAM );
HOOKPROC WINAPI (*SetWindowsHook)( int, HOOKPROC );
BOOL WINAPI (*UnhookWindowsHook)( int, HOOKPROC );
HWND WINAPI (*WindowFromPoint)( POINT );
} userapi;
+/** This is the private message that we send on wheel movement and is
+ * going to be intercepted by the hook, which will translate into scroll msgs. */
static UINT wheel_msg_private;
-static UINT wheel_msg_mousewheel;
+/** The hook that comes after ours. */
static HOOKPROC wheel_hook_proc_next;
-#endif
+#endif /* USE_WHEEL */
#if USE_WIN386
/** Previous int2f handler. */
static LPFN prev_int2f_handler;
@@ -210,13 +212,13 @@ static void post_scroll_msg(HWND hWnd, UINT msg, int z, HWND hScrollBar)
/** Send wheel scrolling events to the most likely candidate window.
@param cursor the cursor position at the time the wheel event occured */
-static void simulate_scroll(POINT cursor, int z, BOOL horizontal)
+static void post_simulated_scroll_msgs(POINT cursor, int z, BOOL horizontal)
{
HWND hWnd;
#if TRACE_WHEEL
- dprintf(DPREFIX "simulate_scroll @%d,%d z=%d %s\n",
- cursor.x, cursor.y,
+ dprintf(DPREFIX "%s @%d,%d z=%d %s\n",
+ __func__, cursor.x, cursor.y,
z, horizontal ? "horiz" : "vert");
#endif
@@ -289,19 +291,10 @@ static void simulate_scroll(POINT cursor, int z, BOOL horizontal)
}
#if TRACE_WHEEL
- dprintf(DPREFIX "simulate_scroll end\n");
+ dprintf(DPREFIX "%s end\n", __func__);
#endif
}
-/** Send a MSH_MOUSEWHEEL message to hWnd. */
-static BOOL send_msg_mousewheel(HWND hWnd, POINT cursor, int z, BOOL horizontal)
-{
- WPARAM wParam = z * WHEEL_DELTA;
- LPARAM lParam = MAKELONG(cursor.x, cursor.y);
- if (horizontal) return FALSE; // TODO there is no MSH_MOUSE(H)WHEEL
- return userapi.SendMessage(hWnd, wheel_msg_mousewheel, wParam, lParam);
-}
-
/** GetMsgProc hook, called for every message before being returned by GetMessage. */
LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam)
{
@@ -313,13 +306,13 @@ LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam)
BOOL horizontal = msg->wParam;
int z = msg->lParam;
- // First try to send zmouse's MSH_MOUSEWHEEL msg,
- // which some win9x era software may handle natively
- if (!send_msg_mousewheel(msg->hwnd, msg->pt, z, horizontal)) {
- // Only if the window didn't handle the MSH_MOUSEWHEEL msg,
- // simulate scrolling events.
- simulate_scroll(msg->pt, z, horizontal);
- }
+ // TODO In theory we could try sending "native" MSH_MOUSEWHEEL msg here
+ // which some early nt/95 software supports (in addition to 98's WM_MOUSEWHEEL)
+ // but I think the fake scroll messages work well enough.
+ // To properly send MSH_MOUSEWHEEL, we'd need to thunk into 32-bit
+ // SendMessage because such win95 software will expect 32-bit WPARAM.
+
+ post_simulated_scroll_msgs(msg->pt, z, horizontal);
// Prevent us from intercepting this message if fwd'd
msg->message = WM_NULL;
@@ -349,6 +342,12 @@ static void post_wheel_msg(int z, BOOL horizontal)
userapi.PostMessage(hWnd, wheel_msg_private, horizontal, z);
}
+#else
+LRESULT CALLBACK WheelHookProc(int code, WPARAM wParam, LPARAM lParam) {
+ // Required since we export this symbol, but not use it
+ (void)code; (void) wParam; (void) lParam;
+ return 0;
+}
#endif /* USE_WHEEL */
/** Called by the int33 mouse driver. */
@@ -362,10 +361,12 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
events, buttons, x, y, delta_x, delta_y);
#endif
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
- if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
- if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_PRESSED) status |= SF_B1_DOWN;
+ if (events & INT33_EVENT_MASK_LEFT_BUTTON_RELEASED) status |= SF_B1_UP;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_PRESSED) status |= SF_B2_DOWN;
+ if (events & INT33_EVENT_MASK_RIGHT_BUTTON_RELEASED) status |= SF_B2_UP;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_PRESSED) status |= SF_B3_DOWN;
+ if (events & INT33_EVENT_MASK_CENTER_BUTTON_RELEASED) status |= SF_B3_UP;
if (events & INT33_EVENT_MASK_MOVEMENT) {
status |= SF_MOVEMENT;
@@ -410,7 +411,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#if TRACE_EVENTS
- dprintf(DPREFIX "post status=0x%x ", status);
+ dprintf(DPREFIX "post nb=%u status=0x%x ", num_buttons, status);
if (status & SF_ABSOLUTE) {
dprintf("x=%u y=%u\n", x, y);
} else {
@@ -418,7 +419,7 @@ void FAR int33_mouse_callback(uint16_t events, uint16_t buttons, int16_t x, int1
}
#endif
- post_event(status, x, y, MOUSE_NUM_BUTTONS, 0, 0);
+ post_event(status, x, y, num_buttons, 0, 0);
}
#if USE_WIN386
@@ -548,7 +549,7 @@ WORD FAR PASCAL Inquire(LPMOUSEINFO lpMouseInfo)
{
lpMouseInfo->msExist = TRUE;
lpMouseInfo->msRelative = 0;
- lpMouseInfo->msNumButtons = MOUSE_NUM_BUTTONS;
+ lpMouseInfo->msNumButtons = MOUSE_MAX_BUTTONS;
lpMouseInfo->msRate = 80;
return sizeof(MOUSEINFO);
}
@@ -563,7 +564,8 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
_enable();
if (!flags.enabled) {
- int33_reset();
+ int33_reset_get_buttons(&num_buttons);
+ num_buttons = BOUND(num_buttons, 2, MOUSE_MAX_BUTTONS);
#if USE_WIN386
// If we are running under win386, hook int2f now.
@@ -585,20 +587,17 @@ VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc)
userapi.DefHookProc = (LPVOID) GetProcAddress(userapi.hUser, "DefHookProc");
userapi.GetActiveWindow = (LPVOID) GetProcAddress(userapi.hUser, "GetActiveWindow");
userapi.GetClassName = (LPVOID) GetProcAddress(userapi.hUser, "GetClassName");
- userapi.GetCursorPos = (LPVOID) GetProcAddress(userapi.hUser, "GetCursorPos");
userapi.GetParent = (LPVOID) GetProcAddress(userapi.hUser, "GetParent");
userapi.GetWindowLong = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowLong");
userapi.GetWindowText = (LPVOID) GetProcAddress(userapi.hUser, "GetWindowText");
userapi.IsWindowEnabled = (LPVOID) GetProcAddress(userapi.hUser, "IsWindowEnabled");
userapi.PostMessage = (LPVOID) GetProcAddress(userapi.hUser, "PostMessage");
userapi.RegisterWindowMessage = (LPVOID) GetProcAddress(userapi.hUser, "RegisterWindowMessage");
- userapi.SendMessage = (LPVOID) GetProcAddress(userapi.hUser, "SendMessage");
userapi.SetWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "SetWindowsHook");
userapi.UnhookWindowsHook = (LPVOID) GetProcAddress(userapi.hUser, "UnhookWindowsHook");
userapi.WindowFromPoint = (LPVOID) GetProcAddress(userapi.hUser, "WindowFromPoint");
wheel_msg_private = userapi.RegisterWindowMessage("VBMOUSE_WHEEL");
- wheel_msg_mousewheel = userapi.RegisterWindowMessage(MSH_MOUSEWHEEL);
wheel_hook_proc_next = userapi.SetWindowsHook(WH_GETMESSAGE, (HOOKPROC)WheelHookProc);
}