[CMAKE]
[reactos.git] / subsystems / win32 / win32k / ntuser / msgqueue.c
index 5d0bee8..77d8096 100644 (file)
@@ -62,32 +62,6 @@ static PAGED_LOOKASIDE_LIST MessageLookasideList;
 
 /* FUNCTIONS *****************************************************************/
 
-//
-// Wakeup any thread/process waiting on idle input.
-//
-static VOID FASTCALL
-IdlePing(VOID)
-{
-  HWND hWnd;
-  PWND Window;
-  PPROCESSINFO W32d = PsGetCurrentProcessWin32Process();
-
-  hWnd = UserGetForegroundWindow();
-
-  Window = UserGetWindowObject(hWnd);
-
-  if (Window && Window->head.pti)
-  {
-     if (Window->head.pti->fsHooks & HOOKID_TO_FLAG(WH_FOREGROUNDIDLE))
-     {
-        co_HOOK_CallHooks(WH_FOREGROUNDIDLE,HC_ACTION,0,0);
-     }
-  }
-
-  if (W32d && W32d->InputIdleEvent)
-     KePulseEvent( W32d->InputIdleEvent, EVENT_INCREMENT, TRUE);
-}
-
 HANDLE FASTCALL
 IntMsqSetWakeMask(DWORD WakeMask)
 {
@@ -140,7 +114,9 @@ MsqDecPaintCountQueue(PUSER_MESSAGE_QUEUE Queue)
 }
 
 
-NTSTATUS FASTCALL
+INIT_FUNCTION
+NTSTATUS
+NTAPI
 MsqInitializeImpl(VOID)
 {
    /*CurrentFocusMessageQueue = NULL;*/
@@ -161,7 +137,7 @@ MsqInitializeImpl(VOID)
 }
 
 VOID FASTCALL
-MsqInsertSystemMessage(MSG* Msg)
+MsqInsertMouseMessage(MSG* Msg)
 {
    LARGE_INTEGER LargeTickCount;
    KIRQL OldIrql;
@@ -559,7 +535,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window, UINT
 BOOL APIENTRY
 co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window,
                           UINT FilterLow, UINT FilterHigh, BOOL Remove,
-                          PUSER_MESSAGE* Message)
+                          PMSG Message)
 {
    KIRQL OldIrql;
    POINT ScreenPoint;
@@ -576,8 +552,6 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window,
    WaitObjects[0] = &HardwareMessageQueueLock;
    do
    {
-      IdlePing();
-
       UserLeaveCo();
 
       WaitStatus = KeWaitForMultipleObjects(2, WaitObjects, WaitAny, UserRequest,
@@ -613,14 +587,15 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window,
                                               DesktopWindow, &ScreenPoint, FALSE, &CurrentEntry);
          if (Accept)
          {
+            *Message = Current->Msg;
             if (Remove)
             {
                RemoveEntryList(&Current->ListEntry);
+               MsqDestroyMessage(Current);
             }
             IntUnLockHardwareMessageQueue(MessageQueue);
             IntUnLockSystemHardwareMessageQueueLock(FALSE);
-            *Message = Current;
-
+          
             if (Desk)
                 Desk->LastInputWasKbd = FALSE;
 
@@ -630,13 +605,14 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window,
       }
       else
       {
+         *Message = Current->Msg;
          if (Remove)
          {
             RemoveEntryList(&Current->ListEntry);
+            MsqDestroyMessage(Current);
          }
          IntUnLockHardwareMessageQueue(MessageQueue);
          IntUnLockSystemHardwareMessageQueueLock(FALSE);
-         *Message = Current;
 
          RETURN(TRUE);
       }
@@ -719,7 +695,12 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWND Window,
                IntUnLockHardwareMessageQueue(MessageQueue);
             }
             IntUnLockSystemHardwareMessageQueueLock(FALSE);
-            *Message = Current;
+            *Message = Current->Msg;
+
+            if (Remove)
+            {
+                MsqDestroyMessage(Current);
+            }
 
             RETURN(TRUE);
          }
@@ -798,7 +779,7 @@ co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    KbdHookData.dwExtraInfo = 0;
    if (co_HOOK_CallHooks(WH_KEYBOARD_LL, HC_ACTION, Msg.message, (LPARAM) &KbdHookData))
    {
-      DPRINT("Kbd msg %d wParam %d lParam 0x%08x dropped by WH_KEYBOARD_LL hook\n",
+      DPRINT1("Kbd msg %d wParam %d lParam 0x%08x dropped by WH_KEYBOARD_LL hook\n",
              Msg.message, Msg.wParam, Msg.lParam);
       if (Entered) UserLeave();
       return;
@@ -948,26 +929,25 @@ co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue)
                   &Message->ListEntry);
 
    if (Message->HookMessage == MSQ_ISHOOK)
-   {
-      Result = co_HOOK_CallHooks(Message->Msg.message,
-                                 (INT)(INT_PTR)Message->Msg.hwnd,
-                                 Message->Msg.wParam,
-                                 Message->Msg.lParam);
+   {  // Direct Hook Call processor
+      Result = co_CallHook( Message->Msg.message,     // HookId
+                           (INT)(INT_PTR)Message->Msg.hwnd, // Code
+                            Message->Msg.wParam,
+                            Message->Msg.lParam);
    }
    else if (Message->HookMessage == MSQ_ISEVENT)
-   {
+   {  // Direct Event Call processor
       Result = co_EVENT_CallEvents( Message->Msg.message,
                                     Message->Msg.hwnd,
                                     Message->Msg.wParam,
                                     Message->Msg.lParam);
    }
    else
-   {
-      /* Call the window procedure. */
-      Result = co_IntSendMessage(Message->Msg.hwnd,
-                                 Message->Msg.message,
-                                 Message->Msg.wParam,
-                                 Message->Msg.lParam);
+   {  /* Call the window procedure. */
+      Result = co_IntSendMessage( Message->Msg.hwnd,
+                                  Message->Msg.message,
+                                  Message->Msg.wParam,
+                                  Message->Msg.lParam);
    }
 
    /* remove the message from the local dispatching list, because it doesn't need
@@ -1133,10 +1113,10 @@ co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
    PUSER_SENT_MESSAGE Message;
    KEVENT CompletionEvent;
    NTSTATUS WaitStatus;
-   LRESULT Result;
    PUSER_MESSAGE_QUEUE ThreadQueue;
    LARGE_INTEGER Timeout;
    PLIST_ENTRY Entry;
+   LRESULT Result = 0;   //// Result could be trashed. ////
 
    if(!(Message = ExAllocatePoolWithTag(PagedPool, sizeof(USER_SENT_MESSAGE), TAG_USRMSG)))
    {
@@ -1154,7 +1134,6 @@ co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
 
    /* FIXME - increase reference counter of sender's message queue here */
 
-   Result = 0;
    Message->Msg.hwnd = Wnd;
    Message->Msg.message = Msg;
    Message->Msg.wParam = wParam;
@@ -1164,6 +1143,7 @@ co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
    Message->SenderQueue = ThreadQueue;
    IntReferenceMessageQueue(ThreadQueue);
    Message->CompletionCallback = NULL;
+   Message->CompletionCallbackContext = 0;
    Message->HookMessage = HookMessage;
    Message->HasPackedLParam = FALSE;
 
@@ -1184,8 +1164,6 @@ co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
 
    if(Block)
    {
-      IdlePing();
-
       UserLeaveCo();
 
       /* don't process messages sent to the thread */
@@ -1247,8 +1225,6 @@ co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
       WaitObjects[1] = ThreadQueue->NewMessages;
       do
       {
-         IdlePing();
-
          UserLeaveCo();
 
          WaitStatus = KeWaitForMultipleObjects(2, WaitObjects, WaitAny, UserRequest,
@@ -1356,7 +1332,7 @@ co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
                   IN PWND Window,
                   IN UINT MsgFilterLow,
                   IN UINT MsgFilterHigh,
-                  OUT PUSER_MESSAGE* Message)
+                  OUT PMSG Message)
 {
    PLIST_ENTRY CurrentEntry;
    PUSER_MESSAGE CurrentMessage;
@@ -1390,7 +1366,13 @@ co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
             RemoveEntryList(&CurrentMessage->ListEntry);
          }
 
-         *Message = CurrentMessage;
+         *Message= CurrentMessage->Msg;
+
+         if (Remove)
+         {
+             MsqDestroyMessage(CurrentMessage);
+         }
+
          return(TRUE);
       }
       CurrentEntry = CurrentEntry->Flink;
@@ -1406,8 +1388,6 @@ co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
    PVOID WaitObjects[2] = {MessageQueue->NewMessages, &HardwareMessageEvent};
    NTSTATUS ret;
 
-   IdlePing(); // Going to wait so send Idle ping.
-
    UserLeaveCo();
 
    ret = KeWaitForMultipleObjects(2,
@@ -1632,18 +1612,6 @@ MsqDestroyMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue)
    IntDereferenceMessageQueue(MessageQueue);
 }
 
-PHOOKTABLE FASTCALL
-MsqGetHooks(PUSER_MESSAGE_QUEUE Queue)
-{
-   return Queue->Hooks;
-}
-
-VOID FASTCALL
-MsqSetHooks(PUSER_MESSAGE_QUEUE Queue, PHOOKTABLE Hooks)
-{
-   Queue->Hooks = Hooks;
-}
-
 LPARAM FASTCALL
 MsqSetMessageExtraInfo(LPARAM lParam)
 {