[WIN32K]
[reactos.git] / reactos / win32ss / user / ntuser / msgqueue.h
1 #pragma once
2
3 #define MSQ_HUNG 5000
4 #define MSQ_NORMAL 0
5 #define MSQ_ISHOOK 1
6 #define MSQ_ISEVENT 2
7 #define MSQ_INJECTMODULE 3
8
9 #define QSIDCOUNTS 6
10
11 typedef enum _QS_ROS_TYPES
12 {
13 QSRosKey = 0,
14 QSRosMouseMove,
15 QSRosMouseButton,
16 QSRosPostMessage,
17 QSRosSendMessage,
18 QSRosHotKey,
19 }QS_ROS_TYPES,*PQS_ROS_TYPES;
20
21 typedef struct _USER_MESSAGE
22 {
23 LIST_ENTRY ListEntry;
24 MSG Msg;
25 DWORD QS_Flags;
26 LONG_PTR ExtraInfo;
27 DWORD dwQEvent;
28 PTHREADINFO pti;
29 } USER_MESSAGE, *PUSER_MESSAGE;
30
31 struct _USER_MESSAGE_QUEUE;
32
33 typedef struct _USER_SENT_MESSAGE
34 {
35 LIST_ENTRY ListEntry;
36 MSG Msg;
37 DWORD QS_Flags; // Original QS bits used to create this message.
38 PKEVENT CompletionEvent;
39 LRESULT* Result;
40 LRESULT lResult;
41 struct _USER_MESSAGE_QUEUE* SenderQueue;
42 struct _USER_MESSAGE_QUEUE* CallBackSenderQueue;
43 SENDASYNCPROC CompletionCallback;
44 ULONG_PTR CompletionCallbackContext;
45 /* entry in the dispatching list of the sender's message queue */
46 LIST_ENTRY DispatchingListEntry;
47 INT HookMessage;
48 BOOL HasPackedLParam;
49 } USER_SENT_MESSAGE, *PUSER_SENT_MESSAGE;
50
51 typedef struct _USER_MESSAGE_QUEUE
52 {
53 /* Reference counter, only access this variable with interlocked functions! */
54 LONG References;
55
56 PTHREADINFO ptiSysLock;
57 /* Owner of the message queue */
58 struct _ETHREAD *Thread;
59 /* Queue of messages sent to the queue. */
60 LIST_ENTRY SentMessagesListHead;
61 /* Queue of messages posted to the queue. */
62 LIST_ENTRY PostedMessagesListHead;
63 /* Queue for hardware messages for the queue. */
64 LIST_ENTRY HardwareMessagesListHead;
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 capture window for this queue. */
82 PWND spwndCapture;
83 /* Current window with focus (ie. receives keyboard input) for this queue. */
84 PWND spwndFocus;
85 /* Current active window for this queue. */
86 PWND spwndActive;
87 PWND spwndActivePrev;
88 /* Current move/size window for this queue */
89 HWND MoveSize;
90 /* Current menu owner window for this queue */
91 HWND MenuOwner;
92 /* Identifes the menu state */
93 BYTE MenuState;
94 /* Caret information for this queue */
95 PTHRDCARETINFO CaretInfo;
96 /* Message Queue Flags */
97 DWORD QF_flags;
98 DWORD cThreads; // Shared message queue counter.
99
100 /* Queue state tracking */
101 // Send list QS_SENDMESSAGE
102 // Post list QS_POSTMESSAGE|QS_HOTKEY|QS_PAINT|QS_TIMER|QS_KEY
103 // Hard list QS_MOUSE|QS_KEY only
104 // Accounting of queue bit sets, the rest are flags. QS_TIMER QS_PAINT counts are handled in thread information.
105 DWORD nCntsQBits[QSIDCOUNTS]; // QS_KEY QS_MOUSEMOVE QS_MOUSEBUTTON QS_POSTMESSAGE QS_SENDMESSAGE QS_HOTKEY
106
107 /* Extra message information */
108 LPARAM ExtraInfo;
109
110 /* State of each key */
111 BYTE afKeyRecentDown[256 / 8]; // 1 bit per key
112 BYTE afKeyState[256 * 2 / 8]; // 2 bits per key
113
114 /* Showing cursor counter (value>=0 - cursor visible, value<0 - cursor hidden) */
115 INT iCursorLevel;
116 /* Cursor object */
117 PCURICON_OBJECT CursorObject;
118
119 /* Messages that are currently dispatched by other threads */
120 LIST_ENTRY DispatchingMessagesHead;
121 /* Messages that are currently dispatched by this message queue, required for cleanup */
122 LIST_ENTRY LocalDispatchingMessagesHead;
123
124 /* Desktop that the message queue is attached to */
125 struct _DESKTOP *Desktop;
126 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;
127
128 #define QF_UPDATEKEYSTATE 0x00000001
129 #define QF_FMENUSTATUSBREAK 0x00000004
130 #define QF_FMENUSTATUS 0x00000008
131 #define QF_FF10STATUS 0x00000010
132 #define QF_MOUSEMOVED 0x00000020 // See MouseMoved.
133 #define QF_ACTIVATIONCHANGE 0x00000040
134 #define QF_TABSWITCHING 0x00000080
135 #define QF_KEYSTATERESET 0x00000100
136 #define QF_INDESTROY 0x00000200
137 #define QF_LOCKNOREMOVE 0x00000400
138 #define QF_FOCUSNULLSINCEACTIVE 0x00000800
139 #define QF_DIALOGACTIVE 0x00004000
140 #define QF_EVENTDEACTIVATEREMOVED 0x00008000
141 #define QF_TRACKMOUSELEAVE 0x00020000
142 #define QF_TRACKMOUSEHOVER 0x00040000
143 #define QF_TRACKMOUSEFIRING 0x00080000
144 #define QF_CAPTURELOCKED 0x00100000
145 #define QF_ACTIVEWNDTRACKING 0x00200000
146
147 /* Internal messages codes */
148 enum internal_event_message
149 {
150 WM_ASYNC_SHOWWINDOW = 0x80000000,
151 WM_ASYNC_SETWINDOWPOS,
152 WM_ASYNC_SETACTIVEWINDOW
153 };
154
155 BOOL FASTCALL MsqIsHung(PUSER_MESSAGE_QUEUE MessageQueue);
156 VOID CALLBACK HungAppSysTimerProc(HWND,UINT,UINT_PTR,DWORD);
157 NTSTATUS FASTCALL co_MsqSendMessage(PUSER_MESSAGE_QUEUE MessageQueue,
158 HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam,
159 UINT uTimeout, BOOL Block, INT HookMessage, ULONG_PTR *uResult);
160 PUSER_MESSAGE FASTCALL MsqCreateMessage(LPMSG Msg);
161 VOID FASTCALL MsqDestroyMessage(PUSER_MESSAGE Message);
162 VOID FASTCALL MsqPostMessage(PUSER_MESSAGE_QUEUE, MSG*, BOOLEAN, DWORD, DWORD);
163 VOID FASTCALL MsqPostQuitMessage(PUSER_MESSAGE_QUEUE MessageQueue, ULONG ExitCode);
164 BOOLEAN APIENTRY
165 MsqPeekMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
166 IN BOOLEAN Remove,
167 IN PWND Window,
168 IN UINT MsgFilterLow,
169 IN UINT MsgFilterHigh,
170 IN UINT QSflags,
171 OUT PMSG Message);
172 BOOL APIENTRY
173 co_MsqPeekHardwareMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
174 IN BOOL Remove,
175 IN PWND Window,
176 IN UINT MsgFilterLow,
177 IN UINT MsgFilterHigh,
178 IN UINT QSflags,
179 OUT MSG* pMsg);
180 BOOL APIENTRY
181 co_MsqPeekMouseMove(IN PUSER_MESSAGE_QUEUE MessageQueue,
182 IN BOOL Remove,
183 IN PWND Window,
184 IN UINT MsgFilterLow,
185 IN UINT MsgFilterHigh,
186 OUT MSG* pMsg);
187 BOOLEAN FASTCALL MsqInitializeMessageQueue(PTHREADINFO, PUSER_MESSAGE_QUEUE);
188 PUSER_MESSAGE_QUEUE FASTCALL MsqCreateMessageQueue(PTHREADINFO);
189 VOID FASTCALL MsqDestroyMessageQueue(PTHREADINFO);
190 INIT_FUNCTION NTSTATUS NTAPI MsqInitializeImpl(VOID);
191 BOOLEAN FASTCALL co_MsqDispatchOneSentMessage(_In_ PUSER_MESSAGE_QUEUE MessageQueue);
192 NTSTATUS FASTCALL
193 co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWND WndFilter,
194 UINT MsgFilterMin, UINT MsgFilterMax);
195 VOID FASTCALL MsqIncPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
196 VOID FASTCALL MsqDecPaintCountQueue(PUSER_MESSAGE_QUEUE Queue);
197 LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
198 LRESULT FASTCALL co_IntPostOrSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
199 LRESULT FASTCALL
200 co_IntSendMessageTimeout(HWND hWnd,
201 UINT Msg,
202 WPARAM wParam,
203 LPARAM lParam,
204 UINT uFlags,
205 UINT uTimeout,
206 ULONG_PTR *uResult);
207
208 BOOL FASTCALL UserSendNotifyMessage( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam );
209 LRESULT FASTCALL co_IntSendMessageNoWait(HWND hWnd,
210 UINT Msg,
211 WPARAM wParam,
212 LPARAM lParam);
213 LRESULT FASTCALL
214 co_IntSendMessageWithCallBack(HWND hWnd,
215 UINT Msg,
216 WPARAM wParam,
217 LPARAM lParam,
218 SENDASYNCPROC CompletionCallback,
219 ULONG_PTR CompletionCallbackContext,
220 ULONG_PTR *uResult);
221 BOOL FASTCALL
222 co_MsqSendMessageAsync(PTHREADINFO ptiReceiver,
223 HWND hwnd,
224 UINT Msg,
225 WPARAM wParam,
226 LPARAM lParam,
227 SENDASYNCPROC CompletionCallback,
228 ULONG_PTR CompletionCallbackContext,
229 BOOL HasPackedLParam,
230 INT HookMessage);
231
232 LRESULT FASTCALL IntDispatchMessage(MSG* Msg);
233 BOOL FASTCALL IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
234 VOID FASTCALL MsqPostHotKeyMessage(PVOID Thread, HWND hWnd, WPARAM wParam, LPARAM lParam);
235 VOID FASTCALL co_MsqInsertMouseMessage(MSG* Msg, DWORD flags, ULONG_PTR dwExtraInfo, BOOL Hook);
236 BOOL FASTCALL MsqIsClkLck(LPMSG Msg, BOOL Remove);
237 BOOL FASTCALL MsqIsDblClk(LPMSG Msg, BOOL Remove);
238 HWND FASTCALL MsqSetStateWindow(PUSER_MESSAGE_QUEUE MessageQueue, ULONG Type, HWND hWnd);
239 BOOL APIENTRY IntInitMessagePumpHook(VOID);
240 BOOL APIENTRY IntUninitMessagePumpHook(VOID);
241
242 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
243 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
244 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PVOID pWindow); /* F*(&$ headers, will be gone in the rewrite! */
245
246 #define IntReferenceMessageQueue(MsgQueue) \
247 InterlockedIncrement(&(MsgQueue)->References)
248
249 #define IntDereferenceMessageQueue(MsgQueue) \
250 do { \
251 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
252 { \
253 TRACE("Free message queue 0x%p\n", (MsgQueue)); \
254 if ((MsgQueue)->NewMessages != NULL) \
255 ObDereferenceObject((MsgQueue)->NewMessages); \
256 ExFreePoolWithTag((MsgQueue), USERTAG_Q); \
257 } \
258 } while(0)
259
260 #define IS_BTN_MESSAGE(message,code) \
261 ((message) == WM_LBUTTON##code || \
262 (message) == WM_MBUTTON##code || \
263 (message) == WM_RBUTTON##code || \
264 (message) == WM_XBUTTON##code || \
265 (message) == WM_NCLBUTTON##code || \
266 (message) == WM_NCMBUTTON##code || \
267 (message) == WM_NCRBUTTON##code || \
268 (message) == WM_NCXBUTTON##code )
269
270 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
271 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
272
273 #define IS_MOUSE_MESSAGE(message) \
274 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
275 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
276
277 #define IS_KBD_MESSAGE(message) \
278 (message >= WM_KEYFIRST && message <= WM_KEYLAST)
279
280 HANDLE FASTCALL IntMsqSetWakeMask(DWORD WakeMask);
281 BOOL FASTCALL IntMsqClearWakeMask(VOID);
282
283 static __inline LONG
284 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
285 {
286 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
287 }
288
289 VOID FASTCALL IdlePing(VOID);
290 VOID FASTCALL IdlePong(VOID);
291 BOOL FASTCALL co_MsqReplyMessage(LRESULT);
292 VOID FASTCALL MsqWakeQueue(PUSER_MESSAGE_QUEUE,DWORD,BOOL);
293 VOID FASTCALL ClearMsgBitsMask(PUSER_MESSAGE_QUEUE,UINT);
294
295 int UserShowCursor(BOOL bShow);
296 PCURICON_OBJECT
297 FASTCALL
298 UserSetCursor(PCURICON_OBJECT NewCursor,
299 BOOL ForceChange);
300
301 DWORD APIENTRY IntGetQueueStatus(DWORD);
302
303 UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam);
304
305 BOOL FASTCALL
306 co_IntGetPeekMessage( PMSG pMsg,
307 HWND hWnd,
308 UINT MsgFilterMin,
309 UINT MsgFilterMax,
310 UINT RemoveMsg,
311 BOOL bGMSG );
312
313 /* EOF */