[CMAKE]
[reactos.git] / 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 #define QSIDCOUNTS 6
12
13 typedef enum _QS_ROS_TYPES
14 {
15 QSRosKey = 0,
16 QSRosMouseMove,
17 QSRosMouseButton,
18 QSRosPostMessage,
19 QSRosSendMessage,
20 QSRosHotKey,
21 }QS_ROS_TYPES,*PQS_ROS_TYPES;
22
23 typedef struct _USER_MESSAGE
24 {
25 LIST_ENTRY ListEntry;
26 MSG Msg;
27 DWORD QS_Flags;
28 } USER_MESSAGE, *PUSER_MESSAGE;
29
30 struct _USER_MESSAGE_QUEUE;
31
32 typedef struct _USER_SENT_MESSAGE
33 {
34 LIST_ENTRY ListEntry;
35 MSG Msg;
36 DWORD QS_Flags; // Original QS bits used to create this message.
37 PKEVENT CompletionEvent;
38 LRESULT* Result;
39 LRESULT lResult;
40 struct _USER_MESSAGE_QUEUE* SenderQueue;
41 struct _USER_MESSAGE_QUEUE* CallBackSenderQueue;
42 SENDASYNCPROC CompletionCallback;
43 ULONG_PTR CompletionCallbackContext;
44 /* entry in the dispatching list of the sender's message queue */
45 LIST_ENTRY DispatchingListEntry;
46 INT HookMessage;
47 BOOL HasPackedLParam;
48 } USER_SENT_MESSAGE, *PUSER_SENT_MESSAGE;
49
50 typedef struct _USER_MESSAGE_QUEUE
51 {
52 /* Reference counter, only access this variable with interlocked functions! */
53 LONG References;
54
55 /* Owner of the message queue */
56 struct _ETHREAD *Thread;
57 /* Queue of messages sent to the queue. */
58 LIST_ENTRY SentMessagesListHead;
59 /* Queue of messages posted to the queue. */
60 LIST_ENTRY PostedMessagesListHead;
61 /* Queue for hardware messages for the queue. */
62 LIST_ENTRY HardwareMessagesListHead;
63 /* Lock for the hardware message list. */
64 KMUTEX HardwareLock;
65 /* True if a WM_MOUSEMOVE is pending */
66 BOOLEAN MouseMoved;
67 /* Current WM_MOUSEMOVE message */
68 MSG MouseMoveMsg;
69 /* Last click message for translating double clicks */
70 MSG msgDblClk;
71 /* True if a WM_QUIT message is pending. */
72 BOOLEAN QuitPosted;
73 /* The quit exit code. */
74 ULONG QuitExitCode;
75 /* Set if there are new messages specified by WakeMask in any of the queues. */
76 PKEVENT NewMessages;
77 /* Handle for the above event (in the context of the process owning the queue). */
78 HANDLE NewMessagesHandle;
79 /* Last time PeekMessage() was called. */
80 ULONG LastMsgRead;
81 /* Current window with focus (ie. receives keyboard input) for this queue. */
82 HWND FocusWindow;
83 /* Current active window for this queue. */
84 HWND ActiveWindow;
85 /* Current capture window for this queue. */
86 HWND CaptureWindow;
87 /* Current move/size window for this queue */
88 HWND MoveSize;
89 /* Current menu owner window for this queue */
90 HWND MenuOwner;
91 /* Identifes the menu state */
92 BYTE MenuState;
93 /* Caret information for this queue */
94 PTHRDCARETINFO CaretInfo;
95
96 /* queue state tracking */
97 // Send list QS_SENDMESSAGE
98 // Post list QS_POSTMESSAGE|QS_HOTKEY|QS_PAINT|QS_TIMER|QS_KEY
99 // Hard list QS_MOUSE|QS_KEY only
100 // Accounting of queue bit sets, the rest are flags. QS_TIMER QS_PAINT counts are handled in thread information.
101 DWORD nCntsQBits[QSIDCOUNTS]; // QS_KEY QS_MOUSEMOVE QS_MOUSEBUTTON QS_POSTMESSAGE QS_SENDMESSAGE QS_HOTKEY
102
103 /* extra message information */
104 LPARAM ExtraInfo;
105
106 /* messages that are currently dispatched by other threads */
107 LIST_ENTRY DispatchingMessagesHead;
108 /* messages that are currently dispatched by this message queue, required for cleanup */
109 LIST_ENTRY LocalDispatchingMessagesHead;
110
111 /* Desktop that the message queue is attached to */
112 struct _DESKTOP *Desktop;
113 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;
114
115 BOOL FASTCALL
116 MsqIsHung(PUSER_MESSAGE_QUEUE MessageQueue);
117 NTSTATUS FASTCALL
118 co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
119 HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam,
120 UINT uTimeout, BOOL Block, INT HookMessage,
121 ULONG_PTR *uResult);
122 PUSER_MESSAGE FASTCALL
123 MsqCreateMessage(LPMSG Msg);
124 VOID FASTCALL
125 MsqDestroyMessage(PUSER_MESSAGE Message);
126 VOID FASTCALL
127 MsqPostMessage(PUSER_MESSAGE_QUEUE MessageQueue,
128 MSG* Msg, BOOLEAN HardwareMessage, DWORD MessageBits);
129 VOID FASTCALL
130 MsqPostQuitMessage(PUSER_MESSAGE_QUEUE MessageQueue, ULONG ExitCode);
131 BOOLEAN APIENTRY
132 MsqPeekMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
133 IN BOOLEAN Remove,
134 IN PWND Window,
135 IN UINT MsgFilterLow,
136 IN UINT MsgFilterHigh,
137 IN UINT QSflags,
138 OUT PMSG Message);
139 BOOL APIENTRY
140 co_MsqPeekHardwareMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
141 IN BOOL Remove,
142 IN PWND Window,
143 IN UINT MsgFilterLow,
144 IN UINT MsgFilterHigh,
145 IN UINT QSflags,
146 OUT MSG* pMsg);
147 BOOL APIENTRY
148 co_MsqPeekMouseMove(IN PUSER_MESSAGE_QUEUE MessageQueue,
149 IN BOOL Remove,
150 IN PWND Window,
151 IN UINT MsgFilterLow,
152 IN UINT MsgFilterHigh,
153 OUT MSG* pMsg);
154 BOOLEAN FASTCALL
155 MsqInitializeMessageQueue(struct _ETHREAD *Thread, PUSER_MESSAGE_QUEUE MessageQueue);
156 VOID FASTCALL
157 MsqCleanupMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
158 PUSER_MESSAGE_QUEUE FASTCALL
159 MsqCreateMessageQueue(struct _ETHREAD *Thread);
160 VOID FASTCALL
161 MsqDestroyMessageQueue(PUSER_MESSAGE_QUEUE MessageQueue);
162 PUSER_MESSAGE_QUEUE FASTCALL
163 MsqGetHardwareMessageQueue(VOID);
164 INIT_FUNCTION
165 NTSTATUS
166 NTAPI
167 MsqInitializeImpl(VOID);
168 BOOLEAN FASTCALL
169 co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue);
170 NTSTATUS FASTCALL
171 co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
172 UINT MsgFilterMin, UINT MsgFilterMax);
173 VOID FASTCALL
174 MsqIncPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
175 VOID FASTCALL
176 MsqDecPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
177 LRESULT FASTCALL
178 co_IntSendMessage(HWND hWnd,
179 UINT Msg,
180 WPARAM wParam,
181 LPARAM lParam);
182 LRESULT FASTCALL
183 co_IntPostOrSendMessage(HWND hWnd,
184 UINT Msg,
185 WPARAM wParam,
186 LPARAM lParam);
187 LRESULT FASTCALL
188 co_IntSendMessageTimeout(HWND hWnd,
189 UINT Msg,
190 WPARAM wParam,
191 LPARAM lParam,
192 UINT uFlags,
193 UINT uTimeout,
194 ULONG_PTR *uResult);
195
196 BOOL FASTCALL UserSendNotifyMessage( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam );
197 LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd,
198 UINT Msg,
199 WPARAM wParam,
200 LPARAM lParam);
201 LRESULT FASTCALL
202 co_IntSendMessageWithCallBack(HWND hWnd,
203 UINT Msg,
204 WPARAM wParam,
205 LPARAM lParam,
206 SENDASYNCPROC CompletionCallback,
207 ULONG_PTR CompletionCallbackContext,
208 ULONG_PTR *uResult);
209
210 LRESULT FASTCALL
211 IntDispatchMessage(MSG* Msg);
212 BOOL FASTCALL
213 IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
214
215 VOID FASTCALL
216 co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
217 VOID FASTCALL
218 MsqPostHotKeyMessage(PVOID Thread, HWND hWnd, WPARAM wParam, LPARAM lParam);
219 VOID FASTCALL
220 co_MsqInsertMouseMessage(MSG* Msg);
221 BOOL FASTCALL
222 MsqIsClkLck(LPMSG Msg, BOOL Remove);
223 BOOL FASTCALL
224 MsqIsDblClk(LPMSG Msg, BOOL Remove);
225 HWND FASTCALL
226 MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
227
228 __inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
229 __inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
230 BOOL APIENTRY IntInitMessagePumpHook();
231 BOOL APIENTRY IntUninitMessagePumpHook();
232 #define MAKE_LONG(x, y) ((((y) & 0xFFFF) << 16) | ((x) & 0xFFFF))
233
234 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
235 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
236 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, will be gone in the rewrite! */
237
238 #define IntLockHardwareMessageQueue(MsgQueue) \
239 KeWaitForMutexObject(&(MsgQueue)->HardwareLock, UserRequest, KernelMode, FALSE, NULL)
240
241 #define IntUnLockHardwareMessageQueue(MsgQueue) \
242 KeReleaseMutex(&(MsgQueue)->HardwareLock, FALSE)
243
244 #define IntReferenceMessageQueue(MsgQueue) \
245 InterlockedIncrement(&(MsgQueue)->References)
246
247 #define IntDereferenceMessageQueue(MsgQueue) \
248 do { \
249 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
250 { \
251 DPRINT("Free message queue 0x%x\n", (MsgQueue)); \
252 if ((MsgQueue)->NewMessages != NULL) \
253 ObDereferenceObject((MsgQueue)->NewMessages); \
254 if ((MsgQueue)->NewMessagesHandle != NULL) \
255 ZwClose((MsgQueue)->NewMessagesHandle); \
256 ExFreePoolWithTag((MsgQueue), USERTAG_Q); \
257 } \
258 } while(0)
259
260 #define IS_BTN_MESSAGE(message,code) \
261 ((message) == WM_LBUTTON##code || \
262 (message) == WM_MBUTTON##code || \
263 (message) == WM_RBUTTON##code || \
264 (message) == WM_XBUTTON##code || \
265 (message) == WM_NCLBUTTON##code || \
266 (message) == WM_NCMBUTTON##code || \
267 (message) == WM_NCRBUTTON##code || \
268 (message) == WM_NCXBUTTON##code )
269
270 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
271 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
272
273 #define IS_MOUSE_MESSAGE(message) \
274 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
275 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
276
277 #define IS_KBD_MESSAGE(message) \
278 (message == WM_KEYDOWN || message == WM_KEYUP)
279
280 HANDLE FASTCALL
281 IntMsqSetWakeMask(DWORD WakeMask);
282
283 BOOL FASTCALL
284 IntMsqClearWakeMask(VOID);
285
286 static __inline LONG
287 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
288 {
289 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
290 }
291
292 VOID FASTCALL IdlePing(VOID);
293 VOID FASTCALL IdlePong(VOID);
294 BOOL FASTCALL co_MsqReplyMessage(LRESULT);
295 UINT FASTCALL GetWakeMask(UINT, UINT);
296 VOID FASTCALL MsqWakeQueue(PUSER_MESSAGE_QUEUE,DWORD,BOOL);
297 VOID FASTCALL ClearMsgBitsMask(PUSER_MESSAGE_QUEUE,UINT);
298
299 /* EOF */