Added missing configuration #if:s and #includes:s.
[wine/dcerpc.git] / windows / input.c
blobd14d18f05d759af6fd8b0dbdac28d637b747751e
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 <ctype.h>
15 #include <assert.h>
17 #include "winuser.h"
18 #include "wine/winbase16.h"
19 #include "wine/winuser16.h"
20 #include "wine/keyboard16.h"
21 #include "win.h"
22 #include "heap.h"
23 #include "input.h"
24 #include "keyboard.h"
25 #include "mouse.h"
26 #include "message.h"
27 #include "module.h"
28 #include "debugtools.h"
29 #include "struct32.h"
30 #include "winerror.h"
31 #include "task.h"
33 DECLARE_DEBUG_CHANNEL(accel)
34 DECLARE_DEBUG_CHANNEL(event)
35 DECLARE_DEBUG_CHANNEL(key)
36 DECLARE_DEBUG_CHANNEL(keyboard)
37 DECLARE_DEBUG_CHANNEL(win)
39 static BOOL InputEnabled = TRUE;
40 static BOOL SwappedButtons = FALSE;
42 BOOL MouseButtonsStates[3];
43 BOOL AsyncMouseButtonsStates[3];
44 BYTE InputKeyStateTable[256];
45 BYTE QueueKeyStateTable[256];
46 BYTE AsyncKeyStateTable[256];
48 typedef union
50 struct
52 unsigned long count : 16;
53 unsigned long code : 8;
54 unsigned long extended : 1;
55 unsigned long unused : 2;
56 unsigned long win_internal : 2;
57 unsigned long context : 1;
58 unsigned long previous : 1;
59 unsigned long transition : 1;
60 } lp1;
61 unsigned long lp2;
62 } KEYLP;
64 /***********************************************************************
65 * keybd_event (USER32.583)
67 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
68 DWORD dwFlags, DWORD dwExtraInfo )
70 DWORD posX, posY, time, extra;
71 WORD message;
72 KEYLP keylp;
73 keylp.lp2 = 0;
75 if (!InputEnabled) return;
78 * If we are called by the Wine keyboard driver, use the additional
79 * info pointed to by the dwExtraInfo argument.
80 * Otherwise, we need to determine that info ourselves (probably
81 * less accurate, but we can't help that ...).
83 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
84 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
86 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
87 posX = wke->posX;
88 posY = wke->posY;
89 time = wke->time;
90 extra = 0;
92 else
94 DWORD keyState;
95 time = GetTickCount();
96 extra = dwExtraInfo;
98 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
99 return;
103 keylp.lp1.count = 1;
104 keylp.lp1.code = bScan;
105 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
106 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
107 * don't remember where I read it - AK */
108 /* it's '1' under windows, when a dialog box appears
109 * and you press one of the underlined keys - DF*/
111 if ( dwFlags & KEYEVENTF_KEYUP )
113 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
114 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
115 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
117 InputKeyStateTable[bVk] &= ~0x80;
118 keylp.lp1.previous = 1;
119 keylp.lp1.transition = 1;
120 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
122 else
124 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
125 keylp.lp1.transition = 0;
127 if (!(InputKeyStateTable[bVk] & 0x80))
128 InputKeyStateTable[bVk] ^= 0x01;
129 InputKeyStateTable[bVk] |= 0x80;
131 message = (InputKeyStateTable[VK_MENU] & 0x80)
132 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
133 ? WM_SYSKEYDOWN : WM_KEYDOWN;
136 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
137 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
140 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
141 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
143 hardware_event( message, bVk, keylp.lp2, posX, posY, time, extra );
146 /***********************************************************************
147 * WIN16_keybd_event (USER.289)
149 void WINAPI WIN16_keybd_event( CONTEXT86 *context )
151 DWORD dwFlags = 0;
153 if (AH_reg(context) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
154 if (BH_reg(context) & 1 ) dwFlags |= KEYEVENTF_EXTENDEDKEY;
156 keybd_event( AL_reg(context), BL_reg(context),
157 dwFlags, MAKELONG(SI_reg(context), DI_reg(context)) );
160 /***********************************************************************
161 * mouse_event (USER32.584)
163 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
164 DWORD cButtons, DWORD dwExtraInfo )
166 DWORD posX, posY, keyState, time, extra;
168 if (!InputEnabled) return;
171 * If we are called by the Wine mouse driver, use the additional
172 * info pointed to by the dwExtraInfo argument.
173 * Otherwise, we need to determine that info ourselves (probably
174 * less accurate, but we can't help that ...).
176 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
177 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
179 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
180 keyState = wme->keyState;
181 time = wme->time;
182 extra = (DWORD)wme->hWnd;
184 assert( dwFlags & MOUSEEVENTF_ABSOLUTE );
185 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
186 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
188 else
190 time = GetTickCount();
191 extra = dwExtraInfo;
193 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
194 return;
196 if ( dwFlags & MOUSEEVENTF_MOVE )
198 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
200 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
201 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
203 else
205 posX += dx;
206 posY += dy;
208 /* We have to actually move the cursor */
209 SetCursorPos( posX, posY );
213 if ( dwFlags & MOUSEEVENTF_MOVE )
215 hardware_event( WM_MOUSEMOVE,
216 keyState, 0L, posX, posY, time, extra );
218 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
220 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
221 hardware_event( WM_LBUTTONDOWN,
222 keyState, 0L, posX, posY, time, extra );
224 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
226 MouseButtonsStates[0] = FALSE;
227 hardware_event( WM_LBUTTONUP,
228 keyState, 0L, posX, posY, time, extra );
230 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
232 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
233 hardware_event( WM_RBUTTONDOWN,
234 keyState, 0L, posX, posY, time, extra );
236 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
238 MouseButtonsStates[2] = FALSE;
239 hardware_event( WM_RBUTTONUP,
240 keyState, 0L, posX, posY, time, extra );
242 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
244 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
245 hardware_event( WM_MBUTTONDOWN,
246 keyState, 0L, posX, posY, time, extra );
248 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
250 MouseButtonsStates[1] = FALSE;
251 hardware_event( WM_MBUTTONUP,
252 keyState, 0L, posX, posY, time, extra );
256 /***********************************************************************
257 * WIN16_mouse_event (USER.299)
259 void WINAPI WIN16_mouse_event( CONTEXT86 *context )
261 mouse_event( AX_reg(context), BX_reg(context), CX_reg(context),
262 DX_reg(context), MAKELONG(SI_reg(context), DI_reg(context)) );
265 /***********************************************************************
266 * GetMouseEventProc (USER.337)
268 FARPROC16 WINAPI GetMouseEventProc16(void)
270 HMODULE16 hmodule = GetModuleHandle16("USER");
271 return NE_GetEntryPoint( hmodule, NE_GetOrdinal( hmodule, "mouse_event" ));
275 /**********************************************************************
276 * EnableHardwareInput (USER.331)
278 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
280 BOOL16 bOldState = InputEnabled;
281 FIXME_(event)("(%d) - stub\n", bEnable);
282 InputEnabled = bEnable;
283 return bOldState;
287 /***********************************************************************
288 * SwapMouseButton16 (USER.186)
290 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
292 BOOL16 ret = SwappedButtons;
293 SwappedButtons = fSwap;
294 return ret;
298 /***********************************************************************
299 * SwapMouseButton32 (USER32.537)
301 BOOL WINAPI SwapMouseButton( BOOL fSwap )
303 BOOL ret = SwappedButtons;
304 SwappedButtons = fSwap;
305 return ret;
308 /**********************************************************************
309 * EVENT_Capture
311 * We need this to be able to generate double click messages
312 * when menu code captures mouse in the window without CS_DBLCLK style.
314 HWND EVENT_Capture(HWND hwnd, INT16 ht)
316 HWND capturePrev = 0, captureWnd = 0;
317 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
318 WND* wndPtr = 0;
319 INT16 captureHT = 0;
321 /* Get the messageQ for the current thread */
322 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
324 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
325 goto CLEANUP;
328 /* Get the current capture window from the perQ data of the current message Q */
329 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
331 if (!hwnd)
333 captureWnd = 0L;
334 captureHT = 0;
336 else
338 wndPtr = WIN_FindWndPtr( hwnd );
339 if (wndPtr)
341 TRACE_(win)("(0x%04x)\n", hwnd );
342 captureWnd = hwnd;
343 captureHT = ht;
347 /* Update the perQ capture window and send messages */
348 if( capturePrev != captureWnd )
350 if (wndPtr)
352 /* Retrieve the message queue associated with this window */
353 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
354 if ( !pMsgQ )
356 WARN_(win)("\tMessage queue not found. Exiting!\n" );
357 goto CLEANUP;
360 /* Make sure that message queue for the window we are setting capture to
361 * shares the same perQ data as the current threads message queue.
363 if ( pCurMsgQ->pQData != pMsgQ->pQData )
364 goto CLEANUP;
367 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
368 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
370 if( capturePrev )
372 WND* wndPtr = WIN_FindWndPtr( capturePrev );
373 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
374 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
375 WIN_ReleaseWndPtr(wndPtr);
379 CLEANUP:
380 /* Unlock the queues before returning */
381 if ( pMsgQ )
382 QUEUE_Unlock( pMsgQ );
383 if ( pCurMsgQ )
384 QUEUE_Unlock( pCurMsgQ );
386 WIN_ReleaseWndPtr(wndPtr);
387 return capturePrev;
391 /**********************************************************************
392 * SetCapture16 (USER.18)
394 HWND16 WINAPI SetCapture16( HWND16 hwnd )
396 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
400 /**********************************************************************
401 * SetCapture32 (USER32.464)
403 HWND WINAPI SetCapture( HWND hwnd )
405 return EVENT_Capture( hwnd, HTCLIENT );
409 /**********************************************************************
410 * ReleaseCapture (USER.19) (USER32.439)
412 BOOL WINAPI ReleaseCapture(void)
414 return (EVENT_Capture( 0, 0 ) != 0);
418 /**********************************************************************
419 * GetCapture16 (USER.236)
421 HWND16 WINAPI GetCapture16(void)
423 return (HWND16)GetCapture();
426 /**********************************************************************
427 * GetCapture32 (USER32.208)
429 HWND WINAPI GetCapture(void)
431 MESSAGEQUEUE *pCurMsgQ = 0;
432 HWND hwndCapture = 0;
434 /* Get the messageQ for the current thread */
435 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
437 TRACE_(win)("GetCapture32: Current message queue not found. Exiting!\n" );
438 return 0;
441 /* Get the current capture window from the perQ data of the current message Q */
442 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
444 QUEUE_Unlock( pCurMsgQ );
445 return hwndCapture;
448 /**********************************************************************
449 * GetKeyState (USER.106)
451 INT16 WINAPI GetKeyState16(INT16 vkey)
453 return GetKeyState(vkey);
456 /**********************************************************************
457 * GetKeyState (USER32.249)
459 * An application calls the GetKeyState function in response to a
460 * keyboard-input message. This function retrieves the state of the key
461 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
463 SHORT WINAPI GetKeyState(INT vkey)
465 INT retval;
467 switch (vkey)
469 case VK_LBUTTON : /* VK_LBUTTON is 1 */
470 retval = MouseButtonsStates[0] ? 0x8000 : 0;
471 break;
472 case VK_MBUTTON : /* VK_MBUTTON is 4 */
473 retval = MouseButtonsStates[1] ? 0x8000 : 0;
474 break;
475 case VK_RBUTTON : /* VK_RBUTTON is 2 */
476 retval = MouseButtonsStates[2] ? 0x8000 : 0;
477 break;
478 default :
479 if (vkey >= 'a' && vkey <= 'z')
480 vkey += 'A' - 'a';
481 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
482 (WORD)(QueueKeyStateTable[vkey] & 0x01);
484 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
485 return retval;
488 /**********************************************************************
489 * GetKeyboardState (USER.222)(USER32.254)
491 * An application calls the GetKeyboardState function in response to a
492 * keyboard-input message. This function retrieves the state of the keyboard
493 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
495 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
497 TRACE_(key)("(%p)\n", lpKeyState);
498 if (lpKeyState != NULL) {
499 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
500 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
501 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
502 memcpy(lpKeyState, QueueKeyStateTable, 256);
505 return TRUE;
508 /**********************************************************************
509 * SetKeyboardState (USER.223)(USER32.484)
511 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
513 TRACE_(key)("(%p)\n", lpKeyState);
514 if (lpKeyState != NULL) {
515 memcpy(QueueKeyStateTable, lpKeyState, 256);
516 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
517 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
518 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
521 return TRUE;
524 /**********************************************************************
525 * GetAsyncKeyState32 (USER32.207)
527 * Determine if a key is or was pressed. retval has high-order
528 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
529 * been pressed.
531 * This uses the variable AsyncMouseButtonsStates and
532 * AsyncKeyStateTable (set in event.c) which have the mouse button
533 * number or key number (whichever is applicable) set to true if the
534 * mouse or key had been depressed since the last call to
535 * GetAsyncKeyState.
537 WORD WINAPI GetAsyncKeyState(INT nKey)
539 short retval;
541 switch (nKey) {
542 case VK_LBUTTON:
543 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
544 (MouseButtonsStates[0] ? 0x8000 : 0);
545 break;
546 case VK_MBUTTON:
547 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
548 (MouseButtonsStates[1] ? 0x8000 : 0);
549 break;
550 case VK_RBUTTON:
551 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
552 (MouseButtonsStates[2] ? 0x8000 : 0);
553 break;
554 default:
555 retval = AsyncKeyStateTable[nKey] |
556 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
557 break;
560 /* all states to false */
561 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
562 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
564 TRACE_(key)("(%x) -> %x\n", nKey, retval);
565 return retval;
568 /**********************************************************************
569 * GetAsyncKeyState16 (USER.249)
571 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
573 return GetAsyncKeyState(nKey);
576 /***********************************************************************
577 * IsUserIdle (USER.333)
579 BOOL16 WINAPI IsUserIdle16(void)
581 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
582 return FALSE;
584 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
585 return FALSE;
587 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
588 return FALSE;
590 /* Should check for screen saver activation here ... */
592 return TRUE;
595 /**********************************************************************
596 * KBD_translate_accelerator
598 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
600 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
601 BYTE fVirt,WORD key,WORD cmd)
603 BOOL sendmsg = FALSE;
605 if(msg->wParam == key)
607 if (msg->message == WM_CHAR) {
608 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
610 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n",
611 msg->wParam&0xff);
612 sendmsg=TRUE;
614 } else {
615 if(fVirt & FVIRTKEY) {
616 INT mask = 0;
617 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
618 msg->wParam,0xff & HIWORD(msg->lParam));
619 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
620 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
621 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
622 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
623 sendmsg=TRUE;
624 else
625 TRACE_(accel)(", but incorrect SHIFT/CTRL/ALT-state\n");
627 else
629 if (!(msg->lParam & 0x01000000)) /* no special_key */
631 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
632 { /* ^^ ALT pressed */
633 TRACE_(accel)("found accel for Alt-%c\n", msg->wParam&0xff);
634 sendmsg=TRUE;
640 if (sendmsg) /* found an accelerator, but send a message... ? */
642 INT16 iSysStat,iStat,mesg=0;
643 HMENU16 hMenu;
645 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
646 mesg=1;
647 else
648 if (GetCapture())
649 mesg=2;
650 else
651 if (!IsWindowEnabled(hWnd))
652 mesg=3;
653 else
655 WND* wndPtr = WIN_FindWndPtr(hWnd);
657 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
658 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
659 cmd, MF_BYCOMMAND) : -1 ;
660 iStat = (hMenu) ? GetMenuState(hMenu,
661 cmd, MF_BYCOMMAND) : -1 ;
663 WIN_ReleaseWndPtr(wndPtr);
665 if (iSysStat!=-1)
667 if (iSysStat & (MF_DISABLED|MF_GRAYED))
668 mesg=4;
669 else
670 mesg=WM_SYSCOMMAND;
672 else
674 if (iStat!=-1)
676 if (IsIconic(hWnd))
677 mesg=5;
678 else
680 if (iStat & (MF_DISABLED|MF_GRAYED))
681 mesg=6;
682 else
683 mesg=WM_COMMAND;
686 else
687 mesg=WM_COMMAND;
690 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
692 TRACE_(accel)(", sending %s, wParam=%0x\n",
693 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
694 cmd);
695 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
697 else
699 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
700 * #0: unknown (please report!)
701 * #1: for WM_KEYUP,WM_SYSKEYUP
702 * #2: mouse is captured
703 * #3: window is disabled
704 * #4: it's a disabled system menu option
705 * #5: it's a menu option, but window is iconic
706 * #6: it's a menu option, but disabled
708 TRACE_(accel)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
709 if(mesg==0)
710 ERR_(accel)(" unknown reason - please report!");
712 return TRUE;
715 return FALSE;
718 /**********************************************************************
719 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
721 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
723 /* YES, Accel16! */
724 LPACCEL16 lpAccelTbl;
725 int i;
727 if (msg == NULL)
729 WARN_(accel)("msg null; should hang here to be win compatible\n");
730 return 0;
732 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
734 WARN_(accel)("invalid accel handle=%x\n", hAccel);
735 return 0;
737 if ((msg->message != WM_KEYDOWN &&
738 msg->message != WM_KEYUP &&
739 msg->message != WM_SYSKEYDOWN &&
740 msg->message != WM_SYSKEYUP &&
741 msg->message != WM_CHAR)) return 0;
743 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
744 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
745 hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
747 i = 0;
750 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
751 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
752 return 1;
753 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
754 WARN_(accel)("couldn't translate accelerator key\n");
755 return 0;
758 /**********************************************************************
759 * TranslateAccelerator16 (USER.178)
761 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
763 LPACCEL16 lpAccelTbl;
764 int i;
765 MSG msg32;
767 if (msg == NULL)
769 WARN_(accel)("msg null; should hang here to be win compatible\n");
770 return 0;
772 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
774 WARN_(accel)("invalid accel handle=%x\n", hAccel);
775 return 0;
777 if ((msg->message != WM_KEYDOWN &&
778 msg->message != WM_KEYUP &&
779 msg->message != WM_SYSKEYDOWN &&
780 msg->message != WM_SYSKEYUP &&
781 msg->message != WM_CHAR)) return 0;
783 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
784 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
786 STRUCT32_MSG16to32(msg,&msg32);
788 i = 0;
791 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
792 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
793 return 1;
794 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
795 WARN_(accel)("couldn't translate accelerator key\n");
796 return 0;
800 /**********************************************************************
801 * VkKeyScanA (USER32.573)
803 WORD WINAPI VkKeyScanA(CHAR cChar)
805 return VkKeyScan16(cChar);
808 /******************************************************************************
809 * VkKeyScanW (USER32.576)
811 WORD WINAPI VkKeyScanW(WCHAR cChar)
813 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
816 /**********************************************************************
817 * VkKeyScanExA (USER32.574)
819 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
821 /* FIXME: complete workaround this is */
822 return VkKeyScan16(cChar);
825 /******************************************************************************
826 * VkKeyScanExW (USER32.575)
828 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
830 /* FIXME: complete workaround this is */
831 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
834 /******************************************************************************
835 * GetKeyboardType32 (USER32.255)
837 INT WINAPI GetKeyboardType(INT nTypeFlag)
839 return GetKeyboardType16(nTypeFlag);
842 /******************************************************************************
843 * MapVirtualKey32A (USER32.383)
845 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
847 return MapVirtualKey16(code,maptype);
850 /******************************************************************************
851 * MapVirtualKey32W (USER32.385)
853 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
855 return MapVirtualKey16(code,maptype);
858 /******************************************************************************
859 * MapVirtualKeyEx32A (USER32.384)
861 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
863 if (hkl)
864 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
865 return MapVirtualKey16(code,maptype);
868 /****************************************************************************
869 * GetKBCodePage32 (USER32.246)
871 UINT WINAPI GetKBCodePage(void)
873 return GetKBCodePage16();
876 /****************************************************************************
877 * GetKeyboardLayoutName16 (USER.477)
879 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
881 return GetKeyboardLayoutNameA(pwszKLID);
884 /***********************************************************************
885 * GetKeyboardLayout (USER32.250)
887 * FIXME: - device handle for keyboard layout defaulted to
888 * the language id. This is the way Windows default works.
889 * - the thread identifier (dwLayout) is also ignored.
891 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
893 HKL layout;
894 layout = GetSystemDefaultLCID(); /* FIXME */
895 layout |= (layout<<16); /* FIXME */
896 TRACE_(keyboard)("returning %08x\n",layout);
897 return layout;
900 /****************************************************************************
901 * GetKeyboardLayoutName32A (USER32.252)
903 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
905 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
906 return 1;
909 /****************************************************************************
910 * GetKeyboardLayoutName32W (USER32.253)
912 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
914 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
915 int res = GetKeyboardLayoutNameA(buf);
916 lstrcpyAtoW(pwszKLID,buf);
917 HeapFree( GetProcessHeap(), 0, buf );
918 return res;
921 /****************************************************************************
922 * GetKeyNameText32A (USER32.247)
924 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
926 return GetKeyNameText16(lParam,lpBuffer,nSize);
929 /****************************************************************************
930 * GetKeyNameText32W (USER32.248)
932 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
934 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
935 int res = GetKeyNameTextA(lParam,buf,nSize);
937 lstrcpynAtoW(lpBuffer,buf,nSize);
938 HeapFree( GetProcessHeap(), 0, buf );
939 return res;
942 /****************************************************************************
943 * ToAscii32 (USER32.546)
945 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
946 LPWORD lpChar,UINT flags )
948 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
951 /****************************************************************************
952 * ToAscii32 (USER32.547)
954 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
955 LPWORD lpChar, UINT flags, HKL dwhkl )
957 /* FIXME: need true implementation */
958 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
961 /**********************************************************************
962 * ActivateKeyboardLayout32 (USER32.1)
964 * Call ignored. WINE supports only system default keyboard layout.
966 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
968 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
969 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
970 return 0;
974 /***********************************************************************
975 * GetKeyboardLayoutList (USER32.251)
977 * FIXME: Supports only the system default language and layout and
978 * returns only 1 value.
980 * Return number of values available if either input parm is
981 * 0, per MS documentation.
984 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
986 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
987 if (!nBuff || !layouts)
988 return 1;
989 if (layouts)
990 layouts[0] = GetKeyboardLayout(0);
991 return 1;
995 /***********************************************************************
996 * RegisterHotKey (USER32.433)
998 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
999 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
1000 return TRUE;
1003 /***********************************************************************
1004 * UnregisterHotKey (USER32.565)
1006 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
1007 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
1008 return TRUE;
1012 /***********************************************************************
1013 * ToUnicode32 (USER32.548)
1015 INT WINAPI ToUnicode(
1016 UINT wVirtKey,
1017 UINT wScanCode,
1018 PBYTE lpKeyState,
1019 LPWSTR pwszBuff,
1020 INT cchBuff,
1021 UINT wFlags) {
1023 FIXME_(keyboard)(": stub\n");
1024 return 0;
1027 /***********************************************************************
1028 * LoadKeyboardLayout32A (USER32.367)
1029 * Call ignored. WINE supports only system default keyboard layout.
1031 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
1033 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
1034 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
1035 return 0;
1038 /***********************************************************************
1039 * LoadKeyboardLayout32W (USER32.368)
1041 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1043 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
1044 int res;
1045 lstrcpynWtoA(buf,pwszKLID,8);
1046 buf[8] = 0;
1047 res = LoadKeyboardLayoutA(buf, Flags);
1048 HeapFree( GetProcessHeap(), 0, buf );
1049 return res;