Started moving some X11 window management code to windows/x11drv.
[wine.git] / windows / message.c
blobc42d49b0e0e95199ecbbc9f52bcdb2f292bc61a5
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 "message.h"
14 #include "win.h"
15 #include "gdi.h"
16 #include "sysmetrics.h"
17 #include "heap.h"
18 #include "hook.h"
19 #include "keyboard.h"
20 #include "spy.h"
21 #include "winpos.h"
22 #include "atom.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 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
34 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
36 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
37 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
39 extern MESSAGEQUEUE *pCursorQueue; /* queue.c */
40 extern MESSAGEQUEUE *pActiveQueue;
42 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
44 static UINT32 doubleClickSpeed = 452;
45 static INT32 debugSMRL = 0; /* intertask SendMessage() recursion level */
47 /***********************************************************************
48 * MSG_CheckFilter
50 BOOL32 MSG_CheckFilter(WORD uMsg, DWORD filter)
52 if( filter )
53 return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter));
54 return TRUE;
57 /***********************************************************************
58 * MSG_SendParentNotify
60 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
61 * the window has the WS_EX_NOPARENTNOTIFY style.
63 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
65 #define lppt ((LPPOINT16)&lValue)
67 /* pt has to be in the client coordinates of the parent window */
69 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
70 while (wndPtr)
72 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
73 lppt->x += wndPtr->rectClient.left;
74 lppt->y += wndPtr->rectClient.top;
75 wndPtr = wndPtr->parent;
76 SendMessage32A( wndPtr->hwndSelf, WM_PARENTNOTIFY,
77 MAKEWPARAM( event, idChild ), lValue );
79 #undef lppt
83 /***********************************************************************
84 * MSG_TranslateMouseMsg
86 * Translate an mouse hardware event into a real mouse message.
87 * Return value indicates whether the translated message must be passed
88 * to the user, left in the queue, or skipped entirely (in this case
89 * HIWORD contains hit test code).
91 static DWORD MSG_TranslateMouseMsg( HWND16 hTopWnd, DWORD filter,
92 MSG16 *msg, BOOL32 remove, WND* pWndScope )
94 static DWORD dblclk_time_limit = 0;
95 static UINT16 clk_message = 0;
96 static HWND16 clk_hwnd = 0;
97 static POINT16 clk_pos = { 0, 0 };
99 WND *pWnd;
100 HWND16 hWnd;
101 INT16 ht, hittest, sendSC = 0;
102 UINT16 message = msg->message;
103 POINT16 screen_pt, pt;
104 HANDLE16 hQ = GetTaskQueue(0);
105 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16(hQ);
106 BOOL32 eatMsg = FALSE;
107 BOOL32 mouseClick = ((message == WM_LBUTTONDOWN) ||
108 (message == WM_RBUTTONDOWN) ||
109 (message == WM_MBUTTONDOWN))?1:0;
110 SYSQ_STATUS ret = 0;
112 /* Find the window */
114 ht = hittest = HTCLIENT;
115 hWnd = GetCapture16();
116 if( !hWnd )
118 ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd );
119 if( !pWnd ) pWnd = WIN_GetDesktop();
120 hWnd = pWnd->hwndSelf;
121 sendSC = 1;
123 else
125 pWnd = WIN_FindWndPtr(hWnd);
126 ht = EVENT_GetCaptureInfo();
129 /* stop if not the right queue */
131 if (pWnd->hmemTaskQ != hQ)
133 /* Not for the current task */
134 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
135 /* Wake up the other task */
136 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
137 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
138 return SYSQ_MSG_ABANDON;
141 /* check if hWnd is within hWndScope */
143 if( hTopWnd && hWnd != hTopWnd )
144 if( !IsChild16(hTopWnd, hWnd) ) return SYSQ_MSG_CONTINUE;
146 if( mouseClick )
148 /* translate double clicks -
149 * note that ...MOUSEMOVEs can slip in between
150 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
152 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
154 if ((message == clk_message) && (hWnd == clk_hwnd) &&
155 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
156 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
157 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
159 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
160 mouseClick++; /* == 2 */
164 screen_pt = pt = msg->pt;
166 if (hittest != HTCLIENT)
168 message += ((INT16)WM_NCMOUSEMOVE - WM_MOUSEMOVE);
169 msg->wParam = hittest;
171 else ScreenToClient16( hWnd, &pt );
173 /* check message filter */
175 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
177 pCursorQueue = queue;
179 /* call WH_MOUSE */
181 if (HOOK_IsHooked( WH_MOUSE ))
183 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
184 if( hook )
186 hook->pt = screen_pt;
187 hook->hwnd = hWnd;
188 hook->wHitTestCode = hittest;
189 hook->dwExtraInfo = 0;
190 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
191 message, (LPARAM)SEGPTR_GET(hook) );
192 SEGPTR_FREE(hook);
194 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
197 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
198 eatMsg = sendSC = 1;
199 else if( remove && mouseClick )
201 HWND32 hwndTop = WIN_GetTopParent( hWnd );
203 if( mouseClick == 1 )
205 /* set conditions */
206 dblclk_time_limit = msg->time;
207 clk_message = msg->message;
208 clk_hwnd = hWnd;
209 clk_pos = screen_pt;
210 } else
211 /* got double click - zero them out */
212 dblclk_time_limit = clk_hwnd = 0;
214 if( sendSC )
216 /* Send the WM_PARENTNOTIFY,
217 * note that even for double/nonclient clicks
218 * notification message is still WM_L/M/RBUTTONDOWN.
221 MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
223 /* Activate the window if needed */
225 if (hWnd != GetActiveWindow16() && hWnd != GetDesktopWindow16())
227 LONG ret = SendMessage16( hWnd, WM_MOUSEACTIVATE, hwndTop,
228 MAKELONG( hittest, message ) );
230 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
231 eatMsg = TRUE;
233 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
234 && hwndTop != GetActiveWindow16() )
235 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
236 eatMsg = TRUE;
239 } else sendSC = (remove && sendSC);
241 /* Send the WM_SETCURSOR message */
243 if (sendSC)
244 SendMessage16( hWnd, WM_SETCURSOR, (WPARAM16)hWnd,
245 MAKELONG( hittest, message ));
246 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
248 msg->hwnd = hWnd;
249 msg->message = message;
250 msg->lParam = MAKELONG( pt.x, pt.y );
251 return SYSQ_MSG_ACCEPT;
255 /***********************************************************************
256 * MSG_TranslateKbdMsg
258 * Translate an keyboard hardware event into a real message.
260 static DWORD MSG_TranslateKbdMsg( HWND16 hTopWnd, DWORD filter,
261 MSG16 *msg, BOOL32 remove )
263 WORD message = msg->message;
264 HWND16 hWnd = GetFocus16();
265 WND *pWnd;
267 /* Should check Ctrl-Esc and PrintScreen here */
269 if (!hWnd)
271 /* Send the message to the active window instead, */
272 /* translating messages to their WM_SYS equivalent */
274 hWnd = GetActiveWindow16();
276 if( message < WM_SYSKEYDOWN )
277 message += WM_SYSKEYDOWN - WM_KEYDOWN;
279 pWnd = WIN_FindWndPtr( hWnd );
280 if (pWnd && (pWnd->hmemTaskQ != GetTaskQueue(0)))
282 /* Not for the current task */
283 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) );
284 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
285 /* Wake up the other task */
286 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
287 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
288 return SYSQ_MSG_ABANDON;
291 if (hTopWnd && hWnd != hTopWnd)
292 if (!IsChild16(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
293 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
295 msg->hwnd = hWnd;
296 msg->message = message;
298 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
299 msg->wParam, msg->lParam )
300 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
304 /***********************************************************************
305 * MSG_JournalRecordMsg
307 * Build an EVENTMSG structure and call JOURNALRECORD hook
309 static void MSG_JournalRecordMsg( MSG16 *msg )
311 EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
312 if (!event) return;
313 event->message = msg->message;
314 event->time = msg->time;
315 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
317 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
318 event->paramH = msg->lParam & 0x7FFF;
319 if (HIWORD(msg->lParam) & 0x0100)
320 event->paramH |= 0x8000; /* special_key - bit */
321 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
322 (LPARAM)SEGPTR_GET(event) );
324 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
326 event->paramL = LOWORD(msg->lParam); /* X pos */
327 event->paramH = HIWORD(msg->lParam); /* Y pos */
328 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
329 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
330 (LPARAM)SEGPTR_GET(event) );
332 else if ((msg->message >= WM_NCMOUSEFIRST) &&
333 (msg->message <= WM_NCMOUSELAST))
335 event->paramL = LOWORD(msg->lParam); /* X pos */
336 event->paramH = HIWORD(msg->lParam); /* Y pos */
337 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
338 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
339 (LPARAM)SEGPTR_GET(event) );
341 SEGPTR_FREE(event);
344 /***********************************************************************
345 * MSG_JournalPlayBackMsg
347 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
349 static int MSG_JournalPlayBackMsg(void)
351 EVENTMSG16 *tmpMsg;
352 long wtime,lParam;
353 WORD keyDown,i,wParam,result=0;
355 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
357 tmpMsg = SEGPTR_NEW(EVENTMSG16);
358 wtime=HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
359 (LPARAM)SEGPTR_GET(tmpMsg));
360 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
361 if (wtime<=0)
363 wtime=0;
364 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
366 wParam=tmpMsg->paramL & 0xFF;
367 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
368 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
370 for (keyDown=i=0; i<256 && !keyDown; i++)
371 if (InputKeyStateTable[i] & 0x80)
372 keyDown++;
373 if (!keyDown)
374 lParam |= 0x40000000;
375 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
377 else /* WM_KEYUP, WM_SYSKEYUP */
379 lParam |= 0xC0000000;
380 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
382 if (InputKeyStateTable[VK_MENU] & 0x80)
383 lParam |= 0x20000000;
384 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
385 lParam |= 0x01000000;
386 hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );
388 else
390 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
392 switch (tmpMsg->message)
394 case WM_LBUTTONDOWN:
395 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
396 case WM_LBUTTONUP:
397 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
398 case WM_MBUTTONDOWN:
399 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
400 case WM_MBUTTONUP:
401 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
402 case WM_RBUTTONDOWN:
403 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
404 case WM_RBUTTONUP:
405 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
407 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
408 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
409 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
410 SetCursorPos32(tmpMsg->paramL,tmpMsg->paramH);
411 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
412 wParam=0;
413 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
414 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
415 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
416 hardware_event( tmpMsg->message, wParam, lParam,
417 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
420 HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_SKIP, 0,
421 (LPARAM)SEGPTR_GET(tmpMsg));
423 else
425 if( tmpMsg->message == WM_QUEUESYNC )
426 if (HOOK_IsHooked( WH_CBT ))
427 HOOK_CallHooks16( WH_CBT, HCBT_QS, 0, 0L);
429 result= QS_MOUSE | QS_KEY; /* ? */
431 SEGPTR_FREE(tmpMsg);
433 return result;
436 /***********************************************************************
437 * MSG_PeekHardwareMsg
439 * Peek for a hardware message matching the hwnd and message filters.
441 static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
442 BOOL32 remove )
444 DWORD status = SYSQ_MSG_ACCEPT;
445 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
446 int i, kbd_msg, pos = sysMsgQueue->nextMessage;
448 /* FIXME: there has to be a better way to do this */
449 joySendMessages();
451 /* If the queue is empty, attempt to fill it */
452 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
453 && TSXPending(display))
454 EVENT_WaitNetEvent( FALSE, FALSE );
456 for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
458 if (pos >= sysMsgQueue->queueSize) pos = 0;
459 *msg = sysMsgQueue->messages[pos].msg;
461 /* Translate message */
463 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
465 HWND32 hWndScope = (HWND32)sysMsgQueue->messages[pos].extraInfo;
467 status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
468 (Options.managed && IsWindow32(hWndScope) )
469 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
470 kbd_msg = 0;
472 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
474 status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove);
475 kbd_msg = 1;
477 else /* Non-standard hardware event */
479 HARDWAREHOOKSTRUCT16 *hook;
480 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
482 BOOL32 ret;
483 hook->hWnd = msg->hwnd;
484 hook->wMessage = msg->message;
485 hook->wParam = msg->wParam;
486 hook->lParam = msg->lParam;
487 ret = HOOK_CallHooks16( WH_HARDWARE,
488 remove ? HC_ACTION : HC_NOREMOVE,
489 0, (LPARAM)SEGPTR_GET(hook) );
490 SEGPTR_FREE(hook);
491 if (ret)
493 QUEUE_RemoveMsg( sysMsgQueue, pos );
494 continue;
496 status = SYSQ_MSG_ACCEPT;
500 switch (LOWORD(status))
502 case SYSQ_MSG_ACCEPT:
503 break;
505 case SYSQ_MSG_SKIP:
506 if (HOOK_IsHooked( WH_CBT ))
507 if( kbd_msg )
508 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
509 msg->wParam, msg->lParam );
510 else
512 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
513 if (hook)
515 hook->pt = msg->pt;
516 hook->hwnd = msg->hwnd;
517 hook->wHitTestCode = HIWORD(status);
518 hook->dwExtraInfo = 0;
519 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message,
520 (LPARAM)SEGPTR_GET(hook) );
521 SEGPTR_FREE(hook);
525 if (remove)
526 QUEUE_RemoveMsg( sysMsgQueue, pos );
527 /* continue */
529 case SYSQ_MSG_CONTINUE:
530 continue;
532 case SYSQ_MSG_ABANDON:
533 return FALSE;
536 if (remove)
538 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
539 QUEUE_RemoveMsg( sysMsgQueue, pos );
541 return TRUE;
543 return FALSE;
547 /**********************************************************************
548 * SetDoubleClickTime16 (USER.20)
550 void WINAPI SetDoubleClickTime16( UINT16 interval )
552 SetDoubleClickTime32( interval );
556 /**********************************************************************
557 * SetDoubleClickTime32 (USER32.480)
559 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
561 doubleClickSpeed = interval ? interval : 500;
562 return TRUE;
566 /**********************************************************************
567 * GetDoubleClickTime16 (USER.21)
569 UINT16 WINAPI GetDoubleClickTime16(void)
571 return doubleClickSpeed;
575 /**********************************************************************
576 * GetDoubleClickTime32 (USER32.239)
578 UINT32 WINAPI GetDoubleClickTime32(void)
580 return doubleClickSpeed;
584 /***********************************************************************
585 * MSG_SendMessage
587 * Implementation of an inter-task SendMessage.
589 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
590 WPARAM32 wParam, LPARAM lParam, WORD flags )
592 INT32 prevSMRL = debugSMRL;
593 QSMCTRL qCtrl = { 0, 1};
594 MESSAGEQUEUE *queue, *destQ;
596 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return 0;
597 if (!(destQ = (MESSAGEQUEUE*)GlobalLock16( hDestQueue ))) return 0;
599 if (IsTaskLocked() || !IsWindow32(hwnd)) return 0;
601 debugSMRL+=4;
602 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
603 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
605 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
607 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
608 queue->changeBits &= ~QS_SMPARAMSFREE;
609 QUEUE_WaitBits( QS_SMPARAMSFREE );
612 /* resume sending */
614 queue->hWnd = hwnd;
615 queue->msg = msg;
616 queue->wParam = LOWORD(wParam);
617 queue->wParamHigh = HIWORD(wParam);
618 queue->lParam = lParam;
619 queue->hPrevSendingTask = destQ->hSendingTask;
620 destQ->hSendingTask = GetTaskQueue(0);
622 queue->wakeBits &= ~QS_SMPARAMSFREE;
623 queue->flags = (queue->flags & ~(QUEUE_SM_WIN32|QUEUE_SM_UNICODE)) | flags;
625 TRACE(sendmsg,"%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl);
627 queue->smResultInit = &qCtrl;
629 QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE );
631 /* perform task switch and wait for the result */
633 while( qCtrl.bPending )
635 if (!(queue->wakeBits & QS_SMRESULT))
637 queue->changeBits &= ~QS_SMRESULT;
638 if (THREAD_IsWin16( THREAD_Current() ))
639 DirectedYield( destQ->hTask );
640 else
641 QUEUE_Signal( destQ->hTask );
642 QUEUE_WaitBits( QS_SMRESULT );
643 TRACE(sendmsg,"\tsm: have result!\n");
645 /* got something */
647 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
649 if (queue->smResult) { /* FIXME, smResult should always be set */
650 queue->smResult->lResult = queue->SendMessageReturn;
651 queue->smResult->bPending = FALSE;
653 queue->wakeBits &= ~QS_SMRESULT;
655 if( queue->smResult != &qCtrl )
656 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
658 queue->smResultInit = NULL;
660 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
661 debugSMRL-=4;
663 return qCtrl.lResult;
667 /***********************************************************************
668 * ReplyMessage16 (USER.115)
670 void WINAPI ReplyMessage16( LRESULT result )
672 MESSAGEQUEUE *senderQ;
673 MESSAGEQUEUE *queue;
675 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return;
677 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
679 while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
681 TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
682 queue->msg, queue->self, senderQ->self);
684 if( queue->wakeBits & QS_SENDMESSAGE )
686 QUEUE_ReceiveMessage( queue );
687 continue; /* ReceiveMessage() already called us */
690 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
691 if (THREAD_IsWin16(THREAD_Current())) OldYield();
693 if( !senderQ ) { TRACE(msg,"\trpm: done\n"); return; }
695 senderQ->SendMessageReturn = result;
696 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
697 (unsigned)queue->smResultCurrent, result );
699 senderQ->smResult = queue->smResultCurrent;
700 queue->InSendMessageHandle = 0;
702 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
703 if (THREAD_IsWin16(THREAD_Current())) DirectedYield( queue->hSendingTask );
707 /***********************************************************************
708 * MSG_PeekMessage
710 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
711 WORD flags, BOOL32 peek )
713 int pos, mask;
714 MESSAGEQUEUE *msgQueue;
715 HQUEUE16 hQueue;
717 #ifdef CONFIG_IPC
718 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
719 DDE_GetRemoteMessage();
720 #endif /* CONFIG_IPC */
722 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
723 if (first || last)
725 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
726 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
727 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
728 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
729 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
730 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
732 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
734 if (IsTaskLocked()) flags |= PM_NOYIELD;
736 /* Never yield on Win32 threads */
737 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
739 while(1)
741 hQueue = GetTaskQueue(0);
742 msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
743 if (!msgQueue) return FALSE;
744 msgQueue->changeBits = 0;
746 /* First handle a message put by SendMessage() */
748 while (msgQueue->wakeBits & QS_SENDMESSAGE)
749 QUEUE_ReceiveMessage( msgQueue );
751 /* Now handle a WM_QUIT message */
753 if (msgQueue->wPostQMsg &&
754 (!first || WM_QUIT >= first) &&
755 (!last || WM_QUIT <= last) )
757 msg->hwnd = hwnd;
758 msg->message = WM_QUIT;
759 msg->wParam = msgQueue->wExitCode;
760 msg->lParam = 0;
761 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
762 break;
765 /* Now find a normal message */
767 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
768 ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
770 QMSG *qmsg = &msgQueue->messages[pos];
771 *msg = qmsg->msg;
772 msgQueue->GetMessageTimeVal = msg->time;
773 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
774 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
776 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
777 break;
780 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
782 /* Now find a hardware event */
784 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
785 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
787 /* Got one */
788 msgQueue->GetMessageTimeVal = msg->time;
789 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
790 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
791 break;
794 /* Check again for SendMessage */
796 while (msgQueue->wakeBits & QS_SENDMESSAGE)
797 QUEUE_ReceiveMessage( msgQueue );
799 /* Now find a WM_PAINT message */
801 if ((msgQueue->wakeBits & mask) & QS_PAINT)
803 WND* wndPtr;
804 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
805 msg->message = WM_PAINT;
806 msg->wParam = 0;
807 msg->lParam = 0;
809 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
811 if( wndPtr->dwStyle & WS_MINIMIZE &&
812 wndPtr->class->hIcon )
814 msg->message = WM_PAINTICON;
815 msg->wParam = 1;
818 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
820 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
822 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
823 QUEUE_DecPaintCount( hQueue );
825 break;
830 /* Check for timer messages, but yield first */
832 if (!(flags & PM_NOYIELD))
834 UserYield();
835 while (msgQueue->wakeBits & QS_SENDMESSAGE)
836 QUEUE_ReceiveMessage( msgQueue );
838 if ((msgQueue->wakeBits & mask) & QS_TIMER)
840 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
843 if (peek)
845 if (!(flags & PM_NOYIELD)) UserYield();
846 return FALSE;
848 msgQueue->wakeMask = mask;
849 QUEUE_WaitBits( mask );
852 /* We got a message */
853 if (flags & PM_REMOVE)
855 WORD message = msg->message;
857 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
859 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
861 if (!(*p & 0x80))
862 *p ^= 0x01;
863 *p |= 0x80;
865 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
866 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
868 if (peek) return TRUE;
869 else return (msg->message != WM_QUIT);
873 /***********************************************************************
874 * MSG_InternalGetMessage
876 * GetMessage() function for internal use. Behave like GetMessage(),
877 * but also call message filters and optionally send WM_ENTERIDLE messages.
878 * 'hwnd' must be the handle of the dialog or menu window.
879 * 'code' is the message filter value (MSGF_??? codes).
881 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
882 WPARAM32 code, WORD flags, BOOL32 sendIdle )
884 for (;;)
886 if (sendIdle)
888 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
890 /* No message present -> send ENTERIDLE and wait */
891 if (IsWindow32(hwndOwner))
892 SendMessage16( hwndOwner, WM_ENTERIDLE,
893 code, (LPARAM)hwnd );
894 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
897 else /* Always wait for a message */
898 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
900 /* Call message filters */
902 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
904 MSG16 *pmsg = SEGPTR_NEW(MSG16);
905 if (pmsg)
907 BOOL32 ret;
908 *pmsg = *msg;
909 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
910 (LPARAM)SEGPTR_GET(pmsg) ) ||
911 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
912 (LPARAM)SEGPTR_GET(pmsg) ));
913 SEGPTR_FREE(pmsg);
914 if (ret)
916 /* Message filtered -> remove it from the queue */
917 /* if it's still there. */
918 if (!(flags & PM_REMOVE))
919 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
920 continue;
925 return (msg->message != WM_QUIT);
930 /***********************************************************************
931 * PeekMessage16 (USER.109)
933 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
934 UINT16 last, UINT16 flags )
936 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
939 /***********************************************************************
940 * PeekMessageA
942 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
943 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
945 MSG16 msg;
946 BOOL32 ret;
947 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
948 /* FIXME: should translate the message to Win32 */
949 STRUCT32_MSG16to32(&msg,lpmsg);
950 return ret;
953 /***********************************************************************
954 * PeekMessageW Check queue for messages
956 * Checks for a message in the thread's queue, filtered as for
957 * GetMessage(). Returns immediately whether a message is available
958 * or not.
960 * Whether a retrieved message is removed from the queue is set by the
961 * _wRemoveMsg_ flags, which should be one of the following values:
963 * PM_NOREMOVE Do not remove the message from the queue.
965 * PM_REMOVE Remove the message from the queue.
967 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
968 * request that the system not yield control during PeekMessage();
969 * however applications may not rely on scheduling behavior.
971 * RETURNS
973 * Nonzero if a message is available and is retrieved, zero otherwise.
975 * CONFORMANCE
977 * ECMA-234, Win32
980 BOOL32 WINAPI PeekMessage32W(
981 LPMSG32 lpmsg, /* buffer to receive message */
982 HWND32 hwnd, /* restrict to messages for hwnd */
983 UINT32 min, /* minimum message to receive */
984 UINT32 max, /* maximum message to receive */
985 UINT32 wRemoveMsg /* removal flags */
987 /* FIXME: Should perform Unicode translation on specific messages */
988 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
991 /***********************************************************************
992 * GetMessage16 (USER.108)
994 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
996 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
997 MSG_PeekMessage( lpmsg,
998 hwnd, first, last, PM_REMOVE, FALSE );
1000 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1001 hwnd, first, last );
1002 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
1003 return (lpmsg->message != WM_QUIT);
1006 /***********************************************************************
1007 * GetMessage32A (USER32.270)
1009 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1011 BOOL32 ret;
1012 MSG16 *msg = SEGPTR_NEW(MSG16);
1013 if (!msg) return 0;
1014 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1015 /* FIXME */
1016 STRUCT32_MSG16to32(msg,lpmsg);
1017 SEGPTR_FREE(msg);
1018 return ret;
1021 /***********************************************************************
1022 * GetMessage32W (USER32.274) Retrieve next message
1024 * GetMessage retrieves the next event from the calling thread's
1025 * queue and deposits it in *lpmsg.
1027 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1028 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1029 * all application messages are retrieved.
1031 * _min_ and _max_ specify the range of messages of interest. If
1032 * min==max==0, no filtering is performed. Useful examples are
1033 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1034 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1036 * WM_PAINT messages are not removed from the queue; they remain until
1037 * processed. Other messages are removed from the queue.
1039 * RETURNS
1041 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1043 * CONFORMANCE
1045 * ECMA-234, Win32
1048 BOOL32 WINAPI GetMessage32W(
1049 MSG32* lpmsg, /* buffer to receive message */
1050 HWND32 hwnd, /* restrict to messages for hwnd */
1051 UINT32 min, /* minimum message to receive */
1052 UINT32 max /* maximum message to receive */
1054 BOOL32 ret;
1055 MSG16 *msg = SEGPTR_NEW(MSG16);
1056 if (!msg) return 0;
1057 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1058 /* FIXME */
1059 STRUCT32_MSG16to32(msg,lpmsg);
1060 SEGPTR_FREE(msg);
1061 return ret;
1065 /***********************************************************************
1066 * PostMessage16 (USER.110)
1068 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1069 LPARAM lParam )
1071 MSG16 msg;
1072 WND *wndPtr;
1074 msg.hwnd = hwnd;
1075 msg.message = message;
1076 msg.wParam = wParam;
1077 msg.lParam = lParam;
1078 msg.time = GetTickCount();
1079 msg.pt.x = 0;
1080 msg.pt.y = 0;
1082 #ifdef CONFIG_IPC
1083 if (DDE_PostMessage(&msg))
1084 return TRUE;
1085 #endif /* CONFIG_IPC */
1087 if (hwnd == HWND_BROADCAST)
1089 TRACE(msg,"HWND_BROADCAST !\n");
1090 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1092 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1094 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1095 wndPtr->hwndSelf, message, wParam, lParam);
1096 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1099 TRACE(msg,"End of HWND_BROADCAST !\n");
1100 return TRUE;
1103 wndPtr = WIN_FindWndPtr( hwnd );
1104 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1106 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1110 /***********************************************************************
1111 * PostMessage32A (USER32.419)
1113 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1114 LPARAM lParam )
1116 /* FIXME */
1117 if (message&0xffff0000)
1118 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1119 if (wParam&0xffff0000)
1120 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1121 return PostMessage16( hwnd, message, wParam, lParam );
1125 /***********************************************************************
1126 * PostMessage32W (USER32.420)
1128 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1129 LPARAM lParam )
1131 /* FIXME */
1132 if (message&0xffff0000)
1133 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1134 if (wParam&0xffff0000)
1135 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1136 return PostMessage16( hwnd, message, wParam, lParam );
1140 /***********************************************************************
1141 * PostAppMessage16 (USER.116)
1143 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1144 LPARAM lParam )
1146 MSG16 msg;
1148 if (GetTaskQueue(hTask) == 0) return FALSE;
1149 msg.hwnd = 0;
1150 msg.message = message;
1151 msg.wParam = wParam;
1152 msg.lParam = lParam;
1153 msg.time = GetTickCount();
1154 msg.pt.x = 0;
1155 msg.pt.y = 0;
1157 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1161 /***********************************************************************
1162 * SendMessage16 (USER.111)
1164 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1165 LPARAM lParam)
1167 WND * wndPtr;
1168 WND **list, **ppWnd;
1169 LRESULT ret;
1171 #ifdef CONFIG_IPC
1172 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1173 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1174 #endif /* CONFIG_IPC */
1176 if (hwnd == HWND_BROADCAST)
1178 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1179 return TRUE;
1180 TRACE(msg,"HWND_BROADCAST !\n");
1181 for (ppWnd = list; *ppWnd; ppWnd++)
1183 wndPtr = *ppWnd;
1184 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1185 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1187 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1188 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1189 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1192 HeapFree( SystemHeap, 0, list );
1193 TRACE(msg,"End of HWND_BROADCAST !\n");
1194 return TRUE;
1197 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1199 LPCWPSTRUCT16 pmsg;
1201 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1203 pmsg->hwnd = hwnd;
1204 pmsg->message= msg;
1205 pmsg->wParam = wParam;
1206 pmsg->lParam = lParam;
1207 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1208 (LPARAM)SEGPTR_GET(pmsg) );
1209 hwnd = pmsg->hwnd;
1210 msg = pmsg->message;
1211 wParam = pmsg->wParam;
1212 lParam = pmsg->lParam;
1213 SEGPTR_FREE( pmsg );
1217 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1219 WARN(msg, "invalid hwnd %04x\n", hwnd );
1220 return 0;
1222 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1223 return 0; /* Don't send anything if the task is dying */
1225 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1227 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1228 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1229 wParam, lParam, 0 );
1230 else
1231 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1232 hwnd, msg, wParam, lParam );
1234 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1235 return ret;
1238 /************************************************************************
1239 * MSG_CallWndProcHook32
1241 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1243 CWPSTRUCT32 cwp;
1245 cwp.lParam = pmsg->lParam;
1246 cwp.wParam = pmsg->wParam;
1247 cwp.message = pmsg->message;
1248 cwp.hwnd = pmsg->hwnd;
1250 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1251 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1253 pmsg->lParam = cwp.lParam;
1254 pmsg->wParam = cwp.wParam;
1255 pmsg->message = cwp.message;
1256 pmsg->hwnd = cwp.hwnd;
1259 /**********************************************************************
1260 * PostThreadMessage32A (USER32.422)
1262 * BUGS
1264 * Thread-local message queues are not supported.
1267 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1268 WPARAM32 wParam, LPARAM lParam )
1270 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1271 if (!thdb || !thdb->process) return FALSE;
1273 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1274 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1277 /**********************************************************************
1278 * PostThreadMessage32W (USER32.423)
1280 * BUGS
1282 * Thread-local message queues are not supported.
1285 BOOL32 WINAPI PostThreadMessage32W(DWORD idThread , UINT32 message,
1286 WPARAM32 wParam, LPARAM lParam )
1288 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1289 if (!thdb || !thdb->process) return FALSE;
1291 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1292 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1295 /***********************************************************************
1296 * SendMessage32A (USER32.454)
1298 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1299 LPARAM lParam )
1301 WND * wndPtr;
1302 WND **list, **ppWnd;
1303 LRESULT ret;
1305 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1307 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1308 return TRUE;
1309 for (ppWnd = list; *ppWnd; ppWnd++)
1311 wndPtr = *ppWnd;
1312 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1313 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1314 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1316 HeapFree( SystemHeap, 0, list );
1317 return TRUE;
1320 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1321 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1323 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1325 WARN(msg, "invalid hwnd %08x\n", hwnd );
1326 return 0;
1329 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1330 return 0; /* Don't send anything if the task is dying */
1332 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1334 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1335 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1336 QUEUE_SM_WIN32 );
1337 else
1338 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1339 hwnd, msg, wParam, lParam );
1341 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1342 return ret;
1346 /***********************************************************************
1347 * SendMessage32W (USER32.459) Send Window Message
1349 * Sends a message to the window procedure of the specified window.
1350 * SendMessage() will not return until the called window procedure
1351 * either returns or calls ReplyMessage().
1353 * Use PostMessage() to send message and return immediately. A window
1354 * procedure may use InSendMessage() to detect
1355 * SendMessage()-originated messages.
1357 * Applications which communicate via HWND_BROADCAST may use
1358 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1359 * with other applications.
1361 * CONFORMANCE
1363 * ECMA-234, Win32
1365 LRESULT WINAPI SendMessage32W(
1366 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1367 the message will be sent to all top-level windows. */
1369 UINT32 msg, /* message */
1370 WPARAM32 wParam, /* message parameter */
1371 LPARAM lParam /* additional message parameter */
1373 WND * wndPtr;
1374 WND **list, **ppWnd;
1375 LRESULT ret;
1377 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1379 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1380 return TRUE;
1381 for (ppWnd = list; *ppWnd; ppWnd++)
1383 wndPtr = *ppWnd;
1384 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1385 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1386 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1388 HeapFree( SystemHeap, 0, list );
1389 return TRUE;
1392 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1393 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1395 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1397 WARN(msg, "invalid hwnd %08x\n", hwnd );
1398 return 0;
1400 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1401 return 0; /* Don't send anything if the task is dying */
1403 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1405 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1406 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1407 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1408 else
1409 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1410 hwnd, msg, wParam, lParam );
1412 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1413 return ret;
1417 /***********************************************************************
1418 * SendMessageTimeout16 (not a WINAPI)
1420 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1421 LPARAM lParam, UINT16 flags,
1422 UINT16 timeout, LPWORD resultp)
1424 FIXME(sendmsg, "(...): semistub\n");
1425 return SendMessage16 (hwnd, msg, wParam, lParam);
1429 /***********************************************************************
1430 * SendMessageTimeout32A (USER32.457)
1432 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1433 LPARAM lParam, UINT32 flags,
1434 UINT32 timeout, LPDWORD resultp)
1436 FIXME(sendmsg, "(...): semistub\n");
1437 return SendMessage32A (hwnd, msg, wParam, lParam);
1441 /***********************************************************************
1442 * SendMessageTimeout32W (USER32.458)
1444 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1445 LPARAM lParam, UINT32 flags,
1446 UINT32 timeout, LPDWORD resultp)
1448 FIXME(sendmsg, "(...): semistub\n");
1449 return SendMessage32W (hwnd, msg, wParam, lParam);
1453 /***********************************************************************
1454 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1456 * WaitMessage() suspends a thread until events appear in the thread's
1457 * queue.
1459 * BUGS
1461 * Is supposed to return BOOL under Win32.
1463 * Thread-local message queues are not supported.
1465 * CONFORMANCE
1467 * ECMA-234, Win32
1470 void WINAPI WaitMessage( void )
1472 QUEUE_WaitBits( QS_ALLINPUT );
1475 /***********************************************************************
1476 * MsgWaitForMultipleObjects (USER32.400)
1478 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1479 BOOL32 fWaitAll, DWORD dwMilliseconds,
1480 DWORD dwWakeMask )
1482 DWORD retv;
1484 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1485 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1486 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1487 if (!msgQueue) return 0xFFFFFFFF;
1489 msgQueue->changeBits = 0;
1490 msgQueue->wakeMask = dwWakeMask;
1492 retv = SYNC_DoWait( nCount, pHandles, fWaitAll, dwMilliseconds, FALSE, TRUE );
1494 return retv;
1499 struct accent_char
1501 BYTE ac_accent;
1502 BYTE ac_char;
1503 BYTE ac_result;
1506 static const struct accent_char accent_chars[] =
1508 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1509 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1510 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1511 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1512 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1513 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1514 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1515 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1516 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1517 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1518 {',', 'C', '\307'}, {',', 'c', '\347'},
1519 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1520 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1521 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1522 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1523 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1524 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1525 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1526 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1527 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1528 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1529 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1530 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1531 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1532 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1533 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1534 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1535 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1536 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1537 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1538 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1539 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1540 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1541 {'s', 's', '\337'}, {'"', 'y', '\377'},
1542 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1543 /* iso-8859-2 uses this */
1544 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1545 {'<', 'S', '\251'}, {'<', 's', '\271'},
1546 {'<', 'T', '\253'}, {'<', 't', '\273'},
1547 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1548 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1549 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1550 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1551 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1552 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1553 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1554 {';', 'E', '\312'}, {';', 'e', '\332'},
1555 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1556 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1557 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1558 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1559 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1560 /* collision whith S, from iso-8859-9 !!! */
1561 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1562 {',', 'T', '\336'}, {',', 't', '\376'},
1563 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1564 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1565 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1566 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1567 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1568 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1569 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1570 /* iso-8859-3 uses this */
1571 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1572 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1573 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1574 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1575 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1576 {'>', 'S', '\336'}, {'>', 's', '\376'},
1577 /* collision whith G( from iso-8859-9 !!! */
1578 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1579 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1580 /* collision whith I. from iso-8859-3 !!! */
1581 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1582 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1583 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1584 /* iso-8859-4 uses this */
1585 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1586 {',', 'L', '\246'}, {',', 'l', '\266'},
1587 {',', 'G', '\253'}, {',', 'g', '\273'},
1588 {',', 'N', '\321'}, {',', 'n', '\361'},
1589 {',', 'K', '\323'}, {',', 'k', '\363'},
1590 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1591 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1592 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1593 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1594 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1595 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1596 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1597 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1598 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1599 {';', 'U', '\331'}, {';', 'u', '\371'},
1600 /* iso-8859-9 uses this */
1601 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1602 * whith the same letters on other iso-8859-x (that is they are on
1603 * different places :-( ), if you use turkish uncomment these and
1604 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1605 * FIXME: should be dynamic according to chosen language
1606 * if/when Wine has turkish support.
1608 /* collision whith G( from iso-8859-3 !!! */
1609 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1610 /* collision whith S, from iso-8859-2 !!! */
1611 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1612 /* collision whith I. from iso-8859-3 !!! */
1613 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1617 /***********************************************************************
1618 * MSG_DoTranslateMessage
1620 * Implementation of TranslateMessage.
1622 * TranslateMessage translates virtual-key messages into character-messages,
1623 * as follows :
1624 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1625 * ditto replacing WM_* with WM_SYS*
1626 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1627 * by the keyboard driver.
1629 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1630 WPARAM32 wParam, LPARAM lParam )
1632 static int dead_char;
1633 BYTE wp[2];
1635 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1636 TRACE(msg, "(%s, %04X, %08lX)\n",
1637 SPY_GetMsgName(message), wParam, lParam );
1638 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1639 TRACE(key, "(%s, %04X, %08lX)\n",
1640 SPY_GetMsgName(message), wParam, lParam );
1642 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1644 TRACE(key, "Translating key %04X, scancode %04X\n",
1645 wParam, HIWORD(lParam) );
1647 /* FIXME : should handle ToAscii yielding 2 */
1648 switch (ToAscii32(wParam, HIWORD(lParam),
1649 QueueKeyStateTable,(LPWORD)wp, 0))
1651 case 1 :
1652 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1653 /* Should dead chars handling go in ToAscii ? */
1654 if (dead_char)
1656 int i;
1658 if (wp[0] == ' ') wp[0] = dead_char;
1659 if (dead_char == 0xa2) dead_char = '(';
1660 else if (dead_char == 0xa8) dead_char = '"';
1661 else if (dead_char == 0xb2) dead_char = ';';
1662 else if (dead_char == 0xb4) dead_char = '\'';
1663 else if (dead_char == 0xb7) dead_char = '<';
1664 else if (dead_char == 0xb8) dead_char = ',';
1665 else if (dead_char == 0xff) dead_char = '.';
1666 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1667 if ((accent_chars[i].ac_accent == dead_char) &&
1668 (accent_chars[i].ac_char == wp[0]))
1670 wp[0] = accent_chars[i].ac_result;
1671 break;
1673 dead_char = 0;
1675 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1676 PostMessage16( hwnd, message, wp[0], lParam );
1677 return TRUE;
1679 case -1 :
1680 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1681 dead_char = wp[0];
1682 TRACE(key, "-1 -> PostMessage(%s)\n",
1683 SPY_GetMsgName(message));
1684 PostMessage16( hwnd, message, wp[0], lParam );
1685 return TRUE;
1687 return FALSE;
1691 /***********************************************************************
1692 * TranslateMessage16 (USER.113)
1694 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1696 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1697 msg->wParam, msg->lParam );
1701 /***********************************************************************
1702 * TranslateMessage32 (USER32.556)
1704 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1706 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1707 msg->wParam, msg->lParam );
1711 /***********************************************************************
1712 * DispatchMessage16 (USER.114)
1714 LONG WINAPI DispatchMessage16( const MSG16* msg )
1716 WND * wndPtr;
1717 LONG retval;
1718 int painting;
1720 /* Process timer messages */
1721 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1723 if (msg->lParam)
1725 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1726 msg->message, msg->wParam, GetTickCount() );
1730 if (!msg->hwnd) return 0;
1731 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1732 if (!wndPtr->winproc) return 0;
1733 painting = (msg->message == WM_PAINT);
1734 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1736 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1737 msg->wParam, msg->lParam );
1738 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1739 msg->hwnd, msg->message,
1740 msg->wParam, msg->lParam );
1741 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1743 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1744 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1746 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1747 msg->hwnd);
1748 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1749 /* Validate the update region to avoid infinite WM_PAINT loop */
1750 ValidateRect32( msg->hwnd, NULL );
1752 return retval;
1756 /***********************************************************************
1757 * DispatchMessage32A (USER32.141)
1759 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1761 WND * wndPtr;
1762 LONG retval;
1763 int painting;
1765 /* Process timer messages */
1766 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1768 if (msg->lParam)
1770 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1771 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1772 msg->message, msg->wParam, GetTickCount() );
1776 if (!msg->hwnd) return 0;
1777 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1778 if (!wndPtr->winproc) return 0;
1779 painting = (msg->message == WM_PAINT);
1780 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1781 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1783 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1784 msg->wParam, msg->lParam );
1785 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1786 msg->hwnd, msg->message,
1787 msg->wParam, msg->lParam );
1788 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1790 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1791 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1793 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1794 msg->hwnd);
1795 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1796 /* Validate the update region to avoid infinite WM_PAINT loop */
1797 ValidateRect32( msg->hwnd, NULL );
1799 return retval;
1803 /***********************************************************************
1804 * DispatchMessage32W (USER32.142) Process Message
1806 * Process the message specified in the structure *_msg_.
1808 * If the lpMsg parameter points to a WM_TIMER message and the
1809 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1810 * points to the function that is called instead of the window
1811 * procedure.
1813 * The message must be valid.
1815 * RETURNS
1817 * DispatchMessage() returns the result of the window procedure invoked.
1819 * CONFORMANCE
1821 * ECMA-234, Win32
1824 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1826 WND * wndPtr;
1827 LONG retval;
1828 int painting;
1830 /* Process timer messages */
1831 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1833 if (msg->lParam)
1835 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1836 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1837 msg->message, msg->wParam, GetTickCount() );
1841 if (!msg->hwnd) return 0;
1842 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1843 if (!wndPtr->winproc) return 0;
1844 painting = (msg->message == WM_PAINT);
1845 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1846 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1848 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1849 msg->wParam, msg->lParam );
1850 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1851 msg->hwnd, msg->message,
1852 msg->wParam, msg->lParam );
1853 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1855 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1856 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1858 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1859 msg->hwnd);
1860 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1861 /* Validate the update region to avoid infinite WM_PAINT loop */
1862 ValidateRect32( msg->hwnd, NULL );
1864 return retval;
1868 /***********************************************************************
1869 * RegisterWindowMessage16 (USER.118)
1871 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1873 TRACE(msg, "%08lx\n", (DWORD)str );
1874 return GlobalAddAtom16( str );
1878 /***********************************************************************
1879 * RegisterWindowMessage32A (USER32.437)
1881 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1883 TRACE(msg, "%s\n", str );
1884 return GlobalAddAtom32A( str );
1888 /***********************************************************************
1889 * RegisterWindowMessage32W (USER32.438)
1891 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1893 TRACE(msg, "%p\n", str );
1894 return GlobalAddAtom32W( str );
1898 /***********************************************************************
1899 * GetTickCount (USER.13) (KERNEL32.299) System Time
1900 * Returns the number of milliseconds, modulo 2^32, since the start
1901 * of the current session.
1903 * CONFORMANCE
1905 * ECMA-234, Win32
1907 DWORD WINAPI GetTickCount(void)
1909 struct timeval t;
1910 gettimeofday( &t, NULL );
1911 /* make extremely compatible: granularity is 25 msec */
1912 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
1916 /***********************************************************************
1917 * GetCurrentTime16 (USER.15)
1919 * (effectively identical to GetTickCount)
1921 DWORD WINAPI GetCurrentTime16(void)
1923 return GetTickCount();
1927 /***********************************************************************
1928 * InSendMessage16 (USER.192)
1930 BOOL16 WINAPI InSendMessage16(void)
1932 return InSendMessage32();
1936 /***********************************************************************
1937 * InSendMessage32 (USER32.320)
1939 BOOL32 WINAPI InSendMessage32(void)
1941 MESSAGEQUEUE *queue;
1943 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
1944 return 0;
1945 return (BOOL32)queue->InSendMessageHandle;
1948 /***********************************************************************
1949 * BroadcastSystemMessage (USER32.12)
1951 LONG WINAPI BroadcastSystemMessage(
1952 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1953 LPARAM lParam
1955 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1956 dwFlags,*recipients,uMessage,wParam,lParam
1958 return 0;
1961 /***********************************************************************
1962 * SendNotifyMessageA (USER32.460)
1963 * FIXME
1964 * The message sended with PostMessage has to be put in the queue
1965 * with a higher priority as the other "Posted" messages.
1966 * QUEUE_AddMsg has to be modifyed.
1968 LONG WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1969 { BOOL32 ret = TRUE;
1970 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1971 hwnd, msg, wParam, lParam);
1973 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1974 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1976 else
1977 { PostMessage32A ( hwnd, msg, wParam, lParam );
1979 return ret;
1981 /***********************************************************************
1982 * SendMessageCallBack32A
1983 * FIXME: It's like PostMessage. The callback gets called when the message
1984 * is processed. We have to modify the message processing for a exact
1985 * implementation...
1987 BOOL32 WINAPI SendMessageCallBack32A(
1988 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
1989 FARPROC32 lpResultCallBack,DWORD dwData)
1991 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
1992 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
1993 if ( hWnd == HWND_BROADCAST)
1994 { PostMessage32A( hWnd, Msg, wParam, lParam);
1995 FIXME(msg,"Broadcast: Callback will not be called!\n");
1996 return TRUE;
1998 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
1999 return TRUE;