e3b57e4779dd8db6eeb859231eac9d32edf80ce5
[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_INJECTMODULE 2
7
8 typedef struct _USER_MESSAGE
9 {
10 LIST_ENTRY ListEntry;
11 MSG Msg;
12 DWORD QS_Flags;
13 LONG_PTR ExtraInfo;
14 DWORD dwQEvent;
15 PTHREADINFO pti;
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 DWORD QS_Flags; // Original QS bits used to create this message.
25 PKEVENT pkCompletionEvent;
26 LRESULT lResult;
27 DWORD flags;
28 PTHREADINFO ptiSender;
29 PTHREADINFO ptiReceiver;
30 SENDASYNCPROC CompletionCallback;
31 PTHREADINFO ptiCallBackSender;
32 ULONG_PTR CompletionCallbackContext;
33 INT HookMessage;
34 BOOL HasPackedLParam;
35 KEVENT CompletionEvent;
36 } USER_SENT_MESSAGE, *PUSER_SENT_MESSAGE;
37
38 #define SMF_RECEIVERDIED 0x00000002
39 #define SMF_SENDERDIED 0x00000004
40 #define SMF_RECEIVERFREE 0x00000008
41 #define SMF_RECEIVEDMESSAGE 0x00000010
42 #define SMF_RECEIVERBUSY 0x00004000
43
44 typedef struct _USER_MESSAGE_QUEUE
45 {
46 /* Reference counter, only access this variable with interlocked functions! */
47 LONG References;
48
49 /* Desktop that the message queue is attached to */
50 struct _DESKTOP *Desktop;
51
52 PTHREADINFO ptiSysLock;
53 ULONG_PTR idSysLock;
54 ULONG_PTR idSysPeek;
55 PTHREADINFO ptiMouse;
56 PTHREADINFO ptiKeyboard;
57
58 /* Queue for hardware messages for the queue. */
59 LIST_ENTRY HardwareMessagesListHead;
60 /* Last click message for translating double clicks */
61 MSG msgDblClk;
62 /* Current capture window for this queue. */
63 PWND spwndCapture;
64 /* Current window with focus (ie. receives keyboard input) for this queue. */
65 PWND spwndFocus;
66 /* Current active window for this queue. */
67 PWND spwndActive;
68 PWND spwndActivePrev;
69 /* Current move/size window for this queue */
70 HWND MoveSize;
71 /* Current menu owner window for this queue */
72 HWND MenuOwner;
73 /* Identifes the menu state */
74 BYTE MenuState;
75 /* Message Queue Flags */
76 DWORD QF_flags;
77 DWORD cThreads; // Shared message queue counter.
78
79 /* Extra message information */
80 LPARAM ExtraInfo;
81
82 /* State of each key */
83 BYTE afKeyRecentDown[256 / 8]; // 1 bit per key
84 BYTE afKeyState[256 * 2 / 8]; // 2 bits per key
85
86 /* Showing cursor counter (value>=0 - cursor visible, value<0 - cursor hidden) */
87 INT iCursorLevel;
88 /* Cursor object */
89 PCURICON_OBJECT CursorObject;
90
91 /* Caret information for this queue */
92 THRDCARETINFO CaretInfo;
93 } USER_MESSAGE_QUEUE, *PUSER_MESSAGE_QUEUE;
94
95 #define QF_UPDATEKEYSTATE 0x00000001
96 #define QF_FMENUSTATUSBREAK 0x00000004
97 #define QF_FMENUSTATUS 0x00000008
98 #define QF_FF10STATUS 0x00000010
99 #define QF_MOUSEMOVED 0x00000020
100 #define QF_ACTIVATIONCHANGE 0x00000040
101 #define QF_TABSWITCHING 0x00000080
102 #define QF_KEYSTATERESET 0x00000100
103 #define QF_INDESTROY 0x00000200
104 #define QF_LOCKNOREMOVE 0x00000400
105 #define QF_FOCUSNULLSINCEACTIVE 0x00000800
106 #define QF_DIALOGACTIVE 0x00004000
107 #define QF_EVENTDEACTIVATEREMOVED 0x00008000
108 #define QF_TRACKMOUSELEAVE 0x00020000
109 #define QF_TRACKMOUSEHOVER 0x00040000
110 #define QF_TRACKMOUSEFIRING 0x00080000
111 #define QF_CAPTURELOCKED 0x00100000
112 #define QF_ACTIVEWNDTRACKING 0x00200000
113
114 /* Internal messages codes */
115 enum internal_event_message
116 {
117 WM_ASYNC_SHOWWINDOW = 0x80000000,
118 WM_ASYNC_SETWINDOWPOS,
119 WM_ASYNC_SETACTIVEWINDOW,
120 WM_ASYNC_DESTROYWINDOW
121 };
122
123 #define POSTEVENT_NWE 14
124
125 extern LIST_ENTRY usmList;
126
127 BOOL FASTCALL MsqIsHung(PTHREADINFO pti);
128 VOID CALLBACK HungAppSysTimerProc(HWND,UINT,UINT_PTR,DWORD);
129 NTSTATUS FASTCALL co_MsqSendMessage(PTHREADINFO ptirec,
130 HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam,
131 UINT uTimeout, BOOL Block, INT HookMessage, ULONG_PTR *uResult);
132 PUSER_MESSAGE FASTCALL MsqCreateMessage(LPMSG Msg);
133 VOID FASTCALL MsqDestroyMessage(PUSER_MESSAGE Message);
134 VOID FASTCALL MsqPostMessage(PTHREADINFO, MSG*, BOOLEAN, DWORD, DWORD, LONG_PTR);
135 VOID FASTCALL MsqPostQuitMessage(PTHREADINFO pti, ULONG ExitCode);
136 BOOLEAN APIENTRY
137 MsqPeekMessage(IN PTHREADINFO pti,
138 IN BOOLEAN Remove,
139 IN PWND Window,
140 IN UINT MsgFilterLow,
141 IN UINT MsgFilterHigh,
142 IN UINT QSflags,
143 OUT LONG_PTR *ExtraInfo,
144 OUT PMSG Message);
145 BOOL APIENTRY
146 co_MsqPeekHardwareMessage(IN PTHREADINFO pti,
147 IN BOOL Remove,
148 IN PWND Window,
149 IN UINT MsgFilterLow,
150 IN UINT MsgFilterHigh,
151 IN UINT QSflags,
152 OUT MSG* pMsg);
153 BOOLEAN FASTCALL MsqInitializeMessageQueue(PTHREADINFO, PUSER_MESSAGE_QUEUE);
154 PUSER_MESSAGE_QUEUE FASTCALL MsqCreateMessageQueue(PTHREADINFO);
155 VOID FASTCALL MsqCleanupThreadMsgs(PTHREADINFO);
156 VOID FASTCALL MsqDestroyMessageQueue(_In_ PTHREADINFO pti);
157 INIT_FUNCTION NTSTATUS NTAPI MsqInitializeImpl(VOID);
158 BOOLEAN FASTCALL co_MsqDispatchOneSentMessage(_In_ PTHREADINFO pti);
159 NTSTATUS FASTCALL
160 co_MsqWaitForNewMessages(PTHREADINFO pti, PWND WndFilter,
161 UINT MsgFilterMin, UINT MsgFilterMax);
162 VOID FASTCALL MsqIncPaintCountQueue(PTHREADINFO);
163 VOID FASTCALL MsqDecPaintCountQueue(PTHREADINFO);
164 LRESULT FASTCALL co_IntSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
165 LRESULT FASTCALL co_IntPostOrSendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
166 LRESULT FASTCALL
167 co_IntSendMessageTimeout(HWND hWnd,
168 UINT Msg,
169 WPARAM wParam,
170 LPARAM lParam,
171 UINT uFlags,
172 UINT uTimeout,
173 ULONG_PTR *uResult);
174
175 BOOL FASTCALL UserSendNotifyMessage( HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam );
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 BOOL FASTCALL
189 co_MsqSendMessageAsync(PTHREADINFO ptiReceiver,
190 HWND hwnd,
191 UINT Msg,
192 WPARAM wParam,
193 LPARAM lParam,
194 SENDASYNCPROC CompletionCallback,
195 ULONG_PTR CompletionCallbackContext,
196 BOOL HasPackedLParam,
197 INT HookMessage);
198
199 VOID FASTCALL IntCoalesceMouseMove(PTHREADINFO);
200 LRESULT FASTCALL IntDispatchMessage(MSG* Msg);
201 BOOL FASTCALL IntTranslateKbdMessage(LPMSG lpMsg, UINT flags);
202 VOID FASTCALL co_MsqInsertMouseMessage(MSG* Msg, DWORD flags, ULONG_PTR dwExtraInfo, BOOL Hook);
203 BOOL FASTCALL MsqIsClkLck(LPMSG Msg, BOOL Remove);
204 BOOL FASTCALL MsqIsDblClk(LPMSG Msg, BOOL Remove);
205 HWND FASTCALL MsqSetStateWindow(PTHREADINFO pti, ULONG Type, HWND hWnd);
206 BOOL APIENTRY IntInitMessagePumpHook(VOID);
207 BOOL APIENTRY IntUninitMessagePumpHook(VOID);
208
209 LPARAM FASTCALL MsqSetMessageExtraInfo(LPARAM lParam);
210 LPARAM FASTCALL MsqGetMessageExtraInfo(VOID);
211 VOID APIENTRY MsqRemoveWindowMessagesFromQueue(PWND pWindow);
212
213 #define IntReferenceMessageQueue(MsgQueue) \
214 InterlockedIncrement(&(MsgQueue)->References)
215
216 #define IntDereferenceMessageQueue(MsgQueue) \
217 do { \
218 if(InterlockedDecrement(&(MsgQueue)->References) == 0) \
219 { \
220 TRACE("Free message queue 0x%p\n", (MsgQueue)); \
221 ExFreePoolWithTag((MsgQueue), USERTAG_Q); \
222 } \
223 } while(0)
224
225 #define IS_BTN_MESSAGE(message,code) \
226 ((message) == WM_LBUTTON##code || \
227 (message) == WM_MBUTTON##code || \
228 (message) == WM_RBUTTON##code || \
229 (message) == WM_XBUTTON##code || \
230 (message) == WM_NCLBUTTON##code || \
231 (message) == WM_NCMBUTTON##code || \
232 (message) == WM_NCRBUTTON##code || \
233 (message) == WM_NCXBUTTON##code )
234
235 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
236 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
237
238 #define IS_MOUSE_MESSAGE(message) \
239 ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || \
240 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST))
241
242 #define IS_KBD_MESSAGE(message) \
243 (message >= WM_KEYFIRST && message <= WM_KEYLAST)
244
245 HANDLE FASTCALL IntMsqSetWakeMask(DWORD WakeMask);
246 BOOL FASTCALL IntMsqClearWakeMask(VOID);
247
248 static __inline LONG
249 MsqCalculateMessageTime(IN PLARGE_INTEGER TickCount)
250 {
251 return (LONG)(TickCount->QuadPart * (KeQueryTimeIncrement() / 10000));
252 }
253
254 VOID FASTCALL IdlePing(VOID);
255 VOID FASTCALL IdlePong(VOID);
256 BOOL FASTCALL co_MsqReplyMessage(LRESULT);
257 VOID FASTCALL MsqWakeQueue(PTHREADINFO,DWORD,BOOL);
258 VOID FASTCALL ClearMsgBitsMask(PTHREADINFO,UINT);
259 BOOL FASTCALL IntCallMsgFilter(LPMSG,INT);
260 WPARAM FASTCALL MsqGetDownKeyState(PUSER_MESSAGE_QUEUE);
261 BOOL FASTCALL IsThreadSuspended(PTHREADINFO);
262 PUSER_SENT_MESSAGE FASTCALL AllocateUserMessage(BOOL);
263 VOID FASTCALL FreeUserMessage(PUSER_SENT_MESSAGE);
264
265
266 int UserShowCursor(BOOL bShow);
267 PCURICON_OBJECT
268 FASTCALL
269 UserSetCursor(PCURICON_OBJECT NewCursor,
270 BOOL ForceChange);
271
272 DWORD APIENTRY IntGetQueueStatus(DWORD);
273
274 UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam);
275
276 BOOL APIENTRY
277 co_IntGetPeekMessage( PMSG pMsg,
278 HWND hWnd,
279 UINT MsgFilterMin,
280 UINT MsgFilterMax,
281 UINT RemoveMsg,
282 BOOL bGMSG );
283 BOOL FASTCALL
284 UserPostThreadMessage( PTHREADINFO pti,
285 UINT Msg,
286 WPARAM wParam,
287 LPARAM lParam );
288 BOOL FASTCALL
289 co_IntWaitMessage( PWND Window,
290 UINT MsgFilterMin,
291 UINT MsgFilterMax );
292
293 /* EOF */