2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
16 #include "sysmetrics.h"
27 /* #define DEBUG_MSG */
30 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
31 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
33 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
34 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
36 extern MESSAGEQUEUE
*pCursorQueue
; /* queue.c */
37 extern MESSAGEQUEUE
*pActiveQueue
;
39 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
41 static UINT32 doubleClickSpeed
= 452;
42 static INT32 debugSMRL
= 0; /* intertask SendMessage() recursion level */
44 /***********************************************************************
47 BOOL32
MSG_CheckFilter(WORD uMsg
, DWORD filter
)
50 return (uMsg
>= LOWORD(filter
) && uMsg
<= HIWORD(filter
));
54 /***********************************************************************
55 * MSG_TranslateMouseMsg
57 * Translate an mouse hardware event into a real mouse message.
58 * Return value indicates whether the translated message must be passed
59 * to the user, left in the queue, or skipped entirely (in this case
60 * HIWORD contains hit test code).
62 static DWORD
MSG_TranslateMouseMsg( HWND16 hWndScope
, DWORD filter
,
63 MSG16
*msg
, BOOL32 remove
)
65 static DWORD dblclk_time_limit
= 0;
66 static UINT16 clk_message
= 0;
67 static HWND16 clk_hwnd
= 0;
68 static POINT16 clk_pos
= { 0, 0 };
72 INT16 ht
, hittest
, sendSC
= 0;
73 UINT16 message
= msg
->message
;
74 POINT16 screen_pt
, pt
;
75 HANDLE16 hQ
= GetTaskQueue(0);
76 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16(hQ
);
77 BOOL32 eatMsg
= FALSE
;
78 BOOL32 mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
79 (message
== WM_RBUTTONDOWN
) ||
80 (message
== WM_MBUTTONDOWN
))?1:0;
85 ht
= hittest
= HTCLIENT
;
86 hWnd
= GetCapture16();
90 ht
= hittest
= WINPOS_WindowFromPoint( WIN_GetDesktop(), msg
->pt
, &pWnd
);
91 if( !pWnd
) pWnd
= WIN_GetDesktop();
92 hWnd
= pWnd
->hwndSelf
;
96 pWnd
= WIN_FindWndPtr(hWnd
);
97 ht
= EVENT_GetCaptureInfo();
100 /* stop if not the right queue */
102 if (pWnd
->hmemTaskQ
!= hQ
)
104 /* Not for the current task */
105 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
106 /* Wake up the other task */
107 queue
= (MESSAGEQUEUE
*)GlobalLock16( pWnd
->hmemTaskQ
);
108 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
109 return SYSQ_MSG_ABANDON
;
112 /* check if hWnd is within hWndScope */
114 if( hWndScope
&& hWnd
!= hWndScope
)
115 if( !IsChild16(hWndScope
, hWnd
) ) return SYSQ_MSG_CONTINUE
;
119 /* translate double clicks -
120 * note that ...MOUSEMOVEs can slip in between
121 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
123 if( pWnd
->class->style
& CS_DBLCLKS
|| ht
!= HTCLIENT
)
125 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
126 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
127 (abs(msg
->pt
.x
- clk_pos
.x
) < SYSMETRICS_CXDOUBLECLK
/2) &&
128 (abs(msg
->pt
.y
- clk_pos
.y
) < SYSMETRICS_CYDOUBLECLK
/2))
130 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
131 mouseClick
++; /* == 2 */
135 screen_pt
= pt
= msg
->pt
;
137 if (hittest
!= HTCLIENT
)
139 message
+= ((INT16
)WM_NCMOUSEMOVE
- WM_MOUSEMOVE
);
140 msg
->wParam
= hittest
;
142 else ScreenToClient16( hWnd
, &pt
);
144 /* check message filter */
146 if (!MSG_CheckFilter(message
, filter
)) return SYSQ_MSG_CONTINUE
;
148 pCursorQueue
= queue
;
152 if (HOOK_IsHooked( WH_MOUSE
))
154 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
157 hook
->pt
= screen_pt
;
159 hook
->wHitTestCode
= hittest
;
160 hook
->dwExtraInfo
= 0;
161 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
162 message
, (LPARAM
)SEGPTR_GET(hook
) );
165 if( ret
) return MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
168 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
170 else if( remove
&& mouseClick
)
172 HWND32 hwndTop
= WIN_GetTopParent( hWnd
);
174 if( mouseClick
== 1 )
177 dblclk_time_limit
= msg
->time
;
178 clk_message
= msg
->message
;
182 /* got double click - zero them out */
183 dblclk_time_limit
= clk_hwnd
= 0;
187 /* Send the WM_PARENTNOTIFY,
188 * note that even for double/nonclient clicks
189 * notification message is still WM_L/M/RBUTTONDOWN.
192 WIN_SendParentNotify( hWnd
, msg
->message
, 0,
193 MAKELPARAM( screen_pt
.x
, screen_pt
.y
) );
195 /* Activate the window if needed */
197 if (hWnd
!= GetActiveWindow16() && hWnd
!= GetDesktopWindow16())
199 LONG ret
= SendMessage16( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
200 MAKELONG( hittest
, message
) );
202 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
205 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
206 && hwndTop
!= GetActiveWindow16() )
207 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
211 } else sendSC
= (remove
&& sendSC
);
213 /* Send the WM_SETCURSOR message */
216 SendMessage16( hWnd
, WM_SETCURSOR
, (WPARAM16
)hWnd
,
217 MAKELONG( hittest
, message
));
218 if (eatMsg
) return MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
221 msg
->message
= message
;
222 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
223 return SYSQ_MSG_ACCEPT
;
227 /***********************************************************************
228 * MSG_TranslateKbdMsg
230 * Translate an keyboard hardware event into a real message.
232 static DWORD
MSG_TranslateKbdMsg( HWND16 hWndScope
, DWORD filter
,
233 MSG16
*msg
, BOOL32 remove
)
235 WORD message
= msg
->message
;
236 HWND16 hWnd
= GetFocus16();
239 /* Should check Ctrl-Esc and PrintScreen here */
243 /* Send the message to the active window instead, */
244 /* translating messages to their WM_SYS equivalent */
246 hWnd
= GetActiveWindow16();
248 if( message
< WM_SYSKEYDOWN
)
249 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
251 pWnd
= WIN_FindWndPtr( hWnd
);
252 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetTaskQueue(0)))
254 /* Not for the current task */
255 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( GetTaskQueue(0) );
256 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
257 /* Wake up the other task */
258 queue
= (MESSAGEQUEUE
*)GlobalLock16( pWnd
->hmemTaskQ
);
259 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
260 return SYSQ_MSG_ABANDON
;
263 if (hWndScope
&& hWnd
!= hWndScope
)
264 if (!IsChild16(hWndScope
, hWnd
)) return SYSQ_MSG_CONTINUE
;
265 if (!MSG_CheckFilter(message
, filter
)) return SYSQ_MSG_CONTINUE
;
268 msg
->message
= message
;
270 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
271 msg
->wParam
, msg
->lParam
)
272 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
276 /***********************************************************************
277 * MSG_JournalRecordMsg
279 * Build an EVENTMSG structure and call JOURNALRECORD hook
281 static void MSG_JournalRecordMsg( MSG16
*msg
)
283 EVENTMSG16
*event
= SEGPTR_NEW(EVENTMSG16
);
285 event
->message
= msg
->message
;
286 event
->time
= msg
->time
;
287 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
289 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
290 event
->paramH
= msg
->lParam
& 0x7FFF;
291 if (HIWORD(msg
->lParam
) & 0x0100)
292 event
->paramH
|= 0x8000; /* special_key - bit */
293 HOOK_CallHooks16( WH_JOURNALRECORD
, HC_ACTION
, 0,
294 (LPARAM
)SEGPTR_GET(event
) );
296 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
298 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
299 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
300 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
301 HOOK_CallHooks16( WH_JOURNALRECORD
, HC_ACTION
, 0,
302 (LPARAM
)SEGPTR_GET(event
) );
304 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
305 (msg
->message
<= WM_NCMOUSELAST
))
307 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
308 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
309 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
310 HOOK_CallHooks16( WH_JOURNALRECORD
, HC_ACTION
, 0,
311 (LPARAM
)SEGPTR_GET(event
) );
316 /***********************************************************************
317 * MSG_JournalPlayBackMsg
319 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
321 static int MSG_JournalPlayBackMsg(void)
325 WORD keyDown
,i
,wParam
,result
=0;
327 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
329 tmpMsg
= SEGPTR_NEW(EVENTMSG16
);
330 wtime
=HOOK_CallHooks16( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
331 (LPARAM
)SEGPTR_GET(tmpMsg
));
332 /* dprintf_msg(stddeb,"Playback wait time =%ld\n",wtime); */
336 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
338 wParam
=tmpMsg
->paramL
& 0xFF;
339 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
340 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
342 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
343 if (InputKeyStateTable
[i
] & 0x80)
346 lParam
|= 0x40000000;
347 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
349 else /* WM_KEYUP, WM_SYSKEYUP */
351 lParam
|= 0xC0000000;
352 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
354 if (InputKeyStateTable
[VK_MENU
] & 0x80)
355 lParam
|= 0x20000000;
356 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
357 lParam
|= 0x01000000;
358 hardware_event( tmpMsg
->message
, wParam
, lParam
,0, 0, tmpMsg
->time
, 0 );
362 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
364 switch (tmpMsg
->message
)
366 case WM_LBUTTONDOWN
:MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=1;break;
367 case WM_LBUTTONUP
: MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=0;break;
368 case WM_MBUTTONDOWN
:MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=1;break;
369 case WM_MBUTTONUP
: MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=0;break;
370 case WM_RBUTTONDOWN
:MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=1;break;
371 case WM_RBUTTONUP
: MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=0;break;
373 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] << 8;
374 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] << 8;
375 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] << 8;
376 SetCursorPos32(tmpMsg
->paramL
,tmpMsg
->paramH
);
377 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
379 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
380 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
381 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
382 hardware_event( tmpMsg
->message
, wParam
, lParam
,
383 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
386 HOOK_CallHooks16( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
387 (LPARAM
)SEGPTR_GET(tmpMsg
));
391 if( tmpMsg
->message
== WM_QUEUESYNC
)
392 if (HOOK_IsHooked( WH_CBT
))
393 HOOK_CallHooks16( WH_CBT
, HCBT_QS
, 0, 0L);
395 result
= QS_MOUSE
| QS_KEY
; /* ? */
402 /***********************************************************************
403 * MSG_PeekHardwareMsg
405 * Peek for a hardware message matching the hwnd and message filters.
407 static BOOL32
MSG_PeekHardwareMsg( MSG16
*msg
, HWND16 hwnd
, DWORD filter
, BOOL32 remove
)
409 DWORD status
= SYSQ_MSG_ACCEPT
;
410 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
411 int i
, kbd_msg
, pos
= sysMsgQueue
->nextMessage
;
413 /* If the queue is empty, attempt to fill it */
414 if (!sysMsgQueue
->msgCount
&& XPending(display
))
415 EVENT_WaitXEvent( FALSE
, FALSE
);
417 for (i
= kbd_msg
= 0; i
< sysMsgQueue
->msgCount
; i
++, pos
++)
419 if (pos
>= sysMsgQueue
->queueSize
) pos
= 0;
420 *msg
= sysMsgQueue
->messages
[pos
].msg
;
422 /* Translate message */
424 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
426 status
= MSG_TranslateMouseMsg(hwnd
, filter
, msg
, remove
);
429 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
431 status
= MSG_TranslateKbdMsg(hwnd
, filter
, msg
, remove
);
434 else /* Non-standard hardware event */
436 HARDWAREHOOKSTRUCT16
*hook
;
437 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
440 hook
->hWnd
= msg
->hwnd
;
441 hook
->wMessage
= msg
->message
;
442 hook
->wParam
= msg
->wParam
;
443 hook
->lParam
= msg
->lParam
;
444 ret
= HOOK_CallHooks16( WH_HARDWARE
,
445 remove
? HC_ACTION
: HC_NOREMOVE
,
446 0, (LPARAM
)SEGPTR_GET(hook
) );
450 QUEUE_RemoveMsg( sysMsgQueue
, pos
);
453 status
= SYSQ_MSG_ACCEPT
;
457 switch (LOWORD(status
))
459 case SYSQ_MSG_ACCEPT
:
463 if (HOOK_IsHooked( WH_CBT
))
465 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
466 msg
->wParam
, msg
->lParam
);
469 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
473 hook
->hwnd
= msg
->hwnd
;
474 hook
->wHitTestCode
= HIWORD(status
);
475 hook
->dwExtraInfo
= 0;
476 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
,
477 (LPARAM
)SEGPTR_GET(hook
) );
483 QUEUE_RemoveMsg( sysMsgQueue
, pos
);
486 case SYSQ_MSG_CONTINUE
:
489 case SYSQ_MSG_ABANDON
:
495 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
496 QUEUE_RemoveMsg( sysMsgQueue
, pos
);
504 /**********************************************************************
505 * SetDoubleClickTime16 (USER.20)
507 void SetDoubleClickTime16( UINT16 interval
)
509 SetDoubleClickTime32( interval
);
513 /**********************************************************************
514 * SetDoubleClickTime32 (USER32.479)
516 BOOL32
SetDoubleClickTime32( UINT32 interval
)
518 doubleClickSpeed
= interval
? interval
: 500;
523 /**********************************************************************
524 * GetDoubleClickTime16 (USER.21)
526 UINT16
GetDoubleClickTime16(void)
528 return doubleClickSpeed
;
532 /**********************************************************************
533 * GetDoubleClickTime32 (USER32.238)
535 UINT32
GetDoubleClickTime32(void)
537 return doubleClickSpeed
;
541 /***********************************************************************
544 * Implementation of an inter-task SendMessage.
546 static LRESULT
MSG_SendMessage( HQUEUE16 hDestQueue
, HWND16 hwnd
, UINT msg
,
547 WPARAM16 wParam
, LPARAM lParam
)
549 INT32 prevSMRL
= debugSMRL
;
550 QSMCTRL qCtrl
= { 0, 1};
551 MESSAGEQUEUE
*queue
, *destQ
;
553 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetTaskQueue(0) ))) return 0;
554 if (!(destQ
= (MESSAGEQUEUE
*)GlobalLock16( hDestQueue
))) return 0;
556 if (IsTaskLocked() || !IsWindow(hwnd
)) return 0;
559 dprintf_sendmsg(stddeb
,"%*sSM: %s [%04x] (%04x -> %04x)\n",
560 prevSMRL
, "", SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
562 if( !(queue
->wakeBits
& QS_SMPARAMSFREE
) )
564 dprintf_sendmsg(stddeb
,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
565 queue
->changeBits
&= ~QS_SMPARAMSFREE
;
566 QUEUE_WaitBits( QS_SMPARAMSFREE
);
573 queue
->wParam
= wParam
;
574 queue
->lParam
= lParam
;
575 queue
->hPrevSendingTask
= destQ
->hSendingTask
;
576 destQ
->hSendingTask
= GetTaskQueue(0);
578 queue
->wakeBits
&= ~QS_SMPARAMSFREE
;
580 dprintf_sendmsg(stddeb
,"%*ssm: smResultInit = %08x\n", prevSMRL
, "", (unsigned)&qCtrl
);
582 queue
->smResultInit
= &qCtrl
;
584 QUEUE_SetWakeBit( destQ
, QS_SENDMESSAGE
);
586 /* perform task switch and wait for the result */
588 while( qCtrl
.bPending
)
590 if (!(queue
->wakeBits
& QS_SMRESULT
))
592 queue
->changeBits
&= ~QS_SMRESULT
;
593 DirectedYield( destQ
->hTask
);
594 QUEUE_WaitBits( QS_SMRESULT
);
595 dprintf_sendmsg(stddeb
,"\tsm: have result!\n");
599 dprintf_sendmsg(stddeb
,"%*ssm: smResult = %08x\n", prevSMRL
, "", (unsigned)queue
->smResult
);
601 if (queue
->smResult
) { /* FIXME, smResult should always be set */
602 queue
->smResult
->lResult
= queue
->SendMessageReturn
;
603 queue
->smResult
->bPending
= FALSE
;
605 queue
->wakeBits
&= ~QS_SMRESULT
;
607 if( queue
->smResult
!= &qCtrl
)
608 dprintf_msg(stddeb
,"%*ssm: weird scenes inside the goldmine!\n", prevSMRL
, "");
610 queue
->smResultInit
= NULL
;
612 dprintf_sendmsg(stddeb
,"%*sSM: [%04x] returning %08lx\n", prevSMRL
, "", msg
, qCtrl
.lResult
);
615 return qCtrl
.lResult
;
619 /***********************************************************************
620 * ReplyMessage (USER.115)
622 void ReplyMessage( LRESULT result
)
624 MESSAGEQUEUE
*senderQ
;
627 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetTaskQueue(0) ))) return;
629 dprintf_msg(stddeb
,"ReplyMessage, queue %04x\n", queue
->self
);
631 while( (senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->InSendMessageHandle
)))
633 dprintf_msg(stddeb
,"\trpm: replying to %04x (%04x -> %04x)\n",
634 queue
->msg
, queue
->self
, senderQ
->self
);
636 if( queue
->wakeBits
& QS_SENDMESSAGE
)
638 QUEUE_ReceiveMessage( queue
);
639 continue; /* ReceiveMessage() already called us */
642 if(!(senderQ
->wakeBits
& QS_SMRESULT
) ) break;
645 if( !senderQ
) { dprintf_msg(stddeb
,"\trpm: done\n"); return; }
647 senderQ
->SendMessageReturn
= result
;
648 dprintf_msg(stddeb
,"\trpm: smResult = %08x, result = %08lx\n",
649 (unsigned)queue
->smResultCurrent
, result
);
651 senderQ
->smResult
= queue
->smResultCurrent
;
652 queue
->InSendMessageHandle
= 0;
654 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
655 DirectedYield( queue
->hSendingTask
);
659 /***********************************************************************
662 static BOOL
MSG_PeekMessage( LPMSG16 msg
, HWND16 hwnd
, WORD first
, WORD last
,
663 WORD flags
, BOOL peek
)
666 MESSAGEQUEUE
*msgQueue
;
670 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
671 DDE_GetRemoteMessage();
672 #endif /* CONFIG_IPC */
674 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
677 /* MSWord gets stuck if we do not check for nonclient mouse messages */
679 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
680 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
681 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
682 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
683 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
684 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
686 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
688 if (IsTaskLocked()) flags
|= PM_NOYIELD
;
692 hQueue
= GetTaskQueue(0);
693 msgQueue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
694 if (!msgQueue
) return FALSE
;
695 msgQueue
->changeBits
= 0;
697 /* First handle a message put by SendMessage() */
699 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
700 QUEUE_ReceiveMessage( msgQueue
);
702 /* Now handle a WM_QUIT message
704 * FIXME: PostQuitMessage() should post WM_QUIT and
705 * set QS_POSTMESSAGE wakebit instead of this.
708 if (msgQueue
->wPostQMsg
&&
709 (!first
|| WM_QUIT
>= first
) &&
710 (!last
|| WM_QUIT
<= last
) )
713 msg
->message
= WM_QUIT
;
714 msg
->wParam
= msgQueue
->wExitCode
;
716 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
720 /* Now find a normal message */
722 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
723 ((pos
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != -1))
725 QMSG
*qmsg
= &msgQueue
->messages
[pos
];
727 msgQueue
->GetMessageTimeVal
= msg
->time
;
728 msgQueue
->GetMessagePosVal
= *(DWORD
*)&msg
->pt
;
729 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
731 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, pos
);
735 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
737 /* Now find a hardware event */
739 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
740 MSG_PeekHardwareMsg( msg
, hwnd
, MAKELONG(first
,last
), flags
& PM_REMOVE
))
743 msgQueue
->GetMessageTimeVal
= msg
->time
;
744 msgQueue
->GetMessagePosVal
= *(DWORD
*)&msg
->pt
;
745 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
749 /* Check again for SendMessage */
751 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
752 QUEUE_ReceiveMessage( msgQueue
);
754 /* Now find a WM_PAINT message */
756 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
759 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
760 msg
->message
= WM_PAINT
;
764 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
766 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
767 wndPtr
->class->hIcon
)
769 msg
->message
= WM_PAINTICON
;
773 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
775 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
777 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
778 QUEUE_DecPaintCount( hQueue
);
785 /* Check for timer messages, but yield first */
787 if (!(flags
& PM_NOYIELD
))
790 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
791 QUEUE_ReceiveMessage( msgQueue
);
793 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
795 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
800 if (!(flags
& PM_NOYIELD
)) UserYield();
803 msgQueue
->wakeMask
= mask
;
804 QUEUE_WaitBits( mask
);
807 /* We got a message */
808 if (flags
& PM_REMOVE
)
810 WORD message
= msg
->message
;
812 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
814 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
820 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
821 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
823 if (peek
) return TRUE
;
824 else return (msg
->message
!= WM_QUIT
);
828 /***********************************************************************
829 * MSG_InternalGetMessage
831 * GetMessage() function for internal use. Behave like GetMessage(),
832 * but also call message filters and optionally send WM_ENTERIDLE messages.
833 * 'hwnd' must be the handle of the dialog or menu window.
834 * 'code' is the message filter value (MSGF_??? codes).
836 BOOL32
MSG_InternalGetMessage( MSG16
*msg
, HWND32 hwnd
, HWND32 hwndOwner
,
837 WPARAM32 code
, WORD flags
, BOOL32 sendIdle
)
843 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
845 /* No message present -> send ENTERIDLE and wait */
846 if (IsWindow(hwndOwner
))
847 SendMessage16( hwndOwner
, WM_ENTERIDLE
,
848 code
, (LPARAM
)hwnd
);
849 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
852 else /* Always wait for a message */
853 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
855 /* Call message filters */
857 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
859 MSG16
*pmsg
= SEGPTR_NEW(MSG16
);
864 ret
= ((BOOL16
)HOOK_CallHooks16( WH_SYSMSGFILTER
, code
, 0,
865 (LPARAM
)SEGPTR_GET(pmsg
) ) ||
866 (BOOL16
)HOOK_CallHooks16( WH_MSGFILTER
, code
, 0,
867 (LPARAM
)SEGPTR_GET(pmsg
) ));
871 /* Message filtered -> remove it from the queue */
872 /* if it's still there. */
873 if (!(flags
& PM_REMOVE
))
874 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
880 return (msg
->message
!= WM_QUIT
);
885 /***********************************************************************
886 * PeekMessage16 (USER.109)
888 BOOL16
PeekMessage16( LPMSG16 msg
, HWND16 hwnd
, UINT16 first
,
889 UINT16 last
, UINT16 flags
)
891 return MSG_PeekMessage( msg
, hwnd
, first
, last
, flags
, TRUE
);
895 /***********************************************************************
896 * GetMessage (USER.108)
898 BOOL
GetMessage( SEGPTR msg
, HWND16 hwnd
, UINT first
, UINT last
)
900 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
901 MSG_PeekMessage( lpmsg
,
902 hwnd
, first
, last
, PM_REMOVE
, FALSE
);
904 dprintf_msg(stddeb
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
906 HOOK_CallHooks16( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)msg
);
907 return (lpmsg
->message
!= WM_QUIT
);
911 /***********************************************************************
912 * PostMessage (USER.110)
914 BOOL
PostMessage( HWND16 hwnd
, WORD message
, WORD wParam
, LONG lParam
)
920 msg
.message
= message
;
923 msg
.time
= GetTickCount();
928 if (DDE_PostMessage(&msg
))
930 #endif /* CONFIG_IPC */
932 if (hwnd
== HWND_BROADCAST
)
934 dprintf_msg(stddeb
,"PostMessage // HWND_BROADCAST !\n");
935 for (wndPtr
= WIN_GetDesktop()->child
; wndPtr
; wndPtr
= wndPtr
->next
)
937 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
939 dprintf_msg(stddeb
,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
940 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
941 PostMessage( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
944 dprintf_msg(stddeb
,"PostMessage // End of HWND_BROADCAST !\n");
948 wndPtr
= WIN_FindWndPtr( hwnd
);
949 if (!wndPtr
|| !wndPtr
->hmemTaskQ
) return FALSE
;
951 return QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
954 /***********************************************************************
955 * PostAppMessage16 (USER.116)
957 BOOL16
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
962 if (GetTaskQueue(hTask
) == 0) return FALSE
;
964 msg
.message
= message
;
967 msg
.time
= GetTickCount();
971 return QUEUE_AddMsg( GetTaskQueue(hTask
), &msg
, 0 );
975 /***********************************************************************
976 * SendMessage16 (USER.111)
978 LRESULT
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
985 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
986 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
987 #endif /* CONFIG_IPC */
989 if (hwnd
== HWND_BROADCAST
)
991 dprintf_msg(stddeb
,"SendMessage // HWND_BROADCAST !\n");
992 list
= WIN_BuildWinArray( WIN_GetDesktop() );
993 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
996 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
997 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
999 dprintf_msg(stddeb
,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1000 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1001 SendMessage16( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1004 HeapFree( SystemHeap
, 0, list
);
1005 dprintf_msg(stddeb
,"SendMessage // End of HWND_BROADCAST !\n");
1009 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1013 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1017 pmsg
->wParam
= wParam
;
1018 pmsg
->lParam
= lParam
;
1019 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1020 (LPARAM
)SEGPTR_GET(pmsg
) );
1022 msg
= pmsg
->message
;
1023 wParam
= pmsg
->wParam
;
1024 lParam
= pmsg
->lParam
;
1025 SEGPTR_FREE( pmsg
);
1029 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1031 fprintf( stderr
, "SendMessage16: invalid hwnd %04x\n", hwnd
);
1034 if (QUEUE_IsDoomedQueue(wndPtr
->hmemTaskQ
))
1035 return 0; /* Don't send anything if the task is dying */
1036 if (wndPtr
->hmemTaskQ
!= GetTaskQueue(0))
1037 return MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
, wParam
, lParam
);
1039 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1040 ret
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1041 hwnd
, msg
, wParam
, lParam
);
1042 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1046 /************************************************************************
1047 * MSG_CallWndProcHook32
1049 static void MSG_CallWndProcHook32( LPMSG32 pmsg
, BOOL32 bUnicode
)
1053 cwp
.lParam
= pmsg
->lParam
;
1054 cwp
.wParam
= pmsg
->wParam
;
1055 cwp
.message
= pmsg
->message
;
1056 cwp
.hwnd
= pmsg
->hwnd
;
1058 if (bUnicode
) HOOK_CallHooks32W(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1059 else HOOK_CallHooks32A( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1061 pmsg
->lParam
= cwp
.lParam
;
1062 pmsg
->wParam
= cwp
.wParam
;
1063 pmsg
->message
= cwp
.message
;
1064 pmsg
->hwnd
= cwp
.hwnd
;
1067 /***********************************************************************
1068 * SendMessage32A (USER32.453)
1070 LRESULT
SendMessage32A(HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
1073 WND
**list
, **ppWnd
;
1076 if (hwnd
== HWND_BROADCAST
)
1078 list
= WIN_BuildWinArray( WIN_GetDesktop() );
1079 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1082 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1083 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1084 SendMessage32A( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1086 HeapFree( SystemHeap
, 0, list
);
1090 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1091 MSG_CallWndProcHook32( (LPMSG32
)&hwnd
, FALSE
);
1093 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1095 fprintf( stderr
, "SendMessage32A: invalid hwnd %08x\n", hwnd
);
1099 if (QUEUE_IsDoomedQueue(wndPtr
->hmemTaskQ
))
1100 return 0; /* Don't send anything if the task is dying */
1102 if (wndPtr
->hmemTaskQ
!= GetTaskQueue(0))
1104 fprintf( stderr
, "SendMessage32A: intertask message [%04x] not supported\n", msg
);
1108 SPY_EnterMessage( SPY_SENDMESSAGE32
, hwnd
, msg
, wParam
, lParam
);
1109 ret
= CallWindowProc32A( (WNDPROC32
)wndPtr
->winproc
,
1110 hwnd
, msg
, wParam
, lParam
);
1111 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, ret
);
1116 /***********************************************************************
1117 * SendMessage32W (USER32.458)
1119 LRESULT
SendMessage32W(HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
1122 WND
**list
, **ppWnd
;
1125 if (hwnd
== HWND_BROADCAST
)
1127 list
= WIN_BuildWinArray( WIN_GetDesktop() );
1128 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1131 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1132 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1133 SendMessage32W( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1135 HeapFree( SystemHeap
, 0, list
);
1139 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1140 MSG_CallWndProcHook32( (LPMSG32
)&hwnd
, TRUE
);
1142 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1144 fprintf( stderr
, "SendMessage32W: invalid hwnd %08x\n", hwnd
);
1147 if (QUEUE_IsDoomedQueue(wndPtr
->hmemTaskQ
))
1148 return 0; /* Don't send anything if the task is dying */
1149 if (wndPtr
->hmemTaskQ
!= GetTaskQueue(0))
1151 fprintf( stderr
, "SendMessage32W: intertask message not supported\n" );
1155 SPY_EnterMessage( SPY_SENDMESSAGE32
, hwnd
, msg
, wParam
, lParam
);
1156 ret
= CallWindowProc32W( (WNDPROC32
)wndPtr
->winproc
,
1157 hwnd
, msg
, wParam
, lParam
);
1158 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, ret
);
1163 /***********************************************************************
1164 * WaitMessage (USER.112) (USER32.577)
1166 void WaitMessage( void )
1168 QUEUE_WaitBits( QS_ALLINPUT
);
1179 static const struct accent_char accent_chars
[] =
1181 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1182 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1183 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1184 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1185 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1186 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1187 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1188 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1189 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1190 {',', 'C', '\307'}, {',', 'c', '\347'},
1191 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1192 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1193 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1194 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1195 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1196 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1197 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1198 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1199 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1200 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1201 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1202 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1203 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1204 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1205 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1206 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1207 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1208 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1209 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1210 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1211 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1212 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1213 {'s', 's', '\337'}, {'"', 'y', '\377'},
1214 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1218 /***********************************************************************
1219 * MSG_DoTranslateMessage
1221 * Implementation of TranslateMessage.
1223 * TranslateMessage translates virtual-key messages into character-messages,
1225 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1226 * ditto replacing WM_* with WM_SYS*
1227 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1228 * by the keyboard driver.
1230 static BOOL32
MSG_DoTranslateMessage( UINT32 message
, HWND32 hwnd
,
1231 WPARAM32 wParam
, LPARAM lParam
)
1233 static int dead_char
;
1236 if ((debugging_msg
&& message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
1238 && message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
))
1239 fprintf(stddeb
, "TranslateMessage(%s, %04X, %08lX)\n",
1240 SPY_GetMsgName(message
), wParam
, lParam
);
1242 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
1244 dprintf_key( stddeb
, "Translating key %04X, scancode %04X\n",
1245 wParam
, HIWORD(lParam
) );
1247 /* FIXME : should handle ToAscii yielding 2 */
1248 switch (ToAscii32(wParam
, HIWORD(lParam
),
1249 QueueKeyStateTable
,(LPWORD
)wp
, 0))
1252 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1253 /* Should dead chars handling go in ToAscii ? */
1258 if (wp
[0] == ' ') wp
[0] = dead_char
;
1259 if (dead_char
== 0xa8) dead_char
= '"';
1260 else if (dead_char
== 0xb4) dead_char
= '\'';
1261 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
1262 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
1263 (accent_chars
[i
].ac_char
== wp
[0]))
1265 wp
[0] = accent_chars
[i
].ac_result
;
1270 dprintf_key(stddeb
, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
1271 PostMessage( hwnd
, message
, wp
[0], lParam
);
1275 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
1277 dprintf_key( stddeb
, "-1 -> PostMessage(%s)\n",
1278 SPY_GetMsgName(message
));
1279 PostMessage( hwnd
, message
, wp
[0], lParam
);
1286 /***********************************************************************
1287 * TranslateMessage16 (USER.113)
1289 BOOL16
TranslateMessage16( const MSG16
*msg
)
1291 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1292 msg
->wParam
, msg
->lParam
);
1296 /***********************************************************************
1297 * TranslateMessage32 (USER32.555)
1299 BOOL32
TranslateMessage32( const MSG32
*msg
)
1301 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1302 msg
->wParam
, msg
->lParam
);
1306 /***********************************************************************
1307 * DispatchMessage16 (USER.114)
1309 LONG
DispatchMessage16( const MSG16
* msg
)
1315 /* Process timer messages */
1316 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1320 /* HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1321 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
1322 msg
->message
, msg
->wParam
, GetTickCount() );
1326 if (!msg
->hwnd
) return 0;
1327 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1328 if (!wndPtr
->winproc
) return 0;
1329 painting
= (msg
->message
== WM_PAINT
);
1330 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1331 /* HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1333 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
1334 msg
->wParam
, msg
->lParam
);
1335 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1336 msg
->hwnd
, msg
->message
,
1337 msg
->wParam
, msg
->lParam
);
1338 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
1340 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
1341 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
1343 fprintf(stderr
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1345 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1346 /* Validate the update region to avoid infinite WM_PAINT loop */
1347 ValidateRect32( msg
->hwnd
, NULL
);
1353 /***********************************************************************
1354 * DispatchMessage32A (USER32.140)
1356 LONG
DispatchMessage32A( const MSG32
* msg
)
1362 /* Process timer messages */
1363 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1367 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1368 return CallWindowProc32A( (WNDPROC32
)msg
->lParam
, msg
->hwnd
,
1369 msg
->message
, msg
->wParam
, GetTickCount() );
1373 if (!msg
->hwnd
) return 0;
1374 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1375 if (!wndPtr
->winproc
) return 0;
1376 painting
= (msg
->message
== WM_PAINT
);
1377 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1378 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1380 SPY_EnterMessage( SPY_DISPATCHMESSAGE32
, msg
->hwnd
, msg
->message
,
1381 msg
->wParam
, msg
->lParam
);
1382 retval
= CallWindowProc32A( (WNDPROC32
)wndPtr
->winproc
,
1383 msg
->hwnd
, msg
->message
,
1384 msg
->wParam
, msg
->lParam
);
1385 SPY_ExitMessage( SPY_RESULT_OK32
, msg
->hwnd
, msg
->message
, retval
);
1387 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
1388 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
1390 fprintf(stderr
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1392 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1393 /* Validate the update region to avoid infinite WM_PAINT loop */
1394 ValidateRect32( msg
->hwnd
, NULL
);
1400 /***********************************************************************
1401 * DispatchMessage32W (USER32.141)
1403 LONG
DispatchMessage32W( const MSG32
* msg
)
1409 /* Process timer messages */
1410 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1414 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1415 return CallWindowProc32W( (WNDPROC32
)msg
->lParam
, msg
->hwnd
,
1416 msg
->message
, msg
->wParam
, GetTickCount() );
1420 if (!msg
->hwnd
) return 0;
1421 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1422 if (!wndPtr
->winproc
) return 0;
1423 painting
= (msg
->message
== WM_PAINT
);
1424 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1425 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1427 SPY_EnterMessage( SPY_DISPATCHMESSAGE32
, msg
->hwnd
, msg
->message
,
1428 msg
->wParam
, msg
->lParam
);
1429 retval
= CallWindowProc32W( (WNDPROC32
)wndPtr
->winproc
,
1430 msg
->hwnd
, msg
->message
,
1431 msg
->wParam
, msg
->lParam
);
1432 SPY_ExitMessage( SPY_RESULT_OK32
, msg
->hwnd
, msg
->message
, retval
);
1434 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
1435 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
1437 fprintf(stderr
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1439 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
1440 /* Validate the update region to avoid infinite WM_PAINT loop */
1441 ValidateRect32( msg
->hwnd
, NULL
);
1447 /***********************************************************************
1448 * RegisterWindowMessage16 (USER.118)
1450 WORD
RegisterWindowMessage16( SEGPTR str
)
1452 dprintf_msg(stddeb
, "RegisterWindowMessage16: %08lx\n", (DWORD
)str
);
1453 return GlobalAddAtom16( str
);
1457 /***********************************************************************
1458 * RegisterWindowMessage32A (USER32.436)
1460 WORD
RegisterWindowMessage32A( LPCSTR str
)
1462 dprintf_msg(stddeb
, "RegisterWindowMessage32A: %s\n", str
);
1463 return GlobalAddAtom32A( str
);
1467 /***********************************************************************
1468 * RegisterWindowMessage32W (USER32.437)
1470 WORD
RegisterWindowMessage32W( LPCWSTR str
)
1472 dprintf_msg(stddeb
, "RegisterWindowMessage32W: %p\n", str
);
1473 return GlobalAddAtom32W( str
);
1477 /***********************************************************************
1478 * GetTickCount (USER.13) (KERNEL32.299)
1480 DWORD
GetTickCount(void)
1483 gettimeofday( &t
, NULL
);
1484 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 1000)) - MSG_WineStartTicks
;
1488 /***********************************************************************
1489 * GetCurrentTime16 (USER.15)
1491 * (effectively identical to GetTickCount)
1493 DWORD
GetCurrentTime16(void)
1495 return GetTickCount();
1499 /***********************************************************************
1500 * InSendMessage16 (USER.192)
1502 BOOL16
InSendMessage16(void)
1504 return InSendMessage32();
1508 /***********************************************************************
1509 * InSendMessage32 (USER32.319)
1511 BOOL32
InSendMessage32(void)
1513 MESSAGEQUEUE
*queue
;
1515 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetTaskQueue(0) )))
1517 return (BOOL32
)queue
->InSendMessageHandle
;