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