2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
18 #include "wine/server.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(msg);
35 DECLARE_DEBUG_CHANNEL(key);
37 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
38 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
40 static BYTE QueueKeyStateTable[256];
41 static UINT doubleClickSpeed = 452;
44 /***********************************************************************
47 inline static BOOL is_keyboard_message( UINT message )
49 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
53 /***********************************************************************
56 inline static BOOL is_mouse_message( UINT message )
58 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
59 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
63 /***********************************************************************
64 * check_message_filter
66 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
70 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
74 return (msg->message >= first && msg->message <= last);
80 /***********************************************************************
81 * process_sent_messages
83 * Process all pending sent messages.
85 inline static void process_sent_messages(void)
88 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
92 /***********************************************************************
93 * queue_hardware_message
95 * store a hardware message in the thread queue
97 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_type type )
99 SERVER_START_REQ( send_message )
102 req->id = (void *)GetWindowThreadProcessId( msg->hwnd, NULL );
103 req->win = msg->hwnd;
104 req->msg = msg->message;
105 req->wparam = msg->wParam;
106 req->lparam = msg->lParam;
109 req->time = msg->time;
110 req->info = extra_info;
118 /***********************************************************************
119 * update_queue_key_state
121 static void update_queue_key_state( UINT msg, WPARAM wp )
156 BYTE *p = &QueueKeyStateTable[wp];
157 if (!(*p & 0x80)) *p ^= 0x01;
160 else QueueKeyStateTable[wp] &= ~0x80;
164 /***********************************************************************
165 * MSG_SendParentNotify
167 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
168 * the window has the WS_EX_NOPARENTNOTIFY style.
170 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
172 /* pt has to be in the client coordinates of the parent window */
173 MapWindowPoints( 0, hwnd, &pt, 1 );
178 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
179 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
180 if (!(parent = GetParent(hwnd))) break;
181 MapWindowPoints( hwnd, parent, &pt, 1 );
183 SendMessageA( hwnd, WM_PARENTNOTIFY,
184 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
189 /***********************************************************************
190 * MSG_JournalPlayBackMsg
192 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
194 void MSG_JournalPlayBackMsg(void)
201 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return;
203 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
204 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
208 msg.message = tmpMsg.message;
209 msg.hwnd = tmpMsg.hwnd;
210 msg.time = tmpMsg.time;
211 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
213 msg.wParam = tmpMsg.paramL & 0xFF;
214 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
215 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
217 for (keyDown=i=0; i<256 && !keyDown; i++)
218 if (InputKeyStateTable[i] & 0x80)
221 msg.lParam |= 0x40000000;
222 InputKeyStateTable[msg.wParam] |= 0x80;
223 AsyncKeyStateTable[msg.wParam] |= 0x80;
225 else /* WM_KEYUP, WM_SYSKEYUP */
227 msg.lParam |= 0xC0000000;
228 InputKeyStateTable[msg.wParam] &= ~0x80;
230 if (InputKeyStateTable[VK_MENU] & 0x80)
231 msg.lParam |= 0x20000000;
232 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
233 msg.lParam |= 0x01000000;
235 msg.pt.x = msg.pt.y = 0;
236 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
238 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
240 switch (tmpMsg.message)
243 InputKeyStateTable[VK_LBUTTON] |= 0x80;
244 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
247 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
250 InputKeyStateTable[VK_MBUTTON] |= 0x80;
251 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
254 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
257 InputKeyStateTable[VK_RBUTTON] |= 0x80;
258 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
261 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
264 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
265 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
267 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
268 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
269 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
271 msg.pt.x = tmpMsg.paramL;
272 msg.pt.y = tmpMsg.paramH;
273 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
275 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
279 if( tmpMsg.message == WM_QUEUESYNC )
280 if (HOOK_IsHooked( WH_CBT ))
281 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
286 /***********************************************************************
287 * process_raw_keyboard_message
289 * returns TRUE if the contents of 'msg' should be passed to the application
291 static BOOL process_raw_keyboard_message( MSG *msg, ULONG_PTR extra_info )
293 if (!(msg->hwnd = GetFocus()))
295 /* Send the message to the active window instead, */
296 /* translating messages to their WM_SYS equivalent */
297 msg->hwnd = GetActiveWindow();
298 if (msg->message < WM_SYSKEYDOWN) msg->message += WM_SYSKEYDOWN - WM_KEYDOWN;
301 if (HOOK_IsHooked( WH_JOURNALRECORD ))
305 event.message = msg->message;
306 event.hwnd = msg->hwnd;
307 event.time = msg->time;
308 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
309 event.paramH = msg->lParam & 0x7FFF;
310 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
311 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
314 return (msg->hwnd != 0);
318 /***********************************************************************
319 * process_cooked_keyboard_message
321 * returns TRUE if the contents of 'msg' should be passed to the application
323 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
327 update_queue_key_state( msg->message, msg->wParam );
329 /* Handle F1 key by sending out WM_HELP message */
330 if ((msg->message == WM_KEYUP) &&
331 (msg->wParam == VK_F1) &&
332 (msg->hwnd != GetDesktopWindow()) &&
333 !MENU_IsMenuActive())
336 hi.cbSize = sizeof(HELPINFO);
337 hi.iContextType = HELPINFO_WINDOW;
338 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
339 hi.hItemHandle = msg->hwnd;
340 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
341 hi.MousePos = msg->pt;
342 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
346 if (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
347 LOWORD(msg->wParam), msg->lParam ))
349 /* skip this message */
350 HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam );
357 /***********************************************************************
358 * process_raw_mouse_message
360 * returns TRUE if the contents of 'msg' should be passed to the application
362 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
369 /* find the window to dispatch this mouse message to */
372 if (!(msg->hwnd = PERQDATA_GetCaptureWnd( &ht )))
374 /* If no capture HWND, find window which contains the mouse position.
375 * Also find the position of the cursor hot spot (hittest) */
376 HWND hWndScope = (HWND)extra_info;
378 if (!IsWindow(hWndScope)) hWndScope = 0;
379 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
380 msg->hwnd = GetDesktopWindow();
384 if (HOOK_IsHooked( WH_JOURNALRECORD ))
387 event.message = msg->message;
388 event.time = msg->time;
389 event.hwnd = msg->hwnd;
390 event.paramL = msg->pt.x;
391 event.paramH = msg->pt.y;
392 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
395 /* translate double clicks */
397 if ((msg->message == WM_LBUTTONDOWN) ||
398 (msg->message == WM_RBUTTONDOWN) ||
399 (msg->message == WM_MBUTTONDOWN))
402 /* translate double clicks -
403 * note that ...MOUSEMOVEs can slip in between
404 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
406 if (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS || ht != HTCLIENT )
408 if ((msg->message == clk_msg.message) &&
409 (msg->hwnd == clk_msg.hwnd) &&
410 (msg->time - clk_msg.time < doubleClickSpeed) &&
411 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
412 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
414 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
419 /* update static double click conditions */
420 if (update) clk_msg = *msg;
424 /* Note: windows has no concept of a non-client wheel message */
425 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
427 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
428 msg->wParam = hittest;
430 else ScreenToClient( msg->hwnd, &pt );
431 msg->lParam = MAKELONG( pt.x, pt.y );
436 /***********************************************************************
437 * process_cooked_mouse_message
439 * returns TRUE if the contents of 'msg' should be passed to the application
441 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
443 INT hittest = HTCLIENT;
444 UINT raw_message = msg->message;
447 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
449 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
450 hittest = msg->wParam;
452 if (raw_message == WM_LBUTTONDBLCLK ||
453 raw_message == WM_RBUTTONDBLCLK ||
454 raw_message == WM_MBUTTONDBLCLK)
456 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
459 if (remove) update_queue_key_state( raw_message, 0 );
461 if (HOOK_IsHooked( WH_MOUSE ))
463 MOUSEHOOKSTRUCT hook;
465 hook.hwnd = msg->hwnd;
466 hook.wHitTestCode = hittest;
467 hook.dwExtraInfo = extra_info;
468 if (HOOK_CallHooksA( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
469 msg->message, (LPARAM)&hook ))
472 hook.hwnd = msg->hwnd;
473 hook.wHitTestCode = hittest;
474 hook.dwExtraInfo = extra_info;
475 HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook );
480 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
482 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
486 if (!remove || GetCapture()) return TRUE;
490 if ((raw_message == WM_LBUTTONDOWN) ||
491 (raw_message == WM_RBUTTONDOWN) ||
492 (raw_message == WM_MBUTTONDOWN))
494 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
496 /* Send the WM_PARENTNOTIFY,
497 * note that even for double/nonclient clicks
498 * notification message is still WM_L/M/RBUTTONDOWN.
500 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
502 /* Activate the window if needed */
504 if (msg->hwnd != GetActiveWindow() && hwndTop != GetDesktopWindow())
506 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, hwndTop,
507 MAKELONG( hittest, raw_message ) );
511 case MA_NOACTIVATEANDEAT:
516 case MA_ACTIVATEANDEAT:
521 if (hwndTop != GetForegroundWindow() )
523 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
528 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
534 /* send the WM_SETCURSOR message */
536 /* Windows sends the normal mouse message as the message parameter
537 in the WM_SETCURSOR message even if it's non-client mouse message */
538 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
544 /***********************************************************************
545 * process_hardware_message
547 * returns TRUE if the contents of 'msg' should be passed to the application
549 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
550 UINT first, UINT last, BOOL remove )
552 if (is_keyboard_message( msg->message ))
554 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
556 else if (is_mouse_message( msg->message ))
558 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
562 ERR( "unknown message type %x\n", msg->message );
566 /* check destination thread and filters */
567 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
568 !WIN_IsCurrentThread( msg->hwnd ))
570 /* queue it for later, or for another thread */
571 queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
575 /* save the message in the cooked queue if we didn't want to remove it */
576 if (!remove) queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
581 /***********************************************************************
582 * MSG_process_cooked_hardware_message
584 * returns TRUE if the contents of 'msg' should be passed to the application
586 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
588 if (is_keyboard_message( msg->message ))
589 return process_cooked_keyboard_message( msg, remove );
591 if (is_mouse_message( msg->message ))
592 return process_cooked_mouse_message( msg, extra_info, remove );
594 ERR( "unknown message type %x\n", msg->message );
599 /**********************************************************************
600 * GetKeyState (USER.106)
602 INT16 WINAPI GetKeyState16(INT16 vkey)
604 return GetKeyState(vkey);
608 /**********************************************************************
609 * GetKeyState (USER32.@)
611 * An application calls the GetKeyState function in response to a
612 * keyboard-input message. This function retrieves the state of the key
613 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
615 SHORT WINAPI GetKeyState(INT vkey)
619 if (vkey >= 'a' && vkey <= 'z') vkey += 'A' - 'a';
620 retval = ((WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) | (QueueKeyStateTable[vkey] & 0x01);
621 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
626 /**********************************************************************
627 * GetKeyboardState (USER.222)
628 * GetKeyboardState (USER32.@)
630 * An application calls the GetKeyboardState function in response to a
631 * keyboard-input message. This function retrieves the state of the keyboard
632 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
634 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
636 TRACE_(key)("(%p)\n", lpKeyState);
637 if (lpKeyState) memcpy(lpKeyState, QueueKeyStateTable, 256);
642 /**********************************************************************
643 * SetKeyboardState (USER.223)
644 * SetKeyboardState (USER32.@)
646 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
648 TRACE_(key)("(%p)\n", lpKeyState);
649 if (lpKeyState) memcpy(QueueKeyStateTable, lpKeyState, 256);
654 /**********************************************************************
655 * SetDoubleClickTime (USER32.@)
657 BOOL WINAPI SetDoubleClickTime( UINT interval )
659 doubleClickSpeed = interval ? interval : 500;
664 /**********************************************************************
665 * GetDoubleClickTime (USER32.@)
667 UINT WINAPI GetDoubleClickTime(void)
669 return doubleClickSpeed;
673 /***********************************************************************
674 * WaitMessage (USER.112) Suspend thread pending messages
675 * WaitMessage (USER32.@) Suspend thread pending messages
677 * WaitMessage() suspends a thread until events appear in the thread's
680 BOOL WINAPI WaitMessage(void)
682 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
686 /***********************************************************************
687 * MsgWaitForMultipleObjectsEx (USER32.@)
689 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
690 DWORD timeout, DWORD mask, DWORD flags )
692 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
694 MESSAGEQUEUE *msgQueue;
696 if (count > MAXIMUM_WAIT_OBJECTS-1)
698 SetLastError( ERROR_INVALID_PARAMETER );
702 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
704 /* set the queue mask */
705 SERVER_START_REQ( set_queue_mask )
707 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
708 req->changed_mask = mask;
714 /* Add the thread event to the handle list */
715 for (i = 0; i < count; i++) handles[i] = pHandles[i];
716 handles[count] = msgQueue->server_queue;
719 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
721 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
722 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
725 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
726 timeout, flags & MWMO_ALERTABLE );
731 /***********************************************************************
732 * MsgWaitForMultipleObjects (USER32.@)
734 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
735 BOOL wait_all, DWORD timeout, DWORD mask )
737 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
738 wait_all ? MWMO_WAITALL : 0 );
742 /***********************************************************************
743 * WaitForInputIdle (USER32.@)
745 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
747 DWORD start_time, elapsed, ret;
748 HANDLE idle_event = -1;
750 SERVER_START_REQ( wait_input_idle )
752 req->handle = hProcess;
753 req->timeout = dwTimeOut;
754 if (!(ret = SERVER_CALL_ERR())) idle_event = req->event;
757 if (ret) return WAIT_FAILED; /* error */
758 if (!idle_event) return 0; /* no event to wait on */
760 start_time = GetTickCount();
763 TRACE("waiting for %x\n", idle_event );
766 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
769 case WAIT_OBJECT_0+1:
770 process_sent_messages();
774 TRACE("timeout or error\n");
780 if (dwTimeOut != INFINITE)
782 elapsed = GetTickCount() - start_time;
783 if (elapsed > dwTimeOut)
793 /***********************************************************************
794 * UserYield (USER.332)
795 * UserYield16 (USER32.@)
797 void WINAPI UserYield16(void)
801 /* Handle sent messages */
802 process_sent_messages();
805 ReleaseThunkLock(&count);
808 RestoreThunkLock(count);
809 /* Handle sent messages again */
810 process_sent_messages();
822 static const struct accent_char accent_chars[] =
824 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
825 {'`', 'A', '\300'}, {'`', 'a', '\340'},
826 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
827 {'^', 'A', '\302'}, {'^', 'a', '\342'},
828 {'~', 'A', '\303'}, {'~', 'a', '\343'},
829 {'"', 'A', '\304'}, {'"', 'a', '\344'},
830 {'O', 'A', '\305'}, {'o', 'a', '\345'},
831 {'0', 'A', '\305'}, {'0', 'a', '\345'},
832 {'A', 'A', '\305'}, {'a', 'a', '\345'},
833 {'A', 'E', '\306'}, {'a', 'e', '\346'},
834 {',', 'C', '\307'}, {',', 'c', '\347'},
835 {'`', 'E', '\310'}, {'`', 'e', '\350'},
836 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
837 {'^', 'E', '\312'}, {'^', 'e', '\352'},
838 {'"', 'E', '\313'}, {'"', 'e', '\353'},
839 {'`', 'I', '\314'}, {'`', 'i', '\354'},
840 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
841 {'^', 'I', '\316'}, {'^', 'i', '\356'},
842 {'"', 'I', '\317'}, {'"', 'i', '\357'},
843 {'-', 'D', '\320'}, {'-', 'd', '\360'},
844 {'~', 'N', '\321'}, {'~', 'n', '\361'},
845 {'`', 'O', '\322'}, {'`', 'o', '\362'},
846 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
847 {'^', 'O', '\324'}, {'^', 'o', '\364'},
848 {'~', 'O', '\325'}, {'~', 'o', '\365'},
849 {'"', 'O', '\326'}, {'"', 'o', '\366'},
850 {'/', 'O', '\330'}, {'/', 'o', '\370'},
851 {'`', 'U', '\331'}, {'`', 'u', '\371'},
852 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
853 {'^', 'U', '\333'}, {'^', 'u', '\373'},
854 {'"', 'U', '\334'}, {'"', 'u', '\374'},
855 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
856 {'T', 'H', '\336'}, {'t', 'h', '\376'},
857 {'s', 's', '\337'}, {'"', 'y', '\377'},
858 {'s', 'z', '\337'}, {'i', 'j', '\377'},
859 /* iso-8859-2 uses this */
860 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
861 {'<', 'S', '\251'}, {'<', 's', '\271'},
862 {'<', 'T', '\253'}, {'<', 't', '\273'},
863 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
864 {'<', 'C', '\310'}, {'<', 'c', '\350'},
865 {'<', 'E', '\314'}, {'<', 'e', '\354'},
866 {'<', 'D', '\317'}, {'<', 'd', '\357'},
867 {'<', 'N', '\322'}, {'<', 'n', '\362'},
868 {'<', 'R', '\330'}, {'<', 'r', '\370'},
869 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
870 {';', 'E', '\312'}, {';', 'e', '\332'},
871 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
872 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
873 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
874 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
875 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
876 /* collision whith S, from iso-8859-9 !!! */
877 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
878 {',', 'T', '\336'}, {',', 't', '\376'},
879 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
880 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
881 {'/', 'D', '\320'}, {'/', 'd', '\360'},
882 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
883 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
884 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
885 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
886 /* iso-8859-3 uses this */
887 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
888 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
889 {'>', 'J', '\254'}, {'>', 'j', '\274'},
890 {'>', 'C', '\306'}, {'>', 'c', '\346'},
891 {'>', 'G', '\330'}, {'>', 'g', '\370'},
892 {'>', 'S', '\336'}, {'>', 's', '\376'},
893 /* collision whith G( from iso-8859-9 !!! */
894 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
895 {'(', 'U', '\335'}, {'(', 'u', '\375'},
896 /* collision whith I. from iso-8859-3 !!! */
897 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
898 {'.', 'C', '\305'}, {'.', 'c', '\345'},
899 {'.', 'G', '\325'}, {'.', 'g', '\365'},
900 /* iso-8859-4 uses this */
901 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
902 {',', 'L', '\246'}, {',', 'l', '\266'},
903 {',', 'G', '\253'}, {',', 'g', '\273'},
904 {',', 'N', '\321'}, {',', 'n', '\361'},
905 {',', 'K', '\323'}, {',', 'k', '\363'},
906 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
907 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
908 {'-', 'A', '\300'}, {'-', 'a', '\340'},
909 {'-', 'I', '\317'}, {'-', 'i', '\357'},
910 {'-', 'O', '\322'}, {'-', 'o', '\362'},
911 {'-', 'U', '\336'}, {'-', 'u', '\376'},
912 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
913 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
914 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
915 {';', 'U', '\331'}, {';', 'u', '\371'},
916 /* iso-8859-9 uses this */
917 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
918 * whith the same letters on other iso-8859-x (that is they are on
919 * different places :-( ), if you use turkish uncomment these and
920 * comment out the lines in iso-8859-2 and iso-8859-3 sections
921 * FIXME: should be dynamic according to chosen language
922 * if/when Wine has turkish support.
924 /* collision whith G( from iso-8859-3 !!! */
925 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
926 /* collision whith S, from iso-8859-2 !!! */
927 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
928 /* collision whith I. from iso-8859-3 !!! */
929 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
933 /***********************************************************************
934 * TranslateMessage (USER32.@)
936 * Implementation of TranslateMessage.
938 * TranslateMessage translates virtual-key messages into character-messages,
940 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
941 * ditto replacing WM_* with WM_SYS*
942 * This produces WM_CHAR messages only for keys mapped to ASCII characters
943 * by the keyboard driver.
945 BOOL WINAPI TranslateMessage( const MSG *msg )
947 static int dead_char;
951 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
952 TRACE_(key)("(%s, %04X, %08lX)\n",
953 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
955 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return FALSE;
957 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
958 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
960 /* FIXME : should handle ToUnicode yielding 2 */
961 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
964 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
965 /* Should dead chars handling go in ToAscii ? */
970 if (wp[0] == ' ') wp[0] = dead_char;
971 if (dead_char == 0xa2) dead_char = '(';
972 else if (dead_char == 0xa8) dead_char = '"';
973 else if (dead_char == 0xb2) dead_char = ';';
974 else if (dead_char == 0xb4) dead_char = '\'';
975 else if (dead_char == 0xb7) dead_char = '<';
976 else if (dead_char == 0xb8) dead_char = ',';
977 else if (dead_char == 0xff) dead_char = '.';
978 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
979 if ((accent_chars[i].ac_accent == dead_char) &&
980 (accent_chars[i].ac_char == wp[0]))
982 wp[0] = accent_chars[i].ac_result;
987 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
988 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
992 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
994 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
995 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
1002 /***********************************************************************
1003 * DispatchMessageA (USER32.@)
1005 LONG WINAPI DispatchMessageA( const MSG* msg )
1012 /* Process timer messages */
1013 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1017 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1019 /* before calling window proc, verify whether timer is still valid;
1020 there's a slim chance that the application kills the timer
1021 between GetMessage and DispatchMessage API calls */
1022 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1023 return 0; /* invalid winproc */
1025 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
1026 msg->message, msg->wParam, GetTickCount() );
1030 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1032 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1035 if (wndPtr == WND_OTHER_PROCESS)
1037 if (IsWindow( msg->hwnd ))
1038 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1039 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1042 if (!(winproc = wndPtr->winproc))
1044 WIN_ReleasePtr( wndPtr );
1047 painting = (msg->message == WM_PAINT);
1048 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1049 WIN_ReleasePtr( wndPtr );
1050 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1052 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1053 msg->wParam, msg->lParam );
1054 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
1055 msg->wParam, msg->lParam );
1056 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1057 msg->wParam, msg->lParam );
1059 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1061 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1062 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1063 WIN_ReleasePtr( wndPtr );
1066 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1067 /* Validate the update region to avoid infinite WM_PAINT loop */
1068 RedrawWindow( msg->hwnd, NULL, 0,
1069 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1076 /***********************************************************************
1077 * DispatchMessageW (USER32.@) Process Message
1079 * Process the message specified in the structure *_msg_.
1081 * If the lpMsg parameter points to a WM_TIMER message and the
1082 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1083 * points to the function that is called instead of the window
1086 * The message must be valid.
1090 * DispatchMessage() returns the result of the window procedure invoked.
1097 LONG WINAPI DispatchMessageW( const MSG* msg )
1104 /* Process timer messages */
1105 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1109 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1111 /* before calling window proc, verify whether timer is still valid;
1112 there's a slim chance that the application kills the timer
1113 between GetMessage and DispatchMessage API calls */
1114 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1115 return 0; /* invalid winproc */
1117 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
1118 msg->message, msg->wParam, GetTickCount() );
1122 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1124 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1127 if (wndPtr == WND_OTHER_PROCESS)
1129 if (IsWindow( msg->hwnd ))
1130 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1131 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1134 if (!(winproc = wndPtr->winproc))
1136 WIN_ReleasePtr( wndPtr );
1139 painting = (msg->message == WM_PAINT);
1140 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1141 WIN_ReleasePtr( wndPtr );
1142 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1144 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1145 msg->wParam, msg->lParam );
1146 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1147 msg->wParam, msg->lParam );
1148 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1149 msg->wParam, msg->lParam );
1151 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1153 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1154 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1155 WIN_ReleasePtr( wndPtr );
1158 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1159 /* Validate the update region to avoid infinite WM_PAINT loop */
1160 RedrawWindow( msg->hwnd, NULL, 0,
1161 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1168 /***********************************************************************
1169 * RegisterWindowMessage (USER.118)
1170 * RegisterWindowMessageA (USER32.@)
1172 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1174 TRACE("%s\n", str );
1175 return GlobalAddAtomA( str );
1179 /***********************************************************************
1180 * RegisterWindowMessageW (USER32.@)
1182 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1184 TRACE("%p\n", str );
1185 return GlobalAddAtomW( str );
1189 /***********************************************************************
1190 * BroadcastSystemMessage (USER32.@)
1192 LONG WINAPI BroadcastSystemMessage(
1193 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1196 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1197 dwFlags,*recipients,uMessage,wParam,lParam