2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
18 #include "wine/server.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(msg);
35 DECLARE_DEBUG_CHANNEL(key);
37 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
38 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
40 static UINT doubleClickSpeed = 452;
43 /***********************************************************************
46 inline static BOOL is_keyboard_message( UINT message )
48 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
52 /***********************************************************************
55 inline static BOOL is_mouse_message( UINT message )
57 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
58 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
62 /***********************************************************************
63 * check_message_filter
65 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
69 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
73 return (msg->message >= first && msg->message <= last);
79 /***********************************************************************
80 * process_sent_messages
82 * Process all pending sent messages.
84 inline static void process_sent_messages(void)
87 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
91 /***********************************************************************
92 * queue_hardware_message
94 * store a hardware message in the thread queue
96 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info, enum message_type type )
98 SERVER_START_REQ( send_message )
101 req->id = (void *)GetWindowThreadProcessId( msg->hwnd, NULL );
102 req->win = msg->hwnd;
103 req->msg = msg->message;
104 req->wparam = msg->wParam;
105 req->lparam = msg->lParam;
108 req->time = msg->time;
109 req->info = extra_info;
117 /***********************************************************************
118 * MSG_SendParentNotify
120 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
121 * the window has the WS_EX_NOPARENTNOTIFY style.
123 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
125 /* pt has to be in the client coordinates of the parent window */
126 MapWindowPoints( 0, hwnd, &pt, 1 );
131 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
132 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
133 if (!(parent = GetParent(hwnd))) break;
134 MapWindowPoints( hwnd, parent, &pt, 1 );
136 SendMessageA( hwnd, WM_PARENTNOTIFY,
137 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
142 /***********************************************************************
143 * MSG_JournalPlayBackMsg
145 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
147 void MSG_JournalPlayBackMsg(void)
154 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return;
156 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
157 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
161 msg.message = tmpMsg.message;
162 msg.hwnd = tmpMsg.hwnd;
163 msg.time = tmpMsg.time;
164 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
166 msg.wParam = tmpMsg.paramL & 0xFF;
167 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
168 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
170 for (keyDown=i=0; i<256 && !keyDown; i++)
171 if (InputKeyStateTable[i] & 0x80)
174 msg.lParam |= 0x40000000;
175 AsyncKeyStateTable[msg.wParam]=InputKeyStateTable[msg.wParam] |= 0x80;
177 else /* WM_KEYUP, WM_SYSKEYUP */
179 msg.lParam |= 0xC0000000;
180 AsyncKeyStateTable[msg.wParam]=InputKeyStateTable[msg.wParam] &= ~0x80;
182 if (InputKeyStateTable[VK_MENU] & 0x80)
183 msg.lParam |= 0x20000000;
184 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
185 msg.lParam |= 0x01000000;
187 msg.pt.x = msg.pt.y = 0;
188 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
190 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
192 switch (tmpMsg.message)
195 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
197 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
199 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
201 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
203 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
205 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
207 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
208 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
209 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
210 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
211 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
213 if (MouseButtonsStates[0]) msg.wParam |= MK_LBUTTON;
214 if (MouseButtonsStates[1]) msg.wParam |= MK_MBUTTON;
215 if (MouseButtonsStates[2]) msg.wParam |= MK_RBUTTON;
217 msg.pt.x = tmpMsg.paramL;
218 msg.pt.y = tmpMsg.paramH;
219 queue_hardware_message( &msg, 0, MSG_HARDWARE_RAW );
221 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
225 if( tmpMsg.message == WM_QUEUESYNC )
226 if (HOOK_IsHooked( WH_CBT ))
227 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
232 /***********************************************************************
233 * process_raw_keyboard_message
235 * returns TRUE if the contents of 'msg' should be passed to the application
237 static BOOL process_raw_keyboard_message( MSG *msg, ULONG_PTR extra_info )
239 if (!(msg->hwnd = GetFocus()))
241 /* Send the message to the active window instead, */
242 /* translating messages to their WM_SYS equivalent */
243 msg->hwnd = GetActiveWindow();
244 if (msg->message < WM_SYSKEYDOWN) msg->message += WM_SYSKEYDOWN - WM_KEYDOWN;
247 if (HOOK_IsHooked( WH_JOURNALRECORD ))
251 event.message = msg->message;
252 event.hwnd = msg->hwnd;
253 event.time = msg->time;
254 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
255 event.paramH = msg->lParam & 0x7FFF;
256 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
257 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
260 return (msg->hwnd != 0);
264 /***********************************************************************
265 * process_cooked_keyboard_message
267 * returns TRUE if the contents of 'msg' should be passed to the application
269 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
273 /* Handle F1 key by sending out WM_HELP message */
274 if ((msg->message == WM_KEYUP) &&
275 (msg->wParam == VK_F1) &&
276 (msg->hwnd != GetDesktopWindow()) &&
277 !MENU_IsMenuActive())
280 hi.cbSize = sizeof(HELPINFO);
281 hi.iContextType = HELPINFO_WINDOW;
282 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
283 hi.hItemHandle = msg->hwnd;
284 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
285 hi.MousePos = msg->pt;
286 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
290 if (HOOK_CallHooksA( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
291 LOWORD(msg->wParam), msg->lParam ))
293 /* skip this message */
294 HOOK_CallHooksA( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam );
301 /***********************************************************************
302 * process_raw_mouse_message
304 * returns TRUE if the contents of 'msg' should be passed to the application
306 static BOOL process_raw_mouse_message( MSG *msg, ULONG_PTR extra_info )
313 /* find the window to dispatch this mouse message to */
316 if (!(msg->hwnd = PERQDATA_GetCaptureWnd( &ht )))
318 /* If no capture HWND, find window which contains the mouse position.
319 * Also find the position of the cursor hot spot (hittest) */
320 HWND hWndScope = (HWND)extra_info;
322 if (!IsWindow(hWndScope)) hWndScope = 0;
323 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
324 msg->hwnd = GetDesktopWindow();
328 if (HOOK_IsHooked( WH_JOURNALRECORD ))
331 event.message = msg->message;
332 event.time = msg->time;
333 event.hwnd = msg->hwnd;
334 event.paramL = msg->pt.x;
335 event.paramH = msg->pt.y;
336 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
339 /* translate double clicks */
341 if ((msg->message == WM_LBUTTONDOWN) ||
342 (msg->message == WM_RBUTTONDOWN) ||
343 (msg->message == WM_MBUTTONDOWN))
346 /* translate double clicks -
347 * note that ...MOUSEMOVEs can slip in between
348 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
350 if (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS || ht != HTCLIENT )
352 if ((msg->message == clk_msg.message) &&
353 (msg->hwnd == clk_msg.hwnd) &&
354 (msg->time - clk_msg.time < doubleClickSpeed) &&
355 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
356 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
358 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
363 /* update static double click conditions */
364 if (update) clk_msg = *msg;
368 /* Note: windows has no concept of a non-client wheel message */
369 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
371 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
372 msg->wParam = hittest;
374 else ScreenToClient( msg->hwnd, &pt );
375 msg->lParam = MAKELONG( pt.x, pt.y );
380 /***********************************************************************
381 * process_cooked_mouse_message
383 * returns TRUE if the contents of 'msg' should be passed to the application
385 static BOOL process_cooked_mouse_message( MSG *msg, BOOL remove )
387 INT hittest = HTCLIENT;
388 UINT raw_message = msg->message;
391 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
393 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
394 hittest = msg->wParam;
396 if (raw_message == WM_LBUTTONDBLCLK ||
397 raw_message == WM_RBUTTONDBLCLK ||
398 raw_message == WM_MBUTTONDBLCLK)
400 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
403 if (HOOK_IsHooked( WH_MOUSE ))
405 MOUSEHOOKSTRUCT hook;
407 hook.hwnd = msg->hwnd;
408 hook.wHitTestCode = hittest;
409 hook.dwExtraInfo = 0;
410 if (HOOK_CallHooksA( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
411 msg->message, (LPARAM)&hook ))
414 hook.hwnd = msg->hwnd;
415 hook.wHitTestCode = hittest;
416 hook.dwExtraInfo = 0;
417 HOOK_CallHooksA( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook );
422 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
424 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
428 if (!remove || GetCapture()) return TRUE;
432 if ((raw_message == WM_LBUTTONDOWN) ||
433 (raw_message == WM_RBUTTONDOWN) ||
434 (raw_message == WM_MBUTTONDOWN))
436 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
438 /* Send the WM_PARENTNOTIFY,
439 * note that even for double/nonclient clicks
440 * notification message is still WM_L/M/RBUTTONDOWN.
442 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
444 /* Activate the window if needed */
446 if (msg->hwnd != GetActiveWindow() && hwndTop != GetDesktopWindow())
448 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, hwndTop,
449 MAKELONG( hittest, raw_message ) );
453 case MA_NOACTIVATEANDEAT:
458 case MA_ACTIVATEANDEAT:
462 if (hwndTop != GetForegroundWindow() )
464 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
469 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
475 /* send the WM_SETCURSOR message */
477 /* Windows sends the normal mouse message as the message parameter
478 in the WM_SETCURSOR message even if it's non-client mouse message */
479 SendMessageA( msg->hwnd, WM_SETCURSOR, msg->hwnd, MAKELONG( hittest, raw_message ));
485 /***********************************************************************
486 * process_hardware_message
488 * returns TRUE if the contents of 'msg' should be passed to the application
490 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
491 UINT first, UINT last, BOOL remove )
493 if (is_keyboard_message( msg->message ))
495 if (!process_raw_keyboard_message( msg, extra_info )) return FALSE;
497 else if (is_mouse_message( msg->message ))
499 if (!process_raw_mouse_message( msg, extra_info )) return FALSE;
503 ERR( "unknown message type %x\n", msg->message );
507 /* check destination thread and filters */
508 if (!check_message_filter( msg, hwnd_filter, first, last ) ||
509 GetWindowThreadProcessId( msg->hwnd, NULL ) != GetCurrentThreadId())
511 /* queue it for later, or for another thread */
512 queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
516 /* save the message in the cooked queue if we didn't want to remove it */
517 if (!remove) queue_hardware_message( msg, extra_info, MSG_HARDWARE_COOKED );
522 /***********************************************************************
523 * MSG_process_cooked_hardware_message
525 * returns TRUE if the contents of 'msg' should be passed to the application
527 BOOL MSG_process_cooked_hardware_message( MSG *msg, BOOL remove )
529 if (is_keyboard_message( msg->message ))
530 return process_cooked_keyboard_message( msg, remove );
532 if (is_mouse_message( msg->message ))
533 return process_cooked_mouse_message( msg, remove );
535 ERR( "unknown message type %x\n", msg->message );
540 /**********************************************************************
541 * SetDoubleClickTime (USER32.@)
543 BOOL WINAPI SetDoubleClickTime( UINT interval )
545 doubleClickSpeed = interval ? interval : 500;
550 /**********************************************************************
551 * GetDoubleClickTime (USER32.@)
553 UINT WINAPI GetDoubleClickTime(void)
555 return doubleClickSpeed;
559 /***********************************************************************
560 * WaitMessage (USER.112) Suspend thread pending messages
561 * WaitMessage (USER32.@) Suspend thread pending messages
563 * WaitMessage() suspends a thread until events appear in the thread's
566 BOOL WINAPI WaitMessage(void)
568 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
572 /***********************************************************************
573 * MsgWaitForMultipleObjectsEx (USER32.@)
575 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
576 DWORD timeout, DWORD mask, DWORD flags )
578 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
580 MESSAGEQUEUE *msgQueue;
582 if (count > MAXIMUM_WAIT_OBJECTS-1)
584 SetLastError( ERROR_INVALID_PARAMETER );
588 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
590 /* set the queue mask */
591 SERVER_START_REQ( set_queue_mask )
593 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
594 req->changed_mask = mask;
600 /* Add the thread event to the handle list */
601 for (i = 0; i < count; i++) handles[i] = pHandles[i];
602 handles[count] = msgQueue->server_queue;
605 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
607 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
608 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
611 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
612 timeout, flags & MWMO_ALERTABLE );
617 /***********************************************************************
618 * MsgWaitForMultipleObjects (USER32.@)
620 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
621 BOOL wait_all, DWORD timeout, DWORD mask )
623 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
624 wait_all ? MWMO_WAITALL : 0 );
628 /***********************************************************************
629 * WaitForInputIdle (USER32.@)
631 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
634 HANDLE idle_event = -1;
636 SERVER_START_REQ( wait_input_idle )
638 req->handle = hProcess;
639 req->timeout = dwTimeOut;
640 if (!(ret = SERVER_CALL_ERR())) idle_event = req->event;
643 if (ret) return 0xffffffff; /* error */
644 if (!idle_event) return 0; /* no event to wait on */
646 cur_time = GetTickCount();
648 TRACE("waiting for %x\n", idle_event );
649 while ( dwTimeOut > GetTickCount() - cur_time || dwTimeOut == INFINITE )
651 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut, QS_SENDMESSAGE );
652 if ( ret == ( WAIT_OBJECT_0 + 1 ))
654 process_sent_messages();
657 if ( ret == WAIT_TIMEOUT || ret == 0xFFFFFFFF )
659 TRACE("timeout or error\n");
673 /***********************************************************************
674 * UserYield (USER.332)
675 * UserYield16 (USER32.@)
677 void WINAPI UserYield16(void)
681 /* Handle sent messages */
682 process_sent_messages();
685 ReleaseThunkLock(&count);
688 RestoreThunkLock(count);
689 /* Handle sent messages again */
690 process_sent_messages();
702 static const struct accent_char accent_chars[] =
704 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
705 {'`', 'A', '\300'}, {'`', 'a', '\340'},
706 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
707 {'^', 'A', '\302'}, {'^', 'a', '\342'},
708 {'~', 'A', '\303'}, {'~', 'a', '\343'},
709 {'"', 'A', '\304'}, {'"', 'a', '\344'},
710 {'O', 'A', '\305'}, {'o', 'a', '\345'},
711 {'0', 'A', '\305'}, {'0', 'a', '\345'},
712 {'A', 'A', '\305'}, {'a', 'a', '\345'},
713 {'A', 'E', '\306'}, {'a', 'e', '\346'},
714 {',', 'C', '\307'}, {',', 'c', '\347'},
715 {'`', 'E', '\310'}, {'`', 'e', '\350'},
716 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
717 {'^', 'E', '\312'}, {'^', 'e', '\352'},
718 {'"', 'E', '\313'}, {'"', 'e', '\353'},
719 {'`', 'I', '\314'}, {'`', 'i', '\354'},
720 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
721 {'^', 'I', '\316'}, {'^', 'i', '\356'},
722 {'"', 'I', '\317'}, {'"', 'i', '\357'},
723 {'-', 'D', '\320'}, {'-', 'd', '\360'},
724 {'~', 'N', '\321'}, {'~', 'n', '\361'},
725 {'`', 'O', '\322'}, {'`', 'o', '\362'},
726 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
727 {'^', 'O', '\324'}, {'^', 'o', '\364'},
728 {'~', 'O', '\325'}, {'~', 'o', '\365'},
729 {'"', 'O', '\326'}, {'"', 'o', '\366'},
730 {'/', 'O', '\330'}, {'/', 'o', '\370'},
731 {'`', 'U', '\331'}, {'`', 'u', '\371'},
732 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
733 {'^', 'U', '\333'}, {'^', 'u', '\373'},
734 {'"', 'U', '\334'}, {'"', 'u', '\374'},
735 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
736 {'T', 'H', '\336'}, {'t', 'h', '\376'},
737 {'s', 's', '\337'}, {'"', 'y', '\377'},
738 {'s', 'z', '\337'}, {'i', 'j', '\377'},
739 /* iso-8859-2 uses this */
740 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
741 {'<', 'S', '\251'}, {'<', 's', '\271'},
742 {'<', 'T', '\253'}, {'<', 't', '\273'},
743 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
744 {'<', 'C', '\310'}, {'<', 'c', '\350'},
745 {'<', 'E', '\314'}, {'<', 'e', '\354'},
746 {'<', 'D', '\317'}, {'<', 'd', '\357'},
747 {'<', 'N', '\322'}, {'<', 'n', '\362'},
748 {'<', 'R', '\330'}, {'<', 'r', '\370'},
749 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
750 {';', 'E', '\312'}, {';', 'e', '\332'},
751 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
752 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
753 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
754 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
755 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
756 /* collision whith S, from iso-8859-9 !!! */
757 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
758 {',', 'T', '\336'}, {',', 't', '\376'},
759 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
760 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
761 {'/', 'D', '\320'}, {'/', 'd', '\360'},
762 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
763 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
764 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
765 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
766 /* iso-8859-3 uses this */
767 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
768 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
769 {'>', 'J', '\254'}, {'>', 'j', '\274'},
770 {'>', 'C', '\306'}, {'>', 'c', '\346'},
771 {'>', 'G', '\330'}, {'>', 'g', '\370'},
772 {'>', 'S', '\336'}, {'>', 's', '\376'},
773 /* collision whith G( from iso-8859-9 !!! */
774 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
775 {'(', 'U', '\335'}, {'(', 'u', '\375'},
776 /* collision whith I. from iso-8859-3 !!! */
777 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
778 {'.', 'C', '\305'}, {'.', 'c', '\345'},
779 {'.', 'G', '\325'}, {'.', 'g', '\365'},
780 /* iso-8859-4 uses this */
781 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
782 {',', 'L', '\246'}, {',', 'l', '\266'},
783 {',', 'G', '\253'}, {',', 'g', '\273'},
784 {',', 'N', '\321'}, {',', 'n', '\361'},
785 {',', 'K', '\323'}, {',', 'k', '\363'},
786 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
787 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
788 {'-', 'A', '\300'}, {'-', 'a', '\340'},
789 {'-', 'I', '\317'}, {'-', 'i', '\357'},
790 {'-', 'O', '\322'}, {'-', 'o', '\362'},
791 {'-', 'U', '\336'}, {'-', 'u', '\376'},
792 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
793 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
794 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
795 {';', 'U', '\331'}, {';', 'u', '\371'},
796 /* iso-8859-9 uses this */
797 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
798 * whith the same letters on other iso-8859-x (that is they are on
799 * different places :-( ), if you use turkish uncomment these and
800 * comment out the lines in iso-8859-2 and iso-8859-3 sections
801 * FIXME: should be dynamic according to chosen language
802 * if/when Wine has turkish support.
804 /* collision whith G( from iso-8859-3 !!! */
805 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
806 /* collision whith S, from iso-8859-2 !!! */
807 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
808 /* collision whith I. from iso-8859-3 !!! */
809 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
813 /***********************************************************************
814 * TranslateMessage (USER32.@)
816 * Implementation of TranslateMessage.
818 * TranslateMessage translates virtual-key messages into character-messages,
820 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
821 * ditto replacing WM_* with WM_SYS*
822 * This produces WM_CHAR messages only for keys mapped to ASCII characters
823 * by the keyboard driver.
825 BOOL WINAPI TranslateMessage( const MSG *msg )
827 static int dead_char;
831 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
832 TRACE_(key)("(%s, %04X, %08lX)\n",
833 SPY_GetMsgName(msg->message), msg->wParam, msg->lParam );
835 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return FALSE;
837 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
838 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
840 /* FIXME : should handle ToUnicode yielding 2 */
841 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), QueueKeyStateTable, wp, 2, 0))
844 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
845 /* Should dead chars handling go in ToAscii ? */
850 if (wp[0] == ' ') wp[0] = dead_char;
851 if (dead_char == 0xa2) dead_char = '(';
852 else if (dead_char == 0xa8) dead_char = '"';
853 else if (dead_char == 0xb2) dead_char = ';';
854 else if (dead_char == 0xb4) dead_char = '\'';
855 else if (dead_char == 0xb7) dead_char = '<';
856 else if (dead_char == 0xb8) dead_char = ',';
857 else if (dead_char == 0xff) dead_char = '.';
858 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
859 if ((accent_chars[i].ac_accent == dead_char) &&
860 (accent_chars[i].ac_char == wp[0]))
862 wp[0] = accent_chars[i].ac_result;
867 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
868 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
872 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
874 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
875 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
882 /***********************************************************************
883 * DispatchMessageA (USER32.@)
885 LONG WINAPI DispatchMessageA( const MSG* msg )
891 /* Process timer messages */
892 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
896 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
898 /* before calling window proc, verify whether timer is still valid;
899 there's a slim chance that the application kills the timer
900 between GetMessage and DispatchMessage API calls */
901 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
902 return 0; /* invalid winproc */
904 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
905 msg->message, msg->wParam, GetTickCount() );
909 if (!msg->hwnd) return 0;
910 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
911 if (!wndPtr->winproc)
916 painting = (msg->message == WM_PAINT);
917 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
918 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
920 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
921 msg->wParam, msg->lParam );
922 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
923 msg->hwnd, msg->message,
924 msg->wParam, msg->lParam );
925 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
926 msg->wParam, msg->lParam );
928 WIN_ReleaseWndPtr(wndPtr);
929 wndPtr = WIN_FindWndPtr(msg->hwnd);
931 if (painting && wndPtr &&
932 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
934 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
936 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
937 /* Validate the update region to avoid infinite WM_PAINT loop */
938 RedrawWindow( wndPtr->hwndSelf, NULL, 0,
939 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
942 WIN_ReleaseWndPtr(wndPtr);
947 /***********************************************************************
948 * DispatchMessageW (USER32.@) Process Message
950 * Process the message specified in the structure *_msg_.
952 * If the lpMsg parameter points to a WM_TIMER message and the
953 * parameter of the WM_TIMER message is not NULL, the lParam parameter
954 * points to the function that is called instead of the window
957 * The message must be valid.
961 * DispatchMessage() returns the result of the window procedure invoked.
968 LONG WINAPI DispatchMessageW( const MSG* msg )
974 /* Process timer messages */
975 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
979 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
981 /* before calling window proc, verify whether timer is still valid;
982 there's a slim chance that the application kills the timer
983 between GetMessage and DispatchMessage API calls */
984 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
985 return 0; /* invalid winproc */
987 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
988 msg->message, msg->wParam, GetTickCount() );
992 if (!msg->hwnd) return 0;
993 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
994 if (!wndPtr->winproc)
999 painting = (msg->message == WM_PAINT);
1000 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1001 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1003 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1004 msg->wParam, msg->lParam );
1005 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1006 msg->hwnd, msg->message,
1007 msg->wParam, msg->lParam );
1008 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1009 msg->wParam, msg->lParam );
1011 WIN_ReleaseWndPtr(wndPtr);
1012 wndPtr = WIN_FindWndPtr(msg->hwnd);
1014 if (painting && wndPtr &&
1015 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1017 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1019 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1020 /* Validate the update region to avoid infinite WM_PAINT loop */
1021 RedrawWindow( wndPtr->hwndSelf, NULL, 0,
1022 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1025 WIN_ReleaseWndPtr(wndPtr);
1030 /***********************************************************************
1031 * RegisterWindowMessage (USER.118)
1032 * RegisterWindowMessageA (USER32.@)
1034 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1036 TRACE("%s\n", str );
1037 return GlobalAddAtomA( str );
1041 /***********************************************************************
1042 * RegisterWindowMessageW (USER32.@)
1044 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1046 TRACE("%p\n", str );
1047 return GlobalAddAtomW( str );
1051 /***********************************************************************
1052 * BroadcastSystemMessage (USER32.@)
1054 LONG WINAPI BroadcastSystemMessage(
1055 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1058 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1059 dwFlags,*recipients,uMessage,wParam,lParam