[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 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 PMSG 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 INIT_FUNCTION
142 NTSTATUS
143 NTAPI
144 MsqInitializeImpl(VOID);
145 BOOLEAN FASTCALL
146 co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue);
147 NTSTATUS FASTCALL
148 co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
149 UINT MsgFilterMin, UINT MsgFilterMax);
150 VOID FASTCALL
151 MsqSendNotifyMessage(PUSER_MESSAGE_QUEUE MessageQueue,
152 PUSER_SENT_MESSAGE_NOTIFY NotifyMessage);
153 VOID FASTCALL
154 MsqIncPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
155 VOID FASTCALL
156 MsqDecPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
157 LRESULT FASTCALL
158 co_IntSendMessage(HWND hWnd,
159 UINT Msg,
160 WPARAM wParam,
161 LPARAM lParam);
162 LRESULT FASTCALL
163 co_IntPostOrSendMessage(HWND hWnd,
164 UINT Msg,
165 WPARAM wParam,
166 LPARAM lParam);
167 LRESULT FASTCALL
168 co_IntSendMessageTimeout(HWND hWnd,
169 UINT Msg,
170 WPARAM wParam,
171 LPARAM lParam,
172 UINT uFlags,
173 UINT uTimeout,
174 ULONG_PTR *uResult);
175
176 LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd,
177 UINT Msg,
178 WPARAM wParam,
179 LPARAM lParam);
180 LRESULT FASTCALL
181 co_IntSendMessageWithCallBack(HWND hWnd,
182 UINT Msg,
183 WPARAM wParam,
184 LPARAM lParam,
185 SENDASYNCPROC CompletionCallback,
186 ULONG_PTR CompletionCallbackContext,
187 ULONG_PTR *uResult);
188
189 LRESULT FASTCALL
190 IntDispatchMessage(MSG* Msg);
191 BOOL FASTCALL
192 IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
193
194 VOID FASTCALL
195 co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
196 VOID FASTCALL
197 MsqPostHotKeyMessage(PVOID Thread, HWND hWnd, WPARAM wParam, LPARAM lParam);
198 VOID FASTCALL
199 MsqInsertMouseMessage(MSG* Msg);
200 BOOL FASTCALL
201 MsqIsClkLck(LPMSG Msg, BOOL Remove);
202 BOOL FASTCALL
203 MsqIsDblClk(LPMSG Msg, BOOL Remove);
204 HWND FASTCALL
205 MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
206
207 __inline BOOL MsqIsSignaled( PUSER_MESSAGE_QUEUE queue );
208 __inline VOID MsqSetQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
209 __inline VOID MsqClearQueueBits( PUSER_MESSAGE_QUEUE queue, WORD bits );
210 BOOL APIENTRY IntInitMessagePumpHook();
211 BOOL APIENTRY IntUninitMessagePumpHook();
212 #define MAKE_LONG(x, y) ((((y) & 0xFFFF) << 16) | ((x) & 0xFFFF))
213
214 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
215 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
216 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, will be gone in the rewrite! */
217
218 #define IntLockHardwareMessageQueue(MsgQueue) \
219 KeWaitForMutexObject(&(MsgQueue)->HardwareLock, UserRequest, KernelMode, FALSE, NULL)
220
221 #define IntUnLockHardwareMessageQueue(MsgQueue) \
222 KeReleaseMutex(&(MsgQueue)->HardwareLock, FALSE)
223
224 #define IntReferenceMessageQueue(MsgQueue) \
225 InterlockedIncrement(&(MsgQueue)->References)
226
227 #define IntDereferenceMessageQueue(MsgQueue) \
228 do { \
229 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
230 { \
231 DPRINT("Free message queue 0x%x\n", (MsgQueue)); \
232 if ((MsgQueue)->NewMessages != NULL) \
233 ObDereferenceObject((MsgQueue)->NewMessages); \
234 if ((MsgQueue)->NewMessagesHandle != NULL) \
235 ZwClose((MsgQueue)->NewMessagesHandle); \
236 ExFreePool((MsgQueue)); \
237 } \
238 } while(0)
239
240 #define IS_BTN_MESSAGE(message,code) \
241 ((message) == WM_LBUTTON##code || \
242 (message) == WM_MBUTTON##code || \
243 (message) == WM_RBUTTON##code || \
244 (message) == WM_XBUTTON##code || \
245 (message) == WM_NCLBUTTON##code || \
246 (message) == WM_NCMBUTTON##code || \
247 (message) == WM_NCRBUTTON##code || \
248 (message) == WM_NCXBUTTON##code )
249
250 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
251 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
252
253 #define IS_MOUSE_MESSAGE(message) \
254 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
255 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
256
257 #define IS_KBD_MESSAGE(message) \
258 (message == WM_KEYDOWN || message == WM_KEYUP)
259
260 HANDLE FASTCALL
261 IntMsqSetWakeMask(DWORD WakeMask);
262
263 BOOL FASTCALL
264 IntMsqClearWakeMask(VOID);
265
266 static __inline LONG
267 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
268 {
269 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
270 }
271
272 /* EOF */