2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
16 #include "sysmetrics.h"
32 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
33 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
35 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
36 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
38 extern MESSAGEQUEUE *pCursorQueue; /* queue.c */
39 extern MESSAGEQUEUE *pActiveQueue;
41 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
43 static UINT32 doubleClickSpeed = 452;
44 static INT32 debugSMRL = 0; /* intertask SendMessage() recursion level */
46 /***********************************************************************
49 BOOL32 MSG_CheckFilter(WORD uMsg, DWORD filter)
52 return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter));
56 /***********************************************************************
57 * MSG_SendParentNotify
59 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
60 * the window has the WS_EX_NOPARENTNOTIFY style.
62 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
64 #define lppt ((LPPOINT16)&lValue)
66 /* pt has to be in the client coordinates of the parent window */
68 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
71 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
72 lppt->x += wndPtr->rectClient.left;
73 lppt->y += wndPtr->rectClient.top;
74 wndPtr = wndPtr->parent;
75 SendMessage32A( wndPtr->hwndSelf, WM_PARENTNOTIFY,
76 MAKEWPARAM( event, idChild ), lValue );
82 /***********************************************************************
83 * MSG_TranslateMouseMsg
85 * Translate an mouse hardware event into a real mouse message.
86 * Return value indicates whether the translated message must be passed
87 * to the user, left in the queue, or skipped entirely (in this case
88 * HIWORD contains hit test code).
90 static DWORD MSG_TranslateMouseMsg( HWND16 hTopWnd, DWORD filter,
91 MSG16 *msg, BOOL32 remove, WND* pWndScope )
93 static DWORD dblclk_time_limit = 0;
94 static UINT16 clk_message = 0;
95 static HWND16 clk_hwnd = 0;
96 static POINT16 clk_pos = { 0, 0 };
100 INT16 ht, hittest, sendSC = 0;
101 UINT16 message = msg->message;
102 POINT16 screen_pt, pt;
103 HANDLE16 hQ = GetFastQueue();
104 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16(hQ);
105 BOOL32 eatMsg = FALSE;
106 BOOL32 mouseClick = ((message == WM_LBUTTONDOWN) ||
107 (message == WM_RBUTTONDOWN) ||
108 (message == WM_MBUTTONDOWN))?1:0;
111 /* Find the window */
113 ht = hittest = HTCLIENT;
114 hWnd = GetCapture16();
117 ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd );
118 if( !pWnd ) pWnd = WIN_GetDesktop();
119 hWnd = pWnd->hwndSelf;
124 pWnd = WIN_FindWndPtr(hWnd);
125 ht = EVENT_GetCaptureInfo();
128 /* stop if not the right queue */
130 if (pWnd->hmemTaskQ != hQ)
132 /* Not for the current task */
133 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
134 /* Wake up the other task */
135 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
136 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
137 return SYSQ_MSG_ABANDON;
140 /* check if hWnd is within hWndScope */
142 if( hTopWnd && hWnd != hTopWnd )
143 if( !IsChild16(hTopWnd, hWnd) ) return SYSQ_MSG_CONTINUE;
147 /* translate double clicks -
148 * note that ...MOUSEMOVEs can slip in between
149 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
151 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
153 if ((message == clk_message) && (hWnd == clk_hwnd) &&
154 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
155 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
156 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
158 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
159 mouseClick++; /* == 2 */
163 screen_pt = pt = msg->pt;
165 if (hittest != HTCLIENT)
167 message += ((INT16)WM_NCMOUSEMOVE - WM_MOUSEMOVE);
168 msg->wParam = hittest;
170 else ScreenToClient16( hWnd, &pt );
172 /* check message filter */
174 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
176 pCursorQueue = queue;
180 if (HOOK_IsHooked( WH_MOUSE ))
182 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
185 hook->pt = screen_pt;
187 hook->wHitTestCode = hittest;
188 hook->dwExtraInfo = 0;
189 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
190 message, (LPARAM)SEGPTR_GET(hook) );
193 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
196 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
198 else if( remove && mouseClick )
200 HWND32 hwndTop = WIN_GetTopParent( hWnd );
202 if( mouseClick == 1 )
205 dblclk_time_limit = msg->time;
206 clk_message = msg->message;
210 /* got double click - zero them out */
211 dblclk_time_limit = clk_hwnd = 0;
215 /* Send the WM_PARENTNOTIFY,
216 * note that even for double/nonclient clicks
217 * notification message is still WM_L/M/RBUTTONDOWN.
220 MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
222 /* Activate the window if needed */
224 if (hWnd != GetActiveWindow16() && hWnd != GetDesktopWindow16())
226 LONG ret = SendMessage16( hWnd, WM_MOUSEACTIVATE, hwndTop,
227 MAKELONG( hittest, message ) );
229 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
232 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
233 && hwndTop != GetActiveWindow16() )
234 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
238 } else sendSC = (remove && sendSC);
240 /* Send the WM_SETCURSOR message */
243 SendMessage16( hWnd, WM_SETCURSOR, (WPARAM16)hWnd,
244 MAKELONG( hittest, message ));
245 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
248 msg->message = message;
249 msg->lParam = MAKELONG( pt.x, pt.y );
250 return SYSQ_MSG_ACCEPT;
254 /***********************************************************************
255 * MSG_TranslateKbdMsg
257 * Translate an keyboard hardware event into a real message.
259 static DWORD MSG_TranslateKbdMsg( HWND16 hTopWnd, DWORD filter,
260 MSG16 *msg, BOOL32 remove )
262 WORD message = msg->message;
263 HWND16 hWnd = GetFocus16();
266 /* Should check Ctrl-Esc and PrintScreen here */
270 /* Send the message to the active window instead, */
271 /* translating messages to their WM_SYS equivalent */
273 hWnd = GetActiveWindow16();
275 if( message < WM_SYSKEYDOWN )
276 message += WM_SYSKEYDOWN - WM_KEYDOWN;
278 pWnd = WIN_FindWndPtr( hWnd );
279 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue()))
281 /* Not for the current task */
282 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( GetFastQueue() );
283 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
284 /* Wake up the other task */
285 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
286 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
287 return SYSQ_MSG_ABANDON;
290 if (hTopWnd && hWnd != hTopWnd)
291 if (!IsChild16(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
292 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
295 msg->message = message;
297 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
298 msg->wParam, msg->lParam )
299 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
303 /***********************************************************************
304 * MSG_JournalRecordMsg
306 * Build an EVENTMSG structure and call JOURNALRECORD hook
308 static void MSG_JournalRecordMsg( MSG16 *msg )
310 EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
312 event->message = msg->message;
313 event->time = msg->time;
314 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
316 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
317 event->paramH = msg->lParam & 0x7FFF;
318 if (HIWORD(msg->lParam) & 0x0100)
319 event->paramH |= 0x8000; /* special_key - bit */
320 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
321 (LPARAM)SEGPTR_GET(event) );
323 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
325 event->paramL = LOWORD(msg->lParam); /* X pos */
326 event->paramH = HIWORD(msg->lParam); /* Y pos */
327 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
328 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
329 (LPARAM)SEGPTR_GET(event) );
331 else if ((msg->message >= WM_NCMOUSEFIRST) &&
332 (msg->message <= WM_NCMOUSELAST))
334 event->paramL = LOWORD(msg->lParam); /* X pos */
335 event->paramH = HIWORD(msg->lParam); /* Y pos */
336 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
337 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
338 (LPARAM)SEGPTR_GET(event) );
343 /***********************************************************************
344 * MSG_JournalPlayBackMsg
346 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
348 static int MSG_JournalPlayBackMsg(void)
352 WORD keyDown,i,wParam,result=0;
354 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
356 tmpMsg = SEGPTR_NEW(EVENTMSG16);
357 wtime=HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
358 (LPARAM)SEGPTR_GET(tmpMsg));
359 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
363 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
365 wParam=tmpMsg->paramL & 0xFF;
366 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
367 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
369 for (keyDown=i=0; i<256 && !keyDown; i++)
370 if (InputKeyStateTable[i] & 0x80)
373 lParam |= 0x40000000;
374 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
376 else /* WM_KEYUP, WM_SYSKEYUP */
378 lParam |= 0xC0000000;
379 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
381 if (InputKeyStateTable[VK_MENU] & 0x80)
382 lParam |= 0x20000000;
383 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
384 lParam |= 0x01000000;
385 hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );
389 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
391 switch (tmpMsg->message)
394 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
396 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
398 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
400 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
402 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
404 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
406 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
407 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
408 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
409 SetCursorPos32(tmpMsg->paramL,tmpMsg->paramH);
410 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
412 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
413 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
414 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
415 hardware_event( tmpMsg->message, wParam, lParam,
416 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
419 HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_SKIP, 0,
420 (LPARAM)SEGPTR_GET(tmpMsg));
424 if( tmpMsg->message == WM_QUEUESYNC )
425 if (HOOK_IsHooked( WH_CBT ))
426 HOOK_CallHooks16( WH_CBT, HCBT_QS, 0, 0L);
428 result= QS_MOUSE | QS_KEY; /* ? */
435 /***********************************************************************
436 * MSG_PeekHardwareMsg
438 * Peek for a hardware message matching the hwnd and message filters.
440 static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
443 DWORD status = SYSQ_MSG_ACCEPT;
444 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
445 int i, kbd_msg, pos = sysMsgQueue->nextMessage;
447 /* FIXME: there has to be a better way to do this */
450 /* If the queue is empty, attempt to fill it */
451 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
453 EVENT_WaitNetEvent( FALSE, FALSE );
455 for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
457 if (pos >= sysMsgQueue->queueSize) pos = 0;
458 *msg = sysMsgQueue->messages[pos].msg;
460 /* Translate message */
462 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
464 HWND32 hWndScope = (HWND32)sysMsgQueue->messages[pos].extraInfo;
466 status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
467 (Options.managed && IsWindow32(hWndScope) )
468 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
471 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
473 status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove);
476 else /* Non-standard hardware event */
478 HARDWAREHOOKSTRUCT16 *hook;
479 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
482 hook->hWnd = msg->hwnd;
483 hook->wMessage = msg->message;
484 hook->wParam = msg->wParam;
485 hook->lParam = msg->lParam;
486 ret = HOOK_CallHooks16( WH_HARDWARE,
487 remove ? HC_ACTION : HC_NOREMOVE,
488 0, (LPARAM)SEGPTR_GET(hook) );
492 QUEUE_RemoveMsg( sysMsgQueue, pos );
495 status = SYSQ_MSG_ACCEPT;
499 switch (LOWORD(status))
501 case SYSQ_MSG_ACCEPT:
505 if (HOOK_IsHooked( WH_CBT ))
508 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
509 msg->wParam, msg->lParam );
512 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
516 hook->hwnd = msg->hwnd;
517 hook->wHitTestCode = HIWORD(status);
518 hook->dwExtraInfo = 0;
519 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message,
520 (LPARAM)SEGPTR_GET(hook) );
527 QUEUE_RemoveMsg( sysMsgQueue, pos );
530 case SYSQ_MSG_CONTINUE:
533 case SYSQ_MSG_ABANDON:
539 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
540 QUEUE_RemoveMsg( sysMsgQueue, pos );
548 /**********************************************************************
549 * SetDoubleClickTime16 (USER.20)
551 void WINAPI SetDoubleClickTime16( UINT16 interval )
553 SetDoubleClickTime32( interval );
557 /**********************************************************************
558 * SetDoubleClickTime32 (USER32.480)
560 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
562 doubleClickSpeed = interval ? interval : 500;
567 /**********************************************************************
568 * GetDoubleClickTime16 (USER.21)
570 UINT16 WINAPI GetDoubleClickTime16(void)
572 return doubleClickSpeed;
576 /**********************************************************************
577 * GetDoubleClickTime32 (USER32.239)
579 UINT32 WINAPI GetDoubleClickTime32(void)
581 return doubleClickSpeed;
585 /***********************************************************************
588 * Implementation of an inter-task SendMessage.
590 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
591 WPARAM32 wParam, LPARAM lParam, WORD flags )
593 INT32 prevSMRL = debugSMRL;
594 QSMCTRL qCtrl = { 0, 1};
595 MESSAGEQUEUE *queue, *destQ;
597 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetFastQueue() ))) return 0;
598 if (!(destQ = (MESSAGEQUEUE*)GlobalLock16( hDestQueue ))) return 0;
600 if (IsTaskLocked() || !IsWindow32(hwnd)) return 0;
603 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
604 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
606 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
608 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
609 QUEUE_WaitBits( QS_SMPARAMSFREE );
616 queue->wParam = LOWORD(wParam);
617 queue->wParamHigh = HIWORD(wParam);
618 queue->lParam = lParam;
619 queue->hPrevSendingTask = destQ->hSendingTask;
620 destQ->hSendingTask = GetFastQueue();
622 QUEUE_ClearWakeBit( queue, QS_SMPARAMSFREE );
623 queue->flags = (queue->flags & ~(QUEUE_SM_WIN32|QUEUE_SM_UNICODE)) | flags;
625 TRACE(sendmsg,"%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl);
627 queue->smResultInit = &qCtrl;
629 QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE );
631 /* perform task switch and wait for the result */
633 while( qCtrl.bPending )
635 if (!(queue->wakeBits & QS_SMRESULT))
637 if (THREAD_IsWin16( THREAD_Current() )) DirectedYield( destQ->hTask );
638 QUEUE_WaitBits( QS_SMRESULT );
639 TRACE(sendmsg,"\tsm: have result!\n");
643 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
645 if (queue->smResult) { /* FIXME, smResult should always be set */
646 queue->smResult->lResult = queue->SendMessageReturn;
647 queue->smResult->bPending = FALSE;
649 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
651 if( queue->smResult != &qCtrl )
652 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
654 queue->smResultInit = NULL;
656 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
659 return qCtrl.lResult;
663 /***********************************************************************
664 * ReplyMessage16 (USER.115)
666 void WINAPI ReplyMessage16( LRESULT result )
668 MESSAGEQUEUE *senderQ;
671 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetFastQueue() ))) return;
673 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
675 while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
677 TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
678 queue->msg, queue->self, senderQ->self);
680 if( queue->wakeBits & QS_SENDMESSAGE )
682 QUEUE_ReceiveMessage( queue );
683 continue; /* ReceiveMessage() already called us */
686 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
687 if (THREAD_IsWin16(THREAD_Current())) OldYield();
689 if( !senderQ ) { TRACE(msg,"\trpm: done\n"); return; }
691 senderQ->SendMessageReturn = result;
692 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
693 (unsigned)queue->smResultCurrent, result );
695 senderQ->smResult = queue->smResultCurrent;
696 queue->InSendMessageHandle = 0;
698 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
699 if (THREAD_IsWin16(THREAD_Current())) DirectedYield( senderQ->hTask );
703 /***********************************************************************
706 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
707 WORD flags, BOOL32 peek )
710 MESSAGEQUEUE *msgQueue;
714 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
715 DDE_GetRemoteMessage();
716 #endif /* CONFIG_IPC */
718 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
721 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
722 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
723 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
724 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
725 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
726 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
728 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
730 if (IsTaskLocked()) flags |= PM_NOYIELD;
732 /* Never yield on Win32 threads */
733 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
737 hQueue = GetFastQueue();
738 msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
739 if (!msgQueue) return FALSE;
740 msgQueue->changeBits = 0;
742 /* First handle a message put by SendMessage() */
744 while (msgQueue->wakeBits & QS_SENDMESSAGE)
745 QUEUE_ReceiveMessage( msgQueue );
747 /* Now handle a WM_QUIT message */
749 if (msgQueue->wPostQMsg &&
750 (!first || WM_QUIT >= first) &&
751 (!last || WM_QUIT <= last) )
754 msg->message = WM_QUIT;
755 msg->wParam = msgQueue->wExitCode;
757 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
761 /* Now find a normal message */
763 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
764 ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
766 QMSG *qmsg = &msgQueue->messages[pos];
768 msgQueue->GetMessageTimeVal = msg->time;
769 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
770 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
772 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
776 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
778 /* Now find a hardware event */
780 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
781 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
784 msgQueue->GetMessageTimeVal = msg->time;
785 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
786 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
790 /* Check again for SendMessage */
792 while (msgQueue->wakeBits & QS_SENDMESSAGE)
793 QUEUE_ReceiveMessage( msgQueue );
795 /* Now find a WM_PAINT message */
797 if ((msgQueue->wakeBits & mask) & QS_PAINT)
800 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
801 msg->message = WM_PAINT;
805 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
807 if( wndPtr->dwStyle & WS_MINIMIZE &&
808 wndPtr->class->hIcon )
810 msg->message = WM_PAINTICON;
814 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
816 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
818 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
819 QUEUE_DecPaintCount( hQueue );
826 /* Check for timer messages, but yield first */
828 if (!(flags & PM_NOYIELD))
831 while (msgQueue->wakeBits & QS_SENDMESSAGE)
832 QUEUE_ReceiveMessage( msgQueue );
834 if ((msgQueue->wakeBits & mask) & QS_TIMER)
836 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
841 if (!(flags & PM_NOYIELD)) UserYield();
844 msgQueue->wakeMask = mask;
845 QUEUE_WaitBits( mask );
848 /* We got a message */
849 if (flags & PM_REMOVE)
851 WORD message = msg->message;
853 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
855 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
861 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
862 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
864 if (peek) return TRUE;
865 else return (msg->message != WM_QUIT);
869 /***********************************************************************
870 * MSG_InternalGetMessage
872 * GetMessage() function for internal use. Behave like GetMessage(),
873 * but also call message filters and optionally send WM_ENTERIDLE messages.
874 * 'hwnd' must be the handle of the dialog or menu window.
875 * 'code' is the message filter value (MSGF_??? codes).
877 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
878 WPARAM32 code, WORD flags, BOOL32 sendIdle )
884 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
886 /* No message present -> send ENTERIDLE and wait */
887 if (IsWindow32(hwndOwner))
888 SendMessage16( hwndOwner, WM_ENTERIDLE,
889 code, (LPARAM)hwnd );
890 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
893 else /* Always wait for a message */
894 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
896 /* Call message filters */
898 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
900 MSG16 *pmsg = SEGPTR_NEW(MSG16);
905 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
906 (LPARAM)SEGPTR_GET(pmsg) ) ||
907 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
908 (LPARAM)SEGPTR_GET(pmsg) ));
912 /* Message filtered -> remove it from the queue */
913 /* if it's still there. */
914 if (!(flags & PM_REMOVE))
915 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
921 return (msg->message != WM_QUIT);
926 /***********************************************************************
927 * PeekMessage16 (USER.109)
929 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
930 UINT16 last, UINT16 flags )
932 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
935 /***********************************************************************
938 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
939 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
943 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
944 /* FIXME: should translate the message to Win32 */
945 STRUCT32_MSG16to32(&msg,lpmsg);
949 /***********************************************************************
950 * PeekMessageW Check queue for messages
952 * Checks for a message in the thread's queue, filtered as for
953 * GetMessage(). Returns immediately whether a message is available
956 * Whether a retrieved message is removed from the queue is set by the
957 * _wRemoveMsg_ flags, which should be one of the following values:
959 * PM_NOREMOVE Do not remove the message from the queue.
961 * PM_REMOVE Remove the message from the queue.
963 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
964 * request that the system not yield control during PeekMessage();
965 * however applications may not rely on scheduling behavior.
969 * Nonzero if a message is available and is retrieved, zero otherwise.
976 BOOL32 WINAPI PeekMessage32W(
977 LPMSG32 lpmsg, /* buffer to receive message */
978 HWND32 hwnd, /* restrict to messages for hwnd */
979 UINT32 min, /* minimum message to receive */
980 UINT32 max, /* maximum message to receive */
981 UINT32 wRemoveMsg /* removal flags */
983 /* FIXME: Should perform Unicode translation on specific messages */
984 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
987 /***********************************************************************
988 * GetMessage16 (USER.108)
990 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
992 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
993 MSG_PeekMessage( lpmsg,
994 hwnd, first, last, PM_REMOVE, FALSE );
996 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
998 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
999 return (lpmsg->message != WM_QUIT);
1002 /***********************************************************************
1003 * GetMessage32A (USER32.270)
1005 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1008 MSG16 *msg = SEGPTR_NEW(MSG16);
1010 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1012 STRUCT32_MSG16to32(msg,lpmsg);
1017 /***********************************************************************
1018 * GetMessage32W (USER32.274) Retrieve next message
1020 * GetMessage retrieves the next event from the calling thread's
1021 * queue and deposits it in *lpmsg.
1023 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1024 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1025 * all application messages are retrieved.
1027 * _min_ and _max_ specify the range of messages of interest. If
1028 * min==max==0, no filtering is performed. Useful examples are
1029 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1030 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1032 * WM_PAINT messages are not removed from the queue; they remain until
1033 * processed. Other messages are removed from the queue.
1037 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1044 BOOL32 WINAPI GetMessage32W(
1045 MSG32* lpmsg, /* buffer to receive message */
1046 HWND32 hwnd, /* restrict to messages for hwnd */
1047 UINT32 min, /* minimum message to receive */
1048 UINT32 max /* maximum message to receive */
1051 MSG16 *msg = SEGPTR_NEW(MSG16);
1053 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1055 STRUCT32_MSG16to32(msg,lpmsg);
1061 /***********************************************************************
1062 * PostMessage16 (USER.110)
1064 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1071 msg.message = message;
1072 msg.wParam = wParam;
1073 msg.lParam = lParam;
1074 msg.time = GetTickCount();
1079 if (DDE_PostMessage(&msg))
1081 #endif /* CONFIG_IPC */
1083 if (hwnd == HWND_BROADCAST)
1085 TRACE(msg,"HWND_BROADCAST !\n");
1086 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1088 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1090 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1091 wndPtr->hwndSelf, message, wParam, lParam);
1092 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1095 TRACE(msg,"End of HWND_BROADCAST !\n");
1099 wndPtr = WIN_FindWndPtr( hwnd );
1100 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1102 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1106 /***********************************************************************
1107 * PostMessage32A (USER32.419)
1109 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1113 if (message&0xffff0000)
1114 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1115 if (wParam&0xffff0000)
1116 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1117 return PostMessage16( hwnd, message, wParam, lParam );
1121 /***********************************************************************
1122 * PostMessage32W (USER32.420)
1124 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1128 if (message&0xffff0000)
1129 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1130 if (wParam&0xffff0000)
1131 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1132 return PostMessage16( hwnd, message, wParam, lParam );
1136 /***********************************************************************
1137 * PostAppMessage16 (USER.116)
1139 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1144 if (GetTaskQueue(hTask) == 0) return FALSE;
1146 msg.message = message;
1147 msg.wParam = wParam;
1148 msg.lParam = lParam;
1149 msg.time = GetTickCount();
1153 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1157 /***********************************************************************
1158 * SendMessage16 (USER.111)
1160 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1164 WND **list, **ppWnd;
1168 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1169 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1170 #endif /* CONFIG_IPC */
1172 if (hwnd == HWND_BROADCAST)
1174 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1176 TRACE(msg,"HWND_BROADCAST !\n");
1177 for (ppWnd = list; *ppWnd; ppWnd++)
1180 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1181 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1183 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1184 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1185 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1188 HeapFree( SystemHeap, 0, list );
1189 TRACE(msg,"End of HWND_BROADCAST !\n");
1193 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1197 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1201 pmsg->wParam = wParam;
1202 pmsg->lParam = lParam;
1203 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1204 (LPARAM)SEGPTR_GET(pmsg) );
1206 msg = pmsg->message;
1207 wParam = pmsg->wParam;
1208 lParam = pmsg->lParam;
1209 SEGPTR_FREE( pmsg );
1213 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1215 WARN(msg, "invalid hwnd %04x\n", hwnd );
1218 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1219 return 0; /* Don't send anything if the task is dying */
1221 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1223 if (wndPtr->hmemTaskQ != GetFastQueue())
1224 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1225 wParam, lParam, 0 );
1227 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1228 hwnd, msg, wParam, lParam );
1230 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1234 /************************************************************************
1235 * MSG_CallWndProcHook32
1237 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1241 cwp.lParam = pmsg->lParam;
1242 cwp.wParam = pmsg->wParam;
1243 cwp.message = pmsg->message;
1244 cwp.hwnd = pmsg->hwnd;
1246 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1247 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1249 pmsg->lParam = cwp.lParam;
1250 pmsg->wParam = cwp.wParam;
1251 pmsg->message = cwp.message;
1252 pmsg->hwnd = cwp.hwnd;
1255 /**********************************************************************
1256 * PostThreadMessage32A (USER32.422)
1260 * Thread-local message queues are not supported.
1263 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1264 WPARAM32 wParam, LPARAM lParam )
1266 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1267 if (!thdb || !thdb->process) return FALSE;
1269 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1270 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1273 /**********************************************************************
1274 * PostThreadMessage32W (USER32.423)
1278 * Thread-local message queues are not supported.
1281 BOOL32 WINAPI PostThreadMessage32W(DWORD idThread , UINT32 message,
1282 WPARAM32 wParam, LPARAM lParam )
1284 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1285 if (!thdb || !thdb->process) return FALSE;
1287 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1288 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1291 /***********************************************************************
1292 * SendMessage32A (USER32.454)
1294 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1298 WND **list, **ppWnd;
1301 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1303 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1305 for (ppWnd = list; *ppWnd; ppWnd++)
1308 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1309 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1310 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1312 HeapFree( SystemHeap, 0, list );
1316 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1317 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1319 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1321 WARN(msg, "invalid hwnd %08x\n", hwnd );
1325 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1326 return 0; /* Don't send anything if the task is dying */
1328 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1330 if (wndPtr->hmemTaskQ != GetFastQueue())
1331 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1334 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1335 hwnd, msg, wParam, lParam );
1337 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1342 /***********************************************************************
1343 * SendMessage32W (USER32.459) Send Window Message
1345 * Sends a message to the window procedure of the specified window.
1346 * SendMessage() will not return until the called window procedure
1347 * either returns or calls ReplyMessage().
1349 * Use PostMessage() to send message and return immediately. A window
1350 * procedure may use InSendMessage() to detect
1351 * SendMessage()-originated messages.
1353 * Applications which communicate via HWND_BROADCAST may use
1354 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1355 * with other applications.
1361 LRESULT WINAPI SendMessage32W(
1362 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1363 the message will be sent to all top-level windows. */
1365 UINT32 msg, /* message */
1366 WPARAM32 wParam, /* message parameter */
1367 LPARAM lParam /* additional message parameter */
1370 WND **list, **ppWnd;
1373 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1375 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1377 for (ppWnd = list; *ppWnd; ppWnd++)
1380 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1381 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1382 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1384 HeapFree( SystemHeap, 0, list );
1388 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1389 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1391 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1393 WARN(msg, "invalid hwnd %08x\n", hwnd );
1396 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1397 return 0; /* Don't send anything if the task is dying */
1399 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1401 if (wndPtr->hmemTaskQ != GetFastQueue())
1402 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1403 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1405 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1406 hwnd, msg, wParam, lParam );
1408 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1413 /***********************************************************************
1414 * SendMessageTimeout16 (not a WINAPI)
1416 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1417 LPARAM lParam, UINT16 flags,
1418 UINT16 timeout, LPWORD resultp)
1420 FIXME(sendmsg, "(...): semistub\n");
1421 return SendMessage16 (hwnd, msg, wParam, lParam);
1425 /***********************************************************************
1426 * SendMessageTimeout32A (USER32.457)
1428 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1429 LPARAM lParam, UINT32 flags,
1430 UINT32 timeout, LPDWORD resultp)
1432 FIXME(sendmsg, "(...): semistub\n");
1433 return SendMessage32A (hwnd, msg, wParam, lParam);
1437 /***********************************************************************
1438 * SendMessageTimeout32W (USER32.458)
1440 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1441 LPARAM lParam, UINT32 flags,
1442 UINT32 timeout, LPDWORD resultp)
1444 FIXME(sendmsg, "(...): semistub\n");
1445 return SendMessage32W (hwnd, msg, wParam, lParam);
1449 /***********************************************************************
1450 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1452 * WaitMessage() suspends a thread until events appear in the thread's
1457 * Is supposed to return BOOL under Win32.
1459 * Thread-local message queues are not supported.
1466 void WINAPI WaitMessage( void )
1468 QUEUE_WaitBits( QS_ALLINPUT );
1471 /***********************************************************************
1472 * MsgWaitForMultipleObjects (USER32.400)
1474 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1475 BOOL32 fWaitAll, DWORD dwMilliseconds,
1480 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1481 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1482 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1483 if (!msgQueue) return 0xFFFFFFFF;
1485 msgQueue->changeBits = 0;
1486 msgQueue->wakeMask = dwWakeMask;
1488 retv = SYNC_DoWait( nCount, pHandles, fWaitAll, dwMilliseconds, FALSE, TRUE );
1502 static const struct accent_char accent_chars[] =
1504 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1505 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1506 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1507 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1508 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1509 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1510 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1511 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1512 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1513 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1514 {',', 'C', '\307'}, {',', 'c', '\347'},
1515 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1516 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1517 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1518 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1519 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1520 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1521 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1522 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1523 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1524 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1525 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1526 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1527 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1528 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1529 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1530 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1531 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1532 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1533 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1534 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1535 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1536 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1537 {'s', 's', '\337'}, {'"', 'y', '\377'},
1538 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1539 /* iso-8859-2 uses this */
1540 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1541 {'<', 'S', '\251'}, {'<', 's', '\271'},
1542 {'<', 'T', '\253'}, {'<', 't', '\273'},
1543 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1544 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1545 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1546 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1547 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1548 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1549 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1550 {';', 'E', '\312'}, {';', 'e', '\332'},
1551 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1552 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1553 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1554 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1555 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1556 /* collision whith S, from iso-8859-9 !!! */
1557 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1558 {',', 'T', '\336'}, {',', 't', '\376'},
1559 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1560 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1561 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1562 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1563 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1564 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1565 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1566 /* iso-8859-3 uses this */
1567 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1568 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1569 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1570 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1571 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1572 {'>', 'S', '\336'}, {'>', 's', '\376'},
1573 /* collision whith G( from iso-8859-9 !!! */
1574 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1575 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1576 /* collision whith I. from iso-8859-3 !!! */
1577 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1578 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1579 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1580 /* iso-8859-4 uses this */
1581 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1582 {',', 'L', '\246'}, {',', 'l', '\266'},
1583 {',', 'G', '\253'}, {',', 'g', '\273'},
1584 {',', 'N', '\321'}, {',', 'n', '\361'},
1585 {',', 'K', '\323'}, {',', 'k', '\363'},
1586 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1587 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1588 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1589 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1590 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1591 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1592 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1593 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1594 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1595 {';', 'U', '\331'}, {';', 'u', '\371'},
1596 /* iso-8859-9 uses this */
1597 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1598 * whith the same letters on other iso-8859-x (that is they are on
1599 * different places :-( ), if you use turkish uncomment these and
1600 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1601 * FIXME: should be dynamic according to chosen language
1602 * if/when Wine has turkish support.
1604 /* collision whith G( from iso-8859-3 !!! */
1605 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1606 /* collision whith S, from iso-8859-2 !!! */
1607 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1608 /* collision whith I. from iso-8859-3 !!! */
1609 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1613 /***********************************************************************
1614 * MSG_DoTranslateMessage
1616 * Implementation of TranslateMessage.
1618 * TranslateMessage translates virtual-key messages into character-messages,
1620 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1621 * ditto replacing WM_* with WM_SYS*
1622 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1623 * by the keyboard driver.
1625 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1626 WPARAM32 wParam, LPARAM lParam )
1628 static int dead_char;
1631 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1632 TRACE(msg, "(%s, %04X, %08lX)\n",
1633 SPY_GetMsgName(message), wParam, lParam );
1634 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1635 TRACE(key, "(%s, %04X, %08lX)\n",
1636 SPY_GetMsgName(message), wParam, lParam );
1638 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1640 TRACE(key, "Translating key %04X, scancode %04X\n",
1641 wParam, HIWORD(lParam) );
1643 /* FIXME : should handle ToAscii yielding 2 */
1644 switch (ToAscii32(wParam, HIWORD(lParam),
1645 QueueKeyStateTable,(LPWORD)wp, 0))
1648 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1649 /* Should dead chars handling go in ToAscii ? */
1654 if (wp[0] == ' ') wp[0] = dead_char;
1655 if (dead_char == 0xa2) dead_char = '(';
1656 else if (dead_char == 0xa8) dead_char = '"';
1657 else if (dead_char == 0xb2) dead_char = ';';
1658 else if (dead_char == 0xb4) dead_char = '\'';
1659 else if (dead_char == 0xb7) dead_char = '<';
1660 else if (dead_char == 0xb8) dead_char = ',';
1661 else if (dead_char == 0xff) dead_char = '.';
1662 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1663 if ((accent_chars[i].ac_accent == dead_char) &&
1664 (accent_chars[i].ac_char == wp[0]))
1666 wp[0] = accent_chars[i].ac_result;
1671 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1672 PostMessage16( hwnd, message, wp[0], lParam );
1676 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1678 TRACE(key, "-1 -> PostMessage(%s)\n",
1679 SPY_GetMsgName(message));
1680 PostMessage16( hwnd, message, wp[0], lParam );
1687 /***********************************************************************
1688 * TranslateMessage16 (USER.113)
1690 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1692 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1693 msg->wParam, msg->lParam );
1697 /***********************************************************************
1698 * TranslateMessage32 (USER32.556)
1700 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1702 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1703 msg->wParam, msg->lParam );
1707 /***********************************************************************
1708 * DispatchMessage16 (USER.114)
1710 LONG WINAPI DispatchMessage16( const MSG16* msg )
1716 /* Process timer messages */
1717 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1721 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1722 msg->message, msg->wParam, GetTickCount() );
1726 if (!msg->hwnd) return 0;
1727 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1728 if (!wndPtr->winproc) return 0;
1729 painting = (msg->message == WM_PAINT);
1730 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1732 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1733 msg->wParam, msg->lParam );
1734 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1735 msg->hwnd, msg->message,
1736 msg->wParam, msg->lParam );
1737 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1739 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1740 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1742 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1744 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1745 /* Validate the update region to avoid infinite WM_PAINT loop */
1746 ValidateRect32( msg->hwnd, NULL );
1752 /***********************************************************************
1753 * DispatchMessage32A (USER32.141)
1755 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1761 /* Process timer messages */
1762 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1766 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1767 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1768 msg->message, msg->wParam, GetTickCount() );
1772 if (!msg->hwnd) return 0;
1773 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1774 if (!wndPtr->winproc) return 0;
1775 painting = (msg->message == WM_PAINT);
1776 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1777 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1779 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1780 msg->wParam, msg->lParam );
1781 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1782 msg->hwnd, msg->message,
1783 msg->wParam, msg->lParam );
1784 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1786 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1787 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1789 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1791 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1792 /* Validate the update region to avoid infinite WM_PAINT loop */
1793 ValidateRect32( msg->hwnd, NULL );
1799 /***********************************************************************
1800 * DispatchMessage32W (USER32.142) Process Message
1802 * Process the message specified in the structure *_msg_.
1804 * If the lpMsg parameter points to a WM_TIMER message and the
1805 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1806 * points to the function that is called instead of the window
1809 * The message must be valid.
1813 * DispatchMessage() returns the result of the window procedure invoked.
1820 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1826 /* Process timer messages */
1827 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1831 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1832 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1833 msg->message, msg->wParam, GetTickCount() );
1837 if (!msg->hwnd) return 0;
1838 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1839 if (!wndPtr->winproc) return 0;
1840 painting = (msg->message == WM_PAINT);
1841 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1842 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1844 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1845 msg->wParam, msg->lParam );
1846 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1847 msg->hwnd, msg->message,
1848 msg->wParam, msg->lParam );
1849 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1851 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1852 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1854 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1856 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1857 /* Validate the update region to avoid infinite WM_PAINT loop */
1858 ValidateRect32( msg->hwnd, NULL );
1864 /***********************************************************************
1865 * RegisterWindowMessage16 (USER.118)
1867 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1869 TRACE(msg, "%08lx\n", (DWORD)str );
1870 return GlobalAddAtom16( str );
1874 /***********************************************************************
1875 * RegisterWindowMessage32A (USER32.437)
1877 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1879 TRACE(msg, "%s\n", str );
1880 return GlobalAddAtom32A( str );
1884 /***********************************************************************
1885 * RegisterWindowMessage32W (USER32.438)
1887 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1889 TRACE(msg, "%p\n", str );
1890 return GlobalAddAtom32W( str );
1894 /***********************************************************************
1895 * GetTickCount (USER.13) (KERNEL32.299) System Time
1896 * Returns the number of milliseconds, modulo 2^32, since the start
1897 * of the current session.
1903 DWORD WINAPI GetTickCount(void)
1906 gettimeofday( &t, NULL );
1907 /* make extremely compatible: granularity is 25 msec */
1908 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
1912 /***********************************************************************
1913 * GetCurrentTime16 (USER.15)
1915 * (effectively identical to GetTickCount)
1917 DWORD WINAPI GetCurrentTime16(void)
1919 return GetTickCount();
1923 /***********************************************************************
1924 * InSendMessage16 (USER.192)
1926 BOOL16 WINAPI InSendMessage16(void)
1928 return InSendMessage32();
1932 /***********************************************************************
1933 * InSendMessage32 (USER32.320)
1935 BOOL32 WINAPI InSendMessage32(void)
1937 MESSAGEQUEUE *queue;
1939 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetFastQueue() )))
1941 return (BOOL32)queue->InSendMessageHandle;
1944 /***********************************************************************
1945 * BroadcastSystemMessage (USER32.12)
1947 LONG WINAPI BroadcastSystemMessage(
1948 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1951 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1952 dwFlags,*recipients,uMessage,wParam,lParam
1957 /***********************************************************************
1958 * SendNotifyMessageA (USER32.460)
1960 * The message sended with PostMessage has to be put in the queue
1961 * with a higher priority as the other "Posted" messages.
1962 * QUEUE_AddMsg has to be modifyed.
1964 BOOL32 WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1965 { BOOL32 ret = TRUE;
1966 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1967 hwnd, msg, wParam, lParam);
1969 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1970 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1973 { PostMessage32A ( hwnd, msg, wParam, lParam );
1978 /***********************************************************************
1979 * SendNotifyMessageW (USER32.461)
1981 * The message sended with PostMessage has to be put in the queue
1982 * with a higher priority as the other "Posted" messages.
1983 * QUEUE_AddMsg has to be modifyed.
1985 BOOL32 WINAPI SendNotifyMessage32W(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1986 { BOOL32 ret = TRUE;
1987 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1988 hwnd, msg, wParam, lParam);
1990 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1991 { ret=SendMessage32W ( hwnd, msg, wParam, lParam );
1994 { PostMessage32W ( hwnd, msg, wParam, lParam );
1999 /***********************************************************************
2000 * SendMessageCallBack32A
2001 * FIXME: It's like PostMessage. The callback gets called when the message
2002 * is processed. We have to modify the message processing for a exact
2005 BOOL32 WINAPI SendMessageCallBack32A(
2006 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
2007 FARPROC32 lpResultCallBack,DWORD dwData)
2009 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2010 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2011 if ( hWnd == HWND_BROADCAST)
2012 { PostMessage32A( hWnd, Msg, wParam, lParam);
2013 FIXME(msg,"Broadcast: Callback will not be called!\n");
2016 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));