Added autoconf check for "inline". You can now use it, it will be
[wine/dcerpc.git] / windows / message.c
blob96072a1dc0d6ecc6eef1ebfe12c799fb5bcfddd5
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 "debug.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 */
1215 /* FIXME: Should perform Unicode translation on specific messages */
1216 return PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1219 /***********************************************************************
1220 * GetMessage16 (USER.108)
1222 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1224 BOOL ret;
1225 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1226 MSG msg32;
1228 ret = GetMessageA( &msg32, hwnd, first, last );
1230 STRUCT32_MSG32to16( &msg32, lpmsg );
1232 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1233 hwnd, first, last );
1235 return ret;
1238 /***********************************************************************
1239 * WIN16_GetMessage32 (USER.820)
1241 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1242 UINT16 last, BOOL16 wHaveParamHigh )
1244 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1246 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1249 lpmsg16_32->wParamHigh = 0; /* you never know... */
1250 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1251 return GetMessage16(msg16_32, hWnd, first, last);
1253 else
1255 MSG msg32;
1256 BOOL16 ret;
1258 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1259 lpmsg16_32->msg.hwnd = msg32.hwnd;
1260 lpmsg16_32->msg.message = msg32.message;
1261 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1262 lpmsg16_32->msg.lParam = msg32.lParam;
1263 lpmsg16_32->msg.time = msg32.time;
1264 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1265 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1266 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1267 return ret;
1271 /***********************************************************************
1272 * GetMessage32A (USER32.270)
1274 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1276 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1278 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1279 hwnd, min, max );
1281 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1283 return (lpmsg->message != WM_QUIT);
1286 /***********************************************************************
1287 * GetMessage32W (USER32.274) Retrieve next message
1289 * GetMessage retrieves the next event from the calling thread's
1290 * queue and deposits it in *lpmsg.
1292 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1293 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1294 * all application messages are retrieved.
1296 * _min_ and _max_ specify the range of messages of interest. If
1297 * min==max==0, no filtering is performed. Useful examples are
1298 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1299 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1301 * WM_PAINT messages are not removed from the queue; they remain until
1302 * processed. Other messages are removed from the queue.
1304 * RETURNS
1306 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1308 * CONFORMANCE
1310 * ECMA-234, Win32
1313 BOOL WINAPI GetMessageW(
1314 MSG* lpmsg, /* buffer to receive message */
1315 HWND hwnd, /* restrict to messages for hwnd */
1316 UINT min, /* minimum message to receive */
1317 UINT max /* maximum message to receive */
1319 /* FIXME */
1320 return GetMessageA(lpmsg, hwnd, min, max);
1324 /***********************************************************************
1325 * PostMessage16 (USER.110)
1327 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1328 LPARAM lParam )
1330 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1334 /***********************************************************************
1335 * PostMessage32A (USER32.419)
1337 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1338 LPARAM lParam )
1340 MSG msg;
1341 WND *wndPtr;
1342 BOOL retvalue;
1344 msg.hwnd = hwnd;
1345 msg.message = message;
1346 msg.wParam = wParam;
1347 msg.lParam = lParam;
1348 msg.time = GetTickCount();
1349 msg.pt.x = 0;
1350 msg.pt.y = 0;
1352 #ifdef CONFIG_IPC
1353 if (DDE_PostMessage(&msg))
1354 return TRUE;
1355 #endif /* CONFIG_IPC */
1357 if (hwnd == HWND_BROADCAST)
1359 WND *pDesktop = WIN_GetDesktop();
1360 TRACE(msg,"HWND_BROADCAST !\n");
1362 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1364 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1366 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1367 wndPtr->hwndSelf, message, wParam, lParam);
1368 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1371 WIN_ReleaseDesktop();
1372 TRACE(msg,"End of HWND_BROADCAST !\n");
1373 return TRUE;
1376 wndPtr = WIN_FindWndPtr( hwnd );
1377 if (!wndPtr || !wndPtr->hmemTaskQ)
1379 retvalue = FALSE;
1380 goto END;
1383 retvalue = QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1384 END:
1385 WIN_ReleaseWndPtr(wndPtr);
1386 return retvalue;
1390 /***********************************************************************
1391 * PostMessage32W (USER32.420)
1393 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1394 LPARAM lParam )
1396 /* FIXME */
1397 return PostMessageA( hwnd, message, wParam, lParam );
1401 /***********************************************************************
1402 * PostAppMessage16 (USER.116)
1404 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1405 LPARAM lParam )
1407 MSG msg;
1409 if (GetTaskQueue16(hTask) == 0) return FALSE;
1410 msg.hwnd = 0;
1411 msg.message = message;
1412 msg.wParam = wParam;
1413 msg.lParam = lParam;
1414 msg.time = GetTickCount();
1415 msg.pt.x = 0;
1416 msg.pt.y = 0;
1418 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1421 /************************************************************************
1422 * MSG_CallWndProcHook32
1424 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1426 CWPSTRUCT cwp;
1428 cwp.lParam = pmsg->lParam;
1429 cwp.wParam = pmsg->wParam;
1430 cwp.message = pmsg->message;
1431 cwp.hwnd = pmsg->hwnd;
1433 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1434 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1436 pmsg->lParam = cwp.lParam;
1437 pmsg->wParam = cwp.wParam;
1438 pmsg->message = cwp.message;
1439 pmsg->hwnd = cwp.hwnd;
1443 /***********************************************************************
1444 * MSG_SendMessage
1446 * return values: 0 if timeout occurs
1447 * 1 otherwise
1449 LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1450 LPARAM lParam, DWORD timeout, WORD flags,
1451 LRESULT *pRes)
1453 WND * wndPtr = 0;
1454 WND **list, **ppWnd;
1455 LRESULT ret = 1;
1457 *pRes = 0;
1459 if (hwnd == HWND_BROADCAST)
1461 *pRes = 1;
1463 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1465 WIN_ReleaseDesktop();
1466 return 1;
1468 WIN_ReleaseDesktop();
1470 TRACE(msg,"HWND_BROADCAST !\n");
1471 for (ppWnd = list; *ppWnd; ppWnd++)
1473 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1474 if (!IsWindow(wndPtr->hwndSelf)) continue;
1475 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1477 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1478 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1479 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1480 timeout, flags, pRes);
1483 WIN_ReleaseWndPtr(wndPtr);
1484 WIN_ReleaseWinArray(list);
1485 TRACE(msg,"End of HWND_BROADCAST !\n");
1486 return 1;
1489 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1491 if (flags & SMSG_UNICODE)
1492 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1493 else if (flags & SMSG_WIN32)
1494 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1495 else
1497 LPCWPSTRUCT16 pmsg;
1499 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1501 pmsg->hwnd = hwnd & 0xffff;
1502 pmsg->message= msg & 0xffff;
1503 pmsg->wParam = wParam & 0xffff;
1504 pmsg->lParam = lParam;
1505 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1506 (LPARAM)SEGPTR_GET(pmsg) );
1507 hwnd = pmsg->hwnd;
1508 msg = pmsg->message;
1509 wParam = pmsg->wParam;
1510 lParam = pmsg->lParam;
1511 SEGPTR_FREE( pmsg );
1516 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1518 WARN(msg, "invalid hwnd %04x\n", hwnd );
1519 return 0;
1521 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1523 ret = 0; /* Don't send anything if the task is dying */
1524 goto END;
1526 if (flags & SMSG_WIN32)
1527 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1528 else
1529 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1531 if (wndPtr->hmemTaskQ != GetFastQueue16())
1532 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1533 wParam, lParam, timeout, flags, pRes );
1534 else
1536 /* Call the right CallWindowProc flavor */
1537 if (flags & SMSG_UNICODE)
1538 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1539 hwnd, msg, wParam, lParam );
1540 else if (flags & SMSG_WIN32)
1541 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1542 hwnd, msg, wParam, lParam );
1543 else
1544 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1545 (HWND16) hwnd, (UINT16) msg,
1546 (WPARAM16) wParam, lParam );
1549 if (flags & SMSG_WIN32)
1550 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1551 else
1552 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1553 END:
1554 WIN_ReleaseWndPtr(wndPtr);
1555 return ret;
1559 /***********************************************************************
1560 * SendMessage16 (USER.111)
1562 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1563 LPARAM lParam)
1565 LRESULT res;
1566 #ifdef CONFIG_IPC
1567 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1568 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1569 #endif /* CONFIG_IPC */
1571 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1573 return res;
1578 /**********************************************************************
1579 * PostThreadMessage32A (USER32.422)
1581 * BUGS
1583 * Thread-local message queues are not supported.
1586 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1587 WPARAM wParam, LPARAM lParam )
1589 MSG msg;
1590 HQUEUE16 hQueue;
1592 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1593 return FALSE;
1595 msg.hwnd = 0;
1596 msg.message = message;
1597 msg.wParam = wParam;
1598 msg.lParam = lParam;
1599 msg.time = GetTickCount();
1600 msg.pt.x = 0;
1601 msg.pt.y = 0;
1603 return QUEUE_AddMsg( hQueue, &msg, 0 );
1606 /**********************************************************************
1607 * PostThreadMessage32W (USER32.423)
1609 * BUGS
1611 * Thread-local message queues are not supported.
1614 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1615 WPARAM wParam, LPARAM lParam )
1617 FIXME(sendmsg, "(...): Should do unicode/ascii conversion!\n");
1618 return PostThreadMessageA(idThread, message, wParam, lParam);
1621 /***********************************************************************
1622 * SendMessage32A (USER32.454)
1624 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1625 LPARAM lParam )
1627 LRESULT res;
1629 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1630 SMSG_WIN32, &res);
1632 return res;
1636 /***********************************************************************
1637 * SendMessage32W (USER32.459) Send Window Message
1639 * Sends a message to the window procedure of the specified window.
1640 * SendMessage() will not return until the called window procedure
1641 * either returns or calls ReplyMessage().
1643 * Use PostMessage() to send message and return immediately. A window
1644 * procedure may use InSendMessage() to detect
1645 * SendMessage()-originated messages.
1647 * Applications which communicate via HWND_BROADCAST may use
1648 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1649 * with other applications.
1651 * CONFORMANCE
1653 * ECMA-234, Win32
1655 LRESULT WINAPI SendMessageW(
1656 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1657 the message will be sent to all top-level windows. */
1659 UINT msg, /* message */
1660 WPARAM wParam, /* message parameter */
1661 LPARAM lParam /* additional message parameter */
1663 LRESULT res;
1665 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1666 SMSG_WIN32 | SMSG_UNICODE, &res);
1668 return res;
1672 /***********************************************************************
1673 * SendMessageTimeout16 (not a WINAPI)
1675 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1676 LPARAM lParam, UINT16 flags,
1677 UINT16 timeout, LPWORD resultp)
1679 LRESULT ret;
1680 LRESULT msgRet;
1682 /* FIXME: need support for SMTO_BLOCK */
1684 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1685 *resultp = (WORD) msgRet;
1686 return ret;
1690 /***********************************************************************
1691 * SendMessageTimeoutA (USER32.457)
1693 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1694 LPARAM lParam, UINT flags,
1695 UINT timeout, LPDWORD resultp)
1697 LRESULT ret;
1698 LRESULT msgRet;
1700 /* FIXME: need support for SMTO_BLOCK */
1702 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1703 &msgRet);
1705 *resultp = (DWORD) msgRet;
1706 return ret;
1710 /***********************************************************************
1711 * SendMessageTimeoutW (USER32.458)
1713 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1714 LPARAM lParam, UINT flags,
1715 UINT timeout, LPDWORD resultp)
1717 LRESULT ret;
1718 LRESULT msgRet;
1720 /* FIXME: need support for SMTO_BLOCK */
1722 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1723 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1725 *resultp = (DWORD) msgRet;
1726 return ret;
1730 /***********************************************************************
1731 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1733 * WaitMessage() suspends a thread until events appear in the thread's
1734 * queue.
1736 * BUGS
1738 * Is supposed to return BOOL under Win32.
1740 * Thread-local message queues are not supported.
1742 * CONFORMANCE
1744 * ECMA-234, Win32
1747 void WINAPI WaitMessage( void )
1749 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1752 /***********************************************************************
1753 * MsgWaitForMultipleObjects (USER32.400)
1755 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1756 BOOL fWaitAll, DWORD dwMilliseconds,
1757 DWORD dwWakeMask )
1759 DWORD i;
1760 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1761 DWORD ret;
1763 HQUEUE16 hQueue = GetFastQueue16();
1764 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1765 if (!msgQueue) return WAIT_FAILED;
1767 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1769 SetLastError( ERROR_INVALID_PARAMETER );
1770 QUEUE_Unlock( msgQueue );
1771 return WAIT_FAILED;
1774 msgQueue->changeBits = 0;
1775 msgQueue->wakeMask = dwWakeMask;
1777 if (THREAD_IsWin16(THREAD_Current()))
1780 * This is a temporary solution to a big problem.
1781 * You see, the main thread of all Win32 programs is created as a 16 bit
1782 * task. This means that if you want on an event using Win32 synchronization
1783 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1784 * This implements a semi-busy loop that checks the handles to wait on and
1785 * also the message queue. When either one is ready, the wait function returns.
1787 * This will all go away when the real Win32 threads are implemented for all
1788 * the threads of an applications. Including the main thread.
1790 DWORD curTime = GetCurrentTime();
1795 * Check the handles in the list.
1797 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1800 * If the handles have been triggered, return.
1802 if (ret != WAIT_TIMEOUT)
1803 break;
1806 * Then, let the 16 bit scheduler do it's thing.
1808 Yield16();
1811 * If a message matching the wait mask has arrived, return.
1813 if (msgQueue->changeBits & dwWakeMask)
1815 ret = nCount;
1816 break;
1820 * And continue doing this until we hit the timeout.
1822 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1824 else
1826 /* Add the thread event to the handle list */
1827 for (i = 0; i < nCount; i++)
1828 handles[i] = pHandles[i];
1829 handles[nCount] = msgQueue->hEvent;
1831 EVENT_Pending();
1833 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1836 QUEUE_Unlock( msgQueue );
1838 return ret;
1843 struct accent_char
1845 BYTE ac_accent;
1846 BYTE ac_char;
1847 BYTE ac_result;
1850 static const struct accent_char accent_chars[] =
1852 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1853 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1854 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1855 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1856 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1857 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1858 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1859 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1860 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1861 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1862 {',', 'C', '\307'}, {',', 'c', '\347'},
1863 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1864 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1865 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1866 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1867 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1868 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1869 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1870 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1871 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1872 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1873 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1874 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1875 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1876 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1877 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1878 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1879 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1880 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1881 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1882 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1883 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1884 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1885 {'s', 's', '\337'}, {'"', 'y', '\377'},
1886 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1887 /* iso-8859-2 uses this */
1888 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1889 {'<', 'S', '\251'}, {'<', 's', '\271'},
1890 {'<', 'T', '\253'}, {'<', 't', '\273'},
1891 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1892 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1893 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1894 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1895 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1896 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1897 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1898 {';', 'E', '\312'}, {';', 'e', '\332'},
1899 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1900 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1901 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1902 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1903 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1904 /* collision whith S, from iso-8859-9 !!! */
1905 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1906 {',', 'T', '\336'}, {',', 't', '\376'},
1907 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1908 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1909 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1910 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1911 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1912 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1913 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1914 /* iso-8859-3 uses this */
1915 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1916 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1917 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1918 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1919 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1920 {'>', 'S', '\336'}, {'>', 's', '\376'},
1921 /* collision whith G( from iso-8859-9 !!! */
1922 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1923 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1924 /* collision whith I. from iso-8859-3 !!! */
1925 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1926 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1927 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1928 /* iso-8859-4 uses this */
1929 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1930 {',', 'L', '\246'}, {',', 'l', '\266'},
1931 {',', 'G', '\253'}, {',', 'g', '\273'},
1932 {',', 'N', '\321'}, {',', 'n', '\361'},
1933 {',', 'K', '\323'}, {',', 'k', '\363'},
1934 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1935 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1936 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1937 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1938 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1939 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1940 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1941 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1942 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1943 {';', 'U', '\331'}, {';', 'u', '\371'},
1944 /* iso-8859-9 uses this */
1945 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1946 * whith the same letters on other iso-8859-x (that is they are on
1947 * different places :-( ), if you use turkish uncomment these and
1948 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1949 * FIXME: should be dynamic according to chosen language
1950 * if/when Wine has turkish support.
1952 /* collision whith G( from iso-8859-3 !!! */
1953 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1954 /* collision whith S, from iso-8859-2 !!! */
1955 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1956 /* collision whith I. from iso-8859-3 !!! */
1957 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1961 /***********************************************************************
1962 * MSG_DoTranslateMessage
1964 * Implementation of TranslateMessage.
1966 * TranslateMessage translates virtual-key messages into character-messages,
1967 * as follows :
1968 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1969 * ditto replacing WM_* with WM_SYS*
1970 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1971 * by the keyboard driver.
1973 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
1974 WPARAM wParam, LPARAM lParam )
1976 static int dead_char;
1977 BYTE wp[2];
1979 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1980 TRACE(msg, "(%s, %04X, %08lX)\n",
1981 SPY_GetMsgName(message), wParam, lParam );
1982 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1983 TRACE(key, "(%s, %04X, %08lX)\n",
1984 SPY_GetMsgName(message), wParam, lParam );
1986 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1988 TRACE(key, "Translating key %04X, scancode %04X\n",
1989 wParam, HIWORD(lParam) );
1991 /* FIXME : should handle ToAscii yielding 2 */
1992 switch (ToAscii(wParam, HIWORD(lParam),
1993 QueueKeyStateTable,(LPWORD)wp, 0))
1995 case 1 :
1996 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1997 /* Should dead chars handling go in ToAscii ? */
1998 if (dead_char)
2000 int i;
2002 if (wp[0] == ' ') wp[0] = dead_char;
2003 if (dead_char == 0xa2) dead_char = '(';
2004 else if (dead_char == 0xa8) dead_char = '"';
2005 else if (dead_char == 0xb2) dead_char = ';';
2006 else if (dead_char == 0xb4) dead_char = '\'';
2007 else if (dead_char == 0xb7) dead_char = '<';
2008 else if (dead_char == 0xb8) dead_char = ',';
2009 else if (dead_char == 0xff) dead_char = '.';
2010 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2011 if ((accent_chars[i].ac_accent == dead_char) &&
2012 (accent_chars[i].ac_char == wp[0]))
2014 wp[0] = accent_chars[i].ac_result;
2015 break;
2017 dead_char = 0;
2019 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2020 PostMessage16( hwnd, message, wp[0], lParam );
2021 return TRUE;
2023 case -1 :
2024 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2025 dead_char = wp[0];
2026 TRACE(key, "-1 -> PostMessage(%s)\n",
2027 SPY_GetMsgName(message));
2028 PostMessage16( hwnd, message, wp[0], lParam );
2029 return TRUE;
2031 return FALSE;
2035 /***********************************************************************
2036 * TranslateMessage16 (USER.113)
2038 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2040 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2041 msg->wParam, msg->lParam );
2045 /***********************************************************************
2046 * WIN16_TranslateMessage32 (USER.821)
2048 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2050 WPARAM wParam;
2052 if (wHaveParamHigh)
2053 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2054 else
2055 wParam = (WPARAM)msg->msg.wParam;
2057 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2058 wParam, msg->msg.lParam );
2061 /***********************************************************************
2062 * TranslateMessage32 (USER32.556)
2064 BOOL WINAPI TranslateMessage( const MSG *msg )
2066 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2067 msg->wParam, msg->lParam );
2071 /***********************************************************************
2072 * DispatchMessage16 (USER.114)
2074 LONG WINAPI DispatchMessage16( const MSG16* msg )
2076 WND * wndPtr;
2077 LONG retval;
2078 int painting;
2080 /* Process timer messages */
2081 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2083 if (msg->lParam)
2085 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2086 msg->message, msg->wParam, GetTickCount() );
2090 if (!msg->hwnd) return 0;
2091 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2092 if (!wndPtr->winproc)
2094 retval = 0;
2095 goto END;
2097 painting = (msg->message == WM_PAINT);
2098 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2100 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2101 msg->wParam, msg->lParam );
2102 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2103 msg->hwnd, msg->message,
2104 msg->wParam, msg->lParam );
2105 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2107 WIN_ReleaseWndPtr(wndPtr);
2108 wndPtr = WIN_FindWndPtr(msg->hwnd);
2109 if (painting && wndPtr &&
2110 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2112 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2113 msg->hwnd);
2114 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2115 /* Validate the update region to avoid infinite WM_PAINT loop */
2116 ValidateRect( msg->hwnd, NULL );
2118 END:
2119 WIN_ReleaseWndPtr(wndPtr);
2120 return retval;
2124 /***********************************************************************
2125 * WIN16_DispatchMessage32 (USER.822)
2127 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2129 if (wHaveParamHigh == FALSE)
2130 return DispatchMessage16(&(lpmsg16_32->msg));
2131 else
2133 MSG msg;
2135 msg.hwnd = lpmsg16_32->msg.hwnd;
2136 msg.message = lpmsg16_32->msg.message;
2137 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2138 msg.lParam = lpmsg16_32->msg.lParam;
2139 msg.time = lpmsg16_32->msg.time;
2140 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2141 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2142 return DispatchMessageA(&msg);
2146 /***********************************************************************
2147 * DispatchMessage32A (USER32.141)
2149 LONG WINAPI DispatchMessageA( const MSG* msg )
2151 WND * wndPtr;
2152 LONG retval;
2153 int painting;
2155 /* Process timer messages */
2156 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2158 if (msg->lParam)
2160 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2161 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2162 msg->message, msg->wParam, GetTickCount() );
2166 if (!msg->hwnd) return 0;
2167 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2168 if (!wndPtr->winproc)
2170 retval = 0;
2171 goto END;
2173 painting = (msg->message == WM_PAINT);
2174 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2175 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2177 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2178 msg->wParam, msg->lParam );
2179 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2180 msg->hwnd, msg->message,
2181 msg->wParam, msg->lParam );
2182 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2184 WIN_ReleaseWndPtr(wndPtr);
2185 wndPtr = WIN_FindWndPtr(msg->hwnd);
2187 if (painting && wndPtr &&
2188 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2190 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2191 msg->hwnd);
2192 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2193 /* Validate the update region to avoid infinite WM_PAINT loop */
2194 ValidateRect( msg->hwnd, NULL );
2196 END:
2197 WIN_ReleaseWndPtr(wndPtr);
2198 return retval;
2202 /***********************************************************************
2203 * DispatchMessage32W (USER32.142) Process Message
2205 * Process the message specified in the structure *_msg_.
2207 * If the lpMsg parameter points to a WM_TIMER message and the
2208 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2209 * points to the function that is called instead of the window
2210 * procedure.
2212 * The message must be valid.
2214 * RETURNS
2216 * DispatchMessage() returns the result of the window procedure invoked.
2218 * CONFORMANCE
2220 * ECMA-234, Win32
2223 LONG WINAPI DispatchMessageW( const MSG* msg )
2225 WND * wndPtr;
2226 LONG retval;
2227 int painting;
2229 /* Process timer messages */
2230 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2232 if (msg->lParam)
2234 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2235 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2236 msg->message, msg->wParam, GetTickCount() );
2240 if (!msg->hwnd) return 0;
2241 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2242 if (!wndPtr->winproc)
2244 retval = 0;
2245 goto END;
2247 painting = (msg->message == WM_PAINT);
2248 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2249 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2251 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2252 msg->wParam, msg->lParam );
2253 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2254 msg->hwnd, msg->message,
2255 msg->wParam, msg->lParam );
2256 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2258 WIN_ReleaseWndPtr(wndPtr);
2259 wndPtr = WIN_FindWndPtr(msg->hwnd);
2261 if (painting && wndPtr &&
2262 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2264 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2265 msg->hwnd);
2266 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2267 /* Validate the update region to avoid infinite WM_PAINT loop */
2268 ValidateRect( msg->hwnd, NULL );
2270 END:
2271 WIN_ReleaseWndPtr(wndPtr);
2272 return retval;
2276 /***********************************************************************
2277 * RegisterWindowMessage16 (USER.118)
2279 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2281 TRACE(msg, "%08lx\n", (DWORD)str );
2282 return GlobalAddAtom16( str );
2286 /***********************************************************************
2287 * RegisterWindowMessage32A (USER32.437)
2289 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2291 TRACE(msg, "%s\n", str );
2292 return GlobalAddAtomA( str );
2296 /***********************************************************************
2297 * RegisterWindowMessage32W (USER32.438)
2299 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2301 TRACE(msg, "%p\n", str );
2302 return GlobalAddAtomW( str );
2306 /***********************************************************************
2307 * GetTickCount (USER.13) (KERNEL32.299) System Time
2308 * Returns the number of milliseconds, modulo 2^32, since the start
2309 * of the current session.
2311 * CONFORMANCE
2313 * ECMA-234, Win32
2315 DWORD WINAPI GetTickCount(void)
2317 struct timeval t;
2318 gettimeofday( &t, NULL );
2319 /* make extremely compatible: granularity is 25 msec */
2320 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2324 /***********************************************************************
2325 * GetCurrentTime16 (USER.15)
2327 * (effectively identical to GetTickCount)
2329 DWORD WINAPI GetCurrentTime16(void)
2331 return GetTickCount();
2335 /***********************************************************************
2336 * InSendMessage16 (USER.192)
2338 BOOL16 WINAPI InSendMessage16(void)
2340 return InSendMessage();
2344 /***********************************************************************
2345 * InSendMessage32 (USER32.320)
2347 BOOL WINAPI InSendMessage(void)
2349 MESSAGEQUEUE *queue;
2350 BOOL ret;
2352 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2353 return 0;
2354 ret = (BOOL)queue->smWaiting;
2356 QUEUE_Unlock( queue );
2357 return ret;
2360 /***********************************************************************
2361 * BroadcastSystemMessage (USER32.12)
2363 LONG WINAPI BroadcastSystemMessage(
2364 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2365 LPARAM lParam
2367 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2368 dwFlags,*recipients,uMessage,wParam,lParam
2370 return 0;
2373 /***********************************************************************
2374 * SendNotifyMessageA (USER32.460)
2375 * FIXME
2376 * The message sended with PostMessage has to be put in the queue
2377 * with a higher priority as the other "Posted" messages.
2378 * QUEUE_AddMsg has to be modifyed.
2380 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2381 { BOOL ret = TRUE;
2382 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2383 hwnd, msg, wParam, lParam);
2385 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2386 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2388 else
2389 { PostMessageA ( hwnd, msg, wParam, lParam );
2391 return ret;
2394 /***********************************************************************
2395 * SendNotifyMessageW (USER32.461)
2396 * FIXME
2397 * The message sended with PostMessage has to be put in the queue
2398 * with a higher priority as the other "Posted" messages.
2399 * QUEUE_AddMsg has to be modifyed.
2401 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2402 { BOOL ret = TRUE;
2403 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2404 hwnd, msg, wParam, lParam);
2406 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2407 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2409 else
2410 { PostMessageW ( hwnd, msg, wParam, lParam );
2412 return ret;
2415 /***********************************************************************
2416 * SendMessageCallBack32A
2417 * FIXME: It's like PostMessage. The callback gets called when the message
2418 * is processed. We have to modify the message processing for a exact
2419 * implementation...
2421 BOOL WINAPI SendMessageCallBackA(
2422 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2423 FARPROC lpResultCallBack,DWORD dwData)
2425 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2426 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2427 if ( hWnd == HWND_BROADCAST)
2428 { PostMessageA( hWnd, Msg, wParam, lParam);
2429 FIXME(msg,"Broadcast: Callback will not be called!\n");
2430 return TRUE;
2432 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2433 return TRUE;