[YAROTOWS] Reintegrate the branch. For a brighter future.
[reactos.git] / reactos / subsystems / win32 / win32k / include / msgqueue.h
1 #pragma once
2
3 #include "hook.h"
4
5 #define MSQ_HUNG 5000
6 #define MSQ_NORMAL 0
7 #define MSQ_ISHOOK 1
8 #define MSQ_ISEVENT 2
9 #define MSQ_SENTNOWAIT 0x80000000
10
11 typedef struct _USER_MESSAGE
12 {
13 LIST_ENTRY ListEntry;
14 MSG Msg;
15 } USER_MESSAGE, *PUSER_MESSAGE;
16
17 struct _USER_MESSAGE_QUEUE;
18
19 typedef struct _USER_SENT_MESSAGE
20 {
21 LIST_ENTRY ListEntry;
22 MSG Msg;
23 PKEVENT CompletionEvent;
24 LRESULT* Result;
25 struct _USER_MESSAGE_QUEUE* SenderQueue;
26 SENDASYNCPROC CompletionCallback;
27 ULONG_PTR CompletionCallbackContext;
28 /* entry in the dispatching list of the sender's message queue */
29 LIST_ENTRY DispatchingListEntry;
30 INT HookMessage;
31 BOOL HasPackedLParam;
32 } USER_SENT_MESSAGE, *PUSER_SENT_MESSAGE;
33
34 typedef struct _USER_SENT_MESSAGE_NOTIFY
35 {
36 SENDASYNCPROC CompletionCallback;
37 ULONG_PTR CompletionCallbackContext;
38 LRESULT Result;
39 HWND hWnd;
40 UINT Msg;
41 LIST_ENTRY ListEntry;
42 } USER_SENT_MESSAGE_NOTIFY, *PUSER_SENT_MESSAGE_NOTIFY;
43
44 typedef struct _USER_MESSAGE_QUEUE
45 {
46 /* Reference counter, only access this variable with interlocked functions! */
47 LONG References;
48
49 /* Owner of the message queue */
50 struct _ETHREAD *Thread;
51 /* Queue of messages sent to the queue. */
52 LIST_ENTRY SentMessagesListHead;
53 /* Queue of messages posted to the queue. */
54 LIST_ENTRY PostedMessagesListHead;
55 /* Queue of sent-message notifies for the queue. */
56 LIST_ENTRY NotifyMessagesListHead;
57 /* Queue for hardware messages for the queue. */
58 LIST_ENTRY HardwareMessagesListHead;
59 /* Lock for the hardware message list. */
60 KMUTEX HardwareLock;
61 /* Pointer to the current WM_MOUSEMOVE message */
62 PUSER_MESSAGE MouseMoveMsg;
63 /* True if a WM_QUIT message is pending. */
64 BOOLEAN QuitPosted;
65 /* The quit exit code. */
66 ULONG QuitExitCode;
67 /* Set if there are new messages specified by WakeMask in any of the queues. */
68 PKEVENT NewMessages;
69 /* Handle for the above event (in the context of the process owning the queue). */
70 HANDLE NewMessagesHandle;
71 /* Last time PeekMessage() was called. */
72 ULONG LastMsgRead;
73 /* Current window with focus (ie. receives keyboard input) for this queue. */
74 HWND FocusWindow;
75 /* Count of paints pending. */
76 ULONG PaintCount;
77 /* Current active window for this queue. */
78 HWND ActiveWindow;
79 /* Current capture window for this queue. */
80 HWND CaptureWindow;
81 /* Current move/size window for this queue */
82 HWND MoveSize;
83 /* Current menu owner window for this queue */
84 HWND MenuOwner;
85 /* Identifes the menu state */
86 BYTE MenuState;
87 /* Caret information for this queue */
88 PTHRDCARETINFO CaretInfo;
89
90 /* queue state tracking */
91 WORD WakeMask;
92 WORD QueueBits;
93 WORD ChangedBits;
94
95 /* extra message information */
96 LPARAM ExtraInfo;
97
98 /* messages that are currently dispatched by other threads */
99 LIST_ENTRY DispatchingMessagesHead;
100 /* messages that are currently dispatched by this message queue, required for cleanup */
101 LIST_ENTRY LocalDispatchingMessagesHead;
102
103 /* Desktop that the message queue is attached to */
104 struct _DESKTOP *Desktop;
105 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;
106
107 BOOL FASTCALL
108 MsqIsHung(PUSER_MESSAGE_QUEUE MessageQueue);
109 NTSTATUS FASTCALL
110 co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
111 HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam,
112 UINT uTimeout, BOOL Block, INT HookMessage,
113 ULONG_PTR *uResult);
114 PUSER_MESSAGE FASTCALL
115 MsqCreateMessage(LPMSG Msg);
116 VOID FASTCALL
117 MsqDestroyMessage(PUSER_MESSAGE Message);
118 VOID FASTCALL
119 MsqPostMessage(PUSER_MESSAGE_QUEUE MessageQueue,
120 MSG* Msg, BOOLEAN HardwareMessage, DWORD MessageBits);
121 VOID FASTCALL
122 MsqPostQuitMessage(PUSER_MESSAGE_QUEUE MessageQueue, ULONG ExitCode);
123 BOOLEAN APIENTRY
124 co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
125 IN BOOLEAN Hardware,
126 IN BOOLEAN Remove,
127 IN PWND Window,
128 IN UINT MsgFilterLow,
129 IN UINT MsgFilterHigh,
130 OUT PUSER_MESSAGE* Message);
131 BOOLEAN FASTCALL
132 MsqInitializeMessageQueue(struct _ETHREAD *Thread, PUSER_MESSAGE_QUEUE MessageQueue);
133 VOID FASTCALL
134 MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
135 PUSER_MESSAGE_QUEUE FASTCALL
136 MsqCreateMessageQueue(struct _ETHREAD *Thread);
137 VOID FASTCALL
138 MsqDestroyMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
139 PUSER_MESSAGE_QUEUE FASTCALL
140 MsqGetHardwareMessageQueue(VOID);
141 NTSTATUS FASTCALL
142 MsqInitializeImpl(VOID);
143 BOOLEAN FASTCALL
144 co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue);
145 NTSTATUS FASTCALL
146 co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
147 UINT MsgFilterMin, UINT MsgFilterMax);
148 VOID FASTCALL
149 MsqSendNotifyMessage(PUSER_MESSAGE_QUEUE MessageQueue,
150 PUSER_SENT_MESSAGE_NOTIFY NotifyMessage);
151 VOID FASTCALL
152 MsqIncPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
153 VOID FASTCALL
154 MsqDecPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
155 LRESULT FASTCALL
156 co_IntSendMessage(HWND hWnd,
157 UINT Msg,
158 WPARAM wParam,
159 LPARAM lParam);
160 LRESULT FASTCALL
161 co_IntPostOrSendMessage(HWND hWnd,
162 UINT Msg,
163 WPARAM wParam,
164 LPARAM lParam);
165 LRESULT FASTCALL
166 co_IntSendMessageTimeout(HWND hWnd,
167 UINT Msg,
168 WPARAM wParam,
169 LPARAM lParam,
170 UINT uFlags,
171 UINT uTimeout,
172 ULONG_PTR *uResult);
173
174 LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd,
175 UINT Msg,
176 WPARAM wParam,
177 LPARAM lParam);
178 LRESULT FASTCALL
179 co_IntSendMessageWithCallBack(HWND hWnd,
180 UINT Msg,
181 WPARAM wParam,
182 LPARAM lParam,
183 SENDASYNCPROC CompletionCallback,
184 ULONG_PTR CompletionCallbackContext,
185 ULONG_PTR *uResult);
186
187 LRESULT FASTCALL
188 IntDispatchMessage(MSG* Msg);
189 BOOL FASTCALL
190 IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
191
192 VOID FASTCALL
193 co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
194 VOID FASTCALL
195 MsqPostHotKeyMessage(PVOID Thread, HWND hWnd, WPARAM wParam, LPARAM lParam);
196 VOID FASTCALL
197 MsqInsertSystemMessage(MSG* Msg);
198 BOOL FASTCALL
199 MsqIsClkLck(LPMSG Msg, BOOL Remove);
200 BOOL FASTCALL
201 MsqIsDblClk(LPMSG Msg, BOOL Remove);
202 HWND FASTCALL
203 MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
204
205 __inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
206 __inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
207 __inline VOID MsqClearQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
208 BOOL APIENTRY IntInitMessagePumpHook();
209 BOOL APIENTRY IntUninitMessagePumpHook();
210 #define MAKE_LONG(x, y) ((((y) & 0xFFFF) << 16) | ((x) & 0xFFFF))
211
212 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
213 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
214 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, will be gone in the rewrite! */
215
216 #define IntLockHardwareMessageQueue(MsgQueue) \
217 KeWaitForMutexObject(&(MsgQueue)->HardwareLock, UserRequest, KernelMode, FALSE, NULL)
218
219 #define IntUnLockHardwareMessageQueue(MsgQueue) \
220 KeReleaseMutex(&(MsgQueue)->HardwareLock, FALSE)
221
222 #define IntReferenceMessageQueue(MsgQueue) \
223 InterlockedIncrement(&(MsgQueue)->References)
224
225 #define IntDereferenceMessageQueue(MsgQueue) \
226 do { \
227 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
228 { \
229 DPRINT("Free message queue 0x%x\n", (MsgQueue)); \
230 if ((MsgQueue)->NewMessages != NULL) \
231 ObDereferenceObject((MsgQueue)->NewMessages); \
232 if ((MsgQueue)->NewMessagesHandle != NULL) \
233 ZwClose((MsgQueue)->NewMessagesHandle); \
234 ExFreePool((MsgQueue)); \
235 } \
236 } while(0)
237
238 #define IS_BTN_MESSAGE(message,code) \
239 ((message) == WM_LBUTTON##code || \
240 (message) == WM_MBUTTON##code || \
241 (message) == WM_RBUTTON##code || \
242 (message) == WM_XBUTTON##code || \
243 (message) == WM_NCLBUTTON##code || \
244 (message) == WM_NCMBUTTON##code || \
245 (message) == WM_NCRBUTTON##code || \
246 (message) == WM_NCXBUTTON##code )
247
248 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
249 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
250
251 #define IS_MOUSE_MESSAGE(message) \
252 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
253 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
254
255 #define IS_KBD_MESSAGE(message) \
256 (message == WM_KEYDOWN || message == WM_KEYUP)
257
258 HANDLE FASTCALL
259 IntMsqSetWakeMask(DWORD WakeMask);
260
261 BOOL FASTCALL
262 IntMsqClearWakeMask(VOID);
263
264 static __inline LONG
265 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
266 {
267 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
268 }
269
270 /* EOF */