[Win32k]
authorJames Tabor <james.tabor@reactos.org>
Sat, 12 Mar 2011 01:29:08 +0000 (01:29 +0000)
committerJames Tabor <james.tabor@reactos.org>
Sat, 12 Mar 2011 01:29:08 +0000 (01:29 +0000)
- Move the drag detection routine to kernel space, this will decrease the number of kernel calls that is noticeable with slower systems running an emulator.

svn path=/trunk/; revision=51021

reactos/dll/win32/user32/windows/input.c
reactos/subsystems/win32/win32k/include/winpos.h
reactos/subsystems/win32/win32k/ntuser/focus.c
reactos/subsystems/win32/win32k/ntuser/message.c
reactos/subsystems/win32/win32k/ntuser/ntstubs.c

index 08e457b..63f266e 100644 (file)
@@ -48,9 +48,8 @@ DragDetect(
   HWND hWnd,
   POINT pt)
 {
-#if 0
   return NtUserDragDetect(hWnd, pt);
-#else
+#if 0
   MSG msg;
   RECT rect;
   POINT tmp;
index b21b910..7f1c52a 100644 (file)
@@ -9,6 +9,9 @@
     NtGdiPtInRegion((WndObject)->hrgnClip, (INT)((x) - (WndObject)->rcWindow.left), \
                     (INT)((y) - (WndObject)->rcWindow.top))))
 
+#define IntPtInRect(lprc,pt) \
+    ((pt.x >= (lprc)->left) && (pt.x < (lprc)->right) && (pt.y >= (lprc)->top) && (pt.y < (lprc)->bottom))
+
 UINT
 FASTCALL co_WinPosArrangeIconicWindows(PWND parent);
 BOOL FASTCALL
index 39e1196..9989e88 100644 (file)
@@ -534,29 +534,23 @@ CLEANUP:
    END_CLEANUP;
 }
 
-/*
- * @implemented
- */
-HWND APIENTRY
-NtUserSetCapture(HWND hWnd)
+
+HWND FASTCALL
+co_UserSetCapture(HWND hWnd)
 {
    PTHREADINFO pti;
    PUSER_MESSAGE_QUEUE ThreadQueue;
    PWND Window, pWnd;
    HWND hWndPrev;
-   DECLARE_RETURN(HWND);
-
-   DPRINT("Enter NtUserSetCapture(%x)\n", hWnd);
-   UserEnterExclusive();
 
    pti = PsGetCurrentThreadWin32Thread();
    ThreadQueue = pti->MessageQueue;
 
-   if((Window = UserGetWindowObject(hWnd)))
+   if ((Window = UserGetWindowObject(hWnd)))
    {
-      if(Window->head.pti->MessageQueue != ThreadQueue)
+      if (Window->head.pti->MessageQueue != ThreadQueue)
       {
-         RETURN(NULL);
+         return NULL;
       }
    }
 
@@ -582,7 +576,21 @@ NtUserSetCapture(HWND hWnd)
    co_IntPostOrSendMessage(hWndPrev, WM_CAPTURECHANGED, 0, (LPARAM)hWnd);
    ThreadQueue->CaptureWindow = hWnd;
 
-   RETURN( hWndPrev);
+   return hWndPrev;
+}
+
+/*
+ * @implemented
+ */
+HWND APIENTRY
+NtUserSetCapture(HWND hWnd)
+{
+   DECLARE_RETURN(HWND);
+
+   DPRINT("Enter NtUserSetCapture(%x)\n", hWnd);
+   UserEnterExclusive();
+
+   RETURN( co_UserSetCapture(hWnd));
 
 CLEANUP:
    DPRINT("Leave NtUserSetCapture, ret=%i\n",_ret_);
index 1a1ae9d..9d5b72b 100644 (file)
@@ -16,6 +16,7 @@
 #include <debug.h>
 
 BOOLEAN NTAPI PsGetProcessExitProcessCalled(PEPROCESS Process);
+HWND FASTCALL co_UserSetCapture(HWND hWnd);
 
 #define PM_BADMSGFLAGS ~((QS_RAWINPUT << 16)|PM_QS_SENDMESSAGE|PM_QS_PAINT|PM_QS_POSTMESSAGE|PM_QS_INPUT|PM_NOYIELD|PM_REMOVE)
 
@@ -1698,6 +1699,76 @@ IntUninitMessagePumpHook()
 
 /** Functions ******************************************************************/
 
+BOOL
+APIENTRY
+NtUserDragDetect(
+   HWND hWnd,
+   POINT pt) // Just like the User call.
+{
+    MSG msg;
+    RECT rect;
+    WORD wDragWidth, wDragHeight;
+    DECLARE_RETURN(BOOL);
+
+    DPRINT("Enter NtUserDragDetect(%x)\n", hWnd);
+    UserEnterExclusive();
+
+    wDragWidth = UserGetSystemMetrics(SM_CXDRAG);
+    wDragHeight= UserGetSystemMetrics(SM_CYDRAG);
+
+    rect.left = pt.x - wDragWidth;
+    rect.right = pt.x + wDragWidth;
+
+    rect.top = pt.y - wDragHeight;
+    rect.bottom = pt.y + wDragHeight;
+
+    co_UserSetCapture(hWnd);
+
+    for (;;)
+    {
+        while (co_IntGetPeekMessage( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE, FALSE ) ||
+               co_IntGetPeekMessage( &msg, 0, WM_QUEUESYNC,  WM_QUEUESYNC, PM_REMOVE, FALSE ) ||
+               co_IntGetPeekMessage( &msg, 0, WM_KEYFIRST,   WM_KEYLAST,   PM_REMOVE, FALSE ) )
+        {
+            if ( msg.message == WM_LBUTTONUP )
+            {
+                co_UserSetCapture(NULL);
+                RETURN( FALSE);
+            }
+            if ( msg.message == WM_MOUSEMOVE )
+            {
+                POINT tmp;
+                tmp.x = (short)LOWORD(msg.lParam);
+                tmp.y = (short)HIWORD(msg.lParam);
+                if( !IntPtInRect( &rect, tmp ) )
+                {
+                    co_UserSetCapture(NULL);
+                    RETURN( TRUE);
+                }
+            }
+            if ( msg.message == WM_KEYDOWN )
+            {
+                if ( msg.wParam == VK_ESCAPE )
+                {
+                   co_UserSetCapture(NULL);
+                   RETURN( TRUE);
+                }
+            }
+            if ( msg.message == WM_QUEUESYNC )
+            {
+                co_HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0 );
+            }
+        }
+        co_IntWaitMessage(NULL, 0, 0);
+    }
+    RETURN( FALSE);
+
+CLEANUP:
+   DPRINT("Leave NtUserDragDetect, ret=%i\n",_ret_);
+   UserLeave();
+   END_CLEANUP;
+}
+
 BOOL APIENTRY
 NtUserPostMessage(HWND hWnd,
                   UINT Msg,
index 821d4d6..7d40582 100644 (file)
@@ -1338,16 +1338,6 @@ NtUserResolveDesktopForWOW(DWORD Unknown0)
    return 0;
 }
 
-BOOL
-APIENTRY
-NtUserDragDetect(
-   HWND hWnd,
-   POINT pt) // Just like the User call.
-{
-   UNIMPLEMENTED
-   return 0;
-}
-
 /*
  * @unimplemented
  */