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
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
29 #include <sys/types.h>
36 #include "wine/server.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msg);
52 WINE_DECLARE_DEBUG_CHANNEL(key);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
57 static BYTE QueueKeyStateTable[256];
60 /***********************************************************************
63 inline static BOOL is_keyboard_message( UINT message )
65 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
69 /***********************************************************************
72 inline static BOOL is_mouse_message( UINT message )
74 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
75 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
79 /***********************************************************************
80 * check_message_filter
82 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
86 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
90 return (msg->message >= first && msg->message <= last);
96 /***********************************************************************
97 * process_sent_messages
99 * Process all pending sent messages.
101 inline static void process_sent_messages(void)
104 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
108 /***********************************************************************
109 * queue_hardware_message
111 * store a hardware message in the thread queue
113 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_type type )
115 SERVER_START_REQ( send_message )
118 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
119 req->win = msg->hwnd;
120 req->msg = msg->message;
121 req->wparam = msg->wParam;
122 req->lparam = msg->lParam;
125 req->time = msg->time;
126 req->info = extra_info;
128 wine_server_call( req );
134 /***********************************************************************
135 * update_queue_key_state
137 static void update_queue_key_state( UINT msg, WPARAM wp, LPARAM lp )
139 BOOL down = FALSE, iskey = FALSE;
177 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RSHIFT : VK_LSHIFT;
180 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RCONTROL : VK_LCONTROL;
183 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RMENU : VK_LMENU;
190 BYTE *p = &QueueKeyStateTable[wp];
191 if (!(*p & 0x80)) *p ^= 0x01;
194 else QueueKeyStateTable[wp] &= ~0x80;
196 { /* also update the "dual" keys properly */
199 BYTE *p = &QueueKeyStateTable[dualkey];
200 if (!(*p & 0x80)) *p ^= 0x01;
203 else QueueKeyStateTable[dualkey] &= ~0x80;
208 /***********************************************************************
209 * MSG_SendParentNotify
211 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
212 * the window has the WS_EX_NOPARENTNOTIFY style.
214 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
216 /* pt has to be in the client coordinates of the parent window */
217 MapWindowPoints( 0, hwnd, &pt, 1 );
222 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
223 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
224 if (!(parent = GetParent(hwnd))) break;
225 MapWindowPoints( hwnd, parent, &pt, 1 );
227 SendMessageA( hwnd, WM_PARENTNOTIFY,
228 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
233 /***********************************************************************
234 * MSG_JournalPlayBackMsg
236 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
238 void MSG_JournalPlayBackMsg(void)
245 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return;
247 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
248 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
252 msg.message = tmpMsg.message;
253 msg.hwnd = tmpMsg.hwnd;
254 msg.time = tmpMsg.time;
255 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
257 msg.wParam = tmpMsg.paramL & 0xFF;
258 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
259 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
261 for (keyDown=i=0; i<256 && !keyDown; i++)
262 if (InputKeyStateTable[i] & 0x80)
265 msg.lParam |= 0x40000000;
266 InputKeyStateTable[msg.wParam] |= 0x80;
267 AsyncKeyStateTable[msg.wParam] |= 0x80;
269 else /* WM_KEYUP, WM_SYSKEYUP */
271 msg.lParam |= 0xC0000000;
272 InputKeyStateTable[msg.wParam] &= ~0x80;
274 if (InputKeyStateTable[VK_MENU] & 0x80)
275 msg.lParam |= 0x20000000;
276 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
277 msg.lParam |= 0x01000000;
279 msg.pt.x = msg.pt.y = 0;
280 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
282 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
284 switch (tmpMsg.message)
287 InputKeyStateTable[VK_LBUTTON] |= 0x80;
288 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
291 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
294 InputKeyStateTable[VK_MBUTTON] |= 0x80;
295 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
298 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
301 InputKeyStateTable[VK_RBUTTON] |= 0x80;
302 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
305 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
308 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
309 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
311 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
312 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
313 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
315 msg.pt.x = tmpMsg.paramL;
316 msg.pt.y = tmpMsg.paramH;
317 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
319 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
323 if( tmpMsg.message == WM_QUEUESYNC )
324 if (HOOK_IsHooked( WH_CBT ))
325 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
330 /***********************************************************************
331 * process_raw_keyboard_message
333 * returns TRUE if the contents of 'msg' should be passed to the application
335 static BOOL process_raw_keyboard_message( MSG *msg, ULONG_PTR extra_info )
337 if (!(msg->hwnd = GetFocus()))
339 /* Send the message to the active window instead, */
340 /* translating messages to their WM_SYS equivalent */
341 msg->hwnd = GetActiveWindow();
342 if (msg->message < WM_SYSKEYDOWN) msg->message += WM_SYSKEYDOWN - WM_KEYDOWN;
345 if (HOOK_IsHooked( WH_JOURNALRECORD ))
349 event.message = msg->message;
350 event.hwnd = msg->hwnd;
351 event.time = msg->time;
352 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
353 event.paramH = msg->lParam & 0x7FFF;
354 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
355 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
358 /* if we are going to throw away the message, update the queue state now */
359 if (!msg->hwnd) update_queue_key_state( msg->message, msg->wParam, msg->lParam );
361 return (msg->hwnd != 0);
365 /***********************************************************************
366 * process_cooked_keyboard_message
368 * returns TRUE if the contents of 'msg' should be passed to the application
370 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
374 update_queue_key_state( msg->message, msg->wParam, msg->lParam );
376 /* Handle F1 key by sending out WM_HELP message */
377 if ((msg->message == WM_KEYUP) &&
378 (msg->wParam == VK_F1) &&
379 (msg->hwnd != GetDesktopWindow()) &&
380 !MENU_IsMenuActive())
383 hi.cbSize = sizeof(HELPINFO);
384 hi.iContextType = HELPINFO_WINDOW;
385 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
386 hi.hItemHandle = msg->hwnd;
387 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
388 hi.MousePos = msg->pt;
389 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
393 if (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
394 LOWORD(msg->wParam), msg->lParam ))
396 /* skip this message */
397 HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam );
404 /***********************************************************************
405 * process_raw_mouse_message
407 * returns TRUE if the contents of 'msg' should be passed to the application
409 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
417 /* find the window to dispatch this mouse message to */
420 GetGUIThreadInfo( GetCurrentThreadId(), &info );
421 if (!(msg->hwnd = info.hwndCapture))
423 /* If no capture HWND, find window which contains the mouse position.
424 * Also find the position of the cursor hot spot (hittest) */
425 HWND hWndScope = (HWND)extra_info;
427 if (!IsWindow(hWndScope)) hWndScope = 0;
428 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
429 msg->hwnd = GetDesktopWindow();
432 if (HOOK_IsHooked( WH_JOURNALRECORD ))
435 event.message = msg->message;
436 event.time = msg->time;
437 event.hwnd = msg->hwnd;
438 event.paramL = msg->pt.x;
439 event.paramH = msg->pt.y;
440 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
443 /* translate double clicks */
445 if ((msg->message == WM_LBUTTONDOWN) ||
446 (msg->message == WM_RBUTTONDOWN) ||
447 (msg->message == WM_MBUTTONDOWN))
450 /* translate double clicks -
451 * note that ...MOUSEMOVEs can slip in between
452 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
454 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
455 hittest != HTCLIENT ||
456 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
458 if ((msg->message == clk_msg.message) &&
459 (msg->hwnd == clk_msg.hwnd) &&
460 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
461 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
462 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
464 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
469 /* update static double click conditions */
470 if (update) clk_msg = *msg;
474 /* Note: windows has no concept of a non-client wheel message */
475 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
477 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
478 msg->wParam = hittest;
482 /* coordinates don't get translated while tracking a menu */
483 /* FIXME: should differentiate popups and top-level menus */
484 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
486 msg->lParam = MAKELONG( pt.x, pt.y );
491 /***********************************************************************
492 * process_cooked_mouse_message
494 * returns TRUE if the contents of 'msg' should be passed to the application
496 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
498 INT hittest = HTCLIENT;
499 UINT raw_message = msg->message;
502 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
504 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
505 hittest = msg->wParam;
507 if (raw_message == WM_LBUTTONDBLCLK ||
508 raw_message == WM_RBUTTONDBLCLK ||
509 raw_message == WM_MBUTTONDBLCLK)
511 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
514 if (remove) update_queue_key_state( raw_message, 0, 0 );
516 if (HOOK_IsHooked( WH_MOUSE ))
518 MOUSEHOOKSTRUCT hook;
520 hook.hwnd = msg->hwnd;
521 hook.wHitTestCode = hittest;
522 hook.dwExtraInfo = extra_info;
523 if (HOOK_CallHooksA( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
524 msg->message, (LPARAM)&hook ))
527 hook.hwnd = msg->hwnd;
528 hook.wHitTestCode = hittest;
529 hook.dwExtraInfo = extra_info;
530 HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook );
535 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
537 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
538 MAKELONG( hittest, raw_message ));
542 if (!remove || GetCapture()) return TRUE;
546 if ((raw_message == WM_LBUTTONDOWN) ||
547 (raw_message == WM_RBUTTONDOWN) ||
548 (raw_message == WM_MBUTTONDOWN))
550 /* Send the WM_PARENTNOTIFY,
551 * note that even for double/nonclient clicks
552 * notification message is still WM_L/M/RBUTTONDOWN.
554 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
556 /* Activate the window if needed */
558 if (msg->hwnd != GetActiveWindow())
560 HWND hwndTop = msg->hwnd;
563 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
564 hwndTop = GetParent( hwndTop );
567 if (hwndTop && hwndTop != GetDesktopWindow())
569 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
570 MAKELONG( hittest, raw_message ) );
573 case MA_NOACTIVATEANDEAT:
578 case MA_ACTIVATEANDEAT:
583 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
586 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
593 /* send the WM_SETCURSOR message */
595 /* Windows sends the normal mouse message as the message parameter
596 in the WM_SETCURSOR message even if it's non-client mouse message */
597 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
598 MAKELONG( hittest, raw_message ));
604 /***********************************************************************
605 * process_hardware_message
607 * returns TRUE if the contents of 'msg' should be passed to the application
609 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
610 UINT first, UINT last, BOOL remove )
612 if (is_keyboard_message( msg->message ))
614 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
616 else if (is_mouse_message( msg->message ))
618 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
622 ERR( "unknown message type %x\n", msg->message );
626 /* check destination thread and filters */
627 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
628 !WIN_IsCurrentThread( msg->hwnd ))
630 /* queue it for later, or for another thread */
631 queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
635 /* save the message in the cooked queue if we didn't want to remove it */
636 if (!remove) queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
641 /***********************************************************************
642 * MSG_process_cooked_hardware_message
644 * returns TRUE if the contents of 'msg' should be passed to the application
646 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
648 if (is_keyboard_message( msg->message ))
649 return process_cooked_keyboard_message( msg, remove );
651 if (is_mouse_message( msg->message ))
652 return process_cooked_mouse_message( msg, extra_info, remove );
654 ERR( "unknown message type %x\n", msg->message );
659 /**********************************************************************
660 * GetKeyState (USER.106)
662 INT16 WINAPI GetKeyState16(INT16 vkey)
664 return GetKeyState(vkey);
668 /**********************************************************************
669 * GetKeyState (USER32.@)
671 * An application calls the GetKeyState function in response to a
672 * keyboard-input message. This function retrieves the state of the key
673 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
675 SHORT WINAPI GetKeyState(INT vkey)
679 if (vkey >= 'a' && vkey <= 'z') vkey += 'A' - 'a';
680 retval = ((WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
681 (QueueKeyStateTable[vkey] & 0x80) |
682 (QueueKeyStateTable[vkey] & 0x01);
683 TRACE("key (0x%x) -> %x\n", vkey, retval);
688 /**********************************************************************
689 * GetKeyboardState (USER.222)
690 * GetKeyboardState (USER32.@)
692 * An application calls the GetKeyboardState function in response to a
693 * keyboard input message. This function retrieves the state of the keyboard
694 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
696 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
698 TRACE_(key)("(%p)\n", lpKeyState);
699 if (lpKeyState) memcpy(lpKeyState, QueueKeyStateTable, 256);
704 /**********************************************************************
705 * SetKeyboardState (USER.223)
706 * SetKeyboardState (USER32.@)
708 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
710 TRACE_(key)("(%p)\n", lpKeyState);
711 if (lpKeyState) memcpy(QueueKeyStateTable, lpKeyState, 256);
716 /***********************************************************************
717 * WaitMessage (USER.112) Suspend thread pending messages
718 * WaitMessage (USER32.@) Suspend thread pending messages
720 * WaitMessage() suspends a thread until events appear in the thread's
723 BOOL WINAPI WaitMessage(void)
725 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
729 /***********************************************************************
730 * MsgWaitForMultipleObjectsEx (USER32.@)
732 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
733 DWORD timeout, DWORD mask, DWORD flags )
735 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
737 MESSAGEQUEUE *msgQueue;
739 if (count > MAXIMUM_WAIT_OBJECTS-1)
741 SetLastError( ERROR_INVALID_PARAMETER );
745 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
747 /* set the queue mask */
748 SERVER_START_REQ( set_queue_mask )
750 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
751 req->changed_mask = mask;
753 wine_server_call( req );
757 /* Add the thread event to the handle list */
758 for (i = 0; i < count; i++) handles[i] = pHandles[i];
759 handles[count] = msgQueue->server_queue;
761 ReleaseThunkLock( &lock );
762 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
764 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
765 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
768 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
769 timeout, flags & MWMO_ALERTABLE );
770 if (lock) RestoreThunkLock( lock );
775 /***********************************************************************
776 * MsgWaitForMultipleObjects (USER32.@)
778 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
779 BOOL wait_all, DWORD timeout, DWORD mask )
781 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
782 wait_all ? MWMO_WAITALL : 0 );
786 /***********************************************************************
787 * WaitForInputIdle (USER32.@)
789 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
791 DWORD start_time, elapsed, ret;
792 HANDLE idle_event = -1;
794 SERVER_START_REQ( wait_input_idle )
796 req->handle = hProcess;
797 req->timeout = dwTimeOut;
798 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
801 if (ret) return WAIT_FAILED; /* error */
802 if (!idle_event) return 0; /* no event to wait on */
804 start_time = GetTickCount();
807 TRACE("waiting for %x\n", idle_event );
810 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
813 case WAIT_OBJECT_0+1:
814 process_sent_messages();
818 TRACE("timeout or error\n");
824 if (dwTimeOut != INFINITE)
826 elapsed = GetTickCount() - start_time;
827 if (elapsed > dwTimeOut)
837 /***********************************************************************
838 * UserYield (USER.332)
840 void WINAPI UserYield16(void)
844 /* Handle sent messages */
845 process_sent_messages();
848 ReleaseThunkLock(&count);
851 RestoreThunkLock(count);
852 /* Handle sent messages again */
853 process_sent_messages();
865 static const struct accent_char accent_chars[] =
867 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
868 {'`', 'A', '\300'}, {'`', 'a', '\340'},
869 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
870 {'^', 'A', '\302'}, {'^', 'a', '\342'},
871 {'~', 'A', '\303'}, {'~', 'a', '\343'},
872 {'"', 'A', '\304'}, {'"', 'a', '\344'},
873 {'O', 'A', '\305'}, {'o', 'a', '\345'},
874 {'0', 'A', '\305'}, {'0', 'a', '\345'},
875 {'A', 'A', '\305'}, {'a', 'a', '\345'},
876 {'A', 'E', '\306'}, {'a', 'e', '\346'},
877 {',', 'C', '\307'}, {',', 'c', '\347'},
878 {'`', 'E', '\310'}, {'`', 'e', '\350'},
879 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
880 {'^', 'E', '\312'}, {'^', 'e', '\352'},
881 {'"', 'E', '\313'}, {'"', 'e', '\353'},
882 {'`', 'I', '\314'}, {'`', 'i', '\354'},
883 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
884 {'^', 'I', '\316'}, {'^', 'i', '\356'},
885 {'"', 'I', '\317'}, {'"', 'i', '\357'},
886 {'-', 'D', '\320'}, {'-', 'd', '\360'},
887 {'~', 'N', '\321'}, {'~', 'n', '\361'},
888 {'`', 'O', '\322'}, {'`', 'o', '\362'},
889 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
890 {'^', 'O', '\324'}, {'^', 'o', '\364'},
891 {'~', 'O', '\325'}, {'~', 'o', '\365'},
892 {'"', 'O', '\326'}, {'"', 'o', '\366'},
893 {'/', 'O', '\330'}, {'/', 'o', '\370'},
894 {'`', 'U', '\331'}, {'`', 'u', '\371'},
895 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
896 {'^', 'U', '\333'}, {'^', 'u', '\373'},
897 {'"', 'U', '\334'}, {'"', 'u', '\374'},
898 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
899 {'T', 'H', '\336'}, {'t', 'h', '\376'},
900 {'s', 's', '\337'}, {'"', 'y', '\377'},
901 {'s', 'z', '\337'}, {'i', 'j', '\377'},
902 /* iso-8859-2 uses this */
903 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
904 {'<', 'S', '\251'}, {'<', 's', '\271'},
905 {'<', 'T', '\253'}, {'<', 't', '\273'},
906 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
907 {'<', 'C', '\310'}, {'<', 'c', '\350'},
908 {'<', 'E', '\314'}, {'<', 'e', '\354'},
909 {'<', 'D', '\317'}, {'<', 'd', '\357'},
910 {'<', 'N', '\322'}, {'<', 'n', '\362'},
911 {'<', 'R', '\330'}, {'<', 'r', '\370'},
912 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
913 {';', 'E', '\312'}, {';', 'e', '\332'},
914 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
915 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
916 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
917 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
918 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
919 /* collision whith S, from iso-8859-9 !!! */
920 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
921 {',', 'T', '\336'}, {',', 't', '\376'},
922 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
923 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
924 {'/', 'D', '\320'}, {'/', 'd', '\360'},
925 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
926 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
927 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
928 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
929 /* iso-8859-3 uses this */
930 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
931 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
932 {'>', 'J', '\254'}, {'>', 'j', '\274'},
933 {'>', 'C', '\306'}, {'>', 'c', '\346'},
934 {'>', 'G', '\330'}, {'>', 'g', '\370'},
935 {'>', 'S', '\336'}, {'>', 's', '\376'},
936 /* collision whith G( from iso-8859-9 !!! */
937 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
938 {'(', 'U', '\335'}, {'(', 'u', '\375'},
939 /* collision whith I. from iso-8859-3 !!! */
940 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
941 {'.', 'C', '\305'}, {'.', 'c', '\345'},
942 {'.', 'G', '\325'}, {'.', 'g', '\365'},
943 /* iso-8859-4 uses this */
944 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
945 {',', 'L', '\246'}, {',', 'l', '\266'},
946 {',', 'G', '\253'}, {',', 'g', '\273'},
947 {',', 'N', '\321'}, {',', 'n', '\361'},
948 {',', 'K', '\323'}, {',', 'k', '\363'},
949 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
950 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
951 {'-', 'A', '\300'}, {'-', 'a', '\340'},
952 {'-', 'I', '\317'}, {'-', 'i', '\357'},
953 {'-', 'O', '\322'}, {'-', 'o', '\362'},
954 {'-', 'U', '\336'}, {'-', 'u', '\376'},
955 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
956 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
957 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
958 {';', 'U', '\331'}, {';', 'u', '\371'},
959 /* iso-8859-9 uses this */
960 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
961 * whith the same letters on other iso-8859-x (that is they are on
962 * different places :-( ), if you use turkish uncomment these and
963 * comment out the lines in iso-8859-2 and iso-8859-3 sections
964 * FIXME: should be dynamic according to chosen language
965 * if/when Wine has turkish support.
967 /* collision whith G( from iso-8859-3 !!! */
968 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
969 /* collision whith S, from iso-8859-2 !!! */
970 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
971 /* collision whith I. from iso-8859-3 !!! */
972 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
976 /***********************************************************************
977 * TranslateMessage (USER32.@)
979 * Implementation of TranslateMessage.
981 * TranslateMessage translates virtual-key messages into character-messages,
983 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
984 * ditto replacing WM_* with WM_SYS*
985 * This produces WM_CHAR messages only for keys mapped to ASCII characters
986 * by the keyboard driver.
988 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
989 * return value is nonzero, regardless of the translation.
992 BOOL WINAPI TranslateMessage( const MSG *msg )
994 static int dead_char;
999 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
1001 TRACE_(key)("(%s, %04X, %08lX)\n",
1002 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
1004 /* Return code must be TRUE no matter what! */
1008 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
1010 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
1011 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
1013 /* FIXME : should handle ToUnicode yielding 2 */
1014 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
1017 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1018 /* Should dead chars handling go in ToAscii ? */
1023 if (wp[0] == ' ') wp[0] = dead_char;
1024 if (dead_char == 0xa2) dead_char = '(';
1025 else if (dead_char == 0xa8) dead_char = '"';
1026 else if (dead_char == 0xb2) dead_char = ';';
1027 else if (dead_char == 0xb4) dead_char = '\'';
1028 else if (dead_char == 0xb7) dead_char = '<';
1029 else if (dead_char == 0xb8) dead_char = ',';
1030 else if (dead_char == 0xff) dead_char = '.';
1031 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1032 if ((accent_chars[i].ac_accent == dead_char) &&
1033 (accent_chars[i].ac_char == wp[0]))
1035 wp[0] = accent_chars[i].ac_result;
1040 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1041 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1045 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1047 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1048 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1055 /***********************************************************************
1056 * DispatchMessageA (USER32.@)
1058 LONG WINAPI DispatchMessageA( const MSG* msg )
1065 /* Process timer messages */
1066 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1070 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1072 /* before calling window proc, verify whether timer is still valid;
1073 there's a slim chance that the application kills the timer
1074 between GetMessage and DispatchMessage API calls */
1075 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1076 return 0; /* invalid winproc */
1078 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
1079 msg->message, msg->wParam, GetTickCount() );
1083 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1085 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1088 if (wndPtr == WND_OTHER_PROCESS)
1090 if (IsWindow( msg->hwnd ))
1091 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1092 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1095 if (!(winproc = wndPtr->winproc))
1097 WIN_ReleasePtr( wndPtr );
1100 painting = (msg->message == WM_PAINT);
1101 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1102 WIN_ReleasePtr( wndPtr );
1103 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1105 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1106 msg->wParam, msg->lParam );
1107 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
1108 msg->wParam, msg->lParam );
1109 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1110 msg->wParam, msg->lParam );
1112 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1114 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1115 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1116 WIN_ReleasePtr( wndPtr );
1119 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1120 /* Validate the update region to avoid infinite WM_PAINT loop */
1121 RedrawWindow( msg->hwnd, NULL, 0,
1122 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1129 /***********************************************************************
1130 * DispatchMessageW (USER32.@) Process Message
1132 * Process the message specified in the structure *_msg_.
1134 * If the lpMsg parameter points to a WM_TIMER message and the
1135 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1136 * points to the function that is called instead of the window
1139 * The message must be valid.
1143 * DispatchMessage() returns the result of the window procedure invoked.
1150 LONG WINAPI DispatchMessageW( const MSG* msg )
1157 /* Process timer messages */
1158 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1162 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1164 /* before calling window proc, verify whether timer is still valid;
1165 there's a slim chance that the application kills the timer
1166 between GetMessage and DispatchMessage API calls */
1167 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1168 return 0; /* invalid winproc */
1170 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
1171 msg->message, msg->wParam, GetTickCount() );
1175 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1177 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1180 if (wndPtr == WND_OTHER_PROCESS)
1182 if (IsWindow( msg->hwnd ))
1183 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1184 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1187 if (!(winproc = wndPtr->winproc))
1189 WIN_ReleasePtr( wndPtr );
1192 painting = (msg->message == WM_PAINT);
1193 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1194 WIN_ReleasePtr( wndPtr );
1195 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1197 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1198 msg->wParam, msg->lParam );
1199 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1200 msg->wParam, msg->lParam );
1201 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1202 msg->wParam, msg->lParam );
1204 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1206 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1207 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1208 WIN_ReleasePtr( wndPtr );
1211 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1212 /* Validate the update region to avoid infinite WM_PAINT loop */
1213 RedrawWindow( msg->hwnd, NULL, 0,
1214 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1221 /***********************************************************************
1222 * RegisterWindowMessage (USER.118)
1223 * RegisterWindowMessageA (USER32.@)
1225 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1227 TRACE("%s\n", str );
1228 return GlobalAddAtomA( str );
1232 /***********************************************************************
1233 * RegisterWindowMessageW (USER32.@)
1235 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1237 TRACE("%p\n", str );
1238 return GlobalAddAtomW( str );
1242 /***********************************************************************
1243 * BroadcastSystemMessage (USER32.@)
1244 * BroadcastSystemMessageA (USER32.@)
1246 LONG WINAPI BroadcastSystemMessage(
1247 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1250 if ((*recipients & BSM_APPLICATIONS)||
1251 (*recipients == BSM_ALLCOMPONENTS))
1253 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1254 dwFlags,*recipients,uMessage,wParam,lParam);
1255 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
1260 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1261 dwFlags,*recipients,uMessage,wParam,lParam);