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