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