Implemented SHCreateShellFolderViewEx.
[wine/hacks.git] / windows / message.c
blob9dff28bf155cf927e9b690987f30d62d0de81e52
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 static 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(GetClassLongA(hWnd, GCL_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 != GetForegroundWindow() )
330 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
331 eatMsg = TRUE;
335 } else sendSC = (remove && sendSC);
337 /* Send the WM_SETCURSOR message */
339 if (sendSC)
340 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
341 MAKELONG( hittest, message ));
342 if (eatMsg)
344 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
345 goto END;
348 retvalue = SYSQ_MSG_ACCEPT;
349 END:
350 WIN_ReleaseWndPtr(pWnd);
352 return retvalue;
356 /***********************************************************************
357 * MSG_TranslateKbdMsg
359 * Translate an keyboard hardware event into a real message.
361 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
362 MSG *msg, BOOL remove )
364 WORD message = msg->message;
365 HWND hWnd = GetFocus();
366 WND *pWnd;
368 /* Should check Ctrl-Esc and PrintScreen here */
370 if (!hWnd)
372 /* Send the message to the active window instead, */
373 /* translating messages to their WM_SYS equivalent */
375 hWnd = GetActiveWindow();
377 if( message < WM_SYSKEYDOWN )
378 message += WM_SYSKEYDOWN - WM_KEYDOWN;
380 pWnd = WIN_FindWndPtr( hWnd );
381 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
383 /* Not for the current task */
384 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
385 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
386 QUEUE_Unlock( queue );
388 /* Wake up the other task */
389 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
390 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
391 QUEUE_Unlock( queue );
392 WIN_ReleaseWndPtr(pWnd);
393 return SYSQ_MSG_ABANDON;
395 WIN_ReleaseWndPtr(pWnd);
397 if (hTopWnd && hWnd != hTopWnd)
398 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
399 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
401 msg->hwnd = hWnd;
402 msg->message = message;
404 return SYSQ_MSG_ACCEPT;
408 /***********************************************************************
409 * MSG_ProcessKbdMsg
411 * Processes a translated keyboard message
413 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
415 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
416 LOWORD (msg->wParam), msg->lParam )
417 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
421 /***********************************************************************
422 * MSG_JournalRecordMsg
424 * Build an EVENTMSG structure and call JOURNALRECORD hook
426 static void MSG_JournalRecordMsg( MSG *msg )
428 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
429 if (!event) return;
430 event->message = msg->message;
431 event->time = msg->time;
432 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
434 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
435 event->paramH = msg->lParam & 0x7FFF;
436 if (HIWORD(msg->lParam) & 0x0100)
437 event->paramH |= 0x8000; /* special_key - bit */
438 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
440 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
442 event->paramL = LOWORD(msg->lParam); /* X pos */
443 event->paramH = HIWORD(msg->lParam); /* Y pos */
444 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
445 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
447 else if ((msg->message >= WM_NCMOUSEFIRST) &&
448 (msg->message <= WM_NCMOUSELAST))
450 event->paramL = LOWORD(msg->lParam); /* X pos */
451 event->paramH = HIWORD(msg->lParam); /* Y pos */
452 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
453 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
456 HeapFree(SystemHeap, 0, event);
459 /***********************************************************************
460 * MSG_JournalPlayBackMsg
462 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
464 static int MSG_JournalPlayBackMsg(void)
466 EVENTMSG *tmpMsg;
467 long wtime,lParam,wParam;
468 WORD keyDown,i,result=0;
470 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
472 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
473 if (!tmpMsg) return result;
475 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
476 (LPARAM) tmpMsg );
477 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
478 if (wtime<=0)
480 wtime=0;
481 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
483 wParam=tmpMsg->paramL & 0xFF;
484 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
485 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
487 for (keyDown=i=0; i<256 && !keyDown; i++)
488 if (InputKeyStateTable[i] & 0x80)
489 keyDown++;
490 if (!keyDown)
491 lParam |= 0x40000000;
492 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
494 else /* WM_KEYUP, WM_SYSKEYUP */
496 lParam |= 0xC0000000;
497 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
499 if (InputKeyStateTable[VK_MENU] & 0x80)
500 lParam |= 0x20000000;
501 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
502 lParam |= 0x01000000;
503 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
504 0, 0, tmpMsg->time, 0 );
506 else
508 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
510 switch (tmpMsg->message)
512 case WM_LBUTTONDOWN:
513 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
514 case WM_LBUTTONUP:
515 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
516 case WM_MBUTTONDOWN:
517 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
518 case WM_MBUTTONUP:
519 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
520 case WM_RBUTTONDOWN:
521 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
522 case WM_RBUTTONUP:
523 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
525 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
526 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
527 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
528 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
529 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
530 wParam=0;
531 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
532 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
533 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
534 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
535 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
538 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
539 (LPARAM) tmpMsg);
541 else
544 if( tmpMsg->message == WM_QUEUESYNC )
545 if (HOOK_IsHooked( WH_CBT ))
546 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
548 result= QS_MOUSE | QS_KEY; /* ? */
550 HeapFree(SystemHeap, 0, tmpMsg);
552 return result;
555 /***********************************************************************
556 * MSG_PeekHardwareMsg
558 * Peek for a hardware message matching the hwnd and message filters.
560 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
561 BOOL remove )
563 /* FIXME: should deal with MSG32 instead of MSG16 */
565 DWORD status = SYSQ_MSG_ACCEPT;
566 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
567 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
568 QMSG *nextqmsg, *qmsg = 0;
569 BOOL bRet = FALSE;
571 /* FIXME: there has to be a better way to do this */
572 joySendMessages();
574 EnterCriticalSection(&sysMsgQueue->cSection);
576 /* Loop through the Q and translate the message we wish to process
577 * while we own the lock. Based on the translation status (abandon/cont/accept)
578 * we then process the message accordingly
581 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
583 INT16 hittest;
584 POINT16 screen_pt;
585 BOOL mouseClick;
587 *msg = qmsg->msg;
589 nextqmsg = qmsg->nextMsg;
591 /* Translate message */
593 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
595 HWND hWndScope = (HWND)qmsg->extraInfo;
596 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
597 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
599 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
600 &hittest, &screen_pt, &mouseClick );
601 msgType = MOUSE_MSG;
603 WIN_ReleaseWndPtr(tmpWnd);
606 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
608 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
609 msgType = KEYBOARD_MSG;
611 else /* Non-standard hardware event */
613 HARDWAREHOOKSTRUCT16 *hook;
614 msgType = HARDWARE_MSG;
615 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
617 BOOL ret;
618 hook->hWnd = msg->hwnd;
619 hook->wMessage = msg->message & 0xffff;
620 hook->wParam = LOWORD (msg->wParam);
621 hook->lParam = msg->lParam;
622 ret = HOOK_CallHooks16( WH_HARDWARE,
623 remove ? HC_ACTION : HC_NOREMOVE,
624 0, (LPARAM)SEGPTR_GET(hook) );
625 SEGPTR_FREE(hook);
626 if (ret)
628 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
629 continue;
631 status = SYSQ_MSG_ACCEPT;
636 switch (LOWORD(status))
638 case SYSQ_MSG_ACCEPT:
640 /* Remove the message from the system msg Q while it is still locked,
641 * before accepting it */
642 if (remove)
644 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
645 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
647 /* Now actually process the message, after we unlock the system msg Q.
648 * We should not hold on to the crst since SendMessage calls during processing
649 * will potentially cause callbacks to PeekMessage from the application.
650 * If we're holding the crst and QUEUE_WaitBits is called with a
651 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
652 * message is being posted to the Q.
654 LeaveCriticalSection(&sysMsgQueue->cSection);
655 if( msgType == KEYBOARD_MSG )
656 status = MSG_ProcessKbdMsg( msg, remove );
657 else if ( msgType == MOUSE_MSG )
658 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
660 /* Reclaim the sys msg Q crst */
661 EnterCriticalSection(&sysMsgQueue->cSection);
663 /* Pass the translated message to the user if it was accepted */
664 if (status == SYSQ_MSG_ACCEPT)
665 break;
667 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
670 case SYSQ_MSG_SKIP:
671 if (HOOK_IsHooked( WH_CBT ))
673 if( msgType == KEYBOARD_MSG )
674 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
675 LOWORD (msg->wParam), msg->lParam );
676 else if ( msgType == MOUSE_MSG )
678 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
679 if (hook)
681 CONV_POINT32TO16( &msg->pt,&hook->pt );
682 hook->hwnd = msg->hwnd;
683 hook->wHitTestCode = HIWORD(status);
684 hook->dwExtraInfo = 0;
685 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
686 (LPARAM)SEGPTR_GET(hook) );
687 SEGPTR_FREE(hook);
692 /* If the message was removed earlier set up nextqmsg so that we start
693 * at the top of the queue again. We need to do this since our next pointer
694 * could be invalid due to us unlocking the system message Q to process the message.
695 * If not removed just refresh nextqmsg to point to the next msg.
697 if (remove)
698 nextqmsg = sysMsgQueue->firstMsg;
699 else
700 nextqmsg = qmsg->nextMsg;
702 continue;
704 case SYSQ_MSG_CONTINUE:
705 continue;
707 case SYSQ_MSG_ABANDON:
708 bRet = FALSE;
709 goto END;
712 bRet = TRUE;
713 goto END;
716 END:
717 LeaveCriticalSection(&sysMsgQueue->cSection);
718 return bRet;
722 /**********************************************************************
723 * SetDoubleClickTime16 (USER.20)
725 void WINAPI SetDoubleClickTime16( UINT16 interval )
727 SetDoubleClickTime( interval );
731 /**********************************************************************
732 * SetDoubleClickTime32 (USER32.480)
734 BOOL WINAPI SetDoubleClickTime( UINT interval )
736 doubleClickSpeed = interval ? interval : 500;
737 return TRUE;
741 /**********************************************************************
742 * GetDoubleClickTime16 (USER.21)
744 UINT16 WINAPI GetDoubleClickTime16(void)
746 return doubleClickSpeed;
750 /**********************************************************************
751 * GetDoubleClickTime32 (USER32.239)
753 UINT WINAPI GetDoubleClickTime(void)
755 return doubleClickSpeed;
759 /***********************************************************************
760 * MSG_SendMessageInterThread
762 * Implementation of an inter-task SendMessage.
763 * Return values:
764 * 0 if error or timeout
765 * 1 if successflul
767 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
768 HWND hwnd, UINT msg,
769 WPARAM wParam, LPARAM lParam,
770 DWORD timeout, WORD flags,
771 LRESULT *pRes)
773 MESSAGEQUEUE *queue, *destQ;
774 SMSG *smsg;
775 LRESULT retVal = 1;
776 int iWndsLocks;
778 *pRes = 0;
780 if (IsTaskLocked16() || !IsWindow(hwnd))
781 return 0;
783 /* create a SMSG structure to hold SendMessage() parameters */
784 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
785 return 0;
786 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
788 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
790 QUEUE_Unlock( queue );
791 return 0;
794 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
795 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
797 /* fill up SMSG structure */
798 smsg->hWnd = hwnd;
799 smsg->msg = msg;
800 smsg->wParam = wParam;
801 smsg->lParam = lParam;
803 smsg->lResult = 0;
804 smsg->hSrcQueue = GetFastQueue16();
805 smsg->hDstQueue = hDestQueue;
806 smsg->flags = flags;
808 /* add smsg struct in the processing SM list of the source queue */
809 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
811 /* add smsg struct in the pending list of the destination queue */
812 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
813 return 0;
815 iWndsLocks = WIN_SuspendWndsLock();
817 /* force destination task to run next, if 16 bit threads */
818 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
819 DirectedYield16( destQ->teb->htask16 );
821 /* wait for the result, note that 16-bit apps almost always get out of
822 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
824 while ( TRUE )
827 * The sequence is crucial to avoid deadlock situations:
828 * - first, we clear the QS_SMRESULT bit
829 * - then, we check the SMSG_HAVE_RESULT bit
830 * - only if this isn't set, we enter the wait state.
832 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
833 * we are guaranteed that -should we now clear the QS_SMRESULT that
834 * was signalled already by the receiver- we will not start waiting.
837 if ( smsg->flags & SMSG_HAVE_RESULT )
839 got:
840 *pRes = smsg->lResult;
841 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
842 break;
845 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
847 if ( smsg->flags & SMSG_HAVE_RESULT )
848 goto got;
850 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
852 /* return with timeout */
853 SetLastError( 0 );
854 retVal = 0;
855 break;
858 WIN_RestoreWndsLock(iWndsLocks);
860 /* remove the smsg from the processingg list of the source queue */
861 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
863 /* Note: the destination thread is in charge of removing the smsg from
864 the pending list */
866 /* In the case of an early reply (or a timeout), sender thread will
867 released the smsg structure if the receiver thread is done
868 (SMSG_RECEIVED set). If the receiver thread isn't done,
869 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
870 responsability to released smsg */
871 EnterCriticalSection( &queue->cSection );
873 if (smsg->flags & SMSG_RECEIVED)
874 HeapFree(SystemHeap, 0, smsg);
875 else
876 smsg->flags |= SMSG_RECEIVER_CLEANS;
878 LeaveCriticalSection( &queue->cSection );
881 QUEUE_Unlock( queue );
882 QUEUE_Unlock( destQ );
884 TRACE_(sendmsg)("done!\n");
885 return retVal;
889 /***********************************************************************
890 * ReplyMessage16 (USER.115)
892 void WINAPI ReplyMessage16( LRESULT result )
894 ReplyMessage( result );
897 /***********************************************************************
898 * ReplyMessage (USER.115)
900 BOOL WINAPI ReplyMessage( LRESULT result )
902 MESSAGEQUEUE *senderQ = 0;
903 MESSAGEQUEUE *queue = 0;
904 SMSG *smsg;
905 BOOL ret = FALSE;
907 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
908 return FALSE;
910 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
913 if ( !(smsg = queue->smWaiting)
914 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
915 goto ReplyMessageEnd;
917 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
919 /* This is the first reply, so pass result to sender */
921 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
923 EnterCriticalSection(&senderQ->cSection);
925 smsg->lResult = result;
926 smsg->flags |= SMSG_ALREADY_REPLIED;
928 /* check if it's an early reply (called by the application) or
929 a regular reply (called by ReceiveMessage) */
930 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
931 smsg->flags |= SMSG_EARLY_REPLY;
933 smsg->flags |= SMSG_HAVE_RESULT;
935 LeaveCriticalSection(&senderQ->cSection);
937 /* tell the sending task that its reply is ready */
938 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
940 /* switch directly to sending task (16 bit thread only) */
941 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
942 DirectedYield16( senderQ->teb->htask16 );
944 ret = TRUE;
947 if (smsg->flags & SMSG_SENDING_REPLY)
949 /* remove msg from the waiting list, since this is the last
950 ReplyMessage */
951 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
953 EnterCriticalSection(&senderQ->cSection);
955 /* tell the sender we're all done with smsg structure */
956 smsg->flags |= SMSG_RECEIVED;
958 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
959 receiver to clean up smsg, it could only happens when there is
960 an early reply or a timeout */
961 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
963 TRACE_(sendmsg)("Receiver cleans up!\n" );
964 HeapFree( SystemHeap, 0, smsg );
967 LeaveCriticalSection(&senderQ->cSection);
970 ReplyMessageEnd:
971 if ( senderQ )
972 QUEUE_Unlock( senderQ );
973 if ( queue )
974 QUEUE_Unlock( queue );
976 return ret;
979 /***********************************************************************
980 * MSG_PeekMessage
982 static BOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, DWORD first, DWORD last,
983 WORD flags, BOOL peek )
985 int mask;
986 MESSAGEQUEUE *msgQueue;
987 HQUEUE16 hQueue;
988 POINT16 pt16;
989 int iWndsLocks;
991 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
992 if (first || last)
994 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
995 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
996 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
997 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
998 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
999 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1001 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1003 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1005 /* Never yield on Win32 threads */
1006 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
1008 iWndsLocks = WIN_SuspendWndsLock();
1010 while(1)
1012 QMSG *qmsg;
1014 hQueue = GetFastQueue16();
1015 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1016 if (!msgQueue)
1018 WIN_RestoreWndsLock(iWndsLocks);
1019 return FALSE;
1021 msgQueue->changeBits = 0;
1023 /* First handle a message put by SendMessage() */
1025 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1026 QUEUE_ReceiveMessage( msgQueue );
1028 /* Now handle a WM_QUIT message */
1030 if (msgQueue->wPostQMsg &&
1031 (!first || WM_QUIT >= first) &&
1032 (!last || WM_QUIT <= last) )
1034 msg->hwnd = hwnd;
1035 msg->message = WM_QUIT;
1036 msg->wParam = msgQueue->wExitCode;
1037 msg->lParam = 0;
1038 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1039 break;
1042 /* Now find a normal message */
1044 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
1045 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1047 *msg = qmsg->msg;
1049 msgQueue->GetMessageTimeVal = msg->time;
1050 CONV_POINT32TO16(&msg->pt, &pt16);
1051 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1052 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1054 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1055 break;
1058 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
1060 /* Now find a hardware event */
1062 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
1063 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
1065 /* Got one */
1066 msgQueue->GetMessageTimeVal = msg->time;
1067 CONV_POINT32TO16(&msg->pt, &pt16);
1068 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1069 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1070 break;
1073 /* Check again for SendMessage */
1075 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1076 QUEUE_ReceiveMessage( msgQueue );
1078 /* Now find a WM_PAINT message */
1080 if ((msgQueue->wakeBits & mask) & QS_PAINT)
1082 WND* wndPtr;
1083 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1084 msg->message = WM_PAINT;
1085 msg->wParam = 0;
1086 msg->lParam = 0;
1088 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
1090 if( wndPtr->dwStyle & WS_MINIMIZE &&
1091 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1093 msg->message = WM_PAINTICON;
1094 msg->wParam = 1;
1097 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1099 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1101 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1102 QUEUE_DecPaintCount( hQueue );
1104 WIN_ReleaseWndPtr(wndPtr);
1105 break;
1107 WIN_ReleaseWndPtr(wndPtr);
1111 /* Check for timer messages, but yield first */
1113 if (!(flags & PM_NOYIELD))
1115 UserYield16();
1116 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1117 QUEUE_ReceiveMessage( msgQueue );
1119 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1121 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1124 if (peek)
1126 if (!(flags & PM_NOYIELD)) UserYield16();
1128 QUEUE_Unlock( msgQueue );
1129 WIN_RestoreWndsLock(iWndsLocks);
1130 return FALSE;
1132 msgQueue->wakeMask = mask;
1133 QUEUE_WaitBits( mask, INFINITE );
1134 QUEUE_Unlock( msgQueue );
1137 WIN_RestoreWndsLock(iWndsLocks);
1139 /* instead of unlocking queue for every break condition, all break
1140 condition will fall here */
1141 QUEUE_Unlock( msgQueue );
1143 /* We got a message */
1144 if (flags & PM_REMOVE)
1146 WORD message = msg->message;
1148 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1150 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1152 if (!(*p & 0x80))
1153 *p ^= 0x01;
1154 *p |= 0x80;
1156 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1157 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1160 if (peek)
1161 return TRUE;
1163 else
1164 return (msg->message != WM_QUIT);
1167 /***********************************************************************
1168 * MSG_InternalGetMessage
1170 * GetMessage() function for internal use. Behave like GetMessage(),
1171 * but also call message filters and optionally send WM_ENTERIDLE messages.
1172 * 'hwnd' must be the handle of the dialog or menu window.
1173 * 'code' is the message filter value (MSGF_??? codes).
1175 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner,
1176 WPARAM code, WORD flags, BOOL sendIdle )
1178 for (;;)
1180 if (sendIdle)
1182 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
1184 /* No message present -> send ENTERIDLE and wait */
1185 if (IsWindow(hwndOwner))
1186 SendMessageA( hwndOwner, WM_ENTERIDLE,
1187 code, (LPARAM)hwnd );
1188 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1191 else /* Always wait for a message */
1192 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1194 /* Call message filters */
1196 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1198 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1199 if (pmsg)
1201 BOOL ret;
1202 *pmsg = *msg;
1203 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1204 (LPARAM) pmsg ) ||
1205 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1206 (LPARAM) pmsg ));
1208 HeapFree( SystemHeap, 0, pmsg );
1209 if (ret)
1211 /* Message filtered -> remove it from the queue */
1212 /* if it's still there. */
1213 if (!(flags & PM_REMOVE))
1214 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
1215 continue;
1220 return (msg->message != WM_QUIT);
1225 /***********************************************************************
1226 * PeekMessage16 (USER.109)
1228 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd, UINT16 first,
1229 UINT16 last, UINT16 flags )
1231 MSG msg32;
1232 BOOL16 ret;
1233 ret = PeekMessageA(&msg32, hwnd, first, last, flags);
1234 STRUCT32_MSG32to16(&msg32, lpmsg);
1235 return ret;
1238 /***********************************************************************
1239 * WIN16_PeekMessage32 (USER.819)
1241 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1242 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
1244 if (wHaveParamHigh == FALSE)
1246 lpmsg16_32->wParamHigh = 0;
1247 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1249 else
1251 MSG msg32;
1252 BOOL16 ret;
1254 ret = (BOOL16)PeekMessageA(&msg32, (HWND)hwnd,
1255 (UINT)first, (UINT)last, (UINT)flags);
1256 lpmsg16_32->msg.hwnd = msg32.hwnd;
1257 lpmsg16_32->msg.message = msg32.message;
1258 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1259 lpmsg16_32->msg.lParam = msg32.lParam;
1260 lpmsg16_32->msg.time = msg32.time;
1261 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1262 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1263 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1264 return ret;
1269 /***********************************************************************
1270 * PeekMessageA
1272 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1273 UINT min,UINT max,UINT wRemoveMsg)
1275 return MSG_PeekMessage( lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1278 /***********************************************************************
1279 * PeekMessageW Check queue for messages
1281 * Checks for a message in the thread's queue, filtered as for
1282 * GetMessage(). Returns immediately whether a message is available
1283 * or not.
1285 * Whether a retrieved message is removed from the queue is set by the
1286 * _wRemoveMsg_ flags, which should be one of the following values:
1288 * PM_NOREMOVE Do not remove the message from the queue.
1290 * PM_REMOVE Remove the message from the queue.
1292 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1293 * request that the system not yield control during PeekMessage();
1294 * however applications may not rely on scheduling behavior.
1296 * RETURNS
1298 * Nonzero if a message is available and is retrieved, zero otherwise.
1300 * CONFORMANCE
1302 * ECMA-234, Win32
1305 BOOL WINAPI PeekMessageW(
1306 LPMSG lpmsg, /* buffer to receive message */
1307 HWND hwnd, /* restrict to messages for hwnd */
1308 UINT min, /* minimum message to receive */
1309 UINT max, /* maximum message to receive */
1310 UINT wRemoveMsg /* removal flags */
1313 BOOL bRet = PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1314 if (bRet)
1315 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1316 return bRet;
1319 /***********************************************************************
1320 * GetMessage16 (USER.108)
1322 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1324 BOOL ret;
1325 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1326 MSG msg32;
1328 ret = GetMessageA( &msg32, hwnd, first, last );
1330 STRUCT32_MSG32to16( &msg32, lpmsg );
1332 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1333 hwnd, first, last );
1335 return ret;
1338 /***********************************************************************
1339 * WIN16_GetMessage32 (USER.820)
1341 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1342 UINT16 last, BOOL16 wHaveParamHigh )
1344 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1346 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1349 lpmsg16_32->wParamHigh = 0; /* you never know... */
1350 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1351 return GetMessage16(msg16_32, hWnd, first, last);
1353 else
1355 MSG msg32;
1356 BOOL16 ret;
1358 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1359 lpmsg16_32->msg.hwnd = msg32.hwnd;
1360 lpmsg16_32->msg.message = msg32.message;
1361 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1362 lpmsg16_32->msg.lParam = msg32.lParam;
1363 lpmsg16_32->msg.time = msg32.time;
1364 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1365 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1366 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1367 return ret;
1371 /***********************************************************************
1372 * GetMessage32A (USER32.270)
1374 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1376 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1378 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1379 hwnd, min, max );
1381 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1383 return (lpmsg->message != WM_QUIT);
1386 /***********************************************************************
1387 * GetMessage32W (USER32.274) Retrieve next message
1389 * GetMessage retrieves the next event from the calling thread's
1390 * queue and deposits it in *lpmsg.
1392 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1393 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1394 * all application messages are retrieved.
1396 * _min_ and _max_ specify the range of messages of interest. If
1397 * min==max==0, no filtering is performed. Useful examples are
1398 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1399 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1401 * WM_PAINT messages are not removed from the queue; they remain until
1402 * processed. Other messages are removed from the queue.
1404 * RETURNS
1406 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1408 * CONFORMANCE
1410 * ECMA-234, Win32
1413 BOOL WINAPI GetMessageW(
1414 MSG* lpmsg, /* buffer to receive message */
1415 HWND hwnd, /* restrict to messages for hwnd */
1416 UINT min, /* minimum message to receive */
1417 UINT max /* maximum message to receive */
1420 BOOL bRet = GetMessageA(lpmsg, hwnd, min, max);
1421 if (bRet)
1422 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1423 return bRet;
1428 /***********************************************************************
1429 * PostMessage16 (USER.110)
1431 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1432 LPARAM lParam )
1434 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1438 /***********************************************************************
1439 * PostMessage32A (USER32.419)
1441 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1442 LPARAM lParam )
1444 MSG msg;
1445 WND *wndPtr;
1446 BOOL retvalue;
1448 msg.hwnd = hwnd;
1449 msg.message = message;
1450 msg.wParam = wParam;
1451 msg.lParam = lParam;
1452 msg.time = GetTickCount();
1453 msg.pt.x = 0;
1454 msg.pt.y = 0;
1456 if (hwnd == HWND_BROADCAST)
1458 WND *pDesktop = WIN_GetDesktop();
1459 TRACE_(msg)("HWND_BROADCAST !\n");
1461 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1463 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1465 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1466 wndPtr->hwndSelf, message, wParam, lParam);
1467 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1470 WIN_ReleaseDesktop();
1471 TRACE_(msg)("End of HWND_BROADCAST !\n");
1472 return TRUE;
1475 wndPtr = WIN_FindWndPtr( hwnd );
1476 if (!wndPtr || !wndPtr->hmemTaskQ)
1478 retvalue = FALSE;
1479 goto END;
1482 retvalue = QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1483 END:
1484 WIN_ReleaseWndPtr(wndPtr);
1485 return retvalue;
1489 /***********************************************************************
1490 * PostMessage32W (USER32.420)
1492 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1493 LPARAM lParam )
1495 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(message));
1496 return PostMessageA( hwnd, message, wParam, lParam );
1500 /***********************************************************************
1501 * PostAppMessage16 (USER.116)
1503 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1504 LPARAM lParam )
1506 MSG msg;
1508 if (GetTaskQueue16(hTask) == 0) return FALSE;
1509 msg.hwnd = 0;
1510 msg.message = message;
1511 msg.wParam = wParam;
1512 msg.lParam = lParam;
1513 msg.time = GetTickCount();
1514 msg.pt.x = 0;
1515 msg.pt.y = 0;
1517 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1520 /************************************************************************
1521 * MSG_CallWndProcHook32
1523 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1525 CWPSTRUCT cwp;
1527 cwp.lParam = pmsg->lParam;
1528 cwp.wParam = pmsg->wParam;
1529 cwp.message = pmsg->message;
1530 cwp.hwnd = pmsg->hwnd;
1532 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1533 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1535 pmsg->lParam = cwp.lParam;
1536 pmsg->wParam = cwp.wParam;
1537 pmsg->message = cwp.message;
1538 pmsg->hwnd = cwp.hwnd;
1542 /***********************************************************************
1543 * MSG_SendMessage
1545 * return values: 0 if timeout occurs
1546 * 1 otherwise
1548 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1549 LPARAM lParam, DWORD timeout, WORD flags,
1550 LRESULT *pRes)
1552 WND * wndPtr = 0;
1553 WND **list, **ppWnd;
1554 LRESULT ret = 1;
1556 *pRes = 0;
1558 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1560 *pRes = 1;
1562 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1564 WIN_ReleaseDesktop();
1565 return 1;
1567 WIN_ReleaseDesktop();
1569 TRACE_(msg)("HWND_BROADCAST !\n");
1570 for (ppWnd = list; *ppWnd; ppWnd++)
1572 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1573 if (!IsWindow(wndPtr->hwndSelf)) continue;
1574 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1576 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1577 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1578 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1579 timeout, flags, pRes);
1582 WIN_ReleaseWndPtr(wndPtr);
1583 WIN_ReleaseWinArray(list);
1584 TRACE_(msg)("End of HWND_BROADCAST !\n");
1585 return 1;
1588 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1590 if (flags & SMSG_UNICODE)
1591 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1592 else if (flags & SMSG_WIN32)
1593 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1594 else
1596 LPCWPSTRUCT16 pmsg;
1598 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1600 pmsg->hwnd = hwnd & 0xffff;
1601 pmsg->message= msg & 0xffff;
1602 pmsg->wParam = wParam & 0xffff;
1603 pmsg->lParam = lParam;
1604 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1605 (LPARAM)SEGPTR_GET(pmsg) );
1606 hwnd = pmsg->hwnd;
1607 msg = pmsg->message;
1608 wParam = pmsg->wParam;
1609 lParam = pmsg->lParam;
1610 SEGPTR_FREE( pmsg );
1615 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1617 WARN_(msg)("invalid hwnd %04x\n", hwnd );
1618 return 0;
1620 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1622 ret = 0; /* Don't send anything if the task is dying */
1623 goto END;
1625 if (flags & SMSG_WIN32)
1626 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1627 else
1628 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1630 if (wndPtr->hmemTaskQ != GetFastQueue16())
1631 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1632 wParam, lParam, timeout, flags, pRes );
1633 else
1635 /* Call the right CallWindowProc flavor */
1636 if (flags & SMSG_UNICODE)
1637 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1638 hwnd, msg, wParam, lParam );
1639 else if (flags & SMSG_WIN32)
1640 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1641 hwnd, msg, wParam, lParam );
1642 else
1643 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1644 (HWND16) hwnd, (UINT16) msg,
1645 (WPARAM16) wParam, lParam );
1648 if (flags & SMSG_WIN32)
1649 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1650 else
1651 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1652 END:
1653 WIN_ReleaseWndPtr(wndPtr);
1654 return ret;
1658 /***********************************************************************
1659 * SendMessage16 (USER.111)
1661 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1662 LPARAM lParam)
1664 LRESULT res;
1665 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1666 return res;
1671 /**********************************************************************
1672 * PostThreadMessage32A (USER32.422)
1674 * BUGS
1676 * Thread-local message queues are not supported.
1679 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1680 WPARAM wParam, LPARAM lParam )
1682 MSG msg;
1683 HQUEUE16 hQueue;
1685 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1686 return FALSE;
1688 msg.hwnd = 0;
1689 msg.message = message;
1690 msg.wParam = wParam;
1691 msg.lParam = lParam;
1692 msg.time = GetTickCount();
1693 msg.pt.x = 0;
1694 msg.pt.y = 0;
1696 return QUEUE_AddMsg( hQueue, &msg, 0 );
1699 /**********************************************************************
1700 * PostThreadMessage32W (USER32.423)
1702 * BUGS
1704 * Thread-local message queues are not supported.
1707 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1708 WPARAM wParam, LPARAM lParam )
1710 FIXME_(sendmsg)("(%s) unicode<->ascii\n",SPY_GetMsgName(message));
1711 return PostThreadMessageA(idThread, message, wParam, lParam);
1714 /***********************************************************************
1715 * SendMessage32A (USER32.454)
1717 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1718 LPARAM lParam )
1720 LRESULT res;
1722 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1723 SMSG_WIN32, &res);
1725 return res;
1729 /***********************************************************************
1730 * SendMessage32W (USER32.459) Send Window Message
1732 * Sends a message to the window procedure of the specified window.
1733 * SendMessage() will not return until the called window procedure
1734 * either returns or calls ReplyMessage().
1736 * Use PostMessage() to send message and return immediately. A window
1737 * procedure may use InSendMessage() to detect
1738 * SendMessage()-originated messages.
1740 * Applications which communicate via HWND_BROADCAST may use
1741 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1742 * with other applications.
1744 * CONFORMANCE
1746 * ECMA-234, Win32
1748 LRESULT WINAPI SendMessageW(
1749 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1750 the message will be sent to all top-level windows. */
1752 UINT msg, /* message */
1753 WPARAM wParam, /* message parameter */
1754 LPARAM lParam /* additional message parameter */
1756 LRESULT res;
1758 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1759 SMSG_WIN32 | SMSG_UNICODE, &res);
1761 return res;
1765 /***********************************************************************
1766 * SendMessageTimeout16 (not a WINAPI)
1768 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1769 LPARAM lParam, UINT16 flags,
1770 UINT16 timeout, LPWORD resultp)
1772 LRESULT ret;
1773 LRESULT msgRet;
1775 /* FIXME: need support for SMTO_BLOCK */
1777 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1778 *resultp = (WORD) msgRet;
1779 return ret;
1783 /***********************************************************************
1784 * SendMessageTimeoutA (USER32.457)
1786 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1787 LPARAM lParam, UINT flags,
1788 UINT timeout, LPDWORD resultp)
1790 LRESULT ret;
1791 LRESULT msgRet;
1793 /* FIXME: need support for SMTO_BLOCK */
1795 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1796 &msgRet);
1798 *resultp = (DWORD) msgRet;
1799 return ret;
1803 /***********************************************************************
1804 * SendMessageTimeoutW (USER32.458)
1806 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1807 LPARAM lParam, UINT flags,
1808 UINT timeout, LPDWORD resultp)
1810 LRESULT ret;
1811 LRESULT msgRet;
1813 /* FIXME: need support for SMTO_BLOCK */
1815 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1816 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1818 *resultp = (DWORD) msgRet;
1819 return ret;
1823 /***********************************************************************
1824 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1826 * WaitMessage() suspends a thread until events appear in the thread's
1827 * queue.
1829 * BUGS
1831 * Is supposed to return BOOL under Win32.
1833 * Thread-local message queues are not supported.
1835 * CONFORMANCE
1837 * ECMA-234, Win32
1840 void WINAPI WaitMessage( void )
1842 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1845 /***********************************************************************
1846 * MsgWaitForMultipleObjects (USER32.400)
1848 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1849 BOOL fWaitAll, DWORD dwMilliseconds,
1850 DWORD dwWakeMask )
1852 DWORD i;
1853 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1854 DWORD ret;
1856 HQUEUE16 hQueue = GetFastQueue16();
1857 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1858 if (!msgQueue) return WAIT_FAILED;
1860 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1862 SetLastError( ERROR_INVALID_PARAMETER );
1863 QUEUE_Unlock( msgQueue );
1864 return WAIT_FAILED;
1867 msgQueue->changeBits = 0;
1868 msgQueue->wakeMask = dwWakeMask;
1870 if (THREAD_IsWin16(NtCurrentTeb()))
1873 * This is a temporary solution to a big problem.
1874 * You see, the main thread of all Win32 programs is created as a 16 bit
1875 * task. This means that if you want on an event using Win32 synchronization
1876 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1877 * This implements a semi-busy loop that checks the handles to wait on and
1878 * also the message queue. When either one is ready, the wait function returns.
1880 * This will all go away when the real Win32 threads are implemented for all
1881 * the threads of an applications. Including the main thread.
1883 DWORD curTime = GetCurrentTime();
1888 * Check the handles in the list.
1890 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1893 * If the handles have been triggered, return.
1895 if (ret != WAIT_TIMEOUT)
1896 break;
1899 * Then, let the 16 bit scheduler do it's thing.
1901 Yield16();
1904 * If a message matching the wait mask has arrived, return.
1906 if (msgQueue->changeBits & dwWakeMask)
1908 ret = nCount;
1909 break;
1913 * And continue doing this until we hit the timeout.
1915 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1917 else
1919 /* Add the thread event to the handle list */
1920 for (i = 0; i < nCount; i++)
1921 handles[i] = pHandles[i];
1922 handles[nCount] = msgQueue->hEvent;
1924 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1927 QUEUE_Unlock( msgQueue );
1929 return ret;
1934 struct accent_char
1936 BYTE ac_accent;
1937 BYTE ac_char;
1938 BYTE ac_result;
1941 static const struct accent_char accent_chars[] =
1943 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1944 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1945 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1946 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1947 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1948 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1949 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1950 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1951 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1952 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1953 {',', 'C', '\307'}, {',', 'c', '\347'},
1954 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1955 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1956 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1957 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1958 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1959 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1960 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1961 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1962 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1963 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1964 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1965 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1966 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1967 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1968 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1969 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1970 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1971 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1972 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1973 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1974 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1975 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1976 {'s', 's', '\337'}, {'"', 'y', '\377'},
1977 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1978 /* iso-8859-2 uses this */
1979 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1980 {'<', 'S', '\251'}, {'<', 's', '\271'},
1981 {'<', 'T', '\253'}, {'<', 't', '\273'},
1982 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1983 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1984 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1985 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1986 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1987 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1988 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1989 {';', 'E', '\312'}, {';', 'e', '\332'},
1990 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1991 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1992 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1993 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1994 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1995 /* collision whith S, from iso-8859-9 !!! */
1996 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1997 {',', 'T', '\336'}, {',', 't', '\376'},
1998 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1999 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2000 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2001 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2002 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2003 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2004 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2005 /* iso-8859-3 uses this */
2006 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2007 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2008 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2009 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2010 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2011 {'>', 'S', '\336'}, {'>', 's', '\376'},
2012 /* collision whith G( from iso-8859-9 !!! */
2013 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2014 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2015 /* collision whith I. from iso-8859-3 !!! */
2016 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2017 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2018 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2019 /* iso-8859-4 uses this */
2020 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2021 {',', 'L', '\246'}, {',', 'l', '\266'},
2022 {',', 'G', '\253'}, {',', 'g', '\273'},
2023 {',', 'N', '\321'}, {',', 'n', '\361'},
2024 {',', 'K', '\323'}, {',', 'k', '\363'},
2025 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2026 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2027 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2028 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2029 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2030 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2031 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2032 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2033 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2034 {';', 'U', '\331'}, {';', 'u', '\371'},
2035 /* iso-8859-9 uses this */
2036 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2037 * whith the same letters on other iso-8859-x (that is they are on
2038 * different places :-( ), if you use turkish uncomment these and
2039 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2040 * FIXME: should be dynamic according to chosen language
2041 * if/when Wine has turkish support.
2043 /* collision whith G( from iso-8859-3 !!! */
2044 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2045 /* collision whith S, from iso-8859-2 !!! */
2046 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2047 /* collision whith I. from iso-8859-3 !!! */
2048 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2052 /***********************************************************************
2053 * MSG_DoTranslateMessage
2055 * Implementation of TranslateMessage.
2057 * TranslateMessage translates virtual-key messages into character-messages,
2058 * as follows :
2059 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2060 * ditto replacing WM_* with WM_SYS*
2061 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2062 * by the keyboard driver.
2064 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2065 WPARAM wParam, LPARAM lParam )
2067 static int dead_char;
2068 BYTE wp[2];
2070 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2071 TRACE_(msg)("(%s, %04X, %08lX)\n",
2072 SPY_GetMsgName(message), wParam, lParam );
2073 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2074 TRACE_(key)("(%s, %04X, %08lX)\n",
2075 SPY_GetMsgName(message), wParam, lParam );
2077 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2079 TRACE_(key)("Translating key %04X, scancode %04X\n",
2080 wParam, HIWORD(lParam) );
2082 /* FIXME : should handle ToAscii yielding 2 */
2083 switch (ToAscii(wParam, HIWORD(lParam),
2084 QueueKeyStateTable,(LPWORD)wp, 0))
2086 case 1 :
2087 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2088 /* Should dead chars handling go in ToAscii ? */
2089 if (dead_char)
2091 int i;
2093 if (wp[0] == ' ') wp[0] = dead_char;
2094 if (dead_char == 0xa2) dead_char = '(';
2095 else if (dead_char == 0xa8) dead_char = '"';
2096 else if (dead_char == 0xb2) dead_char = ';';
2097 else if (dead_char == 0xb4) dead_char = '\'';
2098 else if (dead_char == 0xb7) dead_char = '<';
2099 else if (dead_char == 0xb8) dead_char = ',';
2100 else if (dead_char == 0xff) dead_char = '.';
2101 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2102 if ((accent_chars[i].ac_accent == dead_char) &&
2103 (accent_chars[i].ac_char == wp[0]))
2105 wp[0] = accent_chars[i].ac_result;
2106 break;
2108 dead_char = 0;
2110 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2111 PostMessage16( hwnd, message, wp[0], lParam );
2112 return TRUE;
2114 case -1 :
2115 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2116 dead_char = wp[0];
2117 TRACE_(key)("-1 -> PostMessage(%s)\n",
2118 SPY_GetMsgName(message));
2119 PostMessage16( hwnd, message, wp[0], lParam );
2120 return TRUE;
2122 return FALSE;
2126 /***********************************************************************
2127 * TranslateMessage16 (USER.113)
2129 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2131 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2132 msg->wParam, msg->lParam );
2136 /***********************************************************************
2137 * WIN16_TranslateMessage32 (USER.821)
2139 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2141 WPARAM wParam;
2143 if (wHaveParamHigh)
2144 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2145 else
2146 wParam = (WPARAM)msg->msg.wParam;
2148 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2149 wParam, msg->msg.lParam );
2152 /***********************************************************************
2153 * TranslateMessage32 (USER32.556)
2155 BOOL WINAPI TranslateMessage( const MSG *msg )
2157 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2158 msg->wParam, msg->lParam );
2162 /***********************************************************************
2163 * DispatchMessage16 (USER.114)
2165 LONG WINAPI DispatchMessage16( const MSG16* msg )
2167 WND * wndPtr;
2168 LONG retval;
2169 int painting;
2171 /* Process timer messages */
2172 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2174 if (msg->lParam)
2176 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2177 msg->message, msg->wParam, GetTickCount() );
2181 if (!msg->hwnd) return 0;
2182 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2183 if (!wndPtr->winproc)
2185 retval = 0;
2186 goto END;
2188 painting = (msg->message == WM_PAINT);
2189 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2191 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2192 msg->wParam, msg->lParam );
2193 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2194 msg->hwnd, msg->message,
2195 msg->wParam, msg->lParam );
2196 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2198 WIN_ReleaseWndPtr(wndPtr);
2199 wndPtr = WIN_FindWndPtr(msg->hwnd);
2200 if (painting && wndPtr &&
2201 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2203 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2204 msg->hwnd);
2205 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2206 /* Validate the update region to avoid infinite WM_PAINT loop */
2207 ValidateRect( msg->hwnd, NULL );
2209 END:
2210 WIN_ReleaseWndPtr(wndPtr);
2211 return retval;
2215 /***********************************************************************
2216 * WIN16_DispatchMessage32 (USER.822)
2218 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2220 if (wHaveParamHigh == FALSE)
2221 return DispatchMessage16(&(lpmsg16_32->msg));
2222 else
2224 MSG msg;
2226 msg.hwnd = lpmsg16_32->msg.hwnd;
2227 msg.message = lpmsg16_32->msg.message;
2228 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2229 msg.lParam = lpmsg16_32->msg.lParam;
2230 msg.time = lpmsg16_32->msg.time;
2231 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2232 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2233 return DispatchMessageA(&msg);
2237 /***********************************************************************
2238 * DispatchMessage32A (USER32.141)
2240 LONG WINAPI DispatchMessageA( const MSG* msg )
2242 WND * wndPtr;
2243 LONG retval;
2244 int painting;
2246 /* Process timer messages */
2247 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2249 if (msg->lParam)
2251 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2252 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2253 msg->message, msg->wParam, GetTickCount() );
2257 if (!msg->hwnd) return 0;
2258 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2259 if (!wndPtr->winproc)
2261 retval = 0;
2262 goto END;
2264 painting = (msg->message == WM_PAINT);
2265 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2266 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2268 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2269 msg->wParam, msg->lParam );
2270 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2271 msg->hwnd, msg->message,
2272 msg->wParam, msg->lParam );
2273 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2275 WIN_ReleaseWndPtr(wndPtr);
2276 wndPtr = WIN_FindWndPtr(msg->hwnd);
2278 if (painting && wndPtr &&
2279 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2281 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2282 msg->hwnd);
2283 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2284 /* Validate the update region to avoid infinite WM_PAINT loop */
2285 ValidateRect( msg->hwnd, NULL );
2287 END:
2288 WIN_ReleaseWndPtr(wndPtr);
2289 return retval;
2293 /***********************************************************************
2294 * DispatchMessage32W (USER32.142) Process Message
2296 * Process the message specified in the structure *_msg_.
2298 * If the lpMsg parameter points to a WM_TIMER message and the
2299 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2300 * points to the function that is called instead of the window
2301 * procedure.
2303 * The message must be valid.
2305 * RETURNS
2307 * DispatchMessage() returns the result of the window procedure invoked.
2309 * CONFORMANCE
2311 * ECMA-234, Win32
2314 LONG WINAPI DispatchMessageW( const MSG* msg )
2316 WND * wndPtr;
2317 LONG retval;
2318 int painting;
2320 /* Process timer messages */
2321 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2323 if (msg->lParam)
2325 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2326 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2327 msg->message, msg->wParam, GetTickCount() );
2331 if (!msg->hwnd) return 0;
2332 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2333 if (!wndPtr->winproc)
2335 retval = 0;
2336 goto END;
2338 painting = (msg->message == WM_PAINT);
2339 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2340 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2342 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2343 msg->wParam, msg->lParam );
2344 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2345 msg->hwnd, msg->message,
2346 msg->wParam, msg->lParam );
2347 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2349 WIN_ReleaseWndPtr(wndPtr);
2350 wndPtr = WIN_FindWndPtr(msg->hwnd);
2352 if (painting && wndPtr &&
2353 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2355 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2356 msg->hwnd);
2357 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2358 /* Validate the update region to avoid infinite WM_PAINT loop */
2359 ValidateRect( msg->hwnd, NULL );
2361 END:
2362 WIN_ReleaseWndPtr(wndPtr);
2363 return retval;
2367 /***********************************************************************
2368 * RegisterWindowMessage16 (USER.118)
2370 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2372 TRACE_(msg)("%08lx\n", (DWORD)str );
2373 return GlobalAddAtom16( str );
2377 /***********************************************************************
2378 * RegisterWindowMessage32A (USER32.437)
2380 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2382 TRACE_(msg)("%s\n", str );
2383 return GlobalAddAtomA( str );
2387 /***********************************************************************
2388 * RegisterWindowMessage32W (USER32.438)
2390 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2392 TRACE_(msg)("%p\n", str );
2393 return GlobalAddAtomW( str );
2397 /***********************************************************************
2398 * GetTickCount (USER.13) (KERNEL32.299) System Time
2399 * Returns the number of milliseconds, modulo 2^32, since the start
2400 * of the current session.
2402 * CONFORMANCE
2404 * ECMA-234, Win32
2406 DWORD WINAPI GetTickCount(void)
2408 struct timeval t;
2409 gettimeofday( &t, NULL );
2410 /* make extremely compatible: granularity is 25 msec */
2411 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2415 /***********************************************************************
2416 * GetCurrentTime16 (USER.15)
2418 * (effectively identical to GetTickCount)
2420 DWORD WINAPI GetCurrentTime16(void)
2422 return GetTickCount();
2426 /***********************************************************************
2427 * InSendMessage16 (USER.192)
2429 BOOL16 WINAPI InSendMessage16(void)
2431 return InSendMessage();
2435 /***********************************************************************
2436 * InSendMessage32 (USER32.320)
2438 BOOL WINAPI InSendMessage(void)
2440 MESSAGEQUEUE *queue;
2441 BOOL ret;
2443 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2444 return 0;
2445 ret = (BOOL)queue->smWaiting;
2447 QUEUE_Unlock( queue );
2448 return ret;
2451 /***********************************************************************
2452 * BroadcastSystemMessage (USER32.12)
2454 LONG WINAPI BroadcastSystemMessage(
2455 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2456 LPARAM lParam
2458 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2459 dwFlags,*recipients,uMessage,wParam,lParam
2461 return 0;
2464 /***********************************************************************
2465 * SendNotifyMessageA (USER32.460)
2466 * FIXME
2467 * The message sended with PostMessage has to be put in the queue
2468 * with a higher priority as the other "Posted" messages.
2469 * QUEUE_AddMsg has to be modifyed.
2471 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2472 { BOOL ret = TRUE;
2473 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2474 hwnd, msg, wParam, lParam);
2476 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2477 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2479 else
2480 { PostMessageA ( hwnd, msg, wParam, lParam );
2482 return ret;
2485 /***********************************************************************
2486 * SendNotifyMessageW (USER32.461)
2487 * FIXME
2488 * The message sended with PostMessage has to be put in the queue
2489 * with a higher priority as the other "Posted" messages.
2490 * QUEUE_AddMsg has to be modifyed.
2492 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2493 { BOOL ret = TRUE;
2494 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2495 hwnd, msg, wParam, lParam);
2497 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2498 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2500 else
2501 { PostMessageW ( hwnd, msg, wParam, lParam );
2503 return ret;
2506 /***********************************************************************
2507 * SendMessageCallback32A
2508 * FIXME: It's like PostMessage. The callback gets called when the message
2509 * is processed. We have to modify the message processing for a exact
2510 * implementation...
2512 BOOL WINAPI SendMessageCallbackA(
2513 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2514 FARPROC lpResultCallBack,DWORD dwData)
2516 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2517 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2518 if ( hWnd == HWND_BROADCAST)
2519 { PostMessageA( hWnd, Msg, wParam, lParam);
2520 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2521 return TRUE;
2523 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2524 return TRUE;
2526 /***********************************************************************
2527 * SendMessageCallback32W
2528 * FIXME: It's like PostMessage. The callback gets called when the message
2529 * is processed. We have to modify the message processing for a exact
2530 * implementation...
2532 BOOL WINAPI SendMessageCallbackW(
2533 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2534 FARPROC lpResultCallBack,DWORD dwData)
2536 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2537 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2538 if ( hWnd == HWND_BROADCAST)
2539 { PostMessageW( hWnd, Msg, wParam, lParam);
2540 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2541 return TRUE;
2543 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2544 return TRUE;