blob: 7c36e5125b9ad1f608b1c9890047c856e298d543 [file] [log] [blame]
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001/*
2 * Message queues related functions
3 *
Alexandre Julliardaca05781994-10-17 18:12:41 +00004 * Copyright 1993, 1994 Alexandre Julliard
Alexandre Julliard75a839a1993-07-15 11:13:45 +00005 */
6
Alexandre Julliard401710d1993-09-04 10:09:32 +00007#include <stdlib.h>
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00008#include <string.h>
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00009#include <ctype.h>
Alexandre Julliard5f721f81994-01-04 20:14:34 +000010#include <sys/time.h>
11#include <sys/types.h>
Alexandre Julliardf41aeca1993-09-14 16:47:10 +000012
Marcus Meissner317af321999-02-17 13:51:06 +000013#include "wine/winbase16.h"
Alexandre Julliard75a839a1993-07-15 11:13:45 +000014#include "message.h"
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +000015#include "winerror.h"
Alexandre Julliard75a839a1993-07-15 11:13:45 +000016#include "win.h"
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +000017#include "heap.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000018#include "hook.h"
Ulrich Weiganda11ce321998-11-08 12:27:26 +000019#include "input.h"
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000020#include "spy.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000021#include "winpos.h"
Alexandre Julliarde2991ea1995-07-29 13:09:43 +000022#include "dde.h"
Alexandre Julliardb817f4f1996-03-14 18:08:34 +000023#include "queue.h"
Alexandre Julliard3051b641996-07-05 17:14:13 +000024#include "winproc.h"
Alexandre Julliarddadf78f1998-05-17 17:13:43 +000025#include "thread.h"
Alexandre Julliard84c70f51997-05-09 08:40:27 +000026#include "options.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000027#include "controls.h"
Alexandre Julliard829fe321998-07-26 14:27:39 +000028#include "struct32.h"
Alexandre Julliard06c275a1999-05-02 14:32:27 +000029#include "debugtools.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000030
Alexandre Julliardc5e433a2000-05-30 19:48:18 +000031DEFAULT_DEBUG_CHANNEL(msg);
32DECLARE_DEBUG_CHANNEL(key);
33DECLARE_DEBUG_CHANNEL(sendmsg);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000034
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000035#define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
36#define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
37
Stephane Lussierb3a99de1999-02-09 15:35:12 +000038
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000039typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
40 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000041
Stephane Lussier1c4786f1999-01-28 10:54:11 +000042extern HQUEUE16 hCursorQueue; /* queue.c */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000043
Alexandre Julliarda3960291999-02-26 11:11:13 +000044static UINT doubleClickSpeed = 452;
Stephane Lussier2c86dab1999-02-18 17:34:09 +000045
Alexandre Julliard75a839a1993-07-15 11:13:45 +000046/***********************************************************************
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000047 * MSG_CheckFilter
48 */
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +000049static BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000050{
Stephane Lussierb3a99de1999-02-09 15:35:12 +000051 if( first || last )
52 return (uMsg >= first && uMsg <= last);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000053 return TRUE;
54}
55
56/***********************************************************************
Alexandre Julliard77b99181997-09-14 17:17:23 +000057 * MSG_SendParentNotify
58 *
59 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
60 * the window has the WS_EX_NOPARENTNOTIFY style.
61 */
62static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
63{
Ulrich Weigande27670e2001-01-11 00:52:50 +000064 POINT pt;
Alexandre Julliard77b99181997-09-14 17:17:23 +000065
66 /* pt has to be in the client coordinates of the parent window */
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +000067 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
Alexandre Julliard77b99181997-09-14 17:17:23 +000068
Ulrich Weigande27670e2001-01-11 00:52:50 +000069 pt.x = SLOWORD(lValue);
70 pt.y = SHIWORD(lValue);
71 MapWindowPoints( 0, tmpWnd->hwndSelf, &pt, 1 );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +000072 while (tmpWnd)
Alexandre Julliard77b99181997-09-14 17:17:23 +000073 {
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +000074 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
Ulrich Weigande27670e2001-01-11 00:52:50 +000075 {
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +000076 WIN_ReleaseWndPtr(tmpWnd);
77 break;
78 }
Ulrich Weigande27670e2001-01-11 00:52:50 +000079 pt.x += tmpWnd->rectClient.left;
80 pt.y += tmpWnd->rectClient.top;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +000081 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
82 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
Ulrich Weigande27670e2001-01-11 00:52:50 +000083 MAKEWPARAM( event, idChild ),
84 MAKELONG( pt.x, pt.y ) );
Alexandre Julliard77b99181997-09-14 17:17:23 +000085 }
Alexandre Julliard77b99181997-09-14 17:17:23 +000086}
87
88
89/***********************************************************************
Alexandre Julliardcdd09231994-01-12 11:12:51 +000090 * MSG_TranslateMouseMsg
91 *
Andreas Mohr20cd9352000-09-12 23:40:40 +000092 * Translate a mouse hardware event into a real mouse message.
Noel Borthwickc90243b1999-05-14 08:09:13 +000093 *
94 * Returns:
95 *
96 * SYSQ_MSG_ABANDON - abandon the peek message loop
97 * SYSQ_MSG_CONTINUE - leave the message in the queue and
98 * continue with the translation loop
99 * SYSQ_MSG_ACCEPT - proceed to process the translated message
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000100 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000101static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
Noel Borthwickc90243b1999-05-14 08:09:13 +0000102 MSG *msg, BOOL remove, WND* pWndScope,
103 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000104{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000105 static DWORD dblclk_time_limit = 0;
106 static UINT16 clk_message = 0;
107 static HWND16 clk_hwnd = 0;
108 static POINT16 clk_pos = { 0, 0 };
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000109
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000110 WND *pWnd;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000111 HWND hWnd;
Noel Borthwickc90243b1999-05-14 08:09:13 +0000112 INT16 ht, hittest;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000113 UINT message = msg->message;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000114 POINT16 screen_pt, pt;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000115 HANDLE16 hQ = GetFastQueue16();
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000116 MESSAGEQUEUE *queue = QUEUE_Lock(hQ);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000117 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000118 (message == WM_RBUTTONDOWN) ||
119 (message == WM_MBUTTONDOWN))?1:0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000120 DWORD retvalue;
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000121
Noel Borthwickc90243b1999-05-14 08:09:13 +0000122 /* Find the window to dispatch this mouse message to */
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000123
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000124 CONV_POINT32TO16( &msg->pt, &pt );
125
Alexandre Julliarda3960291999-02-26 11:11:13 +0000126 hWnd = GetCapture();
Noel Borthwickc90243b1999-05-14 08:09:13 +0000127
128 /* If no capture HWND, find window which contains the mouse position.
129 * Also find the position of the cursor hot spot (hittest) */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000130 if( !hWnd )
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000131 {
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000132 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000133 if( !pWnd ) pWnd = WIN_GetDesktop();
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000134 else WIN_LockWndPtr(pWnd);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000135 hWnd = pWnd->hwndSelf;
136 }
137 else
138 {
Noel Borthwickc90243b1999-05-14 08:09:13 +0000139 ht = hittest = HTCLIENT;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000140 pWnd = WIN_FindWndPtr(hWnd);
Noel Borthwickb4278561999-02-05 10:37:53 +0000141 if (queue)
142 ht = PERQDATA_GetCaptureInfo( queue->pQData );
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000143 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000144
Noel Borthwickc90243b1999-05-14 08:09:13 +0000145 /* Save hittest for return */
146 *pHitTest = hittest;
147
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000148 /* stop if not the right queue */
149
150 if (pWnd->hmemTaskQ != hQ)
Alexandre Julliard8b915631996-06-16 16:16:05 +0000151 {
152 /* Not for the current task */
Alexandre Julliard8b915631996-06-16 16:16:05 +0000153 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
154 /* Wake up the other task */
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000155 QUEUE_Unlock( queue );
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000156 queue = QUEUE_Lock( pWnd->hmemTaskQ );
Alexandre Julliard8b915631996-06-16 16:16:05 +0000157 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000158
159 QUEUE_Unlock( queue );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000160 retvalue = SYSQ_MSG_ABANDON;
161 goto END;
Alexandre Julliard8b915631996-06-16 16:16:05 +0000162 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000163
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000164 /* check if hWnd is within hWndScope */
165
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000166 if( hTopWnd && hWnd != hTopWnd )
Alexandre Julliarda3960291999-02-26 11:11:13 +0000167 if( !IsChild(hTopWnd, hWnd) )
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000168 {
169 QUEUE_Unlock( queue );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000170 retvalue = SYSQ_MSG_CONTINUE;
171 goto END;
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000172 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000173
Noel Borthwickc90243b1999-05-14 08:09:13 +0000174 /* Was it a mouse click message */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000175 if( mouseClick )
Alexandre Julliarddba420a1994-02-02 06:48:31 +0000176 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000177 /* translate double clicks -
178 * note that ...MOUSEMOVEs can slip in between
179 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
Alexandre Julliard329f0681996-04-14 13:21:20 +0000180
Patrik Stridvall4bf33541999-06-12 14:52:15 +0000181 if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000182 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000183 if ((message == clk_message) && (hWnd == clk_hwnd) &&
184 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
Marcus Meissnerddca3151999-05-22 11:33:23 +0000185 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
186 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000187 {
188 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
189 mouseClick++; /* == 2 */
190 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +0000191 }
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000192 }
Noel Borthwickc90243b1999-05-14 08:09:13 +0000193 /* save mouse position */
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000194 screen_pt = pt;
Noel Borthwickc90243b1999-05-14 08:09:13 +0000195 *pScreen_pt = pt;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000196
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000197 if (hittest != HTCLIENT)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000198 {
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000199 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
Alexandre Julliarde2991ea1995-07-29 13:09:43 +0000200 msg->wParam = hittest;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000201 }
Noel Borthwickc90243b1999-05-14 08:09:13 +0000202 else
203 ScreenToClient16( hWnd, &pt );
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000204
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000205 /* check message filter */
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000206
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000207 if (!MSG_CheckFilter(message, first, last))
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000208 {
209 QUEUE_Unlock(queue);
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000210 retvalue = SYSQ_MSG_CONTINUE;
211 goto END;
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000212 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000213
Noel Borthwickc90243b1999-05-14 08:09:13 +0000214 /* Update global hCursorQueue */
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000215 hCursorQueue = queue->self;
Noel Borthwickc90243b1999-05-14 08:09:13 +0000216
217 /* Update static double click conditions */
218 if( remove && mouseClick )
219 {
220 if( mouseClick == 1 )
221 {
222 /* set conditions */
223 dblclk_time_limit = msg->time;
224 clk_message = msg->message;
225 clk_hwnd = hWnd;
226 clk_pos = screen_pt;
227 } else
228 /* got double click - zero them out */
229 dblclk_time_limit = clk_hwnd = 0;
230 }
231
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000232 QUEUE_Unlock(queue);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000233
Noel Borthwickc90243b1999-05-14 08:09:13 +0000234 /* Update message params */
235 msg->hwnd = hWnd;
236 msg->message = message;
237 msg->lParam = MAKELONG( pt.x, pt.y );
238 retvalue = SYSQ_MSG_ACCEPT;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000239
Noel Borthwickc90243b1999-05-14 08:09:13 +0000240END:
241 WIN_ReleaseWndPtr(pWnd);
242
243 /* Return mouseclick flag */
244 *pmouseClick = mouseClick;
245
246 return retvalue;
247}
248
249
250/***********************************************************************
251 * MSG_ProcessMouseMsg
252 *
253 * Processes a translated mouse hardware event.
254 * The passed in msg structure should contain the updated hWnd,
255 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
256 *
257 * Returns:
258 *
259 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
260 * HIWORD contains hit test code). Continue translating..
261 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
262 * MSG_PeekHardwareMsg should return TRUE.
263 */
264static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
265 POINT16 screen_pt, BOOL mouseClick )
266{
267 WND *pWnd;
268 HWND hWnd = msg->hwnd;
269 INT16 sendSC = (GetCapture() == 0);
270 UINT message = msg->message;
271 BOOL eatMsg = FALSE;
272 DWORD retvalue;
273
274 pWnd = WIN_FindWndPtr(hWnd);
275
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000276 /* call WH_MOUSE */
277
278 if (HOOK_IsHooked( WH_MOUSE ))
279 {
Noel Borthwickc90243b1999-05-14 08:09:13 +0000280 SYSQ_STATUS ret = 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000281 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
282 if( hook )
283 {
284 hook->pt = screen_pt;
285 hook->hwnd = hWnd;
286 hook->wHitTestCode = hittest;
287 hook->dwExtraInfo = 0;
288 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
289 message, (LPARAM)SEGPTR_GET(hook) );
290 SEGPTR_FREE(hook);
291 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000292 if( ret )
293 {
294 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
295 goto END;
Alexandre Julliard557d8af2000-05-23 23:43:02 +0000296 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000297 }
298
Alexandre Julliard557d8af2000-05-23 23:43:02 +0000299 if (message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST)
300 message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000301
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000302 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
303 eatMsg = sendSC = 1;
304 else if( remove && mouseClick )
305 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000306 HWND hwndTop = WIN_GetTopParent( hWnd );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000307
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000308 if( sendSC )
309 {
310 /* Send the WM_PARENTNOTIFY,
311 * note that even for double/nonclient clicks
312 * notification message is still WM_L/M/RBUTTONDOWN.
313 */
314
Alexandre Julliard557d8af2000-05-23 23:43:02 +0000315 MSG_SendParentNotify( pWnd, message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000316
317 /* Activate the window if needed */
318
Gerard Patel03c13bb1999-07-11 13:52:13 +0000319 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000320 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000321 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000322 MAKELONG( hittest, message ) );
323
324 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
325 eatMsg = TRUE;
326
Gerard Patel03c13bb1999-07-11 13:52:13 +0000327 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
328 && hwndTop != GetForegroundWindow() )
Per Ångström53c20281999-07-04 12:46:37 +0000329 {
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000330 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
331 eatMsg = TRUE;
Per Ångström53c20281999-07-04 12:46:37 +0000332 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000333 }
334 }
335 } else sendSC = (remove && sendSC);
336
337 /* Send the WM_SETCURSOR message */
338
339 if (sendSC)
Abey George9849f161999-07-27 17:06:55 +0000340 {
Abey George9849f161999-07-27 17:06:55 +0000341 /* Windows sends the normal mouse message as the message parameter
342 in the WM_SETCURSOR message even if it's non-client mouse message */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000343 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
Alexandre Julliard557d8af2000-05-23 23:43:02 +0000344 MAKELONG( hittest, message ));
Abey George9849f161999-07-27 17:06:55 +0000345 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000346 if (eatMsg)
347 {
348 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
349 goto END;
350 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000351
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000352 retvalue = SYSQ_MSG_ACCEPT;
353END:
354 WIN_ReleaseWndPtr(pWnd);
355
356 return retvalue;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000357}
358
359
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000360/***********************************************************************
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000361 * MSG_TranslateKbdMsg
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000362 *
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000363 * Translate a keyboard hardware event into a real message.
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000364 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000365static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
366 MSG *msg, BOOL remove )
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000367{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000368 WORD message = msg->message;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000369 HWND hWnd = GetFocus();
Alexandre Julliard8b915631996-06-16 16:16:05 +0000370 WND *pWnd;
371
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000372 /* Should check Ctrl-Esc and PrintScreen here */
373
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000374 if (!hWnd)
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000375 {
376 /* Send the message to the active window instead, */
377 /* translating messages to their WM_SYS equivalent */
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000378
Alexandre Julliarda3960291999-02-26 11:11:13 +0000379 hWnd = GetActiveWindow();
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000380
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000381 if( message < WM_SYSKEYDOWN )
382 message += WM_SYSKEYDOWN - WM_KEYDOWN;
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000383 }
Peter Ganten553e3c92000-08-14 20:53:00 +0000384 if ( !hWnd ) return SYSQ_MSG_ABANDON;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000385 pWnd = WIN_FindWndPtr( hWnd );
Peter Ganten553e3c92000-08-14 20:53:00 +0000386
Alexandre Julliarda3960291999-02-26 11:11:13 +0000387 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
Alexandre Julliard8b915631996-06-16 16:16:05 +0000388 {
389 /* Not for the current task */
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000390 MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() );
Alexandre Julliard8b915631996-06-16 16:16:05 +0000391 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000392 QUEUE_Unlock( queue );
393
Alexandre Julliard8b915631996-06-16 16:16:05 +0000394 /* Wake up the other task */
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000395 queue = QUEUE_Lock( pWnd->hmemTaskQ );
Alexandre Julliard8b915631996-06-16 16:16:05 +0000396 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000397 QUEUE_Unlock( queue );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000398 WIN_ReleaseWndPtr(pWnd);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000399 return SYSQ_MSG_ABANDON;
Alexandre Julliard8b915631996-06-16 16:16:05 +0000400 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000401 WIN_ReleaseWndPtr(pWnd);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000402
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000403 if (hTopWnd && hWnd != hTopWnd)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000404 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000405 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000406
407 msg->hwnd = hWnd;
408 msg->message = message;
409
Noel Borthwickc90243b1999-05-14 08:09:13 +0000410 return SYSQ_MSG_ACCEPT;
411}
412
413
414/***********************************************************************
415 * MSG_ProcessKbdMsg
416 *
417 * Processes a translated keyboard message
418 */
419static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
420{
Ulrich Czekalla33026a22000-02-26 19:13:44 +0000421 /* Handle F1 key by sending out WM_HELP message */
422 if ((msg->message == WM_KEYUP) &&
423 (msg->wParam == VK_F1) &&
Ulrich Czekalla2b569f62000-04-11 19:37:20 +0000424 remove &&
Ulrich Czekalla33026a22000-02-26 19:13:44 +0000425 (msg->hwnd != GetDesktopWindow()) &&
426 !MENU_IsMenuActive())
427 {
428 HELPINFO hi;
429 WND *pWnd = WIN_FindWndPtr(msg->hwnd);
430
431 if (NULL != pWnd)
432 {
433 hi.cbSize = sizeof(HELPINFO);
434 hi.iContextType = HELPINFO_WINDOW;
435 hi.iCtrlId = pWnd->wIDmenu;
436 hi.hItemHandle = msg->hwnd;
437 hi.dwContextId = pWnd->helpContext;
438 hi.MousePos = msg->pt;
439 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
440 }
441 WIN_ReleaseWndPtr(pWnd);
442 }
443
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000444 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000445 LOWORD (msg->wParam), msg->lParam )
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000446 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000447}
448
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000449
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000450/***********************************************************************
451 * MSG_JournalRecordMsg
452 *
453 * Build an EVENTMSG structure and call JOURNALRECORD hook
454 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000455static void MSG_JournalRecordMsg( MSG *msg )
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000456{
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000457 EVENTMSG event;
458
459 event.message = msg->message;
460 event.time = msg->time;
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000461 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
462 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000463 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
464 event.paramH = msg->lParam & 0x7FFF;
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000465 if (HIWORD(msg->lParam) & 0x0100)
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000466 event.paramH |= 0x8000; /* special_key - bit */
467 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000468 }
469 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
470 {
Ulrich Weigande27670e2001-01-11 00:52:50 +0000471 POINT pt;
472 pt.x = SLOWORD(msg->lParam);
473 pt.y = SHIWORD(msg->lParam);
474 ClientToScreen( msg->hwnd, &pt );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000475 event.paramL = pt.x;
476 event.paramH = pt.y;
477 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000478 }
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000479 else if ((msg->message >= WM_NCMOUSEFIRST) &&
480 (msg->message <= WM_NCMOUSELAST))
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000481 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000482 event.paramL = LOWORD(msg->lParam); /* X pos */
483 event.paramH = HIWORD(msg->lParam); /* Y pos */
484 event.message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
485 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000486 }
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000487}
488
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000489/***********************************************************************
490 * MSG_JournalPlayBackMsg
491 *
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000492 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000493 */
494static int MSG_JournalPlayBackMsg(void)
495{
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000496 EVENTMSG tmpMsg;
497 LPARAM lParam;
498 WPARAM wParam;
499 LRESULT wtime;
500 int keyDown,i;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000501
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000502 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return 0;
503
504 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
505 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
506 if (wtime<=0)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000507 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000508 wtime=0;
509 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
510 {
511 wParam=tmpMsg.paramL & 0xFF;
512 lParam=MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
513 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
514 {
515 for (keyDown=i=0; i<256 && !keyDown; i++)
516 if (InputKeyStateTable[i] & 0x80)
517 keyDown++;
518 if (!keyDown)
519 lParam |= 0x40000000;
520 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
521 }
522 else /* WM_KEYUP, WM_SYSKEYUP */
523 {
524 lParam |= 0xC0000000;
525 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
526 }
527 if (InputKeyStateTable[VK_MENU] & 0x80)
528 lParam |= 0x20000000;
529 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
530 lParam |= 0x01000000;
531 hardware_event( tmpMsg.message, wParam, lParam, 0, 0, tmpMsg.time, 0 );
532 }
533 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
534 {
535 switch (tmpMsg.message)
536 {
537 case WM_LBUTTONDOWN:
538 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
539 case WM_LBUTTONUP:
540 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
541 case WM_MBUTTONDOWN:
542 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
543 case WM_MBUTTONUP:
544 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
545 case WM_RBUTTONDOWN:
546 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
547 case WM_RBUTTONUP:
548 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
549 }
550 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
551 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
552 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
553 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
554 lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
555 wParam=0;
556 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
557 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
558 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
559 hardware_event( tmpMsg.message, wParam, lParam,
560 tmpMsg.paramL, tmpMsg.paramH, tmpMsg.time, 0 );
561 }
562 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
563 return 0;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000564 }
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000565 else
566 {
567 if( tmpMsg.message == WM_QUEUESYNC )
568 if (HOOK_IsHooked( WH_CBT ))
569 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000570
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000571 return QS_MOUSE | QS_KEY; /* ? */
572 }
573}
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000574
Alexandre Julliardaca05781994-10-17 18:12:41 +0000575/***********************************************************************
576 * MSG_PeekHardwareMsg
577 *
578 * Peek for a hardware message matching the hwnd and message filters.
579 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000580static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
581 BOOL remove )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000582{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000583 DWORD status = SYSQ_MSG_ACCEPT;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000584 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
Noel Borthwickc90243b1999-05-14 08:09:13 +0000585 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
Stephane Lussier12423111999-02-13 08:54:21 +0000586 QMSG *nextqmsg, *qmsg = 0;
Noel Borthwickc90243b1999-05-14 08:09:13 +0000587 BOOL bRet = FALSE;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000588
Stephane Lussier12423111999-02-13 08:54:21 +0000589 EnterCriticalSection(&sysMsgQueue->cSection);
590
Noel Borthwickc90243b1999-05-14 08:09:13 +0000591 /* Loop through the Q and translate the message we wish to process
592 * while we own the lock. Based on the translation status (abandon/cont/accept)
593 * we then process the message accordingly
594 */
595
596 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000597 {
Noel Borthwickc90243b1999-05-14 08:09:13 +0000598 INT16 hittest;
599 POINT16 screen_pt;
600 BOOL mouseClick;
Stephane Lussiera4c84451999-01-26 09:30:05 +0000601
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000602 *msg = qmsg->msg;
Stephane Lussiera4c84451999-01-26 09:30:05 +0000603
604 nextqmsg = qmsg->nextMsg;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000605
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000606 /* Translate message */
Alexandre Julliardaca05781994-10-17 18:12:41 +0000607
608 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
609 {
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000610 HWND hWndScope = (HWND)qmsg->extraInfo;
611 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
612 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
613
Noel Borthwickc90243b1999-05-14 08:09:13 +0000614 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
615 &hittest, &screen_pt, &mouseClick );
616 msgType = MOUSE_MSG;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000617
618 WIN_ReleaseWndPtr(tmpWnd);
619
Alexandre Julliardaca05781994-10-17 18:12:41 +0000620 }
621 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
622 {
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000623 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
Noel Borthwickc90243b1999-05-14 08:09:13 +0000624 msgType = KEYBOARD_MSG;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000625 }
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000626 else /* Non-standard hardware event */
Alexandre Julliardade697e1995-11-26 13:59:11 +0000627 {
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000628 HARDWAREHOOKSTRUCT16 *hook;
Noel Borthwickc90243b1999-05-14 08:09:13 +0000629 msgType = HARDWARE_MSG;
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000630 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
631 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000632 BOOL ret;
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000633 hook->hWnd = msg->hwnd;
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000634 hook->wMessage = msg->message & 0xffff;
635 hook->wParam = LOWORD (msg->wParam);
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000636 hook->lParam = msg->lParam;
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +0000637 ret = HOOK_CallHooks16( WH_HARDWARE,
638 remove ? HC_ACTION : HC_NOREMOVE,
639 0, (LPARAM)SEGPTR_GET(hook) );
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000640 SEGPTR_FREE(hook);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000641 if (ret)
642 {
Stephane Lussiera4c84451999-01-26 09:30:05 +0000643 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000644 continue;
645 }
646 status = SYSQ_MSG_ACCEPT;
Alexandre Julliard1e37a181996-08-18 16:21:52 +0000647 }
Alexandre Julliardade697e1995-11-26 13:59:11 +0000648 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000649
Noel Borthwickc90243b1999-05-14 08:09:13 +0000650
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000651 switch (LOWORD(status))
652 {
653 case SYSQ_MSG_ACCEPT:
Noel Borthwickc90243b1999-05-14 08:09:13 +0000654 {
655 /* Remove the message from the system msg Q while it is still locked,
656 * before accepting it */
657 if (remove)
658 {
659 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
660 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
661 }
662 /* Now actually process the message, after we unlock the system msg Q.
663 * We should not hold on to the crst since SendMessage calls during processing
664 * will potentially cause callbacks to PeekMessage from the application.
665 * If we're holding the crst and QUEUE_WaitBits is called with a
666 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
667 * message is being posted to the Q.
668 */
669 LeaveCriticalSection(&sysMsgQueue->cSection);
670 if( msgType == KEYBOARD_MSG )
671 status = MSG_ProcessKbdMsg( msg, remove );
672 else if ( msgType == MOUSE_MSG )
673 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
674
675 /* Reclaim the sys msg Q crst */
676 EnterCriticalSection(&sysMsgQueue->cSection);
677
678 /* Pass the translated message to the user if it was accepted */
679 if (status == SYSQ_MSG_ACCEPT)
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000680 break;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000681
Noel Borthwickc90243b1999-05-14 08:09:13 +0000682 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
683 }
684
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000685 case SYSQ_MSG_SKIP:
686 if (HOOK_IsHooked( WH_CBT ))
Jesper Skov5c3e4571998-11-01 19:27:22 +0000687 {
Noel Borthwickc90243b1999-05-14 08:09:13 +0000688 if( msgType == KEYBOARD_MSG )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000689 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000690 LOWORD (msg->wParam), msg->lParam );
Noel Borthwickc90243b1999-05-14 08:09:13 +0000691 else if ( msgType == MOUSE_MSG )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000692 {
693 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
694 if (hook)
695 {
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000696 CONV_POINT32TO16( &msg->pt,&hook->pt );
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000697 hook->hwnd = msg->hwnd;
698 hook->wHitTestCode = HIWORD(status);
699 hook->dwExtraInfo = 0;
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000700 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000701 (LPARAM)SEGPTR_GET(hook) );
702 SEGPTR_FREE(hook);
703 }
704 }
Jesper Skov5c3e4571998-11-01 19:27:22 +0000705 }
Alexandre Julliardaca05781994-10-17 18:12:41 +0000706
Noel Borthwickc90243b1999-05-14 08:09:13 +0000707 /* If the message was removed earlier set up nextqmsg so that we start
708 * at the top of the queue again. We need to do this since our next pointer
709 * could be invalid due to us unlocking the system message Q to process the message.
710 * If not removed just refresh nextqmsg to point to the next msg.
711 */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000712 if (remove)
Noel Borthwickc90243b1999-05-14 08:09:13 +0000713 nextqmsg = sysMsgQueue->firstMsg;
714 else
715 nextqmsg = qmsg->nextMsg;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000716
Noel Borthwickc90243b1999-05-14 08:09:13 +0000717 continue;
718
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000719 case SYSQ_MSG_CONTINUE:
720 continue;
721
722 case SYSQ_MSG_ABANDON:
Noel Borthwickc90243b1999-05-14 08:09:13 +0000723 bRet = FALSE;
724 goto END;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000725 }
726
Noel Borthwickc90243b1999-05-14 08:09:13 +0000727 bRet = TRUE;
728 goto END;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000729 }
Noel Borthwickc90243b1999-05-14 08:09:13 +0000730
731END:
Stephane Lussier12423111999-02-13 08:54:21 +0000732 LeaveCriticalSection(&sysMsgQueue->cSection);
Noel Borthwickc90243b1999-05-14 08:09:13 +0000733 return bRet;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000734}
735
736
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000737/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000738 * SetDoubleClickTime (USER.20)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000739 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000740void WINAPI SetDoubleClickTime16( UINT16 interval )
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000741{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000742 SetDoubleClickTime( interval );
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000743}
744
745
746/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000747 * SetDoubleClickTime (USER32.@)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000748 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000749BOOL WINAPI SetDoubleClickTime( UINT interval )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000750{
751 doubleClickSpeed = interval ? interval : 500;
752 return TRUE;
753}
754
755
756/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000757 * GetDoubleClickTime (USER.21)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000758 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000759UINT16 WINAPI GetDoubleClickTime16(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000760{
761 return doubleClickSpeed;
762}
763
764
765/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000766 * GetDoubleClickTime (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000767 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000768UINT WINAPI GetDoubleClickTime(void)
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000769{
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000770 return doubleClickSpeed;
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000771}
772
773
774/***********************************************************************
Stephane Lussierbae55521999-03-10 16:21:12 +0000775 * MSG_SendMessageInterThread
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000776 *
Alexandre Julliardef702d81996-05-28 18:54:58 +0000777 * Implementation of an inter-task SendMessage.
Stephane Lussierbae55521999-03-10 16:21:12 +0000778 * Return values:
779 * 0 if error or timeout
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000780 * 1 if successful
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000781 */
Stephane Lussierbae55521999-03-10 16:21:12 +0000782static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
783 HWND hwnd, UINT msg,
784 WPARAM wParam, LPARAM lParam,
785 DWORD timeout, WORD flags,
786 LRESULT *pRes)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000787{
Alexandre Julliardef702d81996-05-28 18:54:58 +0000788 MESSAGEQUEUE *queue, *destQ;
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000789 SMSG *smsg;
Stephane Lussierbae55521999-03-10 16:21:12 +0000790 LRESULT retVal = 1;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000791 int iWndsLocks;
Stephane Lussierbae55521999-03-10 16:21:12 +0000792
Ove Kaaven98111292000-11-25 01:23:50 +0000793 if (pRes) *pRes = 0;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000794
Alexandre Julliarda3960291999-02-26 11:11:13 +0000795 if (IsTaskLocked16() || !IsWindow(hwnd))
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000796 return 0;
Alexandre Julliardef702d81996-05-28 18:54:58 +0000797
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000798 /* create a SMSG structure to hold SendMessage() parameters */
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000799 if (! (smsg = (SMSG *) HeapAlloc( GetProcessHeap(), 0, sizeof(SMSG) )) )
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000800 return 0;
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000801 if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000802
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000803 if (!(destQ = QUEUE_Lock( hDestQueue )))
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000804 {
805 QUEUE_Unlock( queue );
806 return 0;
807 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000808
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000809 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000810 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000811
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000812 /* fill up SMSG structure */
813 smsg->hWnd = hwnd;
814 smsg->msg = msg;
815 smsg->wParam = wParam;
816 smsg->lParam = lParam;
817
818 smsg->lResult = 0;
Ove Kaaven98111292000-11-25 01:23:50 +0000819 smsg->hSrcQueue = pRes ? GetFastQueue16() : 0;
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000820 smsg->hDstQueue = hDestQueue;
821 smsg->flags = flags;
Alexandre Julliardef702d81996-05-28 18:54:58 +0000822
Ove Kaaven98111292000-11-25 01:23:50 +0000823 if (pRes) {
824 /* add smsg struct in the processing SM list of the source queue */
825 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
826 } else {
827 /* this is a notification message, we don't need a reply */
828 smsg->flags |= SMSG_ALREADY_REPLIED | SMSG_RECEIVER_CLEANS;
829 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000830
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000831 /* add smsg struct in the pending list of the destination queue */
832 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
Andreas Mohr5e7fa022000-08-29 03:52:46 +0000833 {
834 retVal = 0;
835 goto CLEANUP;
836 }
Alexandre Julliardef702d81996-05-28 18:54:58 +0000837
Ove Kaaven98111292000-11-25 01:23:50 +0000838 if (!pRes) goto CLEANUP; /* don't need a reply */
839
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000840 iWndsLocks = WIN_SuspendWndsLock();
841
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000842 /* force destination task to run next, if 16 bit threads */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000843 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
844 DirectedYield16( destQ->teb->htask16 );
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000845
Alex Korobka073e3bc1999-03-28 09:19:31 +0000846 /* wait for the result, note that 16-bit apps almost always get out of
847 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
848
849 while ( TRUE )
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000850 {
851 /*
852 * The sequence is crucial to avoid deadlock situations:
853 * - first, we clear the QS_SMRESULT bit
854 * - then, we check the SMSG_HAVE_RESULT bit
855 * - only if this isn't set, we enter the wait state.
856 *
857 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
858 * we are guaranteed that -should we now clear the QS_SMRESULT that
859 * was signalled already by the receiver- we will not start waiting.
860 */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000861
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000862 if ( smsg->flags & SMSG_HAVE_RESULT )
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000863 {
Alex Korobka073e3bc1999-03-28 09:19:31 +0000864got:
865 *pRes = smsg->lResult;
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000866 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
Alex Korobka073e3bc1999-03-28 09:19:31 +0000867 break;
868 }
869
870 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
871
872 if ( smsg->flags & SMSG_HAVE_RESULT )
873 goto got;
874
875 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
876 {
877 /* return with timeout */
878 SetLastError( 0 );
879 retVal = 0;
880 break;
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000881 }
Stephane Lussier110cdb11999-02-24 09:43:09 +0000882 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000883 WIN_RestoreWndsLock(iWndsLocks);
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000884
Andreas Mohr260f1a12000-09-22 20:59:29 +0000885 /* remove the smsg from the processing list of the source queue */
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000886 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
887
888 /* Note: the destination thread is in charge of removing the smsg from
889 the pending list */
890
Stephane Lussierbae55521999-03-10 16:21:12 +0000891 /* In the case of an early reply (or a timeout), sender thread will
892 released the smsg structure if the receiver thread is done
893 (SMSG_RECEIVED set). If the receiver thread isn't done,
894 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
Andreas Mohr260f1a12000-09-22 20:59:29 +0000895 responsibility to release smsg */
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000896 EnterCriticalSection( &queue->cSection );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000897
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000898 if (smsg->flags & SMSG_RECEIVED)
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000899 HeapFree(GetProcessHeap(), 0, smsg);
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000900 else
901 smsg->flags |= SMSG_RECEIVER_CLEANS;
902
903 LeaveCriticalSection( &queue->cSection );
Stephane Lussierbae55521999-03-10 16:21:12 +0000904
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000905
Andreas Mohr5e7fa022000-08-29 03:52:46 +0000906CLEANUP:
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000907 QUEUE_Unlock( queue );
908 QUEUE_Unlock( destQ );
909
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000910 TRACE_(sendmsg)("done!\n");
Stephane Lussierbae55521999-03-10 16:21:12 +0000911 return retVal;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000912}
913
914
915/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000916 * ReplyMessage (USER.115)
Alexandre Julliardaca05781994-10-17 18:12:41 +0000917 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000918void WINAPI ReplyMessage16( LRESULT result )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000919{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000920 ReplyMessage( result );
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000921}
Alexandre Julliardaca05781994-10-17 18:12:41 +0000922
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000923/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000924 * ReplyMessage (USER32.@)
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000925 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000926BOOL WINAPI ReplyMessage( LRESULT result )
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000927{
928 MESSAGEQUEUE *senderQ = 0;
929 MESSAGEQUEUE *queue = 0;
930 SMSG *smsg;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000931 BOOL ret = FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000932
Ulrich Weigand52e891d2001-01-29 00:33:35 +0000933 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000934 return FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000935
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000936 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000937
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000938
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000939 if ( !(smsg = queue->smWaiting)
Ove Kaaven98111292000-11-25 01:23:50 +0000940 || !( (senderQ = QUEUE_Lock( smsg->hSrcQueue ))
941 || (smsg->flags & SMSG_ALREADY_REPLIED)) )
Stephane Lussierbae55521999-03-10 16:21:12 +0000942 goto ReplyMessageEnd;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000943
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000944 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
945 {
946 /* This is the first reply, so pass result to sender */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000947
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000948 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000949
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000950 EnterCriticalSection(&senderQ->cSection);
951
952 smsg->lResult = result;
953 smsg->flags |= SMSG_ALREADY_REPLIED;
Francis Beaudetbfaf0631999-02-28 10:02:57 +0000954
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000955 /* check if it's an early reply (called by the application) or
956 a regular reply (called by ReceiveMessage) */
957 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
958 smsg->flags |= SMSG_EARLY_REPLY;
Francis Beaudetbfaf0631999-02-28 10:02:57 +0000959
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000960 smsg->flags |= SMSG_HAVE_RESULT;
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000961
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000962 LeaveCriticalSection(&senderQ->cSection);
Francis Beaudetbfaf0631999-02-28 10:02:57 +0000963
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000964 /* tell the sending task that its reply is ready */
965 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000966
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000967 /* switch directly to sending task (16 bit thread only) */
Alexandre Julliard0a860a01999-06-22 11:43:42 +0000968 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
969 DirectedYield16( senderQ->teb->htask16 );
Ulrich Weigandc68c4b11999-03-17 15:14:31 +0000970
971 ret = TRUE;
972 }
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000973
Stephane Lussierbae55521999-03-10 16:21:12 +0000974 if (smsg->flags & SMSG_SENDING_REPLY)
975 {
Andreas Mohr260f1a12000-09-22 20:59:29 +0000976 /* remove msg from the waiting list, since this is the last
Stephane Lussierbae55521999-03-10 16:21:12 +0000977 ReplyMessage */
978 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
979
Ove Kaavenbea05602000-11-25 21:39:36 +0000980 if (senderQ) EnterCriticalSection(&senderQ->cSection);
Stephane Lussierbae55521999-03-10 16:21:12 +0000981
982 /* tell the sender we're all done with smsg structure */
983 smsg->flags |= SMSG_RECEIVED;
984
985 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
Andreas Mohr260f1a12000-09-22 20:59:29 +0000986 receiver to clean up smsg, it could only happen when there is
Stephane Lussierbae55521999-03-10 16:21:12 +0000987 an early reply or a timeout */
988 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
989 {
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000990 TRACE_(sendmsg)("Receiver cleans up!\n" );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000991 HeapFree( GetProcessHeap(), 0, smsg );
Stephane Lussierbae55521999-03-10 16:21:12 +0000992 }
Ove Kaavenbea05602000-11-25 21:39:36 +0000993
994 if (senderQ) LeaveCriticalSection(&senderQ->cSection);
Stephane Lussierbae55521999-03-10 16:21:12 +0000995 }
996
997ReplyMessageEnd:
Stephane Lussier2c86dab1999-02-18 17:34:09 +0000998 if ( senderQ )
Stephane Lussier1c4786f1999-01-28 10:54:11 +0000999 QUEUE_Unlock( senderQ );
Stephane Lussier2c86dab1999-02-18 17:34:09 +00001000 if ( queue )
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001001 QUEUE_Unlock( queue );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001002
Stephane Lussier2c86dab1999-02-18 17:34:09 +00001003 return ret;
1004}
Alexandre Julliardaca05781994-10-17 18:12:41 +00001005
1006/***********************************************************************
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001007 * MSG_ConvertMsg
1008 */
1009static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1010{
1011 UINT16 msg16;
1012 MSGPARAM16 mp16;
1013
1014 switch ( MAKELONG( srcType, dstType ) )
1015 {
1016 case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
1017 case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
1018 case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
1019 return TRUE;
1020
1021 case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
1022 switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
1023 &msg->message, &msg->wParam, &msg->lParam ) )
1024 {
1025 case 0:
1026 return TRUE;
1027 case 1:
1028 /* Pointer messages were mapped --> need to free allocated memory and fail */
1029 WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1030 default:
1031 return FALSE;
1032 }
1033
1034 case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
1035 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1036 &msg->message, &msg->wParam, &msg->lParam ) )
1037 {
1038 case 0:
1039 return TRUE;
1040 case 1:
1041 /* Pointer messages were mapped --> need to free allocated memory and fail */
1042 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1043 default:
1044 return FALSE;
1045 }
1046
1047 case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
1048 mp16.lParam = msg->lParam;
1049 switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
1050 &msg16, &mp16.wParam, &mp16.lParam ) )
1051 {
1052 case 0:
1053 msg->message = msg16;
1054 msg->wParam = mp16.wParam;
1055 msg->lParam = mp16.lParam;
1056 return TRUE;
1057 case 1:
1058 /* Pointer messages were mapped --> need to free allocated memory and fail */
1059 WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1060 default:
1061 return FALSE;
1062 }
1063
1064 case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
1065 mp16.lParam = msg->lParam;
1066 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1067 &msg16, &mp16.wParam, &mp16.lParam ) )
1068 {
1069 case 0:
1070 msg->message = msg16;
1071 msg->wParam = mp16.wParam;
1072 msg->lParam = mp16.lParam;
1073 return TRUE;
1074 case 1:
1075 /* Pointer messages were mapped --> need to free allocated memory and fail */
1076 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1077 default:
1078 return FALSE;
1079 }
1080
1081 case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
Dmitry Timoshkov3606dc52000-11-15 23:13:17 +00001082 switch ( WINPROC_MapMsg32ATo32W( msg->hwnd, msg->message, &msg->wParam, &msg->lParam ) )
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001083 {
1084 case 0:
1085 return TRUE;
1086 case 1:
1087 /* Pointer messages were mapped --> need to free allocated memory and fail */
1088 WINPROC_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1089 default:
1090 return FALSE;
1091 }
1092
1093 case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
Dmitry Timoshkov3606dc52000-11-15 23:13:17 +00001094 switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, &msg->wParam, &msg->lParam ) )
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001095 {
1096 case 0:
1097 return TRUE;
1098 case 1:
1099 /* Pointer messages were mapped --> need to free allocated memory and fail */
1100 WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1101 default:
1102 return FALSE;
1103 }
1104
1105 default:
1106 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1107 return FALSE;
1108 }
1109}
1110
1111/***********************************************************************
Alexandre Julliard401710d1993-09-04 10:09:32 +00001112 * MSG_PeekMessage
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001113 */
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001114static BOOL MSG_PeekMessage( int type, LPMSG msg_out, HWND hwnd,
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001115 DWORD first, DWORD last, WORD flags, BOOL peek )
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001116{
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001117 int changeBits, mask;
Alexandre Julliard594997c1995-04-30 10:05:20 +00001118 MESSAGEQUEUE *msgQueue;
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +00001119 HQUEUE16 hQueue;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001120 int iWndsLocks;
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001121 MSG msg;
Alexandre Julliard401710d1993-09-04 10:09:32 +00001122
Alexandre Julliardef702d81996-05-28 18:54:58 +00001123 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001124 if (first || last)
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001125 {
Alexandre Julliardac9c9b01996-07-28 18:50:11 +00001126 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1127 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1128 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1129 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1130 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1131 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001132 }
Alexandre Julliardef702d81996-05-28 18:54:58 +00001133 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1134
Alexandre Julliarda3960291999-02-26 11:11:13 +00001135 if (IsTaskLocked16()) flags |= PM_NOYIELD;
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001136
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00001137 /* Never yield on Win32 threads */
Alexandre Julliard0a860a01999-06-22 11:43:42 +00001138 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00001139
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001140 iWndsLocks = WIN_SuspendWndsLock();
1141
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001142 while(1)
1143 {
Stephane Lussiera4c84451999-01-26 09:30:05 +00001144 QMSG *qmsg;
1145
Alexandre Julliarda3960291999-02-26 11:11:13 +00001146 hQueue = GetFastQueue16();
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001147 msgQueue = QUEUE_Lock( hQueue );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001148 if (!msgQueue)
1149 {
1150 WIN_RestoreWndsLock(iWndsLocks);
1151 return FALSE;
1152 }
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001153
1154 EnterCriticalSection( &msgQueue->cSection );
Alexandre Julliardef702d81996-05-28 18:54:58 +00001155 msgQueue->changeBits = 0;
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001156 LeaveCriticalSection( &msgQueue->cSection );
Alexandre Julliard594997c1995-04-30 10:05:20 +00001157
Alexandre Julliardef702d81996-05-28 18:54:58 +00001158 /* First handle a message put by SendMessage() */
1159
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001160 while ( QUEUE_ReceiveMessage( msgQueue ) )
1161 ;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001162
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001163 /* Now handle a WM_QUIT message */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001164
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001165 EnterCriticalSection( &msgQueue->cSection );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001166 if (msgQueue->wPostQMsg &&
1167 (!first || WM_QUIT >= first) &&
1168 (!last || WM_QUIT <= last) )
1169 {
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001170 msg.hwnd = hwnd;
1171 msg.message = WM_QUIT;
1172 msg.wParam = msgQueue->wExitCode;
1173 msg.lParam = 0;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001174 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001175 LeaveCriticalSection( &msgQueue->cSection );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001176 break;
1177 }
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001178 LeaveCriticalSection( &msgQueue->cSection );
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001179
Alexandre Julliardef702d81996-05-28 18:54:58 +00001180 /* Now find a normal message */
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001181
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001182 retry:
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001183 if ((QUEUE_TestWakeBit(msgQueue, mask & QS_POSTMESSAGE)) &&
Stephane Lussiera4c84451999-01-26 09:30:05 +00001184 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
Alexandre Julliardef702d81996-05-28 18:54:58 +00001185 {
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001186 /* Try to convert message to requested type */
1187 MSG tmpMsg = qmsg->msg;
1188 if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
1189 {
Dmitry Timoshkov3606dc52000-11-15 23:13:17 +00001190 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
1191 SPY_GetMsgName(tmpMsg.message));
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001192 QUEUE_RemoveMsg( msgQueue, qmsg );
1193 goto retry;
1194 }
1195
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001196 msg = tmpMsg;
1197 msgQueue->GetMessageTimeVal = msg.time;
1198 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
Alexandre Julliardef702d81996-05-28 18:54:58 +00001199 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001200
Stephane Lussiera4c84451999-01-26 09:30:05 +00001201 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
Alexandre Julliardef702d81996-05-28 18:54:58 +00001202 break;
1203 }
1204
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001205 changeBits = MSG_JournalPlayBackMsg();
1206 EnterCriticalSection( &msgQueue->cSection );
1207 msgQueue->changeBits |= changeBits;
1208 LeaveCriticalSection( &msgQueue->cSection );
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001209
Alexandre Julliardef702d81996-05-28 18:54:58 +00001210 /* Now find a hardware event */
1211
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001212 if (MSG_PeekHardwareMsg( &msg, hwnd, first, last, flags & PM_REMOVE ))
Alexandre Julliardaca05781994-10-17 18:12:41 +00001213 {
1214 /* Got one */
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001215 msgQueue->GetMessageTimeVal = msg.time;
1216 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
Alexandre Julliardaca05781994-10-17 18:12:41 +00001217 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1218 break;
1219 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001220
Alexandre Julliardef702d81996-05-28 18:54:58 +00001221 /* Check again for SendMessage */
1222
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001223 while ( QUEUE_ReceiveMessage( msgQueue ) )
1224 ;
Alexandre Julliardef702d81996-05-28 18:54:58 +00001225
1226 /* Now find a WM_PAINT message */
1227
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001228 if (QUEUE_TestWakeBit(msgQueue, mask & QS_PAINT))
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001229 {
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001230 WND* wndPtr;
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001231 msg.hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1232 msg.message = WM_PAINT;
1233 msg.wParam = 0;
1234 msg.lParam = 0;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00001235
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001236 if ((wndPtr = WIN_FindWndPtr(msg.hwnd)))
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001237 {
1238 if( wndPtr->dwStyle & WS_MINIMIZE &&
Patrik Stridvall4bf33541999-06-12 14:52:15 +00001239 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001240 {
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001241 msg.message = WM_PAINTICON;
1242 msg.wParam = 1;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001243 }
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00001244
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001245 if( !hwnd || msg.hwnd == hwnd || IsChild16(hwnd,msg.hwnd) )
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001246 {
1247 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1248 {
1249 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1250 QUEUE_DecPaintCount( hQueue );
1251 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001252 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001253 break;
1254 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001255 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001256 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001257 }
1258
Alexandre Julliardef702d81996-05-28 18:54:58 +00001259 /* Check for timer messages, but yield first */
1260
1261 if (!(flags & PM_NOYIELD))
1262 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001263 UserYield16();
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001264 while ( QUEUE_ReceiveMessage( msgQueue ) )
1265 ;
Alexandre Julliardef702d81996-05-28 18:54:58 +00001266 }
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001267
1268 if (QUEUE_TestWakeBit(msgQueue, mask & QS_TIMER))
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001269 {
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001270 if (TIMER_GetTimerMsg(&msg, hwnd, hQueue, flags & PM_REMOVE)) break;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001271 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001272
Alexandre Julliardaca05781994-10-17 18:12:41 +00001273 if (peek)
1274 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001275 if (!(flags & PM_NOYIELD)) UserYield16();
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001276
1277 QUEUE_Unlock( msgQueue );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001278 WIN_RestoreWndsLock(iWndsLocks);
Alexandre Julliardef702d81996-05-28 18:54:58 +00001279 return FALSE;
Alexandre Julliardaca05781994-10-17 18:12:41 +00001280 }
Ulrich Weigand52e891d2001-01-29 00:33:35 +00001281
Stephane Lussierbae55521999-03-10 16:21:12 +00001282 QUEUE_WaitBits( mask, INFINITE );
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001283 QUEUE_Unlock( msgQueue );
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001284 }
1285
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001286 WIN_RestoreWndsLock(iWndsLocks);
1287
Stephane Lussier1c4786f1999-01-28 10:54:11 +00001288 /* instead of unlocking queue for every break condition, all break
1289 condition will fall here */
1290 QUEUE_Unlock( msgQueue );
1291
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001292 /* We got a message */
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001293 if (flags & PM_REMOVE)
1294 {
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001295 WORD message = msg.message;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001296
1297 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1298 {
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001299 BYTE *p = &QueueKeyStateTable[msg.wParam & 0xff];
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001300
1301 if (!(*p & 0x80))
1302 *p ^= 0x01;
1303 *p |= 0x80;
1304 }
1305 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001306 QueueKeyStateTable[msg.wParam & 0xff] &= ~0x80;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001307 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001308
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001309 /* copy back our internal safe copy of message data to msg_out.
1310 * msg_out is a variable from the *program*, so it can't be used
1311 * internally as it can get "corrupted" by our use of SendMessage()
1312 * (back to the program) inside the message handling itself. */
1313 *msg_out = msg;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001314 if (peek)
1315 return TRUE;
1316
1317 else
Andreas Mohrcd5f28b2001-02-12 19:15:06 +00001318 return (msg.message != WM_QUIT);
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001319}
1320
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001321/***********************************************************************
Alexandre Julliard58199531994-04-21 01:20:00 +00001322 * MSG_InternalGetMessage
1323 *
1324 * GetMessage() function for internal use. Behave like GetMessage(),
1325 * but also call message filters and optionally send WM_ENTERIDLE messages.
1326 * 'hwnd' must be the handle of the dialog or menu window.
1327 * 'code' is the message filter value (MSGF_??? codes).
1328 */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001329BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
1330 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
Alexandre Julliard58199531994-04-21 01:20:00 +00001331{
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001332 for (;;)
Alexandre Julliard58199531994-04-21 01:20:00 +00001333 {
1334 if (sendIdle)
1335 {
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001336 if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001337 {
1338 /* No message present -> send ENTERIDLE and wait */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001339 if (IsWindow(hwndOwner))
Francis Beaudet7ed1af31999-08-15 16:58:03 +00001340 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001341 SendMessageA( hwndOwner, WM_ENTERIDLE,
Alexandre Julliardef702d81996-05-28 18:54:58 +00001342 code, (LPARAM)hwnd );
Francis Beaudet7ed1af31999-08-15 16:58:03 +00001343
1344 if (idleSent!=NULL)
1345 *idleSent=TRUE;
1346 }
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001347 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001348 }
Alexandre Julliard58199531994-04-21 01:20:00 +00001349 }
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001350 else /* Always wait for a message */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001351 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001352
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001353 /* Call message filters */
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001354
Alexandre Julliard7e6ae4b1996-12-08 19:25:27 +00001355 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001356 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +00001357 MSG *pmsg = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001358 if (pmsg)
1359 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001360 BOOL ret;
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001361 *pmsg = *msg;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001362 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001363 (LPARAM) pmsg ) ||
Alexandre Julliarda3960291999-02-26 11:11:13 +00001364 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001365 (LPARAM) pmsg ));
1366
Alexandre Julliardda2892c2001-02-23 01:13:42 +00001367 HeapFree( GetProcessHeap(), 0, pmsg );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001368 if (ret)
1369 {
1370 /* Message filtered -> remove it from the queue */
1371 /* if it's still there. */
1372 if (!(flags & PM_REMOVE))
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001373 MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
Alexandre Julliard1e37a181996-08-18 16:21:52 +00001374 continue;
1375 }
1376 }
1377 }
1378
1379 return (msg->message != WM_QUIT);
Alexandre Julliard3f2abfa1994-08-16 15:43:11 +00001380 }
Alexandre Julliard58199531994-04-21 01:20:00 +00001381}
1382
1383
1384/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001385 * PeekMessage32 (USER.819)
Alexandre Julliard401710d1993-09-04 10:09:32 +00001386 */
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001387BOOL16 WINAPI PeekMessage32_16( SEGPTR msg16_32, HWND16 hwnd,
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001388 UINT16 first, UINT16 last, UINT16 flags,
1389 BOOL16 wHaveParamHigh )
Alexandre Julliard401710d1993-09-04 10:09:32 +00001390{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001391 BOOL ret;
Alexandre Julliard982a2232000-12-13 20:20:09 +00001392 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001393 MSG msg;
1394
1395 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1396
1397 lpmsg16_32->msg.hwnd = msg.hwnd;
1398 lpmsg16_32->msg.message = msg.message;
1399 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1400 lpmsg16_32->msg.lParam = msg.lParam;
1401 lpmsg16_32->msg.time = msg.time;
1402 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1403 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1404
1405 if ( wHaveParamHigh )
1406 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1407
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001408 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg16_32 );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001409 return ret;
Alexandre Julliard401710d1993-09-04 10:09:32 +00001410}
1411
Alexandre Julliard829fe321998-07-26 14:27:39 +00001412/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001413 * PeekMessage (USER.109)
Andreas Mohr94e44851999-01-23 14:15:17 +00001414 */
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001415BOOL16 WINAPI PeekMessage16( SEGPTR msg, HWND16 hwnd,
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001416 UINT16 first, UINT16 last, UINT16 flags )
Andreas Mohr94e44851999-01-23 14:15:17 +00001417{
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001418 return PeekMessage32_16( msg, hwnd, first, last, flags, FALSE );
Andreas Mohr94e44851999-01-23 14:15:17 +00001419}
1420
Andreas Mohr94e44851999-01-23 14:15:17 +00001421/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001422 * PeekMessageA (USER32.@)
Alexandre Julliard829fe321998-07-26 14:27:39 +00001423 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001424BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001425 UINT min, UINT max, UINT wRemoveMsg)
Alexandre Julliard829fe321998-07-26 14:27:39 +00001426{
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001427 BOOL ret = MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1428
1429 TRACE( "peekmessage %04x, hwnd %04x, filter(%04x - %04x)\n",
1430 lpmsg->message, hwnd, min, max );
1431
1432 if (ret) HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION,
1433 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1434 return ret;
Alexandre Julliard829fe321998-07-26 14:27:39 +00001435}
1436
1437/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001438 * PeekMessageW (USER32.@) Check queue for messages
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001439 *
1440 * Checks for a message in the thread's queue, filtered as for
1441 * GetMessage(). Returns immediately whether a message is available
1442 * or not.
1443 *
1444 * Whether a retrieved message is removed from the queue is set by the
1445 * _wRemoveMsg_ flags, which should be one of the following values:
1446 *
1447 * PM_NOREMOVE Do not remove the message from the queue.
1448 *
1449 * PM_REMOVE Remove the message from the queue.
1450 *
1451 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1452 * request that the system not yield control during PeekMessage();
1453 * however applications may not rely on scheduling behavior.
1454 *
1455 * RETURNS
1456 *
1457 * Nonzero if a message is available and is retrieved, zero otherwise.
1458 *
1459 * CONFORMANCE
1460 *
1461 * ECMA-234, Win32
1462 *
Alexandre Julliard829fe321998-07-26 14:27:39 +00001463 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001464BOOL WINAPI PeekMessageW(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001465 LPMSG lpmsg, /* [out] buffer to receive message */
1466 HWND hwnd, /* [in] restrict to messages for hwnd */
1467 UINT min, /* [in] minimum message to receive */
1468 UINT max, /* [in] maximum message to receive */
1469 UINT wRemoveMsg /* [in] removal flags */
Juergen Schmied13f1b121999-05-02 09:17:48 +00001470)
1471{
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001472 BOOL ret = MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1473 if (ret) HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION,
1474 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1475 return ret;
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001476}
1477
1478
1479/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +00001480 * GetMessage32 (USER.820)
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001481 */
1482BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1483 UINT16 last, BOOL16 wHaveParamHigh )
1484{
Alexandre Julliard982a2232000-12-13 20:20:09 +00001485 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001486 MSG msg;
1487
1488 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1489
1490 lpmsg16_32->msg.hwnd = msg.hwnd;
1491 lpmsg16_32->msg.message = msg.message;
1492 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1493 lpmsg16_32->msg.lParam = msg.lParam;
1494 lpmsg16_32->msg.time = msg.time;
1495 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1496 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1497
1498 if ( wHaveParamHigh )
1499 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1500
1501 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1502 lpmsg16_32->msg.message, hWnd, first, last );
1503
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001504 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)msg16_32 );
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001505 return lpmsg16_32->msg.message != WM_QUIT;
Alexandre Julliard829fe321998-07-26 14:27:39 +00001506}
Alexandre Julliard401710d1993-09-04 10:09:32 +00001507
1508/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001509 * GetMessage (USER.108)
Alexandre Julliard401710d1993-09-04 10:09:32 +00001510 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001511BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
Alexandre Julliard401710d1993-09-04 10:09:32 +00001512{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001513 return GetMessage32_16( msg, hwnd, first, last, FALSE );
Alexandre Julliard401710d1993-09-04 10:09:32 +00001514}
1515
Alexandre Julliard829fe321998-07-26 14:27:39 +00001516/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001517 * GetMessageA (USER32.@)
Andreas Mohr94e44851999-01-23 14:15:17 +00001518 */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001519BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
Andreas Mohr94e44851999-01-23 14:15:17 +00001520{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001521 MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001522
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001523 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1524 lpmsg->message, hwnd, min, max );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001525
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001526 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001527 return lpmsg->message != WM_QUIT;
Alexandre Julliard829fe321998-07-26 14:27:39 +00001528}
1529
1530/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001531 * GetMessageW (USER32.@) Retrieve next message
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001532 *
1533 * GetMessage retrieves the next event from the calling thread's
1534 * queue and deposits it in *lpmsg.
1535 *
1536 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1537 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1538 * all application messages are retrieved.
1539 *
1540 * _min_ and _max_ specify the range of messages of interest. If
1541 * min==max==0, no filtering is performed. Useful examples are
1542 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1543 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1544 *
1545 * WM_PAINT messages are not removed from the queue; they remain until
1546 * processed. Other messages are removed from the queue.
1547 *
1548 * RETURNS
1549 *
1550 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1551 *
1552 * CONFORMANCE
1553 *
1554 * ECMA-234, Win32
1555 *
Alexandre Julliard829fe321998-07-26 14:27:39 +00001556 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001557BOOL WINAPI GetMessageW(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001558 MSG* lpmsg, /* [out] buffer to receive message */
1559 HWND hwnd, /* [in] restrict to messages for hwnd */
1560 UINT min, /* [in] minimum message to receive */
1561 UINT max /* [in] maximum message to receive */
Juergen Schmied13f1b121999-05-02 09:17:48 +00001562)
1563{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001564 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1565
1566 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1567 lpmsg->message, hwnd, min, max );
1568
Alexandre Julliard0ff083b2000-09-24 19:51:15 +00001569 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001570 return lpmsg->message != WM_QUIT;
Alexandre Julliard829fe321998-07-26 14:27:39 +00001571}
1572
Alexandre Julliard401710d1993-09-04 10:09:32 +00001573/***********************************************************************
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001574 * MSG_PostToQueue
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001575 */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001576static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
1577 UINT message, WPARAM wParam, LPARAM lParam )
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001578{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001579 MSG msg;
Stephane Lussierb3a99de1999-02-09 15:35:12 +00001580
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001581 if ( !hQueue ) return FALSE;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00001582
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00001583 msg.hwnd = hwnd;
1584 msg.message = message;
1585 msg.wParam = wParam;
1586 msg.lParam = lParam;
1587 msg.time = GetTickCount();
Sheri Steevesbd59d232000-06-15 00:09:04 +00001588 GetCursorPos(&msg.pt);
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00001589
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001590 return QUEUE_AddMsg( hQueue, type, &msg, 0 );
1591}
1592
1593/***********************************************************************
Marcus Meissner5bcef612001-02-13 01:48:39 +00001594 * MSG_IsPointerMessage
1595 *
1596 * Check whether this message (may) contain pointers.
1597 * Those messages may not be PostMessage()d or GetMessage()d, but are dropped.
1598 *
1599 * FIXME: list of pointer messages might be incomplete.
1600 *
1601 * (We could do a generic !IsBadWritePtr() check, but this would cause too
1602 * much slow down I think. MM20010206)
1603 */
1604static BOOL MSG_IsPointerMessage(UINT message, WPARAM wParam, LPARAM lParam) {
1605 switch (message) {
1606 case WM_CREATE:
1607 case WM_NCCREATE:
1608 case WM_COMPAREITEM:
1609 case WM_DELETEITEM:
1610 case WM_MEASUREITEM:
1611 case WM_DRAWITEM:
1612 case WM_GETMINMAXINFO:
1613 case WM_GETTEXT:
1614 case WM_SETTEXT:
1615 case WM_MDICREATE:
1616 case WM_MDIGETACTIVE:
1617 case WM_NCCALCSIZE:
1618 case WM_WINDOWPOSCHANGING:
1619 case WM_WINDOWPOSCHANGED:
1620 case WM_NOTIFY:
1621 case WM_GETDLGCODE:
1622 case WM_WININICHANGE:
1623 case WM_HELP:
1624 case WM_COPYDATA:
1625 case WM_STYLECHANGING:
1626 case WM_STYLECHANGED:
1627 case WM_DROPOBJECT:
1628 case WM_DRAGMOVE:
1629 case WM_DRAGSELECT:
1630 case WM_QUERYDROPOBJECT:
1631
1632 case CB_DIR:
1633 case CB_ADDSTRING:
1634 case CB_INSERTSTRING:
1635 case CB_FINDSTRING:
1636 case CB_FINDSTRINGEXACT:
1637 case CB_SELECTSTRING:
1638 case CB_GETLBTEXT:
1639 case CB_GETDROPPEDCONTROLRECT:
1640
1641 case LB_DIR:
1642 case LB_ADDFILE:
1643 case LB_ADDSTRING:
1644 case LB_INSERTSTRING:
1645 case LB_GETTEXT:
1646 case LB_GETITEMRECT:
1647 case LB_FINDSTRING:
1648 case LB_FINDSTRINGEXACT:
1649 case LB_SELECTSTRING:
1650 case LB_GETSELITEMS:
1651 case LB_SETTABSTOPS:
1652
1653 case EM_REPLACESEL:
1654 case EM_GETSEL:
1655 case EM_GETRECT:
1656 case EM_SETRECT:
1657 case EM_SETRECTNP:
1658 case EM_GETLINE:
1659 case EM_SETTABSTOPS:
1660 return TRUE;
1661 default:
1662 return FALSE;
1663 }
1664}
1665
1666/***********************************************************************
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001667 * MSG_PostMessage
1668 */
1669static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1670 WPARAM wParam, LPARAM lParam )
1671{
1672 HQUEUE16 hQueue;
1673 WND *wndPtr;
1674
Marcus Meissner5bcef612001-02-13 01:48:39 +00001675 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1676 * that are known to contain pointers are dropped by the Windows 32bit
1677 * PostMessage() with return FALSE; and invalid parameter last error.
1678 * (tested against NT4 by Gerard Patel)
1679 * 16 bit does not care, so we don't either.
1680 */
1681 if ( (type!=QMSG_WIN16) && MSG_IsPointerMessage(message,wParam,lParam)) {
1682 FIXME("Ignoring posted pointer message 0x%04x to hwnd 0x%04x.\n",
1683 message,hwnd
1684 );
1685 SetLastError(ERROR_INVALID_PARAMETER);
1686 return FALSE;
1687 }
1688
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001689 if (hwnd == HWND_BROADCAST)
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001690 {
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001691 WND *pDesktop = WIN_GetDesktop();
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001692 TRACE("HWND_BROADCAST !\n");
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001693
1694 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001695 {
1696 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1697 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001698 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1699 wndPtr->hwndSelf, message, wParam, lParam);
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001700 MSG_PostToQueue( wndPtr->hmemTaskQ, type,
1701 wndPtr->hwndSelf, message, wParam, lParam );
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001702 }
1703 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001704 WIN_ReleaseDesktop();
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001705 TRACE("End of HWND_BROADCAST !\n");
Alexandre Julliard59730ae1996-03-24 16:20:51 +00001706 return TRUE;
Alexandre Julliard2787be81995-05-22 18:23:01 +00001707 }
Alexandre Julliard7e50df31994-08-06 11:22:41 +00001708
Alexandre Julliard2787be81995-05-22 18:23:01 +00001709 wndPtr = WIN_FindWndPtr( hwnd );
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001710 hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001711 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001712
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001713 return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
1714}
Alexandre Julliard21979011997-03-05 08:22:35 +00001715
1716/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001717 * PostMessage (USER.110)
Alexandre Julliard21979011997-03-05 08:22:35 +00001718 */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001719BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1720 LPARAM lParam )
Alexandre Julliard21979011997-03-05 08:22:35 +00001721{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001722 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
Alexandre Julliard21979011997-03-05 08:22:35 +00001723}
1724
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001725/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001726 * PostMessageA (USER32.@)
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001727 */
1728BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1729 LPARAM lParam )
1730{
1731 return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
1732}
1733
1734/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001735 * PostMessageW (USER32.@)
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001736 */
1737BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1738 LPARAM lParam )
1739{
1740 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1741}
Alexandre Julliard21979011997-03-05 08:22:35 +00001742
Alexandre Julliard2787be81995-05-22 18:23:01 +00001743/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +00001744 * PostAppMessage (USER.116)
1745 * PostAppMessage16 (USER32.@)
Alexandre Julliard2787be81995-05-22 18:23:01 +00001746 */
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001747BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1748 WPARAM16 wParam, LPARAM lParam )
Alexandre Julliard2787be81995-05-22 18:23:01 +00001749{
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001750 return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
1751 0, message, wParam, lParam );
Alexandre Julliard2787be81995-05-22 18:23:01 +00001752}
1753
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001754/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001755 * PostThreadMessageA (USER32.@)
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001756 */
1757BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1758 WPARAM wParam, LPARAM lParam )
1759{
1760 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
1761 0, message, wParam, lParam );
1762}
1763
1764/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001765 * PostThreadMessageW (USER32.@)
Ulrich Weigand2faf2cf1999-12-10 03:47:13 +00001766 */
1767BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1768 WPARAM wParam, LPARAM lParam )
1769{
1770 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
1771 0, message, wParam, lParam );
1772}
1773
1774
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001775/************************************************************************
1776 * MSG_CallWndProcHook32
1777 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001778static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001779{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001780 CWPSTRUCT cwp;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001781
1782 cwp.lParam = pmsg->lParam;
1783 cwp.wParam = pmsg->wParam;
1784 cwp.message = pmsg->message;
1785 cwp.hwnd = pmsg->hwnd;
1786
Alexandre Julliarda3960291999-02-26 11:11:13 +00001787 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1788 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00001789
1790 pmsg->lParam = cwp.lParam;
1791 pmsg->wParam = cwp.wParam;
1792 pmsg->message = cwp.message;
1793 pmsg->hwnd = cwp.hwnd;
1794}
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001795
Stephane Lussierbae55521999-03-10 16:21:12 +00001796
1797/***********************************************************************
1798 * MSG_SendMessage
1799 *
1800 * return values: 0 if timeout occurs
1801 * 1 otherwise
1802 */
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +00001803static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
Stephane Lussierbae55521999-03-10 16:21:12 +00001804 LPARAM lParam, DWORD timeout, WORD flags,
1805 LRESULT *pRes)
1806{
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001807 WND * wndPtr = 0;
Stephane Lussierbae55521999-03-10 16:21:12 +00001808 WND **list, **ppWnd;
1809 LRESULT ret = 1;
1810
Ove Kaaven98111292000-11-25 01:23:50 +00001811 if (pRes) *pRes = 0;
Stephane Lussierbae55521999-03-10 16:21:12 +00001812
Uwe Bonnes991fc351999-06-05 15:16:57 +00001813 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
Stephane Lussierbae55521999-03-10 16:21:12 +00001814 {
Ove Kaaven98111292000-11-25 01:23:50 +00001815 if (pRes) *pRes = 1;
Stephane Lussierbae55521999-03-10 16:21:12 +00001816
1817 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001818 {
1819 WIN_ReleaseDesktop();
Stephane Lussierbae55521999-03-10 16:21:12 +00001820 return 1;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001821 }
1822 WIN_ReleaseDesktop();
1823
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001824 TRACE("HWND_BROADCAST !\n");
Stephane Lussierbae55521999-03-10 16:21:12 +00001825 for (ppWnd = list; *ppWnd; ppWnd++)
1826 {
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001827 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
Stephane Lussierbae55521999-03-10 16:21:12 +00001828 if (!IsWindow(wndPtr->hwndSelf)) continue;
1829 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1830 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001831 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1832 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
Stephane Lussierbae55521999-03-10 16:21:12 +00001833 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1834 timeout, flags, pRes);
1835 }
1836 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001837 WIN_ReleaseWndPtr(wndPtr);
1838 WIN_ReleaseWinArray(list);
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001839 TRACE("End of HWND_BROADCAST !\n");
Stephane Lussierbae55521999-03-10 16:21:12 +00001840 return 1;
1841 }
1842
1843 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1844 {
1845 if (flags & SMSG_UNICODE)
1846 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1847 else if (flags & SMSG_WIN32)
1848 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1849 else
1850 {
1851 LPCWPSTRUCT16 pmsg;
1852
1853 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1854 {
1855 pmsg->hwnd = hwnd & 0xffff;
1856 pmsg->message= msg & 0xffff;
1857 pmsg->wParam = wParam & 0xffff;
1858 pmsg->lParam = lParam;
1859 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1860 (LPARAM)SEGPTR_GET(pmsg) );
1861 hwnd = pmsg->hwnd;
1862 msg = pmsg->message;
1863 wParam = pmsg->wParam;
1864 lParam = pmsg->lParam;
1865 SEGPTR_FREE( pmsg );
1866 }
1867 }
1868 }
1869
1870 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1871 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001872 WARN("invalid hwnd %04x\n", hwnd );
Stephane Lussierbae55521999-03-10 16:21:12 +00001873 return 0;
1874 }
1875 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001876 {
1877 ret = 0; /* Don't send anything if the task is dying */
1878 goto END;
1879 }
Stephane Lussierbae55521999-03-10 16:21:12 +00001880 if (flags & SMSG_WIN32)
1881 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1882 else
Ove Kaaven98111292000-11-25 01:23:50 +00001883 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
Stephane Lussierbae55521999-03-10 16:21:12 +00001884
1885 if (wndPtr->hmemTaskQ != GetFastQueue16())
1886 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1887 wParam, lParam, timeout, flags, pRes );
1888 else
1889 {
Ove Kaaven98111292000-11-25 01:23:50 +00001890 LRESULT res;
1891
Stephane Lussierbae55521999-03-10 16:21:12 +00001892 /* Call the right CallWindowProc flavor */
1893 if (flags & SMSG_UNICODE)
Ove Kaaven98111292000-11-25 01:23:50 +00001894 res = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1895 hwnd, msg, wParam, lParam );
Stephane Lussierbae55521999-03-10 16:21:12 +00001896 else if (flags & SMSG_WIN32)
Ove Kaaven98111292000-11-25 01:23:50 +00001897 res = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1898 hwnd, msg, wParam, lParam );
Stephane Lussierbae55521999-03-10 16:21:12 +00001899 else
Ove Kaaven98111292000-11-25 01:23:50 +00001900 res = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
Stephane Lussierbae55521999-03-10 16:21:12 +00001901 (HWND16) hwnd, (UINT16) msg,
1902 (WPARAM16) wParam, lParam );
Ove Kaaven98111292000-11-25 01:23:50 +00001903 if (pRes) *pRes = res;
Stephane Lussierbae55521999-03-10 16:21:12 +00001904 }
1905
1906 if (flags & SMSG_WIN32)
Ove Kaaven98111292000-11-25 01:23:50 +00001907 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, pRes?*pRes:0, wParam, lParam );
Stephane Lussierbae55521999-03-10 16:21:12 +00001908 else
Ove Kaaven98111292000-11-25 01:23:50 +00001909 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, pRes?*pRes:0, wParam, lParam );
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00001910END:
1911 WIN_ReleaseWndPtr(wndPtr);
Stephane Lussierbae55521999-03-10 16:21:12 +00001912 return ret;
1913}
1914
1915
1916/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001917 * SendMessage (USER.111)
Stephane Lussierbae55521999-03-10 16:21:12 +00001918 */
1919LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1920 LPARAM lParam)
1921{
1922 LRESULT res;
Stephane Lussierbae55521999-03-10 16:21:12 +00001923 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
Stephane Lussierbae55521999-03-10 16:21:12 +00001924 return res;
1925}
1926
1927
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001928/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001929 * SendMessageA (USER32.@)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001930 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001931LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001932 LPARAM lParam )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001933 {
Stephane Lussierbae55521999-03-10 16:21:12 +00001934 LRESULT res;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001935
Stephane Lussierbae55521999-03-10 16:21:12 +00001936 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1937 SMSG_WIN32, &res);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001938
Stephane Lussierbae55521999-03-10 16:21:12 +00001939 return res;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001940}
1941
1942
1943/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001944 * SendMessageW (USER32.@) Send Window Message
Douglas Ridgwayefaa5731998-10-25 09:20:30 +00001945 *
1946 * Sends a message to the window procedure of the specified window.
1947 * SendMessage() will not return until the called window procedure
1948 * either returns or calls ReplyMessage().
1949 *
1950 * Use PostMessage() to send message and return immediately. A window
1951 * procedure may use InSendMessage() to detect
1952 * SendMessage()-originated messages.
1953 *
1954 * Applications which communicate via HWND_BROADCAST may use
1955 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1956 * with other applications.
1957 *
1958 * CONFORMANCE
1959 *
1960 * ECMA-234, Win32
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001961 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001962LRESULT WINAPI SendMessageW(
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001963 HWND hwnd, /* [in] Window to send message to. If HWND_BROADCAST,
1964 the message will be sent to all top-level windows. */
Douglas Ridgwayefaa5731998-10-25 09:20:30 +00001965
Patrik Stridvall2b3aa612000-12-01 23:58:28 +00001966 UINT msg, /* [in] message */
1967 WPARAM wParam, /* [in] message parameter */
1968 LPARAM lParam /* [in] additional message parameter */
Douglas Ridgwayefaa5731998-10-25 09:20:30 +00001969) {
Stephane Lussierbae55521999-03-10 16:21:12 +00001970 LRESULT res;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001971
Stephane Lussierbae55521999-03-10 16:21:12 +00001972 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1973 SMSG_WIN32 | SMSG_UNICODE, &res);
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001974
Stephane Lussierbae55521999-03-10 16:21:12 +00001975 return res;
Alexandre Julliard75a839a1993-07-15 11:13:45 +00001976}
1977
1978
1979/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001980 * SendMessageTimeout (not a WINAPI)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001981 */
1982LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1983 LPARAM lParam, UINT16 flags,
1984 UINT16 timeout, LPWORD resultp)
1985{
Stephane Lussierbae55521999-03-10 16:21:12 +00001986 LRESULT ret;
1987 LRESULT msgRet;
1988
1989 /* FIXME: need support for SMTO_BLOCK */
1990
1991 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
Andreas Mohr98c5cd62000-01-04 00:23:32 +00001992 if (resultp) *resultp = (WORD) msgRet;
Stephane Lussierbae55521999-03-10 16:21:12 +00001993 return ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001994}
1995
1996
1997/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001998 * SendMessageTimeoutA (USER32.@)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001999 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002000LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
2001 LPARAM lParam, UINT flags,
2002 UINT timeout, LPDWORD resultp)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00002003{
Stephane Lussierbae55521999-03-10 16:21:12 +00002004 LRESULT ret;
2005 LRESULT msgRet;
2006
2007 /* FIXME: need support for SMTO_BLOCK */
2008
2009 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
2010 &msgRet);
2011
Andreas Mohr98c5cd62000-01-04 00:23:32 +00002012 if (resultp) *resultp = (DWORD) msgRet;
Stephane Lussierbae55521999-03-10 16:21:12 +00002013 return ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00002014}
2015
2016
2017/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002018 * SendMessageTimeoutW (USER32.@)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00002019 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002020LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
2021 LPARAM lParam, UINT flags,
2022 UINT timeout, LPDWORD resultp)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00002023{
Stephane Lussierbae55521999-03-10 16:21:12 +00002024 LRESULT ret;
2025 LRESULT msgRet;
2026
2027 /* FIXME: need support for SMTO_BLOCK */
2028
2029 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
2030 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
2031
Andreas Mohr98c5cd62000-01-04 00:23:32 +00002032 if (resultp) *resultp = (DWORD) msgRet;
Stephane Lussierbae55521999-03-10 16:21:12 +00002033 return ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00002034}
2035
2036
2037/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002038 * WaitMessage (USER.112) (USER32.@) Suspend thread pending messages
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002039 *
2040 * WaitMessage() suspends a thread until events appear in the thread's
2041 * queue.
2042 *
2043 * BUGS
2044 *
2045 * Is supposed to return BOOL under Win32.
2046 *
Douglas Ridgwayefaa5731998-10-25 09:20:30 +00002047 * Thread-local message queues are not supported.
2048 *
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002049 * CONFORMANCE
2050 *
2051 * ECMA-234, Win32
2052 *
Alexandre Julliard7e50df31994-08-06 11:22:41 +00002053 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002054void WINAPI WaitMessage( void )
Alexandre Julliard7e50df31994-08-06 11:22:41 +00002055{
Stephane Lussierbae55521999-03-10 16:21:12 +00002056 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
Alexandre Julliard7e50df31994-08-06 11:22:41 +00002057}
2058
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002059/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002060 * MsgWaitForMultipleObjects (USER32.@)
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002061 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002062DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
2063 BOOL fWaitAll, DWORD dwMilliseconds,
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002064 DWORD dwWakeMask )
2065{
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +00002066 DWORD i;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002067 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002068 DWORD ret;
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002069
Alexandre Julliarda3960291999-02-26 11:11:13 +00002070 HQUEUE16 hQueue = GetFastQueue16();
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002071 MESSAGEQUEUE *msgQueue = QUEUE_Lock( hQueue );
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +00002072 if (!msgQueue) return WAIT_FAILED;
2073
2074 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
2075 {
2076 SetLastError( ERROR_INVALID_PARAMETER );
Stephane Lussier1c4786f1999-01-28 10:54:11 +00002077 QUEUE_Unlock( msgQueue );
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +00002078 return WAIT_FAILED;
2079 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002080
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002081 EnterCriticalSection( &msgQueue->cSection );
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002082 msgQueue->changeBits = 0;
2083 msgQueue->wakeMask = dwWakeMask;
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002084 LeaveCriticalSection( &msgQueue->cSection );
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002085
Alexandre Julliard0a860a01999-06-22 11:43:42 +00002086 if (THREAD_IsWin16(NtCurrentTeb()))
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002087 {
2088 /*
2089 * This is a temporary solution to a big problem.
2090 * You see, the main thread of all Win32 programs is created as a 16 bit
Andreas Mohr2e011a52000-06-01 23:28:25 +00002091 * task. This means that if you wait on an event using Win32 synchronization
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002092 * methods, the 16 bit scheduler is stopped and things might just stop happening.
2093 * This implements a semi-busy loop that checks the handles to wait on and
2094 * also the message queue. When either one is ready, the wait function returns.
2095 *
2096 * This will all go away when the real Win32 threads are implemented for all
2097 * the threads of an applications. Including the main thread.
2098 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002099 DWORD curTime = GetCurrentTime();
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002100
2101 do
2102 {
2103 /*
2104 * Check the handles in the list.
2105 */
2106 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
2107
2108 /*
2109 * If the handles have been triggered, return.
2110 */
2111 if (ret != WAIT_TIMEOUT)
2112 break;
2113
2114 /*
2115 * Then, let the 16 bit scheduler do it's thing.
2116 */
Eric Pouech4d24e0f2000-12-22 23:25:47 +00002117 K32WOWYield16();
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002118
2119 /*
2120 * If a message matching the wait mask has arrived, return.
2121 */
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002122 EnterCriticalSection( &msgQueue->cSection );
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002123 if (msgQueue->changeBits & dwWakeMask)
2124 {
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002125 LeaveCriticalSection( &msgQueue->cSection );
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002126 ret = nCount;
2127 break;
2128 }
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002129 LeaveCriticalSection( &msgQueue->cSection );
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002130
2131 /*
2132 * And continue doing this until we hit the timeout.
2133 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002134 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002135 }
2136 else
2137 {
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +00002138 /* Add the thread event to the handle list */
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002139 for (i = 0; i < nCount; i++)
Alexandre Julliardc5e433a2000-05-30 19:48:18 +00002140 handles[i] = pHandles[i];
2141 handles[nCount] = msgQueue->server_queue;
Peter Ganten6619f5a2000-01-01 22:38:20 +00002142 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
Francis Beaudet6a6f6e21999-02-19 15:34:40 +00002143 }
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002144 QUEUE_Unlock( msgQueue );
Stephane Lussierb3a99de1999-02-09 15:35:12 +00002145 return ret;
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002146}
2147
Eric Pouech982e0ce2001-01-28 23:44:56 +00002148/***********************************************************************
Patrik Stridvalldf75e892001-02-12 03:49:07 +00002149 * MsgWaitForMultipleObjects (USER.640)
Eric Pouech982e0ce2001-01-28 23:44:56 +00002150 */
2151DWORD WINAPI MsgWaitForMultipleObjects16( DWORD nCount, HANDLE *pHandles,
2152 BOOL fWaitAll, DWORD dwMilliseconds,
2153 DWORD dwWakeMask )
2154{
2155 TRACE("(%lu,%p,%u,%lu,0x%lx)\n",
2156 nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2157 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2158}
Alexandre Julliard7e50df31994-08-06 11:22:41 +00002159
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002160struct accent_char
2161{
2162 BYTE ac_accent;
2163 BYTE ac_char;
2164 BYTE ac_result;
2165};
2166
2167static const struct accent_char accent_chars[] =
2168{
Alexandre Julliard21979011997-03-05 08:22:35 +00002169/* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002170 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2171 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2172 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2173 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2174 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2175 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2176 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2177 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2178 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2179 {',', 'C', '\307'}, {',', 'c', '\347'},
2180 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2181 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2182 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2183 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2184 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2185 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2186 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2187 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2188 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2189 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2190 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2191 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2192 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2193 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2194 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2195 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2196 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2197 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2198 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2199 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2200 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2201 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2202 {'s', 's', '\337'}, {'"', 'y', '\377'},
2203 {'s', 'z', '\337'}, {'i', 'j', '\377'},
Alexandre Julliard21979011997-03-05 08:22:35 +00002204 /* iso-8859-2 uses this */
2205 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2206 {'<', 'S', '\251'}, {'<', 's', '\271'},
2207 {'<', 'T', '\253'}, {'<', 't', '\273'},
2208 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2209 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2210 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2211 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2212 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2213 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2214 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2215 {';', 'E', '\312'}, {';', 'e', '\332'},
2216 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2217 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2218 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2219 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2220 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2221/* collision whith S, from iso-8859-9 !!! */
2222 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2223 {',', 'T', '\336'}, {',', 't', '\376'},
2224 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2225 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2226 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2227 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2228 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2229 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2230 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2231 /* iso-8859-3 uses this */
2232 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2233 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2234 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2235 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2236 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2237 {'>', 'S', '\336'}, {'>', 's', '\376'},
2238/* collision whith G( from iso-8859-9 !!! */
2239 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2240 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2241/* collision whith I. from iso-8859-3 !!! */
2242 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2243 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2244 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2245 /* iso-8859-4 uses this */
2246 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2247 {',', 'L', '\246'}, {',', 'l', '\266'},
2248 {',', 'G', '\253'}, {',', 'g', '\273'},
2249 {',', 'N', '\321'}, {',', 'n', '\361'},
2250 {',', 'K', '\323'}, {',', 'k', '\363'},
2251 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2252 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2253 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2254 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2255 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2256 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2257 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2258 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2259 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2260 {';', 'U', '\331'}, {';', 'u', '\371'},
2261 /* iso-8859-9 uses this */
2262 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2263 * whith the same letters on other iso-8859-x (that is they are on
2264 * different places :-( ), if you use turkish uncomment these and
2265 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2266 * FIXME: should be dynamic according to chosen language
2267 * if/when Wine has turkish support.
2268 */
2269/* collision whith G( from iso-8859-3 !!! */
2270/* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2271/* collision whith S, from iso-8859-2 !!! */
2272/* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2273/* collision whith I. from iso-8859-3 !!! */
2274/* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002275};
2276
2277
Alexandre Julliard7e50df31994-08-06 11:22:41 +00002278/***********************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002279 * MSG_DoTranslateMessage
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002280 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002281 * Implementation of TranslateMessage.
2282 *
2283 * TranslateMessage translates virtual-key messages into character-messages,
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002284 * as follows :
2285 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2286 * ditto replacing WM_* with WM_SYS*
2287 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2288 * by the keyboard driver.
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002289 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002290static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2291 WPARAM wParam, LPARAM lParam )
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002292{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002293 static int dead_char;
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +00002294 WCHAR wp[2];
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002295
Alexandre Julliarda11d7b11998-03-01 20:05:02 +00002296 if (message != WM_MOUSEMOVE && message != WM_TIMER)
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002297 TRACE("(%s, %04X, %08lX)\n",
Alexandre Julliarda11d7b11998-03-01 20:05:02 +00002298 SPY_GetMsgName(message), wParam, lParam );
2299 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002300 TRACE_(key)("(%s, %04X, %08lX)\n",
Alexandre Julliarda11d7b11998-03-01 20:05:02 +00002301 SPY_GetMsgName(message), wParam, lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002302
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002303 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002304
Dmitry Timoshkov740bb922000-11-05 20:07:59 +00002305 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2306 SPY_GetVKeyName(wParam), wParam, LOBYTE(HIWORD(lParam)));
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002307
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +00002308 /* FIXME : should handle ToUnicode yielding 2 */
2309 switch (ToUnicode(wParam, HIWORD(lParam), QueueKeyStateTable, wp, 2, 0))
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002310 {
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002311 case 1:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002312 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2313 /* Should dead chars handling go in ToAscii ? */
2314 if (dead_char)
2315 {
2316 int i;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002317
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002318 if (wp[0] == ' ') wp[0] = dead_char;
Alexandre Julliard21979011997-03-05 08:22:35 +00002319 if (dead_char == 0xa2) dead_char = '(';
2320 else if (dead_char == 0xa8) dead_char = '"';
2321 else if (dead_char == 0xb2) dead_char = ';';
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002322 else if (dead_char == 0xb4) dead_char = '\'';
Alexandre Julliard21979011997-03-05 08:22:35 +00002323 else if (dead_char == 0xb7) dead_char = '<';
2324 else if (dead_char == 0xb8) dead_char = ',';
2325 else if (dead_char == 0xff) dead_char = '.';
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002326 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2327 if ((accent_chars[i].ac_accent == dead_char) &&
2328 (accent_chars[i].ac_char == wp[0]))
2329 {
2330 wp[0] = accent_chars[i].ac_result;
2331 break;
2332 }
2333 dead_char = 0;
2334 }
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002335 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +00002336 PostMessageW( hwnd, message, wp[0], lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002337 return TRUE;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +00002338
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002339 case -1:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002340 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2341 dead_char = wp[0];
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +00002342 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2343 PostMessageW( hwnd, message, wp[0], lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002344 return TRUE;
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002345 }
2346 return FALSE;
2347}
2348
2349
2350/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002351 * TranslateMessage (USER.113)
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002352 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002353BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002354{
2355 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2356 msg->wParam, msg->lParam );
2357}
2358
2359
2360/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002361 * TranslateMessage32 (USER.821)
Andreas Mohr94e44851999-01-23 14:15:17 +00002362 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002363BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
Andreas Mohr94e44851999-01-23 14:15:17 +00002364{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002365 WPARAM wParam;
Andreas Mohr94e44851999-01-23 14:15:17 +00002366
2367 if (wHaveParamHigh)
2368 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2369 else
Alexandre Julliarda3960291999-02-26 11:11:13 +00002370 wParam = (WPARAM)msg->msg.wParam;
Andreas Mohr94e44851999-01-23 14:15:17 +00002371
2372 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2373 wParam, msg->msg.lParam );
2374}
2375
2376/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002377 * TranslateMessage (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002378 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002379BOOL WINAPI TranslateMessage( const MSG *msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002380{
2381 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2382 msg->wParam, msg->lParam );
2383}
2384
2385
2386/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002387 * DispatchMessage (USER.114)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002388 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002389LONG WINAPI DispatchMessage16( const MSG16* msg )
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002390{
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002391 WND * wndPtr;
2392 LONG retval;
2393 int painting;
2394
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002395 /* Process timer messages */
2396 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2397 {
2398 if (msg->lParam)
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00002399 {
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002400 /* before calling window proc, verify whether timer is still valid;
2401 there's a slim chance that the application kills the timer
2402 between GetMessage and DispatchMessage API calls */
Stephane Lussier6bac4f22000-09-29 00:56:05 +00002403 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2404 return 0; /* invalid winproc */
2405
Alexandre Julliardd90840e1996-06-11 16:02:08 +00002406 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002407 msg->message, msg->wParam, GetTickCount() );
Alexandre Julliarde2991ea1995-07-29 13:09:43 +00002408 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002409 }
2410
2411 if (!msg->hwnd) return 0;
2412 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002413 if (!wndPtr->winproc)
2414 {
2415 retval = 0;
2416 goto END;
2417 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002418 painting = (msg->message == WM_PAINT);
2419 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002420
2421 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2422 msg->wParam, msg->lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002423 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2424 msg->hwnd, msg->message,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002425 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +00002426 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval,
2427 msg->wParam, msg->lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002428
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002429 WIN_ReleaseWndPtr(wndPtr);
2430 wndPtr = WIN_FindWndPtr(msg->hwnd);
2431 if (painting && wndPtr &&
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +00002432 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002433 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002434 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
Alexandre Julliard54c27111998-03-29 19:44:57 +00002435 msg->hwnd);
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002436 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
Alexandre Julliard4f8c37b1996-01-14 18:12:01 +00002437 /* Validate the update region to avoid infinite WM_PAINT loop */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002438 ValidateRect( msg->hwnd, NULL );
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002439 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002440END:
2441 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliard5f721f81994-01-04 20:14:34 +00002442 return retval;
Alexandre Julliard75a839a1993-07-15 11:13:45 +00002443}
2444
2445
2446/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002447 * DispatchMessage32 (USER.822)
Andreas Mohr94e44851999-01-23 14:15:17 +00002448 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002449LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
Andreas Mohr94e44851999-01-23 14:15:17 +00002450{
2451 if (wHaveParamHigh == FALSE)
2452 return DispatchMessage16(&(lpmsg16_32->msg));
2453 else
2454 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002455 MSG msg;
Andreas Mohr94e44851999-01-23 14:15:17 +00002456
2457 msg.hwnd = lpmsg16_32->msg.hwnd;
2458 msg.message = lpmsg16_32->msg.message;
2459 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2460 msg.lParam = lpmsg16_32->msg.lParam;
2461 msg.time = lpmsg16_32->msg.time;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002462 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2463 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2464 return DispatchMessageA(&msg);
Andreas Mohr94e44851999-01-23 14:15:17 +00002465 }
2466}
2467
2468/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002469 * DispatchMessageA (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002470 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002471LONG WINAPI DispatchMessageA( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002472{
2473 WND * wndPtr;
2474 LONG retval;
2475 int painting;
2476
2477 /* Process timer messages */
2478 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2479 {
2480 if (msg->lParam)
2481 {
2482/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +00002483
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002484 /* before calling window proc, verify whether timer is still valid;
2485 there's a slim chance that the application kills the timer
2486 between GetMessage and DispatchMessage API calls */
Stephane Lussier6bac4f22000-09-29 00:56:05 +00002487 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2488 return 0; /* invalid winproc */
2489
Alexandre Julliarda3960291999-02-26 11:11:13 +00002490 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002491 msg->message, msg->wParam, GetTickCount() );
2492 }
2493 }
2494
2495 if (!msg->hwnd) return 0;
2496 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002497 if (!wndPtr->winproc)
2498 {
2499 retval = 0;
2500 goto END;
2501 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002502 painting = (msg->message == WM_PAINT);
2503 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2504/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2505
Alexandre Julliarda3960291999-02-26 11:11:13 +00002506 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002507 msg->wParam, msg->lParam );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002508 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002509 msg->hwnd, msg->message,
2510 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +00002511 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2512 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002513
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002514 WIN_ReleaseWndPtr(wndPtr);
2515 wndPtr = WIN_FindWndPtr(msg->hwnd);
2516
2517 if (painting && wndPtr &&
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002518 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2519 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002520 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
Alexandre Julliard54c27111998-03-29 19:44:57 +00002521 msg->hwnd);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002522 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2523 /* Validate the update region to avoid infinite WM_PAINT loop */
John R . Sheets278b3bc2000-07-15 21:31:01 +00002524 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2525 RDW_FRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT, 0 );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002526 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002527END:
2528 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002529 return retval;
2530}
2531
2532
2533/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002534 * DispatchMessageW (USER32.@) Process Message
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002535 *
2536 * Process the message specified in the structure *_msg_.
2537 *
2538 * If the lpMsg parameter points to a WM_TIMER message and the
2539 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2540 * points to the function that is called instead of the window
2541 * procedure.
2542 *
2543 * The message must be valid.
2544 *
2545 * RETURNS
2546 *
2547 * DispatchMessage() returns the result of the window procedure invoked.
2548 *
2549 * CONFORMANCE
2550 *
2551 * ECMA-234, Win32
2552 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002553 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002554LONG WINAPI DispatchMessageW( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002555{
2556 WND * wndPtr;
2557 LONG retval;
2558 int painting;
2559
2560 /* Process timer messages */
2561 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2562 {
2563 if (msg->lParam)
2564 {
2565/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +00002566
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002567 /* before calling window proc, verify whether timer is still valid;
2568 there's a slim chance that the application kills the timer
2569 between GetMessage and DispatchMessage API calls */
Stephane Lussier6bac4f22000-09-29 00:56:05 +00002570 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2571 return 0; /* invalid winproc */
2572
Alexandre Julliarda3960291999-02-26 11:11:13 +00002573 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002574 msg->message, msg->wParam, GetTickCount() );
2575 }
2576 }
2577
2578 if (!msg->hwnd) return 0;
2579 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002580 if (!wndPtr->winproc)
2581 {
2582 retval = 0;
2583 goto END;
2584 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002585 painting = (msg->message == WM_PAINT);
2586 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2587/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2588
Alexandre Julliarda3960291999-02-26 11:11:13 +00002589 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002590 msg->wParam, msg->lParam );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002591 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002592 msg->hwnd, msg->message,
2593 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +00002594 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2595 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002596
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002597 WIN_ReleaseWndPtr(wndPtr);
2598 wndPtr = WIN_FindWndPtr(msg->hwnd);
2599
2600 if (painting && wndPtr &&
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002601 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2602 {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002603 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
Alexandre Julliard54c27111998-03-29 19:44:57 +00002604 msg->hwnd);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002605 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2606 /* Validate the update region to avoid infinite WM_PAINT loop */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002607 ValidateRect( msg->hwnd, NULL );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002608 }
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +00002609END:
2610 WIN_ReleaseWndPtr(wndPtr);
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002611 return retval;
2612}
2613
2614
2615/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002616 * RegisterWindowMessage (USER.118)
2617 * RegisterWindowMessageA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002618 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002619WORD WINAPI RegisterWindowMessageA( LPCSTR str )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002620{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002621 TRACE("%s\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002622 return GlobalAddAtomA( str );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00002623}
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00002624
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002625
2626/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002627 * RegisterWindowMessageW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002628 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002629WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002630{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002631 TRACE("%p\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002632 return GlobalAddAtomW( str );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002633}
2634
2635
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +00002636/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002637 * GetCurrentTime (USER.15)
Alexandre Julliardb817f4f1996-03-14 18:08:34 +00002638 *
2639 * (effectively identical to GetTickCount)
Alexandre Julliardade697e1995-11-26 13:59:11 +00002640 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002641DWORD WINAPI GetCurrentTime16(void)
Alexandre Julliardade697e1995-11-26 13:59:11 +00002642{
Alexandre Julliardb817f4f1996-03-14 18:08:34 +00002643 return GetTickCount();
Alexandre Julliardade697e1995-11-26 13:59:11 +00002644}
2645
Alexandre Julliardb817f4f1996-03-14 18:08:34 +00002646
Alexandre Julliardade697e1995-11-26 13:59:11 +00002647/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002648 * InSendMessage (USER.192)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002649 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002650BOOL16 WINAPI InSendMessage16(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002651{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002652 return InSendMessage();
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002653}
2654
2655
2656/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002657 * InSendMessage (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00002658 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002659BOOL WINAPI InSendMessage(void)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002660{
Alexandre Julliardef702d81996-05-28 18:54:58 +00002661 MESSAGEQUEUE *queue;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002662 BOOL ret;
Alexandre Julliardef702d81996-05-28 18:54:58 +00002663
Ulrich Weigand52e891d2001-01-29 00:33:35 +00002664 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
Alexandre Julliardef702d81996-05-28 18:54:58 +00002665 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002666 ret = (BOOL)queue->smWaiting;
Stephane Lussier1c4786f1999-01-28 10:54:11 +00002667
2668 QUEUE_Unlock( queue );
2669 return ret;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00002670}
Alexandre Julliarde658d821997-11-30 17:45:40 +00002671
2672/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002673 * BroadcastSystemMessage (USER32.@)
Alexandre Julliarde658d821997-11-30 17:45:40 +00002674 */
2675LONG WINAPI BroadcastSystemMessage(
Alexandre Julliarda3960291999-02-26 11:11:13 +00002676 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
Alexandre Julliarde658d821997-11-30 17:45:40 +00002677 LPARAM lParam
2678) {
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002679 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
Alexandre Julliard54c27111998-03-29 19:44:57 +00002680 dwFlags,*recipients,uMessage,wParam,lParam
Alexandre Julliarde658d821997-11-30 17:45:40 +00002681 );
2682 return 0;
2683}
Alexandre Julliard02e90081998-01-04 17:49:09 +00002684
2685/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002686 * SendNotifyMessageA (USER32.@)
Alexandre Julliard02e90081998-01-04 17:49:09 +00002687 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002688BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
Ove Kaaven98111292000-11-25 01:23:50 +00002689{
2690 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2691 SMSG_WIN32, NULL);
Alexandre Julliard02e90081998-01-04 17:49:09 +00002692}
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +00002693
2694/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002695 * SendNotifyMessageW (USER32.@)
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +00002696 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002697BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
Ove Kaaven98111292000-11-25 01:23:50 +00002698{
2699 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2700 SMSG_WIN32 | SMSG_UNICODE, NULL);
Alexandre Julliard0c0e3be1998-12-10 15:49:22 +00002701}
2702
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002703/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002704 * SendMessageCallbackA (USER32.@)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002705 * FIXME: It's like PostMessage. The callback gets called when the message
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002706 * is processed. We have to modify the message processing for an exact
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002707 * implementation...
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002708 * The callback is only called when the thread that called us calls one of
2709 * Get/Peek/WaitMessage.
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002710 */
Juergen Schmied13f1b121999-05-02 09:17:48 +00002711BOOL WINAPI SendMessageCallbackA(
Alexandre Julliarda3960291999-02-26 11:11:13 +00002712 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2713 FARPROC lpResultCallBack,DWORD dwData)
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002714{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002715 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2716 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002717 if ( hWnd == HWND_BROADCAST)
Alexandre Julliarda3960291999-02-26 11:11:13 +00002718 { PostMessageA( hWnd, Msg, wParam, lParam);
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002719 FIXME("Broadcast: Callback will not be called!\n");
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002720 return TRUE;
2721 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002722 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002723 return TRUE;
Alexandre Julliardf90efa91998-06-14 15:24:15 +00002724}
Juergen Schmied13f1b121999-05-02 09:17:48 +00002725/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00002726 * SendMessageCallbackW (USER32.@)
Andreas Mohr1af53cb2000-12-09 03:15:32 +00002727 * FIXME: see SendMessageCallbackA.
Juergen Schmied13f1b121999-05-02 09:17:48 +00002728 */
2729BOOL WINAPI SendMessageCallbackW(
2730 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2731 FARPROC lpResultCallBack,DWORD dwData)
2732{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002733 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2734 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
Juergen Schmied13f1b121999-05-02 09:17:48 +00002735 if ( hWnd == HWND_BROADCAST)
2736 { PostMessageW( hWnd, Msg, wParam, lParam);
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002737 FIXME("Broadcast: Callback will not be called!\n");
Juergen Schmied13f1b121999-05-02 09:17:48 +00002738 return TRUE;
2739 }
2740 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2741 return TRUE;
2742}