Added COMPOBJ.DllEntryPoint (Acrobat3 16bit needs it).
[wine.git] / windows / input.c
blob0fce564851e34cdcf679c325da28736a96379fbe
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 "debugtools.h"
28 #include "struct32.h"
29 #include "winerror.h"
30 #include "task.h"
32 DECLARE_DEBUG_CHANNEL(accel)
33 DECLARE_DEBUG_CHANNEL(event)
34 DECLARE_DEBUG_CHANNEL(key)
35 DECLARE_DEBUG_CHANNEL(keyboard)
36 DECLARE_DEBUG_CHANNEL(win)
38 static BOOL InputEnabled = TRUE;
39 static BOOL SwappedButtons = FALSE;
41 BOOL MouseButtonsStates[3];
42 BOOL AsyncMouseButtonsStates[3];
43 BYTE InputKeyStateTable[256];
44 BYTE QueueKeyStateTable[256];
45 BYTE AsyncKeyStateTable[256];
47 typedef union
49 struct
51 unsigned long count : 16;
52 unsigned long code : 8;
53 unsigned long extended : 1;
54 unsigned long unused : 2;
55 unsigned long win_internal : 2;
56 unsigned long context : 1;
57 unsigned long previous : 1;
58 unsigned long transition : 1;
59 } lp1;
60 unsigned long lp2;
61 } KEYLP;
63 /***********************************************************************
64 * keybd_event (USER32.583)
66 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
67 DWORD dwFlags, DWORD dwExtraInfo )
69 DWORD posX, posY, time, extra;
70 WORD message;
71 KEYLP keylp;
72 keylp.lp2 = 0;
74 if (!InputEnabled) return;
77 * If we are called by the Wine keyboard driver, use the additional
78 * info pointed to by the dwExtraInfo argument.
79 * Otherwise, we need to determine that info ourselves (probably
80 * less accurate, but we can't help that ...).
82 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_KEYBDEVENT) )
83 && ((WINE_KEYBDEVENT *)dwExtraInfo)->magic == WINE_KEYBDEVENT_MAGIC )
85 WINE_KEYBDEVENT *wke = (WINE_KEYBDEVENT *)dwExtraInfo;
86 posX = wke->posX;
87 posY = wke->posY;
88 time = wke->time;
89 extra = 0;
91 else
93 DWORD keyState;
94 time = GetTickCount();
95 extra = dwExtraInfo;
97 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
98 return;
102 keylp.lp1.count = 1;
103 keylp.lp1.code = bScan;
104 keylp.lp1.extended = (dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
105 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
106 * don't remember where I read it - AK */
107 /* it's '1' under windows, when a dialog box appears
108 * and you press one of the underlined keys - DF*/
110 if ( dwFlags & KEYEVENTF_KEYUP )
112 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80)
113 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
114 && !(dwFlags & KEYEVENTF_WINE_FORCEEXTENDED); /* for Alt from AltGr */
116 InputKeyStateTable[bVk] &= ~0x80;
117 keylp.lp1.previous = 1;
118 keylp.lp1.transition = 1;
119 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
121 else
123 keylp.lp1.previous = (InputKeyStateTable[bVk] & 0x80) != 0;
124 keylp.lp1.transition = 0;
126 if (!(InputKeyStateTable[bVk] & 0x80))
127 InputKeyStateTable[bVk] ^= 0x01;
128 InputKeyStateTable[bVk] |= 0x80;
130 message = (InputKeyStateTable[VK_MENU] & 0x80)
131 && !(InputKeyStateTable[VK_CONTROL] & 0x80)
132 ? WM_SYSKEYDOWN : WM_KEYDOWN;
135 if ( message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
136 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
139 TRACE_(key)(" wParam=%04X, lParam=%08lX\n", bVk, keylp.lp2 );
140 TRACE_(key)(" InputKeyState=%X\n", InputKeyStateTable[bVk] );
142 hardware_event( message, bVk, keylp.lp2, posX, posY, time, extra );
145 /***********************************************************************
146 * mouse_event (USER32.584)
148 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
149 DWORD cButtons, DWORD dwExtraInfo )
151 DWORD posX, posY, keyState, time, extra;
153 if (!InputEnabled) return;
156 * If we are called by the Wine mouse driver, use the additional
157 * info pointed to by the dwExtraInfo argument.
158 * Otherwise, we need to determine that info ourselves (probably
159 * less accurate, but we can't help that ...).
161 if ( !IsBadReadPtr( (LPVOID)dwExtraInfo, sizeof(WINE_MOUSEEVENT) )
162 && ((WINE_MOUSEEVENT *)dwExtraInfo)->magic == WINE_MOUSEEVENT_MAGIC )
164 WINE_MOUSEEVENT *wme = (WINE_MOUSEEVENT *)dwExtraInfo;
165 keyState = wme->keyState;
166 time = wme->time;
167 extra = (DWORD)wme->hWnd;
169 assert( dwFlags & MOUSEEVENTF_ABSOLUTE );
170 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
171 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
173 else
175 time = GetTickCount();
176 extra = dwExtraInfo;
178 if ( !EVENT_QueryPointer( &posX, &posY, &keyState ))
179 return;
181 if ( dwFlags & MOUSEEVENTF_MOVE )
183 if ( dwFlags & MOUSEEVENTF_ABSOLUTE )
185 posX = (dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
186 posY = (dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
188 else
190 posX += dx;
191 posY += dy;
193 /* We have to actually move the cursor */
194 SetCursorPos( posX, posY );
198 if ( dwFlags & MOUSEEVENTF_MOVE )
200 hardware_event( WM_MOUSEMOVE,
201 keyState, 0L, posX, posY, time, extra );
203 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN) )
205 MouseButtonsStates[0] = AsyncMouseButtonsStates[0] = TRUE;
206 hardware_event( WM_LBUTTONDOWN,
207 keyState, 0L, posX, posY, time, extra );
209 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP) )
211 MouseButtonsStates[0] = FALSE;
212 hardware_event( WM_LBUTTONUP,
213 keyState, 0L, posX, posY, time, extra );
215 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_LEFTDOWN) )
217 MouseButtonsStates[2] = AsyncMouseButtonsStates[2] = TRUE;
218 hardware_event( WM_RBUTTONDOWN,
219 keyState, 0L, posX, posY, time, extra );
221 if ( dwFlags & (!SwappedButtons? MOUSEEVENTF_RIGHTUP : MOUSEEVENTF_LEFTUP) )
223 MouseButtonsStates[2] = FALSE;
224 hardware_event( WM_RBUTTONUP,
225 keyState, 0L, posX, posY, time, extra );
227 if ( dwFlags & MOUSEEVENTF_MIDDLEDOWN )
229 MouseButtonsStates[1] = AsyncMouseButtonsStates[1] = TRUE;
230 hardware_event( WM_MBUTTONDOWN,
231 keyState, 0L, posX, posY, time, extra );
233 if ( dwFlags & MOUSEEVENTF_MIDDLEUP )
235 MouseButtonsStates[1] = FALSE;
236 hardware_event( WM_MBUTTONUP,
237 keyState, 0L, posX, posY, time, extra );
241 /**********************************************************************
242 * EnableHardwareInput (USER.331)
244 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
246 BOOL16 bOldState = InputEnabled;
247 FIXME_(event)("(%d) - stub\n", bEnable);
248 InputEnabled = bEnable;
249 return bOldState;
253 /***********************************************************************
254 * SwapMouseButton16 (USER.186)
256 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
258 BOOL16 ret = SwappedButtons;
259 SwappedButtons = fSwap;
260 return ret;
264 /***********************************************************************
265 * SwapMouseButton32 (USER32.537)
267 BOOL WINAPI SwapMouseButton( BOOL fSwap )
269 BOOL ret = SwappedButtons;
270 SwappedButtons = fSwap;
271 return ret;
274 /**********************************************************************
275 * EVENT_Capture
277 * We need this to be able to generate double click messages
278 * when menu code captures mouse in the window without CS_DBLCLK style.
280 HWND EVENT_Capture(HWND hwnd, INT16 ht)
282 HWND capturePrev = 0, captureWnd = 0;
283 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
284 WND* wndPtr = 0;
285 INT16 captureHT = 0;
287 /* Get the messageQ for the current thread */
288 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
290 WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
291 goto CLEANUP;
294 /* Get the current capture window from the perQ data of the current message Q */
295 capturePrev = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
297 if (!hwnd)
299 captureWnd = 0L;
300 captureHT = 0;
302 else
304 wndPtr = WIN_FindWndPtr( hwnd );
305 if (wndPtr)
307 TRACE_(win)("(0x%04x)\n", hwnd );
308 captureWnd = hwnd;
309 captureHT = ht;
313 /* Update the perQ capture window and send messages */
314 if( capturePrev != captureWnd )
316 if (wndPtr)
318 /* Retrieve the message queue associated with this window */
319 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
320 if ( !pMsgQ )
322 WARN_(win)("\tMessage queue not found. Exiting!\n" );
323 goto CLEANUP;
326 /* Make sure that message queue for the window we are setting capture to
327 * shares the same perQ data as the current threads message queue.
329 if ( pCurMsgQ->pQData != pMsgQ->pQData )
330 goto CLEANUP;
333 PERQDATA_SetCaptureWnd( pCurMsgQ->pQData, captureWnd );
334 PERQDATA_SetCaptureInfo( pCurMsgQ->pQData, captureHT );
336 if( capturePrev )
338 WND* wndPtr = WIN_FindWndPtr( capturePrev );
339 if( wndPtr && (wndPtr->flags & WIN_ISWIN32) )
340 SendMessageA( capturePrev, WM_CAPTURECHANGED, 0L, hwnd);
341 WIN_ReleaseWndPtr(wndPtr);
345 CLEANUP:
346 /* Unlock the queues before returning */
347 if ( pMsgQ )
348 QUEUE_Unlock( pMsgQ );
349 if ( pCurMsgQ )
350 QUEUE_Unlock( pCurMsgQ );
352 WIN_ReleaseWndPtr(wndPtr);
353 return capturePrev;
357 /**********************************************************************
358 * SetCapture16 (USER.18)
360 HWND16 WINAPI SetCapture16( HWND16 hwnd )
362 return (HWND16)EVENT_Capture( hwnd, HTCLIENT );
366 /**********************************************************************
367 * SetCapture32 (USER32.464)
369 HWND WINAPI SetCapture( HWND hwnd )
371 return EVENT_Capture( hwnd, HTCLIENT );
375 /**********************************************************************
376 * ReleaseCapture (USER.19) (USER32.439)
378 BOOL WINAPI ReleaseCapture(void)
380 return (EVENT_Capture( 0, 0 ) != 0);
384 /**********************************************************************
385 * GetCapture16 (USER.236)
387 HWND16 WINAPI GetCapture16(void)
389 return (HWND16)GetCapture();
392 /**********************************************************************
393 * GetCapture32 (USER32.208)
395 HWND WINAPI GetCapture(void)
397 MESSAGEQUEUE *pCurMsgQ = 0;
398 HWND hwndCapture = 0;
400 /* Get the messageQ for the current thread */
401 if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
403 TRACE_(win)("GetCapture32: Current message queue not found. Exiting!\n" );
404 return 0;
407 /* Get the current capture window from the perQ data of the current message Q */
408 hwndCapture = PERQDATA_GetCaptureWnd( pCurMsgQ->pQData );
410 QUEUE_Unlock( pCurMsgQ );
411 return hwndCapture;
414 /**********************************************************************
415 * GetKeyState (USER.106)
417 INT16 WINAPI GetKeyState16(INT16 vkey)
419 return GetKeyState(vkey);
422 /**********************************************************************
423 * GetKeyState (USER32.249)
425 * An application calls the GetKeyState function in response to a
426 * keyboard-input message. This function retrieves the state of the key
427 * at the time the input message was generated. (SDK 3.1 Vol 2. p 390)
429 INT16 WINAPI GetKeyState(INT vkey)
431 INT retval;
433 switch (vkey)
435 case VK_LBUTTON : /* VK_LBUTTON is 1 */
436 retval = MouseButtonsStates[0] ? 0x8000 : 0;
437 break;
438 case VK_MBUTTON : /* VK_MBUTTON is 4 */
439 retval = MouseButtonsStates[1] ? 0x8000 : 0;
440 break;
441 case VK_RBUTTON : /* VK_RBUTTON is 2 */
442 retval = MouseButtonsStates[2] ? 0x8000 : 0;
443 break;
444 default :
445 if (vkey >= 'a' && vkey <= 'z')
446 vkey += 'A' - 'a';
447 retval = ( (WORD)(QueueKeyStateTable[vkey] & 0x80) << 8 ) |
448 (WORD)(QueueKeyStateTable[vkey] & 0x01);
450 /* TRACE(key, "(0x%x) -> %x\n", vkey, retval); */
451 return retval;
454 /**********************************************************************
455 * GetKeyboardState (USER.222)(USER32.254)
457 * An application calls the GetKeyboardState function in response to a
458 * keyboard-input message. This function retrieves the state of the keyboard
459 * at the time the input message was generated. (SDK 3.1 Vol 2. p 387)
461 BOOL WINAPI GetKeyboardState(LPBYTE lpKeyState)
463 TRACE_(key)("(%p)\n", lpKeyState);
464 if (lpKeyState != NULL) {
465 QueueKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
466 QueueKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
467 QueueKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
468 memcpy(lpKeyState, QueueKeyStateTable, 256);
471 return TRUE;
474 /**********************************************************************
475 * SetKeyboardState (USER.223)(USER32.484)
477 BOOL WINAPI SetKeyboardState(LPBYTE lpKeyState)
479 TRACE_(key)("(%p)\n", lpKeyState);
480 if (lpKeyState != NULL) {
481 memcpy(QueueKeyStateTable, lpKeyState, 256);
482 MouseButtonsStates[0] = (QueueKeyStateTable[VK_LBUTTON] != 0);
483 MouseButtonsStates[1] = (QueueKeyStateTable[VK_MBUTTON] != 0);
484 MouseButtonsStates[2] = (QueueKeyStateTable[VK_RBUTTON] != 0);
487 return TRUE;
490 /**********************************************************************
491 * GetAsyncKeyState32 (USER32.207)
493 * Determine if a key is or was pressed. retval has high-order
494 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
495 * been pressed.
497 * This uses the variable AsyncMouseButtonsStates and
498 * AsyncKeyStateTable (set in event.c) which have the mouse button
499 * number or key number (whichever is applicable) set to true if the
500 * mouse or key had been depressed since the last call to
501 * GetAsyncKeyState.
503 WORD WINAPI GetAsyncKeyState(INT nKey)
505 short retval;
507 switch (nKey) {
508 case VK_LBUTTON:
509 retval = (AsyncMouseButtonsStates[0] ? 0x0001 : 0) |
510 (MouseButtonsStates[0] ? 0x8000 : 0);
511 break;
512 case VK_MBUTTON:
513 retval = (AsyncMouseButtonsStates[1] ? 0x0001 : 0) |
514 (MouseButtonsStates[1] ? 0x8000 : 0);
515 break;
516 case VK_RBUTTON:
517 retval = (AsyncMouseButtonsStates[2] ? 0x0001 : 0) |
518 (MouseButtonsStates[2] ? 0x8000 : 0);
519 break;
520 default:
521 retval = AsyncKeyStateTable[nKey] |
522 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
523 break;
526 /* all states to false */
527 memset( AsyncMouseButtonsStates, 0, sizeof(AsyncMouseButtonsStates) );
528 memset( AsyncKeyStateTable, 0, sizeof(AsyncKeyStateTable) );
530 TRACE_(key)("(%x) -> %x\n", nKey, retval);
531 return retval;
534 /**********************************************************************
535 * GetAsyncKeyState16 (USER.249)
537 WORD WINAPI GetAsyncKeyState16(INT16 nKey)
539 return GetAsyncKeyState(nKey);
542 /***********************************************************************
543 * IsUserIdle (USER.333)
545 BOOL16 WINAPI IsUserIdle16(void)
547 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
548 return FALSE;
550 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
551 return FALSE;
553 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
554 return FALSE;
556 /* Should check for screen saver activation here ... */
558 return TRUE;
561 /**********************************************************************
562 * KBD_translate_accelerator
564 * FIXME: should send some WM_INITMENU or/and WM_INITMENUPOPUP -messages
566 static BOOL KBD_translate_accelerator(HWND hWnd,LPMSG msg,
567 BYTE fVirt,WORD key,WORD cmd)
569 BOOL sendmsg = FALSE;
571 if(msg->wParam == key)
573 if (msg->message == WM_CHAR) {
574 if ( !(fVirt & FALT) && !(fVirt & FVIRTKEY) )
576 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n",
577 msg->wParam&0xff);
578 sendmsg=TRUE;
580 } else {
581 if(fVirt & FVIRTKEY) {
582 INT mask = 0;
583 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
584 msg->wParam,0xff & HIWORD(msg->lParam));
585 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
586 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
587 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
588 if(mask == (fVirt & (FSHIFT | FCONTROL | FALT)))
589 sendmsg=TRUE;
590 else
591 TRACE_(accel)(", but incorrect SHIFT/CTRL/ALT-state\n");
593 else
595 if (!(msg->lParam & 0x01000000)) /* no special_key */
597 if ((fVirt & FALT) && (msg->lParam & 0x20000000))
598 { /* ^^ ALT pressed */
599 TRACE_(accel)("found accel for Alt-%c\n", msg->wParam&0xff);
600 sendmsg=TRUE;
606 if (sendmsg) /* found an accelerator, but send a message... ? */
608 INT16 iSysStat,iStat,mesg=0;
609 HMENU16 hMenu;
611 if (msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
612 mesg=1;
613 else
614 if (GetCapture())
615 mesg=2;
616 else
617 if (!IsWindowEnabled(hWnd))
618 mesg=3;
619 else
621 WND* wndPtr = WIN_FindWndPtr(hWnd);
623 hMenu = (wndPtr->dwStyle & WS_CHILD) ? 0 : (HMENU)wndPtr->wIDmenu;
624 iSysStat = (wndPtr->hSysMenu) ? GetMenuState(GetSubMenu16(wndPtr->hSysMenu, 0),
625 cmd, MF_BYCOMMAND) : -1 ;
626 iStat = (hMenu) ? GetMenuState(hMenu,
627 cmd, MF_BYCOMMAND) : -1 ;
629 WIN_ReleaseWndPtr(wndPtr);
631 if (iSysStat!=-1)
633 if (iSysStat & (MF_DISABLED|MF_GRAYED))
634 mesg=4;
635 else
636 mesg=WM_SYSCOMMAND;
638 else
640 if (iStat!=-1)
642 if (IsIconic(hWnd))
643 mesg=5;
644 else
646 if (iStat & (MF_DISABLED|MF_GRAYED))
647 mesg=6;
648 else
649 mesg=WM_COMMAND;
652 else
653 mesg=WM_COMMAND;
656 if ( mesg==WM_COMMAND || mesg==WM_SYSCOMMAND )
658 TRACE_(accel)(", sending %s, wParam=%0x\n",
659 mesg==WM_COMMAND ? "WM_COMMAND" : "WM_SYSCOMMAND",
660 cmd);
661 SendMessageA(hWnd, mesg, cmd, 0x00010000L);
663 else
665 /* some reasons for NOT sending the WM_{SYS}COMMAND message:
666 * #0: unknown (please report!)
667 * #1: for WM_KEYUP,WM_SYSKEYUP
668 * #2: mouse is captured
669 * #3: window is disabled
670 * #4: it's a disabled system menu option
671 * #5: it's a menu option, but window is iconic
672 * #6: it's a menu option, but disabled
674 TRACE_(accel)(", but won't send WM_{SYS}COMMAND, reason is #%d\n",mesg);
675 if(mesg==0)
676 ERR_(accel)(" unknown reason - please report!");
678 return TRUE;
681 return FALSE;
684 /**********************************************************************
685 * TranslateAccelerator32 (USER32.551)(USER32.552)(USER32.553)
687 INT WINAPI TranslateAccelerator(HWND hWnd, HACCEL hAccel, LPMSG msg)
689 /* YES, Accel16! */
690 LPACCEL16 lpAccelTbl;
691 int i;
693 if (msg == NULL)
695 WARN_(accel)("msg null; should hang here to be win compatible\n");
696 return 0;
698 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
700 WARN_(accel)("invalid accel handle=%x\n", hAccel);
701 return 0;
703 if ((msg->message != WM_KEYDOWN &&
704 msg->message != WM_KEYUP &&
705 msg->message != WM_SYSKEYDOWN &&
706 msg->message != WM_SYSKEYUP &&
707 msg->message != WM_CHAR)) return 0;
709 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,"
710 "msg->hwnd=%04x, msg->message=%04x, wParam=%08x, lParam=%lx\n",
711 hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
713 i = 0;
716 if (KBD_translate_accelerator(hWnd,msg,lpAccelTbl[i].fVirt,
717 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
718 return 1;
719 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
720 WARN_(accel)("couldn't translate accelerator key\n");
721 return 0;
724 /**********************************************************************
725 * TranslateAccelerator16 (USER.178)
727 INT16 WINAPI TranslateAccelerator16(HWND16 hWnd, HACCEL16 hAccel, LPMSG16 msg)
729 LPACCEL16 lpAccelTbl;
730 int i;
731 MSG msg32;
733 if (msg == NULL)
735 WARN_(accel)("msg null; should hang here to be win compatible\n");
736 return 0;
738 if (!hAccel || !(lpAccelTbl = (LPACCEL16) LockResource16(hAccel)))
740 WARN_(accel)("invalid accel handle=%x\n", hAccel);
741 return 0;
743 if ((msg->message != WM_KEYDOWN &&
744 msg->message != WM_KEYUP &&
745 msg->message != WM_SYSKEYDOWN &&
746 msg->message != WM_SYSKEYUP &&
747 msg->message != WM_CHAR)) return 0;
749 TRACE_(accel)("TranslateAccelerators hAccel=%04x, hWnd=%04x,\
750 msg->hwnd=%04x, msg->message=%04x, wParam=%04x, lParam=%lx\n", hAccel,hWnd,msg->hwnd,msg->message,msg->wParam,msg->lParam);
752 STRUCT32_MSG16to32(msg,&msg32);
754 i = 0;
757 if (KBD_translate_accelerator(hWnd,&msg32,lpAccelTbl[i].fVirt,
758 lpAccelTbl[i].key,lpAccelTbl[i].cmd))
759 return 1;
760 } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
761 WARN_(accel)("couldn't translate accelerator key\n");
762 return 0;
766 /**********************************************************************
767 * VkKeyScanA (USER32.573)
769 WORD WINAPI VkKeyScanA(CHAR cChar)
771 return VkKeyScan16(cChar);
774 /******************************************************************************
775 * VkKeyScanW (USER32.576)
777 WORD WINAPI VkKeyScanW(WCHAR cChar)
779 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
782 /**********************************************************************
783 * VkKeyScanExA (USER32.574)
785 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
787 /* FIXME: complete workaround this is */
788 return VkKeyScan16(cChar);
791 /******************************************************************************
792 * VkKeyScanExW (USER32.575)
794 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
796 /* FIXME: complete workaround this is */
797 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
800 /******************************************************************************
801 * GetKeyboardType32 (USER32.255)
803 INT WINAPI GetKeyboardType(INT nTypeFlag)
805 return GetKeyboardType16(nTypeFlag);
808 /******************************************************************************
809 * MapVirtualKey32A (USER32.383)
811 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
813 return MapVirtualKey16(code,maptype);
816 /******************************************************************************
817 * MapVirtualKey32W (USER32.385)
819 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
821 return MapVirtualKey16(code,maptype);
824 /******************************************************************************
825 * MapVirtualKeyEx32A (USER32.384)
827 UINT WINAPI MapVirtualKeyEx32A(UINT code, UINT maptype, HKL hkl)
829 if (hkl)
830 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
831 return MapVirtualKey16(code,maptype);
834 /****************************************************************************
835 * GetKBCodePage32 (USER32.246)
837 UINT WINAPI GetKBCodePage(void)
839 return GetKBCodePage16();
842 /****************************************************************************
843 * GetKeyboardLayoutName16 (USER.477)
845 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
847 return GetKeyboardLayoutNameA(pwszKLID);
850 /***********************************************************************
851 * GetKeyboardLayout (USER32.250)
853 * FIXME: - device handle for keyboard layout defaulted to
854 * the language id. This is the way Windows default works.
855 * - the thread identifier (dwLayout) is also ignored.
857 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
859 HKL layout;
860 layout = GetSystemDefaultLCID(); /* FIXME */
861 layout |= (layout<<16); /* FIXME */
862 TRACE_(keyboard)("returning %08x\n",layout);
863 return layout;
866 /****************************************************************************
867 * GetKeyboardLayoutName32A (USER32.252)
869 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
871 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
872 return 1;
875 /****************************************************************************
876 * GetKeyboardLayoutName32W (USER32.253)
878 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
880 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
881 int res = GetKeyboardLayoutNameA(buf);
882 lstrcpyAtoW(pwszKLID,buf);
883 HeapFree( GetProcessHeap(), 0, buf );
884 return res;
887 /****************************************************************************
888 * GetKeyNameText32A (USER32.247)
890 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
892 return GetKeyNameText16(lParam,lpBuffer,nSize);
895 /****************************************************************************
896 * GetKeyNameText32W (USER32.248)
898 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
900 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, nSize );
901 int res = GetKeyNameTextA(lParam,buf,nSize);
903 lstrcpynAtoW(lpBuffer,buf,nSize);
904 HeapFree( GetProcessHeap(), 0, buf );
905 return res;
908 /****************************************************************************
909 * ToAscii32 (USER32.546)
911 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
912 LPWORD lpChar,UINT flags )
914 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
917 /****************************************************************************
918 * ToAscii32 (USER32.547)
920 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
921 LPWORD lpChar, UINT flags, HKL dwhkl )
923 /* FIXME: need true implementation */
924 return ToAscii16(virtKey,scanCode,lpKeyState,lpChar,flags);
927 /**********************************************************************
928 * ActivateKeyboardLayout32 (USER32.1)
930 * Call ignored. WINE supports only system default keyboard layout.
932 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
934 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
935 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
936 return 0;
940 /***********************************************************************
941 * GetKeyboardLayoutList (USER32.251)
943 * FIXME: Supports only the system default language and layout and
944 * returns only 1 value.
946 * Return number of values available if either input parm is
947 * 0, per MS documentation.
950 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
952 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
953 if (!nBuff || !layouts)
954 return 1;
955 if (layouts)
956 layouts[0] = GetKeyboardLayout(0);
957 return 1;
961 /***********************************************************************
962 * RegisterHotKey (USER32.433)
964 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
965 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
966 return TRUE;
969 /***********************************************************************
970 * UnregisterHotKey (USER32.565)
972 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
973 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
974 return TRUE;
978 /***********************************************************************
979 * ToUnicode32 (USER32.548)
981 INT WINAPI ToUnicode(
982 UINT wVirtKey,
983 UINT wScanCode,
984 PBYTE lpKeyState,
985 LPWSTR pwszBuff,
986 int cchBuff,
987 UINT wFlags) {
989 FIXME_(keyboard)(": stub\n");
990 return 0;
993 /***********************************************************************
994 * LoadKeyboardLayout32A (USER32.367)
995 * Call ignored. WINE supports only system default keyboard layout.
997 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
999 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
1000 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
1001 return 0;
1004 /***********************************************************************
1005 * LoadKeyboardLayout32W (USER32.368)
1007 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1009 LPSTR buf = HEAP_xalloc( GetProcessHeap(), 0, strlen("00000409")+1);
1010 int res;
1011 lstrcpynWtoA(buf,pwszKLID,8);
1012 buf[8] = 0;
1013 res = LoadKeyboardLayoutA(buf, Flags);
1014 HeapFree( GetProcessHeap(), 0, buf );
1015 return res;