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
, 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
= 0;
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
= 0;
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
:
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
, 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
, 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 * SetDoubleClickTime (USER32.@)
656 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
658 doubleClickSpeed
= interval
? interval
: 500;
663 /**********************************************************************
664 * GetDoubleClickTime (USER32.@)
666 UINT WINAPI
GetDoubleClickTime(void)
668 return doubleClickSpeed
;
672 /***********************************************************************
673 * WaitMessage (USER.112) Suspend thread pending messages
674 * WaitMessage (USER32.@) Suspend thread pending messages
676 * WaitMessage() suspends a thread until events appear in the thread's
679 BOOL WINAPI
WaitMessage(void)
681 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
685 /***********************************************************************
686 * MsgWaitForMultipleObjectsEx (USER32.@)
688 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
689 DWORD timeout
, DWORD mask
, DWORD flags
)
691 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
693 MESSAGEQUEUE
*msgQueue
;
695 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
697 SetLastError( ERROR_INVALID_PARAMETER
);
701 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
703 /* set the queue mask */
704 SERVER_START_REQ( set_queue_mask
)
706 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
707 req
->changed_mask
= mask
;
713 /* Add the thread event to the handle list */
714 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
715 handles
[count
] = msgQueue
->server_queue
;
718 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
720 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
721 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
724 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
725 timeout
, flags
& MWMO_ALERTABLE
);
730 /***********************************************************************
731 * MsgWaitForMultipleObjects (USER32.@)
733 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
734 BOOL wait_all
, DWORD timeout
, DWORD mask
)
736 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
737 wait_all
? MWMO_WAITALL
: 0 );
741 /***********************************************************************
742 * WaitForInputIdle (USER32.@)
744 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
746 DWORD start_time
, elapsed
, ret
;
747 HANDLE idle_event
= -1;
749 SERVER_START_REQ( wait_input_idle
)
751 req
->handle
= hProcess
;
752 req
->timeout
= dwTimeOut
;
753 if (!(ret
= SERVER_CALL_ERR())) idle_event
= req
->event
;
756 if (ret
) return WAIT_FAILED
; /* error */
757 if (!idle_event
) return 0; /* no event to wait on */
759 start_time
= GetTickCount();
762 TRACE("waiting for %x\n", idle_event
);
765 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
768 case WAIT_OBJECT_0
+1:
769 process_sent_messages();
773 TRACE("timeout or error\n");
779 if (dwTimeOut
!= INFINITE
)
781 elapsed
= GetTickCount() - start_time
;
782 if (elapsed
> dwTimeOut
)
792 /***********************************************************************
793 * UserYield (USER.332)
794 * UserYield16 (USER32.@)
796 void WINAPI
UserYield16(void)
800 /* Handle sent messages */
801 process_sent_messages();
804 ReleaseThunkLock(&count
);
807 RestoreThunkLock(count
);
808 /* Handle sent messages again */
809 process_sent_messages();
821 static const struct accent_char accent_chars
[] =
823 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
824 {'`', 'A', '\300'}, {'`', 'a', '\340'},
825 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
826 {'^', 'A', '\302'}, {'^', 'a', '\342'},
827 {'~', 'A', '\303'}, {'~', 'a', '\343'},
828 {'"', 'A', '\304'}, {'"', 'a', '\344'},
829 {'O', 'A', '\305'}, {'o', 'a', '\345'},
830 {'0', 'A', '\305'}, {'0', 'a', '\345'},
831 {'A', 'A', '\305'}, {'a', 'a', '\345'},
832 {'A', 'E', '\306'}, {'a', 'e', '\346'},
833 {',', 'C', '\307'}, {',', 'c', '\347'},
834 {'`', 'E', '\310'}, {'`', 'e', '\350'},
835 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
836 {'^', 'E', '\312'}, {'^', 'e', '\352'},
837 {'"', 'E', '\313'}, {'"', 'e', '\353'},
838 {'`', 'I', '\314'}, {'`', 'i', '\354'},
839 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
840 {'^', 'I', '\316'}, {'^', 'i', '\356'},
841 {'"', 'I', '\317'}, {'"', 'i', '\357'},
842 {'-', 'D', '\320'}, {'-', 'd', '\360'},
843 {'~', 'N', '\321'}, {'~', 'n', '\361'},
844 {'`', 'O', '\322'}, {'`', 'o', '\362'},
845 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
846 {'^', 'O', '\324'}, {'^', 'o', '\364'},
847 {'~', 'O', '\325'}, {'~', 'o', '\365'},
848 {'"', 'O', '\326'}, {'"', 'o', '\366'},
849 {'/', 'O', '\330'}, {'/', 'o', '\370'},
850 {'`', 'U', '\331'}, {'`', 'u', '\371'},
851 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
852 {'^', 'U', '\333'}, {'^', 'u', '\373'},
853 {'"', 'U', '\334'}, {'"', 'u', '\374'},
854 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
855 {'T', 'H', '\336'}, {'t', 'h', '\376'},
856 {'s', 's', '\337'}, {'"', 'y', '\377'},
857 {'s', 'z', '\337'}, {'i', 'j', '\377'},
858 /* iso-8859-2 uses this */
859 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
860 {'<', 'S', '\251'}, {'<', 's', '\271'},
861 {'<', 'T', '\253'}, {'<', 't', '\273'},
862 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
863 {'<', 'C', '\310'}, {'<', 'c', '\350'},
864 {'<', 'E', '\314'}, {'<', 'e', '\354'},
865 {'<', 'D', '\317'}, {'<', 'd', '\357'},
866 {'<', 'N', '\322'}, {'<', 'n', '\362'},
867 {'<', 'R', '\330'}, {'<', 'r', '\370'},
868 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
869 {';', 'E', '\312'}, {';', 'e', '\332'},
870 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
871 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
872 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
873 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
874 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
875 /* collision whith S, from iso-8859-9 !!! */
876 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
877 {',', 'T', '\336'}, {',', 't', '\376'},
878 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
879 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
880 {'/', 'D', '\320'}, {'/', 'd', '\360'},
881 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
882 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
883 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
884 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
885 /* iso-8859-3 uses this */
886 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
887 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
888 {'>', 'J', '\254'}, {'>', 'j', '\274'},
889 {'>', 'C', '\306'}, {'>', 'c', '\346'},
890 {'>', 'G', '\330'}, {'>', 'g', '\370'},
891 {'>', 'S', '\336'}, {'>', 's', '\376'},
892 /* collision whith G( from iso-8859-9 !!! */
893 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
894 {'(', 'U', '\335'}, {'(', 'u', '\375'},
895 /* collision whith I. from iso-8859-3 !!! */
896 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
897 {'.', 'C', '\305'}, {'.', 'c', '\345'},
898 {'.', 'G', '\325'}, {'.', 'g', '\365'},
899 /* iso-8859-4 uses this */
900 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
901 {',', 'L', '\246'}, {',', 'l', '\266'},
902 {',', 'G', '\253'}, {',', 'g', '\273'},
903 {',', 'N', '\321'}, {',', 'n', '\361'},
904 {',', 'K', '\323'}, {',', 'k', '\363'},
905 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
906 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
907 {'-', 'A', '\300'}, {'-', 'a', '\340'},
908 {'-', 'I', '\317'}, {'-', 'i', '\357'},
909 {'-', 'O', '\322'}, {'-', 'o', '\362'},
910 {'-', 'U', '\336'}, {'-', 'u', '\376'},
911 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
912 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
913 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
914 {';', 'U', '\331'}, {';', 'u', '\371'},
915 /* iso-8859-9 uses this */
916 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
917 * whith the same letters on other iso-8859-x (that is they are on
918 * different places :-( ), if you use turkish uncomment these and
919 * comment out the lines in iso-8859-2 and iso-8859-3 sections
920 * FIXME: should be dynamic according to chosen language
921 * if/when Wine has turkish support.
923 /* collision whith G( from iso-8859-3 !!! */
924 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
925 /* collision whith S, from iso-8859-2 !!! */
926 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
927 /* collision whith I. from iso-8859-3 !!! */
928 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
932 /***********************************************************************
933 * TranslateMessage (USER32.@)
935 * Implementation of TranslateMessage.
937 * TranslateMessage translates virtual-key messages into character-messages,
939 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
940 * ditto replacing WM_* with WM_SYS*
941 * This produces WM_CHAR messages only for keys mapped to ASCII characters
942 * by the keyboard driver.
944 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
946 static int dead_char
;
950 if (msg
->message
>= WM_KEYFIRST
&& msg
->message
<= WM_KEYLAST
)
951 TRACE_(key
)("(%s, %04X, %08lX)\n",
952 SPY_GetMsgName(msg
->message
, msg
->hwnd
), msg
->wParam
, msg
->lParam
);
954 if ((msg
->message
!= WM_KEYDOWN
) && (msg
->message
!= WM_SYSKEYDOWN
)) return FALSE
;
956 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
957 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
959 /* FIXME : should handle ToUnicode yielding 2 */
960 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), QueueKeyStateTable
, wp
, 2, 0))
963 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
964 /* Should dead chars handling go in ToAscii ? */
969 if (wp
[0] == ' ') wp
[0] = dead_char
;
970 if (dead_char
== 0xa2) dead_char
= '(';
971 else if (dead_char
== 0xa8) dead_char
= '"';
972 else if (dead_char
== 0xb2) dead_char
= ';';
973 else if (dead_char
== 0xb4) dead_char
= '\'';
974 else if (dead_char
== 0xb7) dead_char
= '<';
975 else if (dead_char
== 0xb8) dead_char
= ',';
976 else if (dead_char
== 0xff) dead_char
= '.';
977 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
978 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
979 (accent_chars
[i
].ac_char
== wp
[0]))
981 wp
[0] = accent_chars
[i
].ac_result
;
986 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
987 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
991 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
993 TRACE_(key
)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
994 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
1001 /***********************************************************************
1002 * DispatchMessageA (USER32.@)
1004 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
1010 /* Process timer messages */
1011 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1015 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1017 /* before calling window proc, verify whether timer is still valid;
1018 there's a slim chance that the application kills the timer
1019 between GetMessage and DispatchMessage API calls */
1020 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
1021 return 0; /* invalid winproc */
1023 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1024 msg
->message
, msg
->wParam
, GetTickCount() );
1028 if (!msg
->hwnd
) return 0;
1029 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1030 if (!wndPtr
->winproc
)
1035 painting
= (msg
->message
== WM_PAINT
);
1036 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1037 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1039 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1040 msg
->wParam
, msg
->lParam
);
1041 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1042 msg
->hwnd
, msg
->message
,
1043 msg
->wParam
, msg
->lParam
);
1044 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1045 msg
->wParam
, msg
->lParam
);
1047 WIN_ReleaseWndPtr(wndPtr
);
1048 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
1050 if (painting
&& wndPtr
&&
1051 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
1053 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1055 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1056 /* Validate the update region to avoid infinite WM_PAINT loop */
1057 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
1058 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1061 WIN_ReleaseWndPtr(wndPtr
);
1066 /***********************************************************************
1067 * DispatchMessageW (USER32.@) Process Message
1069 * Process the message specified in the structure *_msg_.
1071 * If the lpMsg parameter points to a WM_TIMER message and the
1072 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1073 * points to the function that is called instead of the window
1076 * The message must be valid.
1080 * DispatchMessage() returns the result of the window procedure invoked.
1087 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
1093 /* Process timer messages */
1094 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1098 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1100 /* before calling window proc, verify whether timer is still valid;
1101 there's a slim chance that the application kills the timer
1102 between GetMessage and DispatchMessage API calls */
1103 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
1104 return 0; /* invalid winproc */
1106 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1107 msg
->message
, msg
->wParam
, GetTickCount() );
1111 if (!msg
->hwnd
) return 0;
1112 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1113 if (!wndPtr
->winproc
)
1118 painting
= (msg
->message
== WM_PAINT
);
1119 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1120 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1122 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1123 msg
->wParam
, msg
->lParam
);
1124 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1125 msg
->hwnd
, msg
->message
,
1126 msg
->wParam
, msg
->lParam
);
1127 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1128 msg
->wParam
, msg
->lParam
);
1130 WIN_ReleaseWndPtr(wndPtr
);
1131 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
1133 if (painting
&& wndPtr
&&
1134 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
1136 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1138 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1139 /* Validate the update region to avoid infinite WM_PAINT loop */
1140 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
1141 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1144 WIN_ReleaseWndPtr(wndPtr
);
1149 /***********************************************************************
1150 * RegisterWindowMessage (USER.118)
1151 * RegisterWindowMessageA (USER32.@)
1153 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
1155 TRACE("%s\n", str
);
1156 return GlobalAddAtomA( str
);
1160 /***********************************************************************
1161 * RegisterWindowMessageW (USER32.@)
1163 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
1165 TRACE("%p\n", str
);
1166 return GlobalAddAtomW( str
);
1170 /***********************************************************************
1171 * BroadcastSystemMessage (USER32.@)
1173 LONG WINAPI
BroadcastSystemMessage(
1174 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
1177 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1178 dwFlags
,*recipients
,uMessage
,wParam
,lParam