2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
29 #include <sys/types.h>
36 #include "wine/server.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
49 WINE_DECLARE_DEBUG_CHANNEL(key
);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
54 static BYTE QueueKeyStateTable
[256];
57 /***********************************************************************
60 inline static BOOL
is_keyboard_message( UINT message
)
62 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
66 /***********************************************************************
69 inline static BOOL
is_mouse_message( UINT message
)
71 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
72 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
76 /***********************************************************************
77 * check_message_filter
79 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
83 if (msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
87 return (msg
->message
>= first
&& msg
->message
<= last
);
93 /***********************************************************************
94 * process_sent_messages
96 * Process all pending sent messages.
98 inline static void process_sent_messages(void)
101 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
105 /***********************************************************************
106 * queue_hardware_message
108 * store a hardware message in the thread queue
110 static void queue_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, enum message_type type
)
112 SERVER_START_REQ( send_message
)
115 req
->id
= GetWindowThreadProcessId( msg
->hwnd
, NULL
);
116 req
->win
= msg
->hwnd
;
117 req
->msg
= msg
->message
;
118 req
->wparam
= msg
->wParam
;
119 req
->lparam
= msg
->lParam
;
122 req
->time
= msg
->time
;
123 req
->info
= extra_info
;
125 wine_server_call( req
);
131 /***********************************************************************
132 * update_queue_key_state
134 static void update_queue_key_state( UINT msg
, WPARAM wp
, LPARAM lp
)
136 BOOL down
= FALSE
, iskey
= FALSE
;
174 dualkey
= (HIWORD(lp
) & KF_EXTENDED
) ? VK_RSHIFT
: VK_LSHIFT
;
177 dualkey
= (HIWORD(lp
) & KF_EXTENDED
) ? VK_RCONTROL
: VK_LCONTROL
;
180 dualkey
= (HIWORD(lp
) & KF_EXTENDED
) ? VK_RMENU
: VK_LMENU
;
187 BYTE
*p
= &QueueKeyStateTable
[wp
];
188 if (!(*p
& 0x80)) *p
^= 0x01;
191 else QueueKeyStateTable
[wp
] &= ~0x80;
193 { /* also update the "dual" keys properly */
196 BYTE
*p
= &QueueKeyStateTable
[dualkey
];
197 if (!(*p
& 0x80)) *p
^= 0x01;
200 else QueueKeyStateTable
[dualkey
] &= ~0x80;
205 /***********************************************************************
206 * MSG_SendParentNotify
208 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
209 * the window has the WS_EX_NOPARENTNOTIFY style.
211 static void MSG_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
213 /* pt has to be in the client coordinates of the parent window */
214 MapWindowPoints( 0, hwnd
, &pt
, 1 );
219 if (!(GetWindowLongA( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
220 if (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
221 if (!(parent
= GetParent(hwnd
))) break;
222 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
224 SendMessageA( hwnd
, WM_PARENTNOTIFY
,
225 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
230 #if 0 /* this is broken for now, will require proper support in the server */
232 /***********************************************************************
233 * MSG_JournalPlayBackMsg
235 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
237 void MSG_JournalPlayBackMsg(void)
244 wtime
=HOOK_CallHooks( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0, (LPARAM
)&tmpMsg
, TRUE
);
245 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
249 msg
.message
= tmpMsg
.message
;
250 msg
.hwnd
= tmpMsg
.hwnd
;
251 msg
.time
= tmpMsg
.time
;
252 if ((tmpMsg
.message
>= WM_KEYFIRST
) && (tmpMsg
.message
<= WM_KEYLAST
))
254 msg
.wParam
= tmpMsg
.paramL
& 0xFF;
255 msg
.lParam
= MAKELONG(tmpMsg
.paramH
&0x7ffff,tmpMsg
.paramL
>>8);
256 if (tmpMsg
.message
== WM_KEYDOWN
|| tmpMsg
.message
== WM_SYSKEYDOWN
)
258 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
259 if (InputKeyStateTable
[i
] & 0x80)
262 msg
.lParam
|= 0x40000000;
263 InputKeyStateTable
[msg
.wParam
] |= 0x80;
264 AsyncKeyStateTable
[msg
.wParam
] |= 0x80;
266 else /* WM_KEYUP, WM_SYSKEYUP */
268 msg
.lParam
|= 0xC0000000;
269 InputKeyStateTable
[msg
.wParam
] &= ~0x80;
271 if (InputKeyStateTable
[VK_MENU
] & 0x80)
272 msg
.lParam
|= 0x20000000;
273 if (tmpMsg
.paramH
& 0x8000) /*special_key bit*/
274 msg
.lParam
|= 0x01000000;
276 msg
.pt
.x
= msg
.pt
.y
= 0;
277 queue_hardware_message( &msg
, 0, MSG_HARDWARE_RAW
);
279 else if ((tmpMsg
.message
>= WM_MOUSEFIRST
) && (tmpMsg
.message
<= WM_MOUSELAST
))
281 switch (tmpMsg
.message
)
284 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
285 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
288 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
291 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
292 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
295 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
298 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
299 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
302 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
305 SetCursorPos(tmpMsg
.paramL
,tmpMsg
.paramH
);
306 msg
.lParam
=MAKELONG(tmpMsg
.paramL
,tmpMsg
.paramH
);
308 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) msg
.wParam
|= MK_LBUTTON
;
309 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) msg
.wParam
|= MK_MBUTTON
;
310 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) msg
.wParam
|= MK_RBUTTON
;
312 msg
.pt
.x
= tmpMsg
.paramL
;
313 msg
.pt
.y
= tmpMsg
.paramH
;
314 queue_hardware_message( &msg
, 0, MSG_HARDWARE_RAW
);
316 HOOK_CallHooks( WH_JOURNALPLAYBACK
, HC_SKIP
, 0, (LPARAM
)&tmpMsg
, TRUE
);
320 if( tmpMsg
.message
== WM_QUEUESYNC
) HOOK_CallHooks( WH_CBT
, HCBT_QS
, 0, 0, TRUE
);
326 /***********************************************************************
327 * process_raw_keyboard_message
329 * returns TRUE if the contents of 'msg' should be passed to the application
331 static BOOL
process_raw_keyboard_message( MSG
*msg
, ULONG_PTR extra_info
)
335 if (!(msg
->hwnd
= GetFocus()))
337 /* Send the message to the active window instead, */
338 /* translating messages to their WM_SYS equivalent */
339 msg
->hwnd
= GetActiveWindow();
340 if (msg
->message
< WM_SYSKEYDOWN
) msg
->message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
343 event
.message
= msg
->message
;
344 event
.hwnd
= msg
->hwnd
;
345 event
.time
= msg
->time
;
346 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
347 event
.paramH
= msg
->lParam
& 0x7FFF;
348 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
349 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
351 /* if we are going to throw away the message, update the queue state now */
352 if (!msg
->hwnd
) update_queue_key_state( msg
->message
, msg
->wParam
, msg
->lParam
);
354 return (msg
->hwnd
!= 0);
358 /***********************************************************************
359 * process_cooked_keyboard_message
361 * returns TRUE if the contents of 'msg' should be passed to the application
363 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
367 update_queue_key_state( msg
->message
, msg
->wParam
, msg
->lParam
);
369 /* Handle F1 key by sending out WM_HELP message */
370 if ((msg
->message
== WM_KEYUP
) &&
371 (msg
->wParam
== VK_F1
) &&
372 (msg
->hwnd
!= GetDesktopWindow()) &&
373 !MENU_IsMenuActive())
376 hi
.cbSize
= sizeof(HELPINFO
);
377 hi
.iContextType
= HELPINFO_WINDOW
;
378 hi
.iCtrlId
= GetWindowLongA( msg
->hwnd
, GWL_ID
);
379 hi
.hItemHandle
= msg
->hwnd
;
380 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
381 hi
.MousePos
= msg
->pt
;
382 SendMessageA(msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
386 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
387 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
389 /* skip this message */
390 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
397 /***********************************************************************
398 * process_raw_mouse_message
400 * returns TRUE if the contents of 'msg' should be passed to the application
402 static BOOL
process_raw_mouse_message( MSG
*msg
, ULONG_PTR extra_info
)
411 /* find the window to dispatch this mouse message to */
414 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
415 if (!(msg
->hwnd
= info
.hwndCapture
))
417 /* If no capture HWND, find window which contains the mouse position.
418 * Also find the position of the cursor hot spot (hittest) */
419 HWND hWndScope
= (HWND
)extra_info
;
421 if (!IsWindow(hWndScope
)) hWndScope
= 0;
422 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
423 msg
->hwnd
= GetDesktopWindow();
426 event
.message
= msg
->message
;
427 event
.time
= msg
->time
;
428 event
.hwnd
= msg
->hwnd
;
429 event
.paramL
= msg
->pt
.x
;
430 event
.paramH
= msg
->pt
.y
;
431 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
433 /* translate double clicks */
435 if ((msg
->message
== WM_LBUTTONDOWN
) ||
436 (msg
->message
== WM_RBUTTONDOWN
) ||
437 (msg
->message
== WM_MBUTTONDOWN
))
440 /* translate double clicks -
441 * note that ...MOUSEMOVEs can slip in between
442 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
444 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
445 hittest
!= HTCLIENT
||
446 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
448 if ((msg
->message
== clk_msg
.message
) &&
449 (msg
->hwnd
== clk_msg
.hwnd
) &&
450 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
451 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
452 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
454 msg
->message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
459 /* update static double click conditions */
460 if (update
) clk_msg
= *msg
;
464 /* Note: windows has no concept of a non-client wheel message */
465 if (hittest
!= HTCLIENT
&& msg
->message
!= WM_MOUSEWHEEL
)
467 msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
468 msg
->wParam
= hittest
;
472 /* coordinates don't get translated while tracking a menu */
473 /* FIXME: should differentiate popups and top-level menus */
474 if (!(info
.flags
& GUI_INMENUMODE
)) ScreenToClient( msg
->hwnd
, &pt
);
476 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
481 /***********************************************************************
482 * process_cooked_mouse_message
484 * returns TRUE if the contents of 'msg' should be passed to the application
486 static BOOL
process_cooked_mouse_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
488 MOUSEHOOKSTRUCT hook
;
489 INT hittest
= HTCLIENT
;
490 UINT raw_message
= msg
->message
;
493 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
495 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
496 hittest
= msg
->wParam
;
498 if (raw_message
== WM_LBUTTONDBLCLK
||
499 raw_message
== WM_RBUTTONDBLCLK
||
500 raw_message
== WM_MBUTTONDBLCLK
)
502 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
505 if (remove
) update_queue_key_state( raw_message
, 0, 0 );
508 hook
.hwnd
= msg
->hwnd
;
509 hook
.wHitTestCode
= hittest
;
510 hook
.dwExtraInfo
= extra_info
;
511 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
512 msg
->message
, (LPARAM
)&hook
, TRUE
))
515 hook
.hwnd
= msg
->hwnd
;
516 hook
.wHitTestCode
= hittest
;
517 hook
.dwExtraInfo
= extra_info
;
518 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
, TRUE
);
522 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
524 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
525 MAKELONG( hittest
, raw_message
));
529 if (!remove
|| GetCapture()) return TRUE
;
533 if ((raw_message
== WM_LBUTTONDOWN
) ||
534 (raw_message
== WM_RBUTTONDOWN
) ||
535 (raw_message
== WM_MBUTTONDOWN
))
537 /* Send the WM_PARENTNOTIFY,
538 * note that even for double/nonclient clicks
539 * notification message is still WM_L/M/RBUTTONDOWN.
541 MSG_SendParentNotify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
543 /* Activate the window if needed */
545 if (msg
->hwnd
!= GetActiveWindow())
547 HWND hwndTop
= msg
->hwnd
;
550 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
551 hwndTop
= GetParent( hwndTop
);
554 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
556 LONG ret
= SendMessageA( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
557 MAKELONG( hittest
, raw_message
) );
560 case MA_NOACTIVATEANDEAT
:
565 case MA_ACTIVATEANDEAT
:
570 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
573 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
580 /* send the WM_SETCURSOR message */
582 /* Windows sends the normal mouse message as the message parameter
583 in the WM_SETCURSOR message even if it's non-client mouse message */
584 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
585 MAKELONG( hittest
, raw_message
));
591 /***********************************************************************
592 * process_hardware_message
594 * returns TRUE if the contents of 'msg' should be passed to the application
596 BOOL
MSG_process_raw_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd_filter
,
597 UINT first
, UINT last
, BOOL remove
)
599 if (is_keyboard_message( msg
->message
))
601 if (!process_raw_keyboard_message( msg
, extra_info
)) return FALSE
;
603 else if (is_mouse_message( msg
->message
))
605 if (!process_raw_mouse_message( msg
, extra_info
)) return FALSE
;
609 ERR( "unknown message type %x\n", msg
->message
);
613 /* check destination thread and filters */
614 if (!check_message_filter( msg
, hwnd_filter
, first
, last
) ||
615 !WIN_IsCurrentThread( msg
->hwnd
))
617 /* queue it for later, or for another thread */
618 queue_hardware_message( msg
, extra_info
, MSG_HARDWARE_COOKED
);
622 /* save the message in the cooked queue if we didn't want to remove it */
623 if (!remove
) queue_hardware_message( msg
, extra_info
, MSG_HARDWARE_COOKED
);
628 /***********************************************************************
629 * MSG_process_cooked_hardware_message
631 * returns TRUE if the contents of 'msg' should be passed to the application
633 BOOL
MSG_process_cooked_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, BOOL remove
)
635 if (is_keyboard_message( msg
->message
))
636 return process_cooked_keyboard_message( msg
, remove
);
638 if (is_mouse_message( msg
->message
))
639 return process_cooked_mouse_message( msg
, extra_info
, remove
);
641 ERR( "unknown message type %x\n", msg
->message
);
646 /**********************************************************************
647 * GetKeyState (USER.106)
649 INT16 WINAPI
GetKeyState16(INT16 vkey
)
651 return GetKeyState(vkey
);
655 /**********************************************************************
656 * GetKeyState (USER32.@)
658 * An application calls the GetKeyState function in response to a
659 * keyboard-input message. This function retrieves the state of the key
660 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
662 SHORT WINAPI
GetKeyState(INT vkey
)
666 if (vkey
>= 'a' && vkey
<= 'z') vkey
+= 'A' - 'a';
667 retval
= ((WORD
)(QueueKeyStateTable
[vkey
] & 0x80) << 8 ) |
668 (QueueKeyStateTable
[vkey
] & 0x80) |
669 (QueueKeyStateTable
[vkey
] & 0x01);
670 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
675 /**********************************************************************
676 * GetKeyboardState (USER.222)
677 * GetKeyboardState (USER32.@)
679 * An application calls the GetKeyboardState function in response to a
680 * keyboard input message. This function retrieves the state of the keyboard
681 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
683 BOOL WINAPI
GetKeyboardState(LPBYTE lpKeyState
)
685 TRACE_(key
)("(%p)\n", lpKeyState
);
686 if (lpKeyState
) memcpy(lpKeyState
, QueueKeyStateTable
, 256);
691 /**********************************************************************
692 * SetKeyboardState (USER.223)
693 * SetKeyboardState (USER32.@)
695 BOOL WINAPI
SetKeyboardState(LPBYTE lpKeyState
)
697 TRACE_(key
)("(%p)\n", lpKeyState
);
698 if (lpKeyState
) memcpy(QueueKeyStateTable
, lpKeyState
, 256);
703 /***********************************************************************
704 * WaitMessage (USER.112) Suspend thread pending messages
705 * WaitMessage (USER32.@) Suspend thread pending messages
707 * WaitMessage() suspends a thread until events appear in the thread's
710 BOOL WINAPI
WaitMessage(void)
712 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
716 /***********************************************************************
717 * MsgWaitForMultipleObjectsEx (USER32.@)
719 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
720 DWORD timeout
, DWORD mask
, DWORD flags
)
722 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
724 MESSAGEQUEUE
*msgQueue
;
726 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
728 SetLastError( ERROR_INVALID_PARAMETER
);
732 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
734 /* set the queue mask */
735 SERVER_START_REQ( set_queue_mask
)
737 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
738 req
->changed_mask
= mask
;
740 wine_server_call( req
);
744 /* Add the thread event to the handle list */
745 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
746 handles
[count
] = msgQueue
->server_queue
;
748 ReleaseThunkLock( &lock
);
749 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
751 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
752 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
755 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
756 timeout
, flags
& MWMO_ALERTABLE
);
757 if (lock
) RestoreThunkLock( lock
);
762 /***********************************************************************
763 * MsgWaitForMultipleObjects (USER32.@)
765 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
766 BOOL wait_all
, DWORD timeout
, DWORD mask
)
768 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
769 wait_all
? MWMO_WAITALL
: 0 );
773 /***********************************************************************
774 * WaitForInputIdle (USER32.@)
776 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
778 DWORD start_time
, elapsed
, ret
;
779 HANDLE idle_event
= (HANDLE
)-1;
781 SERVER_START_REQ( wait_input_idle
)
783 req
->handle
= hProcess
;
784 req
->timeout
= dwTimeOut
;
785 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
788 if (ret
) return WAIT_FAILED
; /* error */
789 if (!idle_event
) return 0; /* no event to wait on */
791 start_time
= GetTickCount();
794 TRACE("waiting for %p\n", idle_event
);
797 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
800 case WAIT_OBJECT_0
+1:
801 process_sent_messages();
805 TRACE("timeout or error\n");
811 if (dwTimeOut
!= INFINITE
)
813 elapsed
= GetTickCount() - start_time
;
814 if (elapsed
> dwTimeOut
)
824 /***********************************************************************
825 * UserYield (USER.332)
827 void WINAPI
UserYield16(void)
831 /* Handle sent messages */
832 process_sent_messages();
835 ReleaseThunkLock(&count
);
838 RestoreThunkLock(count
);
839 /* Handle sent messages again */
840 process_sent_messages();
852 static const struct accent_char accent_chars
[] =
854 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
855 {'`', 'A', '\300'}, {'`', 'a', '\340'},
856 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
857 {'^', 'A', '\302'}, {'^', 'a', '\342'},
858 {'~', 'A', '\303'}, {'~', 'a', '\343'},
859 {'"', 'A', '\304'}, {'"', 'a', '\344'},
860 {'O', 'A', '\305'}, {'o', 'a', '\345'},
861 {'0', 'A', '\305'}, {'0', 'a', '\345'},
862 {'A', 'A', '\305'}, {'a', 'a', '\345'},
863 {'A', 'E', '\306'}, {'a', 'e', '\346'},
864 {',', 'C', '\307'}, {',', 'c', '\347'},
865 {'`', 'E', '\310'}, {'`', 'e', '\350'},
866 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
867 {'^', 'E', '\312'}, {'^', 'e', '\352'},
868 {'"', 'E', '\313'}, {'"', 'e', '\353'},
869 {'`', 'I', '\314'}, {'`', 'i', '\354'},
870 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
871 {'^', 'I', '\316'}, {'^', 'i', '\356'},
872 {'"', 'I', '\317'}, {'"', 'i', '\357'},
873 {'-', 'D', '\320'}, {'-', 'd', '\360'},
874 {'~', 'N', '\321'}, {'~', 'n', '\361'},
875 {'`', 'O', '\322'}, {'`', 'o', '\362'},
876 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
877 {'^', 'O', '\324'}, {'^', 'o', '\364'},
878 {'~', 'O', '\325'}, {'~', 'o', '\365'},
879 {'"', 'O', '\326'}, {'"', 'o', '\366'},
880 {'/', 'O', '\330'}, {'/', 'o', '\370'},
881 {'`', 'U', '\331'}, {'`', 'u', '\371'},
882 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
883 {'^', 'U', '\333'}, {'^', 'u', '\373'},
884 {'"', 'U', '\334'}, {'"', 'u', '\374'},
885 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
886 {'T', 'H', '\336'}, {'t', 'h', '\376'},
887 {'s', 's', '\337'}, {'"', 'y', '\377'},
888 {'s', 'z', '\337'}, {'i', 'j', '\377'},
889 /* iso-8859-2 uses this */
890 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
891 {'<', 'S', '\251'}, {'<', 's', '\271'},
892 {'<', 'T', '\253'}, {'<', 't', '\273'},
893 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
894 {'<', 'C', '\310'}, {'<', 'c', '\350'},
895 {'<', 'E', '\314'}, {'<', 'e', '\354'},
896 {'<', 'D', '\317'}, {'<', 'd', '\357'},
897 {'<', 'N', '\322'}, {'<', 'n', '\362'},
898 {'<', 'R', '\330'}, {'<', 'r', '\370'},
899 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
900 {';', 'E', '\312'}, {';', 'e', '\332'},
901 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
902 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
903 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
904 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
905 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
906 /* collision whith S, from iso-8859-9 !!! */
907 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
908 {',', 'T', '\336'}, {',', 't', '\376'},
909 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
910 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
911 {'/', 'D', '\320'}, {'/', 'd', '\360'},
912 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
913 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
914 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
915 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
916 /* iso-8859-3 uses this */
917 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
918 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
919 {'>', 'J', '\254'}, {'>', 'j', '\274'},
920 {'>', 'C', '\306'}, {'>', 'c', '\346'},
921 {'>', 'G', '\330'}, {'>', 'g', '\370'},
922 {'>', 'S', '\336'}, {'>', 's', '\376'},
923 /* collision whith G( from iso-8859-9 !!! */
924 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
925 {'(', 'U', '\335'}, {'(', 'u', '\375'},
926 /* collision whith I. from iso-8859-3 !!! */
927 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
928 {'.', 'C', '\305'}, {'.', 'c', '\345'},
929 {'.', 'G', '\325'}, {'.', 'g', '\365'},
930 /* iso-8859-4 uses this */
931 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
932 {',', 'L', '\246'}, {',', 'l', '\266'},
933 {',', 'G', '\253'}, {',', 'g', '\273'},
934 {',', 'N', '\321'}, {',', 'n', '\361'},
935 {',', 'K', '\323'}, {',', 'k', '\363'},
936 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
937 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
938 {'-', 'A', '\300'}, {'-', 'a', '\340'},
939 {'-', 'I', '\317'}, {'-', 'i', '\357'},
940 {'-', 'O', '\322'}, {'-', 'o', '\362'},
941 {'-', 'U', '\336'}, {'-', 'u', '\376'},
942 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
943 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
944 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
945 {';', 'U', '\331'}, {';', 'u', '\371'},
946 /* iso-8859-9 uses this */
947 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
948 * whith the same letters on other iso-8859-x (that is they are on
949 * different places :-( ), if you use turkish uncomment these and
950 * comment out the lines in iso-8859-2 and iso-8859-3 sections
951 * FIXME: should be dynamic according to chosen language
952 * if/when Wine has turkish support.
954 /* collision whith G( from iso-8859-3 !!! */
955 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
956 /* collision whith S, from iso-8859-2 !!! */
957 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
958 /* collision whith I. from iso-8859-3 !!! */
959 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
963 /***********************************************************************
964 * TranslateMessage (USER32.@)
966 * Implementation of TranslateMessage.
968 * TranslateMessage translates virtual-key messages into character-messages,
970 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
971 * ditto replacing WM_* with WM_SYS*
972 * This produces WM_CHAR messages only for keys mapped to ASCII characters
973 * by the keyboard driver.
975 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
976 * return value is nonzero, regardless of the translation.
979 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
981 static int dead_char
;
986 if (msg
->message
>= WM_KEYFIRST
&& msg
->message
<= WM_KEYLAST
)
988 TRACE_(key
)("(%s, %04X, %08lX)\n",
989 SPY_GetMsgName(msg
->message
, msg
->hwnd
), msg
->wParam
, msg
->lParam
);
991 /* Return code must be TRUE no matter what! */
995 if ((msg
->message
!= WM_KEYDOWN
) && (msg
->message
!= WM_SYSKEYDOWN
)) return rc
;
997 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
998 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
1000 /* FIXME : should handle ToUnicode yielding 2 */
1001 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), QueueKeyStateTable
, wp
, 2, 0))
1004 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1005 /* Should dead chars handling go in ToAscii ? */
1010 if (wp
[0] == ' ') wp
[0] = dead_char
;
1011 if (dead_char
== 0xa2) dead_char
= '(';
1012 else if (dead_char
== 0xa8) dead_char
= '"';
1013 else if (dead_char
== 0xb2) dead_char
= ';';
1014 else if (dead_char
== 0xb4) dead_char
= '\'';
1015 else if (dead_char
== 0xb7) dead_char
= '<';
1016 else if (dead_char
== 0xb8) dead_char
= ',';
1017 else if (dead_char
== 0xff) dead_char
= '.';
1018 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
1019 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
1020 (accent_chars
[i
].ac_char
== wp
[0]))
1022 wp
[0] = accent_chars
[i
].ac_result
;
1027 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
1028 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
1032 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
1034 TRACE_(key
)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message
, msg
->hwnd
));
1035 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
1042 /***********************************************************************
1043 * DispatchMessageA (USER32.@)
1045 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
1052 /* Process timer messages */
1053 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1057 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1059 /* before calling window proc, verify whether timer is still valid;
1060 there's a slim chance that the application kills the timer
1061 between GetMessage and DispatchMessage API calls */
1062 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (WNDPROC
)msg
->lParam
))
1063 return 0; /* invalid winproc */
1065 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1066 msg
->message
, msg
->wParam
, GetTickCount() );
1070 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
1072 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1075 if (wndPtr
== WND_OTHER_PROCESS
)
1077 if (IsWindow( msg
->hwnd
))
1078 ERR( "cannot dispatch msg to other process window %p\n", msg
->hwnd
);
1079 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1082 if (!(winproc
= wndPtr
->winproc
))
1084 WIN_ReleasePtr( wndPtr
);
1087 painting
= (msg
->message
== WM_PAINT
);
1088 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1089 WIN_ReleasePtr( wndPtr
);
1090 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1092 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1093 msg
->wParam
, msg
->lParam
);
1094 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
1095 msg
->wParam
, msg
->lParam
);
1096 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1097 msg
->wParam
, msg
->lParam
);
1099 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
1101 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
1102 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1103 WIN_ReleasePtr( wndPtr
);
1106 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg
->hwnd
);
1107 /* Validate the update region to avoid infinite WM_PAINT loop */
1108 RedrawWindow( msg
->hwnd
, NULL
, 0,
1109 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1116 /***********************************************************************
1117 * DispatchMessageW (USER32.@) Process Message
1119 * Process the message specified in the structure *_msg_.
1121 * If the lpMsg parameter points to a WM_TIMER message and the
1122 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1123 * points to the function that is called instead of the window
1126 * The message must be valid.
1130 * DispatchMessage() returns the result of the window procedure invoked.
1137 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
1144 /* Process timer messages */
1145 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1149 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1151 /* before calling window proc, verify whether timer is still valid;
1152 there's a slim chance that the application kills the timer
1153 between GetMessage and DispatchMessage API calls */
1154 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (WNDPROC
)msg
->lParam
))
1155 return 0; /* invalid winproc */
1157 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
1158 msg
->message
, msg
->wParam
, GetTickCount() );
1162 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
1164 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1167 if (wndPtr
== WND_OTHER_PROCESS
)
1169 if (IsWindow( msg
->hwnd
))
1170 ERR( "cannot dispatch msg to other process window %p\n", msg
->hwnd
);
1171 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1174 if (!(winproc
= wndPtr
->winproc
))
1176 WIN_ReleasePtr( wndPtr
);
1179 painting
= (msg
->message
== WM_PAINT
);
1180 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1181 WIN_ReleasePtr( wndPtr
);
1182 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1184 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
1185 msg
->wParam
, msg
->lParam
);
1186 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
1187 msg
->wParam
, msg
->lParam
);
1188 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
1189 msg
->wParam
, msg
->lParam
);
1191 if (painting
&& (wndPtr
= WIN_GetPtr( msg
->hwnd
)) && (wndPtr
!= WND_OTHER_PROCESS
))
1193 BOOL validate
= ((wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
);
1194 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1195 WIN_ReleasePtr( wndPtr
);
1198 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg
->hwnd
);
1199 /* Validate the update region to avoid infinite WM_PAINT loop */
1200 RedrawWindow( msg
->hwnd
, NULL
, 0,
1201 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
1208 /***********************************************************************
1209 * RegisterWindowMessage (USER.118)
1210 * RegisterWindowMessageA (USER32.@)
1212 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
1214 TRACE("%s\n", str
);
1215 return GlobalAddAtomA( str
);
1219 /***********************************************************************
1220 * RegisterWindowMessageW (USER32.@)
1222 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
1224 TRACE("%p\n", str
);
1225 return GlobalAddAtomW( str
);
1229 /***********************************************************************
1230 * BroadcastSystemMessage (USER32.@)
1231 * BroadcastSystemMessageA (USER32.@)
1233 LONG WINAPI
BroadcastSystemMessage(
1234 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
1237 if ((*recipients
& BSM_APPLICATIONS
)||
1238 (*recipients
== BSM_ALLCOMPONENTS
))
1240 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1241 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);
1242 PostMessageA(HWND_BROADCAST
,uMessage
,wParam
,lParam
);
1247 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1248 dwFlags
,*recipients
,uMessage
,wParam
,lParam
);