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
23 #include "wine/winbase16.h"
24 #include "wine/winuser16.h"
25 #include "wine/server.h"
31 #include "debugtools.h"
34 DECLARE_DEBUG_CHANNEL(key
);
35 DECLARE_DEBUG_CHANNEL(keyboard
);
36 DECLARE_DEBUG_CHANNEL(win
);
37 DEFAULT_DEBUG_CHANNEL(event
);
39 static BOOL InputEnabled
= TRUE
;
40 static BOOL SwappedButtons
;
42 BYTE InputKeyStateTable
[256];
43 BYTE AsyncKeyStateTable
[256];
45 /* Storage for the USER-maintained mouse positions */
46 static DWORD PosX
, PosY
;
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;
65 /***********************************************************************
68 static WORD
get_key_state(void)
74 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
75 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
79 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
80 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
82 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) ret
|= MK_MBUTTON
;
83 if (InputKeyStateTable
[VK_SHIFT
] & 0x80) ret
|= MK_SHIFT
;
84 if (InputKeyStateTable
[VK_CONTROL
] & 0x80) ret
|= MK_CONTROL
;
85 if (InputKeyStateTable
[VK_XBUTTON1
] & 0x80) ret
|= MK_XBUTTON1
;
86 if (InputKeyStateTable
[VK_XBUTTON2
] & 0x80) ret
|= MK_XBUTTON2
;
91 /***********************************************************************
92 * queue_raw_hardware_message
94 * Add a message to the raw hardware queue.
95 * Note: the position is relative to the desktop window.
97 static void queue_raw_hardware_message( UINT message
, WPARAM wParam
, LPARAM lParam
,
98 int xPos
, int yPos
, DWORD time
, ULONG_PTR extraInfo
)
100 SERVER_START_REQ( send_message
)
102 req
->id
= (void *)GetCurrentThreadId();
103 req
->type
= MSG_HARDWARE_RAW
;
106 req
->wparam
= wParam
;
107 req
->lparam
= lParam
;
111 req
->info
= extraInfo
;
113 wine_server_call( req
);
119 /***********************************************************************
122 * Put a keyboard event into a thread queue
124 static void queue_kbd_event( const KEYBDINPUT
*ki
, UINT injected_flags
)
128 KBDLLHOOKSTRUCT hook
;
132 keylp
.lp1
.code
= ki
->wScan
;
133 keylp
.lp1
.extended
= (ki
->dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
134 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
135 * don't remember where I read it - AK */
136 /* it's '1' under windows, when a dialog box appears
137 * and you press one of the underlined keys - DF*/
139 if (ki
->dwFlags
& KEYEVENTF_KEYUP
)
141 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80) &&
142 !(InputKeyStateTable
[VK_CONTROL
] & 0x80);
143 InputKeyStateTable
[ki
->wVk
] &= ~0x80;
144 keylp
.lp1
.previous
= 1;
145 keylp
.lp1
.transition
= 1;
146 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
150 keylp
.lp1
.previous
= (InputKeyStateTable
[ki
->wVk
] & 0x80) != 0;
151 keylp
.lp1
.transition
= 0;
152 if (!(InputKeyStateTable
[ki
->wVk
] & 0x80)) InputKeyStateTable
[ki
->wVk
] ^= 0x01;
153 InputKeyStateTable
[ki
->wVk
] |= 0x80;
154 AsyncKeyStateTable
[ki
->wVk
] |= 0x80;
156 message
= (InputKeyStateTable
[VK_MENU
] & 0x80) && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
157 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
160 if (message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
161 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
163 TRACE_(key
)(" wParam=%04x, lParam=%08lx, InputKeyState=%x\n",
164 ki
->wVk
, keylp
.lp2
, InputKeyStateTable
[ki
->wVk
] );
166 hook
.vkCode
= ki
->wVk
;
167 hook
.scanCode
= ki
->wScan
;
168 hook
.flags
= (keylp
.lp2
>> 24) | injected_flags
;
169 hook
.time
= ki
->time
;
170 hook
.dwExtraInfo
= ki
->dwExtraInfo
;
171 if (!HOOK_CallHooksW( WH_KEYBOARD_LL
, HC_ACTION
, message
, (LPARAM
)&hook
))
172 queue_raw_hardware_message( message
, ki
->wVk
, keylp
.lp2
,
173 PosX
, PosY
, ki
->time
, ki
->dwExtraInfo
);
177 /***********************************************************************
178 * queue_raw_mouse_message
180 static void queue_raw_mouse_message( UINT message
, UINT flags
, INT x
, INT y
, const MOUSEINPUT
*mi
)
186 hook
.mouseData
= MAKELONG( 0, mi
->mouseData
);
188 hook
.time
= mi
->time
;
189 hook
.dwExtraInfo
= mi
->dwExtraInfo
;
191 if (!HOOK_CallHooksW( WH_MOUSE_LL
, HC_ACTION
, message
, (LPARAM
)&hook
))
192 queue_raw_hardware_message( message
, MAKEWPARAM( get_key_state(), mi
->mouseData
),
193 0, x
, y
, mi
->time
, mi
->dwExtraInfo
);
197 /***********************************************************************
200 static void queue_mouse_event( const MOUSEINPUT
*mi
, UINT flags
)
202 if (mi
->dwFlags
& MOUSEEVENTF_ABSOLUTE
)
204 PosX
= (mi
->dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
205 PosY
= (mi
->dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
207 else if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
209 int width
= GetSystemMetrics(SM_CXSCREEN
);
210 int height
= GetSystemMetrics(SM_CYSCREEN
);
211 long posX
= (long) PosX
, posY
= (long) PosY
;
215 /* dx and dy can be negative numbers for relative movements */
216 SystemParametersInfoA(SPI_GETMOUSE
, 0, accel
, 0);
219 if (mi
->dx
> accel
[0] && accel
[2] != 0)
222 if ((mi
->dx
> accel
[1]) && (accel
[2] == 2))
227 posX
+= (long)mi
->dx
* accelMult
;
230 if (mi
->dy
> accel
[0] && accel
[2] != 0)
233 if ((mi
->dy
> accel
[1]) && (accel
[2] == 2))
238 posY
+= (long)mi
->dy
* accelMult
;
240 /* Clip to the current screen size */
241 if (posX
< 0) PosX
= 0;
242 else if (posX
>= width
) PosX
= width
- 1;
245 if (posY
< 0) PosY
= 0;
246 else if (posY
>= height
) PosY
= height
- 1;
250 if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
252 queue_raw_mouse_message( WM_MOUSEMOVE
, flags
, PosX
, PosY
, mi
);
254 if (mi
->dwFlags
& MOUSEEVENTF_LEFTDOWN
)
256 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
257 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
258 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONDOWN
: WM_LBUTTONDOWN
,
259 flags
, PosX
, PosY
, mi
);
261 if (mi
->dwFlags
& MOUSEEVENTF_LEFTUP
)
263 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
264 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONUP
: WM_LBUTTONUP
,
265 flags
, PosX
, PosY
, mi
);
267 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTDOWN
)
269 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
270 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
271 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONDOWN
: WM_RBUTTONDOWN
,
272 flags
, PosX
, PosY
, mi
);
274 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTUP
)
276 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
277 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONUP
: WM_RBUTTONUP
,
278 flags
, PosX
, PosY
, mi
);
280 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
282 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
283 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
284 queue_raw_mouse_message( WM_MBUTTONDOWN
, flags
, PosX
, PosY
, mi
);
286 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEUP
)
288 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
289 queue_raw_mouse_message( WM_MBUTTONUP
, flags
, PosX
, PosY
, mi
);
291 if (mi
->dwFlags
& MOUSEEVENTF_WHEEL
)
293 queue_raw_mouse_message( WM_MOUSEWHEEL
, flags
, PosX
, PosY
, mi
);
295 if (flags
& LLMHF_INJECTED
) /* we have to actually move the cursor */
296 SetCursorPos( PosX
, PosY
);
300 /***********************************************************************
301 * SendInput (USER32.@)
303 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
307 if (!InputEnabled
) return 0;
309 for (i
= 0; i
< count
; i
++, inputs
++)
314 queue_mouse_event( &inputs
->u
.mi
, LLMHF_INJECTED
);
316 case WINE_INTERNAL_INPUT_MOUSE
:
317 queue_mouse_event( &inputs
->u
.mi
, 0 );
320 queue_kbd_event( &inputs
->u
.ki
, LLKHF_INJECTED
);
322 case WINE_INTERNAL_INPUT_KEYBOARD
:
323 queue_kbd_event( &inputs
->u
.ki
, 0 );
326 FIXME( "INPUT_HARDWARE not supported\n" );
334 /***********************************************************************
335 * keybd_event (USER32.@)
337 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
338 DWORD dwFlags
, DWORD dwExtraInfo
)
342 input
.type
= INPUT_KEYBOARD
;
343 input
.u
.ki
.wVk
= bVk
;
344 input
.u
.ki
.wScan
= bScan
;
345 input
.u
.ki
.dwFlags
= dwFlags
;
346 input
.u
.ki
.time
= GetTickCount();
347 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
348 SendInput( 1, &input
, sizeof(input
) );
352 /***********************************************************************
353 * keybd_event (USER.289)
355 void WINAPI
keybd_event16( CONTEXT86
*context
)
359 if (AH_reg(context
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
360 if (BH_reg(context
) & 1 ) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
362 keybd_event( AL_reg(context
), BL_reg(context
),
363 dwFlags
, MAKELONG(SI_reg(context
), DI_reg(context
)) );
367 /***********************************************************************
368 * mouse_event (USER32.@)
370 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
371 DWORD dwData
, DWORD dwExtraInfo
)
375 input
.type
= INPUT_MOUSE
;
378 input
.u
.mi
.mouseData
= dwData
;
379 input
.u
.mi
.dwFlags
= dwFlags
;
380 input
.u
.mi
.time
= GetCurrentTime();
381 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
382 SendInput( 1, &input
, sizeof(input
) );
386 /***********************************************************************
387 * mouse_event (USER.299)
389 void WINAPI
mouse_event16( CONTEXT86
*context
)
391 mouse_event( AX_reg(context
), BX_reg(context
), CX_reg(context
),
392 DX_reg(context
), MAKELONG(SI_reg(context
), DI_reg(context
)) );
395 /***********************************************************************
396 * GetMouseEventProc (USER.337)
398 FARPROC16 WINAPI
GetMouseEventProc16(void)
400 HMODULE16 hmodule
= GetModuleHandle16("USER");
401 return GetProcAddress16( hmodule
, "mouse_event" );
405 /**********************************************************************
406 * EnableHardwareInput (USER.331)
408 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
410 BOOL16 bOldState
= InputEnabled
;
411 FIXME_(event
)("(%d) - stub\n", bEnable
);
412 InputEnabled
= bEnable
;
417 /***********************************************************************
418 * SwapMouseButton (USER.186)
420 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
422 BOOL16 ret
= SwappedButtons
;
423 SwappedButtons
= fSwap
;
428 /***********************************************************************
429 * SwapMouseButton (USER32.@)
431 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
433 BOOL ret
= SwappedButtons
;
434 SwappedButtons
= fSwap
;
439 /***********************************************************************
440 * GetCursorPos (USER.17)
442 BOOL16 WINAPI
GetCursorPos16( POINT16
*pt
)
453 /***********************************************************************
454 * GetCursorPos (USER32.@)
456 BOOL WINAPI
GetCursorPos( POINT
*pt
)
461 if (USER_Driver
.pGetCursorPos
) USER_Driver
.pGetCursorPos( pt
);
466 /***********************************************************************
467 * SetCursorPos (USER.70)
469 void WINAPI
SetCursorPos16( INT16 x
, INT16 y
)
471 SetCursorPos( x
, y
);
475 /***********************************************************************
476 * SetCursorPos (USER32.@)
478 BOOL WINAPI
SetCursorPos( INT x
, INT y
)
480 if (USER_Driver
.pSetCursorPos
) USER_Driver
.pSetCursorPos( x
, y
);
487 /**********************************************************************
490 * We need this to be able to generate double click messages
491 * when menu code captures mouse in the window without CS_DBLCLK style.
493 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
495 HWND capturePrev
= 0, captureWnd
= 0;
496 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
500 capturePrev
= GetCapture();
509 wndPtr
= WIN_FindWndPtr( hwnd
);
512 TRACE_(win
)("(0x%04x)\n", hwnd
);
513 captureWnd
= wndPtr
->hwndSelf
;
518 /* Get the messageQ for the current thread */
519 if (!(pCurMsgQ
= QUEUE_Current()))
521 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
525 /* Update the perQ capture window and send messages */
526 if( capturePrev
!= captureWnd
)
530 /* Retrieve the message queue associated with this window */
531 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
534 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
538 /* Make sure that message queue for the window we are setting capture to
539 * shares the same perQ data as the current threads message queue.
541 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
545 PERQDATA_SetCaptureWnd( captureWnd
, captureHT
);
546 if (capturePrev
) SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
550 /* Unlock the queues before returning */
552 QUEUE_Unlock( pMsgQ
);
554 WIN_ReleaseWndPtr(wndPtr
);
559 /**********************************************************************
560 * SetCapture (USER32.@)
562 HWND WINAPI
SetCapture( HWND hwnd
)
564 return EVENT_Capture( hwnd
, HTCLIENT
);
568 /**********************************************************************
569 * ReleaseCapture (USER32.@)
571 BOOL WINAPI
ReleaseCapture(void)
573 return (EVENT_Capture( 0, 0 ) != 0);
577 /**********************************************************************
578 * GetCapture (USER32.@)
580 HWND WINAPI
GetCapture(void)
583 return PERQDATA_GetCaptureWnd( &hittest
);
586 /**********************************************************************
587 * GetAsyncKeyState (USER32.@)
589 * Determine if a key is or was pressed. retval has high-order
590 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
593 * This uses the variable AsyncMouseButtonsStates and
594 * AsyncKeyStateTable (set in event.c) which have the mouse button
595 * number or key number (whichever is applicable) set to true if the
596 * mouse or key had been depressed since the last call to
599 WORD WINAPI
GetAsyncKeyState(INT nKey
)
601 WORD retval
= ((AsyncKeyStateTable
[nKey
] & 0x80) ? 0x0001 : 0) |
602 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
603 AsyncKeyStateTable
[nKey
] = 0;
604 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
608 /**********************************************************************
609 * GetAsyncKeyState (USER.249)
611 WORD WINAPI
GetAsyncKeyState16(INT16 nKey
)
613 return GetAsyncKeyState(nKey
);
616 /***********************************************************************
617 * IsUserIdle (USER.333)
619 BOOL16 WINAPI
IsUserIdle16(void)
621 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
624 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
627 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
630 /* Should check for screen saver activation here ... */
635 /**********************************************************************
636 * VkKeyScanA (USER32.@)
638 * VkKeyScan translates an ANSI character to a virtual-key and shift code
639 * for the current keyboard.
640 * high-order byte yields :
644 * 3-5 Shift-key combinations that are not used for characters
647 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
648 * FIXME : works ok except for dead chars :
649 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
650 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
652 WORD WINAPI
VkKeyScanA(CHAR cChar
)
654 return USER_Driver
.pVkKeyScan( cChar
);
657 /******************************************************************************
658 * VkKeyScanW (USER32.@)
660 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
662 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
665 /**********************************************************************
666 * VkKeyScanExA (USER32.@)
668 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
670 /* FIXME: complete workaround this is */
671 return VkKeyScanA(cChar
);
674 /******************************************************************************
675 * VkKeyScanExW (USER32.@)
677 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
679 /* FIXME: complete workaround this is */
680 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
683 /******************************************************************************
684 * GetKeyboardType (USER32.@)
686 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
688 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
691 case 0: /* Keyboard type */
692 return 4; /* AT-101 */
693 case 1: /* Keyboard Subtype */
694 return 0; /* There are no defined subtypes */
695 case 2: /* Number of F-keys */
696 return 12; /* We're doing an 101 for now, so return 12 F-keys */
698 WARN_(keyboard
)("Unknown type\n");
699 return 0; /* The book says 0 here, so 0 */
703 /******************************************************************************
704 * MapVirtualKeyA (USER32.@)
706 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
708 return USER_Driver
.pMapVirtualKey( code
, maptype
);
711 /******************************************************************************
712 * MapVirtualKeyW (USER32.@)
714 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
716 return MapVirtualKeyA(code
,maptype
);
719 /******************************************************************************
720 * MapVirtualKeyExA (USER32.@)
722 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
725 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
726 return MapVirtualKeyA(code
,maptype
);
729 /******************************************************************************
730 * MapVirtualKeyExW (USER32.@)
732 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
735 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
736 return MapVirtualKeyA(code
,maptype
);
739 /****************************************************************************
740 * GetKBCodePage (USER32.@)
742 UINT WINAPI
GetKBCodePage(void)
747 /****************************************************************************
748 * GetKeyboardLayoutName (USER.477)
750 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
752 return GetKeyboardLayoutNameA(pwszKLID
);
755 /***********************************************************************
756 * GetKeyboardLayout (USER32.@)
758 * FIXME: - device handle for keyboard layout defaulted to
759 * the language id. This is the way Windows default works.
760 * - the thread identifier (dwLayout) is also ignored.
762 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
765 layout
= GetSystemDefaultLCID(); /* FIXME */
766 layout
|= (layout
<<16); /* FIXME */
767 TRACE_(keyboard
)("returning %08x\n",layout
);
771 /****************************************************************************
772 * GetKeyboardLayoutNameA (USER32.@)
774 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
776 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
780 /****************************************************************************
781 * GetKeyboardLayoutNameW (USER32.@)
783 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
785 char buf
[KL_NAMELENGTH
];
786 int res
= GetKeyboardLayoutNameA(buf
);
787 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, pwszKLID
, KL_NAMELENGTH
);
791 /****************************************************************************
792 * GetKeyNameTextA (USER32.@)
794 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
796 return USER_Driver
.pGetKeyNameText( lParam
, lpBuffer
, nSize
);
799 /****************************************************************************
800 * GetKeyNameTextW (USER32.@)
802 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
805 LPSTR buf
= HeapAlloc( GetProcessHeap(), 0, nSize
);
806 if(buf
== NULL
) return 0; /* FIXME: is this the correct failure value?*/
807 res
= GetKeyNameTextA(lParam
,buf
,nSize
);
809 if (nSize
> 0 && !MultiByteToWideChar( CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
))
810 lpBuffer
[nSize
-1] = 0;
811 HeapFree( GetProcessHeap(), 0, buf
);
815 /****************************************************************************
816 * ToUnicode (USER32.@)
818 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
819 LPWSTR lpwStr
, int size
, UINT flags
)
821 return USER_Driver
.pToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
824 /****************************************************************************
825 * ToUnicodeEx (USER32.@)
827 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
828 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
830 /* FIXME: need true implementation */
831 return ToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
834 /****************************************************************************
837 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
838 LPWORD lpChar
,UINT flags
)
843 ret
= ToUnicode(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
);
844 if(ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
846 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
850 /****************************************************************************
851 * ToAsciiEx (USER32.@)
853 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
854 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
856 /* FIXME: need true implementation */
857 return ToAscii(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
);
860 /**********************************************************************
861 * ActivateKeyboardLayout (USER32.@)
863 * Call ignored. WINE supports only system default keyboard layout.
865 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
867 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
868 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
873 /***********************************************************************
874 * GetKeyboardLayoutList (USER32.@)
876 * FIXME: Supports only the system default language and layout and
877 * returns only 1 value.
879 * Return number of values available if either input parm is
880 * 0, per MS documentation.
883 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
885 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
886 if (!nBuff
|| !layouts
)
889 layouts
[0] = GetKeyboardLayout(0);
894 /***********************************************************************
895 * RegisterHotKey (USER32.@)
897 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
898 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
902 /***********************************************************************
903 * UnregisterHotKey (USER32.@)
905 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
906 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
910 /***********************************************************************
911 * LoadKeyboardLayoutA (USER32.@)
912 * Call ignored. WINE supports only system default keyboard layout.
914 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
916 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
917 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
921 /***********************************************************************
922 * LoadKeyboardLayoutW (USER32.@)
924 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
928 WideCharToMultiByte( CP_ACP
, 0, pwszKLID
, -1, buf
, sizeof(buf
), NULL
, NULL
);
930 return LoadKeyboardLayoutA(buf
, Flags
);
934 typedef struct __TRACKINGLIST
{
936 POINT pos
; /* center of hover rectangle */
937 INT iHoverTime
; /* elapsed time the cursor has been inside of the hover rect */
940 static _TRACKINGLIST TrackingList
[10];
941 static int iTrackMax
= 0;
942 static UINT_PTR timer
;
943 static const INT iTimerInterval
= 50; /* msec for timer interval */
945 /* FIXME: need to implement WM_NCMOUSELEAVE and WM_NCMOUSEHOVER for */
946 /* TrackMouseEventProc and _TrackMouseEvent */
947 static void CALLBACK
TrackMouseEventProc(HWND hwndUnused
, UINT uMsg
, UINT_PTR idEvent
,
953 INT hoverwidth
= 0, hoverheight
= 0;
956 hwnd
= WindowFromPoint(pos
);
958 SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
959 SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
961 /* loop through tracking events we are processing */
962 while (i
< iTrackMax
) {
963 /* see if this tracking event is looking for TME_LEAVE and that the */
964 /* mouse has left the window */
965 if ((TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
) &&
966 (TrackingList
[i
].tme
.hwndTrack
!= hwnd
)) {
967 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
969 /* remove the TME_LEAVE flag */
970 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
973 /* see if we are tracking hovering for this hwnd */
974 if(TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) {
975 /* add the timer interval to the hovering time */
976 TrackingList
[i
].iHoverTime
+=iTimerInterval
;
978 /* has the cursor moved outside the rectangle centered around pos? */
979 if((abs(pos
.x
- TrackingList
[i
].pos
.x
) > (hoverwidth
/ 2.0))
980 || (abs(pos
.y
- TrackingList
[i
].pos
.y
) > (hoverheight
/ 2.0)))
982 /* record this new position as the current position and reset */
983 /* the iHoverTime variable to 0 */
984 TrackingList
[i
].pos
= pos
;
985 TrackingList
[i
].iHoverTime
= 0;
988 /* has the mouse hovered long enough? */
989 if(TrackingList
[i
].iHoverTime
<= TrackingList
[i
].tme
.dwHoverTime
)
991 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSEHOVER
, 0, 0);
993 /* stop tracking mouse hover */
994 TrackingList
[i
].tme
.dwFlags
^= TME_HOVER
;
998 /* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
999 if((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
1000 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)) {
1002 } else { /* remove this entry from the tracking list */
1003 TrackingList
[i
] = TrackingList
[--iTrackMax
];
1007 /* stop the timer if the tracking list is empty */
1008 if(iTrackMax
== 0) {
1009 KillTimer(0, timer
);
1015 /***********************************************************************
1016 * TrackMouseEvent [USER32]
1018 * Requests notification of mouse events
1020 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1021 * to the hwnd specified in the ptme structure. After the event message
1022 * is posted to the hwnd, the entry in the queue is removed.
1024 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1025 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1026 * immediately and the TME_LEAVE flag being ignored.
1029 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1038 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1042 BOOL cancel
= 0, hover
= 0, leave
= 0, query
= 0;
1049 TRACE("%lx, %lx, %x, %lx\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1051 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1052 WARN("wrong TRACKMOUSEEVENT size from app\n");
1053 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME not sure if this is correct */
1057 flags
= ptme
->dwFlags
;
1059 /* if HOVER_DEFAULT was specified replace this with the systems current value */
1060 if(ptme
->dwHoverTime
== HOVER_DEFAULT
)
1061 SystemParametersInfoA(SPI_GETMOUSEHOVERTIME
, 0, &(ptme
->dwHoverTime
), 0);
1064 hwnd
= WindowFromPoint(pos
);
1066 if ( flags
& TME_CANCEL
) {
1067 flags
&= ~ TME_CANCEL
;
1071 if ( flags
& TME_HOVER
) {
1072 flags
&= ~ TME_HOVER
;
1076 if ( flags
& TME_LEAVE
) {
1077 flags
&= ~ TME_LEAVE
;
1081 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1082 if ( flags
& TME_QUERY
) {
1083 flags
&= ~ TME_QUERY
;
1087 /* Find the tracking list entry with the matching hwnd */
1088 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1092 /* hwnd found, fill in the ptme struct */
1094 *ptme
= TrackingList
[i
].tme
;
1098 return TRUE
; /* return here, TME_QUERY is retrieving information */
1102 FIXME("Unknown flag(s) %08lx\n", flags
);
1105 /* find a matching hwnd if one exists */
1108 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1113 TrackingList
[i
].tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1115 /* if we aren't tracking on hover or leave remove this entry */
1116 if(!((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
1117 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)))
1119 TrackingList
[i
] = TrackingList
[--iTrackMax
];
1121 if(iTrackMax
== 0) {
1122 KillTimer(0, timer
);
1128 /* see if hwndTrack isn't the current window */
1129 if(ptme
->hwndTrack
!= hwnd
) {
1131 PostMessageA(ptme
->hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1134 /* See if this hwnd is already being tracked and update the tracking flags */
1135 for(i
= 0; i
< iTrackMax
; i
++) {
1136 if(TrackingList
[i
].tme
.hwndTrack
== ptme
->hwndTrack
) {
1138 TrackingList
[i
].tme
.dwFlags
|= TME_HOVER
;
1139 TrackingList
[i
].tme
.dwHoverTime
= ptme
->dwHoverTime
;
1143 TrackingList
[i
].tme
.dwFlags
|= TME_LEAVE
;
1145 /* reset iHoverTime as per winapi specs */
1146 TrackingList
[i
].iHoverTime
= 0;
1152 /* if the tracking list is full return FALSE */
1153 if (iTrackMax
== sizeof (TrackingList
) / sizeof(*TrackingList
)) {
1157 /* Adding new mouse event to the tracking list */
1158 TrackingList
[iTrackMax
].tme
= *ptme
;
1160 /* Initialize HoverInfo variables even if not hover tracking */
1161 TrackingList
[iTrackMax
].iHoverTime
= 0;
1162 TrackingList
[iTrackMax
].pos
= pos
;
1167 timer
= SetTimer(0, 0, iTimerInterval
, TrackMouseEventProc
);