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"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg);
51 WINE_DECLARE_DEBUG_CHANNEL(key);
53 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
54 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
56 static BYTE QueueKeyStateTable[256];
59 /***********************************************************************
62 inline static BOOL is_keyboard_message( UINT message )
64 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
68 /***********************************************************************
71 inline static BOOL is_mouse_message( UINT message )
73 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
74 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
78 /***********************************************************************
79 * check_message_filter
81 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
85 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
89 return (msg->message >= first && msg->message <= last);
95 /***********************************************************************
96 * process_sent_messages
98 * Process all pending sent messages.
100 inline static void process_sent_messages(void)
103 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
107 /***********************************************************************
108 * queue_hardware_message
110 * store a hardware message in the thread queue
112 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_type type )
114 SERVER_START_REQ( send_message )
117 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
118 req->win = msg->hwnd;
119 req->msg = msg->message;
120 req->wparam = msg->wParam;
121 req->lparam = msg->lParam;
124 req->time = msg->time;
125 req->info = extra_info;
127 wine_server_call( req );
133 /***********************************************************************
134 * update_queue_key_state
136 static void update_queue_key_state( UINT msg, WPARAM wp, LPARAM lp )
138 BOOL down = FALSE, iskey = FALSE;
176 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RSHIFT : VK_LSHIFT;
179 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RCONTROL : VK_LCONTROL;
182 dualkey = (HIWORD(lp) & KF_EXTENDED) ? VK_RMENU : VK_LMENU;
189 BYTE *p = &QueueKeyStateTable[wp];
190 if (!(*p & 0x80)) *p ^= 0x01;
193 else QueueKeyStateTable[wp] &= ~0x80;
195 { /* also update the "dual" keys properly */
198 BYTE *p = &QueueKeyStateTable[dualkey];
199 if (!(*p & 0x80)) *p ^= 0x01;
202 else QueueKeyStateTable[dualkey] &= ~0x80;
207 /***********************************************************************
208 * MSG_SendParentNotify
210 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
211 * the window has the WS_EX_NOPARENTNOTIFY style.
213 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
215 /* pt has to be in the client coordinates of the parent window */
216 MapWindowPoints( 0, hwnd, &pt, 1 );
221 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
222 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
223 if (!(parent = GetParent(hwnd))) break;
224 MapWindowPoints( hwnd, parent, &pt, 1 );
226 SendMessageA( hwnd, WM_PARENTNOTIFY,
227 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
232 #if 0 /* this is broken for now, will require proper support in the server */
234 /***********************************************************************
235 * MSG_JournalPlayBackMsg
237 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
239 void MSG_JournalPlayBackMsg(void)
246 wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE );
247 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
251 msg.message = tmpMsg.message;
252 msg.hwnd = tmpMsg.hwnd;
253 msg.time = tmpMsg.time;
254 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
256 msg.wParam = tmpMsg.paramL & 0xFF;
257 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
258 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
260 for (keyDown=i=0; i<256 && !keyDown; i++)
261 if (InputKeyStateTable[i] & 0x80)
264 msg.lParam |= 0x40000000;
265 InputKeyStateTable[msg.wParam] |= 0x80;
266 AsyncKeyStateTable[msg.wParam] |= 0x80;
268 else /* WM_KEYUP, WM_SYSKEYUP */
270 msg.lParam |= 0xC0000000;
271 InputKeyStateTable[msg.wParam] &= ~0x80;
273 if (InputKeyStateTable[VK_MENU] & 0x80)
274 msg.lParam |= 0x20000000;
275 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
276 msg.lParam |= 0x01000000;
278 msg.pt.x = msg.pt.y = 0;
279 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
281 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
283 switch (tmpMsg.message)
286 InputKeyStateTable[VK_LBUTTON] |= 0x80;
287 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
290 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
293 InputKeyStateTable[VK_MBUTTON] |= 0x80;
294 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
297 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
300 InputKeyStateTable[VK_RBUTTON] |= 0x80;
301 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
304 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
307 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
308 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
310 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
311 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
312 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
314 msg.pt.x = tmpMsg.paramL;
315 msg.pt.y = tmpMsg.paramH;
316 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
318 HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE );
322 if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE );
328 /***********************************************************************
329 * process_raw_keyboard_message
331 * returns TRUE if the contents of 'msg' should be passed to the application
333 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 event.message = msg->message;
346 event.hwnd = msg->hwnd;
347 event.time = msg->time;
348 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
349 event.paramH = msg->lParam & 0x7FFF;
350 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
351 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
353 /* if we are going to throw away the message, update the queue state now */
354 if (!msg->hwnd) update_queue_key_state( msg->message, msg->wParam, msg->lParam );
356 return (msg->hwnd != 0);
360 /***********************************************************************
361 * process_cooked_keyboard_message
363 * returns TRUE if the contents of 'msg' should be passed to the application
365 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
369 update_queue_key_state( msg->message, msg->wParam, msg->lParam );
371 /* Handle F1 key by sending out WM_HELP message */
372 if ((msg->message == WM_KEYUP) &&
373 (msg->wParam == VK_F1) &&
374 (msg->hwnd != GetDesktopWindow()) &&
375 !MENU_IsMenuActive())
378 hi.cbSize = sizeof(HELPINFO);
379 hi.iContextType = HELPINFO_WINDOW;
380 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
381 hi.hItemHandle = msg->hwnd;
382 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
383 hi.MousePos = msg->pt;
384 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
388 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
389 LOWORD(msg->wParam), msg->lParam, TRUE ))
391 /* skip this message */
392 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
399 /***********************************************************************
400 * process_raw_mouse_message
402 * returns TRUE if the contents of 'msg' should be passed to the application
404 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
413 /* find the window to dispatch this mouse message to */
416 GetGUIThreadInfo( GetCurrentThreadId(), &info );
417 if (!(msg->hwnd = info.hwndCapture))
419 /* If no capture HWND, find window which contains the mouse position.
420 * Also find the position of the cursor hot spot (hittest) */
421 HWND hWndScope = (HWND)extra_info;
423 if (!IsWindow(hWndScope)) hWndScope = 0;
424 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
425 msg->hwnd = GetDesktopWindow();
428 event.message = msg->message;
429 event.time = msg->time;
430 event.hwnd = msg->hwnd;
431 event.paramL = msg->pt.x;
432 event.paramH = msg->pt.y;
433 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
435 /* translate double clicks */
437 if ((msg->message == WM_LBUTTONDOWN) ||
438 (msg->message == WM_RBUTTONDOWN) ||
439 (msg->message == WM_MBUTTONDOWN))
442 /* translate double clicks -
443 * note that ...MOUSEMOVEs can slip in between
444 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
446 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
447 hittest != HTCLIENT ||
448 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
450 if ((msg->message == clk_msg.message) &&
451 (msg->hwnd == clk_msg.hwnd) &&
452 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
453 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
454 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
456 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
461 /* update static double click conditions */
462 if (update) clk_msg = *msg;
466 /* Note: windows has no concept of a non-client wheel message */
467 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
469 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
470 msg->wParam = hittest;
474 /* coordinates don't get translated while tracking a menu */
475 /* FIXME: should differentiate popups and top-level menus */
476 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
478 msg->lParam = MAKELONG( pt.x, pt.y );
483 /***********************************************************************
484 * process_cooked_mouse_message
486 * returns TRUE if the contents of 'msg' should be passed to the application
488 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
490 MOUSEHOOKSTRUCT hook;
491 INT hittest = HTCLIENT;
492 UINT raw_message = msg->message;
495 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
497 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
498 hittest = msg->wParam;
500 if (raw_message == WM_LBUTTONDBLCLK ||
501 raw_message == WM_RBUTTONDBLCLK ||
502 raw_message == WM_MBUTTONDBLCLK)
504 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
507 if (remove) update_queue_key_state( raw_message, 0, 0 );
510 hook.hwnd = msg->hwnd;
511 hook.wHitTestCode = hittest;
512 hook.dwExtraInfo = extra_info;
513 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
514 msg->message, (LPARAM)&hook, TRUE ))
517 hook.hwnd = msg->hwnd;
518 hook.wHitTestCode = hittest;
519 hook.dwExtraInfo = extra_info;
520 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
524 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
526 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
527 MAKELONG( hittest, raw_message ));
531 if (!remove || GetCapture()) return TRUE;
535 if ((raw_message == WM_LBUTTONDOWN) ||
536 (raw_message == WM_RBUTTONDOWN) ||
537 (raw_message == WM_MBUTTONDOWN))
539 /* Send the WM_PARENTNOTIFY,
540 * note that even for double/nonclient clicks
541 * notification message is still WM_L/M/RBUTTONDOWN.
543 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
545 /* Activate the window if needed */
547 if (msg->hwnd != GetActiveWindow())
549 HWND hwndTop = msg->hwnd;
552 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
553 hwndTop = GetParent( hwndTop );
556 if (hwndTop && hwndTop != GetDesktopWindow())
558 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
559 MAKELONG( hittest, raw_message ) );
562 case MA_NOACTIVATEANDEAT:
567 case MA_ACTIVATEANDEAT:
572 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
575 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
582 /* send the WM_SETCURSOR message */
584 /* Windows sends the normal mouse message as the message parameter
585 in the WM_SETCURSOR message even if it's non-client mouse message */
586 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
587 MAKELONG( hittest, raw_message ));
593 /***********************************************************************
594 * process_hardware_message
596 * returns TRUE if the contents of 'msg' should be passed to the application
598 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
599 UINT first, UINT last, BOOL remove )
601 if (is_keyboard_message( msg->message ))
603 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
605 else if (is_mouse_message( msg->message ))
607 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
611 ERR( "unknown message type %x\n", msg->message );
615 /* check destination thread and filters */
616 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
617 !WIN_IsCurrentThread( msg->hwnd ))
619 /* queue it for later, or for another thread */
620 queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
624 /* save the message in the cooked queue if we didn't want to remove it */
625 if (!remove) queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
630 /***********************************************************************
631 * MSG_process_cooked_hardware_message
633 * returns TRUE if the contents of 'msg' should be passed to the application
635 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
637 if (is_keyboard_message( msg->message ))
638 return process_cooked_keyboard_message( msg, remove );
640 if (is_mouse_message( msg->message ))
641 return process_cooked_mouse_message( msg, extra_info, remove );
643 ERR( "unknown message type %x\n", msg->message );
648 /**********************************************************************
649 * GetKeyState (USER.106)
651 INT16 WINAPI GetKeyState16(INT16 vkey)
653 return GetKeyState(vkey);
657 /**********************************************************************
658 * GetKeyState (USER32.@)
660 * An application calls the GetKeyState function in response to a
661 * keyboard-input message. This function retrieves the state of the key
662 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
664 SHORT WINAPI GetKeyState(INT vkey)
668 if (vkey >= 'a' && vkey <= 'z') vkey += 'A' - 'a';
669 retval = ((WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
670 (QueueKeyStateTable[vkey] & 0x80) |
671 (QueueKeyStateTable[vkey] & 0x01);
672 TRACE("key (0x%x) -> %x\n", vkey, retval);
677 /**********************************************************************
678 * GetKeyboardState (USER.222)
679 * GetKeyboardState (USER32.@)
681 * An application calls the GetKeyboardState function in response to a
682 * keyboard input message. This function retrieves the state of the keyboard
683 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
685 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
687 TRACE_(key)("(%p)\n", lpKeyState);
688 if (lpKeyState) memcpy(lpKeyState, QueueKeyStateTable, 256);
693 /**********************************************************************
694 * SetKeyboardState (USER.223)
695 * SetKeyboardState (USER32.@)
697 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
699 TRACE_(key)("(%p)\n", lpKeyState);
700 if (lpKeyState) memcpy(QueueKeyStateTable, lpKeyState, 256);
705 /***********************************************************************
706 * WaitMessage (USER.112) Suspend thread pending messages
707 * WaitMessage (USER32.@) Suspend thread pending messages
709 * WaitMessage() suspends a thread until events appear in the thread's
712 BOOL WINAPI WaitMessage(void)
714 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
718 /***********************************************************************
719 * MsgWaitForMultipleObjectsEx (USER32.@)
721 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
722 DWORD timeout, DWORD mask, DWORD flags )
724 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
726 MESSAGEQUEUE *msgQueue;
728 if (count > MAXIMUM_WAIT_OBJECTS-1)
730 SetLastError( ERROR_INVALID_PARAMETER );
734 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
736 /* set the queue mask */
737 SERVER_START_REQ( set_queue_mask )
739 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
740 req->changed_mask = mask;
742 wine_server_call( req );
746 /* Add the thread event to the handle list */
747 for (i = 0; i < count; i++) handles[i] = pHandles[i];
748 handles[count] = msgQueue->server_queue;
750 ReleaseThunkLock( &lock );
751 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
753 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
754 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
757 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
758 timeout, flags & MWMO_ALERTABLE );
759 if (lock) RestoreThunkLock( lock );
764 /***********************************************************************
765 * MsgWaitForMultipleObjects (USER32.@)
767 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
768 BOOL wait_all, DWORD timeout, DWORD mask )
770 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
771 wait_all ? MWMO_WAITALL : 0 );
775 /***********************************************************************
776 * WaitForInputIdle (USER32.@)
778 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
780 DWORD start_time, elapsed, ret;
781 HANDLE idle_event = (HANDLE)-1;
783 SERVER_START_REQ( wait_input_idle )
785 req->handle = hProcess;
786 req->timeout = dwTimeOut;
787 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
790 if (ret) return WAIT_FAILED; /* error */
791 if (!idle_event) return 0; /* no event to wait on */
793 start_time = GetTickCount();
796 TRACE("waiting for %p\n", idle_event );
799 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
802 case WAIT_OBJECT_0+1:
803 process_sent_messages();
807 TRACE("timeout or error\n");
813 if (dwTimeOut != INFINITE)
815 elapsed = GetTickCount() - start_time;
816 if (elapsed > dwTimeOut)
826 /***********************************************************************
827 * UserYield (USER.332)
829 void WINAPI UserYield16(void)
833 /* Handle sent messages */
834 process_sent_messages();
837 ReleaseThunkLock(&count);
840 RestoreThunkLock(count);
841 /* Handle sent messages again */
842 process_sent_messages();
854 static const struct accent_char accent_chars[] =
856 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
857 {'`', 'A', '\300'}, {'`', 'a', '\340'},
858 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
859 {'^', 'A', '\302'}, {'^', 'a', '\342'},
860 {'~', 'A', '\303'}, {'~', 'a', '\343'},
861 {'"', 'A', '\304'}, {'"', 'a', '\344'},
862 {'O', 'A', '\305'}, {'o', 'a', '\345'},
863 {'0', 'A', '\305'}, {'0', 'a', '\345'},
864 {'A', 'A', '\305'}, {'a', 'a', '\345'},
865 {'A', 'E', '\306'}, {'a', 'e', '\346'},
866 {',', 'C', '\307'}, {',', 'c', '\347'},
867 {'`', 'E', '\310'}, {'`', 'e', '\350'},
868 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
869 {'^', 'E', '\312'}, {'^', 'e', '\352'},
870 {'"', 'E', '\313'}, {'"', 'e', '\353'},
871 {'`', 'I', '\314'}, {'`', 'i', '\354'},
872 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
873 {'^', 'I', '\316'}, {'^', 'i', '\356'},
874 {'"', 'I', '\317'}, {'"', 'i', '\357'},
875 {'-', 'D', '\320'}, {'-', 'd', '\360'},
876 {'~', 'N', '\321'}, {'~', 'n', '\361'},
877 {'`', 'O', '\322'}, {'`', 'o', '\362'},
878 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
879 {'^', 'O', '\324'}, {'^', 'o', '\364'},
880 {'~', 'O', '\325'}, {'~', 'o', '\365'},
881 {'"', 'O', '\326'}, {'"', 'o', '\366'},
882 {'/', 'O', '\330'}, {'/', 'o', '\370'},
883 {'`', 'U', '\331'}, {'`', 'u', '\371'},
884 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
885 {'^', 'U', '\333'}, {'^', 'u', '\373'},
886 {'"', 'U', '\334'}, {'"', 'u', '\374'},
887 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
888 {'T', 'H', '\336'}, {'t', 'h', '\376'},
889 {'s', 's', '\337'}, {'"', 'y', '\377'},
890 {'s', 'z', '\337'}, {'i', 'j', '\377'},
891 /* iso-8859-2 uses this */
892 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
893 {'<', 'S', '\251'}, {'<', 's', '\271'},
894 {'<', 'T', '\253'}, {'<', 't', '\273'},
895 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
896 {'<', 'C', '\310'}, {'<', 'c', '\350'},
897 {'<', 'E', '\314'}, {'<', 'e', '\354'},
898 {'<', 'D', '\317'}, {'<', 'd', '\357'},
899 {'<', 'N', '\322'}, {'<', 'n', '\362'},
900 {'<', 'R', '\330'}, {'<', 'r', '\370'},
901 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
902 {';', 'E', '\312'}, {';', 'e', '\332'},
903 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
904 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
905 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
906 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
907 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
908 /* collision whith S, from iso-8859-9 !!! */
909 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
910 {',', 'T', '\336'}, {',', 't', '\376'},
911 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
912 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
913 {'/', 'D', '\320'}, {'/', 'd', '\360'},
914 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
915 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
916 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
917 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
918 /* iso-8859-3 uses this */
919 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
920 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
921 {'>', 'J', '\254'}, {'>', 'j', '\274'},
922 {'>', 'C', '\306'}, {'>', 'c', '\346'},
923 {'>', 'G', '\330'}, {'>', 'g', '\370'},
924 {'>', 'S', '\336'}, {'>', 's', '\376'},
925 /* collision whith G( from iso-8859-9 !!! */
926 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
927 {'(', 'U', '\335'}, {'(', 'u', '\375'},
928 /* collision whith I. from iso-8859-3 !!! */
929 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
930 {'.', 'C', '\305'}, {'.', 'c', '\345'},
931 {'.', 'G', '\325'}, {'.', 'g', '\365'},
932 /* iso-8859-4 uses this */
933 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
934 {',', 'L', '\246'}, {',', 'l', '\266'},
935 {',', 'G', '\253'}, {',', 'g', '\273'},
936 {',', 'N', '\321'}, {',', 'n', '\361'},
937 {',', 'K', '\323'}, {',', 'k', '\363'},
938 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
939 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
940 {'-', 'A', '\300'}, {'-', 'a', '\340'},
941 {'-', 'I', '\317'}, {'-', 'i', '\357'},
942 {'-', 'O', '\322'}, {'-', 'o', '\362'},
943 {'-', 'U', '\336'}, {'-', 'u', '\376'},
944 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
945 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
946 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
947 {';', 'U', '\331'}, {';', 'u', '\371'},
948 /* iso-8859-9 uses this */
949 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
950 * whith the same letters on other iso-8859-x (that is they are on
951 * different places :-( ), if you use turkish uncomment these and
952 * comment out the lines in iso-8859-2 and iso-8859-3 sections
953 * FIXME: should be dynamic according to chosen language
954 * if/when Wine has turkish support.
956 /* collision whith G( from iso-8859-3 !!! */
957 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
958 /* collision whith S, from iso-8859-2 !!! */
959 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
960 /* collision whith I. from iso-8859-3 !!! */
961 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
965 /***********************************************************************
966 * TranslateMessage (USER32.@)
968 * Implementation of TranslateMessage.
970 * TranslateMessage translates virtual-key messages into character-messages,
972 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
973 * ditto replacing WM_* with WM_SYS*
974 * This produces WM_CHAR messages only for keys mapped to ASCII characters
975 * by the keyboard driver.
977 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
978 * return value is nonzero, regardless of the translation.
981 BOOL WINAPI TranslateMessage( const MSG *msg )
983 static int dead_char;
988 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
990 TRACE_(key)("(%s, %04X, %08lX)\n",
991 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
993 /* Return code must be TRUE no matter what! */
997 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
999 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
1000 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
1002 /* FIXME : should handle ToUnicode yielding 2 */
1003 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
1006 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1007 /* Should dead chars handling go in ToAscii ? */
1012 if (wp[0] == ' ') wp[0] = dead_char;
1013 if (dead_char == 0xa2) dead_char = '(';
1014 else if (dead_char == 0xa8) dead_char = '"';
1015 else if (dead_char == 0xb2) dead_char = ';';
1016 else if (dead_char == 0xb4) dead_char = '\'';
1017 else if (dead_char == 0xb7) dead_char = '<';
1018 else if (dead_char == 0xb8) dead_char = ',';
1019 else if (dead_char == 0xff) dead_char = '.';
1020 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1021 if ((accent_chars[i].ac_accent == dead_char) &&
1022 (accent_chars[i].ac_char == wp[0]))
1024 wp[0] = accent_chars[i].ac_result;
1029 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1030 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1034 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1036 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1037 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1044 /***********************************************************************
1045 * DispatchMessageA (USER32.@)
1047 LONG WINAPI DispatchMessageA( const MSG* msg )
1054 /* Process timer messages */
1055 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1059 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1061 /* before calling window proc, verify whether timer is still valid;
1062 there's a slim chance that the application kills the timer
1063 between GetMessage and DispatchMessage API calls */
1064 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1065 return 0; /* invalid winproc */
1067 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
1068 msg->message, msg->wParam, GetTickCount() );
1072 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1074 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1077 if (wndPtr == WND_OTHER_PROCESS)
1079 if (IsWindow( msg->hwnd ))
1080 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
1081 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1084 if (!(winproc = wndPtr->winproc))
1086 WIN_ReleasePtr( wndPtr );
1089 painting = (msg->message == WM_PAINT);
1090 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1091 WIN_ReleasePtr( wndPtr );
1092 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1094 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1095 msg->wParam, msg->lParam );
1096 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
1097 msg->wParam, msg->lParam );
1098 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1099 msg->wParam, msg->lParam );
1101 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1103 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1104 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1105 WIN_ReleasePtr( wndPtr );
1108 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
1109 /* Validate the update region to avoid infinite WM_PAINT loop */
1110 RedrawWindow( msg->hwnd, NULL, 0,
1111 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1118 /***********************************************************************
1119 * DispatchMessageW (USER32.@) Process Message
1121 * Process the message specified in the structure *_msg_.
1123 * If the lpMsg parameter points to a WM_TIMER message and the
1124 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1125 * points to the function that is called instead of the window
1128 * The message must be valid.
1132 * DispatchMessage() returns the result of the window procedure invoked.
1139 LONG WINAPI DispatchMessageW( const MSG* msg )
1146 /* Process timer messages */
1147 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1151 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1153 /* before calling window proc, verify whether timer is still valid;
1154 there's a slim chance that the application kills the timer
1155 between GetMessage and DispatchMessage API calls */
1156 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1157 return 0; /* invalid winproc */
1159 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
1160 msg->message, msg->wParam, GetTickCount() );
1164 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1166 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1169 if (wndPtr == WND_OTHER_PROCESS)
1171 if (IsWindow( msg->hwnd ))
1172 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
1173 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1176 if (!(winproc = wndPtr->winproc))
1178 WIN_ReleasePtr( wndPtr );
1181 painting = (msg->message == WM_PAINT);
1182 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1183 WIN_ReleasePtr( wndPtr );
1184 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1186 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1187 msg->wParam, msg->lParam );
1188 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1189 msg->wParam, msg->lParam );
1190 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1191 msg->wParam, msg->lParam );
1193 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1195 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1196 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1197 WIN_ReleasePtr( wndPtr );
1200 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
1201 /* Validate the update region to avoid infinite WM_PAINT loop */
1202 RedrawWindow( msg->hwnd, NULL, 0,
1203 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1210 /***********************************************************************
1211 * RegisterWindowMessage (USER.118)
1212 * RegisterWindowMessageA (USER32.@)
1214 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1216 TRACE("%s\n", str );
1217 return GlobalAddAtomA( str );
1221 /***********************************************************************
1222 * RegisterWindowMessageW (USER32.@)
1224 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1226 TRACE("%p\n", str );
1227 return GlobalAddAtomW( str );
1231 /***********************************************************************
1232 * BroadcastSystemMessage (USER32.@)
1233 * BroadcastSystemMessageA (USER32.@)
1235 LONG WINAPI BroadcastSystemMessage(
1236 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1239 if ((*recipients & BSM_APPLICATIONS)||
1240 (*recipients == BSM_ALLCOMPONENTS))
1242 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1243 dwFlags,*recipients,uMessage,wParam,lParam);
1244 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
1249 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1250 dwFlags,*recipients,uMessage,wParam,lParam);