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];
43 /***********************************************************************
46 inline static BOOL is_keyboard_message( UINT message )
48 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
52 /***********************************************************************
55 inline static BOOL is_mouse_message( UINT message )
57 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
58 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
62 /***********************************************************************
63 * check_message_filter
65 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
69 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
73 return (msg->message >= first && msg->message <= last);
79 /***********************************************************************
80 * process_sent_messages
82 * Process all pending sent messages.
84 inline static void process_sent_messages(void)
87 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
91 /***********************************************************************
92 * queue_hardware_message
94 * store a hardware message in the thread queue
96 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_type type )
98 SERVER_START_REQ( send_message )
101 req->id = (void *)GetWindowThreadProcessId( msg->hwnd, NULL );
102 req->win = msg->hwnd;
103 req->msg = msg->message;
104 req->wparam = msg->wParam;
105 req->lparam = msg->lParam;
108 req->time = msg->time;
109 req->info = extra_info;
111 wine_server_call( req );
117 /***********************************************************************
118 * update_queue_key_state
120 static void update_queue_key_state( UINT msg, WPARAM wp )
155 BYTE *p = &QueueKeyStateTable[wp];
156 if (!(*p & 0x80)) *p ^= 0x01;
159 else QueueKeyStateTable[wp] &= ~0x80;
163 /***********************************************************************
164 * MSG_SendParentNotify
166 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
167 * the window has the WS_EX_NOPARENTNOTIFY style.
169 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
171 /* pt has to be in the client coordinates of the parent window */
172 MapWindowPoints( 0, hwnd, &pt, 1 );
177 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
178 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
179 if (!(parent = GetParent(hwnd))) break;
180 MapWindowPoints( hwnd, parent, &pt, 1 );
182 SendMessageA( hwnd, WM_PARENTNOTIFY,
183 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
188 /***********************************************************************
189 * MSG_JournalPlayBackMsg
191 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
193 void MSG_JournalPlayBackMsg(void)
200 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return;
202 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
203 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
207 msg.message = tmpMsg.message;
208 msg.hwnd = tmpMsg.hwnd;
209 msg.time = tmpMsg.time;
210 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
212 msg.wParam = tmpMsg.paramL & 0xFF;
213 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
214 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
216 for (keyDown=i=0; i<256 && !keyDown; i++)
217 if (InputKeyStateTable[i] & 0x80)
220 msg.lParam |= 0x40000000;
221 InputKeyStateTable[msg.wParam] |= 0x80;
222 AsyncKeyStateTable[msg.wParam] |= 0x80;
224 else /* WM_KEYUP, WM_SYSKEYUP */
226 msg.lParam |= 0xC0000000;
227 InputKeyStateTable[msg.wParam] &= ~0x80;
229 if (InputKeyStateTable[VK_MENU] & 0x80)
230 msg.lParam |= 0x20000000;
231 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
232 msg.lParam |= 0x01000000;
234 msg.pt.x = msg.pt.y = 0;
235 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
237 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
239 switch (tmpMsg.message)
242 InputKeyStateTable[VK_LBUTTON] |= 0x80;
243 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
246 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
249 InputKeyStateTable[VK_MBUTTON] |= 0x80;
250 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
253 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
256 InputKeyStateTable[VK_RBUTTON] |= 0x80;
257 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
260 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
263 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
264 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
266 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
267 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
268 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
270 msg.pt.x = tmpMsg.paramL;
271 msg.pt.y = tmpMsg.paramH;
272 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
274 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
278 if( tmpMsg.message == WM_QUEUESYNC )
279 if (HOOK_IsHooked( WH_CBT ))
280 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
285 /***********************************************************************
286 * process_raw_keyboard_message
288 * returns TRUE if the contents of 'msg' should be passed to the application
290 static BOOL process_raw_keyboard_message( MSG *msg, ULONG_PTR extra_info )
292 if (!(msg->hwnd = GetFocus()))
294 /* Send the message to the active window instead, */
295 /* translating messages to their WM_SYS equivalent */
296 msg->hwnd = GetActiveWindow();
297 if (msg->message < WM_SYSKEYDOWN) msg->message += WM_SYSKEYDOWN - WM_KEYDOWN;
300 if (HOOK_IsHooked( WH_JOURNALRECORD ))
304 event.message = msg->message;
305 event.hwnd = msg->hwnd;
306 event.time = msg->time;
307 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
308 event.paramH = msg->lParam & 0x7FFF;
309 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
310 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
313 return (msg->hwnd != 0);
317 /***********************************************************************
318 * process_cooked_keyboard_message
320 * returns TRUE if the contents of 'msg' should be passed to the application
322 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
326 update_queue_key_state( msg->message, msg->wParam );
328 /* Handle F1 key by sending out WM_HELP message */
329 if ((msg->message == WM_KEYUP) &&
330 (msg->wParam == VK_F1) &&
331 (msg->hwnd != GetDesktopWindow()) &&
332 !MENU_IsMenuActive())
335 hi.cbSize = sizeof(HELPINFO);
336 hi.iContextType = HELPINFO_WINDOW;
337 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
338 hi.hItemHandle = msg->hwnd;
339 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
340 hi.MousePos = msg->pt;
341 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
345 if (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
346 LOWORD(msg->wParam), msg->lParam ))
348 /* skip this message */
349 HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam );
356 /***********************************************************************
357 * process_raw_mouse_message
359 * returns TRUE if the contents of 'msg' should be passed to the application
361 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
368 /* find the window to dispatch this mouse message to */
371 if (!(msg->hwnd = PERQDATA_GetCaptureWnd( &ht )))
373 /* If no capture HWND, find window which contains the mouse position.
374 * Also find the position of the cursor hot spot (hittest) */
375 HWND hWndScope = (HWND)extra_info;
377 if (!IsWindow(hWndScope)) hWndScope = 0;
378 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
379 msg->hwnd = GetDesktopWindow();
383 if (HOOK_IsHooked( WH_JOURNALRECORD ))
386 event.message = msg->message;
387 event.time = msg->time;
388 event.hwnd = msg->hwnd;
389 event.paramL = msg->pt.x;
390 event.paramH = msg->pt.y;
391 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
394 /* translate double clicks */
396 if ((msg->message == WM_LBUTTONDOWN) ||
397 (msg->message == WM_RBUTTONDOWN) ||
398 (msg->message == WM_MBUTTONDOWN))
401 /* translate double clicks -
402 * note that ...MOUSEMOVEs can slip in between
403 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
405 if (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS || ht != HTCLIENT )
407 if ((msg->message == clk_msg.message) &&
408 (msg->hwnd == clk_msg.hwnd) &&
409 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
410 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
411 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
413 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
418 /* update static double click conditions */
419 if (update) clk_msg = *msg;
423 /* Note: windows has no concept of a non-client wheel message */
424 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
426 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
427 msg->wParam = hittest;
429 else ScreenToClient( msg->hwnd, &pt );
430 msg->lParam = MAKELONG( pt.x, pt.y );
435 /***********************************************************************
436 * process_cooked_mouse_message
438 * returns TRUE if the contents of 'msg' should be passed to the application
440 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
442 INT hittest = HTCLIENT;
443 UINT raw_message = msg->message;
446 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
448 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
449 hittest = msg->wParam;
451 if (raw_message == WM_LBUTTONDBLCLK ||
452 raw_message == WM_RBUTTONDBLCLK ||
453 raw_message == WM_MBUTTONDBLCLK)
455 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
458 if (remove) update_queue_key_state( raw_message, 0 );
460 if (HOOK_IsHooked( WH_MOUSE ))
462 MOUSEHOOKSTRUCT hook;
464 hook.hwnd = msg->hwnd;
465 hook.wHitTestCode = hittest;
466 hook.dwExtraInfo = extra_info;
467 if (HOOK_CallHooksA( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
468 msg->message, (LPARAM)&hook ))
471 hook.hwnd = msg->hwnd;
472 hook.wHitTestCode = hittest;
473 hook.dwExtraInfo = extra_info;
474 HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook );
479 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
481 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
485 if (!remove || GetCapture()) return TRUE;
489 if ((raw_message == WM_LBUTTONDOWN) ||
490 (raw_message == WM_RBUTTONDOWN) ||
491 (raw_message == WM_MBUTTONDOWN))
493 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
495 /* Send the WM_PARENTNOTIFY,
496 * note that even for double/nonclient clicks
497 * notification message is still WM_L/M/RBUTTONDOWN.
499 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
501 /* Activate the window if needed */
503 if (msg->hwnd != GetActiveWindow() && hwndTop != GetDesktopWindow())
505 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, hwndTop,
506 MAKELONG( hittest, raw_message ) );
510 case MA_NOACTIVATEANDEAT:
515 case MA_ACTIVATEANDEAT:
520 if (hwndTop != GetForegroundWindow() )
522 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
527 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
533 /* send the WM_SETCURSOR message */
535 /* Windows sends the normal mouse message as the message parameter
536 in the WM_SETCURSOR message even if it's non-client mouse message */
537 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
543 /***********************************************************************
544 * process_hardware_message
546 * returns TRUE if the contents of 'msg' should be passed to the application
548 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
549 UINT first, UINT last, BOOL remove )
551 if (is_keyboard_message( msg->message ))
553 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
555 else if (is_mouse_message( msg->message ))
557 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
561 ERR( "unknown message type %x\n", msg->message );
565 /* check destination thread and filters */
566 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
567 !WIN_IsCurrentThread( msg->hwnd ))
569 /* queue it for later, or for another thread */
570 queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
574 /* save the message in the cooked queue if we didn't want to remove it */
575 if (!remove) queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
580 /***********************************************************************
581 * MSG_process_cooked_hardware_message
583 * returns TRUE if the contents of 'msg' should be passed to the application
585 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
587 if (is_keyboard_message( msg->message ))
588 return process_cooked_keyboard_message( msg, remove );
590 if (is_mouse_message( msg->message ))
591 return process_cooked_mouse_message( msg, extra_info, remove );
593 ERR( "unknown message type %x\n", msg->message );
598 /**********************************************************************
599 * GetKeyState (USER.106)
601 INT16 WINAPI GetKeyState16(INT16 vkey)
603 return GetKeyState(vkey);
607 /**********************************************************************
608 * GetKeyState (USER32.@)
610 * An application calls the GetKeyState function in response to a
611 * keyboard-input message. This function retrieves the state of the key
612 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
614 SHORT WINAPI GetKeyState(INT vkey)
618 if (vkey >= 'a' && vkey <= 'z') vkey += 'A' - 'a';
619 retval = ((WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) | (QueueKeyStateTable[vkey] & 0x01);
620 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
625 /**********************************************************************
626 * GetKeyboardState (USER.222)
627 * GetKeyboardState (USER32.@)
629 * An application calls the GetKeyboardState function in response to a
630 * keyboard-input message. This function retrieves the state of the keyboard
631 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
633 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
635 TRACE_(key)("(%p)\n", lpKeyState);
636 if (lpKeyState) memcpy(lpKeyState, QueueKeyStateTable, 256);
641 /**********************************************************************
642 * SetKeyboardState (USER.223)
643 * SetKeyboardState (USER32.@)
645 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
647 TRACE_(key)("(%p)\n", lpKeyState);
648 if (lpKeyState) memcpy(QueueKeyStateTable, lpKeyState, 256);
653 /***********************************************************************
654 * WaitMessage (USER.112) Suspend thread pending messages
655 * WaitMessage (USER32.@) Suspend thread pending messages
657 * WaitMessage() suspends a thread until events appear in the thread's
660 BOOL WINAPI WaitMessage(void)
662 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
666 /***********************************************************************
667 * MsgWaitForMultipleObjectsEx (USER32.@)
669 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
670 DWORD timeout, DWORD mask, DWORD flags )
672 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
674 MESSAGEQUEUE *msgQueue;
676 if (count > MAXIMUM_WAIT_OBJECTS-1)
678 SetLastError( ERROR_INVALID_PARAMETER );
682 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
684 /* set the queue mask */
685 SERVER_START_REQ( set_queue_mask )
687 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
688 req->changed_mask = mask;
690 wine_server_call( req );
694 /* Add the thread event to the handle list */
695 for (i = 0; i < count; i++) handles[i] = pHandles[i];
696 handles[count] = msgQueue->server_queue;
699 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
701 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
702 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
705 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
706 timeout, flags & MWMO_ALERTABLE );
711 /***********************************************************************
712 * MsgWaitForMultipleObjects (USER32.@)
714 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
715 BOOL wait_all, DWORD timeout, DWORD mask )
717 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
718 wait_all ? MWMO_WAITALL : 0 );
722 /***********************************************************************
723 * WaitForInputIdle (USER32.@)
725 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
727 DWORD start_time, elapsed, ret;
728 HANDLE idle_event = -1;
730 SERVER_START_REQ( wait_input_idle )
732 req->handle = hProcess;
733 req->timeout = dwTimeOut;
734 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
737 if (ret) return WAIT_FAILED; /* error */
738 if (!idle_event) return 0; /* no event to wait on */
740 start_time = GetTickCount();
743 TRACE("waiting for %x\n", idle_event );
746 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
749 case WAIT_OBJECT_0+1:
750 process_sent_messages();
754 TRACE("timeout or error\n");
760 if (dwTimeOut != INFINITE)
762 elapsed = GetTickCount() - start_time;
763 if (elapsed > dwTimeOut)
773 /***********************************************************************
774 * UserYield (USER.332)
775 * UserYield16 (USER32.@)
777 void WINAPI UserYield16(void)
781 /* Handle sent messages */
782 process_sent_messages();
785 ReleaseThunkLock(&count);
788 RestoreThunkLock(count);
789 /* Handle sent messages again */
790 process_sent_messages();
802 static const struct accent_char accent_chars[] =
804 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
805 {'`', 'A', '\300'}, {'`', 'a', '\340'},
806 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
807 {'^', 'A', '\302'}, {'^', 'a', '\342'},
808 {'~', 'A', '\303'}, {'~', 'a', '\343'},
809 {'"', 'A', '\304'}, {'"', 'a', '\344'},
810 {'O', 'A', '\305'}, {'o', 'a', '\345'},
811 {'0', 'A', '\305'}, {'0', 'a', '\345'},
812 {'A', 'A', '\305'}, {'a', 'a', '\345'},
813 {'A', 'E', '\306'}, {'a', 'e', '\346'},
814 {',', 'C', '\307'}, {',', 'c', '\347'},
815 {'`', 'E', '\310'}, {'`', 'e', '\350'},
816 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
817 {'^', 'E', '\312'}, {'^', 'e', '\352'},
818 {'"', 'E', '\313'}, {'"', 'e', '\353'},
819 {'`', 'I', '\314'}, {'`', 'i', '\354'},
820 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
821 {'^', 'I', '\316'}, {'^', 'i', '\356'},
822 {'"', 'I', '\317'}, {'"', 'i', '\357'},
823 {'-', 'D', '\320'}, {'-', 'd', '\360'},
824 {'~', 'N', '\321'}, {'~', 'n', '\361'},
825 {'`', 'O', '\322'}, {'`', 'o', '\362'},
826 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
827 {'^', 'O', '\324'}, {'^', 'o', '\364'},
828 {'~', 'O', '\325'}, {'~', 'o', '\365'},
829 {'"', 'O', '\326'}, {'"', 'o', '\366'},
830 {'/', 'O', '\330'}, {'/', 'o', '\370'},
831 {'`', 'U', '\331'}, {'`', 'u', '\371'},
832 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
833 {'^', 'U', '\333'}, {'^', 'u', '\373'},
834 {'"', 'U', '\334'}, {'"', 'u', '\374'},
835 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
836 {'T', 'H', '\336'}, {'t', 'h', '\376'},
837 {'s', 's', '\337'}, {'"', 'y', '\377'},
838 {'s', 'z', '\337'}, {'i', 'j', '\377'},
839 /* iso-8859-2 uses this */
840 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
841 {'<', 'S', '\251'}, {'<', 's', '\271'},
842 {'<', 'T', '\253'}, {'<', 't', '\273'},
843 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
844 {'<', 'C', '\310'}, {'<', 'c', '\350'},
845 {'<', 'E', '\314'}, {'<', 'e', '\354'},
846 {'<', 'D', '\317'}, {'<', 'd', '\357'},
847 {'<', 'N', '\322'}, {'<', 'n', '\362'},
848 {'<', 'R', '\330'}, {'<', 'r', '\370'},
849 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
850 {';', 'E', '\312'}, {';', 'e', '\332'},
851 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
852 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
853 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
854 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
855 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
856 /* collision whith S, from iso-8859-9 !!! */
857 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
858 {',', 'T', '\336'}, {',', 't', '\376'},
859 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
860 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
861 {'/', 'D', '\320'}, {'/', 'd', '\360'},
862 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
863 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
864 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
865 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
866 /* iso-8859-3 uses this */
867 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
868 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
869 {'>', 'J', '\254'}, {'>', 'j', '\274'},
870 {'>', 'C', '\306'}, {'>', 'c', '\346'},
871 {'>', 'G', '\330'}, {'>', 'g', '\370'},
872 {'>', 'S', '\336'}, {'>', 's', '\376'},
873 /* collision whith G( from iso-8859-9 !!! */
874 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
875 {'(', 'U', '\335'}, {'(', 'u', '\375'},
876 /* collision whith I. from iso-8859-3 !!! */
877 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
878 {'.', 'C', '\305'}, {'.', 'c', '\345'},
879 {'.', 'G', '\325'}, {'.', 'g', '\365'},
880 /* iso-8859-4 uses this */
881 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
882 {',', 'L', '\246'}, {',', 'l', '\266'},
883 {',', 'G', '\253'}, {',', 'g', '\273'},
884 {',', 'N', '\321'}, {',', 'n', '\361'},
885 {',', 'K', '\323'}, {',', 'k', '\363'},
886 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
887 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
888 {'-', 'A', '\300'}, {'-', 'a', '\340'},
889 {'-', 'I', '\317'}, {'-', 'i', '\357'},
890 {'-', 'O', '\322'}, {'-', 'o', '\362'},
891 {'-', 'U', '\336'}, {'-', 'u', '\376'},
892 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
893 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
894 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
895 {';', 'U', '\331'}, {';', 'u', '\371'},
896 /* iso-8859-9 uses this */
897 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
898 * whith the same letters on other iso-8859-x (that is they are on
899 * different places :-( ), if you use turkish uncomment these and
900 * comment out the lines in iso-8859-2 and iso-8859-3 sections
901 * FIXME: should be dynamic according to chosen language
902 * if/when Wine has turkish support.
904 /* collision whith G( from iso-8859-3 !!! */
905 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
906 /* collision whith S, from iso-8859-2 !!! */
907 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
908 /* collision whith I. from iso-8859-3 !!! */
909 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
913 /***********************************************************************
914 * TranslateMessage (USER32.@)
916 * Implementation of TranslateMessage.
918 * TranslateMessage translates virtual-key messages into character-messages,
920 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
921 * ditto replacing WM_* with WM_SYS*
922 * This produces WM_CHAR messages only for keys mapped to ASCII characters
923 * by the keyboard driver.
925 BOOL WINAPI TranslateMessage( const MSG *msg )
927 static int dead_char;
931 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
932 TRACE_(key)("(%s, %04X, %08lX)\n",
933 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
935 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return FALSE;
937 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
938 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
940 /* FIXME : should handle ToUnicode yielding 2 */
941 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
944 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
945 /* Should dead chars handling go in ToAscii ? */
950 if (wp[0] == ' ') wp[0] = dead_char;
951 if (dead_char == 0xa2) dead_char = '(';
952 else if (dead_char == 0xa8) dead_char = '"';
953 else if (dead_char == 0xb2) dead_char = ';';
954 else if (dead_char == 0xb4) dead_char = '\'';
955 else if (dead_char == 0xb7) dead_char = '<';
956 else if (dead_char == 0xb8) dead_char = ',';
957 else if (dead_char == 0xff) dead_char = '.';
958 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
959 if ((accent_chars[i].ac_accent == dead_char) &&
960 (accent_chars[i].ac_char == wp[0]))
962 wp[0] = accent_chars[i].ac_result;
967 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
968 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
972 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
974 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
975 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
982 /***********************************************************************
983 * DispatchMessageA (USER32.@)
985 LONG WINAPI DispatchMessageA( const MSG* msg )
992 /* Process timer messages */
993 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
997 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
999 /* before calling window proc, verify whether timer is still valid;
1000 there's a slim chance that the application kills the timer
1001 between GetMessage and DispatchMessage API calls */
1002 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1003 return 0; /* invalid winproc */
1005 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
1006 msg->message, msg->wParam, GetTickCount() );
1010 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1012 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1015 if (wndPtr == WND_OTHER_PROCESS)
1017 if (IsWindow( msg->hwnd ))
1018 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1019 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1022 if (!(winproc = wndPtr->winproc))
1024 WIN_ReleasePtr( wndPtr );
1027 painting = (msg->message == WM_PAINT);
1028 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1029 WIN_ReleasePtr( wndPtr );
1030 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1032 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1033 msg->wParam, msg->lParam );
1034 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
1035 msg->wParam, msg->lParam );
1036 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1037 msg->wParam, msg->lParam );
1039 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1041 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1042 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1043 WIN_ReleasePtr( wndPtr );
1046 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1047 /* Validate the update region to avoid infinite WM_PAINT loop */
1048 RedrawWindow( msg->hwnd, NULL, 0,
1049 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1056 /***********************************************************************
1057 * DispatchMessageW (USER32.@) Process Message
1059 * Process the message specified in the structure *_msg_.
1061 * If the lpMsg parameter points to a WM_TIMER message and the
1062 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1063 * points to the function that is called instead of the window
1066 * The message must be valid.
1070 * DispatchMessage() returns the result of the window procedure invoked.
1077 LONG WINAPI DispatchMessageW( const MSG* msg )
1084 /* Process timer messages */
1085 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1089 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1091 /* before calling window proc, verify whether timer is still valid;
1092 there's a slim chance that the application kills the timer
1093 between GetMessage and DispatchMessage API calls */
1094 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
1095 return 0; /* invalid winproc */
1097 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
1098 msg->message, msg->wParam, GetTickCount() );
1102 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1104 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1107 if (wndPtr == WND_OTHER_PROCESS)
1109 if (IsWindow( msg->hwnd ))
1110 ERR( "cannot dispatch msg to other process window %x\n", msg->hwnd );
1111 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1114 if (!(winproc = wndPtr->winproc))
1116 WIN_ReleasePtr( wndPtr );
1119 painting = (msg->message == WM_PAINT);
1120 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1121 WIN_ReleasePtr( wndPtr );
1122 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1124 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1125 msg->wParam, msg->lParam );
1126 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1127 msg->wParam, msg->lParam );
1128 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1129 msg->wParam, msg->lParam );
1131 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1133 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1134 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1135 WIN_ReleasePtr( wndPtr );
1138 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg->hwnd );
1139 /* Validate the update region to avoid infinite WM_PAINT loop */
1140 RedrawWindow( msg->hwnd, NULL, 0,
1141 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1148 /***********************************************************************
1149 * RegisterWindowMessage (USER.118)
1150 * RegisterWindowMessageA (USER32.@)
1152 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1154 TRACE("%s\n", str );
1155 return GlobalAddAtomA( str );
1159 /***********************************************************************
1160 * RegisterWindowMessageW (USER32.@)
1162 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1164 TRACE("%p\n", str );
1165 return GlobalAddAtomW( str );
1169 /***********************************************************************
1170 * BroadcastSystemMessage (USER32.@)
1172 LONG WINAPI BroadcastSystemMessage(
1173 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1176 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1177 dwFlags,*recipients,uMessage,wParam,lParam