2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
17 #include "wine/server.h"
31 #include "debugtools.h"
33 DEFAULT_DEBUG_CHANNEL(msg
);
34 DECLARE_DEBUG_CHANNEL(key
);
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
43 static UINT doubleClickSpeed
= 452;
45 static BOOL
MSG_ConvertMsg( MSG
*msg
, int srcType
, int dstType
);
49 /* flag for messages that contain pointers */
50 /* 16 messages per entry, messages 0..15 map to bits 0..15 */
52 #define SET(msg) (1 << ((msg) & 15))
54 static const unsigned short message_pointer_flags
[] =
57 SET(WM_CREATE
) | SET(WM_GETTEXT
) | SET(WM_SETTEXT
),
61 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
),
65 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) | SET(WM_NOTIFY
),
71 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
73 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
79 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
81 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
97 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_INSERTSTRING
) |
98 SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
),
100 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
106 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
107 SET(LB_DIR
) | SET(LB_FINDSTRING
),
109 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
111 SET(LB_FINDSTRINGEXACT
),
127 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
128 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
)
133 /***********************************************************************
136 inline static int is_pointer_message( UINT message
)
138 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
139 return (message_pointer_flags
[message
/ 16] & (1 << (message
& 15))) != 0;
143 /***********************************************************************
144 * is_keyboard_message
146 inline static BOOL
is_keyboard_message( UINT message
)
148 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
152 /***********************************************************************
155 inline static BOOL
is_mouse_message( UINT message
)
157 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
158 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
162 /***********************************************************************
163 * check_message_filter
165 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
169 if (msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
173 return (msg
->message
>= first
&& msg
->message
<= last
);
179 /***********************************************************************
182 * Convert the wparam of an ASCII message to Unicode.
184 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
186 if (message
== WM_CHARTOITEM
||
187 message
== EM_SETPASSWORDCHAR
||
188 message
== WM_CHAR
||
189 message
== WM_DEADCHAR
||
190 message
== WM_SYSCHAR
||
191 message
== WM_SYSDEADCHAR
||
192 message
== WM_MENUCHAR
)
194 char ch
= LOWORD(wparam
);
196 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
197 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
203 /***********************************************************************
206 * Convert the wparam of a Unicode message to ASCII.
208 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
210 if (message
== WM_CHARTOITEM
||
211 message
== EM_SETPASSWORDCHAR
||
212 message
== WM_CHAR
||
213 message
== WM_DEADCHAR
||
214 message
== WM_SYSCHAR
||
215 message
== WM_SYSDEADCHAR
||
216 message
== WM_MENUCHAR
)
218 WCHAR wch
= LOWORD(wparam
);
220 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
221 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
227 /***********************************************************************
228 * queue_hardware_message
230 * store a hardware message in the thread queue
232 static void queue_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, enum message_kind kind
)
234 SERVER_START_REQ( send_message
)
237 req
->id
= (void *)GetWindowThreadProcessId( msg
->hwnd
, NULL
);
239 req
->win
= msg
->hwnd
;
240 req
->msg
= msg
->message
;
241 req
->wparam
= msg
->wParam
;
242 req
->lparam
= msg
->lParam
;
245 req
->time
= msg
->time
;
246 req
->info
= extra_info
;
253 /***********************************************************************
254 * MSG_SendParentNotify
256 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
257 * the window has the WS_EX_NOPARENTNOTIFY style.
259 static void MSG_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
261 WND
*tmpWnd
= WIN_FindWndPtr(hwnd
);
263 /* pt has to be in the client coordinates of the parent window */
264 MapWindowPoints( 0, tmpWnd
->hwndSelf
, &pt
, 1 );
267 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
269 WIN_ReleaseWndPtr(tmpWnd
);
272 pt
.x
+= tmpWnd
->rectClient
.left
;
273 pt
.y
+= tmpWnd
->rectClient
.top
;
274 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
275 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
276 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
281 /***********************************************************************
282 * MSG_JournalPlayBackMsg
284 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
286 static void MSG_JournalPlayBackMsg(void)
293 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK
)) return;
295 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0, (LPARAM
)&tmpMsg
);
296 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
300 msg
.message
= tmpMsg
.message
;
301 msg
.hwnd
= tmpMsg
.hwnd
;
302 msg
.time
= tmpMsg
.time
;
303 if ((tmpMsg
.message
>= WM_KEYFIRST
) && (tmpMsg
.message
<= WM_KEYLAST
))
305 msg
.wParam
= tmpMsg
.paramL
& 0xFF;
306 msg
.lParam
= MAKELONG(tmpMsg
.paramH
&0x7ffff,tmpMsg
.paramL
>>8);
307 if (tmpMsg
.message
== WM_KEYDOWN
|| tmpMsg
.message
== WM_SYSKEYDOWN
)
309 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
310 if (InputKeyStateTable
[i
] & 0x80)
313 msg
.lParam
|= 0x40000000;
314 AsyncKeyStateTable
[msg
.wParam
]=InputKeyStateTable
[msg
.wParam
] |= 0x80;
316 else /* WM_KEYUP, WM_SYSKEYUP */
318 msg
.lParam
|= 0xC0000000;
319 AsyncKeyStateTable
[msg
.wParam
]=InputKeyStateTable
[msg
.wParam
] &= ~0x80;
321 if (InputKeyStateTable
[VK_MENU
] & 0x80)
322 msg
.lParam
|= 0x20000000;
323 if (tmpMsg
.paramH
& 0x8000) /*special_key bit*/
324 msg
.lParam
|= 0x01000000;
326 msg
.pt
.x
= msg
.pt
.y
= 0;
327 queue_hardware_message( &msg
, 0, RAW_HW_MESSAGE
);
329 else if ((tmpMsg
.message
>= WM_MOUSEFIRST
) && (tmpMsg
.message
<= WM_MOUSELAST
))
331 switch (tmpMsg
.message
)
334 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
336 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
338 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
340 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
342 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
344 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
346 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
347 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
348 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
349 SetCursorPos(tmpMsg
.paramL
,tmpMsg
.paramH
);
350 msg
.lParam
=MAKELONG(tmpMsg
.paramL
,tmpMsg
.paramH
);
352 if (MouseButtonsStates
[0]) msg
.wParam
|= MK_LBUTTON
;
353 if (MouseButtonsStates
[1]) msg
.wParam
|= MK_MBUTTON
;
354 if (MouseButtonsStates
[2]) msg
.wParam
|= MK_RBUTTON
;
356 msg
.pt
.x
= tmpMsg
.paramL
;
357 msg
.pt
.y
= tmpMsg
.paramH
;
358 queue_hardware_message( &msg
, 0, RAW_HW_MESSAGE
);
360 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0, (LPARAM
)&tmpMsg
);
364 if( tmpMsg
.message
== WM_QUEUESYNC
)
365 if (HOOK_IsHooked( WH_CBT
))
366 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
371 /***********************************************************************
372 * process_raw_keyboard_message
374 * returns TRUE if the contents of 'msg' should be passed to the application
376 static BOOL
process_raw_keyboard_message( MSG
*msg
, ULONG_PTR extra_info
)
378 if (!(msg
->hwnd
= GetFocus()))
380 /* Send the message to the active window instead, */
381 /* translating messages to their WM_SYS equivalent */
382 msg
->hwnd
= GetActiveWindow();
383 if (msg
->message
< WM_SYSKEYDOWN
) msg
->message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
386 if (HOOK_IsHooked( WH_JOURNALRECORD
))
390 event
.message
= msg
->message
;
391 event
.hwnd
= msg
->hwnd
;
392 event
.time
= msg
->time
;
393 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
394 event
.paramH
= msg
->lParam
& 0x7FFF;
395 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
396 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
399 return (msg
->hwnd
!= 0);
403 /***********************************************************************
404 * process_cooked_keyboard_message
406 * returns TRUE if the contents of 'msg' should be passed to the application
408 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
412 /* Handle F1 key by sending out WM_HELP message */
413 if ((msg
->message
== WM_KEYUP
) &&
414 (msg
->wParam
== VK_F1
) &&
415 (msg
->hwnd
!= GetDesktopWindow()) &&
416 !MENU_IsMenuActive())
419 hi
.cbSize
= sizeof(HELPINFO
);
420 hi
.iContextType
= HELPINFO_WINDOW
;
421 hi
.iCtrlId
= GetWindowLongA( msg
->hwnd
, GWL_ID
);
422 hi
.hItemHandle
= msg
->hwnd
;
423 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
424 hi
.MousePos
= msg
->pt
;
425 SendMessageA(msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
429 if (HOOK_CallHooksA( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
430 LOWORD(msg
->wParam
), msg
->lParam
))
432 /* skip this message */
433 HOOK_CallHooksA( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
);
440 /***********************************************************************
441 * process_raw_mouse_message
443 * returns TRUE if the contents of 'msg' should be passed to the application
445 static BOOL
process_raw_mouse_message( MSG
*msg
, ULONG_PTR extra_info
)
452 /* find the window to dispatch this mouse message to */
455 if (!(msg
->hwnd
= PERQDATA_GetCaptureWnd( &ht
)))
457 /* If no capture HWND, find window which contains the mouse position.
458 * Also find the position of the cursor hot spot (hittest) */
459 HWND hWndScope
= (HWND
)extra_info
;
461 if (!IsWindow(hWndScope
)) hWndScope
= 0;
462 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
463 msg
->hwnd
= GetDesktopWindow();
467 if (HOOK_IsHooked( WH_JOURNALRECORD
))
470 event
.message
= msg
->message
;
471 event
.time
= msg
->time
;
472 event
.hwnd
= msg
->hwnd
;
473 event
.paramL
= msg
->pt
.x
;
474 event
.paramH
= msg
->pt
.y
;
475 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
478 /* translate double clicks */
480 if ((msg
->message
== WM_LBUTTONDOWN
) ||
481 (msg
->message
== WM_RBUTTONDOWN
) ||
482 (msg
->message
== WM_MBUTTONDOWN
))
485 /* translate double clicks -
486 * note that ...MOUSEMOVEs can slip in between
487 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
489 if (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
|| ht
!= HTCLIENT
)
491 if ((msg
->message
== clk_msg
.message
) &&
492 (msg
->hwnd
== clk_msg
.hwnd
) &&
493 (msg
->time
- clk_msg
.time
< doubleClickSpeed
) &&
494 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
495 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
497 msg
->message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
502 /* update static double click conditions */
503 if (update
) clk_msg
= *msg
;
507 /* Note: windows has no concept of a non-client wheel message */
508 if (hittest
!= HTCLIENT
&& msg
->message
!= WM_MOUSEWHEEL
)
510 msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
511 msg
->wParam
= hittest
;
513 else ScreenToClient( msg
->hwnd
, &pt
);
514 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
519 /***********************************************************************
520 * process_cooked_mouse_message
522 * returns TRUE if the contents of 'msg' should be passed to the application
524 static BOOL
process_cooked_mouse_message( MSG
*msg
, BOOL remove
)
526 INT hittest
= HTCLIENT
;
527 UINT raw_message
= msg
->message
;
530 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
532 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
533 hittest
= msg
->wParam
;
535 if (raw_message
== WM_LBUTTONDBLCLK
||
536 raw_message
== WM_RBUTTONDBLCLK
||
537 raw_message
== WM_MBUTTONDBLCLK
)
539 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
542 if (HOOK_IsHooked( WH_MOUSE
))
544 MOUSEHOOKSTRUCT hook
;
546 hook
.hwnd
= msg
->hwnd
;
547 hook
.wHitTestCode
= hittest
;
548 hook
.dwExtraInfo
= 0;
549 if (HOOK_CallHooksA( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
550 msg
->message
, (LPARAM
)&hook
))
553 hook
.hwnd
= msg
->hwnd
;
554 hook
.wHitTestCode
= hittest
;
555 hook
.dwExtraInfo
= 0;
556 HOOK_CallHooksA( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
);
561 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
563 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, msg
->hwnd
, MAKELONG( hittest
, raw_message
));
567 if (!remove
|| GetCapture()) return TRUE
;
571 if ((raw_message
== WM_LBUTTONDOWN
) ||
572 (raw_message
== WM_RBUTTONDOWN
) ||
573 (raw_message
== WM_MBUTTONDOWN
))
575 HWND hwndTop
= WIN_GetTopParent( msg
->hwnd
);
577 /* Send the WM_PARENTNOTIFY,
578 * note that even for double/nonclient clicks
579 * notification message is still WM_L/M/RBUTTONDOWN.
581 MSG_SendParentNotify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
583 /* Activate the window if needed */
585 if (msg
->hwnd
!= GetActiveWindow() && hwndTop
!= GetDesktopWindow())
587 LONG ret
= SendMessageA( msg
->hwnd
, WM_MOUSEACTIVATE
, hwndTop
,
588 MAKELONG( hittest
, raw_message
) );
592 case MA_NOACTIVATEANDEAT
:
597 case MA_ACTIVATEANDEAT
:
601 if (hwndTop
!= GetForegroundWindow() )
603 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
608 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
614 /* send the WM_SETCURSOR message */
616 /* Windows sends the normal mouse message as the message parameter
617 in the WM_SETCURSOR message even if it's non-client mouse message */
618 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, msg
->hwnd
, MAKELONG( hittest
, raw_message
));
624 /***********************************************************************
625 * process_hardware_message
627 * returns TRUE if the contents of 'msg' should be passed to the application
629 static BOOL
process_raw_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd_filter
,
630 UINT first
, UINT last
, BOOL remove
)
632 if (is_keyboard_message( msg
->message
))
634 if (!process_raw_keyboard_message( msg
, extra_info
)) return FALSE
;
636 else if (is_mouse_message( msg
->message
))
638 if (!process_raw_mouse_message( msg
, extra_info
)) return FALSE
;
642 ERR( "unknown message type %x\n", msg
->message
);
646 /* check destination thread and filters */
647 if (!check_message_filter( msg
, hwnd_filter
, first
, last
) ||
648 GetWindowThreadProcessId( msg
->hwnd
, NULL
) != GetCurrentThreadId())
650 /* queue it for later, or for another thread */
651 queue_hardware_message( msg
, extra_info
, COOKED_HW_MESSAGE
);
655 /* save the message in the cooked queue if we didn't want to remove it */
656 if (!remove
) queue_hardware_message( msg
, extra_info
, COOKED_HW_MESSAGE
);
661 /***********************************************************************
662 * process_cooked_hardware_message
664 * returns TRUE if the contents of 'msg' should be passed to the application
666 static BOOL
process_cooked_hardware_message( MSG
*msg
, BOOL remove
)
668 if (is_keyboard_message( msg
->message
))
669 return process_cooked_keyboard_message( msg
, remove
);
671 if (is_mouse_message( msg
->message
))
672 return process_cooked_mouse_message( msg
, remove
);
674 ERR( "unknown message type %x\n", msg
->message
);
679 /***********************************************************************
680 * handle_sent_message
682 * Handle the reception of a sent message by calling the corresponding window proc
684 static void handle_sent_message( MSG
*msg
, int type
, ULONG_PTR extra_info
)
687 MESSAGEQUEUE
*queue
= QUEUE_Current();
688 ULONG_PTR old_extra_info
= queue
->GetMessageExtraInfoVal
; /* save ExtraInfo */
689 WND
*wndPtr
= WIN_FindWndPtr( msg
->hwnd
);
691 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
692 msg
->hwnd
, msg
->message
, SPY_GetMsgName(msg
->message
),
693 msg
->wParam
, msg
->lParam
);
695 queue
->GetMessageExtraInfoVal
= extra_info
;
697 /* call the right version of CallWindowProcXX */
701 result
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
703 (UINT16
) msg
->message
,
708 result
= CallWindowProcA( wndPtr
->winproc
, msg
->hwnd
, msg
->message
,
709 msg
->wParam
, msg
->lParam
);
712 result
= CallWindowProcW( wndPtr
->winproc
, msg
->hwnd
, msg
->message
,
713 msg
->wParam
, msg
->lParam
);
717 queue
->GetMessageExtraInfoVal
= old_extra_info
; /* Restore extra info */
718 WIN_ReleaseWndPtr(wndPtr
);
720 SERVER_START_REQ( reply_message
)
722 req
->result
= result
;
730 /***********************************************************************
731 * process_sent_messages
733 * Process all pending sent messages
735 static void process_sent_messages(void)
740 ULONG_PTR extra_info
;
744 SERVER_START_REQ( get_message
)
746 req
->flags
= GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
;
750 if (!(res
= SERVER_CALL()))
754 msg
.message
= req
->msg
;
755 msg
.wParam
= req
->wparam
;
756 msg
.lParam
= req
->lparam
;
757 msg
.time
= req
->time
;
760 extra_info
= req
->info
;
766 handle_sent_message( &msg
, type
, extra_info
);
772 /***********************************************************************
775 * Peek for a message matching the given parameters. Return FALSE if none available.
777 static BOOL
peek_message( HWND hwnd
, UINT first
, UINT last
, int flags
, int type
,
778 MSG
*msg
, ULONG_PTR
*extra_info
)
781 enum message_kind kind
;
784 if (!first
&& !last
) last
= ~0;
788 SERVER_START_REQ( get_message
)
792 req
->get_first
= first
;
793 req
->get_last
= last
;
794 if ((ret
= !SERVER_CALL()))
797 msg_type
= req
->type
;
798 msg
->hwnd
= req
->win
;
799 msg
->message
= req
->msg
;
800 msg
->wParam
= req
->wparam
;
801 msg
->lParam
= req
->lparam
;
802 msg
->time
= req
->time
;
805 *extra_info
= req
->info
;
810 if (!ret
) return FALSE
;
815 handle_sent_message( msg
, msg_type
, *extra_info
);
818 /* try to convert message to requested type */
819 if (!MSG_ConvertMsg( msg
, msg_type
, type
))
821 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
822 SPY_GetMsgName(msg
->message
));
824 flags
|= GET_MSG_REMOVE_LAST
;
829 if (!process_raw_hardware_message( msg
, *extra_info
,
830 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
833 case COOKED_HW_MESSAGE
:
834 if (!process_cooked_hardware_message( msg
, flags
& GET_MSG_REMOVE
))
836 flags
|= GET_MSG_REMOVE_LAST
;
842 /* now we got something */
843 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
844 msg
->hwnd
, msg
->message
, SPY_GetMsgName(msg
->message
),
845 msg
->wParam
, msg
->lParam
);
851 /***********************************************************************
854 * See "Windows Internals", p.447
857 * 0 if exit with timeout
860 static int wait_queue_bits( WORD bits
, DWORD timeout
)
864 if (!(queue
= QUEUE_Current())) return 0;
866 TRACE("q %04x waiting for %04x\n", queue
->self
, bits
);
870 unsigned int wake_bits
= 0, changed_bits
= 0;
873 SERVER_START_REQ( set_queue_mask
)
875 req
->wake_mask
= QS_SENDMESSAGE
;
876 req
->changed_mask
= bits
| QS_SENDMESSAGE
;
880 wake_bits
= req
->wake_bits
;
881 changed_bits
= req
->changed_bits
;
886 if (changed_bits
& bits
)
888 /* One of the bits is set; we can return */
891 if (wake_bits
& QS_SENDMESSAGE
)
893 /* Process the sent message immediately */
894 process_sent_messages();
895 continue; /* nested sm crux */
898 TRACE_(msg
)("(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
899 queue
->self
, bits
, wake_bits
, changed_bits
);
901 ReleaseThunkLock( &dwlc
);
902 if (dwlc
) TRACE_(msg
)("had win16 lock\n");
904 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
905 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, timeout
, 0, 0 );
907 WaitForSingleObject( queue
->server_queue
, timeout
);
908 if (dwlc
) RestoreThunkLock( dwlc
);
913 /**********************************************************************
914 * SetDoubleClickTime (USER.20)
916 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
918 SetDoubleClickTime( interval
);
922 /**********************************************************************
923 * SetDoubleClickTime (USER32.@)
925 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
927 doubleClickSpeed
= interval
? interval
: 500;
932 /**********************************************************************
933 * GetDoubleClickTime (USER.21)
935 UINT16 WINAPI
GetDoubleClickTime16(void)
937 return doubleClickSpeed
;
941 /**********************************************************************
942 * GetDoubleClickTime (USER32.@)
944 UINT WINAPI
GetDoubleClickTime(void)
946 return doubleClickSpeed
;
950 /***********************************************************************
951 * MSG_SendMessageInterThread
953 * Implementation of an inter-task SendMessage.
955 * 0 if error or timeout
958 static LRESULT
MSG_SendMessageInterThread( DWORD dest_tid
, HWND hwnd
, UINT msg
,
959 WPARAM wParam
, LPARAM lParam
,
960 DWORD timeout
, WORD type
,
967 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx\n", hwnd
, msg
, SPY_GetMsgName(msg
), wParam
, lParam
);
969 SERVER_START_REQ( send_message
)
971 req
->kind
= SEND_MESSAGE
;
972 req
->id
= (void *)dest_tid
;
976 req
->wparam
= wParam
;
977 req
->lparam
= lParam
;
980 req
->time
= GetCurrentTime();
982 ret
= !SERVER_CALL_ERR();
987 iWndsLocks
= WIN_SuspendWndsLock();
989 /* wait for the result */
990 wait_queue_bits( QS_SMRESULT
, timeout
);
992 SERVER_START_REQ( get_message_reply
)
995 if ((ret
= !SERVER_CALL_ERR())) result
= req
->result
;
999 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1000 hwnd
, msg
, SPY_GetMsgName(msg
), wParam
, lParam
, result
, GetLastError() );
1002 if (!ret
&& (GetLastError() == ERROR_IO_PENDING
))
1004 if (timeout
== INFINITE
) ERR("no timeout but no result\n");
1005 SetLastError(0); /* timeout */
1008 if (pRes
) *pRes
= result
;
1010 WIN_RestoreWndsLock(iWndsLocks
);
1015 /***********************************************************************
1016 * ReplyMessage (USER.115)
1018 void WINAPI
ReplyMessage16( LRESULT result
)
1020 ReplyMessage( result
);
1023 /***********************************************************************
1024 * ReplyMessage (USER32.@)
1026 BOOL WINAPI
ReplyMessage( LRESULT result
)
1029 SERVER_START_REQ( reply_message
)
1031 req
->result
= result
;
1033 ret
= !SERVER_CALL_ERR();
1039 /***********************************************************************
1042 static BOOL
MSG_ConvertMsg( MSG
*msg
, int srcType
, int dstType
)
1044 if (srcType
== QMSG_WIN32A
|| dstType
== QMSG_WIN32A
)
1046 /* posted messages are always either Win16 or Unicode Win32,
1047 * QMSG_WIN32A is only for sent messages */
1048 ERR( "invalid type %d/%d\n", srcType
, dstType
);
1052 if (!srcType
|| srcType
== dstType
) return TRUE
;
1054 if (srcType
== QMSG_WIN16
)
1056 if (dstType
== QMSG_WIN32W
)
1058 switch ( WINPROC_MapMsg16To32W( msg
->hwnd
, msg
->message
, msg
->wParam
,
1059 &msg
->message
, &msg
->wParam
, &msg
->lParam
) )
1064 /* Pointer messages were mapped --> need to free allocated memory and fail */
1065 WINPROC_UnmapMsg16To32W( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
, 0 );
1071 else if (srcType
== QMSG_WIN32W
)
1073 if (dstType
== QMSG_WIN16
)
1078 mp16
.lParam
= msg
->lParam
;
1079 switch ( WINPROC_MapMsg32WTo16( msg
->hwnd
, msg
->message
, msg
->wParam
,
1080 &msg16
, &mp16
.wParam
, &mp16
.lParam
) )
1083 msg
->message
= msg16
;
1084 msg
->wParam
= mp16
.wParam
;
1085 msg
->lParam
= mp16
.lParam
;
1088 /* Pointer messages were mapped --> need to free allocated memory and fail */
1089 WINPROC_UnmapMsg32WTo16( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
, &mp16
);
1096 FIXME( "Invalid message type(s): %d / %d\n", srcType
, dstType
);
1101 /***********************************************************************
1104 static BOOL
MSG_PeekMessage( int type
, LPMSG msg_out
, HWND hwnd
,
1105 DWORD first
, DWORD last
, WORD flags
, BOOL peek
)
1107 int mask
, msg_flags
= 0;
1108 MESSAGEQUEUE
*msgQueue
;
1111 ULONG_PTR extra_info
;
1113 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
1116 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
1117 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
1118 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
1119 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
1120 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
1121 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
1123 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
1125 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
1127 iWndsLocks
= WIN_SuspendWndsLock();
1129 /* check for graphics events */
1130 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1131 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
1133 if (flags
& PM_REMOVE
) msg_flags
|= GET_MSG_REMOVE
;
1137 if (peek_message( hwnd
, first
, last
, msg_flags
, type
, &msg
, &extra_info
))
1139 /* need to fill the window handle for WM_PAINT message */
1140 if (msg
.message
== WM_PAINT
)
1142 if ((msg
.hwnd
= WIN_FindWinToRepaint( hwnd
)))
1144 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
1146 msg
.message
= WM_PAINTICON
;
1149 if( !hwnd
|| msg
.hwnd
== hwnd
|| IsChild(hwnd
,msg
.hwnd
) )
1151 /* clear internal paint flag */
1152 RedrawWindow( msg
.hwnd
, NULL
, 0,
1153 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
1161 /* FIXME: should be done before checking for hw events */
1162 MSG_JournalPlayBackMsg();
1167 if (!(flags
& PM_NOYIELD
)) UserYield16();
1169 WIN_RestoreWndsLock(iWndsLocks
);
1173 wait_queue_bits( mask
, INFINITE
);
1176 WIN_RestoreWndsLock(iWndsLocks
);
1178 if ((msgQueue
= QUEUE_Current()))
1180 msgQueue
->GetMessageTimeVal
= msg
.time
;
1181 msgQueue
->GetMessagePosVal
= MAKELONG( msg
.pt
.x
, msg
.pt
.y
);
1182 msgQueue
->GetMessageExtraInfoVal
= extra_info
;
1185 /* We got a message */
1186 if (flags
& PM_REMOVE
)
1188 if (msg
.message
== WM_KEYDOWN
|| msg
.message
== WM_SYSKEYDOWN
)
1190 BYTE
*p
= &QueueKeyStateTable
[msg
.wParam
& 0xff];
1196 else if (msg
.message
== WM_KEYUP
|| msg
.message
== WM_SYSKEYUP
)
1197 QueueKeyStateTable
[msg
.wParam
& 0xff] &= ~0x80;
1200 /* copy back our internal safe copy of message data to msg_out.
1201 * msg_out is a variable from the *program*, so it can't be used
1202 * internally as it can get "corrupted" by our use of SendMessage()
1203 * (back to the program) inside the message handling itself. */
1209 return (msg
.message
!= WM_QUIT
);
1212 /***********************************************************************
1213 * MSG_InternalGetMessage
1215 * GetMessage() function for internal use. Behave like GetMessage(),
1216 * but also call message filters and optionally send WM_ENTERIDLE messages.
1217 * 'hwnd' must be the handle of the dialog or menu window.
1218 * 'code' is the message filter value (MSGF_??? codes).
1220 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
, UINT first
, UINT last
,
1221 WPARAM code
, WORD flags
, BOOL sendIdle
, BOOL
* idleSent
)
1227 if (!MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, TRUE
))
1229 /* No message present -> send ENTERIDLE and wait */
1230 if (IsWindow(hwndOwner
))
1232 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1233 code
, (LPARAM
)hwnd
);
1238 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, FALSE
);
1241 else /* Always wait for a message */
1242 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, FALSE
);
1244 /* Call message filters */
1246 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1250 if (HOOK_CallHooksW( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&tmp_msg
) ||
1251 HOOK_CallHooksW( WH_MSGFILTER
, code
, 0, (LPARAM
)&tmp_msg
))
1253 /* Message filtered -> remove it from the queue if it's still there. */
1254 if (!(flags
& PM_REMOVE
))
1255 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, PM_REMOVE
, TRUE
);
1259 /* need to return an ASCII message (FIXME) */
1260 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
1261 return (msg
->message
!= WM_QUIT
);
1266 /***********************************************************************
1267 * PeekMessage32 (USER.819)
1269 BOOL16 WINAPI
PeekMessage32_16( SEGPTR msg16_32
, HWND16 hwnd
,
1270 UINT16 first
, UINT16 last
, UINT16 flags
,
1271 BOOL16 wHaveParamHigh
)
1274 MSG32_16
*lpmsg16_32
= MapSL(msg16_32
);
1277 ret
= MSG_PeekMessage( QMSG_WIN16
, &msg
, hwnd
, first
, last
, flags
, TRUE
);
1279 lpmsg16_32
->msg
.hwnd
= msg
.hwnd
;
1280 lpmsg16_32
->msg
.message
= msg
.message
;
1281 lpmsg16_32
->msg
.wParam
= LOWORD(msg
.wParam
);
1282 lpmsg16_32
->msg
.lParam
= msg
.lParam
;
1283 lpmsg16_32
->msg
.time
= msg
.time
;
1284 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
1285 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
1287 if ( wHaveParamHigh
)
1288 lpmsg16_32
->wParamHigh
= HIWORD(msg
.wParam
);
1290 HOOK_CallHooks16( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg16_32
);
1294 /***********************************************************************
1295 * PeekMessage (USER.109)
1297 BOOL16 WINAPI
PeekMessage16( SEGPTR msg
, HWND16 hwnd
,
1298 UINT16 first
, UINT16 last
, UINT16 flags
)
1300 return PeekMessage32_16( msg
, hwnd
, first
, last
, flags
, FALSE
);
1303 /***********************************************************************
1304 * PeekMessageA (USER32.@)
1306 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
, UINT min
, UINT max
, UINT flags
)
1308 BOOL ret
= PeekMessageW( lpmsg
, hwnd
, min
, max
, flags
);
1309 if (ret
) lpmsg
->wParam
= map_wparam_WtoA( lpmsg
->message
, lpmsg
->wParam
);
1313 /***********************************************************************
1314 * PeekMessageW (USER32.@) Check queue for messages
1316 * Checks for a message in the thread's queue, filtered as for
1317 * GetMessage(). Returns immediately whether a message is available
1320 * Whether a retrieved message is removed from the queue is set by the
1321 * _wRemoveMsg_ flags, which should be one of the following values:
1323 * PM_NOREMOVE Do not remove the message from the queue.
1325 * PM_REMOVE Remove the message from the queue.
1327 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1328 * request that the system not yield control during PeekMessage();
1329 * however applications may not rely on scheduling behavior.
1333 * Nonzero if a message is available and is retrieved, zero otherwise.
1340 BOOL WINAPI
PeekMessageW(
1341 LPMSG lpmsg
, /* [out] buffer to receive message */
1342 HWND hwnd
, /* [in] restrict to messages for hwnd */
1343 UINT min
, /* [in] minimum message to receive */
1344 UINT max
, /* [in] maximum message to receive */
1345 UINT wRemoveMsg
/* [in] removal flags */
1348 BOOL ret
= MSG_PeekMessage( QMSG_WIN32W
, lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1349 if (ret
) HOOK_CallHooksW( WH_GETMESSAGE
, HC_ACTION
,
1350 wRemoveMsg
& PM_REMOVE
, (LPARAM
)lpmsg
);
1355 /***********************************************************************
1356 * GetMessage32 (USER.820)
1358 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1359 UINT16 last
, BOOL16 wHaveParamHigh
)
1361 MSG32_16
*lpmsg16_32
= MapSL(msg16_32
);
1364 MSG_PeekMessage( QMSG_WIN16
, &msg
, hWnd
, first
, last
, PM_REMOVE
, FALSE
);
1366 lpmsg16_32
->msg
.hwnd
= msg
.hwnd
;
1367 lpmsg16_32
->msg
.message
= msg
.message
;
1368 lpmsg16_32
->msg
.wParam
= LOWORD(msg
.wParam
);
1369 lpmsg16_32
->msg
.lParam
= msg
.lParam
;
1370 lpmsg16_32
->msg
.time
= msg
.time
;
1371 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
1372 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
1374 if ( wHaveParamHigh
)
1375 lpmsg16_32
->wParamHigh
= HIWORD(msg
.wParam
);
1377 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1378 lpmsg16_32
->msg
.message
, hWnd
, first
, last
);
1380 HOOK_CallHooks16( WH_GETMESSAGE
, HC_ACTION
, PM_REMOVE
, (LPARAM
)msg16_32
);
1381 return lpmsg16_32
->msg
.message
!= WM_QUIT
;
1384 /***********************************************************************
1385 * GetMessage (USER.108)
1387 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1389 return GetMessage32_16( msg
, hwnd
, first
, last
, FALSE
);
1392 /***********************************************************************
1393 * GetMessageA (USER32.@)
1395 BOOL WINAPI
GetMessageA( MSG
*lpmsg
, HWND hwnd
, UINT min
, UINT max
)
1397 GetMessageW( lpmsg
, hwnd
, min
, max
);
1398 lpmsg
->wParam
= map_wparam_WtoA( lpmsg
->message
, lpmsg
->wParam
);
1399 return lpmsg
->message
!= WM_QUIT
;
1402 /***********************************************************************
1403 * GetMessageW (USER32.@) Retrieve next message
1405 * GetMessage retrieves the next event from the calling thread's
1406 * queue and deposits it in *lpmsg.
1408 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1409 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1410 * all application messages are retrieved.
1412 * _min_ and _max_ specify the range of messages of interest. If
1413 * min==max==0, no filtering is performed. Useful examples are
1414 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1415 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1417 * WM_PAINT messages are not removed from the queue; they remain until
1418 * processed. Other messages are removed from the queue.
1422 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1429 BOOL WINAPI
GetMessageW(
1430 MSG
* lpmsg
, /* [out] buffer to receive message */
1431 HWND hwnd
, /* [in] restrict to messages for hwnd */
1432 UINT min
, /* [in] minimum message to receive */
1433 UINT max
/* [in] maximum message to receive */
1436 MSG_PeekMessage( QMSG_WIN32W
, lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1438 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1439 lpmsg
->message
, hwnd
, min
, max
);
1441 HOOK_CallHooksW( WH_GETMESSAGE
, HC_ACTION
, PM_REMOVE
, (LPARAM
)lpmsg
);
1442 return lpmsg
->message
!= WM_QUIT
;
1445 /***********************************************************************
1448 static BOOL
MSG_PostToQueue( DWORD tid
, int type
, HWND hwnd
,
1449 UINT message
, WPARAM wParam
, LPARAM lParam
)
1453 TRACE( "posting %x %x (%s) %x %lx\n", hwnd
, message
, SPY_GetMsgName(message
), wParam
, lParam
);
1455 SERVER_START_REQ( send_message
)
1457 req
->kind
= POST_MESSAGE
;
1458 req
->id
= (void *)tid
;
1462 req
->wparam
= wParam
;
1463 req
->lparam
= lParam
;
1466 req
->time
= GetCurrentTime();
1468 res
= SERVER_CALL();
1474 if (res
== STATUS_INVALID_PARAMETER
)
1475 SetLastError( ERROR_INVALID_THREAD_ID
);
1477 SetLastError( RtlNtStatusToDosError(res
) );
1483 /***********************************************************************
1486 static BOOL
MSG_PostMessage( int type
, HWND hwnd
, UINT message
,
1487 WPARAM wParam
, LPARAM lParam
)
1491 if (hwnd
== HWND_BROADCAST
)
1493 WND
*pDesktop
= WIN_GetDesktop();
1494 TRACE("HWND_BROADCAST !\n");
1496 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1498 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1500 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1501 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1502 MSG_PostToQueue( GetWindowThreadProcessId( wndPtr
->hwndSelf
, NULL
), type
,
1503 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1506 WIN_ReleaseDesktop();
1507 TRACE("End of HWND_BROADCAST !\n");
1511 return MSG_PostToQueue( GetWindowThreadProcessId( hwnd
, NULL
),
1512 type
, hwnd
, message
, wParam
, lParam
);
1516 /***********************************************************************
1517 * PostMessage (USER.110)
1519 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1522 return (BOOL16
) MSG_PostMessage( QMSG_WIN16
, hwnd
, message
, wParam
, lParam
);
1525 /***********************************************************************
1526 * PostMessageA (USER32.@)
1528 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1531 return PostMessageW( hwnd
, message
, map_wparam_AtoW( message
, wParam
), lParam
);
1534 /***********************************************************************
1535 * PostMessageW (USER32.@)
1537 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1540 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1541 * that are known to contain pointers are dropped by the Windows 32bit
1542 * PostMessage() with return FALSE; and invalid parameter last error.
1543 * (tested against NT4 by Gerard Patel)
1545 if (is_pointer_message(message
))
1547 SetLastError(ERROR_INVALID_PARAMETER
);
1550 return MSG_PostMessage( QMSG_WIN32W
, hwnd
, message
, wParam
, lParam
);
1553 /***********************************************************************
1554 * PostAppMessage (USER.116)
1555 * PostAppMessage16 (USER32.@)
1557 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
,
1558 WPARAM16 wParam
, LPARAM lParam
)
1560 TDB
*pTask
= TASK_GetPtr( hTask
);
1561 if (!pTask
) return FALSE
;
1562 return MSG_PostToQueue( (DWORD
)pTask
->teb
->tid
, QMSG_WIN16
, 0, message
, wParam
, lParam
);
1565 /**********************************************************************
1566 * PostThreadMessageA (USER32.@)
1568 BOOL WINAPI
PostThreadMessageA( DWORD idThread
, UINT message
,
1569 WPARAM wParam
, LPARAM lParam
)
1571 return PostThreadMessageW( idThread
, message
, map_wparam_AtoW( message
, wParam
), lParam
);
1574 /**********************************************************************
1575 * PostThreadMessageW (USER32.@)
1577 BOOL WINAPI
PostThreadMessageW( DWORD idThread
, UINT message
,
1578 WPARAM wParam
, LPARAM lParam
)
1580 if (is_pointer_message( message
))
1582 SetLastError( ERROR_INVALID_PARAMETER
);
1585 return MSG_PostToQueue( idThread
, QMSG_WIN32W
, 0, message
, wParam
, lParam
);
1589 /************************************************************************
1590 * MSG_CallWndProcHook32
1592 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1596 cwp
.lParam
= pmsg
->lParam
;
1597 cwp
.wParam
= pmsg
->wParam
;
1598 cwp
.message
= pmsg
->message
;
1599 cwp
.hwnd
= pmsg
->hwnd
;
1601 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1602 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1604 pmsg
->lParam
= cwp
.lParam
;
1605 pmsg
->wParam
= cwp
.wParam
;
1606 pmsg
->message
= cwp
.message
;
1607 pmsg
->hwnd
= cwp
.hwnd
;
1611 /***********************************************************************
1614 * return values: 0 if timeout occurs
1617 static LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1618 LPARAM lParam
, DWORD timeout
, WORD type
,
1622 WND
**list
, **ppWnd
;
1627 if (pRes
) *pRes
= 0;
1629 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1631 if (pRes
) *pRes
= 1;
1633 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1635 WIN_ReleaseDesktop();
1638 WIN_ReleaseDesktop();
1640 TRACE("HWND_BROADCAST !\n");
1641 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1643 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1644 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1645 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1647 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1648 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1649 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1650 timeout
, type
, pRes
);
1653 WIN_ReleaseWndPtr(wndPtr
);
1654 WIN_ReleaseWinArray(list
);
1655 TRACE("End of HWND_BROADCAST !\n");
1659 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1667 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1669 pmsg
->hwnd
= hwnd
& 0xffff;
1670 pmsg
->message
= msg
& 0xffff;
1671 pmsg
->wParam
= wParam
& 0xffff;
1672 pmsg
->lParam
= lParam
;
1673 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1674 (LPARAM
)SEGPTR_GET(pmsg
) );
1676 msg
= pmsg
->message
;
1677 wParam
= pmsg
->wParam
;
1678 lParam
= pmsg
->lParam
;
1679 SEGPTR_FREE( pmsg
);
1684 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1687 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1692 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1694 WARN("invalid hwnd %04x\n", hwnd
);
1697 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1699 WIN_ReleaseWndPtr( wndPtr
);
1700 return 0; /* Don't send anything if the task is dying */
1702 winproc
= (WNDPROC
)wndPtr
->winproc
;
1703 WIN_ReleaseWndPtr( wndPtr
);
1705 if (type
!= QMSG_WIN16
)
1706 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1708 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1710 dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
);
1711 if (dest_tid
&& dest_tid
!= GetCurrentThreadId())
1713 ret
= MSG_SendMessageInterThread( dest_tid
, hwnd
, msg
,
1714 wParam
, lParam
, timeout
, type
, pRes
);
1720 /* Call the right CallWindowProc flavor */
1724 res
= CallWindowProc16( (WNDPROC16
)winproc
, hwnd
, msg
, wParam
, lParam
);
1727 res
= CallWindowProcA( winproc
, hwnd
, msg
, wParam
, lParam
);
1730 res
= CallWindowProcW( winproc
, hwnd
, msg
, wParam
, lParam
);
1733 if (pRes
) *pRes
= res
;
1736 if (type
!= QMSG_WIN16
)
1737 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, pRes
?*pRes
:0, wParam
, lParam
);
1739 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, pRes
?*pRes
:0, wParam
, lParam
);
1745 /***********************************************************************
1746 * SendMessage (USER.111)
1748 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1752 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN16
, &res
);
1757 /***********************************************************************
1758 * SendMessageA (USER32.@)
1760 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1765 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32A
, &res
);
1771 /***********************************************************************
1772 * SendMessageW (USER32.@) Send Window Message
1774 * Sends a message to the window procedure of the specified window.
1775 * SendMessage() will not return until the called window procedure
1776 * either returns or calls ReplyMessage().
1778 * Use PostMessage() to send message and return immediately. A window
1779 * procedure may use InSendMessage() to detect
1780 * SendMessage()-originated messages.
1782 * Applications which communicate via HWND_BROADCAST may use
1783 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1784 * with other applications.
1790 LRESULT WINAPI
SendMessageW(
1791 HWND hwnd
, /* [in] Window to send message to. If HWND_BROADCAST,
1792 the message will be sent to all top-level windows. */
1794 UINT msg
, /* [in] message */
1795 WPARAM wParam
, /* [in] message parameter */
1796 LPARAM lParam
/* [in] additional message parameter */
1800 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32W
, &res
);
1806 /***********************************************************************
1807 * SendMessageTimeout (not a WINAPI)
1809 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1810 LPARAM lParam
, UINT16 flags
,
1811 UINT16 timeout
, LPWORD resultp
)
1816 /* FIXME: need support for SMTO_BLOCK */
1818 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN16
, &msgRet
);
1819 if (resultp
) *resultp
= (WORD
) msgRet
;
1824 /***********************************************************************
1825 * SendMessageTimeoutA (USER32.@)
1827 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1828 LPARAM lParam
, UINT flags
,
1829 UINT timeout
, LPDWORD resultp
)
1834 /* FIXME: need support for SMTO_BLOCK */
1836 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN32A
, &msgRet
);
1838 if (resultp
) *resultp
= (DWORD
) msgRet
;
1843 /***********************************************************************
1844 * SendMessageTimeoutW (USER32.@)
1846 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1847 LPARAM lParam
, UINT flags
,
1848 UINT timeout
, LPDWORD resultp
)
1853 /* FIXME: need support for SMTO_BLOCK */
1855 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN32W
, &msgRet
);
1857 if (resultp
) *resultp
= (DWORD
) msgRet
;
1862 /***********************************************************************
1863 * SendNotifyMessageA (USER32.@)
1865 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1867 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wParam
), lParam
);
1871 /***********************************************************************
1872 * SendNotifyMessageW (USER32.@)
1874 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1876 if (is_pointer_message(msg
))
1878 SetLastError(ERROR_INVALID_PARAMETER
);
1881 return MSG_SendMessage( hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32W
, NULL
);
1885 /***********************************************************************
1886 * SendMessageCallbackA (USER32.@)
1888 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1889 SENDASYNCPROC callback
, ULONG_PTR data
)
1891 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wParam
),
1892 lParam
, callback
, data
);
1896 /***********************************************************************
1897 * SendMessageCallbackW (USER32.@)
1899 * FIXME: It's like PostMessage. The callback gets called when the message
1900 * is processed. We have to modify the message processing for an exact
1902 * The callback is only called when the thread that called us calls one of
1903 * Get/Peek/WaitMessage.
1905 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1906 SENDASYNCPROC callback
, ULONG_PTR data
)
1910 if (is_pointer_message(msg
))
1912 SetLastError(ERROR_INVALID_PARAMETER
);
1915 FIXME( "(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08x),stub!\n",
1916 hwnd
, msg
, wParam
, lParam
, callback
, data
);
1918 if (hwnd
== HWND_BROADCAST
)
1920 PostMessageW( hwnd
, msg
, wParam
, lParam
);
1921 FIXME("Broadcast: Callback will not be called!\n");
1924 result
= SendMessageW( hwnd
, msg
, wParam
, lParam
);
1925 callback( hwnd
, msg
, data
, result
);
1930 /***********************************************************************
1931 * WaitMessage (USER.112) Suspend thread pending messages
1932 * WaitMessage (USER32.@) Suspend thread pending messages
1934 * WaitMessage() suspends a thread until events appear in the thread's
1937 BOOL WINAPI
WaitMessage(void)
1939 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
1943 /***********************************************************************
1944 * MsgWaitForMultipleObjectsEx (USER32.@)
1946 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
1947 DWORD timeout
, DWORD mask
, DWORD flags
)
1949 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1951 MESSAGEQUEUE
*msgQueue
;
1953 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
1955 SetLastError( ERROR_INVALID_PARAMETER
);
1959 if (!(msgQueue
= QUEUE_Current())) return WAIT_FAILED
;
1961 /* set the queue mask */
1962 SERVER_START_REQ( set_queue_mask
)
1964 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
1965 req
->changed_mask
= mask
;
1971 /* Add the thread event to the handle list */
1972 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
1973 handles
[count
] = msgQueue
->server_queue
;
1976 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1978 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
1979 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
1982 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
1983 timeout
, flags
& MWMO_ALERTABLE
);
1988 /***********************************************************************
1989 * MsgWaitForMultipleObjects (USER32.@)
1991 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
1992 BOOL wait_all
, DWORD timeout
, DWORD mask
)
1994 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
1995 wait_all
? MWMO_WAITALL
: 0 );
1999 /***********************************************************************
2000 * MsgWaitForMultipleObjects (USER.640)
2002 DWORD WINAPI
MsgWaitForMultipleObjects16( DWORD count
, CONST HANDLE
*handles
,
2003 BOOL wait_all
, DWORD timeout
, DWORD mask
)
2005 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
2006 wait_all
? MWMO_WAITALL
: 0 );
2010 /***********************************************************************
2011 * WaitForInputIdle (USER32.@)
2013 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
2015 DWORD cur_time
, ret
;
2016 HANDLE idle_event
= -1;
2018 SERVER_START_REQ( wait_input_idle
)
2020 req
->handle
= hProcess
;
2021 req
->timeout
= dwTimeOut
;
2022 if (!(ret
= SERVER_CALL_ERR())) idle_event
= req
->event
;
2025 if (ret
) return 0xffffffff; /* error */
2026 if (!idle_event
) return 0; /* no event to wait on */
2028 cur_time
= GetTickCount();
2030 TRACE("waiting for %x\n", idle_event
);
2031 while ( dwTimeOut
> GetTickCount() - cur_time
|| dwTimeOut
== INFINITE
)
2033 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
, QS_SENDMESSAGE
);
2034 if ( ret
== ( WAIT_OBJECT_0
+ 1 ))
2036 process_sent_messages();
2039 if ( ret
== WAIT_TIMEOUT
|| ret
== 0xFFFFFFFF )
2041 TRACE("timeout or error\n");
2046 TRACE("finished\n");
2051 return WAIT_TIMEOUT
;
2055 /***********************************************************************
2056 * UserYield (USER.332)
2057 * UserYield16 (USER32.@)
2059 void WINAPI
UserYield16(void)
2061 /* Handle sent messages */
2062 process_sent_messages();
2067 /* Handle sent messages again */
2068 process_sent_messages();
2079 static const struct accent_char accent_chars
[] =
2081 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2082 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2083 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2084 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2085 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2086 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2087 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2088 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2089 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2090 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2091 {',', 'C', '\307'}, {',', 'c', '\347'},
2092 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2093 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2094 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2095 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2096 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2097 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2098 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2099 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2100 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2101 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2102 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2103 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2104 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2105 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2106 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2107 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2108 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2109 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2110 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2111 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2112 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2113 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2114 {'s', 's', '\337'}, {'"', 'y', '\377'},
2115 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2116 /* iso-8859-2 uses this */
2117 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2118 {'<', 'S', '\251'}, {'<', 's', '\271'},
2119 {'<', 'T', '\253'}, {'<', 't', '\273'},
2120 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2121 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2122 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2123 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2124 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2125 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2126 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2127 {';', 'E', '\312'}, {';', 'e', '\332'},
2128 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2129 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2130 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2131 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2132 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2133 /* collision whith S, from iso-8859-9 !!! */
2134 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2135 {',', 'T', '\336'}, {',', 't', '\376'},
2136 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2137 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2138 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2139 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2140 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2141 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2142 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2143 /* iso-8859-3 uses this */
2144 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2145 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2146 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2147 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2148 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2149 {'>', 'S', '\336'}, {'>', 's', '\376'},
2150 /* collision whith G( from iso-8859-9 !!! */
2151 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2152 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2153 /* collision whith I. from iso-8859-3 !!! */
2154 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2155 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2156 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2157 /* iso-8859-4 uses this */
2158 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2159 {',', 'L', '\246'}, {',', 'l', '\266'},
2160 {',', 'G', '\253'}, {',', 'g', '\273'},
2161 {',', 'N', '\321'}, {',', 'n', '\361'},
2162 {',', 'K', '\323'}, {',', 'k', '\363'},
2163 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2164 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2165 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2166 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2167 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2168 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2169 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2170 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2171 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2172 {';', 'U', '\331'}, {';', 'u', '\371'},
2173 /* iso-8859-9 uses this */
2174 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2175 * whith the same letters on other iso-8859-x (that is they are on
2176 * different places :-( ), if you use turkish uncomment these and
2177 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2178 * FIXME: should be dynamic according to chosen language
2179 * if/when Wine has turkish support.
2181 /* collision whith G( from iso-8859-3 !!! */
2182 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2183 /* collision whith S, from iso-8859-2 !!! */
2184 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2185 /* collision whith I. from iso-8859-3 !!! */
2186 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2190 /***********************************************************************
2191 * MSG_DoTranslateMessage
2193 * Implementation of TranslateMessage.
2195 * TranslateMessage translates virtual-key messages into character-messages,
2197 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2198 * ditto replacing WM_* with WM_SYS*
2199 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2200 * by the keyboard driver.
2202 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
2203 WPARAM wParam
, LPARAM lParam
)
2205 static int dead_char
;
2208 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
2209 TRACE("(%s, %04X, %08lX)\n",
2210 SPY_GetMsgName(message
), wParam
, lParam
);
2211 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
2212 TRACE_(key
)("(%s, %04X, %08lX)\n",
2213 SPY_GetMsgName(message
), wParam
, lParam
);
2215 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
2217 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2218 SPY_GetVKeyName(wParam
), wParam
, LOBYTE(HIWORD(lParam
)));
2220 /* FIXME : should handle ToUnicode yielding 2 */
2221 switch (ToUnicode(wParam
, HIWORD(lParam
), QueueKeyStateTable
, wp
, 2, 0))
2224 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2225 /* Should dead chars handling go in ToAscii ? */
2230 if (wp
[0] == ' ') wp
[0] = dead_char
;
2231 if (dead_char
== 0xa2) dead_char
= '(';
2232 else if (dead_char
== 0xa8) dead_char
= '"';
2233 else if (dead_char
== 0xb2) dead_char
= ';';
2234 else if (dead_char
== 0xb4) dead_char
= '\'';
2235 else if (dead_char
== 0xb7) dead_char
= '<';
2236 else if (dead_char
== 0xb8) dead_char
= ',';
2237 else if (dead_char
== 0xff) dead_char
= '.';
2238 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2239 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2240 (accent_chars
[i
].ac_char
== wp
[0]))
2242 wp
[0] = accent_chars
[i
].ac_result
;
2247 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2248 PostMessageW( hwnd
, message
, wp
[0], lParam
);
2252 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2254 TRACE_(key
)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2255 PostMessageW( hwnd
, message
, wp
[0], lParam
);
2262 /***********************************************************************
2263 * TranslateMessage (USER.113)
2265 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2267 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2268 msg
->wParam
, msg
->lParam
);
2272 /***********************************************************************
2273 * TranslateMessage32 (USER.821)
2275 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2280 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2282 wParam
= (WPARAM
)msg
->msg
.wParam
;
2284 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2285 wParam
, msg
->msg
.lParam
);
2288 /***********************************************************************
2289 * TranslateMessage (USER32.@)
2291 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2293 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2294 msg
->wParam
, msg
->lParam
);
2298 /***********************************************************************
2299 * DispatchMessage (USER.114)
2301 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2307 /* Process timer messages */
2308 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2312 /* before calling window proc, verify whether timer is still valid;
2313 there's a slim chance that the application kills the timer
2314 between GetMessage and DispatchMessage API calls */
2315 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2316 return 0; /* invalid winproc */
2318 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2319 msg
->message
, msg
->wParam
, GetTickCount() );
2323 if (!msg
->hwnd
) return 0;
2324 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2325 if (!wndPtr
->winproc
)
2330 painting
= (msg
->message
== WM_PAINT
);
2331 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2333 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2334 msg
->wParam
, msg
->lParam
);
2335 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2336 msg
->hwnd
, msg
->message
,
2337 msg
->wParam
, msg
->lParam
);
2338 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
,
2339 msg
->wParam
, msg
->lParam
);
2341 WIN_ReleaseWndPtr(wndPtr
);
2342 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2343 if (painting
&& wndPtr
&&
2344 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2346 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2348 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2349 /* Validate the update region to avoid infinite WM_PAINT loop */
2350 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2351 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2354 WIN_ReleaseWndPtr(wndPtr
);
2359 /***********************************************************************
2360 * DispatchMessage32 (USER.822)
2362 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2364 if (wHaveParamHigh
== FALSE
)
2365 return DispatchMessage16(&(lpmsg16_32
->msg
));
2370 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2371 msg
.message
= lpmsg16_32
->msg
.message
;
2372 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2373 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2374 msg
.time
= lpmsg16_32
->msg
.time
;
2375 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2376 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2377 return DispatchMessageA(&msg
);
2381 /***********************************************************************
2382 * DispatchMessageA (USER32.@)
2384 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2390 /* Process timer messages */
2391 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2395 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2397 /* before calling window proc, verify whether timer is still valid;
2398 there's a slim chance that the application kills the timer
2399 between GetMessage and DispatchMessage API calls */
2400 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2401 return 0; /* invalid winproc */
2403 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2404 msg
->message
, msg
->wParam
, GetTickCount() );
2408 if (!msg
->hwnd
) return 0;
2409 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2410 if (!wndPtr
->winproc
)
2415 painting
= (msg
->message
== WM_PAINT
);
2416 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2417 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2419 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2420 msg
->wParam
, msg
->lParam
);
2421 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2422 msg
->hwnd
, msg
->message
,
2423 msg
->wParam
, msg
->lParam
);
2424 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2425 msg
->wParam
, msg
->lParam
);
2427 WIN_ReleaseWndPtr(wndPtr
);
2428 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2430 if (painting
&& wndPtr
&&
2431 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2433 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2435 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2436 /* Validate the update region to avoid infinite WM_PAINT loop */
2437 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2438 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2441 WIN_ReleaseWndPtr(wndPtr
);
2446 /***********************************************************************
2447 * DispatchMessageW (USER32.@) Process Message
2449 * Process the message specified in the structure *_msg_.
2451 * If the lpMsg parameter points to a WM_TIMER message and the
2452 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2453 * points to the function that is called instead of the window
2456 * The message must be valid.
2460 * DispatchMessage() returns the result of the window procedure invoked.
2467 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2473 /* Process timer messages */
2474 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2478 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2480 /* before calling window proc, verify whether timer is still valid;
2481 there's a slim chance that the application kills the timer
2482 between GetMessage and DispatchMessage API calls */
2483 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2484 return 0; /* invalid winproc */
2486 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2487 msg
->message
, msg
->wParam
, GetTickCount() );
2491 if (!msg
->hwnd
) return 0;
2492 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2493 if (!wndPtr
->winproc
)
2498 painting
= (msg
->message
== WM_PAINT
);
2499 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2500 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2502 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2503 msg
->wParam
, msg
->lParam
);
2504 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2505 msg
->hwnd
, msg
->message
,
2506 msg
->wParam
, msg
->lParam
);
2507 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2508 msg
->wParam
, msg
->lParam
);
2510 WIN_ReleaseWndPtr(wndPtr
);
2511 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2513 if (painting
&& wndPtr
&&
2514 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2516 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2518 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2519 /* Validate the update region to avoid infinite WM_PAINT loop */
2520 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2521 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2524 WIN_ReleaseWndPtr(wndPtr
);
2529 /***********************************************************************
2530 * RegisterWindowMessage (USER.118)
2531 * RegisterWindowMessageA (USER32.@)
2533 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2535 TRACE("%s\n", str
);
2536 return GlobalAddAtomA( str
);
2540 /***********************************************************************
2541 * RegisterWindowMessageW (USER32.@)
2543 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2545 TRACE("%p\n", str
);
2546 return GlobalAddAtomW( str
);
2550 /***********************************************************************
2551 * InSendMessage (USER.192)
2553 BOOL16 WINAPI
InSendMessage16(void)
2555 return InSendMessage();
2559 /***********************************************************************
2560 * InSendMessage (USER32.@)
2562 BOOL WINAPI
InSendMessage(void)
2564 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2568 /***********************************************************************
2569 * InSendMessageEx (USER32.@)
2571 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2574 SERVER_START_REQ( in_send_message
)
2576 if (!SERVER_CALL_ERR()) ret
= req
->flags
;
2583 /***********************************************************************
2584 * BroadcastSystemMessage (USER32.@)
2586 LONG WINAPI
BroadcastSystemMessage(
2587 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2590 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2591 dwFlags
,*recipients
,uMessage
,wParam
,lParam