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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "wine/winbase16.h"
37 #include "wine/winuser16.h"
38 #include "wine/server.h"
42 #include "wine/debug.h"
45 WINE_DECLARE_DEBUG_CHANNEL(key
);
46 WINE_DECLARE_DEBUG_CHANNEL(keyboard
);
47 WINE_DECLARE_DEBUG_CHANNEL(win
);
48 WINE_DEFAULT_DEBUG_CHANNEL(event
);
50 static BOOL InputEnabled
= TRUE
;
51 static BOOL SwappedButtons
;
53 BYTE InputKeyStateTable
[256];
54 BYTE AsyncKeyStateTable
[256];
56 /* Storage for the USER-maintained mouse positions */
57 static DWORD PosX
, PosY
;
63 unsigned long count
: 16;
64 unsigned long code
: 8;
65 unsigned long extended
: 1;
66 unsigned long unused
: 2;
67 unsigned long win_internal
: 2;
68 unsigned long context
: 1;
69 unsigned long previous
: 1;
70 unsigned long transition
: 1;
76 /***********************************************************************
79 static WORD
get_key_state(void)
85 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
86 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
90 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
91 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
93 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) ret
|= MK_MBUTTON
;
94 if (InputKeyStateTable
[VK_SHIFT
] & 0x80) ret
|= MK_SHIFT
;
95 if (InputKeyStateTable
[VK_CONTROL
] & 0x80) ret
|= MK_CONTROL
;
96 if (InputKeyStateTable
[VK_XBUTTON1
] & 0x80) ret
|= MK_XBUTTON1
;
97 if (InputKeyStateTable
[VK_XBUTTON2
] & 0x80) ret
|= MK_XBUTTON2
;
102 /***********************************************************************
103 * queue_raw_hardware_message
105 * Add a message to the raw hardware queue.
106 * Note: the position is relative to the desktop window.
108 static void queue_raw_hardware_message( UINT message
, WPARAM wParam
, LPARAM lParam
,
109 int xPos
, int yPos
, DWORD time
, ULONG_PTR extraInfo
)
111 SERVER_START_REQ( send_message
)
113 req
->id
= GetCurrentThreadId();
114 req
->type
= MSG_HARDWARE_RAW
;
117 req
->wparam
= wParam
;
118 req
->lparam
= lParam
;
122 req
->info
= extraInfo
;
124 wine_server_call( req
);
130 /***********************************************************************
133 * Put a keyboard event into a thread queue
135 static void queue_kbd_event( const KEYBDINPUT
*ki
, UINT injected_flags
)
139 KBDLLHOOKSTRUCT hook
;
143 keylp
.lp1
.code
= ki
->wScan
;
144 keylp
.lp1
.extended
= (ki
->dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
145 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
146 * don't remember where I read it - AK */
147 /* it's '1' under windows, when a dialog box appears
148 * and you press one of the underlined keys - DF*/
150 if (ki
->dwFlags
& KEYEVENTF_KEYUP
)
152 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80) &&
153 !(InputKeyStateTable
[VK_CONTROL
] & 0x80);
154 InputKeyStateTable
[ki
->wVk
] &= ~0x80;
155 keylp
.lp1
.previous
= 1;
156 keylp
.lp1
.transition
= 1;
157 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
161 keylp
.lp1
.previous
= (InputKeyStateTable
[ki
->wVk
] & 0x80) != 0;
162 keylp
.lp1
.transition
= 0;
163 if (!(InputKeyStateTable
[ki
->wVk
] & 0x80)) InputKeyStateTable
[ki
->wVk
] ^= 0x01;
164 InputKeyStateTable
[ki
->wVk
] |= 0x80;
165 AsyncKeyStateTable
[ki
->wVk
] |= 0x80;
167 message
= (InputKeyStateTable
[VK_MENU
] & 0x80) && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
168 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
171 if (message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
172 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
174 TRACE_(key
)(" wParam=%04x, lParam=%08lx, InputKeyState=%x\n",
175 ki
->wVk
, keylp
.lp2
, InputKeyStateTable
[ki
->wVk
] );
177 hook
.vkCode
= ki
->wVk
;
178 hook
.scanCode
= ki
->wScan
;
179 hook
.flags
= (keylp
.lp2
>> 24) | injected_flags
;
180 hook
.time
= ki
->time
;
181 hook
.dwExtraInfo
= ki
->dwExtraInfo
;
182 if (!HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, message
, (LPARAM
)&hook
, TRUE
))
183 queue_raw_hardware_message( message
, ki
->wVk
, keylp
.lp2
,
184 PosX
, PosY
, ki
->time
, ki
->dwExtraInfo
);
188 /***********************************************************************
189 * queue_raw_mouse_message
191 static void queue_raw_mouse_message( UINT message
, UINT flags
, INT x
, INT y
, const MOUSEINPUT
*mi
)
197 hook
.mouseData
= MAKELONG( 0, mi
->mouseData
);
199 hook
.time
= mi
->time
;
200 hook
.dwExtraInfo
= mi
->dwExtraInfo
;
202 if (!HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, message
, (LPARAM
)&hook
, TRUE
))
203 queue_raw_hardware_message( message
, MAKEWPARAM( get_key_state(), mi
->mouseData
),
204 0, x
, y
, mi
->time
, mi
->dwExtraInfo
);
208 /***********************************************************************
211 static void queue_mouse_event( const MOUSEINPUT
*mi
, UINT flags
)
213 if (mi
->dwFlags
& MOUSEEVENTF_ABSOLUTE
)
215 PosX
= (mi
->dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
216 PosY
= (mi
->dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
218 else if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
220 int width
= GetSystemMetrics(SM_CXSCREEN
);
221 int height
= GetSystemMetrics(SM_CYSCREEN
);
222 long posX
= (long) PosX
, posY
= (long) PosY
;
226 /* dx and dy can be negative numbers for relative movements */
227 SystemParametersInfoA(SPI_GETMOUSE
, 0, accel
, 0);
230 if (mi
->dx
> accel
[0] && accel
[2] != 0)
233 if ((mi
->dx
> accel
[1]) && (accel
[2] == 2))
238 posX
+= (long)mi
->dx
* accelMult
;
241 if (mi
->dy
> accel
[0] && accel
[2] != 0)
244 if ((mi
->dy
> accel
[1]) && (accel
[2] == 2))
249 posY
+= (long)mi
->dy
* accelMult
;
251 /* Clip to the current screen size */
252 if (posX
< 0) PosX
= 0;
253 else if (posX
>= width
) PosX
= width
- 1;
256 if (posY
< 0) PosY
= 0;
257 else if (posY
>= height
) PosY
= height
- 1;
261 if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
263 queue_raw_mouse_message( WM_MOUSEMOVE
, flags
, PosX
, PosY
, mi
);
265 if (mi
->dwFlags
& MOUSEEVENTF_LEFTDOWN
)
267 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
268 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
269 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONDOWN
: WM_LBUTTONDOWN
,
270 flags
, PosX
, PosY
, mi
);
272 if (mi
->dwFlags
& MOUSEEVENTF_LEFTUP
)
274 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
275 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONUP
: WM_LBUTTONUP
,
276 flags
, PosX
, PosY
, mi
);
278 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTDOWN
)
280 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
281 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
282 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONDOWN
: WM_RBUTTONDOWN
,
283 flags
, PosX
, PosY
, mi
);
285 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTUP
)
287 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
288 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONUP
: WM_RBUTTONUP
,
289 flags
, PosX
, PosY
, mi
);
291 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
293 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
294 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
295 queue_raw_mouse_message( WM_MBUTTONDOWN
, flags
, PosX
, PosY
, mi
);
297 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEUP
)
299 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
300 queue_raw_mouse_message( WM_MBUTTONUP
, flags
, PosX
, PosY
, mi
);
302 if (mi
->dwFlags
& MOUSEEVENTF_WHEEL
)
304 queue_raw_mouse_message( WM_MOUSEWHEEL
, flags
, PosX
, PosY
, mi
);
306 if (flags
& LLMHF_INJECTED
) /* we have to actually move the cursor */
307 SetCursorPos( PosX
, PosY
);
311 /***********************************************************************
312 * SendInput (USER32.@)
314 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
318 if (!InputEnabled
) return 0;
320 for (i
= 0; i
< count
; i
++, inputs
++)
325 queue_mouse_event( &inputs
->u
.mi
, LLMHF_INJECTED
);
327 case WINE_INTERNAL_INPUT_MOUSE
:
328 queue_mouse_event( &inputs
->u
.mi
, 0 );
331 queue_kbd_event( &inputs
->u
.ki
, LLKHF_INJECTED
);
333 case WINE_INTERNAL_INPUT_KEYBOARD
:
334 queue_kbd_event( &inputs
->u
.ki
, 0 );
337 FIXME( "INPUT_HARDWARE not supported\n" );
345 /***********************************************************************
346 * keybd_event (USER32.@)
348 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
349 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
353 input
.type
= INPUT_KEYBOARD
;
354 input
.u
.ki
.wVk
= bVk
;
355 input
.u
.ki
.wScan
= bScan
;
356 input
.u
.ki
.dwFlags
= dwFlags
;
357 input
.u
.ki
.time
= GetTickCount();
358 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
359 SendInput( 1, &input
, sizeof(input
) );
363 /***********************************************************************
364 * keybd_event (USER.289)
366 void WINAPI
keybd_event16( CONTEXT86
*context
)
370 if (HIBYTE(context
->Eax
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
371 if (HIBYTE(context
->Ebx
) & 0x01) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
373 keybd_event( LOBYTE(context
->Eax
), LOBYTE(context
->Ebx
),
374 dwFlags
, MAKELONG(LOWORD(context
->Esi
), LOWORD(context
->Edi
)) );
378 /***********************************************************************
379 * mouse_event (USER32.@)
381 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
382 DWORD dwData
, ULONG_PTR dwExtraInfo
)
386 input
.type
= INPUT_MOUSE
;
389 input
.u
.mi
.mouseData
= dwData
;
390 input
.u
.mi
.dwFlags
= dwFlags
;
391 input
.u
.mi
.time
= GetCurrentTime();
392 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
393 SendInput( 1, &input
, sizeof(input
) );
397 /***********************************************************************
398 * mouse_event (USER.299)
400 void WINAPI
mouse_event16( CONTEXT86
*context
)
402 mouse_event( LOWORD(context
->Eax
), LOWORD(context
->Ebx
), LOWORD(context
->Ecx
),
403 LOWORD(context
->Edx
), MAKELONG(context
->Esi
, context
->Edi
) );
406 /***********************************************************************
407 * GetMouseEventProc (USER.337)
409 FARPROC16 WINAPI
GetMouseEventProc16(void)
411 HMODULE16 hmodule
= GetModuleHandle16("USER");
412 return GetProcAddress16( hmodule
, "mouse_event" );
416 /**********************************************************************
417 * EnableHardwareInput (USER.331)
419 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
421 BOOL16 bOldState
= InputEnabled
;
422 FIXME_(event
)("(%d) - stub\n", bEnable
);
423 InputEnabled
= bEnable
;
428 /***********************************************************************
429 * SwapMouseButton (USER.186)
431 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
433 BOOL16 ret
= SwappedButtons
;
434 SwappedButtons
= fSwap
;
439 /***********************************************************************
440 * SwapMouseButton (USER32.@)
442 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
444 BOOL ret
= SwappedButtons
;
445 SwappedButtons
= fSwap
;
450 /***********************************************************************
451 * GetCursorPos (USER.17)
453 BOOL16 WINAPI
GetCursorPos16( POINT16
*pt
)
464 /***********************************************************************
465 * GetCursorPos (USER32.@)
467 BOOL WINAPI
GetCursorPos( POINT
*pt
)
472 if (USER_Driver
.pGetCursorPos
) USER_Driver
.pGetCursorPos( pt
);
477 /***********************************************************************
478 * GetCursorInfo (USER32.@)
480 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
482 MESSAGEQUEUE
*queue
= QUEUE_Current();
485 if (queue
->cursor_count
>= 0) pci
->flags
= CURSOR_SHOWING
;
487 GetCursorPos(&pci
->ptScreenPos
);
492 /***********************************************************************
493 * SetCursorPos (USER.70)
495 void WINAPI
SetCursorPos16( INT16 x
, INT16 y
)
497 SetCursorPos( x
, y
);
501 /***********************************************************************
502 * SetCursorPos (USER32.@)
504 BOOL WINAPI
SetCursorPos( INT x
, INT y
)
506 if (USER_Driver
.pSetCursorPos
) USER_Driver
.pSetCursorPos( x
, y
);
513 /**********************************************************************
514 * SetCapture (USER32.@)
516 HWND WINAPI
SetCapture( HWND hwnd
)
520 SERVER_START_REQ( set_capture_window
)
524 if (!wine_server_call_err( req
))
526 previous
= reply
->previous
;
527 hwnd
= reply
->full_handle
;
532 if (previous
&& previous
!= hwnd
)
533 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
538 /**********************************************************************
539 * ReleaseCapture (USER32.@)
541 BOOL WINAPI
ReleaseCapture(void)
543 return (SetCapture(0) != 0);
547 /**********************************************************************
548 * GetCapture (USER32.@)
550 HWND WINAPI
GetCapture(void)
554 SERVER_START_REQ( get_thread_input
)
556 req
->tid
= GetCurrentThreadId();
557 if (!wine_server_call_err( req
)) ret
= reply
->capture
;
564 /**********************************************************************
565 * GetAsyncKeyState (USER32.@)
567 * Determine if a key is or was pressed. retval has high-order
568 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
571 * This uses the variable AsyncMouseButtonsStates and
572 * AsyncKeyStateTable (set in event.c) which have the mouse button
573 * number or key number (whichever is applicable) set to true if the
574 * mouse or key had been depressed since the last call to
577 SHORT WINAPI
GetAsyncKeyState(INT nKey
)
579 SHORT retval
= ((AsyncKeyStateTable
[nKey
] & 0x80) ? 0x0001 : 0) |
580 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
581 AsyncKeyStateTable
[nKey
] = 0;
582 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
586 /**********************************************************************
587 * GetAsyncKeyState (USER.249)
589 INT16 WINAPI
GetAsyncKeyState16(INT16 nKey
)
591 return GetAsyncKeyState(nKey
);
594 /***********************************************************************
595 * IsUserIdle (USER.333)
597 BOOL16 WINAPI
IsUserIdle16(void)
599 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
602 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
605 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
608 /* Should check for screen saver activation here ... */
613 /**********************************************************************
614 * VkKeyScanA (USER32.@)
616 * VkKeyScan translates an ANSI character to a virtual-key and shift code
617 * for the current keyboard.
618 * high-order byte yields :
622 * 3-5 Shift-key combinations that are not used for characters
625 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
626 * FIXME : works ok except for dead chars :
627 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
628 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
630 WORD WINAPI
VkKeyScanA(CHAR cChar
)
632 return USER_Driver
.pVkKeyScan( cChar
);
635 /******************************************************************************
636 * VkKeyScanW (USER32.@)
638 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
640 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
643 /**********************************************************************
644 * VkKeyScanExA (USER32.@)
646 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
648 /* FIXME: complete workaround this is */
649 return VkKeyScanA(cChar
);
652 /******************************************************************************
653 * VkKeyScanExW (USER32.@)
655 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
657 /* FIXME: complete workaround this is */
658 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
661 /******************************************************************************
662 * GetKeyboardType (USER32.@)
664 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
666 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
669 case 0: /* Keyboard type */
670 return 4; /* AT-101 */
671 case 1: /* Keyboard Subtype */
672 return 0; /* There are no defined subtypes */
673 case 2: /* Number of F-keys */
674 return 12; /* We're doing an 101 for now, so return 12 F-keys */
676 WARN_(keyboard
)("Unknown type\n");
677 return 0; /* The book says 0 here, so 0 */
681 /******************************************************************************
682 * MapVirtualKeyA (USER32.@)
684 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
686 return USER_Driver
.pMapVirtualKey( code
, maptype
);
689 /******************************************************************************
690 * MapVirtualKeyW (USER32.@)
692 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
694 return MapVirtualKeyA(code
,maptype
);
697 /******************************************************************************
698 * MapVirtualKeyExA (USER32.@)
700 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
703 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
704 return MapVirtualKeyA(code
,maptype
);
707 /******************************************************************************
708 * MapVirtualKeyExW (USER32.@)
710 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
713 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
714 return MapVirtualKeyA(code
,maptype
);
717 /****************************************************************************
718 * GetKBCodePage (USER32.@)
720 UINT WINAPI
GetKBCodePage(void)
725 /****************************************************************************
726 * GetKeyboardLayoutName (USER.477)
728 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
730 return GetKeyboardLayoutNameA(pwszKLID
);
733 /***********************************************************************
734 * GetKeyboardLayout (USER32.@)
736 * FIXME: - device handle for keyboard layout defaulted to
737 * the language id. This is the way Windows default works.
738 * - the thread identifier (dwLayout) is also ignored.
740 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
743 layout
= GetSystemDefaultLCID(); /* FIXME */
744 layout
|= (layout
<<16); /* FIXME */
745 TRACE_(keyboard
)("returning %08x\n",layout
);
749 /****************************************************************************
750 * GetKeyboardLayoutNameA (USER32.@)
752 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
754 sprintf(pwszKLID
, "%p",GetKeyboardLayout(0));
758 /****************************************************************************
759 * GetKeyboardLayoutNameW (USER32.@)
761 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
763 char buf
[KL_NAMELENGTH
];
764 int res
= GetKeyboardLayoutNameA(buf
);
765 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, pwszKLID
, KL_NAMELENGTH
);
769 /****************************************************************************
770 * GetKeyNameTextA (USER32.@)
772 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
774 return USER_Driver
.pGetKeyNameText( lParam
, lpBuffer
, nSize
);
777 /****************************************************************************
778 * GetKeyNameTextW (USER32.@)
780 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
783 LPSTR buf
= HeapAlloc( GetProcessHeap(), 0, nSize
);
784 if(buf
== NULL
) return 0; /* FIXME: is this the correct failure value?*/
785 res
= GetKeyNameTextA(lParam
,buf
,nSize
);
787 if (nSize
> 0 && !MultiByteToWideChar( CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
))
788 lpBuffer
[nSize
-1] = 0;
789 HeapFree( GetProcessHeap(), 0, buf
);
793 /****************************************************************************
794 * ToUnicode (USER32.@)
796 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
797 LPWSTR lpwStr
, int size
, UINT flags
)
799 return USER_Driver
.pToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
802 /****************************************************************************
803 * ToUnicodeEx (USER32.@)
805 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
806 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
808 /* FIXME: need true implementation */
809 return ToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
812 /****************************************************************************
815 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
816 LPWORD lpChar
,UINT flags
)
821 ret
= ToUnicode(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
);
822 if(ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
824 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
828 /****************************************************************************
829 * ToAsciiEx (USER32.@)
831 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
832 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
834 /* FIXME: need true implementation */
835 return ToAscii(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
);
838 /**********************************************************************
839 * ActivateKeyboardLayout (USER32.@)
841 * Call ignored. WINE supports only system default keyboard layout.
843 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
845 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
846 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
851 /***********************************************************************
852 * GetKeyboardLayoutList (USER32.@)
854 * FIXME: Supports only the system default language and layout and
855 * returns only 1 value.
857 * Return number of values available if either input parm is
858 * 0, per MS documentation.
861 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
863 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
864 if (!nBuff
|| !layouts
)
867 layouts
[0] = GetKeyboardLayout(0);
872 /***********************************************************************
873 * RegisterHotKey (USER32.@)
875 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
876 FIXME_(keyboard
)("(%p,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
880 /***********************************************************************
881 * UnregisterHotKey (USER32.@)
883 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
884 FIXME_(keyboard
)("(%p,%d): stub\n",hwnd
,id
);
888 /***********************************************************************
889 * LoadKeyboardLayoutW (USER32.@)
890 * Call ignored. WINE supports only system default keyboard layout.
892 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
894 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
895 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
899 /***********************************************************************
900 * LoadKeyboardLayoutA (USER32.@)
902 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
905 UNICODE_STRING pwszKLIDW
;
907 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
908 else pwszKLIDW
.Buffer
= NULL
;
910 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
911 RtlFreeUnicodeString(&pwszKLIDW
);
916 typedef struct __TRACKINGLIST
{
918 POINT pos
; /* center of hover rectangle */
919 INT iHoverTime
; /* elapsed time the cursor has been inside of the hover rect */
922 static _TRACKINGLIST TrackingList
[10];
923 static int iTrackMax
= 0;
924 static UINT_PTR timer
;
925 static const INT iTimerInterval
= 50; /* msec for timer interval */
927 /* FIXME: need to implement WM_NCMOUSELEAVE and WM_NCMOUSEHOVER for */
928 /* TrackMouseEventProc and _TrackMouseEvent */
929 static void CALLBACK
TrackMouseEventProc(HWND hwndUnused
, UINT uMsg
, UINT_PTR idEvent
,
936 INT hoverwidth
= 0, hoverheight
= 0;
939 hwnd
= WindowFromPoint(pos
);
941 SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
942 SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
944 /* loop through tracking events we are processing */
945 while (i
< iTrackMax
) {
946 /* see if this tracking event is looking for TME_LEAVE and that the */
947 /* mouse has left the window */
948 if ((TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
) &&
949 (TrackingList
[i
].tme
.hwndTrack
!= hwnd
)) {
950 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
952 /* remove the TME_LEAVE flag */
953 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
956 /* see if we are tracking hovering for this hwnd */
957 if(TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) {
958 /* add the timer interval to the hovering time */
959 TrackingList
[i
].iHoverTime
+=iTimerInterval
;
961 /* has the cursor moved outside the rectangle centered around pos? */
962 if((abs(pos
.x
- TrackingList
[i
].pos
.x
) > (hoverwidth
/ 2.0))
963 || (abs(pos
.y
- TrackingList
[i
].pos
.y
) > (hoverheight
/ 2.0)))
965 /* record this new position as the current position and reset */
966 /* the iHoverTime variable to 0 */
967 TrackingList
[i
].pos
= pos
;
968 TrackingList
[i
].iHoverTime
= 0;
971 /* has the mouse hovered long enough? */
972 if(TrackingList
[i
].iHoverTime
<= TrackingList
[i
].tme
.dwHoverTime
)
976 ScreenToClient(hwnd
, &posClient
);
977 PostMessageW(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSEHOVER
,
978 get_key_state(), MAKELPARAM( posClient
.x
, posClient
.y
));
980 /* stop tracking mouse hover */
981 TrackingList
[i
].tme
.dwFlags
^= TME_HOVER
;
985 /* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
986 if((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
987 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)) {
989 } else { /* remove this entry from the tracking list */
990 TrackingList
[i
] = TrackingList
[--iTrackMax
];
994 /* stop the timer if the tracking list is empty */
1002 /***********************************************************************
1003 * TrackMouseEvent [USER32]
1005 * Requests notification of mouse events
1007 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1008 * to the hwnd specified in the ptme structure. After the event message
1009 * is posted to the hwnd, the entry in the queue is removed.
1011 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1012 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1013 * immediately and the TME_LEAVE flag being ignored.
1016 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1025 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1029 BOOL cancel
= 0, hover
= 0, leave
= 0, query
= 0;
1036 TRACE("%lx, %lx, %p, %lx\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1038 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1039 WARN("wrong TRACKMOUSEEVENT size from app\n");
1040 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME not sure if this is correct */
1044 flags
= ptme
->dwFlags
;
1046 /* if HOVER_DEFAULT was specified replace this with the systems current value */
1047 if(ptme
->dwHoverTime
== HOVER_DEFAULT
)
1048 SystemParametersInfoA(SPI_GETMOUSEHOVERTIME
, 0, &(ptme
->dwHoverTime
), 0);
1051 hwnd
= WindowFromPoint(pos
);
1053 if ( flags
& TME_CANCEL
) {
1054 flags
&= ~ TME_CANCEL
;
1058 if ( flags
& TME_HOVER
) {
1059 flags
&= ~ TME_HOVER
;
1063 if ( flags
& TME_LEAVE
) {
1064 flags
&= ~ TME_LEAVE
;
1068 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1069 if ( flags
& TME_QUERY
) {
1070 flags
&= ~ TME_QUERY
;
1074 /* Find the tracking list entry with the matching hwnd */
1075 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1079 /* hwnd found, fill in the ptme struct */
1081 *ptme
= TrackingList
[i
].tme
;
1085 return TRUE
; /* return here, TME_QUERY is retrieving information */
1089 FIXME("Unknown flag(s) %08lx\n", flags
);
1092 /* find a matching hwnd if one exists */
1095 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1100 TrackingList
[i
].tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1102 /* if we aren't tracking on hover or leave remove this entry */
1103 if(!((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
1104 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)))
1106 TrackingList
[i
] = TrackingList
[--iTrackMax
];
1108 if(iTrackMax
== 0) {
1109 KillTimer(0, timer
);
1115 /* see if hwndTrack isn't the current window */
1116 if(ptme
->hwndTrack
!= hwnd
) {
1118 PostMessageA(ptme
->hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1121 /* See if this hwnd is already being tracked and update the tracking flags */
1122 for(i
= 0; i
< iTrackMax
; i
++) {
1123 if(TrackingList
[i
].tme
.hwndTrack
== ptme
->hwndTrack
) {
1125 TrackingList
[i
].tme
.dwFlags
|= TME_HOVER
;
1126 TrackingList
[i
].tme
.dwHoverTime
= ptme
->dwHoverTime
;
1130 TrackingList
[i
].tme
.dwFlags
|= TME_LEAVE
;
1132 /* reset iHoverTime as per winapi specs */
1133 TrackingList
[i
].iHoverTime
= 0;
1139 /* if the tracking list is full return FALSE */
1140 if (iTrackMax
== sizeof (TrackingList
) / sizeof(*TrackingList
)) {
1144 /* Adding new mouse event to the tracking list */
1145 TrackingList
[iTrackMax
].tme
= *ptme
;
1147 /* Initialize HoverInfo variables even if not hover tracking */
1148 TrackingList
[iTrackMax
].iHoverTime
= 0;
1149 TrackingList
[iTrackMax
].pos
= pos
;
1154 timer
= SetTimer(0, 0, iTimerInterval
, TrackMouseEventProc
);