[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_IntSendMessageTimeout(HWND hWnd,
184 UINT Msg,
185 WPARAM wParam,
186 LPARAM lParam,
187 UINT uFlags,
188 UINT uTimeout,
189 ULONG_PTR *uResult);
190 BOOL FASTCALL UserSendNotifyMessage( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam );
191 LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd,
192 UINT Msg,
193 WPARAM wParam,
194 LPARAM lParam);
195 LRESULT FASTCALL
196 co_IntSendMessageWithCallBack(HWND hWnd,
197 UINT Msg,
198 WPARAM wParam,
199 LPARAM lParam,
200 SENDASYNCPROC CompletionCallback,
201 ULONG_PTR CompletionCallbackContext,
202 ULONG_PTR *uResult);
203
204 LRESULT FASTCALL
205 IntDispatchMessage(MSG* Msg);
206 BOOL FASTCALL
207 IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
208
209 VOID FASTCALL
210 co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
211 VOID FASTCALL
212 MsqPostHotKeyMessage(PVOID Thread, HWND hWnd, WPARAM wParam, LPARAM lParam);
213 VOID FASTCALL
214 co_MsqInsertMouseMessage(MSG* Msg);
215 BOOL FASTCALL
216 MsqIsClkLck(LPMSG Msg, BOOL Remove);
217 BOOL FASTCALL
218 MsqIsDblClk(LPMSG Msg, BOOL Remove);
219 HWND FASTCALL
220 MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
221
222 __inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
223 __inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
224 BOOL APIENTRY IntInitMessagePumpHook();
225 BOOL APIENTRY IntUninitMessagePumpHook();
226 #define MAKE_LONG(x, y) ((((y) & 0xFFFF) << 16) | ((x) & 0xFFFF))
227
228 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
229 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
230 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, will be gone in the rewrite! */
231
232 #define IntLockHardwareMessageQueue(MsgQueue) \
233 KeWaitForMutexObject(&(MsgQueue)->HardwareLock, UserRequest, KernelMode, FALSE, NULL)
234
235 #define IntUnLockHardwareMessageQueue(MsgQueue) \
236 KeReleaseMutex(&(MsgQueue)->HardwareLock, FALSE)
237
238 #define IntReferenceMessageQueue(MsgQueue) \
239 InterlockedIncrement(&(MsgQueue)->References)
240
241 #define IntDereferenceMessageQueue(MsgQueue) \
242 do { \
243 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
244 { \
245 DPRINT("Free message queue 0x%x\n", (MsgQueue)); \
246 if ((MsgQueue)->NewMessages != NULL) \
247 ObDereferenceObject((MsgQueue)->NewMessages); \
248 if ((MsgQueue)->NewMessagesHandle != NULL) \
249 ZwClose((MsgQueue)->NewMessagesHandle); \
250 ExFreePoolWithTag((MsgQueue), USERTAG_Q); \
251 } \
252 } while(0)
253
254 #define IS_BTN_MESSAGE(message,code) \
255 ((message) == WM_LBUTTON##code || \
256 (message) == WM_MBUTTON##code || \
257 (message) == WM_RBUTTON##code || \
258 (message) == WM_XBUTTON##code || \
259 (message) == WM_NCLBUTTON##code || \
260 (message) == WM_NCMBUTTON##code || \
261 (message) == WM_NCRBUTTON##code || \
262 (message) == WM_NCXBUTTON##code )
263
264 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
265 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
266
267 #define IS_MOUSE_MESSAGE(message) \
268 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
269 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
270
271 #define IS_KBD_MESSAGE(message) \
272 (message == WM_KEYDOWN || message == WM_KEYUP)
273
274 HANDLE FASTCALL
275 IntMsqSetWakeMask(DWORD WakeMask);
276
277 BOOL FASTCALL
278 IntMsqClearWakeMask(VOID);
279
280 static __inline LONG
281 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
282 {
283 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
284 }
285
286 VOID FASTCALL IdlePing(VOID);
287 VOID FASTCALL IdlePong(VOID);
288 BOOL FASTCALL co_MsqReplyMessage(LRESULT);
289 UINT FASTCALL GetWakeMask(UINT, UINT);
290 VOID FASTCALL MsqWakeQueue(PUSER_MESSAGE_QUEUE,DWORD,BOOL);
291 VOID FASTCALL ClearMsgBitsMask(PUSER_MESSAGE_QUEUE,UINT);
292
293 /* EOF */