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