blob: cd4de4ac4f3dbddb245a7e2f7b6d2808f3a23043 [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"
Steven Edwardscfcc4492003-11-26 22:29:30 +000022#include "wine/port.h"
Patrik Stridvalld016f812002-08-17 00:43:16 +000023
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000024#include <stdarg.h>
Alexandre Julliard401710d1993-09-04 10:09:32 +000025#include <stdlib.h>
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000026#include <string.h>
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +000027#include <ctype.h>
Patrik Stridvalld016f812002-08-17 00:43:16 +000028#ifdef HAVE_SYS_TIME_H
29# include <sys/time.h>
30#endif
Alexandre Julliard5f721f81994-01-04 20:14:34 +000031#include <sys/types.h>
Alexandre Julliardf41aeca1993-09-14 16:47:10 +000032
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000033#include "windef.h"
Alexandre Julliardd253c582001-08-07 19:19:08 +000034#include "winbase.h"
35#include "wingdi.h"
36#include "winuser.h"
Alexandre Julliard75a839a1993-07-15 11:13:45 +000037#include "message.h"
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +000038#include "winerror.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000039#include "ntstatus.h"
Alexandre Julliard37e95032001-07-19 00:39:09 +000040#include "wine/server.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000041#include "controls.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000042#include "dde.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000043#include "message.h"
Alexandre Julliard18d02972002-12-03 23:34:52 +000044#include "user.h"
45#include "win.h"
46#include "winpos.h"
47#include "winproc.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000048#include "wine/debug.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000049
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000050WINE_DEFAULT_DEBUG_CHANNEL(msg);
51WINE_DECLARE_DEBUG_CHANNEL(key);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000052
Alexandre Julliardac9c9b01996-07-28 18:50:11 +000053#define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
54#define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
55
Alexandre Julliard838d65a2001-06-19 19:16:41 +000056
Alexandre Julliard75a839a1993-07-15 11:13:45 +000057/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +000058 * is_keyboard_message
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000059 */
Alexandre Julliard838d65a2001-06-19 19:16:41 +000060inline static BOOL is_keyboard_message( UINT message )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000061{
Alexandre Julliard838d65a2001-06-19 19:16:41 +000062 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000063}
64
Alexandre Julliard838d65a2001-06-19 19:16:41 +000065
66/***********************************************************************
67 * is_mouse_message
68 */
69inline static BOOL is_mouse_message( UINT message )
70{
71 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
72 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
73}
74
75
76/***********************************************************************
77 * check_message_filter
78 */
79inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
80{
81 if (hwnd)
82 {
83 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
84 }
85 if (first || last)
86 {
87 return (msg->message >= first && msg->message <= last);
88 }
89 return TRUE;
90}
91
92
93/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +000094 * process_sent_messages
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000095 *
Alexandre Julliardd253c582001-08-07 19:19:08 +000096 * Process all pending sent messages.
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000097 */
Alexandre Julliardd253c582001-08-07 19:19:08 +000098inline static void process_sent_messages(void)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +000099{
Alexandre Julliardd253c582001-08-07 19:19:08 +0000100 MSG msg;
101 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000102}
103
104
105/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000106 * queue_hardware_message
107 *
108 * store a hardware message in the thread queue
109 */
Alexandre Julliard242e3952003-01-08 00:27:58 +0000110#if 0
111static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000112{
113 SERVER_START_REQ( send_message )
114 {
Alexandre Julliard242e3952003-01-08 00:27:58 +0000115 req->type = MSG_HARDWARE;
Alexandre Julliard54f22872002-10-03 19:54:57 +0000116 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000117 req->win = msg->hwnd;
118 req->msg = msg->message;
119 req->wparam = msg->wParam;
120 req->lparam = msg->lParam;
121 req->x = msg->pt.x;
122 req->y = msg->pt.y;
123 req->time = msg->time;
124 req->info = extra_info;
Alexandre Julliardd253c582001-08-07 19:19:08 +0000125 req->timeout = 0;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000126 wine_server_call( req );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000127 }
128 SERVER_END_REQ;
129}
Alexandre Julliard242e3952003-01-08 00:27:58 +0000130#endif
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000131
132
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000133/***********************************************************************
Alexandre Julliard77b99181997-09-14 17:17:23 +0000134 * MSG_SendParentNotify
135 *
136 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
137 * the window has the WS_EX_NOPARENTNOTIFY style.
138 */
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000139static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
Alexandre Julliard77b99181997-09-14 17:17:23 +0000140{
Alexandre Julliard77b99181997-09-14 17:17:23 +0000141 /* pt has to be in the client coordinates of the parent window */
Alexandre Julliard4ff32c82001-08-18 18:08:26 +0000142 MapWindowPoints( 0, hwnd, &pt, 1 );
143 for (;;)
Alexandre Julliard77b99181997-09-14 17:17:23 +0000144 {
Alexandre Julliard4ff32c82001-08-18 18:08:26 +0000145 HWND parent;
146
147 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
148 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
149 if (!(parent = GetParent(hwnd))) break;
150 MapWindowPoints( hwnd, parent, &pt, 1 );
151 hwnd = parent;
152 SendMessageA( hwnd, WM_PARENTNOTIFY,
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000153 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
Alexandre Julliard77b99181997-09-14 17:17:23 +0000154 }
Alexandre Julliard77b99181997-09-14 17:17:23 +0000155}
156
157
Alexandre Julliard02861352002-10-29 00:41:42 +0000158#if 0 /* this is broken for now, will require proper support in the server */
159
Alexandre Julliard77b99181997-09-14 17:17:23 +0000160/***********************************************************************
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000161 * MSG_JournalPlayBackMsg
162 *
Vincent Béron9a624912002-05-31 23:06:46 +0000163 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000164 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000165void MSG_JournalPlayBackMsg(void)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000166{
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000167 EVENTMSG tmpMsg;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000168 MSG msg;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000169 LRESULT wtime;
170 int keyDown,i;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000171
Alexandre Julliard02861352002-10-29 00:41:42 +0000172 wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000173 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
174 if (wtime<=0)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000175 {
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000176 wtime=0;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000177 msg.message = tmpMsg.message;
178 msg.hwnd = tmpMsg.hwnd;
179 msg.time = tmpMsg.time;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000180 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
181 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000182 msg.wParam = tmpMsg.paramL & 0xFF;
183 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000184 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
185 {
186 for (keyDown=i=0; i<256 && !keyDown; i++)
187 if (InputKeyStateTable[i] & 0x80)
188 keyDown++;
189 if (!keyDown)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000190 msg.lParam |= 0x40000000;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000191 InputKeyStateTable[msg.wParam] |= 0x80;
192 AsyncKeyStateTable[msg.wParam] |= 0x80;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000193 }
194 else /* WM_KEYUP, WM_SYSKEYUP */
195 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000196 msg.lParam |= 0xC0000000;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000197 InputKeyStateTable[msg.wParam] &= ~0x80;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000198 }
199 if (InputKeyStateTable[VK_MENU] & 0x80)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000200 msg.lParam |= 0x20000000;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000201 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000202 msg.lParam |= 0x01000000;
203
204 msg.pt.x = msg.pt.y = 0;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000205 queue_hardware_message( &msg, 0 );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000206 }
207 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
208 {
209 switch (tmpMsg.message)
210 {
211 case WM_LBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000212 InputKeyStateTable[VK_LBUTTON] |= 0x80;
213 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
214 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000215 case WM_LBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000216 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
217 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000218 case WM_MBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000219 InputKeyStateTable[VK_MBUTTON] |= 0x80;
220 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
221 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000222 case WM_MBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000223 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
224 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000225 case WM_RBUTTONDOWN:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000226 InputKeyStateTable[VK_RBUTTON] |= 0x80;
227 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
228 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000229 case WM_RBUTTONUP:
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000230 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
231 break;
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000232 }
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000233 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000234 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
235 msg.wParam=0;
Alexandre Julliarda21672e2001-10-02 18:53:59 +0000236 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
237 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
238 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000239
240 msg.pt.x = tmpMsg.paramL;
241 msg.pt.y = tmpMsg.paramH;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000242 queue_hardware_message( &msg, 0 );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000243 }
Alexandre Julliard02861352002-10-29 00:41:42 +0000244 HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE );
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000245 }
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000246 else
247 {
Alexandre Julliard02861352002-10-29 00:41:42 +0000248 if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE );
Alexandre Julliardda2892c2001-02-23 01:13:42 +0000249 }
250}
Alexandre Julliard02861352002-10-29 00:41:42 +0000251#endif
Alexandre Julliard940d58c1994-09-16 09:24:37 +0000252
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000253
Alexandre Julliardaca05781994-10-17 18:12:41 +0000254/***********************************************************************
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000255 * process_raw_keyboard_message
Alexandre Julliardaca05781994-10-17 18:12:41 +0000256 *
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000257 * returns TRUE if the contents of 'msg' should be passed to the application
Alexandre Julliardaca05781994-10-17 18:12:41 +0000258 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000259static void process_raw_keyboard_message( MSG *msg )
Alexandre Julliardaca05781994-10-17 18:12:41 +0000260{
Alexandre Julliard02861352002-10-29 00:41:42 +0000261 EVENTMSG event;
262
Alexandre Julliard02861352002-10-29 00:41:42 +0000263 event.message = msg->message;
264 event.hwnd = msg->hwnd;
265 event.time = msg->time;
266 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
267 event.paramH = msg->lParam & 0x7FFF;
268 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
269 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000270}
271
272
273/***********************************************************************
274 * process_cooked_keyboard_message
275 *
276 * returns TRUE if the contents of 'msg' should be passed to the application
277 */
278static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
279{
280 if (remove)
281 {
282 /* Handle F1 key by sending out WM_HELP message */
283 if ((msg->message == WM_KEYUP) &&
284 (msg->wParam == VK_F1) &&
285 (msg->hwnd != GetDesktopWindow()) &&
286 !MENU_IsMenuActive())
287 {
288 HELPINFO hi;
289 hi.cbSize = sizeof(HELPINFO);
290 hi.iContextType = HELPINFO_WINDOW;
291 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
292 hi.hItemHandle = msg->hwnd;
293 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
294 hi.MousePos = msg->pt;
295 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
296 }
297 }
298
Alexandre Julliard02861352002-10-29 00:41:42 +0000299 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
300 LOWORD(msg->wParam), msg->lParam, TRUE ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000301 {
302 /* skip this message */
Alexandre Julliard02861352002-10-29 00:41:42 +0000303 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000304 return FALSE;
305 }
306 return TRUE;
307}
308
309
310/***********************************************************************
311 * process_raw_mouse_message
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000312 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000313static void process_raw_mouse_message( MSG *msg, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000314{
315 static MSG clk_msg;
316
317 POINT pt;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000318 INT hittest;
Alexandre Julliard02861352002-10-29 00:41:42 +0000319 EVENTMSG event;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000320 GUITHREADINFO info;
Alexandre Julliard242e3952003-01-08 00:27:58 +0000321 HWND hWndScope = msg->hwnd;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000322
323 /* find the window to dispatch this mouse message to */
324
Alexandre Julliardee8ab7a2001-06-20 23:16:34 +0000325 hittest = HTCLIENT;
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000326 GetGUIThreadInfo( GetCurrentThreadId(), &info );
327 if (!(msg->hwnd = info.hwndCapture))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000328 {
329 /* If no capture HWND, find window which contains the mouse position.
330 * Also find the position of the cursor hot spot (hittest) */
Alexandre Julliardee8ab7a2001-06-20 23:16:34 +0000331 if (!IsWindow(hWndScope)) hWndScope = 0;
332 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
333 msg->hwnd = GetDesktopWindow();
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000334 }
335
Alexandre Julliard02861352002-10-29 00:41:42 +0000336 event.message = msg->message;
337 event.time = msg->time;
338 event.hwnd = msg->hwnd;
339 event.paramL = msg->pt.x;
340 event.paramH = msg->pt.y;
341 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000342
343 /* translate double clicks */
344
345 if ((msg->message == WM_LBUTTONDOWN) ||
346 (msg->message == WM_RBUTTONDOWN) ||
347 (msg->message == WM_MBUTTONDOWN))
348 {
Alexandre Julliard242e3952003-01-08 00:27:58 +0000349 BOOL update = remove;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000350 /* translate double clicks -
351 * note that ...MOUSEMOVEs can slip in between
352 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
353
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000354 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
355 hittest != HTCLIENT ||
356 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000357 {
358 if ((msg->message == clk_msg.message) &&
359 (msg->hwnd == clk_msg.hwnd) &&
Andriy Palamarchuk2489dc92001-12-06 22:28:43 +0000360 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000361 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
362 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
363 {
364 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
Alexandre Julliard242e3952003-01-08 00:27:58 +0000365 if (remove)
366 {
367 clk_msg.message = 0;
368 update = FALSE;
369 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000370 }
371 }
372 /* update static double click conditions */
373 if (update) clk_msg = *msg;
374 }
375
376 pt = msg->pt;
Travis Michielsenb9bd3f82001-06-29 01:17:55 +0000377 /* Note: windows has no concept of a non-client wheel message */
378 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000379 {
380 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
381 msg->wParam = hittest;
382 }
Alexandre Julliarda9e8f592002-10-12 01:24:37 +0000383 else
384 {
385 /* coordinates don't get translated while tracking a menu */
386 /* FIXME: should differentiate popups and top-level menus */
387 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
388 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000389 msg->lParam = MAKELONG( pt.x, pt.y );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000390}
391
392
393/***********************************************************************
394 * process_cooked_mouse_message
395 *
396 * returns TRUE if the contents of 'msg' should be passed to the application
397 */
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000398static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000399{
Alexandre Julliard02861352002-10-29 00:41:42 +0000400 MOUSEHOOKSTRUCT hook;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000401 INT hittest = HTCLIENT;
402 UINT raw_message = msg->message;
403 BOOL eatMsg;
404
405 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
406 {
407 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
408 hittest = msg->wParam;
409 }
410 if (raw_message == WM_LBUTTONDBLCLK ||
411 raw_message == WM_RBUTTONDBLCLK ||
412 raw_message == WM_MBUTTONDBLCLK)
413 {
414 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
415 }
416
Alexandre Julliard02861352002-10-29 00:41:42 +0000417 hook.pt = msg->pt;
418 hook.hwnd = msg->hwnd;
419 hook.wHitTestCode = hittest;
420 hook.dwExtraInfo = extra_info;
421 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
422 msg->message, (LPARAM)&hook, TRUE ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000423 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000424 hook.pt = msg->pt;
425 hook.hwnd = msg->hwnd;
426 hook.wHitTestCode = hittest;
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000427 hook.dwExtraInfo = extra_info;
Alexandre Julliard02861352002-10-29 00:41:42 +0000428 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
429 return FALSE;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000430 }
431
432 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
433 {
Michael Stefaniuc2247af32002-09-04 19:37:01 +0000434 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
435 MAKELONG( hittest, raw_message ));
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000436 return FALSE;
437 }
438
439 if (!remove || GetCapture()) return TRUE;
440
441 eatMsg = FALSE;
442
443 if ((raw_message == WM_LBUTTONDOWN) ||
444 (raw_message == WM_RBUTTONDOWN) ||
445 (raw_message == WM_MBUTTONDOWN))
446 {
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000447 /* Send the WM_PARENTNOTIFY,
448 * note that even for double/nonclient clicks
449 * notification message is still WM_L/M/RBUTTONDOWN.
450 */
451 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
452
453 /* Activate the window if needed */
454
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000455 if (msg->hwnd != GetActiveWindow())
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000456 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000457 HWND hwndTop = msg->hwnd;
458 while (hwndTop)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000459 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000460 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
461 hwndTop = GetParent( hwndTop );
462 }
463
464 if (hwndTop && hwndTop != GetDesktopWindow())
465 {
466 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
467 MAKELONG( hittest, raw_message ) );
468 switch(ret)
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000469 {
Alexandre Julliard5030bda2002-10-11 23:41:06 +0000470 case MA_NOACTIVATEANDEAT:
471 eatMsg = TRUE;
472 /* fall through */
473 case MA_NOACTIVATE:
474 break;
475 case MA_ACTIVATEANDEAT:
476 eatMsg = TRUE;
477 /* fall through */
478 case MA_ACTIVATE:
479 case 0:
480 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
481 break;
482 default:
483 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
484 break;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000485 }
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000486 }
487 }
488 }
489
490 /* send the WM_SETCURSOR message */
491
492 /* Windows sends the normal mouse message as the message parameter
493 in the WM_SETCURSOR message even if it's non-client mouse message */
Michael Stefaniuc2247af32002-09-04 19:37:01 +0000494 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
495 MAKELONG( hittest, raw_message ));
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000496
497 return !eatMsg;
498}
499
500
501/***********************************************************************
502 * process_hardware_message
503 *
504 * returns TRUE if the contents of 'msg' should be passed to the application
505 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000506BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
507 UINT first, UINT last, BOOL remove )
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000508{
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000509 if (is_keyboard_message( msg->message ))
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000510 {
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000511 process_raw_keyboard_message( msg );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000512 }
513 else if (is_mouse_message( msg->message ))
514 {
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000515 process_raw_mouse_message( msg, remove );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000516 }
517 else
518 {
519 ERR( "unknown message type %x\n", msg->message );
520 return FALSE;
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000521 }
Alexandre Julliard242e3952003-01-08 00:27:58 +0000522 return check_message_filter( msg, hwnd_filter, first, last );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000523}
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000524
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000525
526/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +0000527 * MSG_process_cooked_hardware_message
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000528 *
529 * returns TRUE if the contents of 'msg' should be passed to the application
530 */
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000531BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000532{
533 if (is_keyboard_message( msg->message ))
534 return process_cooked_keyboard_message( msg, remove );
535
536 if (is_mouse_message( msg->message ))
Alexandre Julliard516e40e2001-10-17 17:48:49 +0000537 return process_cooked_mouse_message( msg, extra_info, remove );
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000538
539 ERR( "unknown message type %x\n", msg->message );
Alexandre Julliard838d65a2001-06-19 19:16:41 +0000540 return FALSE;
Alexandre Julliardaca05781994-10-17 18:12:41 +0000541}
542
543
Alexandre Julliardcdd09231994-01-12 11:12:51 +0000544/***********************************************************************
Patrik Stridvall01d5e5b2001-07-02 19:59:40 +0000545 * WaitMessage (USER.112) Suspend thread pending messages
546 * WaitMessage (USER32.@) Suspend thread pending messages
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000547 *
548 * WaitMessage() suspends a thread until events appear in the thread's
549 * queue.
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000550 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000551BOOL WINAPI WaitMessage(void)
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000552{
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000553 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000554}
555
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000556
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000557/***********************************************************************
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000558 * MsgWaitForMultipleObjectsEx (USER32.@)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000559 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000560DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
561 DWORD timeout, DWORD mask, DWORD flags )
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000562{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000563 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000564 DWORD i, ret, lock;
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000565 MESSAGEQUEUE *msgQueue;
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000566
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000567 if (count > MAXIMUM_WAIT_OBJECTS-1)
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000568 {
569 SetLastError( ERROR_INVALID_PARAMETER );
570 return WAIT_FAILED;
571 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000572
Alexandre Julliard8afe6622001-07-26 20:12:22 +0000573 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000574
575 /* set the queue mask */
576 SERVER_START_REQ( set_queue_mask )
577 {
578 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
579 req->changed_mask = mask;
580 req->skip_wait = 0;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000581 wine_server_call( req );
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000582 }
583 SERVER_END_REQ;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000584
Alexandre Julliarddbf2bf01999-01-01 17:05:53 +0000585 /* Add the thread event to the handle list */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000586 for (i = 0; i < count; i++) handles[i] = pHandles[i];
587 handles[count] = msgQueue->server_queue;
588
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000589 ReleaseThunkLock( &lock );
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000590 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
Alexandre Julliard43230042001-05-16 19:52:29 +0000591 {
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000592 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
593 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
Alexandre Julliard43230042001-05-16 19:52:29 +0000594 }
595 else
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000596 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
597 timeout, flags & MWMO_ALERTABLE );
Alexandre Julliard3c43df82002-07-01 18:20:16 +0000598 if (lock) RestoreThunkLock( lock );
Stephane Lussierb3a99de1999-02-09 15:35:12 +0000599 return ret;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000600}
601
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000602
Eric Pouech982e0ce2001-01-28 23:44:56 +0000603/***********************************************************************
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000604 * MsgWaitForMultipleObjects (USER32.@)
Eric Pouech982e0ce2001-01-28 23:44:56 +0000605 */
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000606DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
607 BOOL wait_all, DWORD timeout, DWORD mask )
Eric Pouech982e0ce2001-01-28 23:44:56 +0000608{
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000609 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
610 wait_all ? MWMO_WAITALL : 0 );
Eric Pouech982e0ce2001-01-28 23:44:56 +0000611}
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000612
Alexandre Julliard51ab43b2001-05-18 22:51:56 +0000613
614/***********************************************************************
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000615 * WaitForInputIdle (USER32.@)
616 */
617DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
618{
Francois Gouget671a2ee2001-10-08 20:28:12 +0000619 DWORD start_time, elapsed, ret;
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000620 HANDLE idle_event = (HANDLE)-1;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000621
622 SERVER_START_REQ( wait_input_idle )
623 {
624 req->handle = hProcess;
625 req->timeout = dwTimeOut;
Alexandre Julliard9caa71e2001-11-30 18:46:42 +0000626 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000627 }
628 SERVER_END_REQ;
Francois Gouget671a2ee2001-10-08 20:28:12 +0000629 if (ret) return WAIT_FAILED; /* error */
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000630 if (!idle_event) return 0; /* no event to wait on */
631
Francois Gouget671a2ee2001-10-08 20:28:12 +0000632 start_time = GetTickCount();
633 elapsed = 0;
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000634
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000635 TRACE("waiting for %p\n", idle_event );
Francois Gouget671a2ee2001-10-08 20:28:12 +0000636 do
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000637 {
Francois Gouget671a2ee2001-10-08 20:28:12 +0000638 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
639 switch (ret)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000640 {
Francois Gouget671a2ee2001-10-08 20:28:12 +0000641 case WAIT_OBJECT_0+1:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000642 process_sent_messages();
Francois Gouget671a2ee2001-10-08 20:28:12 +0000643 break;
644 case WAIT_TIMEOUT:
645 case WAIT_FAILED:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000646 TRACE("timeout or error\n");
647 return ret;
Francois Gouget671a2ee2001-10-08 20:28:12 +0000648 default:
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000649 TRACE("finished\n");
650 return 0;
651 }
Francois Gouget671a2ee2001-10-08 20:28:12 +0000652 if (dwTimeOut != INFINITE)
653 {
654 elapsed = GetTickCount() - start_time;
655 if (elapsed > dwTimeOut)
656 break;
657 }
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000658 }
Francois Gouget671a2ee2001-10-08 20:28:12 +0000659 while (1);
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000660
661 return WAIT_TIMEOUT;
662}
663
664
665/***********************************************************************
666 * UserYield (USER.332)
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000667 */
668void WINAPI UserYield16(void)
669{
Alexandre Julliardd253c582001-08-07 19:19:08 +0000670 DWORD count;
671
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000672 /* Handle sent messages */
673 process_sent_messages();
674
675 /* Yield */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000676 ReleaseThunkLock(&count);
677 if (count)
678 {
679 RestoreThunkLock(count);
680 /* Handle sent messages again */
681 process_sent_messages();
682 }
Alexandre Julliard9f55ae62001-06-28 04:37:22 +0000683}
684
685
Alexandre Julliard7e50df31994-08-06 11:22:41 +0000686/***********************************************************************
Alexandre Julliardd253c582001-08-07 19:19:08 +0000687 * TranslateMessage (USER32.@)
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000688 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000689 * Implementation of TranslateMessage.
690 *
691 * TranslateMessage translates virtual-key messages into character-messages,
Alexandre Julliardda0cfb31996-12-01 17:17:47 +0000692 * as follows :
693 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
694 * ditto replacing WM_* with WM_SYS*
695 * This produces WM_CHAR messages only for keys mapped to ASCII characters
696 * by the keyboard driver.
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000697 *
698 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
699 * return value is nonzero, regardless of the translation.
700 *
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000701 */
Alexandre Julliardd253c582001-08-07 19:19:08 +0000702BOOL WINAPI TranslateMessage( const MSG *msg )
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000703{
Alexandre Julliardd253c582001-08-07 19:19:08 +0000704 UINT message;
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +0000705 WCHAR wp[2];
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000706 BOOL rc = FALSE;
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000707 BYTE state[256];
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000708
Alexandre Julliardd253c582001-08-07 19:19:08 +0000709 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000710 {
Alexandre Julliardd253c582001-08-07 19:19:08 +0000711 TRACE_(key)("(%s, %04X, %08lX)\n",
Guy L. Albertellidb9b5492001-09-07 18:38:57 +0000712 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
Alexandre Julliardd253c582001-08-07 19:19:08 +0000713
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000714 /* Return code must be TRUE no matter what! */
715 rc = TRUE;
716 }
717
718 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000719
Dmitry Timoshkov740bb922000-11-05 20:07:59 +0000720 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
Alexandre Julliardd253c582001-08-07 19:19:08 +0000721 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000722
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000723 GetKeyboardState( state );
Dmitry Timoshkov2fa0c662000-11-25 02:09:45 +0000724 /* FIXME : should handle ToUnicode yielding 2 */
Alexandre Julliard8ba666f2003-01-08 19:56:31 +0000725 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000726 {
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000727 case 1:
Alexandre Julliardd253c582001-08-07 19:19:08 +0000728 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
Mike McCormack020f8a42003-05-19 18:56:49 +0000729 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
730 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
Alexandre Julliardd253c582001-08-07 19:19:08 +0000731 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000732 break;
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000733
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000734 case -1:
Alexandre Julliardd253c582001-08-07 19:19:08 +0000735 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
Mike McCormack020f8a42003-05-19 18:56:49 +0000736 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
737 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
Alexandre Julliardd253c582001-08-07 19:19:08 +0000738 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000739 return TRUE;
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000740 }
Alexandre Julliard01ecb572002-06-10 23:02:19 +0000741 return rc;
Alexandre Julliard75a839a1993-07-15 11:13:45 +0000742}
743
744
745/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000746 * DispatchMessageA (USER32.@)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000747 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000748LONG WINAPI DispatchMessageA( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000749{
750 WND * wndPtr;
751 LONG retval;
752 int painting;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000753 WNDPROC winproc;
754
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000755 /* Process timer messages */
756 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
757 {
758 if (msg->lParam)
759 {
760/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000761
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000762 /* before calling window proc, verify whether timer is still valid;
763 there's a slim chance that the application kills the timer
764 between GetMessage and DispatchMessage API calls */
Alexandre Julliard18d02972002-12-03 23:34:52 +0000765 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000766 return 0; /* invalid winproc */
767
Alexandre Julliarda3960291999-02-26 11:11:13 +0000768 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000769 msg->message, msg->wParam, GetTickCount() );
770 }
771 }
772
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000773 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000774 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000775 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
776 return 0;
777 }
778 if (wndPtr == WND_OTHER_PROCESS)
779 {
780 if (IsWindow( msg->hwnd ))
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000781 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000782 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
783 return 0;
784 }
785 if (!(winproc = wndPtr->winproc))
786 {
787 WIN_ReleasePtr( wndPtr );
788 return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000789 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000790 painting = (msg->message == WM_PAINT);
791 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000792 WIN_ReleasePtr( wndPtr );
793/* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000794
Alexandre Julliarda3960291999-02-26 11:11:13 +0000795 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000796 msg->wParam, msg->lParam );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000797 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
798 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +0000799 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000800 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000801
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000802 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000803 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000804 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
805 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
806 WIN_ReleasePtr( wndPtr );
807 if (validate)
808 {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000809 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000810 /* Validate the update region to avoid infinite WM_PAINT loop */
811 RedrawWindow( msg->hwnd, NULL, 0,
812 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
813 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000814 }
815 return retval;
816}
817
818
819/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000820 * DispatchMessageW (USER32.@) Process Message
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000821 *
822 * Process the message specified in the structure *_msg_.
823 *
824 * If the lpMsg parameter points to a WM_TIMER message and the
825 * parameter of the WM_TIMER message is not NULL, the lParam parameter
826 * points to the function that is called instead of the window
827 * procedure.
Vincent Béron9a624912002-05-31 23:06:46 +0000828 *
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000829 * The message must be valid.
830 *
831 * RETURNS
832 *
833 * DispatchMessage() returns the result of the window procedure invoked.
834 *
835 * CONFORMANCE
836 *
Vincent Béron9a624912002-05-31 23:06:46 +0000837 * ECMA-234, Win32
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000838 *
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000839 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000840LONG WINAPI DispatchMessageW( const MSG* msg )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000841{
842 WND * wndPtr;
843 LONG retval;
844 int painting;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000845 WNDPROC winproc;
846
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000847 /* Process timer messages */
848 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
849 {
850 if (msg->lParam)
851 {
852/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000853
Andreas Mohr1af53cb2000-12-09 03:15:32 +0000854 /* before calling window proc, verify whether timer is still valid;
855 there's a slim chance that the application kills the timer
856 between GetMessage and DispatchMessage API calls */
Alexandre Julliard18d02972002-12-03 23:34:52 +0000857 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
Stephane Lussier6bac4f22000-09-29 00:56:05 +0000858 return 0; /* invalid winproc */
859
Alexandre Julliarda3960291999-02-26 11:11:13 +0000860 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000861 msg->message, msg->wParam, GetTickCount() );
862 }
863 }
864
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000865 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000866 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000867 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
868 return 0;
869 }
870 if (wndPtr == WND_OTHER_PROCESS)
871 {
872 if (IsWindow( msg->hwnd ))
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000873 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000874 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
875 return 0;
876 }
877 if (!(winproc = wndPtr->winproc))
878 {
879 WIN_ReleasePtr( wndPtr );
880 return 0;
Francois Boisvert3a3cd9f1999-03-28 12:42:52 +0000881 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000882 painting = (msg->message == WM_PAINT);
883 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000884 WIN_ReleasePtr( wndPtr );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000885/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
886
Alexandre Julliarda3960291999-02-26 11:11:13 +0000887 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000888 msg->wParam, msg->lParam );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000889 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
890 msg->wParam, msg->lParam );
Guy L. Albertelli936c6c42000-10-22 23:52:47 +0000891 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000892 msg->wParam, msg->lParam );
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000893
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000894 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000895 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000896 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
897 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
898 WIN_ReleasePtr( wndPtr );
899 if (validate)
900 {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000901 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000902 /* Validate the update region to avoid infinite WM_PAINT loop */
903 RedrawWindow( msg->hwnd, NULL, 0,
904 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
905 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000906 }
907 return retval;
908}
909
910
911/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000912 * RegisterWindowMessage (USER.118)
913 * RegisterWindowMessageA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000914 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000915WORD WINAPI RegisterWindowMessageA( LPCSTR str )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000916{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000917 TRACE("%s\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000918 return GlobalAddAtomA( str );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000919}
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000920
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000921
922/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000923 * RegisterWindowMessageW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000924 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000925WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000926{
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +0000927 TRACE("%p\n", str );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000928 return GlobalAddAtomW( str );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000929}
930
931
Alexandre Julliard86a8d0f1994-01-18 23:04:40 +0000932/***********************************************************************
Patrik Stridvallfc343442002-08-20 00:20:43 +0000933 * BroadcastSystemMessage (USER32.@)
934 * BroadcastSystemMessageA (USER32.@)
Alexandre Julliarde658d821997-11-30 17:45:40 +0000935 */
Alexandre Julliardb7976c02003-11-26 04:09:00 +0000936LONG WINAPI BroadcastSystemMessageA(
Alexandre Julliarda3960291999-02-26 11:11:13 +0000937 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
Aric Stewart5501f122002-08-16 23:29:48 +0000938 LPARAM lParam )
939{
940 if ((*recipients & BSM_APPLICATIONS)||
941 (*recipients == BSM_ALLCOMPONENTS))
942 {
943 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
944 dwFlags,*recipients,uMessage,wParam,lParam);
945 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
946 return 1;
947 }
948 else
949 {
950 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
951 dwFlags,*recipients,uMessage,wParam,lParam);
952 return -1;
953 }
Alexandre Julliarde658d821997-11-30 17:45:40 +0000954}
Mike McCormack020f8a42003-05-19 18:56:49 +0000955
956/***********************************************************************
957 * BroadcastSystemMessageW (USER32.@)
958 */
959LONG WINAPI BroadcastSystemMessageW(
960 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
961 LPARAM lParam )
962{
963 if ((*recipients & BSM_APPLICATIONS)||
964 (*recipients == BSM_ALLCOMPONENTS))
965 {
966 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
967 dwFlags,*recipients,uMessage,wParam,lParam);
968 PostMessageW(HWND_BROADCAST,uMessage,wParam,lParam);
969 return 1;
970 }
971 else
972 {
973 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
974 dwFlags,*recipients,uMessage,wParam,lParam);
975 return -1;
976 }
977}