Support default output name (a.out); some configure scripts check for
[wine/multimedia.git] / windows / message.c
blob8527cf95f483d6cbe4e4566e4dd9394de41915eb
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
28 #endif
29 #include <sys/types.h>
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "message.h"
35 #include "winerror.h"
36 #include "wine/server.h"
37 #include "controls.h"
38 #include "dde.h"
39 #include "heap.h"
40 #include "message.h"
41 #include "thread.h"
42 #include "user.h"
43 #include "win.h"
44 #include "winpos.h"
45 #include "winproc.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg);
49 WINE_DECLARE_DEBUG_CHANNEL(key);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
55 /***********************************************************************
56 * is_keyboard_message
58 inline static BOOL is_keyboard_message( UINT message )
60 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
64 /***********************************************************************
65 * is_mouse_message
67 inline static BOOL is_mouse_message( UINT message )
69 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
70 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
74 /***********************************************************************
75 * check_message_filter
77 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
79 if (hwnd)
81 if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
83 if (first || last)
85 return (msg->message >= first && msg->message <= last);
87 return TRUE;
91 /***********************************************************************
92 * process_sent_messages
94 * Process all pending sent messages.
96 inline static void process_sent_messages(void)
98 MSG msg;
99 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
103 /***********************************************************************
104 * queue_hardware_message
106 * store a hardware message in the thread queue
108 #if 0
109 static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info )
111 SERVER_START_REQ( send_message )
113 req->type = MSG_HARDWARE;
114 req->id = GetWindowThreadProcessId( msg->hwnd, NULL );
115 req->win = msg->hwnd;
116 req->msg = msg->message;
117 req->wparam = msg->wParam;
118 req->lparam = msg->lParam;
119 req->x = msg->pt.x;
120 req->y = msg->pt.y;
121 req->time = msg->time;
122 req->info = extra_info;
123 req->timeout = 0;
124 wine_server_call( req );
126 SERVER_END_REQ;
128 #endif
131 /***********************************************************************
132 * MSG_SendParentNotify
134 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
135 * the window has the WS_EX_NOPARENTNOTIFY style.
137 static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt )
139 /* pt has to be in the client coordinates of the parent window */
140 MapWindowPoints( 0, hwnd, &pt, 1 );
141 for (;;)
143 HWND parent;
145 if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break;
146 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
147 if (!(parent = GetParent(hwnd))) break;
148 MapWindowPoints( hwnd, parent, &pt, 1 );
149 hwnd = parent;
150 SendMessageA( hwnd, WM_PARENTNOTIFY,
151 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
156 #if 0 /* this is broken for now, will require proper support in the server */
158 /***********************************************************************
159 * MSG_JournalPlayBackMsg
161 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
163 void MSG_JournalPlayBackMsg(void)
165 EVENTMSG tmpMsg;
166 MSG msg;
167 LRESULT wtime;
168 int keyDown,i;
170 wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE );
171 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
172 if (wtime<=0)
174 wtime=0;
175 msg.message = tmpMsg.message;
176 msg.hwnd = tmpMsg.hwnd;
177 msg.time = tmpMsg.time;
178 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
180 msg.wParam = tmpMsg.paramL & 0xFF;
181 msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
182 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
184 for (keyDown=i=0; i<256 && !keyDown; i++)
185 if (InputKeyStateTable[i] & 0x80)
186 keyDown++;
187 if (!keyDown)
188 msg.lParam |= 0x40000000;
189 InputKeyStateTable[msg.wParam] |= 0x80;
190 AsyncKeyStateTable[msg.wParam] |= 0x80;
192 else /* WM_KEYUP, WM_SYSKEYUP */
194 msg.lParam |= 0xC0000000;
195 InputKeyStateTable[msg.wParam] &= ~0x80;
197 if (InputKeyStateTable[VK_MENU] & 0x80)
198 msg.lParam |= 0x20000000;
199 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
200 msg.lParam |= 0x01000000;
202 msg.pt.x = msg.pt.y = 0;
203 queue_hardware_message( &msg, 0 );
205 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
207 switch (tmpMsg.message)
209 case WM_LBUTTONDOWN:
210 InputKeyStateTable[VK_LBUTTON] |= 0x80;
211 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
212 break;
213 case WM_LBUTTONUP:
214 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
215 break;
216 case WM_MBUTTONDOWN:
217 InputKeyStateTable[VK_MBUTTON] |= 0x80;
218 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
219 break;
220 case WM_MBUTTONUP:
221 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
222 break;
223 case WM_RBUTTONDOWN:
224 InputKeyStateTable[VK_RBUTTON] |= 0x80;
225 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
226 break;
227 case WM_RBUTTONUP:
228 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
229 break;
231 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
232 msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
233 msg.wParam=0;
234 if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON;
235 if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON;
236 if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON;
238 msg.pt.x = tmpMsg.paramL;
239 msg.pt.y = tmpMsg.paramH;
240 queue_hardware_message( &msg, 0 );
242 HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE );
244 else
246 if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE );
249 #endif
252 /***********************************************************************
253 * process_raw_keyboard_message
255 * returns TRUE if the contents of 'msg' should be passed to the application
257 static void process_raw_keyboard_message( MSG *msg )
259 EVENTMSG event;
261 event.message = msg->message;
262 event.hwnd = msg->hwnd;
263 event.time = msg->time;
264 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
265 event.paramH = msg->lParam & 0x7FFF;
266 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
267 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
271 /***********************************************************************
272 * process_cooked_keyboard_message
274 * returns TRUE if the contents of 'msg' should be passed to the application
276 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
278 if (remove)
280 /* Handle F1 key by sending out WM_HELP message */
281 if ((msg->message == WM_KEYUP) &&
282 (msg->wParam == VK_F1) &&
283 (msg->hwnd != GetDesktopWindow()) &&
284 !MENU_IsMenuActive())
286 HELPINFO hi;
287 hi.cbSize = sizeof(HELPINFO);
288 hi.iContextType = HELPINFO_WINDOW;
289 hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID );
290 hi.hItemHandle = msg->hwnd;
291 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
292 hi.MousePos = msg->pt;
293 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
297 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
298 LOWORD(msg->wParam), msg->lParam, TRUE ))
300 /* skip this message */
301 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
302 return FALSE;
304 return TRUE;
308 /***********************************************************************
309 * process_raw_mouse_message
311 static void process_raw_mouse_message( MSG *msg, BOOL remove )
313 static MSG clk_msg;
315 POINT pt;
316 INT hittest;
317 EVENTMSG event;
318 GUITHREADINFO info;
319 HWND hWndScope = msg->hwnd;
321 /* find the window to dispatch this mouse message to */
323 hittest = HTCLIENT;
324 GetGUIThreadInfo( GetCurrentThreadId(), &info );
325 if (!(msg->hwnd = info.hwndCapture))
327 /* If no capture HWND, find window which contains the mouse position.
328 * Also find the position of the cursor hot spot (hittest) */
329 if (!IsWindow(hWndScope)) hWndScope = 0;
330 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
331 msg->hwnd = GetDesktopWindow();
334 event.message = msg->message;
335 event.time = msg->time;
336 event.hwnd = msg->hwnd;
337 event.paramL = msg->pt.x;
338 event.paramH = msg->pt.y;
339 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
341 /* translate double clicks */
343 if ((msg->message == WM_LBUTTONDOWN) ||
344 (msg->message == WM_RBUTTONDOWN) ||
345 (msg->message == WM_MBUTTONDOWN))
347 BOOL update = remove;
348 /* translate double clicks -
349 * note that ...MOUSEMOVEs can slip in between
350 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
352 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
353 hittest != HTCLIENT ||
354 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
356 if ((msg->message == clk_msg.message) &&
357 (msg->hwnd == clk_msg.hwnd) &&
358 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
359 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
360 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
362 msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
363 if (remove)
365 clk_msg.message = 0;
366 update = FALSE;
370 /* update static double click conditions */
371 if (update) clk_msg = *msg;
374 pt = msg->pt;
375 /* Note: windows has no concept of a non-client wheel message */
376 if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL)
378 msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
379 msg->wParam = hittest;
381 else
383 /* coordinates don't get translated while tracking a menu */
384 /* FIXME: should differentiate popups and top-level menus */
385 if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt );
387 msg->lParam = MAKELONG( pt.x, pt.y );
391 /***********************************************************************
392 * process_cooked_mouse_message
394 * returns TRUE if the contents of 'msg' should be passed to the application
396 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
398 MOUSEHOOKSTRUCT hook;
399 INT hittest = HTCLIENT;
400 UINT raw_message = msg->message;
401 BOOL eatMsg;
403 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
405 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
406 hittest = msg->wParam;
408 if (raw_message == WM_LBUTTONDBLCLK ||
409 raw_message == WM_RBUTTONDBLCLK ||
410 raw_message == WM_MBUTTONDBLCLK)
412 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
415 hook.pt = msg->pt;
416 hook.hwnd = msg->hwnd;
417 hook.wHitTestCode = hittest;
418 hook.dwExtraInfo = extra_info;
419 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
420 msg->message, (LPARAM)&hook, TRUE ))
422 hook.pt = msg->pt;
423 hook.hwnd = msg->hwnd;
424 hook.wHitTestCode = hittest;
425 hook.dwExtraInfo = extra_info;
426 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
427 return FALSE;
430 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
432 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
433 MAKELONG( hittest, raw_message ));
434 return FALSE;
437 if (!remove || GetCapture()) return TRUE;
439 eatMsg = FALSE;
441 if ((raw_message == WM_LBUTTONDOWN) ||
442 (raw_message == WM_RBUTTONDOWN) ||
443 (raw_message == WM_MBUTTONDOWN))
445 /* Send the WM_PARENTNOTIFY,
446 * note that even for double/nonclient clicks
447 * notification message is still WM_L/M/RBUTTONDOWN.
449 MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt );
451 /* Activate the window if needed */
453 if (msg->hwnd != GetActiveWindow())
455 HWND hwndTop = msg->hwnd;
456 while (hwndTop)
458 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
459 hwndTop = GetParent( hwndTop );
462 if (hwndTop && hwndTop != GetDesktopWindow())
464 LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
465 MAKELONG( hittest, raw_message ) );
466 switch(ret)
468 case MA_NOACTIVATEANDEAT:
469 eatMsg = TRUE;
470 /* fall through */
471 case MA_NOACTIVATE:
472 break;
473 case MA_ACTIVATEANDEAT:
474 eatMsg = TRUE;
475 /* fall through */
476 case MA_ACTIVATE:
477 case 0:
478 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
479 break;
480 default:
481 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
482 break;
488 /* send the WM_SETCURSOR message */
490 /* Windows sends the normal mouse message as the message parameter
491 in the WM_SETCURSOR message even if it's non-client mouse message */
492 SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
493 MAKELONG( hittest, raw_message ));
495 return !eatMsg;
499 /***********************************************************************
500 * process_hardware_message
502 * returns TRUE if the contents of 'msg' should be passed to the application
504 BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter,
505 UINT first, UINT last, BOOL remove )
507 if (is_keyboard_message( msg->message ))
509 process_raw_keyboard_message( msg );
511 else if (is_mouse_message( msg->message ))
513 process_raw_mouse_message( msg, remove );
515 else
517 ERR( "unknown message type %x\n", msg->message );
518 return FALSE;
520 return check_message_filter( msg, hwnd_filter, first, last );
524 /***********************************************************************
525 * MSG_process_cooked_hardware_message
527 * returns TRUE if the contents of 'msg' should be passed to the application
529 BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
531 if (is_keyboard_message( msg->message ))
532 return process_cooked_keyboard_message( msg, remove );
534 if (is_mouse_message( msg->message ))
535 return process_cooked_mouse_message( msg, extra_info, remove );
537 ERR( "unknown message type %x\n", msg->message );
538 return FALSE;
542 /***********************************************************************
543 * WaitMessage (USER.112) Suspend thread pending messages
544 * WaitMessage (USER32.@) Suspend thread pending messages
546 * WaitMessage() suspends a thread until events appear in the thread's
547 * queue.
549 BOOL WINAPI WaitMessage(void)
551 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
555 /***********************************************************************
556 * MsgWaitForMultipleObjectsEx (USER32.@)
558 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
559 DWORD timeout, DWORD mask, DWORD flags )
561 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
562 DWORD i, ret, lock;
563 MESSAGEQUEUE *msgQueue;
565 if (count > MAXIMUM_WAIT_OBJECTS-1)
567 SetLastError( ERROR_INVALID_PARAMETER );
568 return WAIT_FAILED;
571 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
573 /* set the queue mask */
574 SERVER_START_REQ( set_queue_mask )
576 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
577 req->changed_mask = mask;
578 req->skip_wait = 0;
579 wine_server_call( req );
581 SERVER_END_REQ;
583 /* Add the thread event to the handle list */
584 for (i = 0; i < count; i++) handles[i] = pHandles[i];
585 handles[count] = msgQueue->server_queue;
587 ReleaseThunkLock( &lock );
588 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
590 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
591 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
593 else
594 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
595 timeout, flags & MWMO_ALERTABLE );
596 if (lock) RestoreThunkLock( lock );
597 return ret;
601 /***********************************************************************
602 * MsgWaitForMultipleObjects (USER32.@)
604 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
605 BOOL wait_all, DWORD timeout, DWORD mask )
607 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
608 wait_all ? MWMO_WAITALL : 0 );
612 /***********************************************************************
613 * WaitForInputIdle (USER32.@)
615 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
617 DWORD start_time, elapsed, ret;
618 HANDLE idle_event = (HANDLE)-1;
620 SERVER_START_REQ( wait_input_idle )
622 req->handle = hProcess;
623 req->timeout = dwTimeOut;
624 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
626 SERVER_END_REQ;
627 if (ret) return WAIT_FAILED; /* error */
628 if (!idle_event) return 0; /* no event to wait on */
630 start_time = GetTickCount();
631 elapsed = 0;
633 TRACE("waiting for %p\n", idle_event );
636 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
637 switch (ret)
639 case WAIT_OBJECT_0+1:
640 process_sent_messages();
641 break;
642 case WAIT_TIMEOUT:
643 case WAIT_FAILED:
644 TRACE("timeout or error\n");
645 return ret;
646 default:
647 TRACE("finished\n");
648 return 0;
650 if (dwTimeOut != INFINITE)
652 elapsed = GetTickCount() - start_time;
653 if (elapsed > dwTimeOut)
654 break;
657 while (1);
659 return WAIT_TIMEOUT;
663 /***********************************************************************
664 * UserYield (USER.332)
666 void WINAPI UserYield16(void)
668 DWORD count;
670 /* Handle sent messages */
671 process_sent_messages();
673 /* Yield */
674 ReleaseThunkLock(&count);
675 if (count)
677 RestoreThunkLock(count);
678 /* Handle sent messages again */
679 process_sent_messages();
684 struct accent_char
686 BYTE ac_accent;
687 BYTE ac_char;
688 BYTE ac_result;
691 static const struct accent_char accent_chars[] =
693 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
694 {'`', 'A', '\300'}, {'`', 'a', '\340'},
695 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
696 {'^', 'A', '\302'}, {'^', 'a', '\342'},
697 {'~', 'A', '\303'}, {'~', 'a', '\343'},
698 {'"', 'A', '\304'}, {'"', 'a', '\344'},
699 {'O', 'A', '\305'}, {'o', 'a', '\345'},
700 {'0', 'A', '\305'}, {'0', 'a', '\345'},
701 {'A', 'A', '\305'}, {'a', 'a', '\345'},
702 {'A', 'E', '\306'}, {'a', 'e', '\346'},
703 {',', 'C', '\307'}, {',', 'c', '\347'},
704 {'`', 'E', '\310'}, {'`', 'e', '\350'},
705 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
706 {'^', 'E', '\312'}, {'^', 'e', '\352'},
707 {'"', 'E', '\313'}, {'"', 'e', '\353'},
708 {'`', 'I', '\314'}, {'`', 'i', '\354'},
709 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
710 {'^', 'I', '\316'}, {'^', 'i', '\356'},
711 {'"', 'I', '\317'}, {'"', 'i', '\357'},
712 {'-', 'D', '\320'}, {'-', 'd', '\360'},
713 {'~', 'N', '\321'}, {'~', 'n', '\361'},
714 {'`', 'O', '\322'}, {'`', 'o', '\362'},
715 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
716 {'^', 'O', '\324'}, {'^', 'o', '\364'},
717 {'~', 'O', '\325'}, {'~', 'o', '\365'},
718 {'"', 'O', '\326'}, {'"', 'o', '\366'},
719 {'/', 'O', '\330'}, {'/', 'o', '\370'},
720 {'`', 'U', '\331'}, {'`', 'u', '\371'},
721 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
722 {'^', 'U', '\333'}, {'^', 'u', '\373'},
723 {'"', 'U', '\334'}, {'"', 'u', '\374'},
724 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
725 {'T', 'H', '\336'}, {'t', 'h', '\376'},
726 {'s', 's', '\337'}, {'"', 'y', '\377'},
727 {'s', 'z', '\337'}, {'i', 'j', '\377'},
728 /* iso-8859-2 uses this */
729 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
730 {'<', 'S', '\251'}, {'<', 's', '\271'},
731 {'<', 'T', '\253'}, {'<', 't', '\273'},
732 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
733 {'<', 'C', '\310'}, {'<', 'c', '\350'},
734 {'<', 'E', '\314'}, {'<', 'e', '\354'},
735 {'<', 'D', '\317'}, {'<', 'd', '\357'},
736 {'<', 'N', '\322'}, {'<', 'n', '\362'},
737 {'<', 'R', '\330'}, {'<', 'r', '\370'},
738 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
739 {';', 'E', '\312'}, {';', 'e', '\332'},
740 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
741 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
742 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
743 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
744 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
745 /* collision whith S, from iso-8859-9 !!! */
746 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
747 {',', 'T', '\336'}, {',', 't', '\376'},
748 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
749 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
750 {'/', 'D', '\320'}, {'/', 'd', '\360'},
751 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
752 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
753 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
754 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
755 /* iso-8859-3 uses this */
756 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
757 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
758 {'>', 'J', '\254'}, {'>', 'j', '\274'},
759 {'>', 'C', '\306'}, {'>', 'c', '\346'},
760 {'>', 'G', '\330'}, {'>', 'g', '\370'},
761 {'>', 'S', '\336'}, {'>', 's', '\376'},
762 /* collision whith G( from iso-8859-9 !!! */
763 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
764 {'(', 'U', '\335'}, {'(', 'u', '\375'},
765 /* collision whith I. from iso-8859-3 !!! */
766 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
767 {'.', 'C', '\305'}, {'.', 'c', '\345'},
768 {'.', 'G', '\325'}, {'.', 'g', '\365'},
769 /* iso-8859-4 uses this */
770 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
771 {',', 'L', '\246'}, {',', 'l', '\266'},
772 {',', 'G', '\253'}, {',', 'g', '\273'},
773 {',', 'N', '\321'}, {',', 'n', '\361'},
774 {',', 'K', '\323'}, {',', 'k', '\363'},
775 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
776 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
777 {'-', 'A', '\300'}, {'-', 'a', '\340'},
778 {'-', 'I', '\317'}, {'-', 'i', '\357'},
779 {'-', 'O', '\322'}, {'-', 'o', '\362'},
780 {'-', 'U', '\336'}, {'-', 'u', '\376'},
781 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
782 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
783 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
784 {';', 'U', '\331'}, {';', 'u', '\371'},
785 /* iso-8859-9 uses this */
786 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
787 * whith the same letters on other iso-8859-x (that is they are on
788 * different places :-( ), if you use turkish uncomment these and
789 * comment out the lines in iso-8859-2 and iso-8859-3 sections
790 * FIXME: should be dynamic according to chosen language
791 * if/when Wine has turkish support.
793 /* collision whith G( from iso-8859-3 !!! */
794 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
795 /* collision whith S, from iso-8859-2 !!! */
796 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
797 /* collision whith I. from iso-8859-3 !!! */
798 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
802 /***********************************************************************
803 * TranslateMessage (USER32.@)
805 * Implementation of TranslateMessage.
807 * TranslateMessage translates virtual-key messages into character-messages,
808 * as follows :
809 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
810 * ditto replacing WM_* with WM_SYS*
811 * This produces WM_CHAR messages only for keys mapped to ASCII characters
812 * by the keyboard driver.
814 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
815 * return value is nonzero, regardless of the translation.
818 BOOL WINAPI TranslateMessage( const MSG *msg )
820 static int dead_char;
821 UINT message;
822 WCHAR wp[2];
823 BOOL rc = FALSE;
824 BYTE state[256];
826 if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST)
828 TRACE_(key)("(%s, %04X, %08lX)\n",
829 SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam );
831 /* Return code must be TRUE no matter what! */
832 rc = TRUE;
835 if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc;
837 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
838 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
840 GetKeyboardState( state );
841 /* FIXME : should handle ToUnicode yielding 2 */
842 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
844 case 1:
845 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
846 /* Should dead chars handling go in ToAscii ? */
847 if (dead_char)
849 int i;
851 if (wp[0] == ' ') wp[0] = dead_char;
852 if (dead_char == 0xa2) dead_char = '(';
853 else if (dead_char == 0xa8) dead_char = '"';
854 else if (dead_char == 0xb2) dead_char = ';';
855 else if (dead_char == 0xb4) dead_char = '\'';
856 else if (dead_char == 0xb7) dead_char = '<';
857 else if (dead_char == 0xb8) dead_char = ',';
858 else if (dead_char == 0xff) dead_char = '.';
859 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
860 if ((accent_chars[i].ac_accent == dead_char) &&
861 (accent_chars[i].ac_char == wp[0]))
863 wp[0] = accent_chars[i].ac_result;
864 break;
866 dead_char = 0;
868 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
869 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
870 break;
872 case -1:
873 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
874 dead_char = wp[0];
875 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message, msg->hwnd));
876 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
877 return TRUE;
879 return rc;
883 /***********************************************************************
884 * DispatchMessageA (USER32.@)
886 LONG WINAPI DispatchMessageA( const MSG* msg )
888 WND * wndPtr;
889 LONG retval;
890 int painting;
891 WNDPROC winproc;
893 /* Process timer messages */
894 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
896 if (msg->lParam)
898 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
900 /* before calling window proc, verify whether timer is still valid;
901 there's a slim chance that the application kills the timer
902 between GetMessage and DispatchMessage API calls */
903 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
904 return 0; /* invalid winproc */
906 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
907 msg->message, msg->wParam, GetTickCount() );
911 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
913 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
914 return 0;
916 if (wndPtr == WND_OTHER_PROCESS)
918 if (IsWindow( msg->hwnd ))
919 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
920 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
921 return 0;
923 if (!(winproc = wndPtr->winproc))
925 WIN_ReleasePtr( wndPtr );
926 return 0;
928 painting = (msg->message == WM_PAINT);
929 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
930 WIN_ReleasePtr( wndPtr );
931 /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
933 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
934 msg->wParam, msg->lParam );
935 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
936 msg->wParam, msg->lParam );
937 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
938 msg->wParam, msg->lParam );
940 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
942 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
943 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
944 WIN_ReleasePtr( wndPtr );
945 if (validate)
947 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
948 /* Validate the update region to avoid infinite WM_PAINT loop */
949 RedrawWindow( msg->hwnd, NULL, 0,
950 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
953 return retval;
957 /***********************************************************************
958 * DispatchMessageW (USER32.@) Process Message
960 * Process the message specified in the structure *_msg_.
962 * If the lpMsg parameter points to a WM_TIMER message and the
963 * parameter of the WM_TIMER message is not NULL, the lParam parameter
964 * points to the function that is called instead of the window
965 * procedure.
967 * The message must be valid.
969 * RETURNS
971 * DispatchMessage() returns the result of the window procedure invoked.
973 * CONFORMANCE
975 * ECMA-234, Win32
978 LONG WINAPI DispatchMessageW( const MSG* msg )
980 WND * wndPtr;
981 LONG retval;
982 int painting;
983 WNDPROC winproc;
985 /* Process timer messages */
986 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
988 if (msg->lParam)
990 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
992 /* before calling window proc, verify whether timer is still valid;
993 there's a slim chance that the application kills the timer
994 between GetMessage and DispatchMessage API calls */
995 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
996 return 0; /* invalid winproc */
998 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
999 msg->message, msg->wParam, GetTickCount() );
1003 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
1005 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1006 return 0;
1008 if (wndPtr == WND_OTHER_PROCESS)
1010 if (IsWindow( msg->hwnd ))
1011 ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd );
1012 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1013 return 0;
1015 if (!(winproc = wndPtr->winproc))
1017 WIN_ReleasePtr( wndPtr );
1018 return 0;
1020 painting = (msg->message == WM_PAINT);
1021 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1022 WIN_ReleasePtr( wndPtr );
1023 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1025 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
1026 msg->wParam, msg->lParam );
1027 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
1028 msg->wParam, msg->lParam );
1029 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
1030 msg->wParam, msg->lParam );
1032 if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS))
1034 BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate);
1035 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1036 WIN_ReleasePtr( wndPtr );
1037 if (validate)
1039 ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd );
1040 /* Validate the update region to avoid infinite WM_PAINT loop */
1041 RedrawWindow( msg->hwnd, NULL, 0,
1042 RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT );
1045 return retval;
1049 /***********************************************************************
1050 * RegisterWindowMessage (USER.118)
1051 * RegisterWindowMessageA (USER32.@)
1053 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
1055 TRACE("%s\n", str );
1056 return GlobalAddAtomA( str );
1060 /***********************************************************************
1061 * RegisterWindowMessageW (USER32.@)
1063 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
1065 TRACE("%p\n", str );
1066 return GlobalAddAtomW( str );
1070 /***********************************************************************
1071 * BroadcastSystemMessage (USER32.@)
1072 * BroadcastSystemMessageA (USER32.@)
1074 LONG WINAPI BroadcastSystemMessage(
1075 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
1076 LPARAM lParam )
1078 if ((*recipients & BSM_APPLICATIONS)||
1079 (*recipients == BSM_ALLCOMPONENTS))
1081 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n",
1082 dwFlags,*recipients,uMessage,wParam,lParam);
1083 PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam);
1084 return 1;
1086 else
1088 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1089 dwFlags,*recipients,uMessage,wParam,lParam);
1090 return -1;