2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(key
)
33 DECLARE_DEBUG_CHANNEL(msg
)
34 DECLARE_DEBUG_CHANNEL(sendmsg
)
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
40 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
41 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
43 extern HQUEUE16 hCursorQueue
; /* queue.c */
45 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
47 static UINT doubleClickSpeed
= 452;
49 /***********************************************************************
52 static BOOL
MSG_CheckFilter(DWORD uMsg
, DWORD first
, DWORD last
)
55 return (uMsg
>= first
&& uMsg
<= last
);
59 /***********************************************************************
60 * MSG_SendParentNotify
62 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
63 * the window has the WS_EX_NOPARENTNOTIFY style.
65 static void MSG_SendParentNotify(WND
* wndPtr
, WORD event
, WORD idChild
, LPARAM lValue
)
67 #define lppt ((LPPOINT16)&lValue)
69 /* pt has to be in the client coordinates of the parent window */
70 WND
*tmpWnd
= WIN_LockWndPtr(wndPtr
);
72 MapWindowPoints16( 0, tmpWnd
->hwndSelf
, lppt
, 1 );
75 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
77 WIN_ReleaseWndPtr(tmpWnd
);
80 lppt
->x
+= tmpWnd
->rectClient
.left
;
81 lppt
->y
+= tmpWnd
->rectClient
.top
;
82 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
83 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
84 MAKEWPARAM( event
, idChild
), lValue
);
91 /***********************************************************************
92 * MSG_TranslateMouseMsg
94 * Translate an mouse hardware event into a real mouse message.
98 * SYSQ_MSG_ABANDON - abandon the peek message loop
99 * SYSQ_MSG_CONTINUE - leave the message in the queue and
100 * continue with the translation loop
101 * SYSQ_MSG_ACCEPT - proceed to process the translated message
103 static DWORD
MSG_TranslateMouseMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
104 MSG
*msg
, BOOL remove
, WND
* pWndScope
,
105 INT16
*pHitTest
, POINT16
*pScreen_pt
, BOOL
*pmouseClick
)
107 static DWORD dblclk_time_limit
= 0;
108 static UINT16 clk_message
= 0;
109 static HWND16 clk_hwnd
= 0;
110 static POINT16 clk_pos
= { 0, 0 };
115 UINT message
= msg
->message
;
116 POINT16 screen_pt
, pt
;
117 HANDLE16 hQ
= GetFastQueue16();
118 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQ
);
119 BOOL mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
120 (message
== WM_RBUTTONDOWN
) ||
121 (message
== WM_MBUTTONDOWN
))?1:0;
124 /* Find the window to dispatch this mouse message to */
126 CONV_POINT32TO16( &msg
->pt
, &pt
);
130 /* If no capture HWND, find window which contains the mouse position.
131 * Also find the position of the cursor hot spot (hittest) */
134 ht
= hittest
= WINPOS_WindowFromPoint( pWndScope
, pt
, &pWnd
);
135 if( !pWnd
) pWnd
= WIN_GetDesktop();
136 else WIN_LockWndPtr(pWnd
);
137 hWnd
= pWnd
->hwndSelf
;
141 ht
= hittest
= HTCLIENT
;
142 pWnd
= WIN_FindWndPtr(hWnd
);
144 ht
= PERQDATA_GetCaptureInfo( queue
->pQData
);
147 /* Save hittest for return */
150 /* stop if not the right queue */
152 if (pWnd
->hmemTaskQ
!= hQ
)
154 /* Not for the current task */
155 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
156 /* Wake up the other task */
157 QUEUE_Unlock( queue
);
158 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
159 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
161 QUEUE_Unlock( queue
);
162 retvalue
= SYSQ_MSG_ABANDON
;
166 /* check if hWnd is within hWndScope */
168 if( hTopWnd
&& hWnd
!= hTopWnd
)
169 if( !IsChild(hTopWnd
, hWnd
) )
171 QUEUE_Unlock( queue
);
172 retvalue
= SYSQ_MSG_CONTINUE
;
176 /* Was it a mouse click message */
179 /* translate double clicks -
180 * note that ...MOUSEMOVEs can slip in between
181 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
183 if(GetClassLongA(hWnd
, GCL_STYLE
) & CS_DBLCLKS
|| ht
!= HTCLIENT
)
185 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
186 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
187 (abs(msg
->pt
.x
- clk_pos
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
188 (abs(msg
->pt
.y
- clk_pos
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
190 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
191 mouseClick
++; /* == 2 */
195 /* save mouse position */
199 if (hittest
!= HTCLIENT
)
201 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
202 msg
->wParam
= hittest
;
205 ScreenToClient16( hWnd
, &pt
);
207 /* check message filter */
209 if (!MSG_CheckFilter(message
, first
, last
))
212 retvalue
= SYSQ_MSG_CONTINUE
;
216 /* Update global hCursorQueue */
217 hCursorQueue
= queue
->self
;
219 /* Update static double click conditions */
220 if( remove
&& mouseClick
)
222 if( mouseClick
== 1 )
225 dblclk_time_limit
= msg
->time
;
226 clk_message
= msg
->message
;
230 /* got double click - zero them out */
231 dblclk_time_limit
= clk_hwnd
= 0;
236 /* Update message params */
238 msg
->message
= message
;
239 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
240 retvalue
= SYSQ_MSG_ACCEPT
;
243 WIN_ReleaseWndPtr(pWnd
);
245 /* Return mouseclick flag */
246 *pmouseClick
= mouseClick
;
252 /***********************************************************************
253 * MSG_ProcessMouseMsg
255 * Processes a translated mouse hardware event.
256 * The passed in msg structure should contain the updated hWnd,
257 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
261 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
262 * HIWORD contains hit test code). Continue translating..
263 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
264 * MSG_PeekHardwareMsg should return TRUE.
266 static DWORD
MSG_ProcessMouseMsg( MSG
*msg
, BOOL remove
, INT16 hittest
,
267 POINT16 screen_pt
, BOOL mouseClick
)
270 HWND hWnd
= msg
->hwnd
;
271 INT16 sendSC
= (GetCapture() == 0);
272 UINT message
= msg
->message
;
276 pWnd
= WIN_FindWndPtr(hWnd
);
280 if (HOOK_IsHooked( WH_MOUSE
))
283 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
286 hook
->pt
= screen_pt
;
288 hook
->wHitTestCode
= hittest
;
289 hook
->dwExtraInfo
= 0;
290 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
291 message
, (LPARAM
)SEGPTR_GET(hook
) );
296 retvalue
= MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
302 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
304 else if( remove
&& mouseClick
)
306 HWND hwndTop
= WIN_GetTopParent( hWnd
);
310 /* Send the WM_PARENTNOTIFY,
311 * note that even for double/nonclient clicks
312 * notification message is still WM_L/M/RBUTTONDOWN.
315 MSG_SendParentNotify( pWnd
, msg
->message
& 0xffff, 0, MAKELPARAM(screen_pt
.x
, screen_pt
.y
) );
317 /* Activate the window if needed */
319 if (hWnd
!= GetActiveWindow() && hWnd
!= GetDesktopWindow())
321 LONG ret
= SendMessageA( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
322 MAKELONG( hittest
, message
) );
324 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
327 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
328 && hwndTop
!= GetForegroundWindow() )
330 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
335 } else sendSC
= (remove
&& sendSC
);
337 /* Send the WM_SETCURSOR message */
341 UINT uSCMessage
= message
;
343 /* Windows sends the normal mouse message as the message parameter
344 in the WM_SETCURSOR message even if it's non-client mouse message */
346 if (uSCMessage
>= WM_NCMOUSEFIRST
&& uSCMessage
<= WM_NCMOUSELAST
)
347 uSCMessage
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
348 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
,
349 MAKELONG( hittest
, uSCMessage
));
353 retvalue
= MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
357 retvalue
= SYSQ_MSG_ACCEPT
;
359 WIN_ReleaseWndPtr(pWnd
);
365 /***********************************************************************
366 * MSG_TranslateKbdMsg
368 * Translate an keyboard hardware event into a real message.
370 static DWORD
MSG_TranslateKbdMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
371 MSG
*msg
, BOOL remove
)
373 WORD message
= msg
->message
;
374 HWND hWnd
= GetFocus();
377 /* Should check Ctrl-Esc and PrintScreen here */
381 /* Send the message to the active window instead, */
382 /* translating messages to their WM_SYS equivalent */
384 hWnd
= GetActiveWindow();
386 if( message
< WM_SYSKEYDOWN
)
387 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
389 pWnd
= WIN_FindWndPtr( hWnd
);
390 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetFastQueue16()))
392 /* Not for the current task */
393 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
394 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
395 QUEUE_Unlock( queue
);
397 /* Wake up the other task */
398 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
399 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
400 QUEUE_Unlock( queue
);
401 WIN_ReleaseWndPtr(pWnd
);
402 return SYSQ_MSG_ABANDON
;
404 WIN_ReleaseWndPtr(pWnd
);
406 if (hTopWnd
&& hWnd
!= hTopWnd
)
407 if (!IsChild(hTopWnd
, hWnd
)) return SYSQ_MSG_CONTINUE
;
408 if (!MSG_CheckFilter(message
, first
, last
)) return SYSQ_MSG_CONTINUE
;
411 msg
->message
= message
;
413 return SYSQ_MSG_ACCEPT
;
417 /***********************************************************************
420 * Processes a translated keyboard message
422 static DWORD
MSG_ProcessKbdMsg( MSG
*msg
, BOOL remove
)
424 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
425 LOWORD (msg
->wParam
), msg
->lParam
)
426 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
430 /***********************************************************************
431 * MSG_JournalRecordMsg
433 * Build an EVENTMSG structure and call JOURNALRECORD hook
435 static void MSG_JournalRecordMsg( MSG
*msg
)
437 EVENTMSG
*event
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
439 event
->message
= msg
->message
;
440 event
->time
= msg
->time
;
441 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
443 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
444 event
->paramH
= msg
->lParam
& 0x7FFF;
445 if (HIWORD(msg
->lParam
) & 0x0100)
446 event
->paramH
|= 0x8000; /* special_key - bit */
447 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
449 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
451 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
452 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
453 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
454 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
456 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
457 (msg
->message
<= WM_NCMOUSELAST
))
459 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
460 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
461 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
462 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
465 HeapFree(SystemHeap
, 0, event
);
468 /***********************************************************************
469 * MSG_JournalPlayBackMsg
471 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
473 static int MSG_JournalPlayBackMsg(void)
476 long wtime
,lParam
,wParam
;
477 WORD keyDown
,i
,result
=0;
479 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
481 tmpMsg
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
482 if (!tmpMsg
) return result
;
484 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
486 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
490 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
492 wParam
=tmpMsg
->paramL
& 0xFF;
493 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
494 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
496 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
497 if (InputKeyStateTable
[i
] & 0x80)
500 lParam
|= 0x40000000;
501 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
503 else /* WM_KEYUP, WM_SYSKEYUP */
505 lParam
|= 0xC0000000;
506 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
508 if (InputKeyStateTable
[VK_MENU
] & 0x80)
509 lParam
|= 0x20000000;
510 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
511 lParam
|= 0x01000000;
512 hardware_event( tmpMsg
->message
& 0xffff, LOWORD(wParam
), lParam
,
513 0, 0, tmpMsg
->time
, 0 );
517 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
519 switch (tmpMsg
->message
)
522 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
524 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
526 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
528 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
530 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
532 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
534 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
535 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
536 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
537 SetCursorPos(tmpMsg
->paramL
,tmpMsg
->paramH
);
538 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
540 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
541 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
542 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
543 hardware_event( tmpMsg
->message
& 0xffff, LOWORD (wParam
), lParam
,
544 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
547 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
553 if( tmpMsg
->message
== WM_QUEUESYNC
)
554 if (HOOK_IsHooked( WH_CBT
))
555 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
557 result
= QS_MOUSE
| QS_KEY
; /* ? */
559 HeapFree(SystemHeap
, 0, tmpMsg
);
564 /***********************************************************************
565 * MSG_PeekHardwareMsg
567 * Peek for a hardware message matching the hwnd and message filters.
569 static BOOL
MSG_PeekHardwareMsg( MSG
*msg
, HWND hwnd
, DWORD first
, DWORD last
,
572 /* FIXME: should deal with MSG32 instead of MSG16 */
574 DWORD status
= SYSQ_MSG_ACCEPT
;
575 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
576 enum { MOUSE_MSG
= 0, KEYBOARD_MSG
, HARDWARE_MSG
} msgType
;
577 QMSG
*nextqmsg
, *qmsg
= 0;
580 /* FIXME: there has to be a better way to do this */
583 EnterCriticalSection(&sysMsgQueue
->cSection
);
585 /* Loop through the Q and translate the message we wish to process
586 * while we own the lock. Based on the translation status (abandon/cont/accept)
587 * we then process the message accordingly
590 for ( qmsg
= sysMsgQueue
->firstMsg
; qmsg
; qmsg
= nextqmsg
)
598 nextqmsg
= qmsg
->nextMsg
;
600 /* Translate message */
602 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
604 HWND hWndScope
= (HWND
)qmsg
->extraInfo
;
605 WND
*tmpWnd
= (Options
.managed
&& IsWindow(hWndScope
) )
606 ? WIN_FindWndPtr(hWndScope
) : WIN_GetDesktop();
608 status
= MSG_TranslateMouseMsg(hwnd
, first
, last
, msg
, remove
, tmpWnd
,
609 &hittest
, &screen_pt
, &mouseClick
);
612 WIN_ReleaseWndPtr(tmpWnd
);
615 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
617 status
= MSG_TranslateKbdMsg(hwnd
, first
, last
, msg
, remove
);
618 msgType
= KEYBOARD_MSG
;
620 else /* Non-standard hardware event */
622 HARDWAREHOOKSTRUCT16
*hook
;
623 msgType
= HARDWARE_MSG
;
624 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
627 hook
->hWnd
= msg
->hwnd
;
628 hook
->wMessage
= msg
->message
& 0xffff;
629 hook
->wParam
= LOWORD (msg
->wParam
);
630 hook
->lParam
= msg
->lParam
;
631 ret
= HOOK_CallHooks16( WH_HARDWARE
,
632 remove
? HC_ACTION
: HC_NOREMOVE
,
633 0, (LPARAM
)SEGPTR_GET(hook
) );
637 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
640 status
= SYSQ_MSG_ACCEPT
;
645 switch (LOWORD(status
))
647 case SYSQ_MSG_ACCEPT
:
649 /* Remove the message from the system msg Q while it is still locked,
650 * before accepting it */
653 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
654 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
656 /* Now actually process the message, after we unlock the system msg Q.
657 * We should not hold on to the crst since SendMessage calls during processing
658 * will potentially cause callbacks to PeekMessage from the application.
659 * If we're holding the crst and QUEUE_WaitBits is called with a
660 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
661 * message is being posted to the Q.
663 LeaveCriticalSection(&sysMsgQueue
->cSection
);
664 if( msgType
== KEYBOARD_MSG
)
665 status
= MSG_ProcessKbdMsg( msg
, remove
);
666 else if ( msgType
== MOUSE_MSG
)
667 status
= MSG_ProcessMouseMsg( msg
, remove
, hittest
, screen_pt
, mouseClick
);
669 /* Reclaim the sys msg Q crst */
670 EnterCriticalSection(&sysMsgQueue
->cSection
);
672 /* Pass the translated message to the user if it was accepted */
673 if (status
== SYSQ_MSG_ACCEPT
)
676 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
680 if (HOOK_IsHooked( WH_CBT
))
682 if( msgType
== KEYBOARD_MSG
)
683 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
684 LOWORD (msg
->wParam
), msg
->lParam
);
685 else if ( msgType
== MOUSE_MSG
)
687 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
690 CONV_POINT32TO16( &msg
->pt
,&hook
->pt
);
691 hook
->hwnd
= msg
->hwnd
;
692 hook
->wHitTestCode
= HIWORD(status
);
693 hook
->dwExtraInfo
= 0;
694 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
& 0xffff,
695 (LPARAM
)SEGPTR_GET(hook
) );
701 /* If the message was removed earlier set up nextqmsg so that we start
702 * at the top of the queue again. We need to do this since our next pointer
703 * could be invalid due to us unlocking the system message Q to process the message.
704 * If not removed just refresh nextqmsg to point to the next msg.
707 nextqmsg
= sysMsgQueue
->firstMsg
;
709 nextqmsg
= qmsg
->nextMsg
;
713 case SYSQ_MSG_CONTINUE
:
716 case SYSQ_MSG_ABANDON
:
726 LeaveCriticalSection(&sysMsgQueue
->cSection
);
731 /**********************************************************************
732 * SetDoubleClickTime16 (USER.20)
734 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
736 SetDoubleClickTime( interval
);
740 /**********************************************************************
741 * SetDoubleClickTime32 (USER32.480)
743 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
745 doubleClickSpeed
= interval
? interval
: 500;
750 /**********************************************************************
751 * GetDoubleClickTime16 (USER.21)
753 UINT16 WINAPI
GetDoubleClickTime16(void)
755 return doubleClickSpeed
;
759 /**********************************************************************
760 * GetDoubleClickTime32 (USER32.239)
762 UINT WINAPI
GetDoubleClickTime(void)
764 return doubleClickSpeed
;
768 /***********************************************************************
769 * MSG_SendMessageInterThread
771 * Implementation of an inter-task SendMessage.
773 * 0 if error or timeout
776 static LRESULT
MSG_SendMessageInterThread( HQUEUE16 hDestQueue
,
778 WPARAM wParam
, LPARAM lParam
,
779 DWORD timeout
, WORD flags
,
782 MESSAGEQUEUE
*queue
, *destQ
;
789 if (IsTaskLocked16() || !IsWindow(hwnd
))
792 /* create a SMSG structure to hold SendMessage() parameters */
793 if (! (smsg
= (SMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(SMSG
) )) )
795 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
797 if (!(destQ
= (MESSAGEQUEUE
*)QUEUE_Lock( hDestQueue
)))
799 QUEUE_Unlock( queue
);
803 TRACE_(sendmsg
)("SM: %s [%04x] (%04x -> %04x)\n",
804 SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
806 /* fill up SMSG structure */
809 smsg
->wParam
= wParam
;
810 smsg
->lParam
= lParam
;
813 smsg
->hSrcQueue
= GetFastQueue16();
814 smsg
->hDstQueue
= hDestQueue
;
817 /* add smsg struct in the processing SM list of the source queue */
818 QUEUE_AddSMSG(queue
, SM_PROCESSING_LIST
, smsg
);
820 /* add smsg struct in the pending list of the destination queue */
821 if (QUEUE_AddSMSG(destQ
, SM_PENDING_LIST
, smsg
) == FALSE
)
824 iWndsLocks
= WIN_SuspendWndsLock();
826 /* force destination task to run next, if 16 bit threads */
827 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ
->teb
) )
828 DirectedYield16( destQ
->teb
->htask16
);
830 /* wait for the result, note that 16-bit apps almost always get out of
831 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
836 * The sequence is crucial to avoid deadlock situations:
837 * - first, we clear the QS_SMRESULT bit
838 * - then, we check the SMSG_HAVE_RESULT bit
839 * - only if this isn't set, we enter the wait state.
841 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
842 * we are guaranteed that -should we now clear the QS_SMRESULT that
843 * was signalled already by the receiver- we will not start waiting.
846 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
849 *pRes
= smsg
->lResult
;
850 TRACE_(sendmsg
)("smResult = %08x\n", (unsigned)*pRes
);
854 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
856 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
859 if( QUEUE_WaitBits( QS_SMRESULT
, timeout
) == 0 )
861 /* return with timeout */
867 WIN_RestoreWndsLock(iWndsLocks
);
869 /* remove the smsg from the processingg list of the source queue */
870 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
872 /* Note: the destination thread is in charge of removing the smsg from
875 /* In the case of an early reply (or a timeout), sender thread will
876 released the smsg structure if the receiver thread is done
877 (SMSG_RECEIVED set). If the receiver thread isn't done,
878 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
879 responsability to released smsg */
880 EnterCriticalSection( &queue
->cSection
);
882 if (smsg
->flags
& SMSG_RECEIVED
)
883 HeapFree(SystemHeap
, 0, smsg
);
885 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
887 LeaveCriticalSection( &queue
->cSection
);
890 QUEUE_Unlock( queue
);
891 QUEUE_Unlock( destQ
);
893 TRACE_(sendmsg
)("done!\n");
898 /***********************************************************************
899 * ReplyMessage16 (USER.115)
901 void WINAPI
ReplyMessage16( LRESULT result
)
903 ReplyMessage( result
);
906 /***********************************************************************
907 * ReplyMessage (USER.115)
909 BOOL WINAPI
ReplyMessage( LRESULT result
)
911 MESSAGEQUEUE
*senderQ
= 0;
912 MESSAGEQUEUE
*queue
= 0;
916 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
919 TRACE_(sendmsg
)("ReplyMessage, queue %04x\n", queue
->self
);
922 if ( !(smsg
= queue
->smWaiting
)
923 || !(senderQ
= QUEUE_Lock( smsg
->hSrcQueue
)) )
924 goto ReplyMessageEnd
;
926 if ( !(smsg
->flags
& SMSG_ALREADY_REPLIED
) )
928 /* This is the first reply, so pass result to sender */
930 TRACE_(sendmsg
)("\trpm: smResult = %08lx\n", (long) result
);
932 EnterCriticalSection(&senderQ
->cSection
);
934 smsg
->lResult
= result
;
935 smsg
->flags
|= SMSG_ALREADY_REPLIED
;
937 /* check if it's an early reply (called by the application) or
938 a regular reply (called by ReceiveMessage) */
939 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
940 smsg
->flags
|= SMSG_EARLY_REPLY
;
942 smsg
->flags
|= SMSG_HAVE_RESULT
;
944 LeaveCriticalSection(&senderQ
->cSection
);
946 /* tell the sending task that its reply is ready */
947 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
949 /* switch directly to sending task (16 bit thread only) */
950 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ
->teb
) )
951 DirectedYield16( senderQ
->teb
->htask16
);
956 if (smsg
->flags
& SMSG_SENDING_REPLY
)
958 /* remove msg from the waiting list, since this is the last
960 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
962 EnterCriticalSection(&senderQ
->cSection
);
964 /* tell the sender we're all done with smsg structure */
965 smsg
->flags
|= SMSG_RECEIVED
;
967 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
968 receiver to clean up smsg, it could only happens when there is
969 an early reply or a timeout */
970 if ( smsg
->flags
& SMSG_RECEIVER_CLEANS
)
972 TRACE_(sendmsg
)("Receiver cleans up!\n" );
973 HeapFree( SystemHeap
, 0, smsg
);
976 LeaveCriticalSection(&senderQ
->cSection
);
981 QUEUE_Unlock( senderQ
);
983 QUEUE_Unlock( queue
);
988 /***********************************************************************
991 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
992 WORD flags
, BOOL peek
)
995 MESSAGEQUEUE
*msgQueue
;
1000 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
1003 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
1004 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
1005 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
1006 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
1007 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
1008 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
1010 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
1012 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
1014 /* Never yield on Win32 threads */
1015 if (!THREAD_IsWin16(NtCurrentTeb())) flags
|= PM_NOYIELD
;
1017 iWndsLocks
= WIN_SuspendWndsLock();
1023 hQueue
= GetFastQueue16();
1024 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1027 WIN_RestoreWndsLock(iWndsLocks
);
1030 msgQueue
->changeBits
= 0;
1032 /* First handle a message put by SendMessage() */
1034 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1035 QUEUE_ReceiveMessage( msgQueue
);
1037 /* Now handle a WM_QUIT message */
1039 if (msgQueue
->wPostQMsg
&&
1040 (!first
|| WM_QUIT
>= first
) &&
1041 (!last
|| WM_QUIT
<= last
) )
1044 msg
->message
= WM_QUIT
;
1045 msg
->wParam
= msgQueue
->wExitCode
;
1047 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
1051 /* Now find a normal message */
1053 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
1054 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
1058 msgQueue
->GetMessageTimeVal
= msg
->time
;
1059 CONV_POINT32TO16(&msg
->pt
, &pt16
);
1060 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
1061 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
1063 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
1067 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
1069 /* Now find a hardware event */
1071 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
1072 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
1075 msgQueue
->GetMessageTimeVal
= msg
->time
;
1076 CONV_POINT32TO16(&msg
->pt
, &pt16
);
1077 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
1078 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
1082 /* Check again for SendMessage */
1084 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1085 QUEUE_ReceiveMessage( msgQueue
);
1087 /* Now find a WM_PAINT message */
1089 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
1092 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
1093 msg
->message
= WM_PAINT
;
1097 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
1099 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
1100 (HICON
) GetClassLongA(wndPtr
->hwndSelf
, GCL_HICON
) )
1102 msg
->message
= WM_PAINTICON
;
1106 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
1108 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
1110 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
1111 QUEUE_DecPaintCount( hQueue
);
1113 WIN_ReleaseWndPtr(wndPtr
);
1116 WIN_ReleaseWndPtr(wndPtr
);
1120 /* Check for timer messages, but yield first */
1122 if (!(flags
& PM_NOYIELD
))
1125 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1126 QUEUE_ReceiveMessage( msgQueue
);
1128 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
1130 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
1135 if (!(flags
& PM_NOYIELD
)) UserYield16();
1137 QUEUE_Unlock( msgQueue
);
1138 WIN_RestoreWndsLock(iWndsLocks
);
1141 msgQueue
->wakeMask
= mask
;
1142 QUEUE_WaitBits( mask
, INFINITE
);
1143 QUEUE_Unlock( msgQueue
);
1146 WIN_RestoreWndsLock(iWndsLocks
);
1148 /* instead of unlocking queue for every break condition, all break
1149 condition will fall here */
1150 QUEUE_Unlock( msgQueue
);
1152 /* We got a message */
1153 if (flags
& PM_REMOVE
)
1155 WORD message
= msg
->message
;
1157 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
1159 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
1165 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
1166 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
1173 return (msg
->message
!= WM_QUIT
);
1176 /***********************************************************************
1177 * MSG_InternalGetMessage
1179 * GetMessage() function for internal use. Behave like GetMessage(),
1180 * but also call message filters and optionally send WM_ENTERIDLE messages.
1181 * 'hwnd' must be the handle of the dialog or menu window.
1182 * 'code' is the message filter value (MSGF_??? codes).
1184 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
1185 WPARAM code
, WORD flags
, BOOL sendIdle
)
1191 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1193 /* No message present -> send ENTERIDLE and wait */
1194 if (IsWindow(hwndOwner
))
1195 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1196 code
, (LPARAM
)hwnd
);
1197 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1200 else /* Always wait for a message */
1201 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1203 /* Call message filters */
1205 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1207 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1212 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1214 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1217 HeapFree( SystemHeap
, 0, pmsg
);
1220 /* Message filtered -> remove it from the queue */
1221 /* if it's still there. */
1222 if (!(flags
& PM_REMOVE
))
1223 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1229 return (msg
->message
!= WM_QUIT
);
1234 /***********************************************************************
1235 * PeekMessage16 (USER.109)
1237 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1238 UINT16 last
, UINT16 flags
)
1242 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1243 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1247 /***********************************************************************
1248 * WIN16_PeekMessage32 (USER.819)
1250 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1251 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1253 if (wHaveParamHigh
== FALSE
)
1255 lpmsg16_32
->wParamHigh
= 0;
1256 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1263 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1264 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1265 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1266 lpmsg16_32
->msg
.message
= msg32
.message
;
1267 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1268 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1269 lpmsg16_32
->msg
.time
= msg32
.time
;
1270 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1271 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1272 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1278 /***********************************************************************
1281 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1282 UINT min
,UINT max
,UINT wRemoveMsg
)
1284 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1287 /***********************************************************************
1288 * PeekMessageW Check queue for messages
1290 * Checks for a message in the thread's queue, filtered as for
1291 * GetMessage(). Returns immediately whether a message is available
1294 * Whether a retrieved message is removed from the queue is set by the
1295 * _wRemoveMsg_ flags, which should be one of the following values:
1297 * PM_NOREMOVE Do not remove the message from the queue.
1299 * PM_REMOVE Remove the message from the queue.
1301 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1302 * request that the system not yield control during PeekMessage();
1303 * however applications may not rely on scheduling behavior.
1307 * Nonzero if a message is available and is retrieved, zero otherwise.
1314 BOOL WINAPI
PeekMessageW(
1315 LPMSG lpmsg
, /* buffer to receive message */
1316 HWND hwnd
, /* restrict to messages for hwnd */
1317 UINT min
, /* minimum message to receive */
1318 UINT max
, /* maximum message to receive */
1319 UINT wRemoveMsg
/* removal flags */
1322 BOOL bRet
= PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1324 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg
->message
));
1328 /***********************************************************************
1329 * GetMessage16 (USER.108)
1331 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1334 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1337 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1339 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1341 TRACE_(msg
)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1342 hwnd
, first
, last
);
1347 /***********************************************************************
1348 * WIN16_GetMessage32 (USER.820)
1350 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1351 UINT16 last
, BOOL16 wHaveParamHigh
)
1353 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1355 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1358 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1359 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1360 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1367 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1368 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1369 lpmsg16_32
->msg
.message
= msg32
.message
;
1370 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1371 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1372 lpmsg16_32
->msg
.time
= msg32
.time
;
1373 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1374 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1375 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1380 /***********************************************************************
1381 * GetMessage32A (USER32.270)
1383 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1385 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1387 TRACE_(msg
)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1390 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1392 return (lpmsg
->message
!= WM_QUIT
);
1395 /***********************************************************************
1396 * GetMessage32W (USER32.274) Retrieve next message
1398 * GetMessage retrieves the next event from the calling thread's
1399 * queue and deposits it in *lpmsg.
1401 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1402 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1403 * all application messages are retrieved.
1405 * _min_ and _max_ specify the range of messages of interest. If
1406 * min==max==0, no filtering is performed. Useful examples are
1407 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1408 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1410 * WM_PAINT messages are not removed from the queue; they remain until
1411 * processed. Other messages are removed from the queue.
1415 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1422 BOOL WINAPI
GetMessageW(
1423 MSG
* lpmsg
, /* buffer to receive message */
1424 HWND hwnd
, /* restrict to messages for hwnd */
1425 UINT min
, /* minimum message to receive */
1426 UINT max
/* maximum message to receive */
1429 BOOL bRet
= GetMessageA(lpmsg
, hwnd
, min
, max
);
1431 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg
->message
));
1437 /***********************************************************************
1438 * PostMessage16 (USER.110)
1440 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1443 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1447 /***********************************************************************
1448 * PostMessage32A (USER32.419)
1450 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1458 msg
.message
= message
;
1459 msg
.wParam
= wParam
;
1460 msg
.lParam
= lParam
;
1461 msg
.time
= GetTickCount();
1465 if (hwnd
== HWND_BROADCAST
)
1467 WND
*pDesktop
= WIN_GetDesktop();
1468 TRACE_(msg
)("HWND_BROADCAST !\n");
1470 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1472 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1474 TRACE_(msg
)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1475 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1476 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1479 WIN_ReleaseDesktop();
1480 TRACE_(msg
)("End of HWND_BROADCAST !\n");
1484 wndPtr
= WIN_FindWndPtr( hwnd
);
1485 if (!wndPtr
|| !wndPtr
->hmemTaskQ
)
1491 retvalue
= QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1493 WIN_ReleaseWndPtr(wndPtr
);
1498 /***********************************************************************
1499 * PostMessage32W (USER32.420)
1501 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1504 FIXME_(sendmsg
)("(%s) unicode<->ascii\n", SPY_GetMsgName(message
));
1505 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1509 /***********************************************************************
1510 * PostAppMessage16 (USER.116)
1512 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1517 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1519 msg
.message
= message
;
1520 msg
.wParam
= wParam
;
1521 msg
.lParam
= lParam
;
1522 msg
.time
= GetTickCount();
1526 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1529 /************************************************************************
1530 * MSG_CallWndProcHook32
1532 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1536 cwp
.lParam
= pmsg
->lParam
;
1537 cwp
.wParam
= pmsg
->wParam
;
1538 cwp
.message
= pmsg
->message
;
1539 cwp
.hwnd
= pmsg
->hwnd
;
1541 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1542 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1544 pmsg
->lParam
= cwp
.lParam
;
1545 pmsg
->wParam
= cwp
.wParam
;
1546 pmsg
->message
= cwp
.message
;
1547 pmsg
->hwnd
= cwp
.hwnd
;
1551 /***********************************************************************
1554 * return values: 0 if timeout occurs
1557 static LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1558 LPARAM lParam
, DWORD timeout
, WORD flags
,
1562 WND
**list
, **ppWnd
;
1567 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1571 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1573 WIN_ReleaseDesktop();
1576 WIN_ReleaseDesktop();
1578 TRACE_(msg
)("HWND_BROADCAST !\n");
1579 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1581 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1582 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1583 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1585 TRACE_(msg
)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1586 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1587 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1588 timeout
, flags
, pRes
);
1591 WIN_ReleaseWndPtr(wndPtr
);
1592 WIN_ReleaseWinArray(list
);
1593 TRACE_(msg
)("End of HWND_BROADCAST !\n");
1597 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1599 if (flags
& SMSG_UNICODE
)
1600 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1601 else if (flags
& SMSG_WIN32
)
1602 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1607 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1609 pmsg
->hwnd
= hwnd
& 0xffff;
1610 pmsg
->message
= msg
& 0xffff;
1611 pmsg
->wParam
= wParam
& 0xffff;
1612 pmsg
->lParam
= lParam
;
1613 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1614 (LPARAM
)SEGPTR_GET(pmsg
) );
1616 msg
= pmsg
->message
;
1617 wParam
= pmsg
->wParam
;
1618 lParam
= pmsg
->lParam
;
1619 SEGPTR_FREE( pmsg
);
1624 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1626 WARN_(msg
)("invalid hwnd %04x\n", hwnd
);
1629 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1631 ret
= 0; /* Don't send anything if the task is dying */
1634 if (flags
& SMSG_WIN32
)
1635 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1637 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1639 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1640 ret
= MSG_SendMessageInterThread( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1641 wParam
, lParam
, timeout
, flags
, pRes
);
1644 /* Call the right CallWindowProc flavor */
1645 if (flags
& SMSG_UNICODE
)
1646 *pRes
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1647 hwnd
, msg
, wParam
, lParam
);
1648 else if (flags
& SMSG_WIN32
)
1649 *pRes
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1650 hwnd
, msg
, wParam
, lParam
);
1652 *pRes
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1653 (HWND16
) hwnd
, (UINT16
) msg
,
1654 (WPARAM16
) wParam
, lParam
);
1657 if (flags
& SMSG_WIN32
)
1658 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1660 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1662 WIN_ReleaseWndPtr(wndPtr
);
1667 /***********************************************************************
1668 * SendMessage16 (USER.111)
1670 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1674 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, 0, &res
);
1680 /**********************************************************************
1681 * PostThreadMessage32A (USER32.422)
1685 * Thread-local message queues are not supported.
1688 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1689 WPARAM wParam
, LPARAM lParam
)
1694 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1698 msg
.message
= message
;
1699 msg
.wParam
= wParam
;
1700 msg
.lParam
= lParam
;
1701 msg
.time
= GetTickCount();
1705 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1708 /**********************************************************************
1709 * PostThreadMessage32W (USER32.423)
1713 * Thread-local message queues are not supported.
1716 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1717 WPARAM wParam
, LPARAM lParam
)
1719 FIXME_(sendmsg
)("(%s) unicode<->ascii\n",SPY_GetMsgName(message
));
1720 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1723 /***********************************************************************
1724 * SendMessage32A (USER32.454)
1726 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1731 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1738 /***********************************************************************
1739 * SendMessage32W (USER32.459) Send Window Message
1741 * Sends a message to the window procedure of the specified window.
1742 * SendMessage() will not return until the called window procedure
1743 * either returns or calls ReplyMessage().
1745 * Use PostMessage() to send message and return immediately. A window
1746 * procedure may use InSendMessage() to detect
1747 * SendMessage()-originated messages.
1749 * Applications which communicate via HWND_BROADCAST may use
1750 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1751 * with other applications.
1757 LRESULT WINAPI
SendMessageW(
1758 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1759 the message will be sent to all top-level windows. */
1761 UINT msg
, /* message */
1762 WPARAM wParam
, /* message parameter */
1763 LPARAM lParam
/* additional message parameter */
1767 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1768 SMSG_WIN32
| SMSG_UNICODE
, &res
);
1774 /***********************************************************************
1775 * SendMessageTimeout16 (not a WINAPI)
1777 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1778 LPARAM lParam
, UINT16 flags
,
1779 UINT16 timeout
, LPWORD resultp
)
1784 /* FIXME: need support for SMTO_BLOCK */
1786 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, 0, &msgRet
);
1787 *resultp
= (WORD
) msgRet
;
1792 /***********************************************************************
1793 * SendMessageTimeoutA (USER32.457)
1795 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1796 LPARAM lParam
, UINT flags
,
1797 UINT timeout
, LPDWORD resultp
)
1802 /* FIXME: need support for SMTO_BLOCK */
1804 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, SMSG_WIN32
,
1807 *resultp
= (DWORD
) msgRet
;
1812 /***********************************************************************
1813 * SendMessageTimeoutW (USER32.458)
1815 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1816 LPARAM lParam
, UINT flags
,
1817 UINT timeout
, LPDWORD resultp
)
1822 /* FIXME: need support for SMTO_BLOCK */
1824 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
,
1825 SMSG_WIN32
| SMSG_UNICODE
, &msgRet
);
1827 *resultp
= (DWORD
) msgRet
;
1832 /***********************************************************************
1833 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1835 * WaitMessage() suspends a thread until events appear in the thread's
1840 * Is supposed to return BOOL under Win32.
1842 * Thread-local message queues are not supported.
1849 void WINAPI
WaitMessage( void )
1851 QUEUE_WaitBits( QS_ALLINPUT
, INFINITE
);
1854 /***********************************************************************
1855 * MsgWaitForMultipleObjects (USER32.400)
1857 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1858 BOOL fWaitAll
, DWORD dwMilliseconds
,
1862 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1865 HQUEUE16 hQueue
= GetFastQueue16();
1866 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1867 if (!msgQueue
) return WAIT_FAILED
;
1869 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1871 SetLastError( ERROR_INVALID_PARAMETER
);
1872 QUEUE_Unlock( msgQueue
);
1876 msgQueue
->changeBits
= 0;
1877 msgQueue
->wakeMask
= dwWakeMask
;
1879 if (THREAD_IsWin16(NtCurrentTeb()))
1882 * This is a temporary solution to a big problem.
1883 * You see, the main thread of all Win32 programs is created as a 16 bit
1884 * task. This means that if you want on an event using Win32 synchronization
1885 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1886 * This implements a semi-busy loop that checks the handles to wait on and
1887 * also the message queue. When either one is ready, the wait function returns.
1889 * This will all go away when the real Win32 threads are implemented for all
1890 * the threads of an applications. Including the main thread.
1892 DWORD curTime
= GetCurrentTime();
1897 * Check the handles in the list.
1899 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1902 * If the handles have been triggered, return.
1904 if (ret
!= WAIT_TIMEOUT
)
1908 * Then, let the 16 bit scheduler do it's thing.
1913 * If a message matching the wait mask has arrived, return.
1915 if (msgQueue
->changeBits
& dwWakeMask
)
1922 * And continue doing this until we hit the timeout.
1924 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1928 /* Add the thread event to the handle list */
1929 for (i
= 0; i
< nCount
; i
++)
1930 handles
[i
] = pHandles
[i
];
1931 handles
[nCount
] = msgQueue
->hEvent
;
1933 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1936 QUEUE_Unlock( msgQueue
);
1950 static const struct accent_char accent_chars
[] =
1952 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1953 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1954 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1955 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1956 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1957 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1958 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1959 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1960 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1961 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1962 {',', 'C', '\307'}, {',', 'c', '\347'},
1963 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1964 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1965 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1966 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1967 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1968 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1969 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1970 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1971 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1972 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1973 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1974 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1975 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1976 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1977 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1978 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1979 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1980 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1981 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1982 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1983 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1984 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1985 {'s', 's', '\337'}, {'"', 'y', '\377'},
1986 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1987 /* iso-8859-2 uses this */
1988 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1989 {'<', 'S', '\251'}, {'<', 's', '\271'},
1990 {'<', 'T', '\253'}, {'<', 't', '\273'},
1991 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1992 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1993 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1994 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1995 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1996 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1997 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1998 {';', 'E', '\312'}, {';', 'e', '\332'},
1999 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2000 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2001 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2002 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2003 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2004 /* collision whith S, from iso-8859-9 !!! */
2005 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2006 {',', 'T', '\336'}, {',', 't', '\376'},
2007 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2008 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2009 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2010 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2011 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2012 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2013 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2014 /* iso-8859-3 uses this */
2015 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2016 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2017 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2018 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2019 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2020 {'>', 'S', '\336'}, {'>', 's', '\376'},
2021 /* collision whith G( from iso-8859-9 !!! */
2022 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2023 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2024 /* collision whith I. from iso-8859-3 !!! */
2025 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2026 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2027 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2028 /* iso-8859-4 uses this */
2029 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2030 {',', 'L', '\246'}, {',', 'l', '\266'},
2031 {',', 'G', '\253'}, {',', 'g', '\273'},
2032 {',', 'N', '\321'}, {',', 'n', '\361'},
2033 {',', 'K', '\323'}, {',', 'k', '\363'},
2034 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2035 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2036 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2037 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2038 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2039 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2040 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2041 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2042 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2043 {';', 'U', '\331'}, {';', 'u', '\371'},
2044 /* iso-8859-9 uses this */
2045 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2046 * whith the same letters on other iso-8859-x (that is they are on
2047 * different places :-( ), if you use turkish uncomment these and
2048 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2049 * FIXME: should be dynamic according to chosen language
2050 * if/when Wine has turkish support.
2052 /* collision whith G( from iso-8859-3 !!! */
2053 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2054 /* collision whith S, from iso-8859-2 !!! */
2055 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2056 /* collision whith I. from iso-8859-3 !!! */
2057 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2061 /***********************************************************************
2062 * MSG_DoTranslateMessage
2064 * Implementation of TranslateMessage.
2066 * TranslateMessage translates virtual-key messages into character-messages,
2068 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2069 * ditto replacing WM_* with WM_SYS*
2070 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2071 * by the keyboard driver.
2073 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
2074 WPARAM wParam
, LPARAM lParam
)
2076 static int dead_char
;
2079 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
2080 TRACE_(msg
)("(%s, %04X, %08lX)\n",
2081 SPY_GetMsgName(message
), wParam
, lParam
);
2082 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
2083 TRACE_(key
)("(%s, %04X, %08lX)\n",
2084 SPY_GetMsgName(message
), wParam
, lParam
);
2086 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
2088 TRACE_(key
)("Translating key %04X, scancode %04X\n",
2089 wParam
, HIWORD(lParam
) );
2091 /* FIXME : should handle ToAscii yielding 2 */
2092 switch (ToAscii(wParam
, HIWORD(lParam
),
2093 QueueKeyStateTable
,(LPWORD
)wp
, 0))
2096 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2097 /* Should dead chars handling go in ToAscii ? */
2102 if (wp
[0] == ' ') wp
[0] = dead_char
;
2103 if (dead_char
== 0xa2) dead_char
= '(';
2104 else if (dead_char
== 0xa8) dead_char
= '"';
2105 else if (dead_char
== 0xb2) dead_char
= ';';
2106 else if (dead_char
== 0xb4) dead_char
= '\'';
2107 else if (dead_char
== 0xb7) dead_char
= '<';
2108 else if (dead_char
== 0xb8) dead_char
= ',';
2109 else if (dead_char
== 0xff) dead_char
= '.';
2110 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2111 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2112 (accent_chars
[i
].ac_char
== wp
[0]))
2114 wp
[0] = accent_chars
[i
].ac_result
;
2119 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2120 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2124 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2126 TRACE_(key
)("-1 -> PostMessage(%s)\n",
2127 SPY_GetMsgName(message
));
2128 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2135 /***********************************************************************
2136 * TranslateMessage16 (USER.113)
2138 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2140 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2141 msg
->wParam
, msg
->lParam
);
2145 /***********************************************************************
2146 * WIN16_TranslateMessage32 (USER.821)
2148 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2153 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2155 wParam
= (WPARAM
)msg
->msg
.wParam
;
2157 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2158 wParam
, msg
->msg
.lParam
);
2161 /***********************************************************************
2162 * TranslateMessage32 (USER32.556)
2164 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2166 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2167 msg
->wParam
, msg
->lParam
);
2171 /***********************************************************************
2172 * DispatchMessage16 (USER.114)
2174 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2180 /* Process timer messages */
2181 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2185 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2186 msg
->message
, msg
->wParam
, GetTickCount() );
2190 if (!msg
->hwnd
) return 0;
2191 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2192 if (!wndPtr
->winproc
)
2197 painting
= (msg
->message
== WM_PAINT
);
2198 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2200 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2201 msg
->wParam
, msg
->lParam
);
2202 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2203 msg
->hwnd
, msg
->message
,
2204 msg
->wParam
, msg
->lParam
);
2205 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
2207 WIN_ReleaseWndPtr(wndPtr
);
2208 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2209 if (painting
&& wndPtr
&&
2210 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2212 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2214 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2215 /* Validate the update region to avoid infinite WM_PAINT loop */
2216 ValidateRect( msg
->hwnd
, NULL
);
2219 WIN_ReleaseWndPtr(wndPtr
);
2224 /***********************************************************************
2225 * WIN16_DispatchMessage32 (USER.822)
2227 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2229 if (wHaveParamHigh
== FALSE
)
2230 return DispatchMessage16(&(lpmsg16_32
->msg
));
2235 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2236 msg
.message
= lpmsg16_32
->msg
.message
;
2237 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2238 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2239 msg
.time
= lpmsg16_32
->msg
.time
;
2240 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2241 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2242 return DispatchMessageA(&msg
);
2246 /***********************************************************************
2247 * DispatchMessage32A (USER32.141)
2249 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2255 /* Process timer messages */
2256 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2260 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2261 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2262 msg
->message
, msg
->wParam
, GetTickCount() );
2266 if (!msg
->hwnd
) return 0;
2267 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2268 if (!wndPtr
->winproc
)
2273 painting
= (msg
->message
== WM_PAINT
);
2274 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2275 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2277 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2278 msg
->wParam
, msg
->lParam
);
2279 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2280 msg
->hwnd
, msg
->message
,
2281 msg
->wParam
, msg
->lParam
);
2282 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2284 WIN_ReleaseWndPtr(wndPtr
);
2285 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2287 if (painting
&& wndPtr
&&
2288 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2290 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2292 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2293 /* Validate the update region to avoid infinite WM_PAINT loop */
2294 ValidateRect( msg
->hwnd
, NULL
);
2297 WIN_ReleaseWndPtr(wndPtr
);
2302 /***********************************************************************
2303 * DispatchMessage32W (USER32.142) Process Message
2305 * Process the message specified in the structure *_msg_.
2307 * If the lpMsg parameter points to a WM_TIMER message and the
2308 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2309 * points to the function that is called instead of the window
2312 * The message must be valid.
2316 * DispatchMessage() returns the result of the window procedure invoked.
2323 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2329 /* Process timer messages */
2330 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2334 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2335 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2336 msg
->message
, msg
->wParam
, GetTickCount() );
2340 if (!msg
->hwnd
) return 0;
2341 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2342 if (!wndPtr
->winproc
)
2347 painting
= (msg
->message
== WM_PAINT
);
2348 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2349 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2351 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2352 msg
->wParam
, msg
->lParam
);
2353 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2354 msg
->hwnd
, msg
->message
,
2355 msg
->wParam
, msg
->lParam
);
2356 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2358 WIN_ReleaseWndPtr(wndPtr
);
2359 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2361 if (painting
&& wndPtr
&&
2362 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2364 ERR_(msg
)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2366 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2367 /* Validate the update region to avoid infinite WM_PAINT loop */
2368 ValidateRect( msg
->hwnd
, NULL
);
2371 WIN_ReleaseWndPtr(wndPtr
);
2376 /***********************************************************************
2377 * RegisterWindowMessage16 (USER.118)
2379 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2381 TRACE_(msg
)("%08lx\n", (DWORD
)str
);
2382 return GlobalAddAtom16( str
);
2386 /***********************************************************************
2387 * RegisterWindowMessage32A (USER32.437)
2389 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2391 TRACE_(msg
)("%s\n", str
);
2392 return GlobalAddAtomA( str
);
2396 /***********************************************************************
2397 * RegisterWindowMessage32W (USER32.438)
2399 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2401 TRACE_(msg
)("%p\n", str
);
2402 return GlobalAddAtomW( str
);
2406 /***********************************************************************
2407 * GetTickCount (USER.13) (KERNEL32.299) System Time
2408 * Returns the number of milliseconds, modulo 2^32, since the start
2409 * of the current session.
2415 DWORD WINAPI
GetTickCount(void)
2418 gettimeofday( &t
, NULL
);
2419 /* make extremely compatible: granularity is 25 msec */
2420 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2424 /***********************************************************************
2425 * GetCurrentTime16 (USER.15)
2427 * (effectively identical to GetTickCount)
2429 DWORD WINAPI
GetCurrentTime16(void)
2431 return GetTickCount();
2435 /***********************************************************************
2436 * InSendMessage16 (USER.192)
2438 BOOL16 WINAPI
InSendMessage16(void)
2440 return InSendMessage();
2444 /***********************************************************************
2445 * InSendMessage32 (USER32.320)
2447 BOOL WINAPI
InSendMessage(void)
2449 MESSAGEQUEUE
*queue
;
2452 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2454 ret
= (BOOL
)queue
->smWaiting
;
2456 QUEUE_Unlock( queue
);
2460 /***********************************************************************
2461 * BroadcastSystemMessage (USER32.12)
2463 LONG WINAPI
BroadcastSystemMessage(
2464 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2467 FIXME_(sendmsg
)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2468 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2473 /***********************************************************************
2474 * SendNotifyMessageA (USER32.460)
2476 * The message sended with PostMessage has to be put in the queue
2477 * with a higher priority as the other "Posted" messages.
2478 * QUEUE_AddMsg has to be modifyed.
2480 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2482 FIXME_(msg
)("(%04x,%08x,%08x,%08lx) not complete\n",
2483 hwnd
, msg
, wParam
, lParam
);
2485 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2486 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2489 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2494 /***********************************************************************
2495 * SendNotifyMessageW (USER32.461)
2497 * The message sended with PostMessage has to be put in the queue
2498 * with a higher priority as the other "Posted" messages.
2499 * QUEUE_AddMsg has to be modifyed.
2501 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2503 FIXME_(msg
)("(%04x,%08x,%08x,%08lx) not complete\n",
2504 hwnd
, msg
, wParam
, lParam
);
2506 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2507 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2510 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2515 /***********************************************************************
2516 * SendMessageCallback32A
2517 * FIXME: It's like PostMessage. The callback gets called when the message
2518 * is processed. We have to modify the message processing for a exact
2521 BOOL WINAPI
SendMessageCallbackA(
2522 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2523 FARPROC lpResultCallBack
,DWORD dwData
)
2525 FIXME_(msg
)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2526 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2527 if ( hWnd
== HWND_BROADCAST
)
2528 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2529 FIXME_(msg
)("Broadcast: Callback will not be called!\n");
2532 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));
2535 /***********************************************************************
2536 * SendMessageCallback32W
2537 * FIXME: It's like PostMessage. The callback gets called when the message
2538 * is processed. We have to modify the message processing for a exact
2541 BOOL WINAPI
SendMessageCallbackW(
2542 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2543 FARPROC lpResultCallBack
,DWORD dwData
)
2545 FIXME_(msg
)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2546 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2547 if ( hWnd
== HWND_BROADCAST
)
2548 { PostMessageW( hWnd
, Msg
, wParam
, lParam
);
2549 FIXME_(msg
)("Broadcast: Callback will not be called!\n");
2552 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));