2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
27 #include "selectors.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(msg)
35 DECLARE_DEBUG_CHANNEL(key)
36 DECLARE_DEBUG_CHANNEL(sendmsg)
38 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
39 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
42 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
43 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
45 extern HQUEUE16 hCursorQueue; /* queue.c */
47 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
49 static UINT doubleClickSpeed = 452;
51 /***********************************************************************
54 static BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
57 return (uMsg >= first && uMsg <= last);
61 /***********************************************************************
62 * MSG_SendParentNotify
64 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
65 * the window has the WS_EX_NOPARENTNOTIFY style.
67 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
69 #define lppt ((LPPOINT16)&lValue)
71 /* pt has to be in the client coordinates of the parent window */
72 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
74 MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
77 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
79 WIN_ReleaseWndPtr(tmpWnd);
82 lppt->x += tmpWnd->rectClient.left;
83 lppt->y += tmpWnd->rectClient.top;
84 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
85 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
86 MAKEWPARAM( event, idChild ), lValue );
93 /***********************************************************************
94 * MSG_TranslateMouseMsg
96 * Translate an mouse hardware event into a real mouse message.
100 * SYSQ_MSG_ABANDON - abandon the peek message loop
101 * SYSQ_MSG_CONTINUE - leave the message in the queue and
102 * continue with the translation loop
103 * SYSQ_MSG_ACCEPT - proceed to process the translated message
105 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
106 MSG *msg, BOOL remove, WND* pWndScope,
107 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
109 static DWORD dblclk_time_limit = 0;
110 static UINT16 clk_message = 0;
111 static HWND16 clk_hwnd = 0;
112 static POINT16 clk_pos = { 0, 0 };
117 UINT message = msg->message;
118 POINT16 screen_pt, pt;
119 HANDLE16 hQ = GetFastQueue16();
120 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
121 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
122 (message == WM_RBUTTONDOWN) ||
123 (message == WM_MBUTTONDOWN))?1:0;
126 /* Find the window to dispatch this mouse message to */
128 CONV_POINT32TO16( &msg->pt, &pt );
132 /* If no capture HWND, find window which contains the mouse position.
133 * Also find the position of the cursor hot spot (hittest) */
136 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
137 if( !pWnd ) pWnd = WIN_GetDesktop();
138 else WIN_LockWndPtr(pWnd);
139 hWnd = pWnd->hwndSelf;
143 ht = hittest = HTCLIENT;
144 pWnd = WIN_FindWndPtr(hWnd);
146 ht = PERQDATA_GetCaptureInfo( queue->pQData );
149 /* Save hittest for return */
152 /* stop if not the right queue */
154 if (pWnd->hmemTaskQ != hQ)
156 /* Not for the current task */
157 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
158 /* Wake up the other task */
159 QUEUE_Unlock( queue );
160 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
161 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
163 QUEUE_Unlock( queue );
164 retvalue = SYSQ_MSG_ABANDON;
168 /* check if hWnd is within hWndScope */
170 if( hTopWnd && hWnd != hTopWnd )
171 if( !IsChild(hTopWnd, hWnd) )
173 QUEUE_Unlock( queue );
174 retvalue = SYSQ_MSG_CONTINUE;
178 /* Was it a mouse click message */
181 /* translate double clicks -
182 * note that ...MOUSEMOVEs can slip in between
183 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
185 if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
187 if ((message == clk_message) && (hWnd == clk_hwnd) &&
188 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
189 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
190 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
192 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
193 mouseClick++; /* == 2 */
197 /* save mouse position */
201 if (hittest != HTCLIENT)
203 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
204 msg->wParam = hittest;
207 ScreenToClient16( hWnd, &pt );
209 /* check message filter */
211 if (!MSG_CheckFilter(message, first, last))
214 retvalue = SYSQ_MSG_CONTINUE;
218 /* Update global hCursorQueue */
219 hCursorQueue = queue->self;
221 /* Update static double click conditions */
222 if( remove && mouseClick )
224 if( mouseClick == 1 )
227 dblclk_time_limit = msg->time;
228 clk_message = msg->message;
232 /* got double click - zero them out */
233 dblclk_time_limit = clk_hwnd = 0;
238 /* Update message params */
240 msg->message = message;
241 msg->lParam = MAKELONG( pt.x, pt.y );
242 retvalue = SYSQ_MSG_ACCEPT;
245 WIN_ReleaseWndPtr(pWnd);
247 /* Return mouseclick flag */
248 *pmouseClick = mouseClick;
254 /***********************************************************************
255 * MSG_ProcessMouseMsg
257 * Processes a translated mouse hardware event.
258 * The passed in msg structure should contain the updated hWnd,
259 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
263 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
264 * HIWORD contains hit test code). Continue translating..
265 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
266 * MSG_PeekHardwareMsg should return TRUE.
268 static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
269 POINT16 screen_pt, BOOL mouseClick )
272 HWND hWnd = msg->hwnd;
273 INT16 sendSC = (GetCapture() == 0);
274 UINT message = msg->message;
278 pWnd = WIN_FindWndPtr(hWnd);
282 if (HOOK_IsHooked( WH_MOUSE ))
285 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
288 hook->pt = screen_pt;
290 hook->wHitTestCode = hittest;
291 hook->dwExtraInfo = 0;
292 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
293 message, (LPARAM)SEGPTR_GET(hook) );
298 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
304 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
306 else if( remove && mouseClick )
308 HWND hwndTop = WIN_GetTopParent( hWnd );
312 /* Send the WM_PARENTNOTIFY,
313 * note that even for double/nonclient clicks
314 * notification message is still WM_L/M/RBUTTONDOWN.
317 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
319 /* Activate the window if needed */
321 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
323 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
324 MAKELONG( hittest, message ) );
326 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
329 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
330 && hwndTop != GetForegroundWindow() )
332 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
337 } else sendSC = (remove && sendSC);
339 /* Send the WM_SETCURSOR message */
343 UINT uSCMessage = message;
345 /* Windows sends the normal mouse message as the message parameter
346 in the WM_SETCURSOR message even if it's non-client mouse message */
348 if (uSCMessage >= WM_NCMOUSEFIRST && uSCMessage <= WM_NCMOUSELAST)
349 uSCMessage += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
350 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
351 MAKELONG( hittest, uSCMessage));
355 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
359 retvalue = SYSQ_MSG_ACCEPT;
361 WIN_ReleaseWndPtr(pWnd);
367 /***********************************************************************
368 * MSG_TranslateKbdMsg
370 * Translate an keyboard hardware event into a real message.
372 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
373 MSG *msg, BOOL remove )
375 WORD message = msg->message;
376 HWND hWnd = GetFocus();
379 /* Should check Ctrl-Esc and PrintScreen here */
383 /* Send the message to the active window instead, */
384 /* translating messages to their WM_SYS equivalent */
386 hWnd = GetActiveWindow();
388 if( message < WM_SYSKEYDOWN )
389 message += WM_SYSKEYDOWN - WM_KEYDOWN;
391 pWnd = WIN_FindWndPtr( hWnd );
392 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
394 /* Not for the current task */
395 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
396 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
397 QUEUE_Unlock( queue );
399 /* Wake up the other task */
400 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
401 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
402 QUEUE_Unlock( queue );
403 WIN_ReleaseWndPtr(pWnd);
404 return SYSQ_MSG_ABANDON;
406 WIN_ReleaseWndPtr(pWnd);
408 if (hTopWnd && hWnd != hTopWnd)
409 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
410 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
413 msg->message = message;
415 return SYSQ_MSG_ACCEPT;
419 /***********************************************************************
422 * Processes a translated keyboard message
424 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
426 /* Handle F1 key by sending out WM_HELP message */
427 if ((msg->message == WM_KEYUP) &&
428 (msg->wParam == VK_F1) &&
429 (msg->hwnd != GetDesktopWindow()) &&
430 !MENU_IsMenuActive())
433 WND *pWnd = WIN_FindWndPtr(msg->hwnd);
437 hi.cbSize = sizeof(HELPINFO);
438 hi.iContextType = HELPINFO_WINDOW;
439 hi.iCtrlId = pWnd->wIDmenu;
440 hi.hItemHandle = msg->hwnd;
441 hi.dwContextId = pWnd->helpContext;
442 hi.MousePos = msg->pt;
443 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
445 WIN_ReleaseWndPtr(pWnd);
448 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
449 LOWORD (msg->wParam), msg->lParam )
450 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
454 /***********************************************************************
455 * MSG_JournalRecordMsg
457 * Build an EVENTMSG structure and call JOURNALRECORD hook
459 static void MSG_JournalRecordMsg( MSG *msg )
461 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
463 event->message = msg->message;
464 event->time = msg->time;
465 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
467 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
468 event->paramH = msg->lParam & 0x7FFF;
469 if (HIWORD(msg->lParam) & 0x0100)
470 event->paramH |= 0x8000; /* special_key - bit */
471 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
473 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
475 event->paramL = LOWORD(msg->lParam); /* X pos */
476 event->paramH = HIWORD(msg->lParam); /* Y pos */
477 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
478 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
480 else if ((msg->message >= WM_NCMOUSEFIRST) &&
481 (msg->message <= WM_NCMOUSELAST))
483 event->paramL = LOWORD(msg->lParam); /* X pos */
484 event->paramH = HIWORD(msg->lParam); /* Y pos */
485 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
486 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
489 HeapFree(SystemHeap, 0, event);
492 /***********************************************************************
493 * MSG_JournalPlayBackMsg
495 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
497 static int MSG_JournalPlayBackMsg(void)
500 long wtime,lParam,wParam;
501 WORD keyDown,i,result=0;
503 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
505 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
506 if (!tmpMsg) return result;
508 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
510 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
514 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
516 wParam=tmpMsg->paramL & 0xFF;
517 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
518 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
520 for (keyDown=i=0; i<256 && !keyDown; i++)
521 if (InputKeyStateTable[i] & 0x80)
524 lParam |= 0x40000000;
525 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
527 else /* WM_KEYUP, WM_SYSKEYUP */
529 lParam |= 0xC0000000;
530 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
532 if (InputKeyStateTable[VK_MENU] & 0x80)
533 lParam |= 0x20000000;
534 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
535 lParam |= 0x01000000;
536 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
537 0, 0, tmpMsg->time, 0 );
541 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
543 switch (tmpMsg->message)
546 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
548 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
550 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
552 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
554 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
556 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
558 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
559 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
560 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
561 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
562 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
564 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
565 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
566 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
567 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
568 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
571 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
577 if( tmpMsg->message == WM_QUEUESYNC )
578 if (HOOK_IsHooked( WH_CBT ))
579 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
581 result= QS_MOUSE | QS_KEY; /* ? */
583 HeapFree(SystemHeap, 0, tmpMsg);
588 /***********************************************************************
589 * MSG_PeekHardwareMsg
591 * Peek for a hardware message matching the hwnd and message filters.
593 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
596 /* FIXME: should deal with MSG32 instead of MSG16 */
598 DWORD status = SYSQ_MSG_ACCEPT;
599 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
600 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
601 QMSG *nextqmsg, *qmsg = 0;
604 EnterCriticalSection(&sysMsgQueue->cSection);
606 /* Loop through the Q and translate the message we wish to process
607 * while we own the lock. Based on the translation status (abandon/cont/accept)
608 * we then process the message accordingly
611 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
619 nextqmsg = qmsg->nextMsg;
621 /* Translate message */
623 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
625 HWND hWndScope = (HWND)qmsg->extraInfo;
626 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
627 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
629 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
630 &hittest, &screen_pt, &mouseClick );
633 WIN_ReleaseWndPtr(tmpWnd);
636 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
638 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
639 msgType = KEYBOARD_MSG;
641 else /* Non-standard hardware event */
643 HARDWAREHOOKSTRUCT16 *hook;
644 msgType = HARDWARE_MSG;
645 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
648 hook->hWnd = msg->hwnd;
649 hook->wMessage = msg->message & 0xffff;
650 hook->wParam = LOWORD (msg->wParam);
651 hook->lParam = msg->lParam;
652 ret = HOOK_CallHooks16( WH_HARDWARE,
653 remove ? HC_ACTION : HC_NOREMOVE,
654 0, (LPARAM)SEGPTR_GET(hook) );
658 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
661 status = SYSQ_MSG_ACCEPT;
666 switch (LOWORD(status))
668 case SYSQ_MSG_ACCEPT:
670 /* Remove the message from the system msg Q while it is still locked,
671 * before accepting it */
674 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
675 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
677 /* Now actually process the message, after we unlock the system msg Q.
678 * We should not hold on to the crst since SendMessage calls during processing
679 * will potentially cause callbacks to PeekMessage from the application.
680 * If we're holding the crst and QUEUE_WaitBits is called with a
681 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
682 * message is being posted to the Q.
684 LeaveCriticalSection(&sysMsgQueue->cSection);
685 if( msgType == KEYBOARD_MSG )
686 status = MSG_ProcessKbdMsg( msg, remove );
687 else if ( msgType == MOUSE_MSG )
688 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
690 /* Reclaim the sys msg Q crst */
691 EnterCriticalSection(&sysMsgQueue->cSection);
693 /* Pass the translated message to the user if it was accepted */
694 if (status == SYSQ_MSG_ACCEPT)
697 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
701 if (HOOK_IsHooked( WH_CBT ))
703 if( msgType == KEYBOARD_MSG )
704 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
705 LOWORD (msg->wParam), msg->lParam );
706 else if ( msgType == MOUSE_MSG )
708 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
711 CONV_POINT32TO16( &msg->pt,&hook->pt );
712 hook->hwnd = msg->hwnd;
713 hook->wHitTestCode = HIWORD(status);
714 hook->dwExtraInfo = 0;
715 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
716 (LPARAM)SEGPTR_GET(hook) );
722 /* If the message was removed earlier set up nextqmsg so that we start
723 * at the top of the queue again. We need to do this since our next pointer
724 * could be invalid due to us unlocking the system message Q to process the message.
725 * If not removed just refresh nextqmsg to point to the next msg.
728 nextqmsg = sysMsgQueue->firstMsg;
730 nextqmsg = qmsg->nextMsg;
734 case SYSQ_MSG_CONTINUE:
737 case SYSQ_MSG_ABANDON:
747 LeaveCriticalSection(&sysMsgQueue->cSection);
752 /**********************************************************************
753 * SetDoubleClickTime16 (USER.20)
755 void WINAPI SetDoubleClickTime16( UINT16 interval )
757 SetDoubleClickTime( interval );
761 /**********************************************************************
762 * SetDoubleClickTime (USER32.480)
764 BOOL WINAPI SetDoubleClickTime( UINT interval )
766 doubleClickSpeed = interval ? interval : 500;
771 /**********************************************************************
772 * GetDoubleClickTime16 (USER.21)
774 UINT16 WINAPI GetDoubleClickTime16(void)
776 return doubleClickSpeed;
780 /**********************************************************************
781 * GetDoubleClickTime (USER32.239)
783 UINT WINAPI GetDoubleClickTime(void)
785 return doubleClickSpeed;
789 /***********************************************************************
790 * MSG_SendMessageInterThread
792 * Implementation of an inter-task SendMessage.
794 * 0 if error or timeout
797 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
799 WPARAM wParam, LPARAM lParam,
800 DWORD timeout, WORD flags,
803 MESSAGEQUEUE *queue, *destQ;
810 if (IsTaskLocked16() || !IsWindow(hwnd))
813 /* create a SMSG structure to hold SendMessage() parameters */
814 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
816 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
818 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
820 QUEUE_Unlock( queue );
824 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
825 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
827 /* fill up SMSG structure */
830 smsg->wParam = wParam;
831 smsg->lParam = lParam;
834 smsg->hSrcQueue = GetFastQueue16();
835 smsg->hDstQueue = hDestQueue;
838 /* add smsg struct in the processing SM list of the source queue */
839 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
841 /* add smsg struct in the pending list of the destination queue */
842 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
845 iWndsLocks = WIN_SuspendWndsLock();
847 /* force destination task to run next, if 16 bit threads */
848 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
849 DirectedYield16( destQ->teb->htask16 );
851 /* wait for the result, note that 16-bit apps almost always get out of
852 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
857 * The sequence is crucial to avoid deadlock situations:
858 * - first, we clear the QS_SMRESULT bit
859 * - then, we check the SMSG_HAVE_RESULT bit
860 * - only if this isn't set, we enter the wait state.
862 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
863 * we are guaranteed that -should we now clear the QS_SMRESULT that
864 * was signalled already by the receiver- we will not start waiting.
867 if ( smsg->flags & SMSG_HAVE_RESULT )
870 *pRes = smsg->lResult;
871 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
875 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
877 if ( smsg->flags & SMSG_HAVE_RESULT )
880 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
882 /* return with timeout */
888 WIN_RestoreWndsLock(iWndsLocks);
890 /* remove the smsg from the processingg list of the source queue */
891 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
893 /* Note: the destination thread is in charge of removing the smsg from
896 /* In the case of an early reply (or a timeout), sender thread will
897 released the smsg structure if the receiver thread is done
898 (SMSG_RECEIVED set). If the receiver thread isn't done,
899 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
900 responsability to released smsg */
901 EnterCriticalSection( &queue->cSection );
903 if (smsg->flags & SMSG_RECEIVED)
904 HeapFree(SystemHeap, 0, smsg);
906 smsg->flags |= SMSG_RECEIVER_CLEANS;
908 LeaveCriticalSection( &queue->cSection );
911 QUEUE_Unlock( queue );
912 QUEUE_Unlock( destQ );
914 TRACE_(sendmsg)("done!\n");
919 /***********************************************************************
920 * ReplyMessage16 (USER.115)
922 void WINAPI ReplyMessage16( LRESULT result )
924 ReplyMessage( result );
927 /***********************************************************************
928 * ReplyMessage (USER.115)
930 BOOL WINAPI ReplyMessage( LRESULT result )
932 MESSAGEQUEUE *senderQ = 0;
933 MESSAGEQUEUE *queue = 0;
937 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
940 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
943 if ( !(smsg = queue->smWaiting)
944 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
945 goto ReplyMessageEnd;
947 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
949 /* This is the first reply, so pass result to sender */
951 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
953 EnterCriticalSection(&senderQ->cSection);
955 smsg->lResult = result;
956 smsg->flags |= SMSG_ALREADY_REPLIED;
958 /* check if it's an early reply (called by the application) or
959 a regular reply (called by ReceiveMessage) */
960 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
961 smsg->flags |= SMSG_EARLY_REPLY;
963 smsg->flags |= SMSG_HAVE_RESULT;
965 LeaveCriticalSection(&senderQ->cSection);
967 /* tell the sending task that its reply is ready */
968 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
970 /* switch directly to sending task (16 bit thread only) */
971 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
972 DirectedYield16( senderQ->teb->htask16 );
977 if (smsg->flags & SMSG_SENDING_REPLY)
979 /* remove msg from the waiting list, since this is the last
981 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
983 EnterCriticalSection(&senderQ->cSection);
985 /* tell the sender we're all done with smsg structure */
986 smsg->flags |= SMSG_RECEIVED;
988 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
989 receiver to clean up smsg, it could only happens when there is
990 an early reply or a timeout */
991 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
993 TRACE_(sendmsg)("Receiver cleans up!\n" );
994 HeapFree( SystemHeap, 0, smsg );
997 LeaveCriticalSection(&senderQ->cSection);
1002 QUEUE_Unlock( senderQ );
1004 QUEUE_Unlock( queue );
1009 /***********************************************************************
1012 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1017 switch ( MAKELONG( srcType, dstType ) )
1019 case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
1020 case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
1021 case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
1024 case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
1025 switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
1026 &msg->message, &msg->wParam, &msg->lParam ) )
1031 /* Pointer messages were mapped --> need to free allocated memory and fail */
1032 WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1037 case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
1038 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1039 &msg->message, &msg->wParam, &msg->lParam ) )
1044 /* Pointer messages were mapped --> need to free allocated memory and fail */
1045 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1050 case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
1051 mp16.lParam = msg->lParam;
1052 switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
1053 &msg16, &mp16.wParam, &mp16.lParam ) )
1056 msg->message = msg16;
1057 msg->wParam = mp16.wParam;
1058 msg->lParam = mp16.lParam;
1061 /* Pointer messages were mapped --> need to free allocated memory and fail */
1062 WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1067 case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
1068 mp16.lParam = msg->lParam;
1069 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1070 &msg16, &mp16.wParam, &mp16.lParam ) )
1073 msg->message = msg16;
1074 msg->wParam = mp16.wParam;
1075 msg->lParam = mp16.lParam;
1078 /* Pointer messages were mapped --> need to free allocated memory and fail */
1079 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1084 case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
1085 switch ( WINPROC_MapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
1090 /* Pointer messages were mapped --> need to free allocated memory and fail */
1091 WINPROC_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1096 case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
1097 switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
1102 /* Pointer messages were mapped --> need to free allocated memory and fail */
1103 WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1109 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1114 /***********************************************************************
1117 static BOOL MSG_PeekMessage( int type, LPMSG msg, HWND hwnd,
1118 DWORD first, DWORD last, WORD flags, BOOL peek )
1121 MESSAGEQUEUE *msgQueue;
1126 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
1129 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1130 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1131 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1132 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1133 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1134 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1136 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1138 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1140 /* Never yield on Win32 threads */
1141 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
1143 iWndsLocks = WIN_SuspendWndsLock();
1149 hQueue = GetFastQueue16();
1150 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1153 WIN_RestoreWndsLock(iWndsLocks);
1156 msgQueue->changeBits = 0;
1158 /* First handle a message put by SendMessage() */
1160 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1161 QUEUE_ReceiveMessage( msgQueue );
1163 /* Now handle a WM_QUIT message */
1165 if (msgQueue->wPostQMsg &&
1166 (!first || WM_QUIT >= first) &&
1167 (!last || WM_QUIT <= last) )
1170 msg->message = WM_QUIT;
1171 msg->wParam = msgQueue->wExitCode;
1173 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1177 /* Now find a normal message */
1180 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
1181 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1183 /* Try to convert message to requested type */
1184 MSG tmpMsg = qmsg->msg;
1185 if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
1187 ERR( "Message of wrong type contains pointer parameters. Skipped!\n ");
1188 QUEUE_RemoveMsg( msgQueue, qmsg );
1193 msgQueue->GetMessageTimeVal = msg->time;
1194 CONV_POINT32TO16(&msg->pt, &pt16);
1195 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1196 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1198 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1202 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
1204 /* Now find a hardware event */
1206 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
1207 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
1210 msgQueue->GetMessageTimeVal = msg->time;
1211 CONV_POINT32TO16(&msg->pt, &pt16);
1212 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1213 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1217 /* Check again for SendMessage */
1219 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1220 QUEUE_ReceiveMessage( msgQueue );
1222 /* Now find a WM_PAINT message */
1224 if ((msgQueue->wakeBits & mask) & QS_PAINT)
1227 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1228 msg->message = WM_PAINT;
1232 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
1234 if( wndPtr->dwStyle & WS_MINIMIZE &&
1235 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1237 msg->message = WM_PAINTICON;
1241 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1243 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1245 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1246 QUEUE_DecPaintCount( hQueue );
1248 WIN_ReleaseWndPtr(wndPtr);
1251 WIN_ReleaseWndPtr(wndPtr);
1255 /* Check for timer messages, but yield first */
1257 if (!(flags & PM_NOYIELD))
1260 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1261 QUEUE_ReceiveMessage( msgQueue );
1263 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1265 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1270 if (!(flags & PM_NOYIELD)) UserYield16();
1272 QUEUE_Unlock( msgQueue );
1273 WIN_RestoreWndsLock(iWndsLocks);
1276 msgQueue->wakeMask = mask;
1277 QUEUE_WaitBits( mask, INFINITE );
1278 QUEUE_Unlock( msgQueue );
1281 WIN_RestoreWndsLock(iWndsLocks);
1283 /* instead of unlocking queue for every break condition, all break
1284 condition will fall here */
1285 QUEUE_Unlock( msgQueue );
1287 /* We got a message */
1288 if (flags & PM_REMOVE)
1290 WORD message = msg->message;
1292 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1294 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1300 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1301 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1308 return (msg->message != WM_QUIT);
1311 /***********************************************************************
1312 * MSG_InternalGetMessage
1314 * GetMessage() function for internal use. Behave like GetMessage(),
1315 * but also call message filters and optionally send WM_ENTERIDLE messages.
1316 * 'hwnd' must be the handle of the dialog or menu window.
1317 * 'code' is the message filter value (MSGF_??? codes).
1319 BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
1320 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
1326 if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
1328 /* No message present -> send ENTERIDLE and wait */
1329 if (IsWindow(hwndOwner))
1331 SendMessageA( hwndOwner, WM_ENTERIDLE,
1332 code, (LPARAM)hwnd );
1337 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1340 else /* Always wait for a message */
1341 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1343 /* Call message filters */
1345 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1347 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1352 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1354 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1357 HeapFree( SystemHeap, 0, pmsg );
1360 /* Message filtered -> remove it from the queue */
1361 /* if it's still there. */
1362 if (!(flags & PM_REMOVE))
1363 MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
1369 return (msg->message != WM_QUIT);
1374 /***********************************************************************
1375 * PeekMessage32_16 (USER.819)
1377 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1378 UINT16 first, UINT16 last, UINT16 flags,
1379 BOOL16 wHaveParamHigh )
1384 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1386 lpmsg16_32->msg.hwnd = msg.hwnd;
1387 lpmsg16_32->msg.message = msg.message;
1388 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1389 lpmsg16_32->msg.lParam = msg.lParam;
1390 lpmsg16_32->msg.time = msg.time;
1391 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1392 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1394 if ( wHaveParamHigh )
1395 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1400 /***********************************************************************
1401 * PeekMessage16 (USER.109)
1403 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd,
1404 UINT16 first, UINT16 last, UINT16 flags )
1406 return PeekMessage32_16( (LPMSG16_32)lpmsg, hwnd, first, last, flags, FALSE );
1409 /***********************************************************************
1412 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1413 UINT min, UINT max, UINT wRemoveMsg)
1415 return MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1418 /***********************************************************************
1419 * PeekMessageW Check queue for messages
1421 * Checks for a message in the thread's queue, filtered as for
1422 * GetMessage(). Returns immediately whether a message is available
1425 * Whether a retrieved message is removed from the queue is set by the
1426 * _wRemoveMsg_ flags, which should be one of the following values:
1428 * PM_NOREMOVE Do not remove the message from the queue.
1430 * PM_REMOVE Remove the message from the queue.
1432 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1433 * request that the system not yield control during PeekMessage();
1434 * however applications may not rely on scheduling behavior.
1438 * Nonzero if a message is available and is retrieved, zero otherwise.
1445 BOOL WINAPI PeekMessageW(
1446 LPMSG lpmsg, /* buffer to receive message */
1447 HWND hwnd, /* restrict to messages for hwnd */
1448 UINT min, /* minimum message to receive */
1449 UINT max, /* maximum message to receive */
1450 UINT wRemoveMsg /* removal flags */
1453 return MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1457 /***********************************************************************
1458 * GetMessage32_16 (USER.820)
1460 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1461 UINT16 last, BOOL16 wHaveParamHigh )
1463 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1466 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1468 lpmsg16_32->msg.hwnd = msg.hwnd;
1469 lpmsg16_32->msg.message = msg.message;
1470 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1471 lpmsg16_32->msg.lParam = msg.lParam;
1472 lpmsg16_32->msg.time = msg.time;
1473 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1474 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1476 if ( wHaveParamHigh )
1477 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1479 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1480 lpmsg16_32->msg.message, hWnd, first, last );
1482 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg16_32 );
1483 return lpmsg16_32->msg.message != WM_QUIT;
1486 /***********************************************************************
1487 * GetMessage16 (USER.108)
1489 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1491 return GetMessage32_16( msg, hwnd, first, last, FALSE );
1494 /***********************************************************************
1495 * GetMessageA (USER32.270)
1497 BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
1499 MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1501 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1502 lpmsg->message, hwnd, min, max );
1504 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1505 return lpmsg->message != WM_QUIT;
1508 /***********************************************************************
1509 * GetMessageW (USER32.274) Retrieve next message
1511 * GetMessage retrieves the next event from the calling thread's
1512 * queue and deposits it in *lpmsg.
1514 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1515 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1516 * all application messages are retrieved.
1518 * _min_ and _max_ specify the range of messages of interest. If
1519 * min==max==0, no filtering is performed. Useful examples are
1520 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1521 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1523 * WM_PAINT messages are not removed from the queue; they remain until
1524 * processed. Other messages are removed from the queue.
1528 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1535 BOOL WINAPI GetMessageW(
1536 MSG* lpmsg, /* buffer to receive message */
1537 HWND hwnd, /* restrict to messages for hwnd */
1538 UINT min, /* minimum message to receive */
1539 UINT max /* maximum message to receive */
1542 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1544 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1545 lpmsg->message, hwnd, min, max );
1547 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1548 return lpmsg->message != WM_QUIT;
1551 /***********************************************************************
1554 static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
1555 UINT message, WPARAM wParam, LPARAM lParam )
1559 if ( !hQueue ) return FALSE;
1562 msg.message = message;
1563 msg.wParam = wParam;
1564 msg.lParam = lParam;
1565 msg.time = GetTickCount();
1569 return QUEUE_AddMsg( hQueue, type, &msg, 0 );
1572 /***********************************************************************
1575 static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1576 WPARAM wParam, LPARAM lParam )
1581 if (hwnd == HWND_BROADCAST)
1583 WND *pDesktop = WIN_GetDesktop();
1584 TRACE("HWND_BROADCAST !\n");
1586 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1588 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1590 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1591 wndPtr->hwndSelf, message, wParam, lParam);
1592 MSG_PostToQueue( wndPtr->hmemTaskQ, type,
1593 wndPtr->hwndSelf, message, wParam, lParam );
1596 WIN_ReleaseDesktop();
1597 TRACE("End of HWND_BROADCAST !\n");
1601 wndPtr = WIN_FindWndPtr( hwnd );
1602 hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
1603 WIN_ReleaseWndPtr(wndPtr);
1605 return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
1608 /***********************************************************************
1609 * PostMessage16 (USER.110)
1611 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1614 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
1617 /***********************************************************************
1618 * PostMessageA (USER32.419)
1620 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1623 return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
1626 /***********************************************************************
1627 * PostMessageW (USER32.420)
1629 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1632 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1635 /***********************************************************************
1636 * PostAppMessage16 (USER.116)
1638 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1639 WPARAM16 wParam, LPARAM lParam )
1641 return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
1642 0, message, wParam, lParam );
1645 /**********************************************************************
1646 * PostThreadMessageA (USER32.422)
1648 BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1649 WPARAM wParam, LPARAM lParam )
1651 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
1652 0, message, wParam, lParam );
1655 /**********************************************************************
1656 * PostThreadMessageW (USER32.423)
1658 BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1659 WPARAM wParam, LPARAM lParam )
1661 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
1662 0, message, wParam, lParam );
1666 /************************************************************************
1667 * MSG_CallWndProcHook32
1669 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1673 cwp.lParam = pmsg->lParam;
1674 cwp.wParam = pmsg->wParam;
1675 cwp.message = pmsg->message;
1676 cwp.hwnd = pmsg->hwnd;
1678 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1679 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1681 pmsg->lParam = cwp.lParam;
1682 pmsg->wParam = cwp.wParam;
1683 pmsg->message = cwp.message;
1684 pmsg->hwnd = cwp.hwnd;
1688 /***********************************************************************
1691 * return values: 0 if timeout occurs
1694 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1695 LPARAM lParam, DWORD timeout, WORD flags,
1699 WND **list, **ppWnd;
1704 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1708 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1710 WIN_ReleaseDesktop();
1713 WIN_ReleaseDesktop();
1715 TRACE("HWND_BROADCAST !\n");
1716 for (ppWnd = list; *ppWnd; ppWnd++)
1718 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1719 if (!IsWindow(wndPtr->hwndSelf)) continue;
1720 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1722 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1723 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1724 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1725 timeout, flags, pRes);
1728 WIN_ReleaseWndPtr(wndPtr);
1729 WIN_ReleaseWinArray(list);
1730 TRACE("End of HWND_BROADCAST !\n");
1734 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1736 if (flags & SMSG_UNICODE)
1737 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1738 else if (flags & SMSG_WIN32)
1739 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1744 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1746 pmsg->hwnd = hwnd & 0xffff;
1747 pmsg->message= msg & 0xffff;
1748 pmsg->wParam = wParam & 0xffff;
1749 pmsg->lParam = lParam;
1750 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1751 (LPARAM)SEGPTR_GET(pmsg) );
1753 msg = pmsg->message;
1754 wParam = pmsg->wParam;
1755 lParam = pmsg->lParam;
1756 SEGPTR_FREE( pmsg );
1761 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1763 WARN("invalid hwnd %04x\n", hwnd );
1766 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1768 ret = 0; /* Don't send anything if the task is dying */
1771 if (flags & SMSG_WIN32)
1772 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1774 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1776 if (wndPtr->hmemTaskQ != GetFastQueue16())
1777 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1778 wParam, lParam, timeout, flags, pRes );
1781 /* Call the right CallWindowProc flavor */
1782 if (flags & SMSG_UNICODE)
1783 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1784 hwnd, msg, wParam, lParam );
1785 else if (flags & SMSG_WIN32)
1786 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1787 hwnd, msg, wParam, lParam );
1789 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1790 (HWND16) hwnd, (UINT16) msg,
1791 (WPARAM16) wParam, lParam );
1794 if (flags & SMSG_WIN32)
1795 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, *pRes );
1797 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, *pRes );
1799 WIN_ReleaseWndPtr(wndPtr);
1804 /***********************************************************************
1805 * SendMessage16 (USER.111)
1807 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1811 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1816 /***********************************************************************
1817 * SendMessageA (USER32.454)
1819 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1824 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1831 /***********************************************************************
1832 * SendMessageW (USER32.459) Send Window Message
1834 * Sends a message to the window procedure of the specified window.
1835 * SendMessage() will not return until the called window procedure
1836 * either returns or calls ReplyMessage().
1838 * Use PostMessage() to send message and return immediately. A window
1839 * procedure may use InSendMessage() to detect
1840 * SendMessage()-originated messages.
1842 * Applications which communicate via HWND_BROADCAST may use
1843 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1844 * with other applications.
1850 LRESULT WINAPI SendMessageW(
1851 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1852 the message will be sent to all top-level windows. */
1854 UINT msg, /* message */
1855 WPARAM wParam, /* message parameter */
1856 LPARAM lParam /* additional message parameter */
1860 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1861 SMSG_WIN32 | SMSG_UNICODE, &res);
1867 /***********************************************************************
1868 * SendMessageTimeout16 (not a WINAPI)
1870 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1871 LPARAM lParam, UINT16 flags,
1872 UINT16 timeout, LPWORD resultp)
1877 /* FIXME: need support for SMTO_BLOCK */
1879 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1880 if (resultp) *resultp = (WORD) msgRet;
1885 /***********************************************************************
1886 * SendMessageTimeoutA (USER32.457)
1888 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1889 LPARAM lParam, UINT flags,
1890 UINT timeout, LPDWORD resultp)
1895 /* FIXME: need support for SMTO_BLOCK */
1897 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1900 if (resultp) *resultp = (DWORD) msgRet;
1905 /***********************************************************************
1906 * SendMessageTimeoutW (USER32.458)
1908 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1909 LPARAM lParam, UINT flags,
1910 UINT timeout, LPDWORD resultp)
1915 /* FIXME: need support for SMTO_BLOCK */
1917 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1918 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1920 if (resultp) *resultp = (DWORD) msgRet;
1925 /***********************************************************************
1926 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1928 * WaitMessage() suspends a thread until events appear in the thread's
1933 * Is supposed to return BOOL under Win32.
1935 * Thread-local message queues are not supported.
1942 void WINAPI WaitMessage( void )
1944 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1947 /***********************************************************************
1948 * MsgWaitForMultipleObjects (USER32.400)
1950 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1951 BOOL fWaitAll, DWORD dwMilliseconds,
1955 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1957 PDB * pdb = PROCESS_Current();
1959 HQUEUE16 hQueue = GetFastQueue16();
1960 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1961 if (!msgQueue) return WAIT_FAILED;
1963 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1965 SetLastError( ERROR_INVALID_PARAMETER );
1966 QUEUE_Unlock( msgQueue );
1970 msgQueue->changeBits = 0;
1971 msgQueue->wakeMask = dwWakeMask;
1973 if (THREAD_IsWin16(NtCurrentTeb()))
1976 * This is a temporary solution to a big problem.
1977 * You see, the main thread of all Win32 programs is created as a 16 bit
1978 * task. This means that if you want on an event using Win32 synchronization
1979 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1980 * This implements a semi-busy loop that checks the handles to wait on and
1981 * also the message queue. When either one is ready, the wait function returns.
1983 * This will all go away when the real Win32 threads are implemented for all
1984 * the threads of an applications. Including the main thread.
1986 DWORD curTime = GetCurrentTime();
1991 * Check the handles in the list.
1993 SetEvent ( pdb->idle_event );
1994 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1997 * If the handles have been triggered, return.
1999 if (ret != WAIT_TIMEOUT)
2003 * Then, let the 16 bit scheduler do it's thing.
2008 * If a message matching the wait mask has arrived, return.
2010 if (msgQueue->changeBits & dwWakeMask)
2017 * And continue doing this until we hit the timeout.
2019 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
2023 /* Add the thread event to the handle list */
2024 for (i = 0; i < nCount; i++)
2025 handles[i] = pHandles[i];
2026 handles[nCount] = msgQueue->hEvent;
2028 if ( pdb->main_queue == INVALID_HANDLE_VALUE16 ) pdb->main_queue = hQueue;
2029 if ( pdb->main_queue == hQueue ) SetEvent ( pdb->idle_event );
2030 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
2031 if ( pdb->main_queue == hQueue ) ResetEvent ( pdb->idle_event );
2035 QUEUE_Unlock( msgQueue );
2049 static const struct accent_char accent_chars[] =
2051 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2052 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2053 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2054 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2055 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2056 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2057 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2058 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2059 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2060 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2061 {',', 'C', '\307'}, {',', 'c', '\347'},
2062 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2063 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2064 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2065 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2066 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2067 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2068 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2069 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2070 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2071 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2072 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2073 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2074 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2075 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2076 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2077 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2078 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2079 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2080 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2081 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2082 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2083 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2084 {'s', 's', '\337'}, {'"', 'y', '\377'},
2085 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2086 /* iso-8859-2 uses this */
2087 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2088 {'<', 'S', '\251'}, {'<', 's', '\271'},
2089 {'<', 'T', '\253'}, {'<', 't', '\273'},
2090 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2091 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2092 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2093 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2094 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2095 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2096 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2097 {';', 'E', '\312'}, {';', 'e', '\332'},
2098 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2099 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2100 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2101 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2102 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2103 /* collision whith S, from iso-8859-9 !!! */
2104 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2105 {',', 'T', '\336'}, {',', 't', '\376'},
2106 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2107 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2108 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2109 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2110 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2111 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2112 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2113 /* iso-8859-3 uses this */
2114 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2115 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2116 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2117 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2118 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2119 {'>', 'S', '\336'}, {'>', 's', '\376'},
2120 /* collision whith G( from iso-8859-9 !!! */
2121 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2122 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2123 /* collision whith I. from iso-8859-3 !!! */
2124 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2125 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2126 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2127 /* iso-8859-4 uses this */
2128 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2129 {',', 'L', '\246'}, {',', 'l', '\266'},
2130 {',', 'G', '\253'}, {',', 'g', '\273'},
2131 {',', 'N', '\321'}, {',', 'n', '\361'},
2132 {',', 'K', '\323'}, {',', 'k', '\363'},
2133 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2134 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2135 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2136 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2137 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2138 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2139 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2140 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2141 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2142 {';', 'U', '\331'}, {';', 'u', '\371'},
2143 /* iso-8859-9 uses this */
2144 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2145 * whith the same letters on other iso-8859-x (that is they are on
2146 * different places :-( ), if you use turkish uncomment these and
2147 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2148 * FIXME: should be dynamic according to chosen language
2149 * if/when Wine has turkish support.
2151 /* collision whith G( from iso-8859-3 !!! */
2152 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2153 /* collision whith S, from iso-8859-2 !!! */
2154 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2155 /* collision whith I. from iso-8859-3 !!! */
2156 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2160 /***********************************************************************
2161 * MSG_DoTranslateMessage
2163 * Implementation of TranslateMessage.
2165 * TranslateMessage translates virtual-key messages into character-messages,
2167 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2168 * ditto replacing WM_* with WM_SYS*
2169 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2170 * by the keyboard driver.
2172 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2173 WPARAM wParam, LPARAM lParam )
2175 static int dead_char;
2178 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2179 TRACE("(%s, %04X, %08lX)\n",
2180 SPY_GetMsgName(message), wParam, lParam );
2181 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2182 TRACE_(key)("(%s, %04X, %08lX)\n",
2183 SPY_GetMsgName(message), wParam, lParam );
2185 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2187 TRACE_(key)("Translating key %04X, scancode %04X\n",
2188 wParam, HIWORD(lParam) );
2190 /* FIXME : should handle ToAscii yielding 2 */
2191 switch (ToAscii(wParam, HIWORD(lParam),
2192 QueueKeyStateTable,(LPWORD)wp, 0))
2195 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2196 /* Should dead chars handling go in ToAscii ? */
2201 if (wp[0] == ' ') wp[0] = dead_char;
2202 if (dead_char == 0xa2) dead_char = '(';
2203 else if (dead_char == 0xa8) dead_char = '"';
2204 else if (dead_char == 0xb2) dead_char = ';';
2205 else if (dead_char == 0xb4) dead_char = '\'';
2206 else if (dead_char == 0xb7) dead_char = '<';
2207 else if (dead_char == 0xb8) dead_char = ',';
2208 else if (dead_char == 0xff) dead_char = '.';
2209 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2210 if ((accent_chars[i].ac_accent == dead_char) &&
2211 (accent_chars[i].ac_char == wp[0]))
2213 wp[0] = accent_chars[i].ac_result;
2218 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2219 PostMessage16( hwnd, message, wp[0], lParam );
2223 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2225 TRACE_(key)("-1 -> PostMessage(%s)\n",
2226 SPY_GetMsgName(message));
2227 PostMessage16( hwnd, message, wp[0], lParam );
2234 /***********************************************************************
2235 * TranslateMessage16 (USER.113)
2237 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2239 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2240 msg->wParam, msg->lParam );
2244 /***********************************************************************
2245 * WIN16_TranslateMessage32 (USER.821)
2247 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2252 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2254 wParam = (WPARAM)msg->msg.wParam;
2256 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2257 wParam, msg->msg.lParam );
2260 /***********************************************************************
2261 * TranslateMessage (USER32.556)
2263 BOOL WINAPI TranslateMessage( const MSG *msg )
2265 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2266 msg->wParam, msg->lParam );
2270 /***********************************************************************
2271 * DispatchMessage16 (USER.114)
2273 LONG WINAPI DispatchMessage16( const MSG16* msg )
2279 /* Process timer messages */
2280 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2284 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2285 msg->message, msg->wParam, GetTickCount() );
2289 if (!msg->hwnd) return 0;
2290 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2291 if (!wndPtr->winproc)
2296 painting = (msg->message == WM_PAINT);
2297 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2299 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2300 msg->wParam, msg->lParam );
2301 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2302 msg->hwnd, msg->message,
2303 msg->wParam, msg->lParam );
2304 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2306 WIN_ReleaseWndPtr(wndPtr);
2307 wndPtr = WIN_FindWndPtr(msg->hwnd);
2308 if (painting && wndPtr &&
2309 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2311 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2313 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2314 /* Validate the update region to avoid infinite WM_PAINT loop */
2315 ValidateRect( msg->hwnd, NULL );
2318 WIN_ReleaseWndPtr(wndPtr);
2323 /***********************************************************************
2324 * WIN16_DispatchMessage32 (USER.822)
2326 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2328 if (wHaveParamHigh == FALSE)
2329 return DispatchMessage16(&(lpmsg16_32->msg));
2334 msg.hwnd = lpmsg16_32->msg.hwnd;
2335 msg.message = lpmsg16_32->msg.message;
2336 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2337 msg.lParam = lpmsg16_32->msg.lParam;
2338 msg.time = lpmsg16_32->msg.time;
2339 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2340 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2341 return DispatchMessageA(&msg);
2345 /***********************************************************************
2346 * DispatchMessageA (USER32.141)
2348 LONG WINAPI DispatchMessageA( const MSG* msg )
2354 /* Process timer messages */
2355 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2359 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2360 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2361 msg->message, msg->wParam, GetTickCount() );
2365 if (!msg->hwnd) return 0;
2366 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2367 if (!wndPtr->winproc)
2372 painting = (msg->message == WM_PAINT);
2373 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2374 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2376 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2377 msg->wParam, msg->lParam );
2378 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2379 msg->hwnd, msg->message,
2380 msg->wParam, msg->lParam );
2381 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2383 WIN_ReleaseWndPtr(wndPtr);
2384 wndPtr = WIN_FindWndPtr(msg->hwnd);
2386 if (painting && wndPtr &&
2387 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2389 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2391 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2392 /* Validate the update region to avoid infinite WM_PAINT loop */
2393 ValidateRect( msg->hwnd, NULL );
2396 WIN_ReleaseWndPtr(wndPtr);
2401 /***********************************************************************
2402 * DispatchMessageW (USER32.142) Process Message
2404 * Process the message specified in the structure *_msg_.
2406 * If the lpMsg parameter points to a WM_TIMER message and the
2407 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2408 * points to the function that is called instead of the window
2411 * The message must be valid.
2415 * DispatchMessage() returns the result of the window procedure invoked.
2422 LONG WINAPI DispatchMessageW( const MSG* msg )
2428 /* Process timer messages */
2429 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2433 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2434 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2435 msg->message, msg->wParam, GetTickCount() );
2439 if (!msg->hwnd) return 0;
2440 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2441 if (!wndPtr->winproc)
2446 painting = (msg->message == WM_PAINT);
2447 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2448 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2450 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2451 msg->wParam, msg->lParam );
2452 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2453 msg->hwnd, msg->message,
2454 msg->wParam, msg->lParam );
2455 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2457 WIN_ReleaseWndPtr(wndPtr);
2458 wndPtr = WIN_FindWndPtr(msg->hwnd);
2460 if (painting && wndPtr &&
2461 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2463 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2465 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2466 /* Validate the update region to avoid infinite WM_PAINT loop */
2467 ValidateRect( msg->hwnd, NULL );
2470 WIN_ReleaseWndPtr(wndPtr);
2475 /***********************************************************************
2476 * RegisterWindowMessageA (USER.118) (USER32.437)
2478 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2480 TRACE("%s\n", str );
2481 return GlobalAddAtomA( str );
2485 /***********************************************************************
2486 * RegisterWindowMessageW (USER32.438)
2488 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2490 TRACE("%p\n", str );
2491 return GlobalAddAtomW( str );
2495 /***********************************************************************
2496 * GetCurrentTime16 (USER.15)
2498 * (effectively identical to GetTickCount)
2500 DWORD WINAPI GetCurrentTime16(void)
2502 return GetTickCount();
2506 /***********************************************************************
2507 * InSendMessage16 (USER.192)
2509 BOOL16 WINAPI InSendMessage16(void)
2511 return InSendMessage();
2515 /***********************************************************************
2516 * InSendMessage (USER32.320)
2518 BOOL WINAPI InSendMessage(void)
2520 MESSAGEQUEUE *queue;
2523 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2525 ret = (BOOL)queue->smWaiting;
2527 QUEUE_Unlock( queue );
2531 /***********************************************************************
2532 * BroadcastSystemMessage (USER32.12)
2534 LONG WINAPI BroadcastSystemMessage(
2535 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2538 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2539 dwFlags,*recipients,uMessage,wParam,lParam
2544 /***********************************************************************
2545 * SendNotifyMessageA (USER32.460)
2547 * The message sended with PostMessage has to be put in the queue
2548 * with a higher priority as the other "Posted" messages.
2549 * QUEUE_AddMsg has to be modifyed.
2551 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2553 FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
2554 hwnd, msg, wParam, lParam);
2556 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2557 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2560 { PostMessageA ( hwnd, msg, wParam, lParam );
2565 /***********************************************************************
2566 * SendNotifyMessageW (USER32.461)
2568 * The message sended with PostMessage has to be put in the queue
2569 * with a higher priority as the other "Posted" messages.
2570 * QUEUE_AddMsg has to be modifyed.
2572 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2574 FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
2575 hwnd, msg, wParam, lParam);
2577 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2578 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2581 { PostMessageW ( hwnd, msg, wParam, lParam );
2586 /***********************************************************************
2587 * SendMessageCallbackA
2588 * FIXME: It's like PostMessage. The callback gets called when the message
2589 * is processed. We have to modify the message processing for a exact
2592 BOOL WINAPI SendMessageCallbackA(
2593 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2594 FARPROC lpResultCallBack,DWORD dwData)
2596 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2597 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2598 if ( hWnd == HWND_BROADCAST)
2599 { PostMessageA( hWnd, Msg, wParam, lParam);
2600 FIXME("Broadcast: Callback will not be called!\n");
2603 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2606 /***********************************************************************
2607 * SendMessageCallbackW
2608 * FIXME: It's like PostMessage. The callback gets called when the message
2609 * is processed. We have to modify the message processing for a exact
2612 BOOL WINAPI SendMessageCallbackW(
2613 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2614 FARPROC lpResultCallBack,DWORD dwData)
2616 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2617 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2618 if ( hWnd == HWND_BROADCAST)
2619 { PostMessageW( hWnd, Msg, wParam, lParam);
2620 FIXME("Broadcast: Callback will not be called!\n");
2623 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));