Call SetCursorPos for an injected mouse message only if we really need to move mouse pointer

Dmitry Timoshkov dmitry at baikal.ru
Mon Mar 7 08:48:48 CST 2005


Hello,

while hunting a bug in mouse message handling (which turned out to be
a known bug with processing hardware messages) I wrote this test case
and fixed small bug preventing it succeed on Wine.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    - Call SetCursorPos for an injected mouse message only if we really
    need to move mouse pointer.
    - Add a test case for mouse click handling

diff -up cvs/hq/wine/dlls/user/tests/win.c wine/dlls/user/tests/win.c
--- cvs/hq/wine/dlls/user/tests/win.c	2005-03-05 23:26:14.000000000 +0800
+++ wine/dlls/user/tests/win.c	2005-03-07 21:51:49.000000000 +0800
@@ -48,6 +48,7 @@
 static HWND (WINAPI *pGetAncestor)(HWND,UINT);
 static BOOL (WINAPI *pGetWindowInfo)(HWND,WINDOWINFO*);
 
+static BOOL test_lbuttondown_flag;
 static HWND hwndMessage;
 static HWND hwndMain, hwndMain2;
 static HHOOK hhook;
@@ -521,6 +522,10 @@ static LRESULT WINAPI main_window_procA(
 		ok(!got_getminmaxinfo, "main: WM_GETMINMAXINFO should NOT have been received before WM_NCCREATE\n");
 	    break;
 	}
+        case WM_COMMAND:
+            if (test_lbuttondown_flag)
+                ShowWindow((HWND)wparam, SW_SHOW);
+            break;
     }
 
     return DefWindowProcA(hwnd, msg, wparam, lparam);
@@ -569,7 +574,7 @@ static BOOL RegisterWindowClasses(void)
 {
     WNDCLASSA cls;
 
-    cls.style = 0;
+    cls.style = CS_DBLCLKS;
     cls.lpfnWndProc = main_window_procA;
     cls.cbClsExtra = 0;
     cls.cbWndExtra = 0;
@@ -2241,6 +2246,53 @@ static void test_mouse_input(HWND hwnd)
     ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
     ok( !ret, "message %04x available\n", msg.message);
 
+    /* test mouse clicks */
+
+    ShowWindow(hwnd, SW_SHOW);
+    ShowWindow(popup, SW_SHOW);
+
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+
+    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONDBLCLK, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+
+    ret = PeekMessageA(&msg, 0, 0, 0, PM_REMOVE);
+    ok(!ret, "message %04x available\n", msg.message);
+
+    ShowWindow(popup, SW_HIDE);
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+
+    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
+    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
+
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == hwnd && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+
+    test_lbuttondown_flag = TRUE;
+    SendMessageA(hwnd, WM_COMMAND, (WPARAM)popup, 0);
+    test_lbuttondown_flag = FALSE;
+
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONDOWN, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+    ok(msg.hwnd == popup && msg.message == WM_LBUTTONUP, "hwnd %p message %04x\n", msg.hwnd, msg.message);
+    ok(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE), "no message available\n");
+
     DestroyWindow(popup);
 }
 
diff -up cvs/hq/wine/windows/input.c wine/windows/input.c
--- cvs/hq/wine/windows/input.c	2004-12-09 13:40:28.000000000 +0800
+++ wine/windows/input.c	2005-03-07 21:47:41.000000000 +0800
@@ -285,6 +285,8 @@ static void queue_mouse_event( const MOU
     if (mi->dwFlags & MOUSEEVENTF_MOVE)
     {
         queue_raw_mouse_message( WM_MOUSEMOVE, flags, PosX, PosY, mi );
+        if (flags & LLMHF_INJECTED)  /* we have to actually move the cursor */
+            SetCursorPos( PosX, PosY );
     }
     if (mi->dwFlags & MOUSEEVENTF_LEFTDOWN)
     {
@@ -327,8 +329,6 @@ static void queue_mouse_event( const MOU
     {
         queue_raw_mouse_message( WM_MOUSEWHEEL, flags, PosX, PosY, mi );
     }
-    if (flags & LLMHF_INJECTED)  /* we have to actually move the cursor */
-        SetCursorPos( PosX, PosY );
 }
 
 






More information about the wine-patches mailing list