* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* $Id$
- *
+/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Message queues
- * FILE: subsys/win32k/ntuser/msgqueue.c
+ * FILE: subsystems/win32/win32k/ntuser/msgqueue.c
* PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
* REVISION HISTORY:
* 06-06-2001 CSH Created
{
HWND hWnd;
PWINDOW_OBJECT Window;
- PW32PROCESS W32d = PsGetCurrentProcessWin32Process();
+ PPROCESSINFO W32d = PsGetCurrentProcessWin32Process();
hWnd = UserGetForegroundWindow();
if (Window && Window->ti)
{
- if (Window->ti->Hooks & HOOKID_TO_FLAG(WH_FOREGROUNDIDLE))
+ if (Window->ti->fsHooks & HOOKID_TO_FLAG(WH_FOREGROUNDIDLE))
{
co_HOOK_CallHooks(WH_FOREGROUNDIDLE,HC_ACTION,0,0);
}
return FALSE;
MessageQueue = Win32Thread->MessageQueue;
+// HACK!!!!!!! Newbies that wrote this should hold your head down in shame! (jt)
MessageQueue->WakeMask = ~0;
return TRUE;
return Res;
}
-BOOL static STDCALL
-co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT FilterLow, UINT FilterHigh,
+static BOOL APIENTRY
+co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Window, UINT FilterLow, UINT FilterHigh,
PUSER_MESSAGE Message, BOOL Remove, PBOOL Freed,
PWINDOW_OBJECT ScopeWin, PPOINT ScreenPoint, BOOL FromGlobalQueue, PLIST_ENTRY *Next)
{
USHORT Msg = Message->Msg.message;
- PWINDOW_OBJECT Window = NULL;
+ PWINDOW_OBJECT CaptureWindow = NULL;
HWND hCaptureWin;
ASSERT_REFS_CO(ScopeWin);
hCaptureWin = IntGetCaptureWindow();
if (hCaptureWin == NULL)
{
- if(Msg == WM_MOUSEWHEEL)
+ if (Msg == WM_MOUSEWHEEL)
{
- Window = UserGetWindowObject(IntGetFocusWindow());
- if (Window) UserReferenceObject(Window);
+ CaptureWindow = UserGetWindowObject(IntGetFocusWindow());
+ if (CaptureWindow) UserReferenceObject(CaptureWindow);
}
else
{
- co_WinPosWindowFromPoint(ScopeWin, NULL, &Message->Msg.pt, &Window);
- if(Window == NULL)
+ co_WinPosWindowFromPoint(ScopeWin, NULL, &Message->Msg.pt, &CaptureWindow);
+ if(CaptureWindow == NULL)
{
- Window = ScopeWin;
- if (Window) UserReferenceObject(Window);
+ CaptureWindow = ScopeWin;
+ if (CaptureWindow) UserReferenceObject(CaptureWindow);
}
else
{
{
/* FIXME - window messages should go to the right window if no buttons are
pressed */
- Window = UserGetWindowObject(hCaptureWin);
- if (Window) UserReferenceObject(Window);
+ CaptureWindow = UserGetWindowObject(hCaptureWin);
+ if (CaptureWindow) UserReferenceObject(CaptureWindow);
}
- if (Window == NULL)
+ if (CaptureWindow == NULL)
{
if(!FromGlobalQueue)
{
return(FALSE);
}
- if (Window->MessageQueue != MessageQueue)
+ if (CaptureWindow->MessageQueue != MessageQueue)
{
if (! FromGlobalQueue)
{
/* lock the destination message queue, so we don't get in trouble with other
threads, messing with it at the same time */
- IntLockHardwareMessageQueue(Window->MessageQueue);
- InsertTailList(&Window->MessageQueue->HardwareMessagesListHead,
+ IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
+ InsertTailList(&CaptureWindow->MessageQueue->HardwareMessagesListHead,
&Message->ListEntry);
if(Message->Msg.message == WM_MOUSEMOVE)
{
- if(Window->MessageQueue->MouseMoveMsg)
+ if(CaptureWindow->MessageQueue->MouseMoveMsg)
{
/* remove the old WM_MOUSEMOVE message, we're processing a more recent
one */
- RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
- ExFreePool(Window->MessageQueue->MouseMoveMsg);
+ RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+ ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
}
/* save the pointer to the WM_MOUSEMOVE message in the new queue */
- Window->MessageQueue->MouseMoveMsg = Message;
+ CaptureWindow->MessageQueue->MouseMoveMsg = Message;
- Window->MessageQueue->QueueBits |= QS_MOUSEMOVE;
- Window->MessageQueue->ChangedBits |= QS_MOUSEMOVE;
- if (Window->MessageQueue->WakeMask & QS_MOUSEMOVE)
- KeSetEvent(Window->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
+ CaptureWindow->MessageQueue->QueueBits |= QS_MOUSEMOVE;
+ CaptureWindow->MessageQueue->ChangedBits |= QS_MOUSEMOVE;
+ if (CaptureWindow->MessageQueue->WakeMask & QS_MOUSEMOVE)
+ KeSetEvent(CaptureWindow->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
}
else
{
- Window->MessageQueue->QueueBits |= QS_MOUSEBUTTON;
- Window->MessageQueue->ChangedBits |= QS_MOUSEBUTTON;
- if (Window->MessageQueue->WakeMask & QS_MOUSEBUTTON)
- KeSetEvent(Window->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
+ CaptureWindow->MessageQueue->QueueBits |= QS_MOUSEBUTTON;
+ CaptureWindow->MessageQueue->ChangedBits |= QS_MOUSEBUTTON;
+ if (CaptureWindow->MessageQueue->WakeMask & QS_MOUSEBUTTON)
+ KeSetEvent(CaptureWindow->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
}
- IntUnLockHardwareMessageQueue(Window->MessageQueue);
+ IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
*Freed = FALSE;
- UserDereferenceObject(Window);
+ UserDereferenceObject(CaptureWindow);
return(FALSE);
}
*ScreenPoint = Message->Msg.pt;
- if((hWnd != NULL && Window->hSelf != hWnd) ||
+ if((Window != NULL && (int)Window != 1 && CaptureWindow->hSelf != Window->hSelf) ||
((FilterLow != 0 || FilterHigh != 0) && (Msg < FilterLow || Msg > FilterHigh)))
{
/* Reject the message because it doesn't match the filter */
/* Lock the message queue so no other thread can mess with it.
Our own message queue is not locked while fetching from the global
queue, so we have to make sure nothing interferes! */
- IntLockHardwareMessageQueue(Window->MessageQueue);
+ IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
/* if we're from the global queue, we need to add our message to our
private queue so we don't loose it! */
- InsertTailList(&Window->MessageQueue->HardwareMessagesListHead,
+ InsertTailList(&CaptureWindow->MessageQueue->HardwareMessagesListHead,
&Message->ListEntry);
}
if (Message->Msg.message == WM_MOUSEMOVE)
{
- if(Window->MessageQueue->MouseMoveMsg &&
- (Window->MessageQueue->MouseMoveMsg != Message))
+ if(CaptureWindow->MessageQueue->MouseMoveMsg &&
+ (CaptureWindow->MessageQueue->MouseMoveMsg != Message))
{
/* delete the old message */
- RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
- ExFreePool(Window->MessageQueue->MouseMoveMsg);
+ RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+ ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
if (!FromGlobalQueue)
{
// We might have deleted the next one in our queue, so fix next
}
/* always save a pointer to this WM_MOUSEMOVE message here because we're
sure that the message is in the private queue */
- Window->MessageQueue->MouseMoveMsg = Message;
+ CaptureWindow->MessageQueue->MouseMoveMsg = Message;
}
if(FromGlobalQueue)
{
- IntUnLockHardwareMessageQueue(Window->MessageQueue);
+ IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
}
- UserDereferenceObject(Window);
+ UserDereferenceObject(CaptureWindow);
*Freed = FALSE;
return(FALSE);
}
/* FIXME - only assign if removing? */
- Message->Msg.hwnd = Window->hSelf;
+ Message->Msg.hwnd = CaptureWindow->hSelf;
Message->Msg.message = Msg;
Message->Msg.lParam = MAKELONG(Message->Msg.pt.x, Message->Msg.pt.y);
/* Lock the message queue so no other thread can mess with it.
Our own message queue is not locked while fetching from the global
queue, so we have to make sure nothing interferes! */
- IntLockHardwareMessageQueue(Window->MessageQueue);
- if(Window->MessageQueue->MouseMoveMsg)
+ IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
+ if(CaptureWindow->MessageQueue->MouseMoveMsg)
{
/* delete the WM_(NC)MOUSEMOVE message in the private queue, we're dealing
with one that's been sent later */
- RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
- ExFreePool(Window->MessageQueue->MouseMoveMsg);
+ RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+ ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
/* our message is not in the private queue so we can remove the pointer
instead of setting it to the current message we're processing */
- Window->MessageQueue->MouseMoveMsg = NULL;
+ CaptureWindow->MessageQueue->MouseMoveMsg = NULL;
}
- IntUnLockHardwareMessageQueue(Window->MessageQueue);
+ IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
}
- else if(Window->MessageQueue->MouseMoveMsg == Message)
+ else if (CaptureWindow->MessageQueue->MouseMoveMsg == Message)
{
- Window->MessageQueue->MouseMoveMsg = NULL;
+ CaptureWindow->MessageQueue->MouseMoveMsg = NULL;
}
}
- UserDereferenceObject(Window);
+ UserDereferenceObject(CaptureWindow);
*Freed = FALSE;
return(TRUE);
}
-BOOL STDCALL
-co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
+BOOL APIENTRY
+co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Window,
UINT FilterLow, UINT FilterHigh, BOOL Remove,
PUSER_MESSAGE* Message)
{
UserMode, FALSE, NULL, NULL);
UserEnterCo();
-
- while (co_MsqDispatchOneSentMessage(MessageQueue))
- {
- ;
- }
}
while (NT_SUCCESS(WaitStatus) && STATUS_WAIT_0 != WaitStatus);
if (DesktopWindow)
{
UserRefObjectCo(DesktopWindow, &Ref);//can DesktopWindow be NULL?
- Desk = DesktopWindow->ti->Desktop;
+ Desk = DesktopWindow->ti->pDeskInfo;
}
/* Process messages in the message queue itself. */
{
- Accept = co_MsqTranslateMouseMessage(MessageQueue, hWnd, FilterLow, FilterHigh,
+ Accept = co_MsqTranslateMouseMessage(MessageQueue, Window, FilterLow, FilterHigh,
Current, Remove, &Freed,
DesktopWindow, &ScreenPoint, FALSE, &CurrentEntry);
if (Accept)
{
const ULONG ActiveStamp = HardwareMessageQueueStamp;
/* Translate the message. */
- Accept = co_MsqTranslateMouseMessage(MessageQueue, hWnd, FilterLow, FilterHigh,
+ Accept = co_MsqTranslateMouseMessage(MessageQueue, Window, FilterLow, FilterHigh,
Current, Remove, &Freed,
DesktopWindow, &ScreenPoint, TRUE, NULL);
if (Accept)
LARGE_INTEGER LargeTickCount;
KBDLLHOOKSTRUCT KbdHookData;
EVENTMSG Event;
+ BOOLEAN Entered = FALSE;
DPRINT("MsqPostKeyboardMessage(uMsg 0x%x, wParam 0x%x, lParam 0x%x)\n",
uMsg, wParam, lParam);
// Condition may arise when calling MsqPostMessage and waiting for an event.
- if (!UserIsEntered()) UserEnterExclusive(); // Fixme: Not sure ATM if this thread is locked.
+ if (!UserIsEntered())
+ {
+ // Fixme: Not sure ATM if this thread is locked.
+ UserEnterExclusive();
+ Entered = TRUE;
+ }
FocusMessageQueue = IntGetFocusMessageQueue();
{
DPRINT("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;
}
if (FocusMessageQueue == NULL)
{
DPRINT("No focus message queue\n");
+ if (Entered) UserLeave();
return;
}
{
DPRINT("Invalid focus window handle\n");
}
- if (UserIsEntered()) UserLeave();
+
+ if (Entered) UserLeave();
+ return;
}
VOID FASTCALL
{
Result = co_EVENT_CallEvents( Message->Msg.message,
Message->Msg.hwnd,
- (LONG) Message->Msg.wParam,
- (LONG) Message->Msg.lParam);
+ Message->Msg.wParam,
+ Message->Msg.lParam);
}
else
{
return(TRUE);
}
-VOID STDCALL
+VOID APIENTRY
MsqRemoveWindowMessagesFromQueue(PVOID pWindow)
{
PUSER_SENT_MESSAGE SentMessage;
KeSetEvent(MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
}
-BOOLEAN STDCALL
+BOOLEAN APIENTRY
co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
IN BOOLEAN Hardware,
IN BOOLEAN Remove,
- IN HWND Wnd,
+ IN PWINDOW_OBJECT Window,
IN UINT MsgFilterLow,
IN UINT MsgFilterHigh,
OUT PUSER_MESSAGE* Message)
if (Hardware)
{
- return(co_MsqPeekHardwareMessage(MessageQueue, Wnd,
+ return(co_MsqPeekHardwareMessage(MessageQueue, Window,
MsgFilterLow, MsgFilterHigh,
Remove, Message));
}
{
CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE,
ListEntry);
- if ((Wnd == 0 || Wnd == CurrentMessage->Msg.hwnd) &&
+ if ((!Window || (int)Window == 1 || Window->hSelf == CurrentMessage->Msg.hwnd) &&
((MsgFilterLow == 0 && MsgFilterHigh == 0) ||
(MsgFilterLow <= CurrentMessage->Msg.message &&
MsgFilterHigh >= CurrentMessage->Msg.message)))
}
NTSTATUS FASTCALL
-co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, HWND WndFilter,
+co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT WndFilter,
UINT MsgFilterMin, UINT MsgFilterMax)
{
PVOID WaitObjects[2] = {MessageQueue->NewMessages, &HardwareMessageEvent};
MessageQueue->LastMsgRead = LargeTickCount.u.LowPart;
MessageQueue->FocusWindow = NULL;
MessageQueue->PaintCount = 0;
+// HACK!!!!!!! Newbies that wrote this should hold your head down in shame! (jt)
MessageQueue->WakeMask = ~0;
MessageQueue->NewMessagesHandle = NULL;
{
PUSER_MESSAGE_QUEUE MessageQueue;
- MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePoolWithTag(PagedPool,
+ MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePoolWithTag(NonPagedPool,
sizeof(USER_MESSAGE_QUEUE) + sizeof(THRDCARETINFO),
TAG_MSGQ);
BOOLEAN FASTCALL
MsqGetTimerMessage(PUSER_MESSAGE_QUEUE MessageQueue,
- HWND WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
+ PWINDOW_OBJECT WindowFilter, UINT MsgFilterMin, UINT MsgFilterMax,
MSG *Msg, BOOLEAN Restart)
{
PTIMER_ENTRY Timer;
DPRINT("Checking timer %p wnd %x expiry %I64d\n", Timer, Timer->Wnd,
Timer->ExpiryTime.QuadPart);
EnumEntry = EnumEntry->Flink;
- if ((NULL == WndFilter || Timer->Wnd == WndFilter) &&
+ if ((NULL == WindowFilter || Timer->Wnd == WindowFilter->hSelf) &&
((MsgFilterMin == 0 && MsgFilterMax == 0) ||
(MsgFilterMin <= Timer->Msg &&
Timer->Msg <= MsgFilterMax)))
else
{
DPRINT("timer %p (wnd %x msg %d) failed filter wnd %x msgmin %d msgmax %d\n",
- Timer, Timer->Wnd, Timer->Msg, WndFilter, MsgFilterMin, MsgFilterMax);
+ Timer, Timer->Wnd, Timer->Msg, WindowFilter->hSelf, MsgFilterMin, MsgFilterMax);
}
}
BOOLEAN FASTCALL
MsqGetFirstTimerExpiry(PUSER_MESSAGE_QUEUE MessageQueue,
- HWND WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
+ PWINDOW_OBJECT WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
PLARGE_INTEGER FirstTimerExpiry)
{
PTIMER_ENTRY Timer;
Timer = CONTAINING_RECORD(MessageQueue->TimerListHead.Flink,
TIMER_ENTRY, ListEntry);
EnumEntry = EnumEntry->Flink;
- if ((NULL == WndFilter || Timer->Wnd == WndFilter) &&
+ if ((NULL == WndFilter || (int)WndFilter == 1 || Timer->Wnd == WndFilter->hSelf) &&
((MsgFilterMin == 0 && MsgFilterMax == 0) ||
(MsgFilterMin <= Timer->Msg &&
Timer->Msg <= MsgFilterMax)))