2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
17 #include "sysmetrics.h"
31 #include "debugtools.h"
33 DECLARE_DEBUG_CHANNEL(key
)
34 DECLARE_DEBUG_CHANNEL(msg
)
35 DECLARE_DEBUG_CHANNEL(sendmsg
)
37 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
38 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
41 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
42 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
44 extern HQUEUE16 hCursorQueue
; /* queue.c */
46 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
48 static UINT doubleClickSpeed
= 452;
50 /***********************************************************************
53 BOOL
MSG_CheckFilter(DWORD uMsg
, DWORD first
, DWORD last
)
56 return (uMsg
>= first
&& uMsg
<= last
);
60 /***********************************************************************
61 * MSG_SendParentNotify
63 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
64 * the window has the WS_EX_NOPARENTNOTIFY style.
66 static void MSG_SendParentNotify(WND
* wndPtr
, WORD event
, WORD idChild
, LPARAM lValue
)
68 #define lppt ((LPPOINT16)&lValue)
70 /* pt has to be in the client coordinates of the parent window */
71 WND
*tmpWnd
= WIN_LockWndPtr(wndPtr
);
73 MapWindowPoints16( 0, tmpWnd
->hwndSelf
, lppt
, 1 );
76 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
78 WIN_ReleaseWndPtr(tmpWnd
);
81 lppt
->x
+= tmpWnd
->rectClient
.left
;
82 lppt
->y
+= tmpWnd
->rectClient
.top
;
83 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
84 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
85 MAKEWPARAM( event
, idChild
), lValue
);
92 /***********************************************************************
93 * MSG_TranslateMouseMsg
95 * Translate an mouse hardware event into a real mouse message.
99 * SYSQ_MSG_ABANDON - abandon the peek message loop
100 * SYSQ_MSG_CONTINUE - leave the message in the queue and
101 * continue with the translation loop
102 * SYSQ_MSG_ACCEPT - proceed to process the translated message
104 static DWORD
MSG_TranslateMouseMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
105 MSG
*msg
, BOOL remove
, WND
* pWndScope
,
106 INT16
*pHitTest
, POINT16
*pScreen_pt
, BOOL
*pmouseClick
)
108 static DWORD dblclk_time_limit
= 0;
109 static UINT16 clk_message
= 0;
110 static HWND16 clk_hwnd
= 0;
111 static POINT16 clk_pos
= { 0, 0 };
116 UINT message
= msg
->message
;
117 POINT16 screen_pt
, pt
;
118 HANDLE16 hQ
= GetFastQueue16();
119 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQ
);
120 BOOL mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
121 (message
== WM_RBUTTONDOWN
) ||
122 (message
== WM_MBUTTONDOWN
))?1:0;
125 /* Find the window to dispatch this mouse message to */
127 CONV_POINT32TO16( &msg
->pt
, &pt
);
131 /* If no capture HWND, find window which contains the mouse position.
132 * Also find the position of the cursor hot spot (hittest) */
135 ht
= hittest
= WINPOS_WindowFromPoint( pWndScope
, pt
, &pWnd
);
136 if( !pWnd
) pWnd
= WIN_GetDesktop();
137 else WIN_LockWndPtr(pWnd
);
138 hWnd
= pWnd
->hwndSelf
;
142 ht
= hittest
= HTCLIENT
;
143 pWnd
= WIN_FindWndPtr(hWnd
);
145 ht
= PERQDATA_GetCaptureInfo( queue
->pQData
);
148 /* Save hittest for return */
151 /* stop if not the right queue */
153 if (pWnd
->hmemTaskQ
!= hQ
)
155 /* Not for the current task */
156 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
157 /* Wake up the other task */
158 QUEUE_Unlock( queue
);
159 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
160 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
162 QUEUE_Unlock( queue
);
163 retvalue
= SYSQ_MSG_ABANDON
;
167 /* check if hWnd is within hWndScope */
169 if( hTopWnd
&& hWnd
!= hTopWnd
)
170 if( !IsChild(hTopWnd
, hWnd
) )
172 QUEUE_Unlock( queue
);
173 retvalue
= SYSQ_MSG_CONTINUE
;
177 /* Was it a mouse click message */
180 /* translate double clicks -
181 * note that ...MOUSEMOVEs can slip in between
182 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
184 if( pWnd
->class->style
& CS_DBLCLKS
|| ht
!= HTCLIENT
)
186 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
187 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
188 (abs(msg
->pt
.x
- clk_pos
.x
) < SYSMETRICS_CXDOUBLECLK
/2) &&
189 (abs(msg
->pt
.y
- clk_pos
.y
) < SYSMETRICS_CYDOUBLECLK
/2))
191 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
192 mouseClick
++; /* == 2 */
196 /* save mouse position */
200 if (hittest
!= HTCLIENT
)
202 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
203 msg
->wParam
= hittest
;
206 ScreenToClient16( hWnd
, &pt
);
208 /* check message filter */
210 if (!MSG_CheckFilter(message
, first
, last
))
213 retvalue
= SYSQ_MSG_CONTINUE
;
217 /* Update global hCursorQueue */
218 hCursorQueue
= queue
->self
;
220 /* Update static double click conditions */
221 if( remove
&& mouseClick
)
223 if( mouseClick
== 1 )
226 dblclk_time_limit
= msg
->time
;
227 clk_message
= msg
->message
;
231 /* got double click - zero them out */
232 dblclk_time_limit
= clk_hwnd
= 0;
237 /* Update message params */
239 msg
->message
= message
;
240 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
241 retvalue
= SYSQ_MSG_ACCEPT
;
244 WIN_ReleaseWndPtr(pWnd
);
246 /* Return mouseclick flag */
247 *pmouseClick
= mouseClick
;
253 /***********************************************************************
254 * MSG_ProcessMouseMsg
256 * Processes a translated mouse hardware event.
257 * The passed in msg structure should contain the updated hWnd,
258 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
262 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
263 * HIWORD contains hit test code). Continue translating..
264 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
265 * MSG_PeekHardwareMsg should return TRUE.
267 static DWORD
MSG_ProcessMouseMsg( MSG
*msg
, BOOL remove
, INT16 hittest
,
268 POINT16 screen_pt
, BOOL mouseClick
)
271 HWND hWnd
= msg
->hwnd
;
272 INT16 sendSC
= (GetCapture() == 0);
273 UINT message
= msg
->message
;
277 pWnd
= WIN_FindWndPtr(hWnd
);
281 if (HOOK_IsHooked( WH_MOUSE
))
284 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
287 hook
->pt
= screen_pt
;
289 hook
->wHitTestCode
= hittest
;
290 hook
->dwExtraInfo
= 0;
291 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
292 message
, (LPARAM
)SEGPTR_GET(hook
) );
297 retvalue
= MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
303 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
305 else if( remove
&& mouseClick
)
307 HWND hwndTop
= WIN_GetTopParent( hWnd
);
311 /* Send the WM_PARENTNOTIFY,
312 * note that even for double/nonclient clicks
313 * notification message is still WM_L/M/RBUTTONDOWN.
316 MSG_SendParentNotify( pWnd
, msg
->message
& 0xffff, 0, MAKELPARAM(screen_pt
.x
, screen_pt
.y
) );
318 /* Activate the window if needed */
320 if (hWnd
!= GetActiveWindow() && hWnd
!= GetDesktopWindow())
322 LONG ret
= SendMessageA( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
323 MAKELONG( hittest
, message
) );
325 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
328 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
329 && hwndTop
!= GetActiveWindow() )
330 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
334 } else sendSC
= (remove
&& sendSC
);
336 /* Send the WM_SETCURSOR message */
339 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
,
340 MAKELONG( hittest
, message
));
343 retvalue
= MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
347 retvalue
= SYSQ_MSG_ACCEPT
;
349 WIN_ReleaseWndPtr(pWnd
);
355 /***********************************************************************
356 * MSG_TranslateKbdMsg
358 * Translate an keyboard hardware event into a real message.
360 static DWORD
MSG_TranslateKbdMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
361 MSG
*msg
, BOOL remove
)
363 WORD message
= msg
->message
;
364 HWND hWnd
= GetFocus();
367 /* Should check Ctrl-Esc and PrintScreen here */
371 /* Send the message to the active window instead, */
372 /* translating messages to their WM_SYS equivalent */
374 hWnd
= GetActiveWindow();
376 if( message
< WM_SYSKEYDOWN
)
377 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
379 pWnd
= WIN_FindWndPtr( hWnd
);
380 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetFastQueue16()))
382 /* Not for the current task */
383 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
384 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
385 QUEUE_Unlock( queue
);
387 /* Wake up the other task */
388 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
389 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
390 QUEUE_Unlock( queue
);
391 WIN_ReleaseWndPtr(pWnd
);
392 return SYSQ_MSG_ABANDON
;
394 WIN_ReleaseWndPtr(pWnd
);
396 if (hTopWnd
&& hWnd
!= hTopWnd
)
397 if (!IsChild(hTopWnd
, hWnd
)) return SYSQ_MSG_CONTINUE
;
398 if (!MSG_CheckFilter(message
, first
, last
)) return SYSQ_MSG_CONTINUE
;
401 msg
->message
= message
;
403 return SYSQ_MSG_ACCEPT
;
407 /***********************************************************************
410 * Processes a translated keyboard message
412 static DWORD
MSG_ProcessKbdMsg( MSG
*msg
, BOOL remove
)
414 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
415 LOWORD (msg
->wParam
), msg
->lParam
)
416 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
420 /***********************************************************************
421 * MSG_JournalRecordMsg
423 * Build an EVENTMSG structure and call JOURNALRECORD hook
425 static void MSG_JournalRecordMsg( MSG
*msg
)
427 EVENTMSG
*event
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
429 event
->message
= msg
->message
;
430 event
->time
= msg
->time
;
431 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
433 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
434 event
->paramH
= msg
->lParam
& 0x7FFF;
435 if (HIWORD(msg
->lParam
) & 0x0100)
436 event
->paramH
|= 0x8000; /* special_key - bit */
437 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
439 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
441 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
442 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
443 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
444 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
446 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
447 (msg
->message
<= WM_NCMOUSELAST
))
449 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
450 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
451 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
452 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
455 HeapFree(SystemHeap
, 0, event
);
458 /***********************************************************************
459 * MSG_JournalPlayBackMsg
461 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
463 static int MSG_JournalPlayBackMsg(void)
466 long wtime
,lParam
,wParam
;
467 WORD keyDown
,i
,result
=0;
469 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
471 tmpMsg
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
472 if (!tmpMsg
) return result
;
474 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
476 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
480 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
482 wParam
=tmpMsg
->paramL
& 0xFF;
483 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
484 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
486 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
487 if (InputKeyStateTable
[i
] & 0x80)
490 lParam
|= 0x40000000;
491 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
493 else /* WM_KEYUP, WM_SYSKEYUP */
495 lParam
|= 0xC0000000;
496 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
498 if (InputKeyStateTable
[VK_MENU
] & 0x80)
499 lParam
|= 0x20000000;
500 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
501 lParam
|= 0x01000000;
502 hardware_event( tmpMsg
->message
& 0xffff, LOWORD(wParam
), lParam
,
503 0, 0, tmpMsg
->time
, 0 );
507 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
509 switch (tmpMsg
->message
)
512 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
514 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
516 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
518 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
520 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
522 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
524 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
525 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
526 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
527 SetCursorPos(tmpMsg
->paramL
,tmpMsg
->paramH
);
528 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
530 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
531 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
532 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
533 hardware_event( tmpMsg
->message
& 0xffff, LOWORD (wParam
), lParam
,
534 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
537 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
543 if( tmpMsg
->message
== WM_QUEUESYNC
)
544 if (HOOK_IsHooked( WH_CBT
))
545 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
547 result
= QS_MOUSE
| QS_KEY
; /* ? */
549 HeapFree(SystemHeap
, 0, tmpMsg
);
554 /***********************************************************************
555 * MSG_PeekHardwareMsg
557 * Peek for a hardware message matching the hwnd and message filters.
559 static BOOL
MSG_PeekHardwareMsg( MSG
*msg
, HWND hwnd
, DWORD first
, DWORD last
,
562 /* FIXME: should deal with MSG32 instead of MSG16 */
564 DWORD status
= SYSQ_MSG_ACCEPT
;
565 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
566 enum { MOUSE_MSG
= 0, KEYBOARD_MSG
, HARDWARE_MSG
} msgType
;
567 QMSG
*nextqmsg
, *qmsg
= 0;
570 /* FIXME: there has to be a better way to do this */
573 EnterCriticalSection(&sysMsgQueue
->cSection
);
575 /* If the queue is empty, attempt to fill it */
576 if (!sysMsgQueue
->msgCount
&& THREAD_IsWin16( THREAD_Current() )
579 LeaveCriticalSection(&sysMsgQueue
->cSection
);
581 EVENT_WaitNetEvent( FALSE
, TRUE
);
583 EnterCriticalSection(&sysMsgQueue
->cSection
);
586 /* Loop through the Q and translate the message we wish to process
587 * while we own the lock. Based on the translation status (abandon/cont/accept)
588 * we then process the message accordingly
591 for ( qmsg
= sysMsgQueue
->firstMsg
; qmsg
; qmsg
= nextqmsg
)
599 nextqmsg
= qmsg
->nextMsg
;
601 /* Translate message */
603 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
605 HWND hWndScope
= (HWND
)qmsg
->extraInfo
;
606 WND
*tmpWnd
= (Options
.managed
&& IsWindow(hWndScope
) )
607 ? WIN_FindWndPtr(hWndScope
) : WIN_GetDesktop();
609 status
= MSG_TranslateMouseMsg(hwnd
, first
, last
, msg
, remove
, tmpWnd
,
610 &hittest
, &screen_pt
, &mouseClick
);
613 WIN_ReleaseWndPtr(tmpWnd
);
616 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
618 status
= MSG_TranslateKbdMsg(hwnd
, first
, last
, msg
, remove
);
619 msgType
= KEYBOARD_MSG
;
621 else /* Non-standard hardware event */
623 HARDWAREHOOKSTRUCT16
*hook
;
624 msgType
= HARDWARE_MSG
;
625 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
628 hook
->hWnd
= msg
->hwnd
;
629 hook
->wMessage
= msg
->message
& 0xffff;
630 hook
->wParam
= LOWORD (msg
->wParam
);
631 hook
->lParam
= msg
->lParam
;
632 ret
= HOOK_CallHooks16( WH_HARDWARE
,
633 remove
? HC_ACTION
: HC_NOREMOVE
,
634 0, (LPARAM
)SEGPTR_GET(hook
) );
638 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
641 status
= SYSQ_MSG_ACCEPT
;
646 switch (LOWORD(status
))
648 case SYSQ_MSG_ACCEPT
:
650 /* Remove the message from the system msg Q while it is still locked,
651 * before accepting it */
654 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
655 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
657 /* Now actually process the message, after we unlock the system msg Q.
658 * We should not hold on to the crst since SendMessage calls during processing
659 * will potentially cause callbacks to PeekMessage from the application.
660 * If we're holding the crst and QUEUE_WaitBits is called with a
661 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
662 * message is being posted to the Q.
664 LeaveCriticalSection(&sysMsgQueue
->cSection
);
665 if( msgType
== KEYBOARD_MSG
)
666 status
= MSG_ProcessKbdMsg( msg
, remove
);
667 else if ( msgType
== MOUSE_MSG
)
668 status
= MSG_ProcessMouseMsg( msg
, remove
, hittest
, screen_pt
, mouseClick
);
670 /* Reclaim the sys msg Q crst */
671 EnterCriticalSection(&sysMsgQueue
->cSection
);
673 /* Pass the translated message to the user if it was accepted */
674 if (status
== SYSQ_MSG_ACCEPT
)
677 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
681 if (HOOK_IsHooked( WH_CBT
))
683 if( msgType
== KEYBOARD_MSG
)
684 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
685 LOWORD (msg
->wParam
), msg
->lParam
);
686 else if ( msgType
== MOUSE_MSG
)
688 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
691 CONV_POINT32TO16( &msg
->pt
,&hook
->pt
);
692 hook
->hwnd
= msg
->hwnd
;
693 hook
->wHitTestCode
= HIWORD(status
);
694 hook
->dwExtraInfo
= 0;
695 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
& 0xffff,
696 (LPARAM
)SEGPTR_GET(hook
) );
702 /* If the message was removed earlier set up nextqmsg so that we start
703 * at the top of the queue again. We need to do this since our next pointer
704 * could be invalid due to us unlocking the system message Q to process the message.
705 * If not removed just refresh nextqmsg to point to the next msg.
708 nextqmsg
= sysMsgQueue
->firstMsg
;
710 nextqmsg
= qmsg
->nextMsg
;
714 case SYSQ_MSG_CONTINUE
:
717 case SYSQ_MSG_ABANDON
:
727 LeaveCriticalSection(&sysMsgQueue
->cSection
);
732 /**********************************************************************
733 * SetDoubleClickTime16 (USER.20)
735 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
737 SetDoubleClickTime( interval
);
741 /**********************************************************************
742 * SetDoubleClickTime32 (USER32.480)
744 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
746 doubleClickSpeed
= interval
? interval
: 500;
751 /**********************************************************************
752 * GetDoubleClickTime16 (USER.21)
754 UINT16 WINAPI
GetDoubleClickTime16(void)
756 return doubleClickSpeed
;
760 /**********************************************************************
761 * GetDoubleClickTime32 (USER32.239)
763 UINT WINAPI
GetDoubleClickTime(void)
765 return doubleClickSpeed
;
769 /***********************************************************************
770 * MSG_SendMessageInterThread
772 * Implementation of an inter-task SendMessage.
774 * 0 if error or timeout
777 static LRESULT
MSG_SendMessageInterThread( HQUEUE16 hDestQueue
,
779 WPARAM wParam
, LPARAM lParam
,
780 DWORD timeout
, WORD flags
,
783 MESSAGEQUEUE
*queue
, *destQ
;
790 if (IsTaskLocked16() || !IsWindow(hwnd
))
793 /* create a SMSG structure to hold SendMessage() parameters */
794 if (! (smsg
= (SMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(SMSG
) )) )
796 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
798 if (!(destQ
= (MESSAGEQUEUE
*)QUEUE_Lock( hDestQueue
)))
800 QUEUE_Unlock( queue
);
804 TRACE_(sendmsg
)("SM: %s [%04x] (%04x -> %04x)\n",
805 SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
807 /* fill up SMSG structure */
810 smsg
->wParam
= wParam
;
811 smsg
->lParam
= lParam
;
814 smsg
->hSrcQueue
= GetFastQueue16();
815 smsg
->hDstQueue
= hDestQueue
;
818 /* add smsg struct in the processing SM list of the source queue */
819 QUEUE_AddSMSG(queue
, SM_PROCESSING_LIST
, smsg
);
821 /* add smsg struct in the pending list of the destination queue */
822 if (QUEUE_AddSMSG(destQ
, SM_PENDING_LIST
, smsg
) == FALSE
)
825 iWndsLocks
= WIN_SuspendWndsLock();
827 /* force destination task to run next, if 16 bit threads */
828 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ
->thdb
) )
829 DirectedYield16( destQ
->thdb
->teb
.htask16
);
831 /* wait for the result, note that 16-bit apps almost always get out of
832 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
837 * The sequence is crucial to avoid deadlock situations:
838 * - first, we clear the QS_SMRESULT bit
839 * - then, we check the SMSG_HAVE_RESULT bit
840 * - only if this isn't set, we enter the wait state.
842 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
843 * we are guaranteed that -should we now clear the QS_SMRESULT that
844 * was signalled already by the receiver- we will not start waiting.
847 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
850 *pRes
= smsg
->lResult
;
851 TRACE_(sendmsg
)("smResult = %08x\n", (unsigned)*pRes
);
855 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
857 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
860 if( QUEUE_WaitBits( QS_SMRESULT
, timeout
) == 0 )
862 /* return with timeout */
868 WIN_RestoreWndsLock(iWndsLocks
);
870 /* remove the smsg from the processingg list of the source queue */
871 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
873 /* Note: the destination thread is in charge of removing the smsg from
876 /* In the case of an early reply (or a timeout), sender thread will
877 released the smsg structure if the receiver thread is done
878 (SMSG_RECEIVED set). If the receiver thread isn't done,
879 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
880 responsability to released smsg */
881 EnterCriticalSection( &queue
->cSection
);
883 if (smsg
->flags
& SMSG_RECEIVED
)
884 HeapFree(SystemHeap
, 0, smsg
);
886 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
888 LeaveCriticalSection( &queue
->cSection
);
891 QUEUE_Unlock( queue
);
892 QUEUE_Unlock( destQ
);
894 TRACE_(sendmsg
)("done!\n");
899 /***********************************************************************
900 * ReplyMessage16 (USER.115)
902 void WINAPI
ReplyMessage16( LRESULT result
)
904 ReplyMessage( result
);
907 /***********************************************************************
908 * ReplyMessage (USER.115)
910 BOOL WINAPI
ReplyMessage( LRESULT result
)
912 MESSAGEQUEUE
*senderQ
= 0;
913 MESSAGEQUEUE
*queue
= 0;
917 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
920 TRACE_(sendmsg
)("ReplyMessage, queue %04x\n", queue
->self
);
923 if ( !(smsg
= queue
->smWaiting
)
924 || !(senderQ
= QUEUE_Lock( smsg
->hSrcQueue
)) )
925 goto ReplyMessageEnd
;
927 if ( !(smsg
->flags
& SMSG_ALREADY_REPLIED
) )
929 /* This is the first reply, so pass result to sender */
931 TRACE_(sendmsg
)("\trpm: smResult = %08lx\n", (long) result
);
933 EnterCriticalSection(&senderQ
->cSection
);
935 smsg
->lResult
= result
;
936 smsg
->flags
|= SMSG_ALREADY_REPLIED
;
938 /* check if it's an early reply (called by the application) or
939 a regular reply (called by ReceiveMessage) */
940 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
941 smsg
->flags
|= SMSG_EARLY_REPLY
;
943 smsg
->flags
|= SMSG_HAVE_RESULT
;
945 LeaveCriticalSection(&senderQ
->cSection
);
947 /* tell the sending task that its reply is ready */
948 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
950 /* switch directly to sending task (16 bit thread only) */
951 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ
->thdb
) )
952 DirectedYield16( senderQ
->thdb
->teb
.htask16
);
957 if (smsg
->flags
& SMSG_SENDING_REPLY
)
959 /* remove msg from the waiting list, since this is the last
961 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
963 EnterCriticalSection(&senderQ
->cSection
);
965 /* tell the sender we're all done with smsg structure */
966 smsg
->flags
|= SMSG_RECEIVED
;
968 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
969 receiver to clean up smsg, it could only happens when there is
970 an early reply or a timeout */
971 if ( smsg
->flags
& SMSG_RECEIVER_CLEANS
)
973 TRACE_(sendmsg
)("Receiver cleans up!\n" );
974 HeapFree( SystemHeap
, 0, smsg
);
977 LeaveCriticalSection(&senderQ
->cSection
);
982 QUEUE_Unlock( senderQ
);
984 QUEUE_Unlock( queue
);
989 /***********************************************************************
992 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
993 WORD flags
, BOOL peek
)
996 MESSAGEQUEUE
*msgQueue
;
1002 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
1003 DDE_GetRemoteMessage();
1004 #endif /* CONFIG_IPC */
1006 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
1009 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
1010 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
1011 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
1012 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
1013 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
1014 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
1016 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
1018 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
1020 /* Never yield on Win32 threads */
1021 if (!THREAD_IsWin16(THREAD_Current())) flags
|= PM_NOYIELD
;
1023 iWndsLocks
= WIN_SuspendWndsLock();
1029 hQueue
= GetFastQueue16();
1030 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1033 WIN_RestoreWndsLock(iWndsLocks
);
1036 msgQueue
->changeBits
= 0;
1038 /* First handle a message put by SendMessage() */
1040 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1041 QUEUE_ReceiveMessage( msgQueue
);
1043 /* Now handle a WM_QUIT message */
1045 if (msgQueue
->wPostQMsg
&&
1046 (!first
|| WM_QUIT
>= first
) &&
1047 (!last
|| WM_QUIT
<= last
) )
1050 msg
->message
= WM_QUIT
;
1051 msg
->wParam
= msgQueue
->wExitCode
;
1053 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
1057 /* Now find a normal message */
1059 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
1060 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
1064 msgQueue
->GetMessageTimeVal
= msg
->time
;
1065 CONV_POINT32TO16(&msg
->pt
, &pt16
);
1066 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
1067 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
1069 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
1073 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
1075 /* Now find a hardware event */
1077 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
1078 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
1081 msgQueue
->GetMessageTimeVal
= msg
->time
;
1082 CONV_POINT32TO16(&msg
->pt
, &pt16
);
1083 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
1084 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
1088 /* Check again for SendMessage */
1090 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1091 QUEUE_ReceiveMessage( msgQueue
);
1093 /* Now find a WM_PAINT message */
1095 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
1098 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
1099 msg
->message
= WM_PAINT
;
1103 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
1105 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
1106 wndPtr
->class->hIcon
)
1108 msg
->message
= WM_PAINTICON
;
1112 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
1114 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
1116 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
1117 QUEUE_DecPaintCount( hQueue
);
1119 WIN_ReleaseWndPtr(wndPtr
);
1122 WIN_ReleaseWndPtr(wndPtr
);
1126 /* Check for timer messages, but yield first */
1128 if (!(flags
& PM_NOYIELD
))
1131 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1132 QUEUE_ReceiveMessage( msgQueue
);
1134 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
1136 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
1141 if (!(flags
& PM_NOYIELD
)) UserYield16();
1143 QUEUE_Unlock( msgQueue
);
1144 WIN_RestoreWndsLock(iWndsLocks
);
1147 msgQueue
->wakeMask
= mask
;
1148 QUEUE_WaitBits( mask
, INFINITE
);
1149 QUEUE_Unlock( msgQueue
);
1152 WIN_RestoreWndsLock(iWndsLocks
);
1154 /* instead of unlocking queue for every break condition, all break
1155 condition will fall here */
1156 QUEUE_Unlock( msgQueue
);
1158 /* We got a message */
1159 if (flags
& PM_REMOVE
)
1161 WORD message
= msg
->message
;
1163 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
1165 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
1171 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
1172 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
1179 return (msg
->message
!= WM_QUIT
);
1182 /***********************************************************************
1183 * MSG_InternalGetMessage
1185 * GetMessage() function for internal use. Behave like GetMessage(),
1186 * but also call message filters and optionally send WM_ENTERIDLE messages.
1187 * 'hwnd' must be the handle of the dialog or menu window.
1188 * 'code' is the message filter value (MSGF_??? codes).
1190 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
1191 WPARAM code
, WORD flags
, BOOL sendIdle
)
1197 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1199 /* No message present -> send ENTERIDLE and wait */
1200 if (IsWindow(hwndOwner
))
1201 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1202 code
, (LPARAM
)hwnd
);
1203 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1206 else /* Always wait for a message */
1207 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1209 /* Call message filters */
1211 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1213 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1218 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1220 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1223 HeapFree( SystemHeap
, 0, pmsg
);
1226 /* Message filtered -> remove it from the queue */
1227 /* if it's still there. */
1228 if (!(flags
& PM_REMOVE
))
1229 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1235 return (msg
->message
!= WM_QUIT
);
1240 /***********************************************************************
1241 * PeekMessage16 (USER.109)
1243 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1244 UINT16 last
, UINT16 flags
)
1248 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1249 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1253 /***********************************************************************
1254 * WIN16_PeekMessage32 (USER.819)
1256 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1257 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1259 if (wHaveParamHigh
== FALSE
)
1261 lpmsg16_32
->wParamHigh
= 0;
1262 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1269 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1270 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1271 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1272 lpmsg16_32
->msg
.message
= msg32
.message
;
1273 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1274 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1275 lpmsg16_32
->msg
.time
= msg32
.time
;
1276 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1277 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1278 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1284 /***********************************************************************
1287 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1288 UINT min
,UINT max
,UINT wRemoveMsg
)
1290 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1293 /***********************************************************************
1294 * PeekMessageW Check queue for messages
1296 * Checks for a message in the thread's queue, filtered as for
1297 * GetMessage(). Returns immediately whether a message is available
1300 * Whether a retrieved message is removed from the queue is set by the
1301 * _wRemoveMsg_ flags, which should be one of the following values:
1303 * PM_NOREMOVE Do not remove the message from the queue.
1305 * PM_REMOVE Remove the message from the queue.
1307 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1308 * request that the system not yield control during PeekMessage();
1309 * however applications may not rely on scheduling behavior.
1313 * Nonzero if a message is available and is retrieved, zero otherwise.
1320 BOOL WINAPI
PeekMessageW(
1321 LPMSG lpmsg
, /* buffer to receive message */
1322 HWND hwnd
, /* restrict to messages for hwnd */
1323 UINT min
, /* minimum message to receive */
1324 UINT max
, /* maximum message to receive */
1325 UINT wRemoveMsg
/* removal flags */
1328 BOOL bRet
= PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1330 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg
->message
));
1334 /***********************************************************************
1335 * GetMessage16 (USER.108)
1337 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1340 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1343 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1345 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1347 TRACE_(msg
)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1348 hwnd
, first
, last
);
1353 /***********************************************************************
1354 * WIN16_GetMessage32 (USER.820)
1356 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1357 UINT16 last
, BOOL16 wHaveParamHigh
)
1359 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1361 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1364 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1365 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1366 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1373 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1374 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1375 lpmsg16_32
->msg
.message
= msg32
.message
;
1376 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1377 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1378 lpmsg16_32
->msg
.time
= msg32
.time
;
1379 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1380 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1381 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1386 /***********************************************************************
1387 * GetMessage32A (USER32.270)
1389 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1391 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1393 TRACE_(msg
)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1396 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1398 return (lpmsg
->message
!= WM_QUIT
);
1401 /***********************************************************************
1402 * GetMessage32W (USER32.274) Retrieve next message
1404 * GetMessage retrieves the next event from the calling thread's
1405 * queue and deposits it in *lpmsg.
1407 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1408 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1409 * all application messages are retrieved.
1411 * _min_ and _max_ specify the range of messages of interest. If
1412 * min==max==0, no filtering is performed. Useful examples are
1413 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1414 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1416 * WM_PAINT messages are not removed from the queue; they remain until
1417 * processed. Other messages are removed from the queue.
1421 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1428 BOOL WINAPI
GetMessageW(
1429 MSG
* lpmsg
, /* buffer to receive message */
1430 HWND hwnd
, /* restrict to messages for hwnd */
1431 UINT min
, /* minimum message to receive */
1432 UINT max
/* maximum message to receive */
1435 BOOL bRet
= GetMessageA(lpmsg
, hwnd
, min
, max
);
1437 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg
->message
));
1443 /***********************************************************************
1444 * PostMessage16 (USER.110)
1446 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1449 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1453 /***********************************************************************
1454 * PostMessage32A (USER32.419)
1456 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1464 msg
.message
= message
;
1465 msg
.wParam
= wParam
;
1466 msg
.lParam
= lParam
;
1467 msg
.time
= GetTickCount();
1472 if (DDE_PostMessage(&msg
))
1474 #endif /* CONFIG_IPC */
1476 if (hwnd
== HWND_BROADCAST
)
1478 WND
*pDesktop
= WIN_GetDesktop();
1479 TRACE_(msg
)("HWND_BROADCAST !\n");
1481 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1483 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1485 TRACE_(msg
)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1486 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1487 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1490 WIN_ReleaseDesktop();
1491 TRACE_(msg
)("End of HWND_BROADCAST !\n");
1495 wndPtr
= WIN_FindWndPtr( hwnd
);
1496 if (!wndPtr
|| !wndPtr
->hmemTaskQ
)
1502 retvalue
= QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1504 WIN_ReleaseWndPtr(wndPtr
);
1509 /***********************************************************************
1510 * PostMessage32W (USER32.420)
1512 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1515 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(message
));
1516 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1520 /***********************************************************************
1521 * PostAppMessage16 (USER.116)
1523 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1528 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1530 msg
.message
= message
;
1531 msg
.wParam
= wParam
;
1532 msg
.lParam
= lParam
;
1533 msg
.time
= GetTickCount();
1537 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1540 /************************************************************************
1541 * MSG_CallWndProcHook32
1543 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1547 cwp
.lParam
= pmsg
->lParam
;
1548 cwp
.wParam
= pmsg
->wParam
;
1549 cwp
.message
= pmsg
->message
;
1550 cwp
.hwnd
= pmsg
->hwnd
;
1552 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1553 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1555 pmsg
->lParam
= cwp
.lParam
;
1556 pmsg
->wParam
= cwp
.wParam
;
1557 pmsg
->message
= cwp
.message
;
1558 pmsg
->hwnd
= cwp
.hwnd
;
1562 /***********************************************************************
1565 * return values: 0 if timeout occurs
1568 LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1569 LPARAM lParam
, DWORD timeout
, WORD flags
,
1573 WND
**list
, **ppWnd
;
1578 if (hwnd
== HWND_BROADCAST
)
1582 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1584 WIN_ReleaseDesktop();
1587 WIN_ReleaseDesktop();
1589 TRACE_(msg
)("HWND_BROADCAST !\n");
1590 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1592 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1593 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1594 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1596 TRACE_(msg
)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1597 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1598 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1599 timeout
, flags
, pRes
);
1602 WIN_ReleaseWndPtr(wndPtr
);
1603 WIN_ReleaseWinArray(list
);
1604 TRACE_(msg
)("End of HWND_BROADCAST !\n");
1608 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1610 if (flags
& SMSG_UNICODE
)
1611 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1612 else if (flags
& SMSG_WIN32
)
1613 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1618 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1620 pmsg
->hwnd
= hwnd
& 0xffff;
1621 pmsg
->message
= msg
& 0xffff;
1622 pmsg
->wParam
= wParam
& 0xffff;
1623 pmsg
->lParam
= lParam
;
1624 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1625 (LPARAM
)SEGPTR_GET(pmsg
) );
1627 msg
= pmsg
->message
;
1628 wParam
= pmsg
->wParam
;
1629 lParam
= pmsg
->lParam
;
1630 SEGPTR_FREE( pmsg
);
1635 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1637 WARN_(msg
)("invalid hwnd %04x\n", hwnd
);
1640 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1642 ret
= 0; /* Don't send anything if the task is dying */
1645 if (flags
& SMSG_WIN32
)
1646 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1648 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1650 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1651 ret
= MSG_SendMessageInterThread( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1652 wParam
, lParam
, timeout
, flags
, pRes
);
1655 /* Call the right CallWindowProc flavor */
1656 if (flags
& SMSG_UNICODE
)
1657 *pRes
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1658 hwnd
, msg
, wParam
, lParam
);
1659 else if (flags
& SMSG_WIN32
)
1660 *pRes
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1661 hwnd
, msg
, wParam
, lParam
);
1663 *pRes
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1664 (HWND16
) hwnd
, (UINT16
) msg
,
1665 (WPARAM16
) wParam
, lParam
);
1668 if (flags
& SMSG_WIN32
)
1669 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1671 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1673 WIN_ReleaseWndPtr(wndPtr
);
1678 /***********************************************************************
1679 * SendMessage16 (USER.111)
1681 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1686 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
1687 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
1688 #endif /* CONFIG_IPC */
1690 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, 0, &res
);
1697 /**********************************************************************
1698 * PostThreadMessage32A (USER32.422)
1702 * Thread-local message queues are not supported.
1705 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1706 WPARAM wParam
, LPARAM lParam
)
1711 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1715 msg
.message
= message
;
1716 msg
.wParam
= wParam
;
1717 msg
.lParam
= lParam
;
1718 msg
.time
= GetTickCount();
1722 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1725 /**********************************************************************
1726 * PostThreadMessage32W (USER32.423)
1730 * Thread-local message queues are not supported.
1733 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1734 WPARAM wParam
, LPARAM lParam
)
1736 FIXME_(sendmsg
)("(%s) unicode<->ascii\n",SPY_GetMsgName(message
));
1737 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1740 /***********************************************************************
1741 * SendMessage32A (USER32.454)
1743 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1748 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1755 /***********************************************************************
1756 * SendMessage32W (USER32.459) Send Window Message
1758 * Sends a message to the window procedure of the specified window.
1759 * SendMessage() will not return until the called window procedure
1760 * either returns or calls ReplyMessage().
1762 * Use PostMessage() to send message and return immediately. A window
1763 * procedure may use InSendMessage() to detect
1764 * SendMessage()-originated messages.
1766 * Applications which communicate via HWND_BROADCAST may use
1767 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1768 * with other applications.
1774 LRESULT WINAPI
SendMessageW(
1775 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1776 the message will be sent to all top-level windows. */
1778 UINT msg
, /* message */
1779 WPARAM wParam
, /* message parameter */
1780 LPARAM lParam
/* additional message parameter */
1784 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1785 SMSG_WIN32
| SMSG_UNICODE
, &res
);
1791 /***********************************************************************
1792 * SendMessageTimeout16 (not a WINAPI)
1794 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1795 LPARAM lParam
, UINT16 flags
,
1796 UINT16 timeout
, LPWORD resultp
)
1801 /* FIXME: need support for SMTO_BLOCK */
1803 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, 0, &msgRet
);
1804 *resultp
= (WORD
) msgRet
;
1809 /***********************************************************************
1810 * SendMessageTimeoutA (USER32.457)
1812 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1813 LPARAM lParam
, UINT flags
,
1814 UINT timeout
, LPDWORD resultp
)
1819 /* FIXME: need support for SMTO_BLOCK */
1821 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, SMSG_WIN32
,
1824 *resultp
= (DWORD
) msgRet
;
1829 /***********************************************************************
1830 * SendMessageTimeoutW (USER32.458)
1832 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1833 LPARAM lParam
, UINT flags
,
1834 UINT timeout
, LPDWORD resultp
)
1839 /* FIXME: need support for SMTO_BLOCK */
1841 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
,
1842 SMSG_WIN32
| SMSG_UNICODE
, &msgRet
);
1844 *resultp
= (DWORD
) msgRet
;
1849 /***********************************************************************
1850 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1852 * WaitMessage() suspends a thread until events appear in the thread's
1857 * Is supposed to return BOOL under Win32.
1859 * Thread-local message queues are not supported.
1866 void WINAPI
WaitMessage( void )
1868 QUEUE_WaitBits( QS_ALLINPUT
, INFINITE
);
1871 /***********************************************************************
1872 * MsgWaitForMultipleObjects (USER32.400)
1874 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1875 BOOL fWaitAll
, DWORD dwMilliseconds
,
1879 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1882 HQUEUE16 hQueue
= GetFastQueue16();
1883 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1884 if (!msgQueue
) return WAIT_FAILED
;
1886 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1888 SetLastError( ERROR_INVALID_PARAMETER
);
1889 QUEUE_Unlock( msgQueue
);
1893 msgQueue
->changeBits
= 0;
1894 msgQueue
->wakeMask
= dwWakeMask
;
1896 if (THREAD_IsWin16(THREAD_Current()))
1899 * This is a temporary solution to a big problem.
1900 * You see, the main thread of all Win32 programs is created as a 16 bit
1901 * task. This means that if you want on an event using Win32 synchronization
1902 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1903 * This implements a semi-busy loop that checks the handles to wait on and
1904 * also the message queue. When either one is ready, the wait function returns.
1906 * This will all go away when the real Win32 threads are implemented for all
1907 * the threads of an applications. Including the main thread.
1909 DWORD curTime
= GetCurrentTime();
1914 * Check the handles in the list.
1916 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1919 * If the handles have been triggered, return.
1921 if (ret
!= WAIT_TIMEOUT
)
1925 * Then, let the 16 bit scheduler do it's thing.
1930 * If a message matching the wait mask has arrived, return.
1932 if (msgQueue
->changeBits
& dwWakeMask
)
1939 * And continue doing this until we hit the timeout.
1941 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1945 /* Add the thread event to the handle list */
1946 for (i
= 0; i
< nCount
; i
++)
1947 handles
[i
] = pHandles
[i
];
1948 handles
[nCount
] = msgQueue
->hEvent
;
1952 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1955 QUEUE_Unlock( msgQueue
);
1969 static const struct accent_char accent_chars
[] =
1971 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1972 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1973 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1974 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1975 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1976 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1977 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1978 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1979 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1980 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1981 {',', 'C', '\307'}, {',', 'c', '\347'},
1982 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1983 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1984 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1985 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1986 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1987 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1988 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1989 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1990 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1991 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1992 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1993 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1994 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1995 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1996 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1997 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1998 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1999 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2000 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2001 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2002 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2003 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2004 {'s', 's', '\337'}, {'"', 'y', '\377'},
2005 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2006 /* iso-8859-2 uses this */
2007 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2008 {'<', 'S', '\251'}, {'<', 's', '\271'},
2009 {'<', 'T', '\253'}, {'<', 't', '\273'},
2010 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2011 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2012 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2013 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2014 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2015 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2016 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2017 {';', 'E', '\312'}, {';', 'e', '\332'},
2018 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2019 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2020 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2021 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2022 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2023 /* collision whith S, from iso-8859-9 !!! */
2024 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2025 {',', 'T', '\336'}, {',', 't', '\376'},
2026 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2027 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2028 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2029 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2030 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2031 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2032 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2033 /* iso-8859-3 uses this */
2034 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2035 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2036 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2037 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2038 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2039 {'>', 'S', '\336'}, {'>', 's', '\376'},
2040 /* collision whith G( from iso-8859-9 !!! */
2041 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2042 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2043 /* collision whith I. from iso-8859-3 !!! */
2044 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2045 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2046 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2047 /* iso-8859-4 uses this */
2048 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2049 {',', 'L', '\246'}, {',', 'l', '\266'},
2050 {',', 'G', '\253'}, {',', 'g', '\273'},
2051 {',', 'N', '\321'}, {',', 'n', '\361'},
2052 {',', 'K', '\323'}, {',', 'k', '\363'},
2053 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2054 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2055 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2056 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2057 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2058 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2059 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2060 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2061 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2062 {';', 'U', '\331'}, {';', 'u', '\371'},
2063 /* iso-8859-9 uses this */
2064 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2065 * whith the same letters on other iso-8859-x (that is they are on
2066 * different places :-( ), if you use turkish uncomment these and
2067 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2068 * FIXME: should be dynamic according to chosen language
2069 * if/when Wine has turkish support.
2071 /* collision whith G( from iso-8859-3 !!! */
2072 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2073 /* collision whith S, from iso-8859-2 !!! */
2074 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2075 /* collision whith I. from iso-8859-3 !!! */
2076 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2080 /***********************************************************************
2081 * MSG_DoTranslateMessage
2083 * Implementation of TranslateMessage.
2085 * TranslateMessage translates virtual-key messages into character-messages,
2087 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2088 * ditto replacing WM_* with WM_SYS*
2089 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2090 * by the keyboard driver.
2092 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
2093 WPARAM wParam
, LPARAM lParam
)
2095 static int dead_char
;
2098 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
2099 TRACE_(msg
)("(%s, %04X, %08lX)\n",
2100 SPY_GetMsgName(message
), wParam
, lParam
);
2101 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
2102 TRACE_(key
)("(%s, %04X, %08lX)\n",
2103 SPY_GetMsgName(message
), wParam
, lParam
);
2105 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
2107 TRACE_(key
)("Translating key %04X, scancode %04X\n",
2108 wParam
, HIWORD(lParam
) );
2110 /* FIXME : should handle ToAscii yielding 2 */
2111 switch (ToAscii(wParam
, HIWORD(lParam
),
2112 QueueKeyStateTable
,(LPWORD
)wp
, 0))
2115 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2116 /* Should dead chars handling go in ToAscii ? */
2121 if (wp
[0] == ' ') wp
[0] = dead_char
;
2122 if (dead_char
== 0xa2) dead_char
= '(';
2123 else if (dead_char
== 0xa8) dead_char
= '"';
2124 else if (dead_char
== 0xb2) dead_char
= ';';
2125 else if (dead_char
== 0xb4) dead_char
= '\'';
2126 else if (dead_char
== 0xb7) dead_char
= '<';
2127 else if (dead_char
== 0xb8) dead_char
= ',';
2128 else if (dead_char
== 0xff) dead_char
= '.';
2129 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2130 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2131 (accent_chars
[i
].ac_char
== wp
[0]))
2133 wp
[0] = accent_chars
[i
].ac_result
;
2138 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2139 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2143 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2145 TRACE_(key
)("-1 -> PostMessage(%s)\n",
2146 SPY_GetMsgName(message
));
2147 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2154 /***********************************************************************
2155 * TranslateMessage16 (USER.113)
2157 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2159 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2160 msg
->wParam
, msg
->lParam
);
2164 /***********************************************************************
2165 * WIN16_TranslateMessage32 (USER.821)
2167 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2172 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2174 wParam
= (WPARAM
)msg
->msg
.wParam
;
2176 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2177 wParam
, msg
->msg
.lParam
);
2180 /***********************************************************************
2181 * TranslateMessage32 (USER32.556)
2183 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2185 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2186 msg
->wParam
, msg
->lParam
);
2190 /***********************************************************************
2191 * DispatchMessage16 (USER.114)
2193 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2199 /* Process timer messages */
2200 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2204 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2205 msg
->message
, msg
->wParam
, GetTickCount() );
2209 if (!msg
->hwnd
) return 0;
2210 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2211 if (!wndPtr
->winproc
)
2216 painting
= (msg
->message
== WM_PAINT
);
2217 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2219 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2220 msg
->wParam
, msg
->lParam
);
2221 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2222 msg
->hwnd
, msg
->message
,
2223 msg
->wParam
, msg
->lParam
);
2224 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
2226 WIN_ReleaseWndPtr(wndPtr
);
2227 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2228 if (painting
&& wndPtr
&&
2229 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2231 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2233 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2234 /* Validate the update region to avoid infinite WM_PAINT loop */
2235 ValidateRect( msg
->hwnd
, NULL
);
2238 WIN_ReleaseWndPtr(wndPtr
);
2243 /***********************************************************************
2244 * WIN16_DispatchMessage32 (USER.822)
2246 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2248 if (wHaveParamHigh
== FALSE
)
2249 return DispatchMessage16(&(lpmsg16_32
->msg
));
2254 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2255 msg
.message
= lpmsg16_32
->msg
.message
;
2256 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2257 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2258 msg
.time
= lpmsg16_32
->msg
.time
;
2259 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2260 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2261 return DispatchMessageA(&msg
);
2265 /***********************************************************************
2266 * DispatchMessage32A (USER32.141)
2268 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2274 /* Process timer messages */
2275 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2279 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2280 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2281 msg
->message
, msg
->wParam
, GetTickCount() );
2285 if (!msg
->hwnd
) return 0;
2286 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2287 if (!wndPtr
->winproc
)
2292 painting
= (msg
->message
== WM_PAINT
);
2293 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2294 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2296 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2297 msg
->wParam
, msg
->lParam
);
2298 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2299 msg
->hwnd
, msg
->message
,
2300 msg
->wParam
, msg
->lParam
);
2301 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2303 WIN_ReleaseWndPtr(wndPtr
);
2304 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2306 if (painting
&& wndPtr
&&
2307 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2309 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2311 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2312 /* Validate the update region to avoid infinite WM_PAINT loop */
2313 ValidateRect( msg
->hwnd
, NULL
);
2316 WIN_ReleaseWndPtr(wndPtr
);
2321 /***********************************************************************
2322 * DispatchMessage32W (USER32.142) Process Message
2324 * Process the message specified in the structure *_msg_.
2326 * If the lpMsg parameter points to a WM_TIMER message and the
2327 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2328 * points to the function that is called instead of the window
2331 * The message must be valid.
2335 * DispatchMessage() returns the result of the window procedure invoked.
2342 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2348 /* Process timer messages */
2349 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2353 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2354 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2355 msg
->message
, msg
->wParam
, GetTickCount() );
2359 if (!msg
->hwnd
) return 0;
2360 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2361 if (!wndPtr
->winproc
)
2366 painting
= (msg
->message
== WM_PAINT
);
2367 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2368 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2370 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2371 msg
->wParam
, msg
->lParam
);
2372 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2373 msg
->hwnd
, msg
->message
,
2374 msg
->wParam
, msg
->lParam
);
2375 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2377 WIN_ReleaseWndPtr(wndPtr
);
2378 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2380 if (painting
&& wndPtr
&&
2381 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2383 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2385 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2386 /* Validate the update region to avoid infinite WM_PAINT loop */
2387 ValidateRect( msg
->hwnd
, NULL
);
2390 WIN_ReleaseWndPtr(wndPtr
);
2395 /***********************************************************************
2396 * RegisterWindowMessage16 (USER.118)
2398 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2400 TRACE_(msg
)("%08lx\n", (DWORD
)str
);
2401 return GlobalAddAtom16( str
);
2405 /***********************************************************************
2406 * RegisterWindowMessage32A (USER32.437)
2408 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2410 TRACE_(msg
)("%s\n", str
);
2411 return GlobalAddAtomA( str
);
2415 /***********************************************************************
2416 * RegisterWindowMessage32W (USER32.438)
2418 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2420 TRACE_(msg
)("%p\n", str
);
2421 return GlobalAddAtomW( str
);
2425 /***********************************************************************
2426 * GetTickCount (USER.13) (KERNEL32.299) System Time
2427 * Returns the number of milliseconds, modulo 2^32, since the start
2428 * of the current session.
2434 DWORD WINAPI
GetTickCount(void)
2437 gettimeofday( &t
, NULL
);
2438 /* make extremely compatible: granularity is 25 msec */
2439 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2443 /***********************************************************************
2444 * GetCurrentTime16 (USER.15)
2446 * (effectively identical to GetTickCount)
2448 DWORD WINAPI
GetCurrentTime16(void)
2450 return GetTickCount();
2454 /***********************************************************************
2455 * InSendMessage16 (USER.192)
2457 BOOL16 WINAPI
InSendMessage16(void)
2459 return InSendMessage();
2463 /***********************************************************************
2464 * InSendMessage32 (USER32.320)
2466 BOOL WINAPI
InSendMessage(void)
2468 MESSAGEQUEUE
*queue
;
2471 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2473 ret
= (BOOL
)queue
->smWaiting
;
2475 QUEUE_Unlock( queue
);
2479 /***********************************************************************
2480 * BroadcastSystemMessage (USER32.12)
2482 LONG WINAPI
BroadcastSystemMessage(
2483 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2486 FIXME_(sendmsg
)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2487 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2492 /***********************************************************************
2493 * SendNotifyMessageA (USER32.460)
2495 * The message sended with PostMessage has to be put in the queue
2496 * with a higher priority as the other "Posted" messages.
2497 * QUEUE_AddMsg has to be modifyed.
2499 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2501 FIXME_(msg
)("(%04x,%08x,%08x,%08lx) not complete\n",
2502 hwnd
, msg
, wParam
, lParam
);
2504 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2505 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2508 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2513 /***********************************************************************
2514 * SendNotifyMessageW (USER32.461)
2516 * The message sended with PostMessage has to be put in the queue
2517 * with a higher priority as the other "Posted" messages.
2518 * QUEUE_AddMsg has to be modifyed.
2520 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2522 FIXME_(msg
)("(%04x,%08x,%08x,%08lx) not complete\n",
2523 hwnd
, msg
, wParam
, lParam
);
2525 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2526 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2529 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2534 /***********************************************************************
2535 * SendMessageCallback32A
2536 * FIXME: It's like PostMessage. The callback gets called when the message
2537 * is processed. We have to modify the message processing for a exact
2540 BOOL WINAPI
SendMessageCallbackA(
2541 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2542 FARPROC lpResultCallBack
,DWORD dwData
)
2544 FIXME_(msg
)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2545 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2546 if ( hWnd
== HWND_BROADCAST
)
2547 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2548 FIXME_(msg
)("Broadcast: Callback will not be called!\n");
2551 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));
2554 /***********************************************************************
2555 * SendMessageCallback32W
2556 * FIXME: It's like PostMessage. The callback gets called when the message
2557 * is processed. We have to modify the message processing for a exact
2560 BOOL WINAPI
SendMessageCallbackW(
2561 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2562 FARPROC lpResultCallBack
,DWORD dwData
)
2564 FIXME_(msg
)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2565 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2566 if ( hWnd
== HWND_BROADCAST
)
2567 { PostMessageW( hWnd
, Msg
, wParam
, lParam
);
2568 FIXME_(msg
)("Broadcast: Callback will not be called!\n");
2571 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));