Paper size and orientation prop sheet for wineps.
[wine.git] / windows / input.c
blobb8c6d4144a699db70f5576dbe998a80f7a87eb1d
1 /*
2 * USER Input processing
4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
12 #include <stdlib.h>
13 #include <string.h>
14 #include <stdio.h>
15 #include <ctype.h>
16 #include <assert.h>
18 #include "windef.h"
19 #include "wingdi.h"
20 #include "winuser.h"
21 #include "wine/winbase16.h"
22 #include "wine/winuser16.h"
23 #include "wine/keyboard16.h"
24 #include "win.h"
25 #include "heap.h"
26 #include "input.h"
27 #include "keyboard.h"
28 #include "mouse.h"
29 #include "message.h"
30 #include "queue.h"
31 #include "module.h"
32 #include "debugtools.h"
33 #include "struct32.h"
34 #include "winerror.h"
35 #include "task.h"
37 DECLARE_DEBUG_CHANNEL(accel);
38 DECLARE_DEBUG_CHANNEL(event);
39 DECLARE_DEBUG_CHANNEL(key);
40 DECLARE_DEBUG_CHANNEL(keyboard);
41 DECLARE_DEBUG_CHANNEL(win);
43 static BOOL InputEnabled = TRUE;
44 BOOL SwappedButtons = FALSE;
46 BOOL MouseButtonsStates[3];
47 BOOL AsyncMouseButtonsStates[3];
48 BYTE InputKeyStateTable[256];
49 BYTE QueueKeyStateTable[256];
50 BYTE AsyncKeyStateTable[256];
52 /* Storage for the USER-maintained mouse positions */
53 DWORD PosX, PosY;
55 typedef union
57 struct
59 unsigned long count : 16;
60 unsigned long code : 8;
61 unsigned long extended : 1;
62 unsigned long unused : 2;
63 unsigned long win_internal : 2;
64 unsigned long context : 1;
65 unsigned long previous : 1;
66 unsigned long transition : 1;
67 } lp1;
68 unsigned long lp2;
69 } KEYLP;
71 /***********************************************************************
72 * keybd_event (USER32.583)
74 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
75 DWORD dwFlags, DWORD dwExtraInfo )
77 DWORD time, extra;
78 WORD message;
79 KEYLP keylp;
80 keylp.lp2 = 0;
82 if (!InputEnabled) return;
85 * If we are called by the Wine keyboard driver, use the additional
86 * info pointed to by the dwExtraInfo argument.
87 * Otherwise, we need to determine that info ourselves (probably
88 * less accurate, but we can't help that ...).
90 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
91 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
93 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
94 time = wke->time;
95 extra = 0;
97 else
99 time = GetTickCount();
100 extra = dwExtraInfo;
104 keylp.lp1.count = 1;
105 keylp.lp1.code = bScan;
106 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
107 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
108 * don't remember where I read it - AK */
109 /* it's '1' under windows, when a dialog box appears
110 * and you press one of the underlined keys - DF*/
112 if ( dwFlags & KEYEVENTF_KEYUP )
114 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
115 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
116 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
118 InputKeyStateTable[bVk] &= ~0x80;
119 keylp.lp1.previous = 1;
120 keylp.lp1.transition = 1;
121 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
123 else
125 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
126 keylp.lp1.transition = 0;
128 if (!(InputKeyStateTable[bVk] & 0x80))
129 InputKeyStateTable[bVk] ^= 0x01;
130 InputKeyStateTable[bVk] |= 0x80;
132 message = (InputKeyStateTable[VK_MENU] & 0x80)
133 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
134 ? WM_SYSKEYDOWN : WM_KEYDOWN;
137 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
138 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
141 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
142 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
144 hardware_event( message, bVk, keylp.lp2, PosX, PosY, time, extra );
147 /***********************************************************************
148 * WIN16_keybd_event (USER.289)
150 void WINAPI WIN16_keybd_event( CONTEXT86 *context )
152 DWORD dwFlags = 0;
154 if (AH_reg(context) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
155 if (BH_reg(context) & 1 ) dwFlags |= KEYEVENTF_EXTENDEDKEY;
157 keybd_event( AL_reg(context), BL_reg(context),
158 dwFlags, MAKELONG(SI_reg(context), DI_reg(context)) );
161 /***********************************************************************
162 * mouse_event (USER32.584)
164 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
165 DWORD cButtons, DWORD dwExtraInfo )
167 DWORD time, extra;
168 DWORD keyState;
170 if (!InputEnabled) return;
172 if ( dwFlags & MOUSEEVENTF_MOVE )
174 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
176 PosX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
177 PosY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
179 else
181 int width = GetSystemMetrics(SM_CXSCREEN);
182 int height = GetSystemMetrics(SM_CYSCREEN);
183 long posX = (long) PosX, posY = (long) PosY;
185 /* dx and dy can be negative numbers for relative movements */
186 posX += (long) dx;
187 posY += (long) dy;
189 /* Clip to the current screen size */
190 if (posX < 0) PosX = 0;
191 else if (posX >= width) PosX = width - 1;
192 else PosX = posX;
194 if (posY < 0) PosY = 0;
195 else if (posY >= height) PosY = height - 1;
196 else PosY = posY;
201 * If we are called by the Wine mouse driver, use the additional
202 * info pointed to by the dwExtraInfo argument.
203 * Otherwise, we need to determine that info ourselves (probably
204 * less accurate, but we can't help that ...).
206 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
207 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
209 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
210 time = wme->time;
211 extra = (DWORD)wme->hWnd;
212 keyState = wme->keyState;
214 if (keyState != GET_KEYSTATE()) {
215 /* We need to update the keystate with what X provides us */
216 MouseButtonsStates[SwappedButtons ? 2 : 0] = (keyState & MK_LBUTTON ? TRUE : FALSE);
217 MouseButtonsStates[SwappedButtons ? 0 : 2] = (keyState & MK_RBUTTON ? TRUE : FALSE);
218 MouseButtonsStates[1] = (keyState & MK_MBUTTON ? TRUE : FALSE);
219 InputKeyStateTable[VK_SHIFT] = (keyState & MK_SHIFT ? 0x80 : 0);
220 InputKeyStateTable[VK_CONTROL] = (keyState & MK_CONTROL ? 0x80 : 0);
223 else
225 time = GetTickCount();
226 extra = dwExtraInfo;
227 keyState = GET_KEYSTATE();
229 if ( dwFlags & MOUSEEVENTF_MOVE )
231 /* We have to actually move the cursor */
232 SetCursorPos( PosX, PosY );
237 if ( dwFlags & MOUSEEVENTF_MOVE )
239 hardware_event( WM_MOUSEMOVE,
240 keyState, 0L, PosX, PosY, time, extra );
242 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
244 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
245 hardware_event( WM_LBUTTONDOWN,
246 keyState, 0L, PosX, PosY, time, extra );
248 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
250 MouseButtonsStates[0] = FALSE;
251 hardware_event( WM_LBUTTONUP,
252 keyState, 0L, PosX, PosY, time, extra );
254 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
256 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
257 hardware_event( WM_RBUTTONDOWN,
258 keyState, 0L, PosX, PosY, time, extra );
260 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
262 MouseButtonsStates[2] = FALSE;
263 hardware_event( WM_RBUTTONUP,
264 keyState, 0L, PosX, PosY, time, extra );
266 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
268 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
269 hardware_event( WM_MBUTTONDOWN,
270 keyState, 0L, PosX, PosY, time, extra );
272 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
274 MouseButtonsStates[1] = FALSE;
275 hardware_event( WM_MBUTTONUP,
276 keyState, 0L, PosX, PosY, time, extra );
278 if ( dwFlags & MOUSEEVENTF_WHEEL )
280 hardware_event( WM_MOUSEWHEEL,
281 keyState, 0L, PosX, PosY, time, extra );
285 /***********************************************************************
286 * WIN16_mouse_event (USER.299)
288 void WINAPI WIN16_mouse_event( CONTEXT86 *context )
290 mouse_event( AX_reg(context), BX_reg(context), CX_reg(context),
291 DX_reg(context), MAKELONG(SI_reg(context), DI_reg(context)) );
294 /***********************************************************************
295 * GetMouseEventProc (USER.337)
297 FARPROC16 WINAPI GetMouseEventProc16(void)
299 HMODULE16 hmodule = GetModuleHandle16("USER");
300 return NE_GetEntryPoint( hmodule, NE_GetOrdinal( hmodule, "mouse_event" ));
304 /**********************************************************************
305 * EnableHardwareInput (USER.331)
307 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
309 BOOL16 bOldState = InputEnabled;
310 FIXME_(event)("(%d) - stub\n", bEnable);
311 InputEnabled = bEnable;
312 return bOldState;
316 /***********************************************************************
317 * SwapMouseButton16 (USER.186)
319 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
321 BOOL16 ret = SwappedButtons;
322 SwappedButtons = fSwap;
323 return ret;
327 /***********************************************************************
328 * SwapMouseButton (USER32.537)
330 BOOL WINAPI SwapMouseButton( BOOL fSwap )
332 BOOL ret = SwappedButtons;
333 SwappedButtons = fSwap;
334 return ret;
337 /**********************************************************************
338 * EVENT_Capture
340 * We need this to be able to generate double click messages
341 * when menu code captures mouse in the window without CS_DBLCLK style.
343 HWND EVENT_Capture(HWND hwnd, INT16 ht)
345 HWND capturePrev = 0, captureWnd = 0;
346 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
347 WND* wndPtr = 0;
348 INT16 captureHT = 0;
350 /* Get the messageQ for the current thread */
351 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
353 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
354 goto CLEANUP;
357 /* Get the current capture window from the perQ data of the current message Q */
358 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
360 if (!hwnd)
362 captureWnd = 0L;
363 captureHT = 0;
365 else
367 wndPtr = WIN_FindWndPtr( hwnd );
368 if (wndPtr)
370 TRACE_(win)("(0x%04x)\n", hwnd );
371 captureWnd = hwnd;
372 captureHT = ht;
376 /* Update the perQ capture window and send messages */
377 if( capturePrev != captureWnd )
379 if (wndPtr)
381 /* Retrieve the message queue associated with this window */
382 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
383 if ( !pMsgQ )
385 WARN_(win)("\tMessage queue not found. Exiting!\n" );
386 goto CLEANUP;
389 /* Make sure that message queue for the window we are setting capture to
390 * shares the same perQ data as the current threads message queue.
392 if ( pCurMsgQ->pQData != pMsgQ->pQData )
393 goto CLEANUP;
396 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
397 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
399 if( capturePrev )
401 WND* xwndPtr = WIN_FindWndPtr( capturePrev );
402 if( xwndPtr && (xwndPtr->flags & WIN_ISWIN32) )
403 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
404 WIN_ReleaseWndPtr(xwndPtr);
408 CLEANUP:
409 /* Unlock the queues before returning */
410 if ( pMsgQ )
411 QUEUE_Unlock( pMsgQ );
412 if ( pCurMsgQ )
413 QUEUE_Unlock( pCurMsgQ );
415 WIN_ReleaseWndPtr(wndPtr);
416 return capturePrev;
420 /**********************************************************************
421 * SetCapture16 (USER.18)
423 HWND16 WINAPI SetCapture16( HWND16 hwnd )
425 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
429 /**********************************************************************
430 * SetCapture (USER32.464)
432 HWND WINAPI SetCapture( HWND hwnd )
434 return EVENT_Capture( hwnd, HTCLIENT );
438 /**********************************************************************
439 * ReleaseCapture (USER.19) (USER32.439)
441 BOOL WINAPI ReleaseCapture(void)
443 return (EVENT_Capture( 0, 0 ) != 0);
447 /**********************************************************************
448 * GetCapture16 (USER.236)
450 HWND16 WINAPI GetCapture16(void)
452 return (HWND16)GetCapture();
455 /**********************************************************************
456 * GetCapture (USER32.208)
458 HWND WINAPI GetCapture(void)
460 MESSAGEQUEUE *pCurMsgQ = 0;
461 HWND hwndCapture = 0;
463 /* Get the messageQ for the current thread */
464 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
466 TRACE_(win)("GetCapture: Current message queue not found. Exiting!\n" );
467 return 0;
470 /* Get the current capture window from the perQ data of the current message Q */
471 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
473 QUEUE_Unlock( pCurMsgQ );
474 return hwndCapture;
477 /**********************************************************************
478 * GetKeyState (USER.106)
480 INT16 WINAPI GetKeyState16(INT16 vkey)
482 return GetKeyState(vkey);
485 /**********************************************************************
486 * GetKeyState (USER32.249)
488 * An application calls the GetKeyState function in response to a
489 * keyboard-input message. This function retrieves the state of the key
490 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
492 SHORT WINAPI GetKeyState(INT vkey)
494 INT retval;
496 switch (vkey)
498 case VK_LBUTTON : /* VK_LBUTTON is 1 */
499 retval = MouseButtonsStates[0] ? 0x8000 : 0;
500 break;
501 case VK_MBUTTON : /* VK_MBUTTON is 4 */
502 retval = MouseButtonsStates[1] ? 0x8000 : 0;
503 break;
504 case VK_RBUTTON : /* VK_RBUTTON is 2 */
505 retval = MouseButtonsStates[2] ? 0x8000 : 0;
506 break;
507 default :
508 if (vkey >= 'a' && vkey <= 'z')
509 vkey += 'A' - 'a';
510 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
511 (WORD)(QueueKeyStateTable[vkey] & 0x01);
513 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
514 return retval;
517 /**********************************************************************
518 * GetKeyboardState (USER.222)(USER32.254)
520 * An application calls the GetKeyboardState function in response to a
521 * keyboard-input message. This function retrieves the state of the keyboard
522 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
524 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
526 TRACE_(key)("(%p)\n", lpKeyState);
527 if (lpKeyState != NULL) {
528 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
529 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
530 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
531 memcpy(lpKeyState, QueueKeyStateTable, 256);
534 return TRUE;
537 /**********************************************************************
538 * SetKeyboardState (USER.223)(USER32.484)
540 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
542 TRACE_(key)("(%p)\n", lpKeyState);
543 if (lpKeyState != NULL) {
544 memcpy(QueueKeyStateTable, lpKeyState, 256);
545 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
546 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
547 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
550 return TRUE;
553 /**********************************************************************
554 * GetAsyncKeyState (USER32.207)
556 * Determine if a key is or was pressed. retval has high-order
557 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
558 * been pressed.
560 * This uses the variable AsyncMouseButtonsStates and
561 * AsyncKeyStateTable (set in event.c) which have the mouse button
562 * number or key number (whichever is applicable) set to true if the
563 * mouse or key had been depressed since the last call to
564 * GetAsyncKeyState.
566 WORD WINAPI GetAsyncKeyState(INT nKey)
568 short retval;
570 switch (nKey) {
571 case VK_LBUTTON:
572 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
573 (MouseButtonsStates[0] ? 0x8000 : 0);
574 break;
575 case VK_MBUTTON:
576 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
577 (MouseButtonsStates[1] ? 0x8000 : 0);
578 break;
579 case VK_RBUTTON:
580 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
581 (MouseButtonsStates[2] ? 0x8000 : 0);
582 break;
583 default:
584 retval = AsyncKeyStateTable[nKey] |
585 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
586 break;
589 /* all states to false */
590 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
591 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
593 TRACE_(key)("(%x) -> %x\n", nKey, retval);
594 return retval;
597 /**********************************************************************
598 * GetAsyncKeyState16 (USER.249)
600 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
602 return GetAsyncKeyState(nKey);
605 /***********************************************************************
606 * IsUserIdle (USER.333)
608 BOOL16 WINAPI IsUserIdle16(void)
610 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
611 return FALSE;
613 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
614 return FALSE;
616 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
617 return FALSE;
619 /* Should check for screen saver activation here ... */
621 return TRUE;
624 /**********************************************************************
625 * KBD_translate_accelerator
627 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
629 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
630 BYTE fVirt,WORD key,WORD cmd)
632 BOOL sendmsg = FALSE;
634 if(msg->wParam == key)
636 if (msg->message == WM_CHAR) {
637 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
639 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n",
640 msg->wParam&0xff);
641 sendmsg=TRUE;
643 } else {
644 if(fVirt & FVIRTKEY) {
645 INT mask = 0;
646 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
647 msg->wParam,0xff & HIWORD(msg->lParam));
648 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
649 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
650 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
651 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
652 sendmsg=TRUE;
653 else
654 TRACE_(accel)(", but incorrect SHIFT/CTRL/ALT-state\n");
656 else
658 if (!(msg->lParam & 0x01000000)) /* no special_key */
660 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
661 { /* ^^ ALT pressed */
662 TRACE_(accel)("found accel for Alt-%c\n", msg->wParam&0xff);
663 sendmsg=TRUE;
669 if (sendmsg) /* found an accelerator, but send a message... ? */
671 INT16 iSysStat,iStat,mesg=0;
672 HMENU16 hMenu;
674 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
675 mesg=1;
676 else
677 if (GetCapture())
678 mesg=2;
679 else
680 if (!IsWindowEnabled(hWnd))
681 mesg=3;
682 else
684 WND* wndPtr = WIN_FindWndPtr(hWnd);
686 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
687 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
688 cmd, MF_BYCOMMAND) : -1 ;
689 iStat = (hMenu) ? GetMenuState(hMenu,
690 cmd, MF_BYCOMMAND) : -1 ;
692 WIN_ReleaseWndPtr(wndPtr);
694 if (iSysStat!=-1)
696 if (iSysStat & (MF_DISABLED|MF_GRAYED))
697 mesg=4;
698 else
699 mesg=WM_SYSCOMMAND;
701 else
703 if (iStat!=-1)
705 if (IsIconic(hWnd))
706 mesg=5;
707 else
709 if (iStat & (MF_DISABLED|MF_GRAYED))
710 mesg=6;
711 else
712 mesg=WM_COMMAND;
715 else
716 mesg=WM_COMMAND;
719 if( mesg==WM_COMMAND ) {
720 TRACE_(accel)(", sending WM_COMMAND, wParam=%0x\n", 0x10000 | cmd);
721 SendMessageA(hWnd, mesg, 0x10000 | cmd, 0L);
722 } else if( mesg==WM_SYSCOMMAND ) {
723 TRACE_(accel)(", sending WM_SYSCOMMAND, wParam=%0x\n", cmd);
724 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
726 else
728 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
729 * #0: unknown (please report!)
730 * #1: for WM_KEYUP,WM_SYSKEYUP
731 * #2: mouse is captured
732 * #3: window is disabled
733 * #4: it's a disabled system menu option
734 * #5: it's a menu option, but window is iconic
735 * #6: it's a menu option, but disabled
737 TRACE_(accel)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
738 if(mesg==0)
739 ERR_(accel)(" unknown reason - please report!");
741 return TRUE;
744 return FALSE;
747 /**********************************************************************
748 * TranslateAccelerator (USER32.551)(USER32.552)(USER32.553)
750 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
752 /* YES, Accel16! */
753 LPACCEL16 lpAccelTbl;
754 int i;
756 if (msg == NULL)
758 WARN_(accel)("msg null; should hang here to be win compatible\n");
759 return 0;
761 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
763 WARN_(accel)("invalid accel handle=%x\n", hAccel);
764 return 0;
766 if ((msg->message != WM_KEYDOWN &&
767 msg->message != WM_KEYUP &&
768 msg->message != WM_SYSKEYDOWN &&
769 msg->message != WM_SYSKEYUP &&
770 msg->message != WM_CHAR)) return 0;
772 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
773 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
774 hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
776 i = 0;
779 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
780 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
781 return 1;
782 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
783 WARN_(accel)("couldn't translate accelerator key\n");
784 return 0;
787 /**********************************************************************
788 * TranslateAccelerator16 (USER.178)
790 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
792 LPACCEL16 lpAccelTbl;
793 int i;
794 MSG msg32;
796 if (msg == NULL)
798 WARN_(accel)("msg null; should hang here to be win compatible\n");
799 return 0;
801 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
803 WARN_(accel)("invalid accel handle=%x\n", hAccel);
804 return 0;
806 if ((msg->message != WM_KEYDOWN &&
807 msg->message != WM_KEYUP &&
808 msg->message != WM_SYSKEYDOWN &&
809 msg->message != WM_SYSKEYUP &&
810 msg->message != WM_CHAR)) return 0;
812 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
813 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
815 STRUCT32_MSG16to32(msg,&msg32);
817 i = 0;
820 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
821 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
822 return 1;
823 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
824 WARN_(accel)("couldn't translate accelerator key\n");
825 return 0;
829 /**********************************************************************
830 * VkKeyScanA (USER32.573)
832 WORD WINAPI VkKeyScanA(CHAR cChar)
834 return VkKeyScan16(cChar);
837 /******************************************************************************
838 * VkKeyScanW (USER32.576)
840 WORD WINAPI VkKeyScanW(WCHAR cChar)
842 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
845 /**********************************************************************
846 * VkKeyScanExA (USER32.574)
848 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
850 /* FIXME: complete workaround this is */
851 return VkKeyScan16(cChar);
854 /******************************************************************************
855 * VkKeyScanExW (USER32.575)
857 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
859 /* FIXME: complete workaround this is */
860 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
863 /******************************************************************************
864 * GetKeyboardType (USER32.255)
866 INT WINAPI GetKeyboardType(INT nTypeFlag)
868 return GetKeyboardType16(nTypeFlag);
871 /******************************************************************************
872 * MapVirtualKeyA (USER32.383)
874 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
876 return MapVirtualKey16(code,maptype);
879 /******************************************************************************
880 * MapVirtualKeyW (USER32.385)
882 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
884 return MapVirtualKey16(code,maptype);
887 /******************************************************************************
888 * MapVirtualKeyExA (USER32.384)
890 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
892 if (hkl)
893 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
894 return MapVirtualKey16(code,maptype);
897 /****************************************************************************
898 * GetKBCodePage (USER32.246)
900 UINT WINAPI GetKBCodePage(void)
902 return GetKBCodePage16();
905 /****************************************************************************
906 * GetKeyboardLayoutName16 (USER.477)
908 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
910 return GetKeyboardLayoutNameA(pwszKLID);
913 /***********************************************************************
914 * GetKeyboardLayout (USER32.250)
916 * FIXME: - device handle for keyboard layout defaulted to
917 * the language id. This is the way Windows default works.
918 * - the thread identifier (dwLayout) is also ignored.
920 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
922 HKL layout;
923 layout = GetSystemDefaultLCID(); /* FIXME */
924 layout |= (layout<<16); /* FIXME */
925 TRACE_(keyboard)("returning %08x\n",layout);
926 return layout;
929 /****************************************************************************
930 * GetKeyboardLayoutNameA (USER32.252)
932 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
934 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
935 return 1;
938 /****************************************************************************
939 * GetKeyboardLayoutNameW (USER32.253)
941 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
943 char buf[9];
944 int res = GetKeyboardLayoutNameA(buf);
945 lstrcpyAtoW(pwszKLID,buf);
946 return res;
949 /****************************************************************************
950 * GetKeyNameTextA (USER32.247)
952 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
954 return GetKeyNameText16(lParam,lpBuffer,nSize);
957 /****************************************************************************
958 * GetKeyNameTextW (USER32.248)
960 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
962 int res;
963 LPSTR buf = HeapAlloc( GetProcessHeap(), 0, nSize );
964 if(buf == NULL) return 0; /* FIXME: is this the correct failure value?*/
965 res = GetKeyNameTextA(lParam,buf,nSize);
967 lstrcpynAtoW(lpBuffer,buf,nSize);
968 HeapFree( GetProcessHeap(), 0, buf );
969 return res;
972 /****************************************************************************
973 * ToAscii (USER32.546)
975 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
976 LPWORD lpChar,UINT flags )
978 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
981 /****************************************************************************
982 * ToAsciiEx (USER32.547)
984 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
985 LPWORD lpChar, UINT flags, HKL dwhkl )
987 /* FIXME: need true implementation */
988 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
991 /**********************************************************************
992 * ActivateKeyboardLayout (USER32.1)
994 * Call ignored. WINE supports only system default keyboard layout.
996 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
998 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
999 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
1000 return 0;
1004 /***********************************************************************
1005 * GetKeyboardLayoutList (USER32.251)
1007 * FIXME: Supports only the system default language and layout and
1008 * returns only 1 value.
1010 * Return number of values available if either input parm is
1011 * 0, per MS documentation.
1014 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
1016 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
1017 if (!nBuff || !layouts)
1018 return 1;
1019 if (layouts)
1020 layouts[0] = GetKeyboardLayout(0);
1021 return 1;
1025 /***********************************************************************
1026 * RegisterHotKey (USER32.433)
1028 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
1029 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
1030 return TRUE;
1033 /***********************************************************************
1034 * UnregisterHotKey (USER32.565)
1036 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
1037 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
1038 return TRUE;
1042 /***********************************************************************
1043 * ToUnicode (USER32.548)
1045 INT WINAPI ToUnicode(
1046 UINT wVirtKey,
1047 UINT wScanCode,
1048 PBYTE lpKeyState,
1049 LPWSTR pwszBuff,
1050 INT cchBuff,
1051 UINT wFlags) {
1053 FIXME_(keyboard)(": stub\n");
1054 return 0;
1057 /***********************************************************************
1058 * LoadKeyboardLayoutA (USER32.367)
1059 * Call ignored. WINE supports only system default keyboard layout.
1061 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
1063 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
1064 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
1065 return 0;
1068 /***********************************************************************
1069 * LoadKeyboardLayoutW (USER32.368)
1071 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1073 char buf[9];
1075 lstrcpynWtoA(buf,pwszKLID,8);
1076 buf[8] = 0;
1077 return LoadKeyboardLayoutA(buf, Flags);