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"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg);
49 WINE_DECLARE_DEBUG_CHANNEL(key);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
54 static BYTE QueueKeyStateTable[256];
57 /***********************************************************************
60 inline static BOOL is_keyboard_message( UINT message )
62 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
66 /***********************************************************************
69 inline static BOOL is_mouse_message( UINT message )
71 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
72 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
76 /***********************************************************************
77 * check_message_filter
79 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
83 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
87 return (msg->message >= first && msg->message <= last);
93 /***********************************************************************
94 * process_sent_messages
96 * Process all pending sent messages.
98 inline static void process_sent_messages(void)
101 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
105 /***********************************************************************
106 * queue_hardware_message
108 * store a hardware message in the thread queue
111 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info )
113 SERVER_START_REQ( send_message )
115 req->type = MSG_HARDWARE;
116 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
117 req->win = msg->hwnd;
118 req->msg = msg->message;
119 req->wparam = msg->wParam;
120 req->lparam = msg->lParam;
123 req->time = msg->time;
124 req->info = extra_info;
126 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 );
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 );
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, BOOL remove )
412 HWND hWndScope = msg->hwnd;
414 /* find the window to dispatch this mouse message to */
417 GetGUIThreadInfo( GetCurrentThreadId(), &info );
418 if (!(msg->hwnd = info.hwndCapture))
420 /* If no capture HWND, find window which contains the mouse position.
421 * Also find the position of the cursor hot spot (hittest) */
422 if (!IsWindow(hWndScope)) hWndScope = 0;
423 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
424 msg->hwnd = GetDesktopWindow();
427 event.message = msg->message;
428 event.time = msg->time;
429 event.hwnd = msg->hwnd;
430 event.paramL = msg->pt.x;
431 event.paramH = msg->pt.y;
432 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
434 /* translate double clicks */
436 if ((msg->message == WM_LBUTTONDOWN) ||
437 (msg->message == WM_RBUTTONDOWN) ||
438 (msg->message == WM_MBUTTONDOWN))
440 BOOL update = remove;
441 /* translate double clicks -
442 * note that ...MOUSEMOVEs can slip in between
443 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
445 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
446 hittest != HTCLIENT ||
447 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
449 if ((msg->message == clk_msg.message) &&
450 (msg->hwnd == clk_msg.hwnd) &&
451 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
452 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
453 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
455 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
463 /* update static double click conditions */
464 if (update) clk_msg = *msg;
468 /* Note: windows has no concept of a non-client wheel message */
469 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
471 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
472 msg->wParam = hittest;
476 /* coordinates don't get translated while tracking a menu */
477 /* FIXME: should differentiate popups and top-level menus */
478 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
480 msg->lParam = MAKELONG( pt.x, pt.y );
485 /***********************************************************************
486 * process_cooked_mouse_message
488 * returns TRUE if the contents of 'msg' should be passed to the application
490 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
492 MOUSEHOOKSTRUCT hook;
493 INT hittest = HTCLIENT;
494 UINT raw_message = msg->message;
497 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
499 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
500 hittest = msg->wParam;
502 if (raw_message == WM_LBUTTONDBLCLK ||
503 raw_message == WM_RBUTTONDBLCLK ||
504 raw_message == WM_MBUTTONDBLCLK)
506 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
509 if (remove) update_queue_key_state( raw_message, 0, 0 );
512 hook.hwnd = msg->hwnd;
513 hook.wHitTestCode = hittest;
514 hook.dwExtraInfo = extra_info;
515 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
516 msg->message, (LPARAM)&hook, TRUE ))
519 hook.hwnd = msg->hwnd;
520 hook.wHitTestCode = hittest;
521 hook.dwExtraInfo = extra_info;
522 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
526 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
528 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
529 MAKELONG( hittest, raw_message ));
533 if (!remove || GetCapture()) return TRUE;
537 if ((raw_message == WM_LBUTTONDOWN) ||
538 (raw_message == WM_RBUTTONDOWN) ||
539 (raw_message == WM_MBUTTONDOWN))
541 /* Send the WM_PARENTNOTIFY,
542 * note that even for double/nonclient clicks
543 * notification message is still WM_L/M/RBUTTONDOWN.
545 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
547 /* Activate the window if needed */
549 if (msg->hwnd != GetActiveWindow())
551 HWND hwndTop = msg->hwnd;
554 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
555 hwndTop = GetParent( hwndTop );
558 if (hwndTop && hwndTop != GetDesktopWindow())
560 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
561 MAKELONG( hittest, raw_message ) );
564 case MA_NOACTIVATEANDEAT:
569 case MA_ACTIVATEANDEAT:
574 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
577 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
584 /* send the WM_SETCURSOR message */
586 /* Windows sends the normal mouse message as the message parameter
587 in the WM_SETCURSOR message even if it's non-client mouse message */
588 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
589 MAKELONG( hittest, raw_message ));
595 /***********************************************************************
596 * process_hardware_message
598 * returns TRUE if the contents of 'msg' should be passed to the application
600 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
601 UINT first, UINT last, BOOL remove )
603 if (is_keyboard_message( msg->message ))
605 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
607 else if (is_mouse_message( msg->message ))
609 if (!process_raw_mouse_message( msg, extra_info, remove )) return FALSE;
613 ERR( "unknown message type %x\n", msg->message );
616 return check_message_filter( msg, hwnd_filter, first, last );
620 /***********************************************************************
621 * MSG_process_cooked_hardware_message
623 * returns TRUE if the contents of 'msg' should be passed to the application
625 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
627 if (is_keyboard_message( msg->message ))
628 return process_cooked_keyboard_message( msg, remove );
630 if (is_mouse_message( msg->message ))
631 return process_cooked_mouse_message( msg, extra_info, remove );
633 ERR( "unknown message type %x\n", msg->message );
638 /**********************************************************************
639 * GetKeyState (USER.106)
641 INT16 WINAPI GetKeyState16(INT16 vkey)
643 return GetKeyState(vkey);
647 /**********************************************************************
648 * GetKeyState (USER32.@)
650 * An application calls the GetKeyState function in response to a
651 * keyboard-input message. This function retrieves the state of the key
652 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
654 SHORT WINAPI GetKeyState(INT vkey)
658 if (vkey >= 'a' && vkey <= 'z') vkey += 'A' - 'a';
659 retval = ((WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
660 (QueueKeyStateTable[vkey] & 0x80) |
661 (QueueKeyStateTable[vkey] & 0x01);
662 TRACE("key (0x%x) -> %x\n", vkey, retval);
667 /**********************************************************************
668 * GetKeyboardState (USER.222)
669 * GetKeyboardState (USER32.@)
671 * An application calls the GetKeyboardState function in response to a
672 * keyboard input message. This function retrieves the state of the keyboard
673 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
675 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
677 TRACE_(key)("(%p)\n", lpKeyState);
678 if (lpKeyState) memcpy(lpKeyState, QueueKeyStateTable, 256);
683 /**********************************************************************
684 * SetKeyboardState (USER.223)
685 * SetKeyboardState (USER32.@)
687 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
689 TRACE_(key)("(%p)\n", lpKeyState);
690 if (lpKeyState) memcpy(QueueKeyStateTable, lpKeyState, 256);
695 /***********************************************************************
696 * WaitMessage (USER.112) Suspend thread pending messages
697 * WaitMessage (USER32.@) Suspend thread pending messages
699 * WaitMessage() suspends a thread until events appear in the thread's
702 BOOL WINAPI WaitMessage(void)
704 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
708 /***********************************************************************
709 * MsgWaitForMultipleObjectsEx (USER32.@)
711 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
712 DWORD timeout, DWORD mask, DWORD flags )
714 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
716 MESSAGEQUEUE *msgQueue;
718 if (count > MAXIMUM_WAIT_OBJECTS-1)
720 SetLastError( ERROR_INVALID_PARAMETER );
724 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
726 /* set the queue mask */
727 SERVER_START_REQ( set_queue_mask )
729 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
730 req->changed_mask = mask;
732 wine_server_call( req );
736 /* Add the thread event to the handle list */
737 for (i = 0; i < count; i++) handles[i] = pHandles[i];
738 handles[count] = msgQueue->server_queue;
740 ReleaseThunkLock( &lock );
741 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
743 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
744 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
747 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
748 timeout, flags & MWMO_ALERTABLE );
749 if (lock) RestoreThunkLock( lock );
754 /***********************************************************************
755 * MsgWaitForMultipleObjects (USER32.@)
757 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
758 BOOL wait_all, DWORD timeout, DWORD mask )
760 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
761 wait_all ? MWMO_WAITALL : 0 );
765 /***********************************************************************
766 * WaitForInputIdle (USER32.@)
768 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
770 DWORD start_time, elapsed, ret;
771 HANDLE idle_event = (HANDLE)-1;
773 SERVER_START_REQ( wait_input_idle )
775 req->handle = hProcess;
776 req->timeout = dwTimeOut;
777 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
780 if (ret) return WAIT_FAILED; /* error */
781 if (!idle_event) return 0; /* no event to wait on */
783 start_time = GetTickCount();
786 TRACE("waiting for %p\n", idle_event );
789 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
792 case WAIT_OBJECT_0+1:
793 process_sent_messages();
797 TRACE("timeout or error\n");
803 if (dwTimeOut != INFINITE)
805 elapsed = GetTickCount() - start_time;
806 if (elapsed > dwTimeOut)
816 /***********************************************************************
817 * UserYield (USER.332)
819 void WINAPI UserYield16(void)
823 /* Handle sent messages */
824 process_sent_messages();
827 ReleaseThunkLock(&count);
830 RestoreThunkLock(count);
831 /* Handle sent messages again */
832 process_sent_messages();
844 static const struct accent_char accent_chars[] =
846 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
847 {'`', 'A', '\300'}, {'`', 'a', '\340'},
848 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
849 {'^', 'A', '\302'}, {'^', 'a', '\342'},
850 {'~', 'A', '\303'}, {'~', 'a', '\343'},
851 {'"', 'A', '\304'}, {'"', 'a', '\344'},
852 {'O', 'A', '\305'}, {'o', 'a', '\345'},
853 {'0', 'A', '\305'}, {'0', 'a', '\345'},
854 {'A', 'A', '\305'}, {'a', 'a', '\345'},
855 {'A', 'E', '\306'}, {'a', 'e', '\346'},
856 {',', 'C', '\307'}, {',', 'c', '\347'},
857 {'`', 'E', '\310'}, {'`', 'e', '\350'},
858 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
859 {'^', 'E', '\312'}, {'^', 'e', '\352'},
860 {'"', 'E', '\313'}, {'"', 'e', '\353'},
861 {'`', 'I', '\314'}, {'`', 'i', '\354'},
862 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
863 {'^', 'I', '\316'}, {'^', 'i', '\356'},
864 {'"', 'I', '\317'}, {'"', 'i', '\357'},
865 {'-', 'D', '\320'}, {'-', 'd', '\360'},
866 {'~', 'N', '\321'}, {'~', 'n', '\361'},
867 {'`', 'O', '\322'}, {'`', 'o', '\362'},
868 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
869 {'^', 'O', '\324'}, {'^', 'o', '\364'},
870 {'~', 'O', '\325'}, {'~', 'o', '\365'},
871 {'"', 'O', '\326'}, {'"', 'o', '\366'},
872 {'/', 'O', '\330'}, {'/', 'o', '\370'},
873 {'`', 'U', '\331'}, {'`', 'u', '\371'},
874 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
875 {'^', 'U', '\333'}, {'^', 'u', '\373'},
876 {'"', 'U', '\334'}, {'"', 'u', '\374'},
877 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
878 {'T', 'H', '\336'}, {'t', 'h', '\376'},
879 {'s', 's', '\337'}, {'"', 'y', '\377'},
880 {'s', 'z', '\337'}, {'i', 'j', '\377'},
881 /* iso-8859-2 uses this */
882 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
883 {'<', 'S', '\251'}, {'<', 's', '\271'},
884 {'<', 'T', '\253'}, {'<', 't', '\273'},
885 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
886 {'<', 'C', '\310'}, {'<', 'c', '\350'},
887 {'<', 'E', '\314'}, {'<', 'e', '\354'},
888 {'<', 'D', '\317'}, {'<', 'd', '\357'},
889 {'<', 'N', '\322'}, {'<', 'n', '\362'},
890 {'<', 'R', '\330'}, {'<', 'r', '\370'},
891 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
892 {';', 'E', '\312'}, {';', 'e', '\332'},
893 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
894 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
895 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
896 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
897 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
898 /* collision whith S, from iso-8859-9 !!! */
899 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
900 {',', 'T', '\336'}, {',', 't', '\376'},
901 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
902 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
903 {'/', 'D', '\320'}, {'/', 'd', '\360'},
904 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
905 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
906 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
907 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
908 /* iso-8859-3 uses this */
909 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
910 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
911 {'>', 'J', '\254'}, {'>', 'j', '\274'},
912 {'>', 'C', '\306'}, {'>', 'c', '\346'},
913 {'>', 'G', '\330'}, {'>', 'g', '\370'},
914 {'>', 'S', '\336'}, {'>', 's', '\376'},
915 /* collision whith G( from iso-8859-9 !!! */
916 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
917 {'(', 'U', '\335'}, {'(', 'u', '\375'},
918 /* collision whith I. from iso-8859-3 !!! */
919 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
920 {'.', 'C', '\305'}, {'.', 'c', '\345'},
921 {'.', 'G', '\325'}, {'.', 'g', '\365'},
922 /* iso-8859-4 uses this */
923 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
924 {',', 'L', '\246'}, {',', 'l', '\266'},
925 {',', 'G', '\253'}, {',', 'g', '\273'},
926 {',', 'N', '\321'}, {',', 'n', '\361'},
927 {',', 'K', '\323'}, {',', 'k', '\363'},
928 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
929 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
930 {'-', 'A', '\300'}, {'-', 'a', '\340'},
931 {'-', 'I', '\317'}, {'-', 'i', '\357'},
932 {'-', 'O', '\322'}, {'-', 'o', '\362'},
933 {'-', 'U', '\336'}, {'-', 'u', '\376'},
934 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
935 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
936 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
937 {';', 'U', '\331'}, {';', 'u', '\371'},
938 /* iso-8859-9 uses this */
939 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
940 * whith the same letters on other iso-8859-x (that is they are on
941 * different places :-( ), if you use turkish uncomment these and
942 * comment out the lines in iso-8859-2 and iso-8859-3 sections
943 * FIXME: should be dynamic according to chosen language
944 * if/when Wine has turkish support.
946 /* collision whith G( from iso-8859-3 !!! */
947 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
948 /* collision whith S, from iso-8859-2 !!! */
949 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
950 /* collision whith I. from iso-8859-3 !!! */
951 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
955 /***********************************************************************
956 * TranslateMessage (USER32.@)
958 * Implementation of TranslateMessage.
960 * TranslateMessage translates virtual-key messages into character-messages,
962 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
963 * ditto replacing WM_* with WM_SYS*
964 * This produces WM_CHAR messages only for keys mapped to ASCII characters
965 * by the keyboard driver.
967 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
968 * return value is nonzero, regardless of the translation.
971 BOOL WINAPI TranslateMessage( const MSG *msg )
973 static int dead_char;
978 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
980 TRACE_(key)("(%s, %04X, %08lX)\n",
981 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
983 /* Return code must be TRUE no matter what! */
987 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
989 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
990 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
992 /* FIXME : should handle ToUnicode yielding 2 */
993 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
996 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
997 /* Should dead chars handling go in ToAscii ? */
1002 if (wp[0] == ' ') wp[0] = dead_char;
1003 if (dead_char == 0xa2) dead_char = '(';
1004 else if (dead_char == 0xa8) dead_char = '"';
1005 else if (dead_char == 0xb2) dead_char = ';';
1006 else if (dead_char == 0xb4) dead_char = '\'';
1007 else if (dead_char == 0xb7) dead_char = '<';
1008 else if (dead_char == 0xb8) dead_char = ',';
1009 else if (dead_char == 0xff) dead_char = '.';
1010 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1011 if ((accent_chars[i].ac_accent == dead_char) &&
1012 (accent_chars[i].ac_char == wp[0]))
1014 wp[0] = accent_chars[i].ac_result;
1019 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1020 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1024 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1026 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
1027 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1034 /***********************************************************************
1035 * DispatchMessageA (USER32.@)
1037 LONG WINAPI DispatchMessageA( const MSG* msg )
1044 /* Process timer messages */
1045 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1049 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1051 /* before calling window proc, verify whether timer is still valid;
1052 there's a slim chance that the application kills the timer
1053 between GetMessage and DispatchMessage API calls */
1054 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
1055 return 0; /* invalid winproc */
1057 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
1058 msg->message, msg->wParam, GetTickCount() );
1062 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1064 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1067 if (wndPtr == WND_OTHER_PROCESS)
1069 if (IsWindow( msg->hwnd ))
1070 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
1071 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1074 if (!(winproc = wndPtr->winproc))
1076 WIN_ReleasePtr( wndPtr );
1079 painting = (msg->message == WM_PAINT);
1080 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1081 WIN_ReleasePtr( wndPtr );
1082 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1084 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1085 msg->wParam, msg->lParam );
1086 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
1087 msg->wParam, msg->lParam );
1088 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1089 msg->wParam, msg->lParam );
1091 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1093 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1094 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1095 WIN_ReleasePtr( wndPtr );
1098 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
1099 /* Validate the update region to avoid infinite WM_PAINT loop */
1100 RedrawWindow( msg->hwnd, NULL, 0,
1101 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1108 /***********************************************************************
1109 * DispatchMessageW (USER32.@) Process Message
1111 * Process the message specified in the structure *_msg_.
1113 * If the lpMsg parameter points to a WM_TIMER message and the
1114 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1115 * points to the function that is called instead of the window
1118 * The message must be valid.
1122 * DispatchMessage() returns the result of the window procedure invoked.
1129 LONG WINAPI DispatchMessageW( const MSG* msg )
1136 /* Process timer messages */
1137 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1141 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1143 /* before calling window proc, verify whether timer is still valid;
1144 there's a slim chance that the application kills the timer
1145 between GetMessage and DispatchMessage API calls */
1146 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
1147 return 0; /* invalid winproc */
1149 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
1150 msg->message, msg->wParam, GetTickCount() );
1154 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1156 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1159 if (wndPtr == WND_OTHER_PROCESS)
1161 if (IsWindow( msg->hwnd ))
1162 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
1163 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1166 if (!(winproc = wndPtr->winproc))
1168 WIN_ReleasePtr( wndPtr );
1171 painting = (msg->message == WM_PAINT);
1172 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1173 WIN_ReleasePtr( wndPtr );
1174 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1176 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1177 msg->wParam, msg->lParam );
1178 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1179 msg->wParam, msg->lParam );
1180 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1181 msg->wParam, msg->lParam );
1183 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1185 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1186 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1187 WIN_ReleasePtr( wndPtr );
1190 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
1191 /* Validate the update region to avoid infinite WM_PAINT loop */
1192 RedrawWindow( msg->hwnd, NULL, 0,
1193 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1200 /***********************************************************************
1201 * RegisterWindowMessage (USER.118)
1202 * RegisterWindowMessageA (USER32.@)
1204 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1206 TRACE("%s\n", str );
1207 return GlobalAddAtomA( str );
1211 /***********************************************************************
1212 * RegisterWindowMessageW (USER32.@)
1214 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1216 TRACE("%p\n", str );
1217 return GlobalAddAtomW( str );
1221 /***********************************************************************
1222 * BroadcastSystemMessage (USER32.@)
1223 * BroadcastSystemMessageA (USER32.@)
1225 LONG WINAPI BroadcastSystemMessage(
1226 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1229 if ((*recipients & BSM_APPLICATIONS)||
1230 (*recipients == BSM_ALLCOMPONENTS))
1232 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1233 dwFlags,*recipients,uMessage,wParam,lParam);
1234 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
1239 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1240 dwFlags,*recipients,uMessage,wParam,lParam);