Removed process argument to PROCESS_CallUserSignalProc.
[wine/multimedia.git] / windows / message.c
blob9059185756ace84fef203105922a967e05e49115
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 "heap.h"
18 #include "hook.h"
19 #include "input.h"
20 #include "spy.h"
21 #include "winpos.h"
22 #include "dde.h"
23 #include "queue.h"
24 #include "winproc.h"
25 #include "task.h"
26 #include "process.h"
27 #include "thread.h"
28 #include "options.h"
29 #include "struct32.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(key)
33 DECLARE_DEBUG_CHANNEL(msg)
34 DECLARE_DEBUG_CHANNEL(sendmsg)
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
40 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
41 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
43 extern HQUEUE16 hCursorQueue; /* queue.c */
45 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
47 static UINT doubleClickSpeed = 452;
49 /***********************************************************************
50 * MSG_CheckFilter
52 BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
54 if( first || last )
55 return (uMsg >= first && uMsg <= last);
56 return TRUE;
59 /***********************************************************************
60 * MSG_SendParentNotify
62 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
63 * the window has the WS_EX_NOPARENTNOTIFY style.
65 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
67 #define lppt ((LPPOINT16)&lValue)
69 /* pt has to be in the client coordinates of the parent window */
70 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
72 MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
73 while (tmpWnd)
75 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
77 WIN_ReleaseWndPtr(tmpWnd);
78 break;
80 lppt->x += tmpWnd->rectClient.left;
81 lppt->y += tmpWnd->rectClient.top;
82 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
83 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
84 MAKEWPARAM( event, idChild ), lValue );
87 #undef lppt
91 /***********************************************************************
92 * MSG_TranslateMouseMsg
94 * Translate an mouse hardware event into a real mouse message.
96 * Returns:
98 * SYSQ_MSG_ABANDON - abandon the peek message loop
99 * SYSQ_MSG_CONTINUE - leave the message in the queue and
100 * continue with the translation loop
101 * SYSQ_MSG_ACCEPT - proceed to process the translated message
103 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
104 MSG *msg, BOOL remove, WND* pWndScope,
105 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
107 static DWORD dblclk_time_limit = 0;
108 static UINT16 clk_message = 0;
109 static HWND16 clk_hwnd = 0;
110 static POINT16 clk_pos = { 0, 0 };
112 WND *pWnd;
113 HWND hWnd;
114 INT16 ht, hittest;
115 UINT message = msg->message;
116 POINT16 screen_pt, pt;
117 HANDLE16 hQ = GetFastQueue16();
118 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
119 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
120 (message == WM_RBUTTONDOWN) ||
121 (message == WM_MBUTTONDOWN))?1:0;
122 DWORD retvalue;
124 /* Find the window to dispatch this mouse message to */
126 CONV_POINT32TO16( &msg->pt, &pt );
128 hWnd = GetCapture();
130 /* If no capture HWND, find window which contains the mouse position.
131 * Also find the position of the cursor hot spot (hittest) */
132 if( !hWnd )
134 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
135 if( !pWnd ) pWnd = WIN_GetDesktop();
136 else WIN_LockWndPtr(pWnd);
137 hWnd = pWnd->hwndSelf;
139 else
141 ht = hittest = HTCLIENT;
142 pWnd = WIN_FindWndPtr(hWnd);
143 if (queue)
144 ht = PERQDATA_GetCaptureInfo( queue->pQData );
147 /* Save hittest for return */
148 *pHitTest = hittest;
150 /* stop if not the right queue */
152 if (pWnd->hmemTaskQ != hQ)
154 /* Not for the current task */
155 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
156 /* Wake up the other task */
157 QUEUE_Unlock( queue );
158 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
159 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
161 QUEUE_Unlock( queue );
162 retvalue = SYSQ_MSG_ABANDON;
163 goto END;
166 /* check if hWnd is within hWndScope */
168 if( hTopWnd && hWnd != hTopWnd )
169 if( !IsChild(hTopWnd, hWnd) )
171 QUEUE_Unlock( queue );
172 retvalue = SYSQ_MSG_CONTINUE;
173 goto END;
176 /* Was it a mouse click message */
177 if( mouseClick )
179 /* translate double clicks -
180 * note that ...MOUSEMOVEs can slip in between
181 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
183 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
185 if ((message == clk_message) && (hWnd == clk_hwnd) &&
186 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
187 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
188 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
190 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
191 mouseClick++; /* == 2 */
195 /* save mouse position */
196 screen_pt = pt;
197 *pScreen_pt = pt;
199 if (hittest != HTCLIENT)
201 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
202 msg->wParam = hittest;
204 else
205 ScreenToClient16( hWnd, &pt );
207 /* check message filter */
209 if (!MSG_CheckFilter(message, first, last))
211 QUEUE_Unlock(queue);
212 retvalue = SYSQ_MSG_CONTINUE;
213 goto END;
216 /* Update global hCursorQueue */
217 hCursorQueue = queue->self;
219 /* Update static double click conditions */
220 if( remove && mouseClick )
222 if( mouseClick == 1 )
224 /* set conditions */
225 dblclk_time_limit = msg->time;
226 clk_message = msg->message;
227 clk_hwnd = hWnd;
228 clk_pos = screen_pt;
229 } else
230 /* got double click - zero them out */
231 dblclk_time_limit = clk_hwnd = 0;
234 QUEUE_Unlock(queue);
236 /* Update message params */
237 msg->hwnd = hWnd;
238 msg->message = message;
239 msg->lParam = MAKELONG( pt.x, pt.y );
240 retvalue = SYSQ_MSG_ACCEPT;
242 END:
243 WIN_ReleaseWndPtr(pWnd);
245 /* Return mouseclick flag */
246 *pmouseClick = mouseClick;
248 return retvalue;
252 /***********************************************************************
253 * MSG_ProcessMouseMsg
255 * Processes a translated mouse hardware event.
256 * The passed in msg structure should contain the updated hWnd,
257 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
259 * Returns:
261 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
262 * HIWORD contains hit test code). Continue translating..
263 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
264 * MSG_PeekHardwareMsg should return TRUE.
266 static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
267 POINT16 screen_pt, BOOL mouseClick )
269 WND *pWnd;
270 HWND hWnd = msg->hwnd;
271 INT16 sendSC = (GetCapture() == 0);
272 UINT message = msg->message;
273 BOOL eatMsg = FALSE;
274 DWORD retvalue;
276 pWnd = WIN_FindWndPtr(hWnd);
278 /* call WH_MOUSE */
280 if (HOOK_IsHooked( WH_MOUSE ))
282 SYSQ_STATUS ret = 0;
283 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
284 if( hook )
286 hook->pt = screen_pt;
287 hook->hwnd = hWnd;
288 hook->wHitTestCode = hittest;
289 hook->dwExtraInfo = 0;
290 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
291 message, (LPARAM)SEGPTR_GET(hook) );
292 SEGPTR_FREE(hook);
294 if( ret )
296 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
297 goto END;
302 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
303 eatMsg = sendSC = 1;
304 else if( remove && mouseClick )
306 HWND hwndTop = WIN_GetTopParent( hWnd );
308 if( sendSC )
310 /* Send the WM_PARENTNOTIFY,
311 * note that even for double/nonclient clicks
312 * notification message is still WM_L/M/RBUTTONDOWN.
315 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
317 /* Activate the window if needed */
319 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
321 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
322 MAKELONG( hittest, message ) );
324 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
325 eatMsg = TRUE;
327 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
328 && hwndTop != GetActiveWindow() )
329 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
330 eatMsg = TRUE;
333 } else sendSC = (remove && sendSC);
335 /* Send the WM_SETCURSOR message */
337 if (sendSC)
338 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
339 MAKELONG( hittest, message ));
340 if (eatMsg)
342 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
343 goto END;
346 retvalue = SYSQ_MSG_ACCEPT;
347 END:
348 WIN_ReleaseWndPtr(pWnd);
350 return retvalue;
354 /***********************************************************************
355 * MSG_TranslateKbdMsg
357 * Translate an keyboard hardware event into a real message.
359 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
360 MSG *msg, BOOL remove )
362 WORD message = msg->message;
363 HWND hWnd = GetFocus();
364 WND *pWnd;
366 /* Should check Ctrl-Esc and PrintScreen here */
368 if (!hWnd)
370 /* Send the message to the active window instead, */
371 /* translating messages to their WM_SYS equivalent */
373 hWnd = GetActiveWindow();
375 if( message < WM_SYSKEYDOWN )
376 message += WM_SYSKEYDOWN - WM_KEYDOWN;
378 pWnd = WIN_FindWndPtr( hWnd );
379 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
381 /* Not for the current task */
382 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
383 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
384 QUEUE_Unlock( queue );
386 /* Wake up the other task */
387 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
388 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
389 QUEUE_Unlock( queue );
390 WIN_ReleaseWndPtr(pWnd);
391 return SYSQ_MSG_ABANDON;
393 WIN_ReleaseWndPtr(pWnd);
395 if (hTopWnd && hWnd != hTopWnd)
396 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
397 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
399 msg->hwnd = hWnd;
400 msg->message = message;
402 return SYSQ_MSG_ACCEPT;
406 /***********************************************************************
407 * MSG_ProcessKbdMsg
409 * Processes a translated keyboard message
411 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
413 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
414 LOWORD (msg->wParam), msg->lParam )
415 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
419 /***********************************************************************
420 * MSG_JournalRecordMsg
422 * Build an EVENTMSG structure and call JOURNALRECORD hook
424 static void MSG_JournalRecordMsg( MSG *msg )
426 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
427 if (!event) return;
428 event->message = msg->message;
429 event->time = msg->time;
430 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
432 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
433 event->paramH = msg->lParam & 0x7FFF;
434 if (HIWORD(msg->lParam) & 0x0100)
435 event->paramH |= 0x8000; /* special_key - bit */
436 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
438 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
440 event->paramL = LOWORD(msg->lParam); /* X pos */
441 event->paramH = HIWORD(msg->lParam); /* Y pos */
442 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
443 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
445 else if ((msg->message >= WM_NCMOUSEFIRST) &&
446 (msg->message <= WM_NCMOUSELAST))
448 event->paramL = LOWORD(msg->lParam); /* X pos */
449 event->paramH = HIWORD(msg->lParam); /* Y pos */
450 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
451 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
454 HeapFree(SystemHeap, 0, event);
457 /***********************************************************************
458 * MSG_JournalPlayBackMsg
460 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
462 static int MSG_JournalPlayBackMsg(void)
464 EVENTMSG *tmpMsg;
465 long wtime,lParam,wParam;
466 WORD keyDown,i,result=0;
468 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
470 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
471 if (!tmpMsg) return result;
473 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
474 (LPARAM) tmpMsg );
475 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
476 if (wtime<=0)
478 wtime=0;
479 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
481 wParam=tmpMsg->paramL & 0xFF;
482 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
483 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
485 for (keyDown=i=0; i<256 && !keyDown; i++)
486 if (InputKeyStateTable[i] & 0x80)
487 keyDown++;
488 if (!keyDown)
489 lParam |= 0x40000000;
490 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
492 else /* WM_KEYUP, WM_SYSKEYUP */
494 lParam |= 0xC0000000;
495 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
497 if (InputKeyStateTable[VK_MENU] & 0x80)
498 lParam |= 0x20000000;
499 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
500 lParam |= 0x01000000;
501 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
502 0, 0, tmpMsg->time, 0 );
504 else
506 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
508 switch (tmpMsg->message)
510 case WM_LBUTTONDOWN:
511 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
512 case WM_LBUTTONUP:
513 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
514 case WM_MBUTTONDOWN:
515 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
516 case WM_MBUTTONUP:
517 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
518 case WM_RBUTTONDOWN:
519 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
520 case WM_RBUTTONUP:
521 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
523 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
524 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
525 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
526 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
527 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
528 wParam=0;
529 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
530 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
531 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
532 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
533 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
536 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
537 (LPARAM) tmpMsg);
539 else
542 if( tmpMsg->message == WM_QUEUESYNC )
543 if (HOOK_IsHooked( WH_CBT ))
544 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
546 result= QS_MOUSE | QS_KEY; /* ? */
548 HeapFree(SystemHeap, 0, tmpMsg);
550 return result;
553 /***********************************************************************
554 * MSG_PeekHardwareMsg
556 * Peek for a hardware message matching the hwnd and message filters.
558 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
559 BOOL remove )
561 /* FIXME: should deal with MSG32 instead of MSG16 */
563 DWORD status = SYSQ_MSG_ACCEPT;
564 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
565 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
566 QMSG *nextqmsg, *qmsg = 0;
567 BOOL bRet = FALSE;
569 /* FIXME: there has to be a better way to do this */
570 joySendMessages();
572 EnterCriticalSection(&sysMsgQueue->cSection);
574 /* Loop through the Q and translate the message we wish to process
575 * while we own the lock. Based on the translation status (abandon/cont/accept)
576 * we then process the message accordingly
579 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
581 INT16 hittest;
582 POINT16 screen_pt;
583 BOOL mouseClick;
585 *msg = qmsg->msg;
587 nextqmsg = qmsg->nextMsg;
589 /* Translate message */
591 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
593 HWND hWndScope = (HWND)qmsg->extraInfo;
594 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
595 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
597 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
598 &hittest, &screen_pt, &mouseClick );
599 msgType = MOUSE_MSG;
601 WIN_ReleaseWndPtr(tmpWnd);
604 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
606 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
607 msgType = KEYBOARD_MSG;
609 else /* Non-standard hardware event */
611 HARDWAREHOOKSTRUCT16 *hook;
612 msgType = HARDWARE_MSG;
613 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
615 BOOL ret;
616 hook->hWnd = msg->hwnd;
617 hook->wMessage = msg->message & 0xffff;
618 hook->wParam = LOWORD (msg->wParam);
619 hook->lParam = msg->lParam;
620 ret = HOOK_CallHooks16( WH_HARDWARE,
621 remove ? HC_ACTION : HC_NOREMOVE,
622 0, (LPARAM)SEGPTR_GET(hook) );
623 SEGPTR_FREE(hook);
624 if (ret)
626 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
627 continue;
629 status = SYSQ_MSG_ACCEPT;
634 switch (LOWORD(status))
636 case SYSQ_MSG_ACCEPT:
638 /* Remove the message from the system msg Q while it is still locked,
639 * before accepting it */
640 if (remove)
642 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
643 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
645 /* Now actually process the message, after we unlock the system msg Q.
646 * We should not hold on to the crst since SendMessage calls during processing
647 * will potentially cause callbacks to PeekMessage from the application.
648 * If we're holding the crst and QUEUE_WaitBits is called with a
649 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
650 * message is being posted to the Q.
652 LeaveCriticalSection(&sysMsgQueue->cSection);
653 if( msgType == KEYBOARD_MSG )
654 status = MSG_ProcessKbdMsg( msg, remove );
655 else if ( msgType == MOUSE_MSG )
656 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
658 /* Reclaim the sys msg Q crst */
659 EnterCriticalSection(&sysMsgQueue->cSection);
661 /* Pass the translated message to the user if it was accepted */
662 if (status == SYSQ_MSG_ACCEPT)
663 break;
665 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
668 case SYSQ_MSG_SKIP:
669 if (HOOK_IsHooked( WH_CBT ))
671 if( msgType == KEYBOARD_MSG )
672 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
673 LOWORD (msg->wParam), msg->lParam );
674 else if ( msgType == MOUSE_MSG )
676 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
677 if (hook)
679 CONV_POINT32TO16( &msg->pt,&hook->pt );
680 hook->hwnd = msg->hwnd;
681 hook->wHitTestCode = HIWORD(status);
682 hook->dwExtraInfo = 0;
683 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
684 (LPARAM)SEGPTR_GET(hook) );
685 SEGPTR_FREE(hook);
690 /* If the message was removed earlier set up nextqmsg so that we start
691 * at the top of the queue again. We need to do this since our next pointer
692 * could be invalid due to us unlocking the system message Q to process the message.
693 * If not removed just refresh nextqmsg to point to the next msg.
695 if (remove)
696 nextqmsg = sysMsgQueue->firstMsg;
697 else
698 nextqmsg = qmsg->nextMsg;
700 continue;
702 case SYSQ_MSG_CONTINUE:
703 continue;
705 case SYSQ_MSG_ABANDON:
706 bRet = FALSE;
707 goto END;
710 bRet = TRUE;
711 goto END;
714 END:
715 LeaveCriticalSection(&sysMsgQueue->cSection);
716 return bRet;
720 /**********************************************************************
721 * SetDoubleClickTime16 (USER.20)
723 void WINAPI SetDoubleClickTime16( UINT16 interval )
725 SetDoubleClickTime( interval );
729 /**********************************************************************
730 * SetDoubleClickTime32 (USER32.480)
732 BOOL WINAPI SetDoubleClickTime( UINT interval )
734 doubleClickSpeed = interval ? interval : 500;
735 return TRUE;
739 /**********************************************************************
740 * GetDoubleClickTime16 (USER.21)
742 UINT16 WINAPI GetDoubleClickTime16(void)
744 return doubleClickSpeed;
748 /**********************************************************************
749 * GetDoubleClickTime32 (USER32.239)
751 UINT WINAPI GetDoubleClickTime(void)
753 return doubleClickSpeed;
757 /***********************************************************************
758 * MSG_SendMessageInterThread
760 * Implementation of an inter-task SendMessage.
761 * Return values:
762 * 0 if error or timeout
763 * 1 if successflul
765 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
766 HWND hwnd, UINT msg,
767 WPARAM wParam, LPARAM lParam,
768 DWORD timeout, WORD flags,
769 LRESULT *pRes)
771 MESSAGEQUEUE *queue, *destQ;
772 SMSG *smsg;
773 LRESULT retVal = 1;
774 int iWndsLocks;
776 *pRes = 0;
778 if (IsTaskLocked16() || !IsWindow(hwnd))
779 return 0;
781 /* create a SMSG structure to hold SendMessage() parameters */
782 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
783 return 0;
784 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
786 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
788 QUEUE_Unlock( queue );
789 return 0;
792 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
793 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
795 /* fill up SMSG structure */
796 smsg->hWnd = hwnd;
797 smsg->msg = msg;
798 smsg->wParam = wParam;
799 smsg->lParam = lParam;
801 smsg->lResult = 0;
802 smsg->hSrcQueue = GetFastQueue16();
803 smsg->hDstQueue = hDestQueue;
804 smsg->flags = flags;
806 /* add smsg struct in the processing SM list of the source queue */
807 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
809 /* add smsg struct in the pending list of the destination queue */
810 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
811 return 0;
813 iWndsLocks = WIN_SuspendWndsLock();
815 /* force destination task to run next, if 16 bit threads */
816 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ->thdb) )
817 DirectedYield16( destQ->thdb->teb.htask16 );
819 /* wait for the result, note that 16-bit apps almost always get out of
820 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
822 while ( TRUE )
825 * The sequence is crucial to avoid deadlock situations:
826 * - first, we clear the QS_SMRESULT bit
827 * - then, we check the SMSG_HAVE_RESULT bit
828 * - only if this isn't set, we enter the wait state.
830 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
831 * we are guaranteed that -should we now clear the QS_SMRESULT that
832 * was signalled already by the receiver- we will not start waiting.
835 if ( smsg->flags & SMSG_HAVE_RESULT )
837 got:
838 *pRes = smsg->lResult;
839 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
840 break;
843 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
845 if ( smsg->flags & SMSG_HAVE_RESULT )
846 goto got;
848 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
850 /* return with timeout */
851 SetLastError( 0 );
852 retVal = 0;
853 break;
856 WIN_RestoreWndsLock(iWndsLocks);
858 /* remove the smsg from the processingg list of the source queue */
859 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
861 /* Note: the destination thread is in charge of removing the smsg from
862 the pending list */
864 /* In the case of an early reply (or a timeout), sender thread will
865 released the smsg structure if the receiver thread is done
866 (SMSG_RECEIVED set). If the receiver thread isn't done,
867 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
868 responsability to released smsg */
869 EnterCriticalSection( &queue->cSection );
871 if (smsg->flags & SMSG_RECEIVED)
872 HeapFree(SystemHeap, 0, smsg);
873 else
874 smsg->flags |= SMSG_RECEIVER_CLEANS;
876 LeaveCriticalSection( &queue->cSection );
879 QUEUE_Unlock( queue );
880 QUEUE_Unlock( destQ );
882 TRACE_(sendmsg)("done!\n");
883 return retVal;
887 /***********************************************************************
888 * ReplyMessage16 (USER.115)
890 void WINAPI ReplyMessage16( LRESULT result )
892 ReplyMessage( result );
895 /***********************************************************************
896 * ReplyMessage (USER.115)
898 BOOL WINAPI ReplyMessage( LRESULT result )
900 MESSAGEQUEUE *senderQ = 0;
901 MESSAGEQUEUE *queue = 0;
902 SMSG *smsg;
903 BOOL ret = FALSE;
905 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
906 return FALSE;
908 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
911 if ( !(smsg = queue->smWaiting)
912 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
913 goto ReplyMessageEnd;
915 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
917 /* This is the first reply, so pass result to sender */
919 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
921 EnterCriticalSection(&senderQ->cSection);
923 smsg->lResult = result;
924 smsg->flags |= SMSG_ALREADY_REPLIED;
926 /* check if it's an early reply (called by the application) or
927 a regular reply (called by ReceiveMessage) */
928 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
929 smsg->flags |= SMSG_EARLY_REPLY;
931 smsg->flags |= SMSG_HAVE_RESULT;
933 LeaveCriticalSection(&senderQ->cSection);
935 /* tell the sending task that its reply is ready */
936 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
938 /* switch directly to sending task (16 bit thread only) */
939 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ->thdb ) )
940 DirectedYield16( senderQ->thdb->teb.htask16 );
942 ret = TRUE;
945 if (smsg->flags & SMSG_SENDING_REPLY)
947 /* remove msg from the waiting list, since this is the last
948 ReplyMessage */
949 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
951 EnterCriticalSection(&senderQ->cSection);
953 /* tell the sender we're all done with smsg structure */
954 smsg->flags |= SMSG_RECEIVED;
956 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
957 receiver to clean up smsg, it could only happens when there is
958 an early reply or a timeout */
959 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
961 TRACE_(sendmsg)("Receiver cleans up!\n" );
962 HeapFree( SystemHeap, 0, smsg );
965 LeaveCriticalSection(&senderQ->cSection);
968 ReplyMessageEnd:
969 if ( senderQ )
970 QUEUE_Unlock( senderQ );
971 if ( queue )
972 QUEUE_Unlock( queue );
974 return ret;
977 /***********************************************************************
978 * MSG_PeekMessage
980 static BOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, DWORD first, DWORD last,
981 WORD flags, BOOL peek )
983 int mask;
984 MESSAGEQUEUE *msgQueue;
985 HQUEUE16 hQueue;
986 POINT16 pt16;
987 int iWndsLocks;
989 #ifdef CONFIG_IPC
990 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
991 DDE_GetRemoteMessage();
992 #endif /* CONFIG_IPC */
994 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
995 if (first || last)
997 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
998 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
999 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1000 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1001 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1002 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1004 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1006 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1008 /* Never yield on Win32 threads */
1009 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
1011 iWndsLocks = WIN_SuspendWndsLock();
1013 while(1)
1015 QMSG *qmsg;
1017 hQueue = GetFastQueue16();
1018 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1019 if (!msgQueue)
1021 WIN_RestoreWndsLock(iWndsLocks);
1022 return FALSE;
1024 msgQueue->changeBits = 0;
1026 /* First handle a message put by SendMessage() */
1028 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1029 QUEUE_ReceiveMessage( msgQueue );
1031 /* Now handle a WM_QUIT message */
1033 if (msgQueue->wPostQMsg &&
1034 (!first || WM_QUIT >= first) &&
1035 (!last || WM_QUIT <= last) )
1037 msg->hwnd = hwnd;
1038 msg->message = WM_QUIT;
1039 msg->wParam = msgQueue->wExitCode;
1040 msg->lParam = 0;
1041 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1042 break;
1045 /* Now find a normal message */
1047 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
1048 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1050 *msg = qmsg->msg;
1052 msgQueue->GetMessageTimeVal = msg->time;
1053 CONV_POINT32TO16(&msg->pt, &pt16);
1054 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1055 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1057 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1058 break;
1061 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
1063 /* Now find a hardware event */
1065 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
1066 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
1068 /* Got one */
1069 msgQueue->GetMessageTimeVal = msg->time;
1070 CONV_POINT32TO16(&msg->pt, &pt16);
1071 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1072 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1073 break;
1076 /* Check again for SendMessage */
1078 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1079 QUEUE_ReceiveMessage( msgQueue );
1081 /* Now find a WM_PAINT message */
1083 if ((msgQueue->wakeBits & mask) & QS_PAINT)
1085 WND* wndPtr;
1086 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1087 msg->message = WM_PAINT;
1088 msg->wParam = 0;
1089 msg->lParam = 0;
1091 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
1093 if( wndPtr->dwStyle & WS_MINIMIZE &&
1094 wndPtr->class->hIcon )
1096 msg->message = WM_PAINTICON;
1097 msg->wParam = 1;
1100 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1102 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1104 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1105 QUEUE_DecPaintCount( hQueue );
1107 WIN_ReleaseWndPtr(wndPtr);
1108 break;
1110 WIN_ReleaseWndPtr(wndPtr);
1114 /* Check for timer messages, but yield first */
1116 if (!(flags & PM_NOYIELD))
1118 UserYield16();
1119 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1120 QUEUE_ReceiveMessage( msgQueue );
1122 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1124 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1127 if (peek)
1129 if (!(flags & PM_NOYIELD)) UserYield16();
1131 QUEUE_Unlock( msgQueue );
1132 WIN_RestoreWndsLock(iWndsLocks);
1133 return FALSE;
1135 msgQueue->wakeMask = mask;
1136 QUEUE_WaitBits( mask, INFINITE );
1137 QUEUE_Unlock( msgQueue );
1140 WIN_RestoreWndsLock(iWndsLocks);
1142 /* instead of unlocking queue for every break condition, all break
1143 condition will fall here */
1144 QUEUE_Unlock( msgQueue );
1146 /* We got a message */
1147 if (flags & PM_REMOVE)
1149 WORD message = msg->message;
1151 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1153 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1155 if (!(*p & 0x80))
1156 *p ^= 0x01;
1157 *p |= 0x80;
1159 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1160 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1163 if (peek)
1164 return TRUE;
1166 else
1167 return (msg->message != WM_QUIT);
1170 /***********************************************************************
1171 * MSG_InternalGetMessage
1173 * GetMessage() function for internal use. Behave like GetMessage(),
1174 * but also call message filters and optionally send WM_ENTERIDLE messages.
1175 * 'hwnd' must be the handle of the dialog or menu window.
1176 * 'code' is the message filter value (MSGF_??? codes).
1178 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner,
1179 WPARAM code, WORD flags, BOOL sendIdle )
1181 for (;;)
1183 if (sendIdle)
1185 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
1187 /* No message present -> send ENTERIDLE and wait */
1188 if (IsWindow(hwndOwner))
1189 SendMessageA( hwndOwner, WM_ENTERIDLE,
1190 code, (LPARAM)hwnd );
1191 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1194 else /* Always wait for a message */
1195 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1197 /* Call message filters */
1199 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1201 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1202 if (pmsg)
1204 BOOL ret;
1205 *pmsg = *msg;
1206 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1207 (LPARAM) pmsg ) ||
1208 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1209 (LPARAM) pmsg ));
1211 HeapFree( SystemHeap, 0, pmsg );
1212 if (ret)
1214 /* Message filtered -> remove it from the queue */
1215 /* if it's still there. */
1216 if (!(flags & PM_REMOVE))
1217 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
1218 continue;
1223 return (msg->message != WM_QUIT);
1228 /***********************************************************************
1229 * PeekMessage16 (USER.109)
1231 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd, UINT16 first,
1232 UINT16 last, UINT16 flags )
1234 MSG msg32;
1235 BOOL16 ret;
1236 ret = PeekMessageA(&msg32, hwnd, first, last, flags);
1237 STRUCT32_MSG32to16(&msg32, lpmsg);
1238 return ret;
1241 /***********************************************************************
1242 * WIN16_PeekMessage32 (USER.819)
1244 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1245 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
1247 if (wHaveParamHigh == FALSE)
1249 lpmsg16_32->wParamHigh = 0;
1250 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1252 else
1254 MSG msg32;
1255 BOOL16 ret;
1257 ret = (BOOL16)PeekMessageA(&msg32, (HWND)hwnd,
1258 (UINT)first, (UINT)last, (UINT)flags);
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;
1272 /***********************************************************************
1273 * PeekMessageA
1275 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1276 UINT min,UINT max,UINT wRemoveMsg)
1278 return MSG_PeekMessage( lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1281 /***********************************************************************
1282 * PeekMessageW Check queue for messages
1284 * Checks for a message in the thread's queue, filtered as for
1285 * GetMessage(). Returns immediately whether a message is available
1286 * or not.
1288 * Whether a retrieved message is removed from the queue is set by the
1289 * _wRemoveMsg_ flags, which should be one of the following values:
1291 * PM_NOREMOVE Do not remove the message from the queue.
1293 * PM_REMOVE Remove the message from the queue.
1295 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1296 * request that the system not yield control during PeekMessage();
1297 * however applications may not rely on scheduling behavior.
1299 * RETURNS
1301 * Nonzero if a message is available and is retrieved, zero otherwise.
1303 * CONFORMANCE
1305 * ECMA-234, Win32
1308 BOOL WINAPI PeekMessageW(
1309 LPMSG lpmsg, /* buffer to receive message */
1310 HWND hwnd, /* restrict to messages for hwnd */
1311 UINT min, /* minimum message to receive */
1312 UINT max, /* maximum message to receive */
1313 UINT wRemoveMsg /* removal flags */
1316 BOOL bRet = PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1317 if (bRet)
1318 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1319 return bRet;
1322 /***********************************************************************
1323 * GetMessage16 (USER.108)
1325 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1327 BOOL ret;
1328 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1329 MSG msg32;
1331 ret = GetMessageA( &msg32, hwnd, first, last );
1333 STRUCT32_MSG32to16( &msg32, lpmsg );
1335 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1336 hwnd, first, last );
1338 return ret;
1341 /***********************************************************************
1342 * WIN16_GetMessage32 (USER.820)
1344 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1345 UINT16 last, BOOL16 wHaveParamHigh )
1347 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1349 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1352 lpmsg16_32->wParamHigh = 0; /* you never know... */
1353 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1354 return GetMessage16(msg16_32, hWnd, first, last);
1356 else
1358 MSG msg32;
1359 BOOL16 ret;
1361 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1362 lpmsg16_32->msg.hwnd = msg32.hwnd;
1363 lpmsg16_32->msg.message = msg32.message;
1364 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1365 lpmsg16_32->msg.lParam = msg32.lParam;
1366 lpmsg16_32->msg.time = msg32.time;
1367 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1368 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1369 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1370 return ret;
1374 /***********************************************************************
1375 * GetMessage32A (USER32.270)
1377 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1379 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1381 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1382 hwnd, min, max );
1384 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1386 return (lpmsg->message != WM_QUIT);
1389 /***********************************************************************
1390 * GetMessage32W (USER32.274) Retrieve next message
1392 * GetMessage retrieves the next event from the calling thread's
1393 * queue and deposits it in *lpmsg.
1395 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1396 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1397 * all application messages are retrieved.
1399 * _min_ and _max_ specify the range of messages of interest. If
1400 * min==max==0, no filtering is performed. Useful examples are
1401 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1402 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1404 * WM_PAINT messages are not removed from the queue; they remain until
1405 * processed. Other messages are removed from the queue.
1407 * RETURNS
1409 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1411 * CONFORMANCE
1413 * ECMA-234, Win32
1416 BOOL WINAPI GetMessageW(
1417 MSG* lpmsg, /* buffer to receive message */
1418 HWND hwnd, /* restrict to messages for hwnd */
1419 UINT min, /* minimum message to receive */
1420 UINT max /* maximum message to receive */
1423 BOOL bRet = GetMessageA(lpmsg, hwnd, min, max);
1424 if (bRet)
1425 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1426 return bRet;
1431 /***********************************************************************
1432 * PostMessage16 (USER.110)
1434 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1435 LPARAM lParam )
1437 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1441 /***********************************************************************
1442 * PostMessage32A (USER32.419)
1444 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1445 LPARAM lParam )
1447 MSG msg;
1448 WND *wndPtr;
1449 BOOL retvalue;
1451 msg.hwnd = hwnd;
1452 msg.message = message;
1453 msg.wParam = wParam;
1454 msg.lParam = lParam;
1455 msg.time = GetTickCount();
1456 msg.pt.x = 0;
1457 msg.pt.y = 0;
1459 #ifdef CONFIG_IPC
1460 if (DDE_PostMessage(&msg))
1461 return TRUE;
1462 #endif /* CONFIG_IPC */
1464 if (hwnd == HWND_BROADCAST)
1466 WND *pDesktop = WIN_GetDesktop();
1467 TRACE_(msg)("HWND_BROADCAST !\n");
1469 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1471 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1473 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1474 wndPtr->hwndSelf, message, wParam, lParam);
1475 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1478 WIN_ReleaseDesktop();
1479 TRACE_(msg)("End of HWND_BROADCAST !\n");
1480 return TRUE;
1483 wndPtr = WIN_FindWndPtr( hwnd );
1484 if (!wndPtr || !wndPtr->hmemTaskQ)
1486 retvalue = FALSE;
1487 goto END;
1490 retvalue = QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1491 END:
1492 WIN_ReleaseWndPtr(wndPtr);
1493 return retvalue;
1497 /***********************************************************************
1498 * PostMessage32W (USER32.420)
1500 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1501 LPARAM lParam )
1503 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(message));
1504 return PostMessageA( hwnd, message, wParam, lParam );
1508 /***********************************************************************
1509 * PostAppMessage16 (USER.116)
1511 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1512 LPARAM lParam )
1514 MSG msg;
1516 if (GetTaskQueue16(hTask) == 0) return FALSE;
1517 msg.hwnd = 0;
1518 msg.message = message;
1519 msg.wParam = wParam;
1520 msg.lParam = lParam;
1521 msg.time = GetTickCount();
1522 msg.pt.x = 0;
1523 msg.pt.y = 0;
1525 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1528 /************************************************************************
1529 * MSG_CallWndProcHook32
1531 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1533 CWPSTRUCT cwp;
1535 cwp.lParam = pmsg->lParam;
1536 cwp.wParam = pmsg->wParam;
1537 cwp.message = pmsg->message;
1538 cwp.hwnd = pmsg->hwnd;
1540 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1541 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1543 pmsg->lParam = cwp.lParam;
1544 pmsg->wParam = cwp.wParam;
1545 pmsg->message = cwp.message;
1546 pmsg->hwnd = cwp.hwnd;
1550 /***********************************************************************
1551 * MSG_SendMessage
1553 * return values: 0 if timeout occurs
1554 * 1 otherwise
1556 LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1557 LPARAM lParam, DWORD timeout, WORD flags,
1558 LRESULT *pRes)
1560 WND * wndPtr = 0;
1561 WND **list, **ppWnd;
1562 LRESULT ret = 1;
1564 *pRes = 0;
1566 if (hwnd == HWND_BROADCAST)
1568 *pRes = 1;
1570 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1572 WIN_ReleaseDesktop();
1573 return 1;
1575 WIN_ReleaseDesktop();
1577 TRACE_(msg)("HWND_BROADCAST !\n");
1578 for (ppWnd = list; *ppWnd; ppWnd++)
1580 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1581 if (!IsWindow(wndPtr->hwndSelf)) continue;
1582 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1584 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1585 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1586 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1587 timeout, flags, pRes);
1590 WIN_ReleaseWndPtr(wndPtr);
1591 WIN_ReleaseWinArray(list);
1592 TRACE_(msg)("End of HWND_BROADCAST !\n");
1593 return 1;
1596 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1598 if (flags & SMSG_UNICODE)
1599 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1600 else if (flags & SMSG_WIN32)
1601 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1602 else
1604 LPCWPSTRUCT16 pmsg;
1606 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1608 pmsg->hwnd = hwnd & 0xffff;
1609 pmsg->message= msg & 0xffff;
1610 pmsg->wParam = wParam & 0xffff;
1611 pmsg->lParam = lParam;
1612 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1613 (LPARAM)SEGPTR_GET(pmsg) );
1614 hwnd = pmsg->hwnd;
1615 msg = pmsg->message;
1616 wParam = pmsg->wParam;
1617 lParam = pmsg->lParam;
1618 SEGPTR_FREE( pmsg );
1623 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1625 WARN_(msg)("invalid hwnd %04x\n", hwnd );
1626 return 0;
1628 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1630 ret = 0; /* Don't send anything if the task is dying */
1631 goto END;
1633 if (flags & SMSG_WIN32)
1634 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1635 else
1636 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1638 if (wndPtr->hmemTaskQ != GetFastQueue16())
1639 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1640 wParam, lParam, timeout, flags, pRes );
1641 else
1643 /* Call the right CallWindowProc flavor */
1644 if (flags & SMSG_UNICODE)
1645 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1646 hwnd, msg, wParam, lParam );
1647 else if (flags & SMSG_WIN32)
1648 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1649 hwnd, msg, wParam, lParam );
1650 else
1651 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1652 (HWND16) hwnd, (UINT16) msg,
1653 (WPARAM16) wParam, lParam );
1656 if (flags & SMSG_WIN32)
1657 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1658 else
1659 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1660 END:
1661 WIN_ReleaseWndPtr(wndPtr);
1662 return ret;
1666 /***********************************************************************
1667 * SendMessage16 (USER.111)
1669 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1670 LPARAM lParam)
1672 LRESULT res;
1673 #ifdef CONFIG_IPC
1674 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1675 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1676 #endif /* CONFIG_IPC */
1678 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1680 return res;
1685 /**********************************************************************
1686 * PostThreadMessage32A (USER32.422)
1688 * BUGS
1690 * Thread-local message queues are not supported.
1693 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1694 WPARAM wParam, LPARAM lParam )
1696 MSG msg;
1697 HQUEUE16 hQueue;
1699 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1700 return FALSE;
1702 msg.hwnd = 0;
1703 msg.message = message;
1704 msg.wParam = wParam;
1705 msg.lParam = lParam;
1706 msg.time = GetTickCount();
1707 msg.pt.x = 0;
1708 msg.pt.y = 0;
1710 return QUEUE_AddMsg( hQueue, &msg, 0 );
1713 /**********************************************************************
1714 * PostThreadMessage32W (USER32.423)
1716 * BUGS
1718 * Thread-local message queues are not supported.
1721 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1722 WPARAM wParam, LPARAM lParam )
1724 FIXME_(sendmsg)("(%s) unicode<->ascii\n",SPY_GetMsgName(message));
1725 return PostThreadMessageA(idThread, message, wParam, lParam);
1728 /***********************************************************************
1729 * SendMessage32A (USER32.454)
1731 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1732 LPARAM lParam )
1734 LRESULT res;
1736 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1737 SMSG_WIN32, &res);
1739 return res;
1743 /***********************************************************************
1744 * SendMessage32W (USER32.459) Send Window Message
1746 * Sends a message to the window procedure of the specified window.
1747 * SendMessage() will not return until the called window procedure
1748 * either returns or calls ReplyMessage().
1750 * Use PostMessage() to send message and return immediately. A window
1751 * procedure may use InSendMessage() to detect
1752 * SendMessage()-originated messages.
1754 * Applications which communicate via HWND_BROADCAST may use
1755 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1756 * with other applications.
1758 * CONFORMANCE
1760 * ECMA-234, Win32
1762 LRESULT WINAPI SendMessageW(
1763 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1764 the message will be sent to all top-level windows. */
1766 UINT msg, /* message */
1767 WPARAM wParam, /* message parameter */
1768 LPARAM lParam /* additional message parameter */
1770 LRESULT res;
1772 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1773 SMSG_WIN32 | SMSG_UNICODE, &res);
1775 return res;
1779 /***********************************************************************
1780 * SendMessageTimeout16 (not a WINAPI)
1782 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1783 LPARAM lParam, UINT16 flags,
1784 UINT16 timeout, LPWORD resultp)
1786 LRESULT ret;
1787 LRESULT msgRet;
1789 /* FIXME: need support for SMTO_BLOCK */
1791 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1792 *resultp = (WORD) msgRet;
1793 return ret;
1797 /***********************************************************************
1798 * SendMessageTimeoutA (USER32.457)
1800 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1801 LPARAM lParam, UINT flags,
1802 UINT timeout, LPDWORD resultp)
1804 LRESULT ret;
1805 LRESULT msgRet;
1807 /* FIXME: need support for SMTO_BLOCK */
1809 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1810 &msgRet);
1812 *resultp = (DWORD) msgRet;
1813 return ret;
1817 /***********************************************************************
1818 * SendMessageTimeoutW (USER32.458)
1820 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1821 LPARAM lParam, UINT flags,
1822 UINT timeout, LPDWORD resultp)
1824 LRESULT ret;
1825 LRESULT msgRet;
1827 /* FIXME: need support for SMTO_BLOCK */
1829 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1830 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1832 *resultp = (DWORD) msgRet;
1833 return ret;
1837 /***********************************************************************
1838 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1840 * WaitMessage() suspends a thread until events appear in the thread's
1841 * queue.
1843 * BUGS
1845 * Is supposed to return BOOL under Win32.
1847 * Thread-local message queues are not supported.
1849 * CONFORMANCE
1851 * ECMA-234, Win32
1854 void WINAPI WaitMessage( void )
1856 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1859 /***********************************************************************
1860 * MsgWaitForMultipleObjects (USER32.400)
1862 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1863 BOOL fWaitAll, DWORD dwMilliseconds,
1864 DWORD dwWakeMask )
1866 DWORD i;
1867 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1868 DWORD ret;
1870 HQUEUE16 hQueue = GetFastQueue16();
1871 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1872 if (!msgQueue) return WAIT_FAILED;
1874 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1876 SetLastError( ERROR_INVALID_PARAMETER );
1877 QUEUE_Unlock( msgQueue );
1878 return WAIT_FAILED;
1881 msgQueue->changeBits = 0;
1882 msgQueue->wakeMask = dwWakeMask;
1884 if (THREAD_IsWin16(THREAD_Current()))
1887 * This is a temporary solution to a big problem.
1888 * You see, the main thread of all Win32 programs is created as a 16 bit
1889 * task. This means that if you want on an event using Win32 synchronization
1890 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1891 * This implements a semi-busy loop that checks the handles to wait on and
1892 * also the message queue. When either one is ready, the wait function returns.
1894 * This will all go away when the real Win32 threads are implemented for all
1895 * the threads of an applications. Including the main thread.
1897 DWORD curTime = GetCurrentTime();
1902 * Check the handles in the list.
1904 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1907 * If the handles have been triggered, return.
1909 if (ret != WAIT_TIMEOUT)
1910 break;
1913 * Then, let the 16 bit scheduler do it's thing.
1915 Yield16();
1918 * If a message matching the wait mask has arrived, return.
1920 if (msgQueue->changeBits & dwWakeMask)
1922 ret = nCount;
1923 break;
1927 * And continue doing this until we hit the timeout.
1929 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1931 else
1933 /* Add the thread event to the handle list */
1934 for (i = 0; i < nCount; i++)
1935 handles[i] = pHandles[i];
1936 handles[nCount] = msgQueue->hEvent;
1938 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1941 QUEUE_Unlock( msgQueue );
1943 return ret;
1948 struct accent_char
1950 BYTE ac_accent;
1951 BYTE ac_char;
1952 BYTE ac_result;
1955 static const struct accent_char accent_chars[] =
1957 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1958 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1959 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1960 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1961 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1962 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1963 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1964 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1965 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1966 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1967 {',', 'C', '\307'}, {',', 'c', '\347'},
1968 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1969 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1970 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1971 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1972 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1973 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1974 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1975 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1976 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1977 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1978 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1979 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1980 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1981 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1982 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1983 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1984 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1985 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1986 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1987 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1988 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1989 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1990 {'s', 's', '\337'}, {'"', 'y', '\377'},
1991 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1992 /* iso-8859-2 uses this */
1993 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1994 {'<', 'S', '\251'}, {'<', 's', '\271'},
1995 {'<', 'T', '\253'}, {'<', 't', '\273'},
1996 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1997 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1998 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1999 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2000 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2001 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2002 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2003 {';', 'E', '\312'}, {';', 'e', '\332'},
2004 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2005 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2006 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2007 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2008 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2009 /* collision whith S, from iso-8859-9 !!! */
2010 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2011 {',', 'T', '\336'}, {',', 't', '\376'},
2012 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2013 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2014 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2015 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2016 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2017 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2018 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2019 /* iso-8859-3 uses this */
2020 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2021 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2022 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2023 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2024 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2025 {'>', 'S', '\336'}, {'>', 's', '\376'},
2026 /* collision whith G( from iso-8859-9 !!! */
2027 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2028 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2029 /* collision whith I. from iso-8859-3 !!! */
2030 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2031 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2032 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2033 /* iso-8859-4 uses this */
2034 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2035 {',', 'L', '\246'}, {',', 'l', '\266'},
2036 {',', 'G', '\253'}, {',', 'g', '\273'},
2037 {',', 'N', '\321'}, {',', 'n', '\361'},
2038 {',', 'K', '\323'}, {',', 'k', '\363'},
2039 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2040 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2041 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2042 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2043 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2044 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2045 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2046 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2047 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2048 {';', 'U', '\331'}, {';', 'u', '\371'},
2049 /* iso-8859-9 uses this */
2050 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2051 * whith the same letters on other iso-8859-x (that is they are on
2052 * different places :-( ), if you use turkish uncomment these and
2053 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2054 * FIXME: should be dynamic according to chosen language
2055 * if/when Wine has turkish support.
2057 /* collision whith G( from iso-8859-3 !!! */
2058 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2059 /* collision whith S, from iso-8859-2 !!! */
2060 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2061 /* collision whith I. from iso-8859-3 !!! */
2062 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2066 /***********************************************************************
2067 * MSG_DoTranslateMessage
2069 * Implementation of TranslateMessage.
2071 * TranslateMessage translates virtual-key messages into character-messages,
2072 * as follows :
2073 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2074 * ditto replacing WM_* with WM_SYS*
2075 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2076 * by the keyboard driver.
2078 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2079 WPARAM wParam, LPARAM lParam )
2081 static int dead_char;
2082 BYTE wp[2];
2084 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2085 TRACE_(msg)("(%s, %04X, %08lX)\n",
2086 SPY_GetMsgName(message), wParam, lParam );
2087 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2088 TRACE_(key)("(%s, %04X, %08lX)\n",
2089 SPY_GetMsgName(message), wParam, lParam );
2091 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2093 TRACE_(key)("Translating key %04X, scancode %04X\n",
2094 wParam, HIWORD(lParam) );
2096 /* FIXME : should handle ToAscii yielding 2 */
2097 switch (ToAscii(wParam, HIWORD(lParam),
2098 QueueKeyStateTable,(LPWORD)wp, 0))
2100 case 1 :
2101 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2102 /* Should dead chars handling go in ToAscii ? */
2103 if (dead_char)
2105 int i;
2107 if (wp[0] == ' ') wp[0] = dead_char;
2108 if (dead_char == 0xa2) dead_char = '(';
2109 else if (dead_char == 0xa8) dead_char = '"';
2110 else if (dead_char == 0xb2) dead_char = ';';
2111 else if (dead_char == 0xb4) dead_char = '\'';
2112 else if (dead_char == 0xb7) dead_char = '<';
2113 else if (dead_char == 0xb8) dead_char = ',';
2114 else if (dead_char == 0xff) dead_char = '.';
2115 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2116 if ((accent_chars[i].ac_accent == dead_char) &&
2117 (accent_chars[i].ac_char == wp[0]))
2119 wp[0] = accent_chars[i].ac_result;
2120 break;
2122 dead_char = 0;
2124 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2125 PostMessage16( hwnd, message, wp[0], lParam );
2126 return TRUE;
2128 case -1 :
2129 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2130 dead_char = wp[0];
2131 TRACE_(key)("-1 -> PostMessage(%s)\n",
2132 SPY_GetMsgName(message));
2133 PostMessage16( hwnd, message, wp[0], lParam );
2134 return TRUE;
2136 return FALSE;
2140 /***********************************************************************
2141 * TranslateMessage16 (USER.113)
2143 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2145 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2146 msg->wParam, msg->lParam );
2150 /***********************************************************************
2151 * WIN16_TranslateMessage32 (USER.821)
2153 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2155 WPARAM wParam;
2157 if (wHaveParamHigh)
2158 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2159 else
2160 wParam = (WPARAM)msg->msg.wParam;
2162 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2163 wParam, msg->msg.lParam );
2166 /***********************************************************************
2167 * TranslateMessage32 (USER32.556)
2169 BOOL WINAPI TranslateMessage( const MSG *msg )
2171 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2172 msg->wParam, msg->lParam );
2176 /***********************************************************************
2177 * DispatchMessage16 (USER.114)
2179 LONG WINAPI DispatchMessage16( const MSG16* msg )
2181 WND * wndPtr;
2182 LONG retval;
2183 int painting;
2185 /* Process timer messages */
2186 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2188 if (msg->lParam)
2190 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2191 msg->message, msg->wParam, GetTickCount() );
2195 if (!msg->hwnd) return 0;
2196 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2197 if (!wndPtr->winproc)
2199 retval = 0;
2200 goto END;
2202 painting = (msg->message == WM_PAINT);
2203 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2205 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2206 msg->wParam, msg->lParam );
2207 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2208 msg->hwnd, msg->message,
2209 msg->wParam, msg->lParam );
2210 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2212 WIN_ReleaseWndPtr(wndPtr);
2213 wndPtr = WIN_FindWndPtr(msg->hwnd);
2214 if (painting && wndPtr &&
2215 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2217 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2218 msg->hwnd);
2219 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2220 /* Validate the update region to avoid infinite WM_PAINT loop */
2221 ValidateRect( msg->hwnd, NULL );
2223 END:
2224 WIN_ReleaseWndPtr(wndPtr);
2225 return retval;
2229 /***********************************************************************
2230 * WIN16_DispatchMessage32 (USER.822)
2232 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2234 if (wHaveParamHigh == FALSE)
2235 return DispatchMessage16(&(lpmsg16_32->msg));
2236 else
2238 MSG msg;
2240 msg.hwnd = lpmsg16_32->msg.hwnd;
2241 msg.message = lpmsg16_32->msg.message;
2242 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2243 msg.lParam = lpmsg16_32->msg.lParam;
2244 msg.time = lpmsg16_32->msg.time;
2245 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2246 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2247 return DispatchMessageA(&msg);
2251 /***********************************************************************
2252 * DispatchMessage32A (USER32.141)
2254 LONG WINAPI DispatchMessageA( const MSG* msg )
2256 WND * wndPtr;
2257 LONG retval;
2258 int painting;
2260 /* Process timer messages */
2261 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2263 if (msg->lParam)
2265 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2266 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2267 msg->message, msg->wParam, GetTickCount() );
2271 if (!msg->hwnd) return 0;
2272 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2273 if (!wndPtr->winproc)
2275 retval = 0;
2276 goto END;
2278 painting = (msg->message == WM_PAINT);
2279 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2280 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2282 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2283 msg->wParam, msg->lParam );
2284 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2285 msg->hwnd, msg->message,
2286 msg->wParam, msg->lParam );
2287 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2289 WIN_ReleaseWndPtr(wndPtr);
2290 wndPtr = WIN_FindWndPtr(msg->hwnd);
2292 if (painting && wndPtr &&
2293 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2295 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2296 msg->hwnd);
2297 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2298 /* Validate the update region to avoid infinite WM_PAINT loop */
2299 ValidateRect( msg->hwnd, NULL );
2301 END:
2302 WIN_ReleaseWndPtr(wndPtr);
2303 return retval;
2307 /***********************************************************************
2308 * DispatchMessage32W (USER32.142) Process Message
2310 * Process the message specified in the structure *_msg_.
2312 * If the lpMsg parameter points to a WM_TIMER message and the
2313 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2314 * points to the function that is called instead of the window
2315 * procedure.
2317 * The message must be valid.
2319 * RETURNS
2321 * DispatchMessage() returns the result of the window procedure invoked.
2323 * CONFORMANCE
2325 * ECMA-234, Win32
2328 LONG WINAPI DispatchMessageW( const MSG* msg )
2330 WND * wndPtr;
2331 LONG retval;
2332 int painting;
2334 /* Process timer messages */
2335 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2337 if (msg->lParam)
2339 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2340 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2341 msg->message, msg->wParam, GetTickCount() );
2345 if (!msg->hwnd) return 0;
2346 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2347 if (!wndPtr->winproc)
2349 retval = 0;
2350 goto END;
2352 painting = (msg->message == WM_PAINT);
2353 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2354 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2356 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2357 msg->wParam, msg->lParam );
2358 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2359 msg->hwnd, msg->message,
2360 msg->wParam, msg->lParam );
2361 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2363 WIN_ReleaseWndPtr(wndPtr);
2364 wndPtr = WIN_FindWndPtr(msg->hwnd);
2366 if (painting && wndPtr &&
2367 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2369 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2370 msg->hwnd);
2371 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2372 /* Validate the update region to avoid infinite WM_PAINT loop */
2373 ValidateRect( msg->hwnd, NULL );
2375 END:
2376 WIN_ReleaseWndPtr(wndPtr);
2377 return retval;
2381 /***********************************************************************
2382 * RegisterWindowMessage16 (USER.118)
2384 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2386 TRACE_(msg)("%08lx\n", (DWORD)str );
2387 return GlobalAddAtom16( str );
2391 /***********************************************************************
2392 * RegisterWindowMessage32A (USER32.437)
2394 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2396 TRACE_(msg)("%s\n", str );
2397 return GlobalAddAtomA( str );
2401 /***********************************************************************
2402 * RegisterWindowMessage32W (USER32.438)
2404 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2406 TRACE_(msg)("%p\n", str );
2407 return GlobalAddAtomW( str );
2411 /***********************************************************************
2412 * GetTickCount (USER.13) (KERNEL32.299) System Time
2413 * Returns the number of milliseconds, modulo 2^32, since the start
2414 * of the current session.
2416 * CONFORMANCE
2418 * ECMA-234, Win32
2420 DWORD WINAPI GetTickCount(void)
2422 struct timeval t;
2423 gettimeofday( &t, NULL );
2424 /* make extremely compatible: granularity is 25 msec */
2425 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2429 /***********************************************************************
2430 * GetCurrentTime16 (USER.15)
2432 * (effectively identical to GetTickCount)
2434 DWORD WINAPI GetCurrentTime16(void)
2436 return GetTickCount();
2440 /***********************************************************************
2441 * InSendMessage16 (USER.192)
2443 BOOL16 WINAPI InSendMessage16(void)
2445 return InSendMessage();
2449 /***********************************************************************
2450 * InSendMessage32 (USER32.320)
2452 BOOL WINAPI InSendMessage(void)
2454 MESSAGEQUEUE *queue;
2455 BOOL ret;
2457 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2458 return 0;
2459 ret = (BOOL)queue->smWaiting;
2461 QUEUE_Unlock( queue );
2462 return ret;
2465 /***********************************************************************
2466 * BroadcastSystemMessage (USER32.12)
2468 LONG WINAPI BroadcastSystemMessage(
2469 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2470 LPARAM lParam
2472 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2473 dwFlags,*recipients,uMessage,wParam,lParam
2475 return 0;
2478 /***********************************************************************
2479 * SendNotifyMessageA (USER32.460)
2480 * FIXME
2481 * The message sended with PostMessage has to be put in the queue
2482 * with a higher priority as the other "Posted" messages.
2483 * QUEUE_AddMsg has to be modifyed.
2485 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2486 { BOOL ret = TRUE;
2487 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2488 hwnd, msg, wParam, lParam);
2490 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2491 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2493 else
2494 { PostMessageA ( hwnd, msg, wParam, lParam );
2496 return ret;
2499 /***********************************************************************
2500 * SendNotifyMessageW (USER32.461)
2501 * FIXME
2502 * The message sended with PostMessage has to be put in the queue
2503 * with a higher priority as the other "Posted" messages.
2504 * QUEUE_AddMsg has to be modifyed.
2506 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2507 { BOOL ret = TRUE;
2508 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2509 hwnd, msg, wParam, lParam);
2511 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2512 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2514 else
2515 { PostMessageW ( hwnd, msg, wParam, lParam );
2517 return ret;
2520 /***********************************************************************
2521 * SendMessageCallback32A
2522 * FIXME: It's like PostMessage. The callback gets called when the message
2523 * is processed. We have to modify the message processing for a exact
2524 * implementation...
2526 BOOL WINAPI SendMessageCallbackA(
2527 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2528 FARPROC lpResultCallBack,DWORD dwData)
2530 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2531 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2532 if ( hWnd == HWND_BROADCAST)
2533 { PostMessageA( hWnd, Msg, wParam, lParam);
2534 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2535 return TRUE;
2537 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2538 return TRUE;
2540 /***********************************************************************
2541 * SendMessageCallback32W
2542 * FIXME: It's like PostMessage. The callback gets called when the message
2543 * is processed. We have to modify the message processing for a exact
2544 * implementation...
2546 BOOL WINAPI SendMessageCallbackW(
2547 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2548 FARPROC lpResultCallBack,DWORD dwData)
2550 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2551 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2552 if ( hWnd == HWND_BROADCAST)
2553 { PostMessageW( hWnd, Msg, wParam, lParam);
2554 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2555 return TRUE;
2557 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2558 return TRUE;