Mask off bit 0x80 in the accelerator table entry field fVirt if it's
[wine.git] / windows / message.c
blob317a720f246e4c7c11b97ff4e6d0a8bbe22cf45d
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
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.
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.
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
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <ctype.h>
27 #ifdef HAVE_SYS_TIME_H
28 # include <sys/time.h>
29 #endif
30 #include <sys/types.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "message.h"
37 #include "winerror.h"
38 #include "ntstatus.h"
39 #include "wine/server.h"
40 #include "controls.h"
41 #include "dde.h"
42 #include "message.h"
43 #include "user.h"
44 #include "win.h"
45 #include "winpos.h"
46 #include "winproc.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(msg);
50 WINE_DECLARE_DEBUG_CHANNEL(key);
52 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
56 /***********************************************************************
57 * is_keyboard_message
59 inline static BOOL is_keyboard_message( UINT message )
61 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
65 /***********************************************************************
66 * is_mouse_message
68 inline static BOOL is_mouse_message( UINT message )
70 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
71 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
75 /***********************************************************************
76 * check_message_filter
78 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
80 if (hwnd)
82 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
84 if (first || last)
86 return (msg->message >= first && msg->message <= last);
88 return TRUE;
92 /***********************************************************************
93 * process_sent_messages
95 * Process all pending sent messages.
97 inline static void process_sent_messages(void)
99 MSG msg;
100 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
104 /***********************************************************************
105 * queue_hardware_message
107 * store a hardware message in the thread queue
109 #if 0
110 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info )
112 SERVER_START_REQ( send_message )
114 req->type = MSG_HARDWARE;
115 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
116 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;
124 req->timeout = 0;
125 wine_server_call( req );
127 SERVER_END_REQ;
129 #endif
132 /***********************************************************************
133 * MSG_SendParentNotify
135 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
136 * the window has the WS_EX_NOPARENTNOTIFY style.
138 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
140 /* pt has to be in the client coordinates of the parent window */
141 MapWindowPoints( 0, hwnd, &pt, 1 );
142 for (;;)
144 HWND parent;
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,
152 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
157 #if 0 /* this is broken for now, will require proper support in the server */
159 /***********************************************************************
160 * MSG_JournalPlayBackMsg
162 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
164 void MSG_JournalPlayBackMsg(void)
166 EVENTMSG tmpMsg;
167 MSG msg;
168 LRESULT wtime;
169 int keyDown,i;
171 wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE );
172 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
173 if (wtime<=0)
175 wtime=0;
176 msg.message = tmpMsg.message;
177 msg.hwnd = tmpMsg.hwnd;
178 msg.time = tmpMsg.time;
179 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
181 msg.wParam = tmpMsg.paramL & 0xFF;
182 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
183 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
185 for (keyDown=i=0; i<256 && !keyDown; i++)
186 if (InputKeyStateTable[i] & 0x80)
187 keyDown++;
188 if (!keyDown)
189 msg.lParam |= 0x40000000;
190 InputKeyStateTable[msg.wParam] |= 0x80;
191 AsyncKeyStateTable[msg.wParam] |= 0x80;
193 else /* WM_KEYUP, WM_SYSKEYUP */
195 msg.lParam |= 0xC0000000;
196 InputKeyStateTable[msg.wParam] &= ~0x80;
198 if (InputKeyStateTable[VK_MENU] & 0x80)
199 msg.lParam |= 0x20000000;
200 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
201 msg.lParam |= 0x01000000;
203 msg.pt.x = msg.pt.y = 0;
204 queue_hardware_message( &msg, 0 );
206 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
208 switch (tmpMsg.message)
210 case WM_LBUTTONDOWN:
211 InputKeyStateTable[VK_LBUTTON] |= 0x80;
212 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
213 break;
214 case WM_LBUTTONUP:
215 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
216 break;
217 case WM_MBUTTONDOWN:
218 InputKeyStateTable[VK_MBUTTON] |= 0x80;
219 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
220 break;
221 case WM_MBUTTONUP:
222 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
223 break;
224 case WM_RBUTTONDOWN:
225 InputKeyStateTable[VK_RBUTTON] |= 0x80;
226 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
227 break;
228 case WM_RBUTTONUP:
229 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
230 break;
232 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
233 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
234 msg.wParam=0;
235 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;
239 msg.pt.x = tmpMsg.paramL;
240 msg.pt.y = tmpMsg.paramH;
241 queue_hardware_message( &msg, 0 );
243 HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE );
245 else
247 if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE );
250 #endif
253 /***********************************************************************
254 * process_raw_keyboard_message
256 * returns TRUE if the contents of 'msg' should be passed to the application
258 static void process_raw_keyboard_message( MSG *msg )
260 EVENTMSG event;
262 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 );
272 /***********************************************************************
273 * process_cooked_keyboard_message
275 * returns TRUE if the contents of 'msg' should be passed to the application
277 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
279 if (remove)
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())
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);
298 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
299 LOWORD(msg->wParam), msg->lParam, TRUE ))
301 /* skip this message */
302 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
303 return FALSE;
305 return TRUE;
309 /***********************************************************************
310 * process_raw_mouse_message
312 static void process_raw_mouse_message( MSG *msg, BOOL remove )
314 static MSG clk_msg;
316 POINT pt;
317 INT hittest;
318 EVENTMSG event;
319 GUITHREADINFO info;
320 HWND hWndScope = msg->hwnd;
322 /* find the window to dispatch this mouse message to */
324 hittest = HTCLIENT;
325 GetGUIThreadInfo( GetCurrentThreadId(), &info );
326 if (!(msg->hwnd = info.hwndCapture))
328 /* If no capture HWND, find window which contains the mouse position.
329 * Also find the position of the cursor hot spot (hittest) */
330 if (!IsWindow(hWndScope)) hWndScope = 0;
331 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
332 msg->hwnd = GetDesktopWindow();
335 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 );
342 /* translate double clicks */
344 if ((msg->message == WM_LBUTTONDOWN) ||
345 (msg->message == WM_RBUTTONDOWN) ||
346 (msg->message == WM_MBUTTONDOWN))
348 BOOL update = remove;
349 /* translate double clicks -
350 * note that ...MOUSEMOVEs can slip in between
351 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
353 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
354 hittest != HTCLIENT ||
355 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
357 if ((msg->message == clk_msg.message) &&
358 (msg->hwnd == clk_msg.hwnd) &&
359 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
360 (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))
363 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
364 if (remove)
366 clk_msg.message = 0;
367 update = FALSE;
371 /* update static double click conditions */
372 if (update) clk_msg = *msg;
375 pt = msg->pt;
376 /* Note: windows has no concept of a non-client wheel message */
377 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
379 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
380 msg->wParam = hittest;
382 else
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 );
388 msg->lParam = MAKELONG( pt.x, pt.y );
392 /***********************************************************************
393 * process_cooked_mouse_message
395 * returns TRUE if the contents of 'msg' should be passed to the application
397 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
399 MOUSEHOOKSTRUCT hook;
400 INT hittest = HTCLIENT;
401 UINT raw_message = msg->message;
402 BOOL eatMsg;
404 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
406 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
407 hittest = msg->wParam;
409 if (raw_message == WM_LBUTTONDBLCLK ||
410 raw_message == WM_RBUTTONDBLCLK ||
411 raw_message == WM_MBUTTONDBLCLK)
413 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
416 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 ))
423 hook.pt = msg->pt;
424 hook.hwnd = msg->hwnd;
425 hook.wHitTestCode = hittest;
426 hook.dwExtraInfo = extra_info;
427 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
428 return FALSE;
431 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
433 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
434 MAKELONG( hittest, raw_message ));
435 return FALSE;
438 if (!remove || GetCapture()) return TRUE;
440 eatMsg = FALSE;
442 if ((raw_message == WM_LBUTTONDOWN) ||
443 (raw_message == WM_RBUTTONDOWN) ||
444 (raw_message == WM_MBUTTONDOWN))
446 /* Send the WM_PARENTNOTIFY,
447 * note that even for double/nonclient clicks
448 * notification message is still WM_L/M/RBUTTONDOWN.
450 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
452 /* Activate the window if needed */
454 if (msg->hwnd != GetActiveWindow())
456 HWND hwndTop = msg->hwnd;
457 while (hwndTop)
459 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
460 hwndTop = GetParent( hwndTop );
463 if (hwndTop && hwndTop != GetDesktopWindow())
465 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
466 MAKELONG( hittest, raw_message ) );
467 switch(ret)
469 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;
489 /* send the WM_SETCURSOR message */
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 */
493 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
494 MAKELONG( hittest, raw_message ));
496 return !eatMsg;
500 /***********************************************************************
501 * process_hardware_message
503 * returns TRUE if the contents of 'msg' should be passed to the application
505 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
506 UINT first, UINT last, BOOL remove )
508 if (is_keyboard_message( msg->message ))
510 process_raw_keyboard_message( msg );
512 else if (is_mouse_message( msg->message ))
514 process_raw_mouse_message( msg, remove );
516 else
518 ERR( "unknown message type %x\n", msg->message );
519 return FALSE;
521 return check_message_filter( msg, hwnd_filter, first, last );
525 /***********************************************************************
526 * MSG_process_cooked_hardware_message
528 * returns TRUE if the contents of 'msg' should be passed to the application
530 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
532 if (is_keyboard_message( msg->message ))
533 return process_cooked_keyboard_message( msg, remove );
535 if (is_mouse_message( msg->message ))
536 return process_cooked_mouse_message( msg, extra_info, remove );
538 ERR( "unknown message type %x\n", msg->message );
539 return FALSE;
543 /***********************************************************************
544 * WaitMessage (USER.112) Suspend thread pending messages
545 * WaitMessage (USER32.@) Suspend thread pending messages
547 * WaitMessage() suspends a thread until events appear in the thread's
548 * queue.
550 BOOL WINAPI WaitMessage(void)
552 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
556 /***********************************************************************
557 * MsgWaitForMultipleObjectsEx (USER32.@)
559 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
560 DWORD timeout, DWORD mask, DWORD flags )
562 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
563 DWORD i, ret, lock;
564 MESSAGEQUEUE *msgQueue;
566 if (count > MAXIMUM_WAIT_OBJECTS-1)
568 SetLastError( ERROR_INVALID_PARAMETER );
569 return WAIT_FAILED;
572 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
574 /* set the queue mask */
575 SERVER_START_REQ( set_queue_mask )
577 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
578 req->changed_mask = mask;
579 req->skip_wait = 0;
580 wine_server_call( req );
582 SERVER_END_REQ;
584 /* Add the thread event to the handle list */
585 for (i = 0; i < count; i++) handles[i] = pHandles[i];
586 handles[count] = msgQueue->server_queue;
588 ReleaseThunkLock( &lock );
589 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
591 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
592 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
594 else
595 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
596 timeout, flags & MWMO_ALERTABLE );
597 if (lock) RestoreThunkLock( lock );
598 return ret;
602 /***********************************************************************
603 * MsgWaitForMultipleObjects (USER32.@)
605 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
606 BOOL wait_all, DWORD timeout, DWORD mask )
608 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
609 wait_all ? MWMO_WAITALL : 0 );
613 /***********************************************************************
614 * WaitForInputIdle (USER32.@)
616 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
618 DWORD start_time, elapsed, ret;
619 HANDLE idle_event = (HANDLE)-1;
621 SERVER_START_REQ( wait_input_idle )
623 req->handle = hProcess;
624 req->timeout = dwTimeOut;
625 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
627 SERVER_END_REQ;
628 if (ret) return WAIT_FAILED; /* error */
629 if (!idle_event) return 0; /* no event to wait on */
631 start_time = GetTickCount();
632 elapsed = 0;
634 TRACE("waiting for %p\n", idle_event );
637 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
638 switch (ret)
640 case WAIT_OBJECT_0+1:
641 process_sent_messages();
642 break;
643 case WAIT_TIMEOUT:
644 case WAIT_FAILED:
645 TRACE("timeout or error\n");
646 return ret;
647 default:
648 TRACE("finished\n");
649 return 0;
651 if (dwTimeOut != INFINITE)
653 elapsed = GetTickCount() - start_time;
654 if (elapsed > dwTimeOut)
655 break;
658 while (1);
660 return WAIT_TIMEOUT;
664 /***********************************************************************
665 * UserYield (USER.332)
667 void WINAPI UserYield16(void)
669 DWORD count;
671 /* Handle sent messages */
672 process_sent_messages();
674 /* Yield */
675 ReleaseThunkLock(&count);
676 if (count)
678 RestoreThunkLock(count);
679 /* Handle sent messages again */
680 process_sent_messages();
685 /***********************************************************************
686 * TranslateMessage (USER32.@)
688 * Implementation of TranslateMessage.
690 * TranslateMessage translates virtual-key messages into character-messages,
691 * 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.
697 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
698 * return value is nonzero, regardless of the translation.
701 BOOL WINAPI TranslateMessage( const MSG *msg )
703 UINT message;
704 WCHAR wp[2];
705 BOOL rc = FALSE;
706 BYTE state[256];
708 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
710 TRACE_(key)("(%s, %04X, %08lX)\n",
711 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
713 /* Return code must be TRUE no matter what! */
714 rc = TRUE;
717 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
719 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
720 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
722 GetKeyboardState( state );
723 /* FIXME : should handle ToUnicode yielding 2 */
724 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
726 case 1:
727 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
728 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
729 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
730 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
731 break;
733 case -1:
734 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
735 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
736 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
737 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
738 return TRUE;
740 return rc;
744 /***********************************************************************
745 * DispatchMessageA (USER32.@)
747 LONG WINAPI DispatchMessageA( const MSG* msg )
749 WND * wndPtr;
750 LONG retval;
751 int painting;
752 WNDPROC winproc;
754 /* Process timer messages */
755 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
757 if (msg->lParam)
759 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
761 /* 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 */
764 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
765 return 0; /* invalid winproc */
767 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
768 msg->message, msg->wParam, GetTickCount() );
772 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
774 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
775 return 0;
777 if (wndPtr == WND_OTHER_PROCESS)
779 if (IsWindow( msg->hwnd ))
780 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
781 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
782 return 0;
784 if (!(winproc = wndPtr->winproc))
786 WIN_ReleasePtr( wndPtr );
787 return 0;
789 painting = (msg->message == WM_PAINT);
790 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
791 WIN_ReleasePtr( wndPtr );
792 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
794 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
795 msg->wParam, msg->lParam );
796 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
797 msg->wParam, msg->lParam );
798 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
799 msg->wParam, msg->lParam );
801 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
803 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
804 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
805 WIN_ReleasePtr( wndPtr );
806 if (validate)
808 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
809 /* 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 );
814 return retval;
818 /***********************************************************************
819 * DispatchMessageW (USER32.@) Process Message
821 * Process the message specified in the structure *_msg_.
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.
828 * The message must be valid.
830 * RETURNS
832 * DispatchMessage() returns the result of the window procedure invoked.
834 * CONFORMANCE
836 * ECMA-234, Win32
839 LONG WINAPI DispatchMessageW( const MSG* msg )
841 WND * wndPtr;
842 LONG retval;
843 int painting;
844 WNDPROC winproc;
846 /* Process timer messages */
847 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
849 if (msg->lParam)
851 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
853 /* 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 */
856 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
857 return 0; /* invalid winproc */
859 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
860 msg->message, msg->wParam, GetTickCount() );
864 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
866 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
867 return 0;
869 if (wndPtr == WND_OTHER_PROCESS)
871 if (IsWindow( msg->hwnd ))
872 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
873 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
874 return 0;
876 if (!(winproc = wndPtr->winproc))
878 WIN_ReleasePtr( wndPtr );
879 return 0;
881 painting = (msg->message == WM_PAINT);
882 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
883 WIN_ReleasePtr( wndPtr );
884 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
886 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
887 msg->wParam, msg->lParam );
888 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
889 msg->wParam, msg->lParam );
890 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
891 msg->wParam, msg->lParam );
893 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
895 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
896 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
897 WIN_ReleasePtr( wndPtr );
898 if (validate)
900 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
901 /* 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 );
906 return retval;
910 /***********************************************************************
911 * RegisterWindowMessage (USER.118)
912 * RegisterWindowMessageA (USER32.@)
914 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
916 TRACE("%s\n", str );
917 return GlobalAddAtomA( str );
921 /***********************************************************************
922 * RegisterWindowMessageW (USER32.@)
924 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
926 TRACE("%p\n", str );
927 return GlobalAddAtomW( str );
931 /***********************************************************************
932 * BroadcastSystemMessage (USER32.@)
933 * BroadcastSystemMessageA (USER32.@)
935 LONG WINAPI BroadcastSystemMessageA(
936 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
937 LPARAM lParam )
939 if ((*recipients & BSM_APPLICATIONS)||
940 (*recipients == BSM_ALLCOMPONENTS))
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;
947 else
949 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
950 dwFlags,*recipients,uMessage,wParam,lParam);
951 return -1;
955 /***********************************************************************
956 * BroadcastSystemMessageW (USER32.@)
958 LONG WINAPI BroadcastSystemMessageW(
959 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
960 LPARAM lParam )
962 if ((*recipients & BSM_APPLICATIONS)||
963 (*recipients == BSM_ALLCOMPONENTS))
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;
970 else
972 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
973 dwFlags,*recipients,uMessage,wParam,lParam);
974 return -1;