VxDCall functions do not need to be 'register'.
[wine/multimedia.git] / windows / message.c
blob60c08de0a35b77a9eae15fb40ce206eff2ad4e37
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <sys/time.h>
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
14 #include "message.h"
15 #include "winerror.h"
16 #include "win.h"
17 #include "sysmetrics.h"
18 #include "heap.h"
19 #include "hook.h"
20 #include "input.h"
21 #include "spy.h"
22 #include "winpos.h"
23 #include "dde.h"
24 #include "queue.h"
25 #include "winproc.h"
26 #include "task.h"
27 #include "process.h"
28 #include "thread.h"
29 #include "options.h"
30 #include "struct32.h"
31 #include "debugtools.h"
33 DECLARE_DEBUG_CHANNEL(key)
34 DECLARE_DEBUG_CHANNEL(msg)
35 DECLARE_DEBUG_CHANNEL(sendmsg)
37 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
38 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
41 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
42 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
44 extern HQUEUE16 hCursorQueue; /* queue.c */
46 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
48 static UINT doubleClickSpeed = 452;
50 /***********************************************************************
51 * MSG_CheckFilter
53 BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
55 if( first || last )
56 return (uMsg >= first && uMsg <= last);
57 return TRUE;
60 /***********************************************************************
61 * MSG_SendParentNotify
63 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
64 * the window has the WS_EX_NOPARENTNOTIFY style.
66 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
68 #define lppt ((LPPOINT16)&lValue)
70 /* pt has to be in the client coordinates of the parent window */
71 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
73 MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
74 while (tmpWnd)
76 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
78 WIN_ReleaseWndPtr(tmpWnd);
79 break;
81 lppt->x += tmpWnd->rectClient.left;
82 lppt->y += tmpWnd->rectClient.top;
83 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
84 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
85 MAKEWPARAM( event, idChild ), lValue );
88 #undef lppt
92 /***********************************************************************
93 * MSG_TranslateMouseMsg
95 * Translate an mouse hardware event into a real mouse message.
96 * Return value indicates whether the translated message must be passed
97 * to the user, left in the queue, or skipped entirely (in this case
98 * HIWORD contains hit test code).
100 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
101 MSG *msg, BOOL remove, WND* pWndScope )
103 static DWORD dblclk_time_limit = 0;
104 static UINT16 clk_message = 0;
105 static HWND16 clk_hwnd = 0;
106 static POINT16 clk_pos = { 0, 0 };
108 WND *pWnd;
109 HWND hWnd;
110 INT16 ht, hittest, sendSC = 0;
111 UINT message = msg->message;
112 POINT16 screen_pt, pt;
113 HANDLE16 hQ = GetFastQueue16();
114 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
115 BOOL eatMsg = FALSE;
116 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
117 (message == WM_RBUTTONDOWN) ||
118 (message == WM_MBUTTONDOWN))?1:0;
119 SYSQ_STATUS ret = 0;
120 DWORD retvalue;
122 /* Find the window */
124 CONV_POINT32TO16( &msg->pt, &pt );
126 ht = hittest = HTCLIENT;
127 hWnd = GetCapture();
128 if( !hWnd )
130 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
131 if( !pWnd ) pWnd = WIN_GetDesktop();
132 else WIN_LockWndPtr(pWnd);
133 hWnd = pWnd->hwndSelf;
134 sendSC = 1;
136 else
138 pWnd = WIN_FindWndPtr(hWnd);
139 if (queue)
140 ht = PERQDATA_GetCaptureInfo( queue->pQData );
143 /* stop if not the right queue */
145 if (pWnd->hmemTaskQ != hQ)
147 /* Not for the current task */
148 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
149 /* Wake up the other task */
150 QUEUE_Unlock( queue );
151 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
152 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
154 QUEUE_Unlock( queue );
155 retvalue = SYSQ_MSG_ABANDON;
156 goto END;
159 /* check if hWnd is within hWndScope */
161 if( hTopWnd && hWnd != hTopWnd )
162 if( !IsChild(hTopWnd, hWnd) )
164 QUEUE_Unlock( queue );
165 retvalue = SYSQ_MSG_CONTINUE;
166 goto END;
169 if( mouseClick )
171 /* translate double clicks -
172 * note that ...MOUSEMOVEs can slip in between
173 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
175 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
177 if ((message == clk_message) && (hWnd == clk_hwnd) &&
178 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
179 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
180 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
182 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
183 mouseClick++; /* == 2 */
187 screen_pt = pt;
189 if (hittest != HTCLIENT)
191 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
192 msg->wParam = hittest;
194 else ScreenToClient16( hWnd, &pt );
196 /* check message filter */
198 if (!MSG_CheckFilter(message, first, last))
200 QUEUE_Unlock(queue);
201 retvalue = SYSQ_MSG_CONTINUE;
202 goto END;
205 hCursorQueue = queue->self;
206 QUEUE_Unlock(queue);
209 /* call WH_MOUSE */
211 if (HOOK_IsHooked( WH_MOUSE ))
213 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
214 if( hook )
216 hook->pt = screen_pt;
217 hook->hwnd = hWnd;
218 hook->wHitTestCode = hittest;
219 hook->dwExtraInfo = 0;
220 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
221 message, (LPARAM)SEGPTR_GET(hook) );
222 SEGPTR_FREE(hook);
224 if( ret )
226 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
227 goto END;
233 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
234 eatMsg = sendSC = 1;
235 else if( remove && mouseClick )
237 HWND hwndTop = WIN_GetTopParent( hWnd );
239 if( mouseClick == 1 )
241 /* set conditions */
242 dblclk_time_limit = msg->time;
243 clk_message = msg->message;
244 clk_hwnd = hWnd;
245 clk_pos = screen_pt;
246 } else
247 /* got double click - zero them out */
248 dblclk_time_limit = clk_hwnd = 0;
250 if( sendSC )
252 /* Send the WM_PARENTNOTIFY,
253 * note that even for double/nonclient clicks
254 * notification message is still WM_L/M/RBUTTONDOWN.
257 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
259 /* Activate the window if needed */
261 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
263 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
264 MAKELONG( hittest, message ) );
266 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
267 eatMsg = TRUE;
269 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
270 && hwndTop != GetActiveWindow() )
271 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
272 eatMsg = TRUE;
275 } else sendSC = (remove && sendSC);
277 /* Send the WM_SETCURSOR message */
279 if (sendSC)
280 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
281 MAKELONG( hittest, message ));
282 if (eatMsg)
284 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
285 goto END;
288 msg->hwnd = hWnd;
289 msg->message = message;
290 msg->lParam = MAKELONG( pt.x, pt.y );
291 retvalue = SYSQ_MSG_ACCEPT;
292 END:
293 WIN_ReleaseWndPtr(pWnd);
295 return retvalue;
299 /***********************************************************************
300 * MSG_TranslateKbdMsg
302 * Translate an keyboard hardware event into a real message.
304 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
305 MSG *msg, BOOL remove )
307 WORD message = msg->message;
308 HWND hWnd = GetFocus();
309 WND *pWnd;
311 /* Should check Ctrl-Esc and PrintScreen here */
313 if (!hWnd)
315 /* Send the message to the active window instead, */
316 /* translating messages to their WM_SYS equivalent */
318 hWnd = GetActiveWindow();
320 if( message < WM_SYSKEYDOWN )
321 message += WM_SYSKEYDOWN - WM_KEYDOWN;
323 pWnd = WIN_FindWndPtr( hWnd );
324 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
326 /* Not for the current task */
327 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
328 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
329 QUEUE_Unlock( queue );
331 /* Wake up the other task */
332 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
333 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
334 QUEUE_Unlock( queue );
335 WIN_ReleaseWndPtr(pWnd);
336 return SYSQ_MSG_ABANDON;
338 WIN_ReleaseWndPtr(pWnd);
340 if (hTopWnd && hWnd != hTopWnd)
341 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
342 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
344 msg->hwnd = hWnd;
345 msg->message = message;
347 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
348 LOWORD (msg->wParam), msg->lParam )
349 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
353 /***********************************************************************
354 * MSG_JournalRecordMsg
356 * Build an EVENTMSG structure and call JOURNALRECORD hook
358 static void MSG_JournalRecordMsg( MSG *msg )
360 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
361 if (!event) return;
362 event->message = msg->message;
363 event->time = msg->time;
364 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
366 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
367 event->paramH = msg->lParam & 0x7FFF;
368 if (HIWORD(msg->lParam) & 0x0100)
369 event->paramH |= 0x8000; /* special_key - bit */
370 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
372 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
374 event->paramL = LOWORD(msg->lParam); /* X pos */
375 event->paramH = HIWORD(msg->lParam); /* Y pos */
376 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
377 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
379 else if ((msg->message >= WM_NCMOUSEFIRST) &&
380 (msg->message <= WM_NCMOUSELAST))
382 event->paramL = LOWORD(msg->lParam); /* X pos */
383 event->paramH = HIWORD(msg->lParam); /* Y pos */
384 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
385 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
388 HeapFree(SystemHeap, 0, event);
391 /***********************************************************************
392 * MSG_JournalPlayBackMsg
394 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
396 static int MSG_JournalPlayBackMsg(void)
398 EVENTMSG *tmpMsg;
399 long wtime,lParam,wParam;
400 WORD keyDown,i,result=0;
402 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
404 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
405 if (!tmpMsg) return result;
407 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
408 (LPARAM) tmpMsg );
409 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
410 if (wtime<=0)
412 wtime=0;
413 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
415 wParam=tmpMsg->paramL & 0xFF;
416 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
417 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
419 for (keyDown=i=0; i<256 && !keyDown; i++)
420 if (InputKeyStateTable[i] & 0x80)
421 keyDown++;
422 if (!keyDown)
423 lParam |= 0x40000000;
424 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
426 else /* WM_KEYUP, WM_SYSKEYUP */
428 lParam |= 0xC0000000;
429 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
431 if (InputKeyStateTable[VK_MENU] & 0x80)
432 lParam |= 0x20000000;
433 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
434 lParam |= 0x01000000;
435 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
436 0, 0, tmpMsg->time, 0 );
438 else
440 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
442 switch (tmpMsg->message)
444 case WM_LBUTTONDOWN:
445 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
446 case WM_LBUTTONUP:
447 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
448 case WM_MBUTTONDOWN:
449 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
450 case WM_MBUTTONUP:
451 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
452 case WM_RBUTTONDOWN:
453 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
454 case WM_RBUTTONUP:
455 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
457 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
458 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
459 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
460 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
461 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
462 wParam=0;
463 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
464 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
465 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
466 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
467 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
470 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
471 (LPARAM) tmpMsg);
473 else
476 if( tmpMsg->message == WM_QUEUESYNC )
477 if (HOOK_IsHooked( WH_CBT ))
478 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
480 result= QS_MOUSE | QS_KEY; /* ? */
482 HeapFree(SystemHeap, 0, tmpMsg);
484 return result;
487 /***********************************************************************
488 * MSG_PeekHardwareMsg
490 * Peek for a hardware message matching the hwnd and message filters.
492 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
493 BOOL remove )
495 /* FIXME: should deal with MSG32 instead of MSG16 */
497 DWORD status = SYSQ_MSG_ACCEPT;
498 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
499 int kbd_msg;
500 QMSG *nextqmsg, *qmsg = 0;
502 /* FIXME: there has to be a better way to do this */
503 joySendMessages();
505 EnterCriticalSection(&sysMsgQueue->cSection);
507 qmsg = sysMsgQueue->firstMsg;
509 /* If the queue is empty, attempt to fill it */
510 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
511 && EVENT_Pending())
513 LeaveCriticalSection(&sysMsgQueue->cSection);
514 EVENT_WaitNetEvent( FALSE, TRUE );
515 EnterCriticalSection(&sysMsgQueue->cSection);
518 for ( kbd_msg = 0; qmsg; qmsg = nextqmsg)
521 *msg = qmsg->msg;
523 nextqmsg = qmsg->nextMsg;
525 /* Translate message */
527 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
530 HWND hWndScope = (HWND)qmsg->extraInfo;
531 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
532 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
534 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove,tmpWnd );
535 kbd_msg = 0;
537 WIN_ReleaseWndPtr(tmpWnd);
540 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
542 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
543 kbd_msg = 1;
545 else /* Non-standard hardware event */
547 HARDWAREHOOKSTRUCT16 *hook;
548 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
550 BOOL ret;
551 hook->hWnd = msg->hwnd;
552 hook->wMessage = msg->message & 0xffff;
553 hook->wParam = LOWORD (msg->wParam);
554 hook->lParam = msg->lParam;
555 ret = HOOK_CallHooks16( WH_HARDWARE,
556 remove ? HC_ACTION : HC_NOREMOVE,
557 0, (LPARAM)SEGPTR_GET(hook) );
558 SEGPTR_FREE(hook);
559 if (ret)
561 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
562 continue;
564 status = SYSQ_MSG_ACCEPT;
568 switch (LOWORD(status))
570 case SYSQ_MSG_ACCEPT:
571 break;
573 case SYSQ_MSG_SKIP:
574 if (HOOK_IsHooked( WH_CBT ))
576 if( kbd_msg )
577 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
578 LOWORD (msg->wParam), msg->lParam );
579 else
581 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
582 if (hook)
584 CONV_POINT32TO16( &msg->pt,&hook->pt );
585 hook->hwnd = msg->hwnd;
586 hook->wHitTestCode = HIWORD(status);
587 hook->dwExtraInfo = 0;
588 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
589 (LPARAM)SEGPTR_GET(hook) );
590 SEGPTR_FREE(hook);
595 if (remove)
596 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
597 /* continue */
599 case SYSQ_MSG_CONTINUE:
600 continue;
602 case SYSQ_MSG_ABANDON:
603 LeaveCriticalSection(&sysMsgQueue->cSection);
604 return FALSE;
607 if (remove)
609 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
610 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
612 LeaveCriticalSection(&sysMsgQueue->cSection);
613 return TRUE;
615 LeaveCriticalSection(&sysMsgQueue->cSection);
616 return FALSE;
620 /**********************************************************************
621 * SetDoubleClickTime16 (USER.20)
623 void WINAPI SetDoubleClickTime16( UINT16 interval )
625 SetDoubleClickTime( interval );
629 /**********************************************************************
630 * SetDoubleClickTime32 (USER32.480)
632 BOOL WINAPI SetDoubleClickTime( UINT interval )
634 doubleClickSpeed = interval ? interval : 500;
635 return TRUE;
639 /**********************************************************************
640 * GetDoubleClickTime16 (USER.21)
642 UINT16 WINAPI GetDoubleClickTime16(void)
644 return doubleClickSpeed;
648 /**********************************************************************
649 * GetDoubleClickTime32 (USER32.239)
651 UINT WINAPI GetDoubleClickTime(void)
653 return doubleClickSpeed;
657 /***********************************************************************
658 * MSG_SendMessageInterThread
660 * Implementation of an inter-task SendMessage.
661 * Return values:
662 * 0 if error or timeout
663 * 1 if successflul
665 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
666 HWND hwnd, UINT msg,
667 WPARAM wParam, LPARAM lParam,
668 DWORD timeout, WORD flags,
669 LRESULT *pRes)
671 MESSAGEQUEUE *queue, *destQ;
672 SMSG *smsg;
673 LRESULT retVal = 1;
674 int iWndsLocks;
676 *pRes = 0;
678 if (IsTaskLocked16() || !IsWindow(hwnd))
679 return 0;
681 /* create a SMSG structure to hold SendMessage() parameters */
682 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
683 return 0;
684 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
686 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
688 QUEUE_Unlock( queue );
689 return 0;
692 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
693 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
695 /* fill up SMSG structure */
696 smsg->hWnd = hwnd;
697 smsg->msg = msg;
698 smsg->wParam = wParam;
699 smsg->lParam = lParam;
701 smsg->lResult = 0;
702 smsg->hSrcQueue = GetFastQueue16();
703 smsg->hDstQueue = hDestQueue;
704 smsg->flags = flags;
706 /* add smsg struct in the processing SM list of the source queue */
707 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
709 /* add smsg struct in the pending list of the destination queue */
710 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
711 return 0;
713 iWndsLocks = WIN_SuspendWndsLock();
715 /* force destination task to run next, if 16 bit threads */
716 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ->thdb) )
717 DirectedYield16( destQ->thdb->teb.htask16 );
719 /* wait for the result, note that 16-bit apps almost always get out of
720 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
722 while ( TRUE )
725 * The sequence is crucial to avoid deadlock situations:
726 * - first, we clear the QS_SMRESULT bit
727 * - then, we check the SMSG_HAVE_RESULT bit
728 * - only if this isn't set, we enter the wait state.
730 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
731 * we are guaranteed that -should we now clear the QS_SMRESULT that
732 * was signalled already by the receiver- we will not start waiting.
735 if ( smsg->flags & SMSG_HAVE_RESULT )
737 got:
738 *pRes = smsg->lResult;
739 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
740 break;
743 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
745 if ( smsg->flags & SMSG_HAVE_RESULT )
746 goto got;
748 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
750 /* return with timeout */
751 SetLastError( 0 );
752 retVal = 0;
753 break;
756 WIN_RestoreWndsLock(iWndsLocks);
758 /* remove the smsg from the processingg list of the source queue */
759 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
761 /* Note: the destination thread is in charge of removing the smsg from
762 the pending list */
764 /* In the case of an early reply (or a timeout), sender thread will
765 released the smsg structure if the receiver thread is done
766 (SMSG_RECEIVED set). If the receiver thread isn't done,
767 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
768 responsability to released smsg */
769 EnterCriticalSection( &queue->cSection );
771 if (smsg->flags & SMSG_RECEIVED)
772 HeapFree(SystemHeap, 0, smsg);
773 else
774 smsg->flags |= SMSG_RECEIVER_CLEANS;
776 LeaveCriticalSection( &queue->cSection );
779 QUEUE_Unlock( queue );
780 QUEUE_Unlock( destQ );
782 TRACE_(sendmsg)("done!\n");
783 return retVal;
787 /***********************************************************************
788 * ReplyMessage16 (USER.115)
790 void WINAPI ReplyMessage16( LRESULT result )
792 ReplyMessage( result );
795 /***********************************************************************
796 * ReplyMessage (USER.115)
798 BOOL WINAPI ReplyMessage( LRESULT result )
800 MESSAGEQUEUE *senderQ = 0;
801 MESSAGEQUEUE *queue = 0;
802 SMSG *smsg;
803 BOOL ret = FALSE;
805 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
806 return FALSE;
808 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
811 if ( !(smsg = queue->smWaiting)
812 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
813 goto ReplyMessageEnd;
815 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
817 /* This is the first reply, so pass result to sender */
819 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
821 EnterCriticalSection(&senderQ->cSection);
823 smsg->lResult = result;
824 smsg->flags |= SMSG_ALREADY_REPLIED;
826 /* check if it's an early reply (called by the application) or
827 a regular reply (called by ReceiveMessage) */
828 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
829 smsg->flags |= SMSG_EARLY_REPLY;
831 smsg->flags |= SMSG_HAVE_RESULT;
833 LeaveCriticalSection(&senderQ->cSection);
835 /* tell the sending task that its reply is ready */
836 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
838 /* switch directly to sending task (16 bit thread only) */
839 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ->thdb ) )
840 DirectedYield16( senderQ->thdb->teb.htask16 );
842 ret = TRUE;
845 if (smsg->flags & SMSG_SENDING_REPLY)
847 /* remove msg from the waiting list, since this is the last
848 ReplyMessage */
849 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
851 EnterCriticalSection(&senderQ->cSection);
853 /* tell the sender we're all done with smsg structure */
854 smsg->flags |= SMSG_RECEIVED;
856 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
857 receiver to clean up smsg, it could only happens when there is
858 an early reply or a timeout */
859 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
861 TRACE_(sendmsg)("Receiver cleans up!\n" );
862 HeapFree( SystemHeap, 0, smsg );
865 LeaveCriticalSection(&senderQ->cSection);
868 ReplyMessageEnd:
869 if ( senderQ )
870 QUEUE_Unlock( senderQ );
871 if ( queue )
872 QUEUE_Unlock( queue );
874 return ret;
877 /***********************************************************************
878 * MSG_PeekMessage
880 static BOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, DWORD first, DWORD last,
881 WORD flags, BOOL peek )
883 int mask;
884 MESSAGEQUEUE *msgQueue;
885 HQUEUE16 hQueue;
886 POINT16 pt16;
887 int iWndsLocks;
889 #ifdef CONFIG_IPC
890 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
891 DDE_GetRemoteMessage();
892 #endif /* CONFIG_IPC */
894 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
895 if (first || last)
897 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
898 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
899 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
900 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
901 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
902 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
904 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
906 if (IsTaskLocked16()) flags |= PM_NOYIELD;
908 /* Never yield on Win32 threads */
909 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
911 iWndsLocks = WIN_SuspendWndsLock();
913 while(1)
915 QMSG *qmsg;
917 hQueue = GetFastQueue16();
918 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
919 if (!msgQueue)
921 WIN_RestoreWndsLock(iWndsLocks);
922 return FALSE;
924 msgQueue->changeBits = 0;
926 /* First handle a message put by SendMessage() */
928 while (msgQueue->wakeBits & QS_SENDMESSAGE)
929 QUEUE_ReceiveMessage( msgQueue );
931 /* Now handle a WM_QUIT message */
933 if (msgQueue->wPostQMsg &&
934 (!first || WM_QUIT >= first) &&
935 (!last || WM_QUIT <= last) )
937 msg->hwnd = hwnd;
938 msg->message = WM_QUIT;
939 msg->wParam = msgQueue->wExitCode;
940 msg->lParam = 0;
941 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
942 break;
945 /* Now find a normal message */
947 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
948 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
950 *msg = qmsg->msg;
952 msgQueue->GetMessageTimeVal = msg->time;
953 CONV_POINT32TO16(&msg->pt, &pt16);
954 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
955 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
957 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
958 break;
961 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
963 /* Now find a hardware event */
965 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
966 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
968 /* Got one */
969 msgQueue->GetMessageTimeVal = msg->time;
970 CONV_POINT32TO16(&msg->pt, &pt16);
971 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
972 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
973 break;
976 /* Check again for SendMessage */
978 while (msgQueue->wakeBits & QS_SENDMESSAGE)
979 QUEUE_ReceiveMessage( msgQueue );
981 /* Now find a WM_PAINT message */
983 if ((msgQueue->wakeBits & mask) & QS_PAINT)
985 WND* wndPtr;
986 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
987 msg->message = WM_PAINT;
988 msg->wParam = 0;
989 msg->lParam = 0;
991 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
993 if( wndPtr->dwStyle & WS_MINIMIZE &&
994 wndPtr->class->hIcon )
996 msg->message = WM_PAINTICON;
997 msg->wParam = 1;
1000 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1002 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1004 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1005 QUEUE_DecPaintCount( hQueue );
1007 WIN_ReleaseWndPtr(wndPtr);
1008 break;
1010 WIN_ReleaseWndPtr(wndPtr);
1014 /* Check for timer messages, but yield first */
1016 if (!(flags & PM_NOYIELD))
1018 UserYield16();
1019 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1020 QUEUE_ReceiveMessage( msgQueue );
1022 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1024 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1027 if (peek)
1029 if (!(flags & PM_NOYIELD)) UserYield16();
1031 QUEUE_Unlock( msgQueue );
1032 WIN_RestoreWndsLock(iWndsLocks);
1033 return FALSE;
1035 msgQueue->wakeMask = mask;
1036 QUEUE_WaitBits( mask, INFINITE );
1037 QUEUE_Unlock( msgQueue );
1040 WIN_RestoreWndsLock(iWndsLocks);
1042 /* instead of unlocking queue for every break condition, all break
1043 condition will fall here */
1044 QUEUE_Unlock( msgQueue );
1046 /* We got a message */
1047 if (flags & PM_REMOVE)
1049 WORD message = msg->message;
1051 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1053 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1055 if (!(*p & 0x80))
1056 *p ^= 0x01;
1057 *p |= 0x80;
1059 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1060 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1063 if (peek)
1064 return TRUE;
1066 else
1067 return (msg->message != WM_QUIT);
1070 /***********************************************************************
1071 * MSG_InternalGetMessage
1073 * GetMessage() function for internal use. Behave like GetMessage(),
1074 * but also call message filters and optionally send WM_ENTERIDLE messages.
1075 * 'hwnd' must be the handle of the dialog or menu window.
1076 * 'code' is the message filter value (MSGF_??? codes).
1078 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner,
1079 WPARAM code, WORD flags, BOOL sendIdle )
1081 for (;;)
1083 if (sendIdle)
1085 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
1087 /* No message present -> send ENTERIDLE and wait */
1088 if (IsWindow(hwndOwner))
1089 SendMessageA( hwndOwner, WM_ENTERIDLE,
1090 code, (LPARAM)hwnd );
1091 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1094 else /* Always wait for a message */
1095 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1097 /* Call message filters */
1099 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1101 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1102 if (pmsg)
1104 BOOL ret;
1105 *pmsg = *msg;
1106 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1107 (LPARAM) pmsg ) ||
1108 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1109 (LPARAM) pmsg ));
1111 HeapFree( SystemHeap, 0, pmsg );
1112 if (ret)
1114 /* Message filtered -> remove it from the queue */
1115 /* if it's still there. */
1116 if (!(flags & PM_REMOVE))
1117 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
1118 continue;
1123 return (msg->message != WM_QUIT);
1128 /***********************************************************************
1129 * PeekMessage16 (USER.109)
1131 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd, UINT16 first,
1132 UINT16 last, UINT16 flags )
1134 MSG msg32;
1135 BOOL16 ret;
1136 ret = PeekMessageA(&msg32, hwnd, first, last, flags);
1137 STRUCT32_MSG32to16(&msg32, lpmsg);
1138 return ret;
1141 /***********************************************************************
1142 * WIN16_PeekMessage32 (USER.819)
1144 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1145 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
1147 if (wHaveParamHigh == FALSE)
1149 lpmsg16_32->wParamHigh = 0;
1150 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1152 else
1154 MSG msg32;
1155 BOOL16 ret;
1157 ret = (BOOL16)PeekMessageA(&msg32, (HWND)hwnd,
1158 (UINT)first, (UINT)last, (UINT)flags);
1159 lpmsg16_32->msg.hwnd = msg32.hwnd;
1160 lpmsg16_32->msg.message = msg32.message;
1161 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1162 lpmsg16_32->msg.lParam = msg32.lParam;
1163 lpmsg16_32->msg.time = msg32.time;
1164 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1165 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1166 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1167 return ret;
1172 /***********************************************************************
1173 * PeekMessageA
1175 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1176 UINT min,UINT max,UINT wRemoveMsg)
1178 return MSG_PeekMessage( lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1181 /***********************************************************************
1182 * PeekMessageW Check queue for messages
1184 * Checks for a message in the thread's queue, filtered as for
1185 * GetMessage(). Returns immediately whether a message is available
1186 * or not.
1188 * Whether a retrieved message is removed from the queue is set by the
1189 * _wRemoveMsg_ flags, which should be one of the following values:
1191 * PM_NOREMOVE Do not remove the message from the queue.
1193 * PM_REMOVE Remove the message from the queue.
1195 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1196 * request that the system not yield control during PeekMessage();
1197 * however applications may not rely on scheduling behavior.
1199 * RETURNS
1201 * Nonzero if a message is available and is retrieved, zero otherwise.
1203 * CONFORMANCE
1205 * ECMA-234, Win32
1208 BOOL WINAPI PeekMessageW(
1209 LPMSG lpmsg, /* buffer to receive message */
1210 HWND hwnd, /* restrict to messages for hwnd */
1211 UINT min, /* minimum message to receive */
1212 UINT max, /* maximum message to receive */
1213 UINT wRemoveMsg /* removal flags */
1216 BOOL bRet = PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1217 if (bRet)
1218 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1219 return bRet;
1222 /***********************************************************************
1223 * GetMessage16 (USER.108)
1225 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1227 BOOL ret;
1228 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1229 MSG msg32;
1231 ret = GetMessageA( &msg32, hwnd, first, last );
1233 STRUCT32_MSG32to16( &msg32, lpmsg );
1235 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1236 hwnd, first, last );
1238 return ret;
1241 /***********************************************************************
1242 * WIN16_GetMessage32 (USER.820)
1244 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1245 UINT16 last, BOOL16 wHaveParamHigh )
1247 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1249 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1252 lpmsg16_32->wParamHigh = 0; /* you never know... */
1253 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1254 return GetMessage16(msg16_32, hWnd, first, last);
1256 else
1258 MSG msg32;
1259 BOOL16 ret;
1261 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1262 lpmsg16_32->msg.hwnd = msg32.hwnd;
1263 lpmsg16_32->msg.message = msg32.message;
1264 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1265 lpmsg16_32->msg.lParam = msg32.lParam;
1266 lpmsg16_32->msg.time = msg32.time;
1267 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1268 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1269 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1270 return ret;
1274 /***********************************************************************
1275 * GetMessage32A (USER32.270)
1277 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1279 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1281 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1282 hwnd, min, max );
1284 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1286 return (lpmsg->message != WM_QUIT);
1289 /***********************************************************************
1290 * GetMessage32W (USER32.274) Retrieve next message
1292 * GetMessage retrieves the next event from the calling thread's
1293 * queue and deposits it in *lpmsg.
1295 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1296 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1297 * all application messages are retrieved.
1299 * _min_ and _max_ specify the range of messages of interest. If
1300 * min==max==0, no filtering is performed. Useful examples are
1301 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1302 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1304 * WM_PAINT messages are not removed from the queue; they remain until
1305 * processed. Other messages are removed from the queue.
1307 * RETURNS
1309 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1311 * CONFORMANCE
1313 * ECMA-234, Win32
1316 BOOL WINAPI GetMessageW(
1317 MSG* lpmsg, /* buffer to receive message */
1318 HWND hwnd, /* restrict to messages for hwnd */
1319 UINT min, /* minimum message to receive */
1320 UINT max /* maximum message to receive */
1323 BOOL bRet = GetMessageA(lpmsg, hwnd, min, max);
1324 if (bRet)
1325 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1326 return bRet;
1331 /***********************************************************************
1332 * PostMessage16 (USER.110)
1334 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1335 LPARAM lParam )
1337 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1341 /***********************************************************************
1342 * PostMessage32A (USER32.419)
1344 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1345 LPARAM lParam )
1347 MSG msg;
1348 WND *wndPtr;
1349 BOOL retvalue;
1351 msg.hwnd = hwnd;
1352 msg.message = message;
1353 msg.wParam = wParam;
1354 msg.lParam = lParam;
1355 msg.time = GetTickCount();
1356 msg.pt.x = 0;
1357 msg.pt.y = 0;
1359 #ifdef CONFIG_IPC
1360 if (DDE_PostMessage(&msg))
1361 return TRUE;
1362 #endif /* CONFIG_IPC */
1364 if (hwnd == HWND_BROADCAST)
1366 WND *pDesktop = WIN_GetDesktop();
1367 TRACE_(msg)("HWND_BROADCAST !\n");
1369 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1371 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1373 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1374 wndPtr->hwndSelf, message, wParam, lParam);
1375 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1378 WIN_ReleaseDesktop();
1379 TRACE_(msg)("End of HWND_BROADCAST !\n");
1380 return TRUE;
1383 wndPtr = WIN_FindWndPtr( hwnd );
1384 if (!wndPtr || !wndPtr->hmemTaskQ)
1386 retvalue = FALSE;
1387 goto END;
1390 retvalue = QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1391 END:
1392 WIN_ReleaseWndPtr(wndPtr);
1393 return retvalue;
1397 /***********************************************************************
1398 * PostMessage32W (USER32.420)
1400 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1401 LPARAM lParam )
1403 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(message));
1404 return PostMessageA( hwnd, message, wParam, lParam );
1408 /***********************************************************************
1409 * PostAppMessage16 (USER.116)
1411 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1412 LPARAM lParam )
1414 MSG msg;
1416 if (GetTaskQueue16(hTask) == 0) return FALSE;
1417 msg.hwnd = 0;
1418 msg.message = message;
1419 msg.wParam = wParam;
1420 msg.lParam = lParam;
1421 msg.time = GetTickCount();
1422 msg.pt.x = 0;
1423 msg.pt.y = 0;
1425 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1428 /************************************************************************
1429 * MSG_CallWndProcHook32
1431 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1433 CWPSTRUCT cwp;
1435 cwp.lParam = pmsg->lParam;
1436 cwp.wParam = pmsg->wParam;
1437 cwp.message = pmsg->message;
1438 cwp.hwnd = pmsg->hwnd;
1440 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1441 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1443 pmsg->lParam = cwp.lParam;
1444 pmsg->wParam = cwp.wParam;
1445 pmsg->message = cwp.message;
1446 pmsg->hwnd = cwp.hwnd;
1450 /***********************************************************************
1451 * MSG_SendMessage
1453 * return values: 0 if timeout occurs
1454 * 1 otherwise
1456 LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1457 LPARAM lParam, DWORD timeout, WORD flags,
1458 LRESULT *pRes)
1460 WND * wndPtr = 0;
1461 WND **list, **ppWnd;
1462 LRESULT ret = 1;
1464 *pRes = 0;
1466 if (hwnd == HWND_BROADCAST)
1468 *pRes = 1;
1470 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1472 WIN_ReleaseDesktop();
1473 return 1;
1475 WIN_ReleaseDesktop();
1477 TRACE_(msg)("HWND_BROADCAST !\n");
1478 for (ppWnd = list; *ppWnd; ppWnd++)
1480 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1481 if (!IsWindow(wndPtr->hwndSelf)) continue;
1482 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1484 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1485 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1486 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1487 timeout, flags, pRes);
1490 WIN_ReleaseWndPtr(wndPtr);
1491 WIN_ReleaseWinArray(list);
1492 TRACE_(msg)("End of HWND_BROADCAST !\n");
1493 return 1;
1496 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1498 if (flags & SMSG_UNICODE)
1499 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1500 else if (flags & SMSG_WIN32)
1501 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1502 else
1504 LPCWPSTRUCT16 pmsg;
1506 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1508 pmsg->hwnd = hwnd & 0xffff;
1509 pmsg->message= msg & 0xffff;
1510 pmsg->wParam = wParam & 0xffff;
1511 pmsg->lParam = lParam;
1512 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1513 (LPARAM)SEGPTR_GET(pmsg) );
1514 hwnd = pmsg->hwnd;
1515 msg = pmsg->message;
1516 wParam = pmsg->wParam;
1517 lParam = pmsg->lParam;
1518 SEGPTR_FREE( pmsg );
1523 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1525 WARN_(msg)("invalid hwnd %04x\n", hwnd );
1526 return 0;
1528 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1530 ret = 0; /* Don't send anything if the task is dying */
1531 goto END;
1533 if (flags & SMSG_WIN32)
1534 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1535 else
1536 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1538 if (wndPtr->hmemTaskQ != GetFastQueue16())
1539 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1540 wParam, lParam, timeout, flags, pRes );
1541 else
1543 /* Call the right CallWindowProc flavor */
1544 if (flags & SMSG_UNICODE)
1545 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1546 hwnd, msg, wParam, lParam );
1547 else if (flags & SMSG_WIN32)
1548 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1549 hwnd, msg, wParam, lParam );
1550 else
1551 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1552 (HWND16) hwnd, (UINT16) msg,
1553 (WPARAM16) wParam, lParam );
1556 if (flags & SMSG_WIN32)
1557 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1558 else
1559 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1560 END:
1561 WIN_ReleaseWndPtr(wndPtr);
1562 return ret;
1566 /***********************************************************************
1567 * SendMessage16 (USER.111)
1569 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1570 LPARAM lParam)
1572 LRESULT res;
1573 #ifdef CONFIG_IPC
1574 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1575 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1576 #endif /* CONFIG_IPC */
1578 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1580 return res;
1585 /**********************************************************************
1586 * PostThreadMessage32A (USER32.422)
1588 * BUGS
1590 * Thread-local message queues are not supported.
1593 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1594 WPARAM wParam, LPARAM lParam )
1596 MSG msg;
1597 HQUEUE16 hQueue;
1599 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1600 return FALSE;
1602 msg.hwnd = 0;
1603 msg.message = message;
1604 msg.wParam = wParam;
1605 msg.lParam = lParam;
1606 msg.time = GetTickCount();
1607 msg.pt.x = 0;
1608 msg.pt.y = 0;
1610 return QUEUE_AddMsg( hQueue, &msg, 0 );
1613 /**********************************************************************
1614 * PostThreadMessage32W (USER32.423)
1616 * BUGS
1618 * Thread-local message queues are not supported.
1621 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1622 WPARAM wParam, LPARAM lParam )
1624 FIXME_(sendmsg)("(%s) unicode<->ascii\n",SPY_GetMsgName(message));
1625 return PostThreadMessageA(idThread, message, wParam, lParam);
1628 /***********************************************************************
1629 * SendMessage32A (USER32.454)
1631 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1632 LPARAM lParam )
1634 LRESULT res;
1636 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1637 SMSG_WIN32, &res);
1639 return res;
1643 /***********************************************************************
1644 * SendMessage32W (USER32.459) Send Window Message
1646 * Sends a message to the window procedure of the specified window.
1647 * SendMessage() will not return until the called window procedure
1648 * either returns or calls ReplyMessage().
1650 * Use PostMessage() to send message and return immediately. A window
1651 * procedure may use InSendMessage() to detect
1652 * SendMessage()-originated messages.
1654 * Applications which communicate via HWND_BROADCAST may use
1655 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1656 * with other applications.
1658 * CONFORMANCE
1660 * ECMA-234, Win32
1662 LRESULT WINAPI SendMessageW(
1663 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1664 the message will be sent to all top-level windows. */
1666 UINT msg, /* message */
1667 WPARAM wParam, /* message parameter */
1668 LPARAM lParam /* additional message parameter */
1670 LRESULT res;
1672 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1673 SMSG_WIN32 | SMSG_UNICODE, &res);
1675 return res;
1679 /***********************************************************************
1680 * SendMessageTimeout16 (not a WINAPI)
1682 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1683 LPARAM lParam, UINT16 flags,
1684 UINT16 timeout, LPWORD resultp)
1686 LRESULT ret;
1687 LRESULT msgRet;
1689 /* FIXME: need support for SMTO_BLOCK */
1691 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1692 *resultp = (WORD) msgRet;
1693 return ret;
1697 /***********************************************************************
1698 * SendMessageTimeoutA (USER32.457)
1700 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1701 LPARAM lParam, UINT flags,
1702 UINT timeout, LPDWORD resultp)
1704 LRESULT ret;
1705 LRESULT msgRet;
1707 /* FIXME: need support for SMTO_BLOCK */
1709 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1710 &msgRet);
1712 *resultp = (DWORD) msgRet;
1713 return ret;
1717 /***********************************************************************
1718 * SendMessageTimeoutW (USER32.458)
1720 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1721 LPARAM lParam, UINT flags,
1722 UINT timeout, LPDWORD resultp)
1724 LRESULT ret;
1725 LRESULT msgRet;
1727 /* FIXME: need support for SMTO_BLOCK */
1729 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1730 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1732 *resultp = (DWORD) msgRet;
1733 return ret;
1737 /***********************************************************************
1738 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1740 * WaitMessage() suspends a thread until events appear in the thread's
1741 * queue.
1743 * BUGS
1745 * Is supposed to return BOOL under Win32.
1747 * Thread-local message queues are not supported.
1749 * CONFORMANCE
1751 * ECMA-234, Win32
1754 void WINAPI WaitMessage( void )
1756 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1759 /***********************************************************************
1760 * MsgWaitForMultipleObjects (USER32.400)
1762 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1763 BOOL fWaitAll, DWORD dwMilliseconds,
1764 DWORD dwWakeMask )
1766 DWORD i;
1767 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1768 DWORD ret;
1770 HQUEUE16 hQueue = GetFastQueue16();
1771 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1772 if (!msgQueue) return WAIT_FAILED;
1774 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1776 SetLastError( ERROR_INVALID_PARAMETER );
1777 QUEUE_Unlock( msgQueue );
1778 return WAIT_FAILED;
1781 msgQueue->changeBits = 0;
1782 msgQueue->wakeMask = dwWakeMask;
1784 if (THREAD_IsWin16(THREAD_Current()))
1787 * This is a temporary solution to a big problem.
1788 * You see, the main thread of all Win32 programs is created as a 16 bit
1789 * task. This means that if you want on an event using Win32 synchronization
1790 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1791 * This implements a semi-busy loop that checks the handles to wait on and
1792 * also the message queue. When either one is ready, the wait function returns.
1794 * This will all go away when the real Win32 threads are implemented for all
1795 * the threads of an applications. Including the main thread.
1797 DWORD curTime = GetCurrentTime();
1802 * Check the handles in the list.
1804 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1807 * If the handles have been triggered, return.
1809 if (ret != WAIT_TIMEOUT)
1810 break;
1813 * Then, let the 16 bit scheduler do it's thing.
1815 Yield16();
1818 * If a message matching the wait mask has arrived, return.
1820 if (msgQueue->changeBits & dwWakeMask)
1822 ret = nCount;
1823 break;
1827 * And continue doing this until we hit the timeout.
1829 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1831 else
1833 /* Add the thread event to the handle list */
1834 for (i = 0; i < nCount; i++)
1835 handles[i] = pHandles[i];
1836 handles[nCount] = msgQueue->hEvent;
1838 EVENT_Pending();
1840 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1843 QUEUE_Unlock( msgQueue );
1845 return ret;
1850 struct accent_char
1852 BYTE ac_accent;
1853 BYTE ac_char;
1854 BYTE ac_result;
1857 static const struct accent_char accent_chars[] =
1859 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1860 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1861 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1862 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1863 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1864 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1865 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1866 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1867 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1868 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1869 {',', 'C', '\307'}, {',', 'c', '\347'},
1870 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1871 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1872 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1873 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1874 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1875 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1876 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1877 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1878 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1879 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1880 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1881 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1882 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1883 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1884 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1885 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1886 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1887 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1888 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1889 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1890 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1891 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1892 {'s', 's', '\337'}, {'"', 'y', '\377'},
1893 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1894 /* iso-8859-2 uses this */
1895 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1896 {'<', 'S', '\251'}, {'<', 's', '\271'},
1897 {'<', 'T', '\253'}, {'<', 't', '\273'},
1898 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1899 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1900 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1901 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1902 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1903 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1904 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1905 {';', 'E', '\312'}, {';', 'e', '\332'},
1906 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1907 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1908 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1909 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1910 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1911 /* collision whith S, from iso-8859-9 !!! */
1912 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1913 {',', 'T', '\336'}, {',', 't', '\376'},
1914 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1915 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1916 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1917 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1918 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1919 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1920 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1921 /* iso-8859-3 uses this */
1922 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1923 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1924 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1925 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1926 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1927 {'>', 'S', '\336'}, {'>', 's', '\376'},
1928 /* collision whith G( from iso-8859-9 !!! */
1929 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1930 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1931 /* collision whith I. from iso-8859-3 !!! */
1932 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1933 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1934 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1935 /* iso-8859-4 uses this */
1936 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1937 {',', 'L', '\246'}, {',', 'l', '\266'},
1938 {',', 'G', '\253'}, {',', 'g', '\273'},
1939 {',', 'N', '\321'}, {',', 'n', '\361'},
1940 {',', 'K', '\323'}, {',', 'k', '\363'},
1941 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1942 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1943 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1944 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1945 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1946 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1947 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1948 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1949 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1950 {';', 'U', '\331'}, {';', 'u', '\371'},
1951 /* iso-8859-9 uses this */
1952 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1953 * whith the same letters on other iso-8859-x (that is they are on
1954 * different places :-( ), if you use turkish uncomment these and
1955 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1956 * FIXME: should be dynamic according to chosen language
1957 * if/when Wine has turkish support.
1959 /* collision whith G( from iso-8859-3 !!! */
1960 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1961 /* collision whith S, from iso-8859-2 !!! */
1962 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1963 /* collision whith I. from iso-8859-3 !!! */
1964 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1968 /***********************************************************************
1969 * MSG_DoTranslateMessage
1971 * Implementation of TranslateMessage.
1973 * TranslateMessage translates virtual-key messages into character-messages,
1974 * as follows :
1975 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1976 * ditto replacing WM_* with WM_SYS*
1977 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1978 * by the keyboard driver.
1980 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
1981 WPARAM wParam, LPARAM lParam )
1983 static int dead_char;
1984 BYTE wp[2];
1986 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1987 TRACE_(msg)("(%s, %04X, %08lX)\n",
1988 SPY_GetMsgName(message), wParam, lParam );
1989 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1990 TRACE_(key)("(%s, %04X, %08lX)\n",
1991 SPY_GetMsgName(message), wParam, lParam );
1993 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1995 TRACE_(key)("Translating key %04X, scancode %04X\n",
1996 wParam, HIWORD(lParam) );
1998 /* FIXME : should handle ToAscii yielding 2 */
1999 switch (ToAscii(wParam, HIWORD(lParam),
2000 QueueKeyStateTable,(LPWORD)wp, 0))
2002 case 1 :
2003 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2004 /* Should dead chars handling go in ToAscii ? */
2005 if (dead_char)
2007 int i;
2009 if (wp[0] == ' ') wp[0] = dead_char;
2010 if (dead_char == 0xa2) dead_char = '(';
2011 else if (dead_char == 0xa8) dead_char = '"';
2012 else if (dead_char == 0xb2) dead_char = ';';
2013 else if (dead_char == 0xb4) dead_char = '\'';
2014 else if (dead_char == 0xb7) dead_char = '<';
2015 else if (dead_char == 0xb8) dead_char = ',';
2016 else if (dead_char == 0xff) dead_char = '.';
2017 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2018 if ((accent_chars[i].ac_accent == dead_char) &&
2019 (accent_chars[i].ac_char == wp[0]))
2021 wp[0] = accent_chars[i].ac_result;
2022 break;
2024 dead_char = 0;
2026 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2027 PostMessage16( hwnd, message, wp[0], lParam );
2028 return TRUE;
2030 case -1 :
2031 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2032 dead_char = wp[0];
2033 TRACE_(key)("-1 -> PostMessage(%s)\n",
2034 SPY_GetMsgName(message));
2035 PostMessage16( hwnd, message, wp[0], lParam );
2036 return TRUE;
2038 return FALSE;
2042 /***********************************************************************
2043 * TranslateMessage16 (USER.113)
2045 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2047 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2048 msg->wParam, msg->lParam );
2052 /***********************************************************************
2053 * WIN16_TranslateMessage32 (USER.821)
2055 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2057 WPARAM wParam;
2059 if (wHaveParamHigh)
2060 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2061 else
2062 wParam = (WPARAM)msg->msg.wParam;
2064 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2065 wParam, msg->msg.lParam );
2068 /***********************************************************************
2069 * TranslateMessage32 (USER32.556)
2071 BOOL WINAPI TranslateMessage( const MSG *msg )
2073 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2074 msg->wParam, msg->lParam );
2078 /***********************************************************************
2079 * DispatchMessage16 (USER.114)
2081 LONG WINAPI DispatchMessage16( const MSG16* msg )
2083 WND * wndPtr;
2084 LONG retval;
2085 int painting;
2087 /* Process timer messages */
2088 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2090 if (msg->lParam)
2092 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2093 msg->message, msg->wParam, GetTickCount() );
2097 if (!msg->hwnd) return 0;
2098 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2099 if (!wndPtr->winproc)
2101 retval = 0;
2102 goto END;
2104 painting = (msg->message == WM_PAINT);
2105 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2107 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2108 msg->wParam, msg->lParam );
2109 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2110 msg->hwnd, msg->message,
2111 msg->wParam, msg->lParam );
2112 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2114 WIN_ReleaseWndPtr(wndPtr);
2115 wndPtr = WIN_FindWndPtr(msg->hwnd);
2116 if (painting && wndPtr &&
2117 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2119 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2120 msg->hwnd);
2121 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2122 /* Validate the update region to avoid infinite WM_PAINT loop */
2123 ValidateRect( msg->hwnd, NULL );
2125 END:
2126 WIN_ReleaseWndPtr(wndPtr);
2127 return retval;
2131 /***********************************************************************
2132 * WIN16_DispatchMessage32 (USER.822)
2134 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2136 if (wHaveParamHigh == FALSE)
2137 return DispatchMessage16(&(lpmsg16_32->msg));
2138 else
2140 MSG msg;
2142 msg.hwnd = lpmsg16_32->msg.hwnd;
2143 msg.message = lpmsg16_32->msg.message;
2144 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2145 msg.lParam = lpmsg16_32->msg.lParam;
2146 msg.time = lpmsg16_32->msg.time;
2147 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2148 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2149 return DispatchMessageA(&msg);
2153 /***********************************************************************
2154 * DispatchMessage32A (USER32.141)
2156 LONG WINAPI DispatchMessageA( const MSG* msg )
2158 WND * wndPtr;
2159 LONG retval;
2160 int painting;
2162 /* Process timer messages */
2163 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2165 if (msg->lParam)
2167 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2168 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2169 msg->message, msg->wParam, GetTickCount() );
2173 if (!msg->hwnd) return 0;
2174 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2175 if (!wndPtr->winproc)
2177 retval = 0;
2178 goto END;
2180 painting = (msg->message == WM_PAINT);
2181 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2182 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2184 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2185 msg->wParam, msg->lParam );
2186 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2187 msg->hwnd, msg->message,
2188 msg->wParam, msg->lParam );
2189 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2191 WIN_ReleaseWndPtr(wndPtr);
2192 wndPtr = WIN_FindWndPtr(msg->hwnd);
2194 if (painting && wndPtr &&
2195 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2197 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2198 msg->hwnd);
2199 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2200 /* Validate the update region to avoid infinite WM_PAINT loop */
2201 ValidateRect( msg->hwnd, NULL );
2203 END:
2204 WIN_ReleaseWndPtr(wndPtr);
2205 return retval;
2209 /***********************************************************************
2210 * DispatchMessage32W (USER32.142) Process Message
2212 * Process the message specified in the structure *_msg_.
2214 * If the lpMsg parameter points to a WM_TIMER message and the
2215 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2216 * points to the function that is called instead of the window
2217 * procedure.
2219 * The message must be valid.
2221 * RETURNS
2223 * DispatchMessage() returns the result of the window procedure invoked.
2225 * CONFORMANCE
2227 * ECMA-234, Win32
2230 LONG WINAPI DispatchMessageW( const MSG* msg )
2232 WND * wndPtr;
2233 LONG retval;
2234 int painting;
2236 /* Process timer messages */
2237 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2239 if (msg->lParam)
2241 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2242 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2243 msg->message, msg->wParam, GetTickCount() );
2247 if (!msg->hwnd) return 0;
2248 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2249 if (!wndPtr->winproc)
2251 retval = 0;
2252 goto END;
2254 painting = (msg->message == WM_PAINT);
2255 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2256 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2258 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2259 msg->wParam, msg->lParam );
2260 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2261 msg->hwnd, msg->message,
2262 msg->wParam, msg->lParam );
2263 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2265 WIN_ReleaseWndPtr(wndPtr);
2266 wndPtr = WIN_FindWndPtr(msg->hwnd);
2268 if (painting && wndPtr &&
2269 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2271 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2272 msg->hwnd);
2273 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2274 /* Validate the update region to avoid infinite WM_PAINT loop */
2275 ValidateRect( msg->hwnd, NULL );
2277 END:
2278 WIN_ReleaseWndPtr(wndPtr);
2279 return retval;
2283 /***********************************************************************
2284 * RegisterWindowMessage16 (USER.118)
2286 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2288 TRACE_(msg)("%08lx\n", (DWORD)str );
2289 return GlobalAddAtom16( str );
2293 /***********************************************************************
2294 * RegisterWindowMessage32A (USER32.437)
2296 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2298 TRACE_(msg)("%s\n", str );
2299 return GlobalAddAtomA( str );
2303 /***********************************************************************
2304 * RegisterWindowMessage32W (USER32.438)
2306 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2308 TRACE_(msg)("%p\n", str );
2309 return GlobalAddAtomW( str );
2313 /***********************************************************************
2314 * GetTickCount (USER.13) (KERNEL32.299) System Time
2315 * Returns the number of milliseconds, modulo 2^32, since the start
2316 * of the current session.
2318 * CONFORMANCE
2320 * ECMA-234, Win32
2322 DWORD WINAPI GetTickCount(void)
2324 struct timeval t;
2325 gettimeofday( &t, NULL );
2326 /* make extremely compatible: granularity is 25 msec */
2327 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2331 /***********************************************************************
2332 * GetCurrentTime16 (USER.15)
2334 * (effectively identical to GetTickCount)
2336 DWORD WINAPI GetCurrentTime16(void)
2338 return GetTickCount();
2342 /***********************************************************************
2343 * InSendMessage16 (USER.192)
2345 BOOL16 WINAPI InSendMessage16(void)
2347 return InSendMessage();
2351 /***********************************************************************
2352 * InSendMessage32 (USER32.320)
2354 BOOL WINAPI InSendMessage(void)
2356 MESSAGEQUEUE *queue;
2357 BOOL ret;
2359 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2360 return 0;
2361 ret = (BOOL)queue->smWaiting;
2363 QUEUE_Unlock( queue );
2364 return ret;
2367 /***********************************************************************
2368 * BroadcastSystemMessage (USER32.12)
2370 LONG WINAPI BroadcastSystemMessage(
2371 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2372 LPARAM lParam
2374 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2375 dwFlags,*recipients,uMessage,wParam,lParam
2377 return 0;
2380 /***********************************************************************
2381 * SendNotifyMessageA (USER32.460)
2382 * FIXME
2383 * The message sended with PostMessage has to be put in the queue
2384 * with a higher priority as the other "Posted" messages.
2385 * QUEUE_AddMsg has to be modifyed.
2387 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2388 { BOOL ret = TRUE;
2389 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2390 hwnd, msg, wParam, lParam);
2392 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2393 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2395 else
2396 { PostMessageA ( hwnd, msg, wParam, lParam );
2398 return ret;
2401 /***********************************************************************
2402 * SendNotifyMessageW (USER32.461)
2403 * FIXME
2404 * The message sended with PostMessage has to be put in the queue
2405 * with a higher priority as the other "Posted" messages.
2406 * QUEUE_AddMsg has to be modifyed.
2408 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2409 { BOOL ret = TRUE;
2410 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2411 hwnd, msg, wParam, lParam);
2413 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2414 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2416 else
2417 { PostMessageW ( hwnd, msg, wParam, lParam );
2419 return ret;
2422 /***********************************************************************
2423 * SendMessageCallback32A
2424 * FIXME: It's like PostMessage. The callback gets called when the message
2425 * is processed. We have to modify the message processing for a exact
2426 * implementation...
2428 BOOL WINAPI SendMessageCallbackA(
2429 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2430 FARPROC lpResultCallBack,DWORD dwData)
2432 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2433 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2434 if ( hWnd == HWND_BROADCAST)
2435 { PostMessageA( hWnd, Msg, wParam, lParam);
2436 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2437 return TRUE;
2439 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2440 return TRUE;
2442 /***********************************************************************
2443 * SendMessageCallback32W
2444 * FIXME: It's like PostMessage. The callback gets called when the message
2445 * is processed. We have to modify the message processing for a exact
2446 * implementation...
2448 BOOL WINAPI SendMessageCallbackW(
2449 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2450 FARPROC lpResultCallBack,DWORD dwData)
2452 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2453 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2454 if ( hWnd == HWND_BROADCAST)
2455 { PostMessageW( hWnd, Msg, wParam, lParam);
2456 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2457 return TRUE;
2459 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2460 return TRUE;