2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
29 #include <sys/types.h>
36 #include "wine/server.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
52 WINE_DECLARE_DEBUG_CHANNEL(key
);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
57 static BYTE QueueKeyStateTable
[256];
60 /***********************************************************************
63 inline static BOOL
is_keyboard_message( UINT message
)
65 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
69 /***********************************************************************
72 inline static BOOL
is_mouse_message( UINT message
)
74 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
75 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
79 /***********************************************************************
80 * check_message_filter
82 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
86 if (msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
90 return (msg
->message
>= first
&& msg
->message
<= last
);
96 /***********************************************************************
97 * process_sent_messages
99 * Process all pending sent messages.
101 inline static void process_sent_messages(void)
104 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
108 /***********************************************************************
109 * queue_hardware_message
111 * store a hardware message in the thread queue
113 static void queue_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, enum message_type type
)
115 SERVER_START_REQ( send_message
)
118 req
->id
= GetWindowThreadProcessId( msg
->hwnd
, NULL
);
119 req
->win
= msg
->hwnd
;
120 req
->msg
= msg
->message
;
121 req
->wparam
= msg
->wParam
;
122 req
->lparam
= msg
->lParam
;
125 req
->time
= msg
->time
;
126 req
->info
= extra_info
;
128 wine_server_call( req
);
134 /***********************************************************************
135 * update_queue_key_state
137 static void update_queue_key_state( UINT msg
, WPARAM wp
)
172 BYTE
*p
= &QueueKeyStateTable
[wp
];
173 if (!(*p
& 0x80)) *p
^= 0x01;
176 else QueueKeyStateTable
[wp
] &= ~0x80;
180 /***********************************************************************
181 * MSG_SendParentNotify
183 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
184 * the window has the WS_EX_NOPARENTNOTIFY style.
186 static void MSG_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
188 /* pt has to be in the client coordinates of the parent window */
189 MapWindowPoints( 0, hwnd
, &pt
, 1 );
194 if (!(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
195 if (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
196 if (!(parent
= GetParent(hwnd
))) break;
197 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
199 SendMessageA( hwnd
, WM_PARENTNOTIFY
,
200 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
205 /***********************************************************************
206 * MSG_JournalPlayBackMsg
208 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
210 void MSG_JournalPlayBackMsg(void)
217 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK
)) return;
219 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0, (LPARAM
)&tmpMsg
);
220 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
224 msg
.message
= tmpMsg
.message
;
225 msg
.hwnd
= tmpMsg
.hwnd
;
226 msg
.time
= tmpMsg
.time
;
227 if ((tmpMsg
.message
>= WM_KEYFIRST
) && (tmpMsg
.message
<= WM_KEYLAST
))
229 msg
.wParam
= tmpMsg
.paramL
& 0xFF;
230 msg
.lParam
= MAKELONG(tmpMsg
.paramH
&0x7ffff,tmpMsg
.paramL
>>8);
231 if (tmpMsg
.message
== WM_KEYDOWN
|| tmpMsg
.message
== WM_SYSKEYDOWN
)
233 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
234 if (InputKeyStateTable
[i
] & 0x80)
237 msg
.lParam
|= 0x40000000;
238 InputKeyStateTable
[msg
.wParam
] |= 0x80;
239 AsyncKeyStateTable
[msg
.wParam
] |= 0x80;
241 else /* WM_KEYUP, WM_SYSKEYUP */
243 msg
.lParam
|= 0xC0000000;
244 InputKeyStateTable
[msg
.wParam
] &= ~0x80;
246 if (InputKeyStateTable
[VK_MENU
] & 0x80)
247 msg
.lParam
|= 0x20000000;
248 if (tmpMsg
.paramH
& 0x8000) /*special_key bit*/
249 msg
.lParam
|= 0x01000000;
251 msg
.pt
.x
= msg
.pt
.y
= 0;
252 queue_hardware_message( &msg
, 0, MSG_HARDWARE_RAW
);
254 else if ((tmpMsg
.message
>= WM_MOUSEFIRST
) && (tmpMsg
.message
<= WM_MOUSELAST
))
256 switch (tmpMsg
.message
)
259 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
260 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
263 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
266 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
267 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
270 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
273 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
274 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
277 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
280 SetCursorPos(tmpMsg
.paramL
,tmpMsg
.paramH
);
281 msg
.lParam
=MAKELONG(tmpMsg
.paramL
,tmpMsg
.paramH
);
283 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) msg
.wParam
|= MK_LBUTTON
;
284 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) msg
.wParam
|= MK_MBUTTON
;
285 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) msg
.wParam
|= MK_RBUTTON
;
287 msg
.pt
.x
= tmpMsg
.paramL
;
288 msg
.pt
.y
= tmpMsg
.paramH
;
289 queue_hardware_message( &msg
, 0, MSG_HARDWARE_RAW
);
291 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0, (LPARAM
)&tmpMsg
);
295 if( tmpMsg
.message
== WM_QUEUESYNC
)
296 if (HOOK_IsHooked( WH_CBT
))
297 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
302 /***********************************************************************
303 * process_raw_keyboard_message
305 * returns TRUE if the contents of 'msg' should be passed to the application
307 static BOOL
process_raw_keyboard_message( MSG
*msg
, ULONG_PTR extra_info
)
309 if (!(msg
->hwnd
= GetFocus()))
311 /* Send the message to the active window instead, */
312 /* translating messages to their WM_SYS equivalent */
313 msg
->hwnd
= GetActiveWindow();
314 if (msg
->message
< WM_SYSKEYDOWN
) msg
->message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
317 if (HOOK_IsHooked( WH_JOURNALRECORD
))
321 event
.message
= msg
->message
;
322 event
.hwnd
= msg
->hwnd
;
323 event
.time
= msg
->time
;
324 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
325 event
.paramH
= msg
->lParam
& 0x7FFF;
326 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
327 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
330 /* if we are going to throw away the message, update the queue state now */
331 if (!msg
->hwnd
) update_queue_key_state( msg
->message
, msg
->wParam
);
333 return (msg
->hwnd
!= 0);
337 /***********************************************************************
338 * process_cooked_keyboard_message
340 * returns TRUE if the contents of 'msg' should be passed to the application
342 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
346 update_queue_key_state( msg
->message
, msg
->wParam
);
348 /* Handle F1 key by sending out WM_HELP message */
349 if ((msg
->message
== WM_KEYUP
) &&
350 (msg
->wParam
== VK_F1
) &&
351 (msg
->hwnd
!= GetDesktopWindow()) &&
352 !MENU_IsMenuActive())
355 hi
.cbSize
= sizeof(HELPINFO
);
356 hi
.iContextType
= HELPINFO_WINDOW
;
357 hi
.iCtrlId
= GetWindowLongA( msg
->hwnd
, GWL_ID
);
358 hi
.hItemHandle
= msg
->hwnd
;
359 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
360 hi
.MousePos
= msg
->pt
;
361 SendMessageA(msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
365 if (HOOK_CallHooksA( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
366 LOWORD(msg
->wParam
), msg
->lParam
))
368 /* skip this message */
369 HOOK_CallHooksA( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
);
376 /***********************************************************************
377 * process_raw_mouse_message
379 * returns TRUE if the contents of 'msg' should be passed to the application
381 static BOOL
process_raw_mouse_message( MSG
*msg
, ULONG_PTR extra_info
)
389 /* find the window to dispatch this mouse message to */
392 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
393 if (!(msg
->hwnd
= info
.hwndCapture
))
395 /* If no capture HWND, find window which contains the mouse position.
396 * Also find the position of the cursor hot spot (hittest) */
397 HWND hWndScope
= (HWND
)extra_info
;
399 if (!IsWindow(hWndScope
)) hWndScope
= 0;
400 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
401 msg
->hwnd
= GetDesktopWindow();
404 if (HOOK_IsHooked( WH_JOURNALRECORD
))
407 event
.message
= msg
->message
;
408 event
.time
= msg
->time
;
409 event
.hwnd
= msg
->hwnd
;
410 event
.paramL
= msg
->pt
.x
;
411 event
.paramH
= msg
->pt
.y
;
412 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
415 /* translate double clicks */
417 if ((msg
->message
== WM_LBUTTONDOWN
) ||
418 (msg
->message
== WM_RBUTTONDOWN
) ||
419 (msg
->message
== WM_MBUTTONDOWN
))
422 /* translate double clicks -
423 * note that ...MOUSEMOVEs can slip in between
424 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
426 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
427 hittest
!= HTCLIENT
||
428 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
430 if ((msg
->message
== clk_msg
.message
) &&
431 (msg
->hwnd
== clk_msg
.hwnd
) &&
432 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
433 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
434 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
436 msg
->message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
441 /* update static double click conditions */
442 if (update
) clk_msg
= *msg
;
446 /* Note: windows has no concept of a non-client wheel message */
447 if (hittest
!= HTCLIENT
&& msg
->message
!= WM_MOUSEWHEEL
)
449 msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
450 msg
->wParam
= hittest
;
454 /* coordinates don't get translated while tracking a menu */
455 /* FIXME: should differentiate popups and top-level menus */
456 if (!(info
.flags
& GUI_INMENUMODE
)) ScreenToClient( msg
->hwnd
, &pt
);
458 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
463 /***********************************************************************
464 * process_cooked_mouse_message
466 * returns TRUE if the contents of 'msg' should be passed to the application
468 static BOOL
process_cooked_mouse_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
470 INT hittest
= HTCLIENT
;
471 UINT raw_message
= msg
->message
;
474 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
476 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
477 hittest
= msg
->wParam
;
479 if (raw_message
== WM_LBUTTONDBLCLK
||
480 raw_message
== WM_RBUTTONDBLCLK
||
481 raw_message
== WM_MBUTTONDBLCLK
)
483 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
486 if (remove
) update_queue_key_state( raw_message
, 0 );
488 if (HOOK_IsHooked( WH_MOUSE
))
490 MOUSEHOOKSTRUCT hook
;
492 hook
.hwnd
= msg
->hwnd
;
493 hook
.wHitTestCode
= hittest
;
494 hook
.dwExtraInfo
= extra_info
;
495 if (HOOK_CallHooksA( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
496 msg
->message
, (LPARAM
)&hook
))
499 hook
.hwnd
= msg
->hwnd
;
500 hook
.wHitTestCode
= hittest
;
501 hook
.dwExtraInfo
= extra_info
;
502 HOOK_CallHooksA( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
);
507 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
509 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
510 MAKELONG( hittest
, raw_message
));
514 if (!remove
|| GetCapture()) return TRUE
;
518 if ((raw_message
== WM_LBUTTONDOWN
) ||
519 (raw_message
== WM_RBUTTONDOWN
) ||
520 (raw_message
== WM_MBUTTONDOWN
))
522 /* Send the WM_PARENTNOTIFY,
523 * note that even for double/nonclient clicks
524 * notification message is still WM_L/M/RBUTTONDOWN.
526 MSG_SendParentNotify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
528 /* Activate the window if needed */
530 if (msg
->hwnd
!= GetActiveWindow())
532 HWND hwndTop
= msg
->hwnd
;
535 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
536 hwndTop
= GetParent( hwndTop
);
539 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
541 LONG ret
= SendMessageA( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
542 MAKELONG( hittest
, raw_message
) );
545 case MA_NOACTIVATEANDEAT
:
550 case MA_ACTIVATEANDEAT
:
555 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
558 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
565 /* send the WM_SETCURSOR message */
567 /* Windows sends the normal mouse message as the message parameter
568 in the WM_SETCURSOR message even if it's non-client mouse message */
569 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
570 MAKELONG( hittest
, raw_message
));
576 /***********************************************************************
577 * process_hardware_message
579 * returns TRUE if the contents of 'msg' should be passed to the application
581 BOOL
MSG_process_raw_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd_filter
,
582 UINT first
, UINT last
, BOOL remove
)
584 if (is_keyboard_message( msg
->message
))
586 if (!process_raw_keyboard_message( msg
, extra_info
)) return FALSE
;
588 else if (is_mouse_message( msg
->message
))
590 if (!process_raw_mouse_message( msg
, extra_info
)) return FALSE
;
594 ERR( "unknown message type %x\n", msg
->message
);
598 /* check destination thread and filters */
599 if (!check_message_filter( msg
, hwnd_filter
, first
, last
) ||
600 !WIN_IsCurrentThread( msg
->hwnd
))
602 /* queue it for later, or for another thread */
603 queue_hardware_message( msg
, extra_info
, MSG_HARDWARE_COOKED
);
607 /* save the message in the cooked queue if we didn't want to remove it */
608 if (!remove
) queue_hardware_message( msg
, extra_info
, MSG_HARDWARE_COOKED
);
613 /***********************************************************************
614 * MSG_process_cooked_hardware_message
616 * returns TRUE if the contents of 'msg' should be passed to the application
618 BOOL
MSG_process_cooked_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
620 if (is_keyboard_message( msg
->message
))
621 return process_cooked_keyboard_message( msg
, remove
);
623 if (is_mouse_message( msg
->message
))
624 return process_cooked_mouse_message( msg
, extra_info
, remove
);
626 ERR( "unknown message type %x\n", msg
->message
);
631 /**********************************************************************
632 * GetKeyState (USER.106)
634 INT16 WINAPI
GetKeyState16(INT16 vkey
)
636 return GetKeyState(vkey
);
640 /**********************************************************************
641 * GetKeyState (USER32.@)
643 * An application calls the GetKeyState function in response to a
644 * keyboard-input message. This function retrieves the state of the key
645 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
647 SHORT WINAPI
GetKeyState(INT vkey
)
651 if (vkey
>= 'a' && vkey
<= 'z') vkey
+= 'A' - 'a';
652 retval
= ((WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
653 (QueueKeyStateTable
[vkey
] & 0x80) |
654 (QueueKeyStateTable
[vkey
] & 0x01);
655 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
660 /**********************************************************************
661 * GetKeyboardState (USER.222)
662 * GetKeyboardState (USER32.@)
664 * An application calls the GetKeyboardState function in response to a
665 * keyboard-input message. This function retrieves the state of the keyboard
666 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
668 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
670 TRACE_(key
)("(%p)\n", lpKeyState
);
671 if (lpKeyState
) memcpy(lpKeyState
, QueueKeyStateTable
, 256);
676 /**********************************************************************
677 * SetKeyboardState (USER.223)
678 * SetKeyboardState (USER32.@)
680 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
682 TRACE_(key
)("(%p)\n", lpKeyState
);
683 if (lpKeyState
) memcpy(QueueKeyStateTable
, lpKeyState
, 256);
688 /***********************************************************************
689 * WaitMessage (USER.112) Suspend thread pending messages
690 * WaitMessage (USER32.@) Suspend thread pending messages
692 * WaitMessage() suspends a thread until events appear in the thread's
695 BOOL WINAPI
WaitMessage(void)
697 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
701 /***********************************************************************
702 * MsgWaitForMultipleObjectsEx (USER32.@)
704 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
705 DWORD timeout
, DWORD mask
, DWORD flags
)
707 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
709 MESSAGEQUEUE
*msgQueue
;
711 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
713 SetLastError( ERROR_INVALID_PARAMETER
);
717 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
719 /* set the queue mask */
720 SERVER_START_REQ( set_queue_mask
)
722 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
723 req
->changed_mask
= mask
;
725 wine_server_call( req
);
729 /* Add the thread event to the handle list */
730 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
731 handles
[count
] = msgQueue
->server_queue
;
733 ReleaseThunkLock( &lock
);
734 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
736 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
737 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
740 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
741 timeout
, flags
& MWMO_ALERTABLE
);
742 if (lock
) RestoreThunkLock( lock
);
747 /***********************************************************************
748 * MsgWaitForMultipleObjects (USER32.@)
750 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
751 BOOL wait_all
, DWORD timeout
, DWORD mask
)
753 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
754 wait_all
? MWMO_WAITALL
: 0 );
758 /***********************************************************************
759 * WaitForInputIdle (USER32.@)
761 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
763 DWORD start_time
, elapsed
, ret
;
764 HANDLE idle_event
= -1;
766 SERVER_START_REQ( wait_input_idle
)
768 req
->handle
= hProcess
;
769 req
->timeout
= dwTimeOut
;
770 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
773 if (ret
) return WAIT_FAILED
; /* error */
774 if (!idle_event
) return 0; /* no event to wait on */
776 start_time
= GetTickCount();
779 TRACE("waiting for %x\n", idle_event
);
782 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
785 case WAIT_OBJECT_0
+1:
786 process_sent_messages();
790 TRACE("timeout or error\n");
796 if (dwTimeOut
!= INFINITE
)
798 elapsed
= GetTickCount() - start_time
;
799 if (elapsed
> dwTimeOut
)
809 /***********************************************************************
810 * UserYield (USER.332)
812 void WINAPI
UserYield16(void)
816 /* Handle sent messages */
817 process_sent_messages();
820 ReleaseThunkLock(&count
);
823 RestoreThunkLock(count
);
824 /* Handle sent messages again */
825 process_sent_messages();
837 static const struct accent_char accent_chars
[] =
839 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
840 {'`', 'A', '\300'}, {'`', 'a', '\340'},
841 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
842 {'^', 'A', '\302'}, {'^', 'a', '\342'},
843 {'~', 'A', '\303'}, {'~', 'a', '\343'},
844 {'"', 'A', '\304'}, {'"', 'a', '\344'},
845 {'O', 'A', '\305'}, {'o', 'a', '\345'},
846 {'0', 'A', '\305'}, {'0', 'a', '\345'},
847 {'A', 'A', '\305'}, {'a', 'a', '\345'},
848 {'A', 'E', '\306'}, {'a', 'e', '\346'},
849 {',', 'C', '\307'}, {',', 'c', '\347'},
850 {'`', 'E', '\310'}, {'`', 'e', '\350'},
851 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
852 {'^', 'E', '\312'}, {'^', 'e', '\352'},
853 {'"', 'E', '\313'}, {'"', 'e', '\353'},
854 {'`', 'I', '\314'}, {'`', 'i', '\354'},
855 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
856 {'^', 'I', '\316'}, {'^', 'i', '\356'},
857 {'"', 'I', '\317'}, {'"', 'i', '\357'},
858 {'-', 'D', '\320'}, {'-', 'd', '\360'},
859 {'~', 'N', '\321'}, {'~', 'n', '\361'},
860 {'`', 'O', '\322'}, {'`', 'o', '\362'},
861 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
862 {'^', 'O', '\324'}, {'^', 'o', '\364'},
863 {'~', 'O', '\325'}, {'~', 'o', '\365'},
864 {'"', 'O', '\326'}, {'"', 'o', '\366'},
865 {'/', 'O', '\330'}, {'/', 'o', '\370'},
866 {'`', 'U', '\331'}, {'`', 'u', '\371'},
867 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
868 {'^', 'U', '\333'}, {'^', 'u', '\373'},
869 {'"', 'U', '\334'}, {'"', 'u', '\374'},
870 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
871 {'T', 'H', '\336'}, {'t', 'h', '\376'},
872 {'s', 's', '\337'}, {'"', 'y', '\377'},
873 {'s', 'z', '\337'}, {'i', 'j', '\377'},
874 /* iso-8859-2 uses this */
875 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
876 {'<', 'S', '\251'}, {'<', 's', '\271'},
877 {'<', 'T', '\253'}, {'<', 't', '\273'},
878 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
879 {'<', 'C', '\310'}, {'<', 'c', '\350'},
880 {'<', 'E', '\314'}, {'<', 'e', '\354'},
881 {'<', 'D', '\317'}, {'<', 'd', '\357'},
882 {'<', 'N', '\322'}, {'<', 'n', '\362'},
883 {'<', 'R', '\330'}, {'<', 'r', '\370'},
884 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
885 {';', 'E', '\312'}, {';', 'e', '\332'},
886 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
887 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
888 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
889 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
890 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
891 /* collision whith S, from iso-8859-9 !!! */
892 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
893 {',', 'T', '\336'}, {',', 't', '\376'},
894 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
895 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
896 {'/', 'D', '\320'}, {'/', 'd', '\360'},
897 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
898 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
899 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
900 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
901 /* iso-8859-3 uses this */
902 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
903 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
904 {'>', 'J', '\254'}, {'>', 'j', '\274'},
905 {'>', 'C', '\306'}, {'>', 'c', '\346'},
906 {'>', 'G', '\330'}, {'>', 'g', '\370'},
907 {'>', 'S', '\336'}, {'>', 's', '\376'},
908 /* collision whith G( from iso-8859-9 !!! */
909 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
910 {'(', 'U', '\335'}, {'(', 'u', '\375'},
911 /* collision whith I. from iso-8859-3 !!! */
912 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
913 {'.', 'C', '\305'}, {'.', 'c', '\345'},
914 {'.', 'G', '\325'}, {'.', 'g', '\365'},
915 /* iso-8859-4 uses this */
916 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
917 {',', 'L', '\246'}, {',', 'l', '\266'},
918 {',', 'G', '\253'}, {',', 'g', '\273'},
919 {',', 'N', '\321'}, {',', 'n', '\361'},
920 {',', 'K', '\323'}, {',', 'k', '\363'},
921 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
922 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
923 {'-', 'A', '\300'}, {'-', 'a', '\340'},
924 {'-', 'I', '\317'}, {'-', 'i', '\357'},
925 {'-', 'O', '\322'}, {'-', 'o', '\362'},
926 {'-', 'U', '\336'}, {'-', 'u', '\376'},
927 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
928 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
929 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
930 {';', 'U', '\331'}, {';', 'u', '\371'},
931 /* iso-8859-9 uses this */
932 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
933 * whith the same letters on other iso-8859-x (that is they are on
934 * different places :-( ), if you use turkish uncomment these and
935 * comment out the lines in iso-8859-2 and iso-8859-3 sections
936 * FIXME: should be dynamic according to chosen language
937 * if/when Wine has turkish support.
939 /* collision whith G( from iso-8859-3 !!! */
940 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
941 /* collision whith S, from iso-8859-2 !!! */
942 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
943 /* collision whith I. from iso-8859-3 !!! */
944 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
948 /***********************************************************************
949 * TranslateMessage (USER32.@)
951 * Implementation of TranslateMessage.
953 * TranslateMessage translates virtual-key messages into character-messages,
955 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
956 * ditto replacing WM_* with WM_SYS*
957 * This produces WM_CHAR messages only for keys mapped to ASCII characters
958 * by the keyboard driver.
960 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
961 * return value is nonzero, regardless of the translation.
964 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
966 static int dead_char
;
971 if (msg
->message
>= WM_KEYFIRST
&& msg
->message
<= WM_KEYLAST
)
973 TRACE_(key
)("(%s, %04X, %08lX)\n",
974 SPY_GetMsgName(msg
->message
, msg
->hwnd
), msg
->wParam
, msg
->lParam
);
976 /* Return code must be TRUE no matter what! */
980 if ((msg
->message
!= WM_KEYDOWN
) && (msg
->message
!= WM_SYSKEYDOWN
)) return rc
;
982 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
983 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
985 /* FIXME : should handle ToUnicode yielding 2 */
986 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), QueueKeyStateTable
, wp
, 2, 0))
989 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
990 /* Should dead chars handling go in ToAscii ? */
995 if (wp
[0] == ' ') wp
[0] = dead_char
;
996 if (dead_char
== 0xa2) dead_char
= '(';
997 else if (dead_char
== 0xa8) dead_char
= '"';
998 else if (dead_char
== 0xb2) dead_char
= ';';
999 else if (dead_char
== 0xb4) dead_char
= '\'';
1000 else if (dead_char
== 0xb7) dead_char
= '<';
1001 else if (dead_char
== 0xb8) dead_char
= ',';
1002 else if (dead_char
== 0xff) dead_char
= '.';
1003 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
1004 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
1005 (accent_chars
[i
].ac_char
== wp
[0]))
1007 wp
[0] = accent_chars
[i
].ac_result
;
1012 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
1013 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
1017 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
1019 TRACE_(key
)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
1020 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
1027 /***********************************************************************
1028 * DispatchMessageA (USER32.@)
1030 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
1037 /* Process timer messages */
1038 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1042 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1044 /* before calling window proc, verify whether timer is still valid;
1045 there's a slim chance that the application kills the timer
1046 between GetMessage and DispatchMessage API calls */
1047 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
1048 return 0; /* invalid winproc */
1050 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1051 msg
->message
, msg
->wParam
, GetTickCount() );
1055 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
1057 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1060 if (wndPtr
== WND_OTHER_PROCESS
)
1062 if (IsWindow( msg
->hwnd
))
1063 ERR( "cannot dispatch msg to other process window %x\n", msg
->hwnd
);
1064 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1067 if (!(winproc
= wndPtr
->winproc
))
1069 WIN_ReleasePtr( wndPtr
);
1072 painting
= (msg
->message
== WM_PAINT
);
1073 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1074 WIN_ReleasePtr( wndPtr
);
1075 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1077 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1078 msg
->wParam
, msg
->lParam
);
1079 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
1080 msg
->wParam
, msg
->lParam
);
1081 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1082 msg
->wParam
, msg
->lParam
);
1084 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
1086 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
1087 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1088 WIN_ReleasePtr( wndPtr
);
1091 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg
->hwnd
);
1092 /* Validate the update region to avoid infinite WM_PAINT loop */
1093 RedrawWindow( msg
->hwnd
, NULL
, 0,
1094 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1101 /***********************************************************************
1102 * DispatchMessageW (USER32.@) Process Message
1104 * Process the message specified in the structure *_msg_.
1106 * If the lpMsg parameter points to a WM_TIMER message and the
1107 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1108 * points to the function that is called instead of the window
1111 * The message must be valid.
1115 * DispatchMessage() returns the result of the window procedure invoked.
1122 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
1129 /* Process timer messages */
1130 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1134 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1136 /* before calling window proc, verify whether timer is still valid;
1137 there's a slim chance that the application kills the timer
1138 between GetMessage and DispatchMessage API calls */
1139 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
1140 return 0; /* invalid winproc */
1142 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1143 msg
->message
, msg
->wParam
, GetTickCount() );
1147 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
1149 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1152 if (wndPtr
== WND_OTHER_PROCESS
)
1154 if (IsWindow( msg
->hwnd
))
1155 ERR( "cannot dispatch msg to other process window %x\n", msg
->hwnd
);
1156 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1159 if (!(winproc
= wndPtr
->winproc
))
1161 WIN_ReleasePtr( wndPtr
);
1164 painting
= (msg
->message
== WM_PAINT
);
1165 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1166 WIN_ReleasePtr( wndPtr
);
1167 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1169 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1170 msg
->wParam
, msg
->lParam
);
1171 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
1172 msg
->wParam
, msg
->lParam
);
1173 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1174 msg
->wParam
, msg
->lParam
);
1176 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
1178 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
1179 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1180 WIN_ReleasePtr( wndPtr
);
1183 ERR( "BeginPaint not called on WM_PAINT for hwnd %04x!\n", msg
->hwnd
);
1184 /* Validate the update region to avoid infinite WM_PAINT loop */
1185 RedrawWindow( msg
->hwnd
, NULL
, 0,
1186 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1193 /***********************************************************************
1194 * RegisterWindowMessage (USER.118)
1195 * RegisterWindowMessageA (USER32.@)
1197 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
1199 TRACE("%s\n", str
);
1200 return GlobalAddAtomA( str
);
1204 /***********************************************************************
1205 * RegisterWindowMessageW (USER32.@)
1207 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
1209 TRACE("%p\n", str
);
1210 return GlobalAddAtomW( str
);
1214 /***********************************************************************
1215 * BroadcastSystemMessage (USER32.@)
1216 * BroadcastSystemMessageA (USER32.@)
1218 LONG WINAPI
BroadcastSystemMessage(
1219 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
1222 if ((*recipients
& BSM_APPLICATIONS
)||
1223 (*recipients
== BSM_ALLCOMPONENTS
))
1225 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1226 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);
1227 PostMessageA(HWND_BROADCAST
,uMessage
,wParam
,lParam
);
1232 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1233 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);