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