blob: 20b7b16177087a7c34a03026dfcb3e3cc8d9b25f [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 Julliard0799c1a2002-03-09 23:29:33 +00005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard75a839a1993-07-15 11:13:45 +000019 */
20
Patrik Stridvalld016f812002-08-17 00:43:16 +000021#include "config.h"
22
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000023#include <stdarg.h>
Alexandre Julliard401710d1993-09-04 10:09:32 +000024#include <stdlib.h>
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000025#include <string.h>
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +000026#include <ctype.h>
Patrik Stridvalld016f812002-08-17 00:43:16 +000027#ifdef HAVE_SYS_TIME_H
28# include <sys/time.h>
29#endif
Alexandre Julliard5f721f81994-01-04 20:14:34 +000030#include <sys/types.h>
Alexandre Julliardf41aeca1993-09-14 16:47:10 +000031
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000032#include "windef.h"
Alexandre Julliardd253c582001-08-07 19:19:08 +000033#include "winbase.h"
34#include "wingdi.h"
35#include "winuser.h"
Alexandre Julliard75a839a1993-07-15 11:13:45 +000036#include "message.h"
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +000037#include "winerror.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000038#include "ntstatus.h"
Alexandre Julliard37e95032001-07-19 00:39:09 +000039#include "wine/server.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000040#include "controls.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000041#include "dde.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000042#include "message.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000043#include "user.h"
44#include "win.h"
45#include "winpos.h"
46#include "winproc.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000047#include "wine/debug.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000048
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000049WINE_DEFAULT_DEBUG_CHANNEL(msg);
50WINE_DECLARE_DEBUG_CHANNEL(key);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000051
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000052#define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53#define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
54
Alexandre Julliard838d65a2001-06-19 19:16:41 +000055
Alexandre Julliard75a839a1993-07-15 11:13:45 +000056/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +000057 * is_keyboard_message
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000058 */
Alexandre Julliard838d65a2001-06-19 19:16:41 +000059inline static BOOL is_keyboard_message( UINT message )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000060{
Alexandre Julliard838d65a2001-06-19 19:16:41 +000061 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000062}
63
Alexandre Julliard838d65a2001-06-19 19:16:41 +000064
65/***********************************************************************
66 * is_mouse_message
67 */
68inline static BOOL is_mouse_message( UINT message )
69{
70 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
71 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
72}
73
74
75/***********************************************************************
76 * check_message_filter
77 */
78inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
79{
80 if (hwnd)
81 {
82 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
83 }
84 if (first || last)
85 {
86 return (msg->message >= first && msg->message <= last);
87 }
88 return TRUE;
89}
90
91
92/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +000093 * process_sent_messages
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000094 *
Alexandre Julliardd253c582001-08-07 19:19:08 +000095 * Process all pending sent messages.
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000096 */
Alexandre Julliardd253c582001-08-07 19:19:08 +000097inline static void process_sent_messages(void)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000098{
Alexandre Julliardd253c582001-08-07 19:19:08 +000099 MSG msg;
100 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000101}
102
103
104/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000105 * queue_hardware_message
106 *
107 * store a hardware message in the thread queue
108 */
Alexandre Julliard242e3952003-01-08 00:27:58 +0000109#if 0
110static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000111{
112 SERVER_START_REQ( send_message )
113 {
Alexandre Julliard242e3952003-01-08 00:27:58 +0000114 req->type = MSG_HARDWARE;
Alexandre Julliard54f22872002-10-03 19:54:57 +0000115 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000116 req->win = msg->hwnd;
117 req->msg = msg->message;
118 req->wparam = msg->wParam;
119 req->lparam = msg->lParam;
120 req->x = msg->pt.x;
121 req->y = msg->pt.y;
122 req->time = msg->time;
123 req->info = extra_info;
Alexandre Julliardd253c582001-08-07 19:19:08 +0000124 req->timeout = 0;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000125 wine_server_call( req );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000126 }
127 SERVER_END_REQ;
128}
Alexandre Julliard242e3952003-01-08 00:27:58 +0000129#endif
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000130
131
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000132/***********************************************************************
Alexandre Julliard77b99181997-09-14 17:17:23 +0000133 * MSG_SendParentNotify
134 *
135 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
136 * the window has the WS_EX_NOPARENTNOTIFY style.
137 */
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000138static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
Alexandre Julliard77b99181997-09-14 17:17:23 +0000139{
Alexandre Julliard77b99181997-09-14 17:17:23 +0000140 /* pt has to be in the client coordinates of the parent window */
Alexandre Julliard4ff32c82001-08-18 18:08:26 +0000141 MapWindowPoints( 0, hwnd, &pt, 1 );
142 for (;;)
Alexandre Julliard77b99181997-09-14 17:17:23 +0000143 {
Alexandre Julliard4ff32c82001-08-18 18:08:26 +0000144 HWND parent;
145
146 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
147 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
148 if (!(parent = GetParent(hwnd))) break;
149 MapWindowPoints( hwnd, parent, &pt, 1 );
150 hwnd = parent;
151 SendMessageA( hwnd, WM_PARENTNOTIFY,
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000152 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000153 }
Alexandre Julliard77b99181997-09-14 17:17:23 +0000154}
155
156
Alexandre Julliard02861352002-10-29 00:41:42 +0000157#if 0 /* this is broken for now, will require proper support in the server */
158
Alexandre Julliard77b99181997-09-14 17:17:23 +0000159/***********************************************************************
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000160 * MSG_JournalPlayBackMsg
161 *
Vincent Béron9a624912002-05-31 23:06:46 +0000162 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000163 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000164void MSG_JournalPlayBackMsg(void)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000165{
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000166 EVENTMSG tmpMsg;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000167 MSG msg;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000168 LRESULT wtime;
169 int keyDown,i;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000170
Alexandre Julliard02861352002-10-29 00:41:42 +0000171 wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000172 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
173 if (wtime<=0)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000174 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000175 wtime=0;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000176 msg.message = tmpMsg.message;
177 msg.hwnd = tmpMsg.hwnd;
178 msg.time = tmpMsg.time;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000179 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
180 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000181 msg.wParam = tmpMsg.paramL & 0xFF;
182 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000183 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
184 {
185 for (keyDown=i=0; i<256 && !keyDown; i++)
186 if (InputKeyStateTable[i] & 0x80)
187 keyDown++;
188 if (!keyDown)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000189 msg.lParam |= 0x40000000;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000190 InputKeyStateTable[msg.wParam] |= 0x80;
191 AsyncKeyStateTable[msg.wParam] |= 0x80;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000192 }
193 else /* WM_KEYUP, WM_SYSKEYUP */
194 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000195 msg.lParam |= 0xC0000000;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000196 InputKeyStateTable[msg.wParam] &= ~0x80;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000197 }
198 if (InputKeyStateTable[VK_MENU] & 0x80)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000199 msg.lParam |= 0x20000000;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000200 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000201 msg.lParam |= 0x01000000;
202
203 msg.pt.x = msg.pt.y = 0;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000204 queue_hardware_message( &msg, 0 );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000205 }
206 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
207 {
208 switch (tmpMsg.message)
209 {
210 case WM_LBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000211 InputKeyStateTable[VK_LBUTTON] |= 0x80;
212 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
213 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000214 case WM_LBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000215 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
216 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000217 case WM_MBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000218 InputKeyStateTable[VK_MBUTTON] |= 0x80;
219 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
220 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000221 case WM_MBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000222 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
223 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000224 case WM_RBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000225 InputKeyStateTable[VK_RBUTTON] |= 0x80;
226 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
227 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000228 case WM_RBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000229 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
230 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000231 }
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000232 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000233 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
234 msg.wParam=0;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000235 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
236 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
237 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000238
239 msg.pt.x = tmpMsg.paramL;
240 msg.pt.y = tmpMsg.paramH;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000241 queue_hardware_message( &msg, 0 );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000242 }
Alexandre Julliard02861352002-10-29 00:41:42 +0000243 HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE );
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000244 }
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000245 else
246 {
Alexandre Julliard02861352002-10-29 00:41:42 +0000247 if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000248 }
249}
Alexandre Julliard02861352002-10-29 00:41:42 +0000250#endif
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000251
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000252
Alexandre Julliardaca05781994-10-17 18:12:41 +0000253/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000254 * process_raw_keyboard_message
Alexandre Julliardaca05781994-10-17 18:12:41 +0000255 *
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000256 * returns TRUE if the contents of 'msg' should be passed to the application
Alexandre Julliardaca05781994-10-17 18:12:41 +0000257 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000258static void process_raw_keyboard_message( MSG *msg )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000259{
Alexandre Julliard02861352002-10-29 00:41:42 +0000260 EVENTMSG event;
261
Alexandre Julliard02861352002-10-29 00:41:42 +0000262 event.message = msg->message;
263 event.hwnd = msg->hwnd;
264 event.time = msg->time;
265 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
266 event.paramH = msg->lParam & 0x7FFF;
267 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
268 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000269}
270
271
272/***********************************************************************
273 * process_cooked_keyboard_message
274 *
275 * returns TRUE if the contents of 'msg' should be passed to the application
276 */
277static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
278{
279 if (remove)
280 {
281 /* Handle F1 key by sending out WM_HELP message */
282 if ((msg->message == WM_KEYUP) &&
283 (msg->wParam == VK_F1) &&
284 (msg->hwnd != GetDesktopWindow()) &&
285 !MENU_IsMenuActive())
286 {
287 HELPINFO hi;
288 hi.cbSize = sizeof(HELPINFO);
289 hi.iContextType = HELPINFO_WINDOW;
290 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
291 hi.hItemHandle = msg->hwnd;
292 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
293 hi.MousePos = msg->pt;
294 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
295 }
296 }
297
Alexandre Julliard02861352002-10-29 00:41:42 +0000298 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
299 LOWORD(msg->wParam), msg->lParam, TRUE ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000300 {
301 /* skip this message */
Alexandre Julliard02861352002-10-29 00:41:42 +0000302 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000303 return FALSE;
304 }
305 return TRUE;
306}
307
308
309/***********************************************************************
310 * process_raw_mouse_message
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000311 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000312static void process_raw_mouse_message( MSG *msg, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000313{
314 static MSG clk_msg;
315
316 POINT pt;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000317 INT hittest;
Alexandre Julliard02861352002-10-29 00:41:42 +0000318 EVENTMSG event;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000319 GUITHREADINFO info;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000320 HWND hWndScope = msg->hwnd;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000321
322 /* find the window to dispatch this mouse message to */
323
Alexandre Julliardee8ab7a2001-06-20 23:16:34 +0000324 hittest = HTCLIENT;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000325 GetGUIThreadInfo( GetCurrentThreadId(), &info );
326 if (!(msg->hwnd = info.hwndCapture))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000327 {
328 /* If no capture HWND, find window which contains the mouse position.
329 * Also find the position of the cursor hot spot (hittest) */
Alexandre Julliardee8ab7a2001-06-20 23:16:34 +0000330 if (!IsWindow(hWndScope)) hWndScope = 0;
331 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
332 msg->hwnd = GetDesktopWindow();
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000333 }
334
Alexandre Julliard02861352002-10-29 00:41:42 +0000335 event.message = msg->message;
336 event.time = msg->time;
337 event.hwnd = msg->hwnd;
338 event.paramL = msg->pt.x;
339 event.paramH = msg->pt.y;
340 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000341
342 /* translate double clicks */
343
344 if ((msg->message == WM_LBUTTONDOWN) ||
345 (msg->message == WM_RBUTTONDOWN) ||
346 (msg->message == WM_MBUTTONDOWN))
347 {
Alexandre Julliard242e3952003-01-08 00:27:58 +0000348 BOOL update = remove;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000349 /* translate double clicks -
350 * note that ...MOUSEMOVEs can slip in between
351 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
352
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000353 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
354 hittest != HTCLIENT ||
355 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000356 {
357 if ((msg->message == clk_msg.message) &&
358 (msg->hwnd == clk_msg.hwnd) &&
Andriy Palamarchuk2489dc92001-12-06 22:28:43 +0000359 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000360 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
361 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
362 {
363 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
Alexandre Julliard242e3952003-01-08 00:27:58 +0000364 if (remove)
365 {
366 clk_msg.message = 0;
367 update = FALSE;
368 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000369 }
370 }
371 /* update static double click conditions */
372 if (update) clk_msg = *msg;
373 }
374
375 pt = msg->pt;
Travis Michielsenb9bd3f82001-06-29 01:17:55 +0000376 /* Note: windows has no concept of a non-client wheel message */
377 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000378 {
379 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
380 msg->wParam = hittest;
381 }
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000382 else
383 {
384 /* coordinates don't get translated while tracking a menu */
385 /* FIXME: should differentiate popups and top-level menus */
386 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
387 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000388 msg->lParam = MAKELONG( pt.x, pt.y );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000389}
390
391
392/***********************************************************************
393 * process_cooked_mouse_message
394 *
395 * returns TRUE if the contents of 'msg' should be passed to the application
396 */
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000397static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000398{
Alexandre Julliard02861352002-10-29 00:41:42 +0000399 MOUSEHOOKSTRUCT hook;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000400 INT hittest = HTCLIENT;
401 UINT raw_message = msg->message;
402 BOOL eatMsg;
403
404 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
405 {
406 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
407 hittest = msg->wParam;
408 }
409 if (raw_message == WM_LBUTTONDBLCLK ||
410 raw_message == WM_RBUTTONDBLCLK ||
411 raw_message == WM_MBUTTONDBLCLK)
412 {
413 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
414 }
415
Alexandre Julliard02861352002-10-29 00:41:42 +0000416 hook.pt = msg->pt;
417 hook.hwnd = msg->hwnd;
418 hook.wHitTestCode = hittest;
419 hook.dwExtraInfo = extra_info;
420 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
421 msg->message, (LPARAM)&hook, TRUE ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000422 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000423 hook.pt = msg->pt;
424 hook.hwnd = msg->hwnd;
425 hook.wHitTestCode = hittest;
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000426 hook.dwExtraInfo = extra_info;
Alexandre Julliard02861352002-10-29 00:41:42 +0000427 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
428 return FALSE;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000429 }
430
431 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
432 {
Michael Stefaniuc2247af32002-09-04 19:37:01 +0000433 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
434 MAKELONG( hittest, raw_message ));
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000435 return FALSE;
436 }
437
438 if (!remove || GetCapture()) return TRUE;
439
440 eatMsg = FALSE;
441
442 if ((raw_message == WM_LBUTTONDOWN) ||
443 (raw_message == WM_RBUTTONDOWN) ||
444 (raw_message == WM_MBUTTONDOWN))
445 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000446 /* Send the WM_PARENTNOTIFY,
447 * note that even for double/nonclient clicks
448 * notification message is still WM_L/M/RBUTTONDOWN.
449 */
450 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
451
452 /* Activate the window if needed */
453
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000454 if (msg->hwnd != GetActiveWindow())
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000455 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000456 HWND hwndTop = msg->hwnd;
457 while (hwndTop)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000458 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000459 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
460 hwndTop = GetParent( hwndTop );
461 }
462
463 if (hwndTop && hwndTop != GetDesktopWindow())
464 {
465 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
466 MAKELONG( hittest, raw_message ) );
467 switch(ret)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000468 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000469 case MA_NOACTIVATEANDEAT:
470 eatMsg = TRUE;
471 /* fall through */
472 case MA_NOACTIVATE:
473 break;
474 case MA_ACTIVATEANDEAT:
475 eatMsg = TRUE;
476 /* fall through */
477 case MA_ACTIVATE:
478 case 0:
479 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
480 break;
481 default:
482 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
483 break;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000484 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000485 }
486 }
487 }
488
489 /* send the WM_SETCURSOR message */
490
491 /* Windows sends the normal mouse message as the message parameter
492 in the WM_SETCURSOR message even if it's non-client mouse message */
Michael Stefaniuc2247af32002-09-04 19:37:01 +0000493 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
494 MAKELONG( hittest, raw_message ));
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000495
496 return !eatMsg;
497}
498
499
500/***********************************************************************
501 * process_hardware_message
502 *
503 * returns TRUE if the contents of 'msg' should be passed to the application
504 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000505BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
506 UINT first, UINT last, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000507{
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000508 if (is_keyboard_message( msg->message ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000509 {
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000510 process_raw_keyboard_message( msg );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000511 }
512 else if (is_mouse_message( msg->message ))
513 {
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000514 process_raw_mouse_message( msg, remove );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000515 }
516 else
517 {
518 ERR( "unknown message type %x\n", msg->message );
519 return FALSE;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000520 }
Alexandre Julliard242e3952003-01-08 00:27:58 +0000521 return check_message_filter( msg, hwnd_filter, first, last );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000522}
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000523
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000524
525/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +0000526 * MSG_process_cooked_hardware_message
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000527 *
528 * returns TRUE if the contents of 'msg' should be passed to the application
529 */
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000530BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000531{
532 if (is_keyboard_message( msg->message ))
533 return process_cooked_keyboard_message( msg, remove );
534
535 if (is_mouse_message( msg->message ))
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000536 return process_cooked_mouse_message( msg, extra_info, remove );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000537
538 ERR( "unknown message type %x\n", msg->message );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000539 return FALSE;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000540}
541
542
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000543/***********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +0000544 * WaitMessage (USER.112) Suspend thread pending messages
545 * WaitMessage (USER32.@) Suspend thread pending messages
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000546 *
547 * WaitMessage() suspends a thread until events appear in the thread's
548 * queue.
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000549 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000550BOOL WINAPI WaitMessage(void)
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000551{
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000552 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000553}
554
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000555
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000556/***********************************************************************
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000557 * MsgWaitForMultipleObjectsEx (USER32.@)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000558 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000559DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
560 DWORD timeout, DWORD mask, DWORD flags )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000561{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000562 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000563 DWORD i, ret, lock;
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000564 MESSAGEQUEUE *msgQueue;
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000565
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000566 if (count > MAXIMUM_WAIT_OBJECTS-1)
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000567 {
568 SetLastError( ERROR_INVALID_PARAMETER );
569 return WAIT_FAILED;
570 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000571
Alexandre Julliard8afe6622001-07-26 20:12:22 +0000572 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000573
574 /* set the queue mask */
575 SERVER_START_REQ( set_queue_mask )
576 {
577 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
578 req->changed_mask = mask;
579 req->skip_wait = 0;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000580 wine_server_call( req );
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000581 }
582 SERVER_END_REQ;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000583
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000584 /* Add the thread event to the handle list */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000585 for (i = 0; i < count; i++) handles[i] = pHandles[i];
586 handles[count] = msgQueue->server_queue;
587
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000588 ReleaseThunkLock( &lock );
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000589 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
Alexandre Julliard43230042001-05-16 19:52:29 +0000590 {
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000591 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
592 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
Alexandre Julliard43230042001-05-16 19:52:29 +0000593 }
594 else
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000595 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
596 timeout, flags & MWMO_ALERTABLE );
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000597 if (lock) RestoreThunkLock( lock );
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000598 return ret;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000599}
600
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000601
Eric Pouech982e0ce2001-01-28 23:44:56 +0000602/***********************************************************************
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000603 * MsgWaitForMultipleObjects (USER32.@)
Eric Pouech982e0ce2001-01-28 23:44:56 +0000604 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000605DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
606 BOOL wait_all, DWORD timeout, DWORD mask )
Eric Pouech982e0ce2001-01-28 23:44:56 +0000607{
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000608 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
609 wait_all ? MWMO_WAITALL : 0 );
Eric Pouech982e0ce2001-01-28 23:44:56 +0000610}
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000611
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000612
613/***********************************************************************
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000614 * WaitForInputIdle (USER32.@)
615 */
616DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
617{
Francois Gouget671a2ee2001-10-08 20:28:12 +0000618 DWORD start_time, elapsed, ret;
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000619 HANDLE idle_event = (HANDLE)-1;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000620
621 SERVER_START_REQ( wait_input_idle )
622 {
623 req->handle = hProcess;
624 req->timeout = dwTimeOut;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000625 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000626 }
627 SERVER_END_REQ;
Francois Gouget671a2ee2001-10-08 20:28:12 +0000628 if (ret) return WAIT_FAILED; /* error */
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000629 if (!idle_event) return 0; /* no event to wait on */
630
Francois Gouget671a2ee2001-10-08 20:28:12 +0000631 start_time = GetTickCount();
632 elapsed = 0;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000633
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000634 TRACE("waiting for %p\n", idle_event );
Francois Gouget671a2ee2001-10-08 20:28:12 +0000635 do
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000636 {
Francois Gouget671a2ee2001-10-08 20:28:12 +0000637 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
638 switch (ret)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000639 {
Francois Gouget671a2ee2001-10-08 20:28:12 +0000640 case WAIT_OBJECT_0+1:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000641 process_sent_messages();
Francois Gouget671a2ee2001-10-08 20:28:12 +0000642 break;
643 case WAIT_TIMEOUT:
644 case WAIT_FAILED:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000645 TRACE("timeout or error\n");
646 return ret;
Francois Gouget671a2ee2001-10-08 20:28:12 +0000647 default:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000648 TRACE("finished\n");
649 return 0;
650 }
Francois Gouget671a2ee2001-10-08 20:28:12 +0000651 if (dwTimeOut != INFINITE)
652 {
653 elapsed = GetTickCount() - start_time;
654 if (elapsed > dwTimeOut)
655 break;
656 }
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000657 }
Francois Gouget671a2ee2001-10-08 20:28:12 +0000658 while (1);
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000659
660 return WAIT_TIMEOUT;
661}
662
663
664/***********************************************************************
665 * UserYield (USER.332)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000666 */
667void WINAPI UserYield16(void)
668{
Alexandre Julliardd253c582001-08-07 19:19:08 +0000669 DWORD count;
670
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000671 /* Handle sent messages */
672 process_sent_messages();
673
674 /* Yield */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000675 ReleaseThunkLock(&count);
676 if (count)
677 {
678 RestoreThunkLock(count);
679 /* Handle sent messages again */
680 process_sent_messages();
681 }
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000682}
683
684
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000685/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +0000686 * TranslateMessage (USER32.@)
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000687 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000688 * Implementation of TranslateMessage.
689 *
690 * TranslateMessage translates virtual-key messages into character-messages,
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000691 * as follows :
692 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
693 * ditto replacing WM_* with WM_SYS*
694 * This produces WM_CHAR messages only for keys mapped to ASCII characters
695 * by the keyboard driver.
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000696 *
697 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
698 * return value is nonzero, regardless of the translation.
699 *
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000700 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000701BOOL WINAPI TranslateMessage( const MSG *msg )
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000702{
Alexandre Julliardd253c582001-08-07 19:19:08 +0000703 UINT message;
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +0000704 WCHAR wp[2];
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000705 BOOL rc = FALSE;
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000706 BYTE state[256];
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000707
Alexandre Julliardd253c582001-08-07 19:19:08 +0000708 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000709 {
Alexandre Julliardd253c582001-08-07 19:19:08 +0000710 TRACE_(key)("(%s, %04X, %08lX)\n",
Guy L. Albertellidb9b5492001-09-07 18:38:57 +0000711 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
Alexandre Julliardd253c582001-08-07 19:19:08 +0000712
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000713 /* Return code must be TRUE no matter what! */
714 rc = TRUE;
715 }
716
717 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000718
Dmitry Timoshkov740bb922000-11-05 20:07:59 +0000719 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
Alexandre Julliardd253c582001-08-07 19:19:08 +0000720 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000721
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000722 GetKeyboardState( state );
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +0000723 /* FIXME : should handle ToUnicode yielding 2 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000724 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000725 {
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000726 case 1:
Alexandre Julliardd253c582001-08-07 19:19:08 +0000727 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
Mike McCormack020f8a42003-05-19 18:56:49 +0000728 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
729 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
Alexandre Julliardd253c582001-08-07 19:19:08 +0000730 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000731 break;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000732
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000733 case -1:
Alexandre Julliardd253c582001-08-07 19:19:08 +0000734 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
Mike McCormack020f8a42003-05-19 18:56:49 +0000735 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
736 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
Alexandre Julliardd253c582001-08-07 19:19:08 +0000737 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000738 return TRUE;
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000739 }
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000740 return rc;
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000741}
742
743
744/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000745 * DispatchMessageA (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000746 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000747LONG WINAPI DispatchMessageA( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000748{
749 WND * wndPtr;
750 LONG retval;
751 int painting;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000752 WNDPROC winproc;
753
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000754 /* Process timer messages */
755 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
756 {
757 if (msg->lParam)
758 {
759/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000760
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000761 /* before calling window proc, verify whether timer is still valid;
762 there's a slim chance that the application kills the timer
763 between GetMessage and DispatchMessage API calls */
Alexandre Julliard18d02972002-12-03 23:34:52 +0000764 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000765 return 0; /* invalid winproc */
766
Alexandre Julliarda3960291999-02-26 11:11:13 +0000767 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000768 msg->message, msg->wParam, GetTickCount() );
769 }
770 }
771
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000772 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000773 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000774 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
775 return 0;
776 }
777 if (wndPtr == WND_OTHER_PROCESS)
778 {
779 if (IsWindow( msg->hwnd ))
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000780 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000781 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
782 return 0;
783 }
784 if (!(winproc = wndPtr->winproc))
785 {
786 WIN_ReleasePtr( wndPtr );
787 return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000788 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000789 painting = (msg->message == WM_PAINT);
790 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000791 WIN_ReleasePtr( wndPtr );
792/* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000793
Alexandre Julliarda3960291999-02-26 11:11:13 +0000794 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000795 msg->wParam, msg->lParam );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000796 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
797 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +0000798 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000799 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000800
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000801 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000802 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000803 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
804 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
805 WIN_ReleasePtr( wndPtr );
806 if (validate)
807 {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000808 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000809 /* Validate the update region to avoid infinite WM_PAINT loop */
810 RedrawWindow( msg->hwnd, NULL, 0,
811 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
812 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000813 }
814 return retval;
815}
816
817
818/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000819 * DispatchMessageW (USER32.@) Process Message
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000820 *
821 * Process the message specified in the structure *_msg_.
822 *
823 * If the lpMsg parameter points to a WM_TIMER message and the
824 * parameter of the WM_TIMER message is not NULL, the lParam parameter
825 * points to the function that is called instead of the window
826 * procedure.
Vincent Béron9a624912002-05-31 23:06:46 +0000827 *
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000828 * The message must be valid.
829 *
830 * RETURNS
831 *
832 * DispatchMessage() returns the result of the window procedure invoked.
833 *
834 * CONFORMANCE
835 *
Vincent Béron9a624912002-05-31 23:06:46 +0000836 * ECMA-234, Win32
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000837 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000838 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000839LONG WINAPI DispatchMessageW( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000840{
841 WND * wndPtr;
842 LONG retval;
843 int painting;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000844 WNDPROC winproc;
845
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000846 /* Process timer messages */
847 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
848 {
849 if (msg->lParam)
850 {
851/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000852
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000853 /* before calling window proc, verify whether timer is still valid;
854 there's a slim chance that the application kills the timer
855 between GetMessage and DispatchMessage API calls */
Alexandre Julliard18d02972002-12-03 23:34:52 +0000856 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000857 return 0; /* invalid winproc */
858
Alexandre Julliarda3960291999-02-26 11:11:13 +0000859 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000860 msg->message, msg->wParam, GetTickCount() );
861 }
862 }
863
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000864 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000865 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000866 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
867 return 0;
868 }
869 if (wndPtr == WND_OTHER_PROCESS)
870 {
871 if (IsWindow( msg->hwnd ))
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000872 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000873 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
874 return 0;
875 }
876 if (!(winproc = wndPtr->winproc))
877 {
878 WIN_ReleasePtr( wndPtr );
879 return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000880 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000881 painting = (msg->message == WM_PAINT);
882 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000883 WIN_ReleasePtr( wndPtr );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000884/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
885
Alexandre Julliarda3960291999-02-26 11:11:13 +0000886 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000887 msg->wParam, msg->lParam );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000888 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
889 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +0000890 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000891 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000892
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000893 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000894 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000895 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
896 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
897 WIN_ReleasePtr( wndPtr );
898 if (validate)
899 {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000900 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000901 /* Validate the update region to avoid infinite WM_PAINT loop */
902 RedrawWindow( msg->hwnd, NULL, 0,
903 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
904 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000905 }
906 return retval;
907}
908
909
910/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000911 * RegisterWindowMessage (USER.118)
912 * RegisterWindowMessageA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000913 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000914WORD WINAPI RegisterWindowMessageA( LPCSTR str )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000915{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000916 TRACE("%s\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000917 return GlobalAddAtomA( str );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000918}
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000919
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000920
921/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000922 * RegisterWindowMessageW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000923 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000924WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000925{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000926 TRACE("%p\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000927 return GlobalAddAtomW( str );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000928}
929
930
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000931/***********************************************************************
Patrik Stridvallfc343442002-08-20 00:20:43 +0000932 * BroadcastSystemMessage (USER32.@)
933 * BroadcastSystemMessageA (USER32.@)
Alexandre Julliarde658d821997-11-30 17:45:40 +0000934 */
935LONG WINAPI BroadcastSystemMessage(
Alexandre Julliarda3960291999-02-26 11:11:13 +0000936 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
Aric Stewart5501f122002-08-16 23:29:48 +0000937 LPARAM lParam )
938{
939 if ((*recipients & BSM_APPLICATIONS)||
940 (*recipients == BSM_ALLCOMPONENTS))
941 {
942 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
943 dwFlags,*recipients,uMessage,wParam,lParam);
944 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
945 return 1;
946 }
947 else
948 {
949 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
950 dwFlags,*recipients,uMessage,wParam,lParam);
951 return -1;
952 }
Alexandre Julliarde658d821997-11-30 17:45:40 +0000953}
Mike McCormack020f8a42003-05-19 18:56:49 +0000954
955/***********************************************************************
956 * BroadcastSystemMessageW (USER32.@)
957 */
958LONG WINAPI BroadcastSystemMessageW(
959 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
960 LPARAM lParam )
961{
962 if ((*recipients & BSM_APPLICATIONS)||
963 (*recipients == BSM_ALLCOMPONENTS))
964 {
965 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
966 dwFlags,*recipients,uMessage,wParam,lParam);
967 PostMessageW(HWND_BROADCAST,uMessage,wParam,lParam);
968 return 1;
969 }
970 else
971 {
972 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
973 dwFlags,*recipients,uMessage,wParam,lParam);
974 return -1;
975 }
976}