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"
44 #include "wine/debug.h"
47 WINE_DECLARE_DEBUG_CHANNEL(key
);
48 WINE_DECLARE_DEBUG_CHANNEL(keyboard
);
49 WINE_DECLARE_DEBUG_CHANNEL(win
);
50 WINE_DEFAULT_DEBUG_CHANNEL(event
);
52 static BOOL InputEnabled
= TRUE
;
53 static BOOL SwappedButtons
;
55 BYTE InputKeyStateTable
[256];
56 BYTE AsyncKeyStateTable
[256];
58 /* Storage for the USER-maintained mouse positions */
59 static DWORD PosX
, PosY
;
65 unsigned long count
: 16;
66 unsigned long code
: 8;
67 unsigned long extended
: 1;
68 unsigned long unused
: 2;
69 unsigned long win_internal
: 2;
70 unsigned long context
: 1;
71 unsigned long previous
: 1;
72 unsigned long transition
: 1;
78 /***********************************************************************
81 static WORD
get_key_state(void)
87 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
88 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
92 if (InputKeyStateTable
[VK_LBUTTON
] & 0x80) ret
|= MK_LBUTTON
;
93 if (InputKeyStateTable
[VK_RBUTTON
] & 0x80) ret
|= MK_RBUTTON
;
95 if (InputKeyStateTable
[VK_MBUTTON
] & 0x80) ret
|= MK_MBUTTON
;
96 if (InputKeyStateTable
[VK_SHIFT
] & 0x80) ret
|= MK_SHIFT
;
97 if (InputKeyStateTable
[VK_CONTROL
] & 0x80) ret
|= MK_CONTROL
;
98 if (InputKeyStateTable
[VK_XBUTTON1
] & 0x80) ret
|= MK_XBUTTON1
;
99 if (InputKeyStateTable
[VK_XBUTTON2
] & 0x80) ret
|= MK_XBUTTON2
;
104 /***********************************************************************
105 * queue_raw_hardware_message
107 * Add a message to the raw hardware queue.
108 * Note: the position is relative to the desktop window.
110 static void queue_raw_hardware_message( UINT message
, WPARAM wParam
, LPARAM lParam
,
111 int xPos
, int yPos
, DWORD time
, ULONG_PTR extraInfo
)
113 SERVER_START_REQ( send_message
)
115 req
->id
= (void *)GetCurrentThreadId();
116 req
->type
= MSG_HARDWARE_RAW
;
119 req
->wparam
= wParam
;
120 req
->lparam
= lParam
;
124 req
->info
= extraInfo
;
126 wine_server_call( req
);
132 /***********************************************************************
135 * Put a keyboard event into a thread queue
137 static void queue_kbd_event( const KEYBDINPUT
*ki
, UINT injected_flags
)
141 KBDLLHOOKSTRUCT hook
;
145 keylp
.lp1
.code
= ki
->wScan
;
146 keylp
.lp1
.extended
= (ki
->dwFlags
& KEYEVENTF_EXTENDEDKEY
) != 0;
147 keylp
.lp1
.win_internal
= 0; /* this has something to do with dialogs,
148 * don't remember where I read it - AK */
149 /* it's '1' under windows, when a dialog box appears
150 * and you press one of the underlined keys - DF*/
152 if (ki
->dwFlags
& KEYEVENTF_KEYUP
)
154 BOOL sysKey
= (InputKeyStateTable
[VK_MENU
] & 0x80) &&
155 !(InputKeyStateTable
[VK_CONTROL
] & 0x80);
156 InputKeyStateTable
[ki
->wVk
] &= ~0x80;
157 keylp
.lp1
.previous
= 1;
158 keylp
.lp1
.transition
= 1;
159 message
= sysKey
? WM_SYSKEYUP
: WM_KEYUP
;
163 keylp
.lp1
.previous
= (InputKeyStateTable
[ki
->wVk
] & 0x80) != 0;
164 keylp
.lp1
.transition
= 0;
165 if (!(InputKeyStateTable
[ki
->wVk
] & 0x80)) InputKeyStateTable
[ki
->wVk
] ^= 0x01;
166 InputKeyStateTable
[ki
->wVk
] |= 0x80;
167 AsyncKeyStateTable
[ki
->wVk
] |= 0x80;
169 message
= (InputKeyStateTable
[VK_MENU
] & 0x80) && !(InputKeyStateTable
[VK_CONTROL
] & 0x80)
170 ? WM_SYSKEYDOWN
: WM_KEYDOWN
;
173 if (message
== WM_SYSKEYDOWN
|| message
== WM_SYSKEYUP
)
174 keylp
.lp1
.context
= (InputKeyStateTable
[VK_MENU
] & 0x80) != 0; /* 1 if alt */
176 TRACE_(key
)(" wParam=%04x, lParam=%08lx, InputKeyState=%x\n",
177 ki
->wVk
, keylp
.lp2
, InputKeyStateTable
[ki
->wVk
] );
179 hook
.vkCode
= ki
->wVk
;
180 hook
.scanCode
= ki
->wScan
;
181 hook
.flags
= (keylp
.lp2
>> 24) | injected_flags
;
182 hook
.time
= ki
->time
;
183 hook
.dwExtraInfo
= ki
->dwExtraInfo
;
184 if (!HOOK_CallHooksW( WH_KEYBOARD_LL
, HC_ACTION
, message
, (LPARAM
)&hook
))
185 queue_raw_hardware_message( message
, ki
->wVk
, keylp
.lp2
,
186 PosX
, PosY
, ki
->time
, ki
->dwExtraInfo
);
190 /***********************************************************************
191 * queue_raw_mouse_message
193 static void queue_raw_mouse_message( UINT message
, UINT flags
, INT x
, INT y
, const MOUSEINPUT
*mi
)
199 hook
.mouseData
= MAKELONG( 0, mi
->mouseData
);
201 hook
.time
= mi
->time
;
202 hook
.dwExtraInfo
= mi
->dwExtraInfo
;
204 if (!HOOK_CallHooksW( WH_MOUSE_LL
, HC_ACTION
, message
, (LPARAM
)&hook
))
205 queue_raw_hardware_message( message
, MAKEWPARAM( get_key_state(), mi
->mouseData
),
206 0, x
, y
, mi
->time
, mi
->dwExtraInfo
);
210 /***********************************************************************
213 static void queue_mouse_event( const MOUSEINPUT
*mi
, UINT flags
)
215 if (mi
->dwFlags
& MOUSEEVENTF_ABSOLUTE
)
217 PosX
= (mi
->dx
* GetSystemMetrics(SM_CXSCREEN
)) >> 16;
218 PosY
= (mi
->dy
* GetSystemMetrics(SM_CYSCREEN
)) >> 16;
220 else if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
222 int width
= GetSystemMetrics(SM_CXSCREEN
);
223 int height
= GetSystemMetrics(SM_CYSCREEN
);
224 long posX
= (long) PosX
, posY
= (long) PosY
;
228 /* dx and dy can be negative numbers for relative movements */
229 SystemParametersInfoA(SPI_GETMOUSE
, 0, accel
, 0);
232 if (mi
->dx
> accel
[0] && accel
[2] != 0)
235 if ((mi
->dx
> accel
[1]) && (accel
[2] == 2))
240 posX
+= (long)mi
->dx
* accelMult
;
243 if (mi
->dy
> accel
[0] && accel
[2] != 0)
246 if ((mi
->dy
> accel
[1]) && (accel
[2] == 2))
251 posY
+= (long)mi
->dy
* accelMult
;
253 /* Clip to the current screen size */
254 if (posX
< 0) PosX
= 0;
255 else if (posX
>= width
) PosX
= width
- 1;
258 if (posY
< 0) PosY
= 0;
259 else if (posY
>= height
) PosY
= height
- 1;
263 if (mi
->dwFlags
& MOUSEEVENTF_MOVE
)
265 queue_raw_mouse_message( WM_MOUSEMOVE
, flags
, PosX
, PosY
, mi
);
267 if (mi
->dwFlags
& MOUSEEVENTF_LEFTDOWN
)
269 InputKeyStateTable
[VK_LBUTTON
] |= 0x80;
270 AsyncKeyStateTable
[VK_LBUTTON
] |= 0x80;
271 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONDOWN
: WM_LBUTTONDOWN
,
272 flags
, PosX
, PosY
, mi
);
274 if (mi
->dwFlags
& MOUSEEVENTF_LEFTUP
)
276 InputKeyStateTable
[VK_LBUTTON
] &= ~0x80;
277 queue_raw_mouse_message( SwappedButtons
? WM_RBUTTONUP
: WM_LBUTTONUP
,
278 flags
, PosX
, PosY
, mi
);
280 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTDOWN
)
282 InputKeyStateTable
[VK_RBUTTON
] |= 0x80;
283 AsyncKeyStateTable
[VK_RBUTTON
] |= 0x80;
284 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONDOWN
: WM_RBUTTONDOWN
,
285 flags
, PosX
, PosY
, mi
);
287 if (mi
->dwFlags
& MOUSEEVENTF_RIGHTUP
)
289 InputKeyStateTable
[VK_RBUTTON
] &= ~0x80;
290 queue_raw_mouse_message( SwappedButtons
? WM_LBUTTONUP
: WM_RBUTTONUP
,
291 flags
, PosX
, PosY
, mi
);
293 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEDOWN
)
295 InputKeyStateTable
[VK_MBUTTON
] |= 0x80;
296 AsyncKeyStateTable
[VK_MBUTTON
] |= 0x80;
297 queue_raw_mouse_message( WM_MBUTTONDOWN
, flags
, PosX
, PosY
, mi
);
299 if (mi
->dwFlags
& MOUSEEVENTF_MIDDLEUP
)
301 InputKeyStateTable
[VK_MBUTTON
] &= ~0x80;
302 queue_raw_mouse_message( WM_MBUTTONUP
, flags
, PosX
, PosY
, mi
);
304 if (mi
->dwFlags
& MOUSEEVENTF_WHEEL
)
306 queue_raw_mouse_message( WM_MOUSEWHEEL
, flags
, PosX
, PosY
, mi
);
308 if (flags
& LLMHF_INJECTED
) /* we have to actually move the cursor */
309 SetCursorPos( PosX
, PosY
);
313 /***********************************************************************
314 * SendInput (USER32.@)
316 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
320 if (!InputEnabled
) return 0;
322 for (i
= 0; i
< count
; i
++, inputs
++)
327 queue_mouse_event( &inputs
->u
.mi
, LLMHF_INJECTED
);
329 case WINE_INTERNAL_INPUT_MOUSE
:
330 queue_mouse_event( &inputs
->u
.mi
, 0 );
333 queue_kbd_event( &inputs
->u
.ki
, LLKHF_INJECTED
);
335 case WINE_INTERNAL_INPUT_KEYBOARD
:
336 queue_kbd_event( &inputs
->u
.ki
, 0 );
339 FIXME( "INPUT_HARDWARE not supported\n" );
347 /***********************************************************************
348 * keybd_event (USER32.@)
350 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
351 DWORD dwFlags
, DWORD dwExtraInfo
)
355 input
.type
= INPUT_KEYBOARD
;
356 input
.u
.ki
.wVk
= bVk
;
357 input
.u
.ki
.wScan
= bScan
;
358 input
.u
.ki
.dwFlags
= dwFlags
;
359 input
.u
.ki
.time
= GetTickCount();
360 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
361 SendInput( 1, &input
, sizeof(input
) );
365 /***********************************************************************
366 * keybd_event (USER.289)
368 void WINAPI
keybd_event16( CONTEXT86
*context
)
372 if (HIBYTE(context
->Eax
) & 0x80) dwFlags
|= KEYEVENTF_KEYUP
;
373 if (HIBYTE(context
->Ebx
) & 0x01) dwFlags
|= KEYEVENTF_EXTENDEDKEY
;
375 keybd_event( LOBYTE(context
->Eax
), LOBYTE(context
->Ebx
),
376 dwFlags
, MAKELONG(LOWORD(context
->Esi
), LOWORD(context
->Edi
)) );
380 /***********************************************************************
381 * mouse_event (USER32.@)
383 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
384 DWORD dwData
, DWORD dwExtraInfo
)
388 input
.type
= INPUT_MOUSE
;
391 input
.u
.mi
.mouseData
= dwData
;
392 input
.u
.mi
.dwFlags
= dwFlags
;
393 input
.u
.mi
.time
= GetCurrentTime();
394 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
395 SendInput( 1, &input
, sizeof(input
) );
399 /***********************************************************************
400 * mouse_event (USER.299)
402 void WINAPI
mouse_event16( CONTEXT86
*context
)
404 mouse_event( LOWORD(context
->Eax
), LOWORD(context
->Ebx
), LOWORD(context
->Ecx
),
405 LOWORD(context
->Edx
), MAKELONG(context
->Esi
, context
->Edi
) );
408 /***********************************************************************
409 * GetMouseEventProc (USER.337)
411 FARPROC16 WINAPI
GetMouseEventProc16(void)
413 HMODULE16 hmodule
= GetModuleHandle16("USER");
414 return GetProcAddress16( hmodule
, "mouse_event" );
418 /**********************************************************************
419 * EnableHardwareInput (USER.331)
421 BOOL16 WINAPI
EnableHardwareInput16(BOOL16 bEnable
)
423 BOOL16 bOldState
= InputEnabled
;
424 FIXME_(event
)("(%d) - stub\n", bEnable
);
425 InputEnabled
= bEnable
;
430 /***********************************************************************
431 * SwapMouseButton (USER.186)
433 BOOL16 WINAPI
SwapMouseButton16( BOOL16 fSwap
)
435 BOOL16 ret
= SwappedButtons
;
436 SwappedButtons
= fSwap
;
441 /***********************************************************************
442 * SwapMouseButton (USER32.@)
444 BOOL WINAPI
SwapMouseButton( BOOL fSwap
)
446 BOOL ret
= SwappedButtons
;
447 SwappedButtons
= fSwap
;
452 /***********************************************************************
453 * GetCursorPos (USER.17)
455 BOOL16 WINAPI
GetCursorPos16( POINT16
*pt
)
466 /***********************************************************************
467 * GetCursorPos (USER32.@)
469 BOOL WINAPI
GetCursorPos( POINT
*pt
)
474 if (USER_Driver
.pGetCursorPos
) USER_Driver
.pGetCursorPos( pt
);
479 /***********************************************************************
480 * GetCursorInfo (USER32.@)
482 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
484 MESSAGEQUEUE
*queue
= QUEUE_Current();
487 if (queue
->cursor_count
>= 0) pci
->flags
= CURSOR_SHOWING
;
489 GetCursorPos(&pci
->ptScreenPos
);
494 /***********************************************************************
495 * SetCursorPos (USER.70)
497 void WINAPI
SetCursorPos16( INT16 x
, INT16 y
)
499 SetCursorPos( x
, y
);
503 /***********************************************************************
504 * SetCursorPos (USER32.@)
506 BOOL WINAPI
SetCursorPos( INT x
, INT y
)
508 if (USER_Driver
.pSetCursorPos
) USER_Driver
.pSetCursorPos( x
, y
);
515 /**********************************************************************
518 * We need this to be able to generate double click messages
519 * when menu code captures mouse in the window without CS_DBLCLK style.
521 HWND
EVENT_Capture(HWND hwnd
, INT16 ht
)
523 HWND capturePrev
= 0, captureWnd
= 0;
524 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
528 capturePrev
= GetCapture();
537 wndPtr
= WIN_FindWndPtr( hwnd
);
540 TRACE_(win
)("(0x%04x)\n", hwnd
);
541 captureWnd
= wndPtr
->hwndSelf
;
546 /* Get the messageQ for the current thread */
547 if (!(pCurMsgQ
= QUEUE_Current()))
549 WARN_(win
)("\tCurrent message queue not found. Exiting!\n" );
553 /* Update the perQ capture window and send messages */
554 if( capturePrev
!= captureWnd
)
558 /* Retrieve the message queue associated with this window */
559 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
562 WARN_(win
)("\tMessage queue not found. Exiting!\n" );
566 /* Make sure that message queue for the window we are setting capture to
567 * shares the same perQ data as the current threads message queue.
569 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
573 PERQDATA_SetCaptureWnd( captureWnd
, captureHT
);
574 if (capturePrev
) SendMessageA( capturePrev
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
578 /* Unlock the queues before returning */
580 QUEUE_Unlock( pMsgQ
);
582 WIN_ReleaseWndPtr(wndPtr
);
587 /**********************************************************************
588 * SetCapture (USER32.@)
590 HWND WINAPI
SetCapture( HWND hwnd
)
592 return EVENT_Capture( hwnd
, HTCLIENT
);
596 /**********************************************************************
597 * ReleaseCapture (USER32.@)
599 BOOL WINAPI
ReleaseCapture(void)
601 return (EVENT_Capture( 0, 0 ) != 0);
605 /**********************************************************************
606 * GetCapture (USER32.@)
608 HWND WINAPI
GetCapture(void)
611 return PERQDATA_GetCaptureWnd( &hittest
);
614 /**********************************************************************
615 * GetAsyncKeyState (USER32.@)
617 * Determine if a key is or was pressed. retval has high-order
618 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
621 * This uses the variable AsyncMouseButtonsStates and
622 * AsyncKeyStateTable (set in event.c) which have the mouse button
623 * number or key number (whichever is applicable) set to true if the
624 * mouse or key had been depressed since the last call to
627 SHORT WINAPI
GetAsyncKeyState(INT nKey
)
629 SHORT retval
= ((AsyncKeyStateTable
[nKey
] & 0x80) ? 0x0001 : 0) |
630 ((InputKeyStateTable
[nKey
] & 0x80) ? 0x8000 : 0);
631 AsyncKeyStateTable
[nKey
] = 0;
632 TRACE_(key
)("(%x) -> %x\n", nKey
, retval
);
636 /**********************************************************************
637 * GetAsyncKeyState (USER.249)
639 INT16 WINAPI
GetAsyncKeyState16(INT16 nKey
)
641 return GetAsyncKeyState(nKey
);
644 /***********************************************************************
645 * IsUserIdle (USER.333)
647 BOOL16 WINAPI
IsUserIdle16(void)
649 if ( GetAsyncKeyState( VK_LBUTTON
) & 0x8000 )
652 if ( GetAsyncKeyState( VK_RBUTTON
) & 0x8000 )
655 if ( GetAsyncKeyState( VK_MBUTTON
) & 0x8000 )
658 /* Should check for screen saver activation here ... */
663 /**********************************************************************
664 * VkKeyScanA (USER32.@)
666 * VkKeyScan translates an ANSI character to a virtual-key and shift code
667 * for the current keyboard.
668 * high-order byte yields :
672 * 3-5 Shift-key combinations that are not used for characters
675 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
676 * FIXME : works ok except for dead chars :
677 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
678 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
680 WORD WINAPI
VkKeyScanA(CHAR cChar
)
682 return USER_Driver
.pVkKeyScan( cChar
);
685 /******************************************************************************
686 * VkKeyScanW (USER32.@)
688 WORD WINAPI
VkKeyScanW(WCHAR cChar
)
690 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
693 /**********************************************************************
694 * VkKeyScanExA (USER32.@)
696 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
698 /* FIXME: complete workaround this is */
699 return VkKeyScanA(cChar
);
702 /******************************************************************************
703 * VkKeyScanExW (USER32.@)
705 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
707 /* FIXME: complete workaround this is */
708 return VkKeyScanA((CHAR
)cChar
); /* FIXME: check unicode */
711 /******************************************************************************
712 * GetKeyboardType (USER32.@)
714 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
716 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
719 case 0: /* Keyboard type */
720 return 4; /* AT-101 */
721 case 1: /* Keyboard Subtype */
722 return 0; /* There are no defined subtypes */
723 case 2: /* Number of F-keys */
724 return 12; /* We're doing an 101 for now, so return 12 F-keys */
726 WARN_(keyboard
)("Unknown type\n");
727 return 0; /* The book says 0 here, so 0 */
731 /******************************************************************************
732 * MapVirtualKeyA (USER32.@)
734 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
736 return USER_Driver
.pMapVirtualKey( code
, maptype
);
739 /******************************************************************************
740 * MapVirtualKeyW (USER32.@)
742 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
744 return MapVirtualKeyA(code
,maptype
);
747 /******************************************************************************
748 * MapVirtualKeyExA (USER32.@)
750 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
753 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
754 return MapVirtualKeyA(code
,maptype
);
757 /******************************************************************************
758 * MapVirtualKeyExW (USER32.@)
760 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
763 FIXME_(keyboard
)("(%d,%d,0x%08lx), hkl unhandled!\n",code
,maptype
,(DWORD
)hkl
);
764 return MapVirtualKeyA(code
,maptype
);
767 /****************************************************************************
768 * GetKBCodePage (USER32.@)
770 UINT WINAPI
GetKBCodePage(void)
775 /****************************************************************************
776 * GetKeyboardLayoutName (USER.477)
778 INT16 WINAPI
GetKeyboardLayoutName16(LPSTR pwszKLID
)
780 return GetKeyboardLayoutNameA(pwszKLID
);
783 /***********************************************************************
784 * GetKeyboardLayout (USER32.@)
786 * FIXME: - device handle for keyboard layout defaulted to
787 * the language id. This is the way Windows default works.
788 * - the thread identifier (dwLayout) is also ignored.
790 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
793 layout
= GetSystemDefaultLCID(); /* FIXME */
794 layout
|= (layout
<<16); /* FIXME */
795 TRACE_(keyboard
)("returning %08x\n",layout
);
799 /****************************************************************************
800 * GetKeyboardLayoutNameA (USER32.@)
802 INT WINAPI
GetKeyboardLayoutNameA(LPSTR pwszKLID
)
804 sprintf(pwszKLID
, "%08x",GetKeyboardLayout(0));
808 /****************************************************************************
809 * GetKeyboardLayoutNameW (USER32.@)
811 INT WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
813 char buf
[KL_NAMELENGTH
];
814 int res
= GetKeyboardLayoutNameA(buf
);
815 MultiByteToWideChar( CP_ACP
, 0, buf
, -1, pwszKLID
, KL_NAMELENGTH
);
819 /****************************************************************************
820 * GetKeyNameTextA (USER32.@)
822 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
824 return USER_Driver
.pGetKeyNameText( lParam
, lpBuffer
, nSize
);
827 /****************************************************************************
828 * GetKeyNameTextW (USER32.@)
830 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
833 LPSTR buf
= HeapAlloc( GetProcessHeap(), 0, nSize
);
834 if(buf
== NULL
) return 0; /* FIXME: is this the correct failure value?*/
835 res
= GetKeyNameTextA(lParam
,buf
,nSize
);
837 if (nSize
> 0 && !MultiByteToWideChar( CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
))
838 lpBuffer
[nSize
-1] = 0;
839 HeapFree( GetProcessHeap(), 0, buf
);
843 /****************************************************************************
844 * ToUnicode (USER32.@)
846 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
847 LPWSTR lpwStr
, int size
, UINT flags
)
849 return USER_Driver
.pToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
852 /****************************************************************************
853 * ToUnicodeEx (USER32.@)
855 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
856 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
858 /* FIXME: need true implementation */
859 return ToUnicode(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
);
862 /****************************************************************************
865 INT WINAPI
ToAscii( UINT virtKey
,UINT scanCode
,LPBYTE lpKeyState
,
866 LPWORD lpChar
,UINT flags
)
871 ret
= ToUnicode(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
);
872 if(ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
874 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
878 /****************************************************************************
879 * ToAsciiEx (USER32.@)
881 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
882 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
884 /* FIXME: need true implementation */
885 return ToAscii(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
);
888 /**********************************************************************
889 * ActivateKeyboardLayout (USER32.@)
891 * Call ignored. WINE supports only system default keyboard layout.
893 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
895 TRACE_(keyboard
)("(%d, %d)\n", hLayout
, flags
);
896 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
901 /***********************************************************************
902 * GetKeyboardLayoutList (USER32.@)
904 * FIXME: Supports only the system default language and layout and
905 * returns only 1 value.
907 * Return number of values available if either input parm is
908 * 0, per MS documentation.
911 INT WINAPI
GetKeyboardLayoutList(INT nBuff
,HKL
*layouts
)
913 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
914 if (!nBuff
|| !layouts
)
917 layouts
[0] = GetKeyboardLayout(0);
922 /***********************************************************************
923 * RegisterHotKey (USER32.@)
925 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
) {
926 FIXME_(keyboard
)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
930 /***********************************************************************
931 * UnregisterHotKey (USER32.@)
933 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
) {
934 FIXME_(keyboard
)("(0x%08x,%d): stub\n",hwnd
,id
);
938 /***********************************************************************
939 * LoadKeyboardLayoutA (USER32.@)
940 * Call ignored. WINE supports only system default keyboard layout.
942 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
944 TRACE_(keyboard
)("(%s, %d)\n", pwszKLID
, Flags
);
945 ERR_(keyboard
)("Only default system keyboard layout supported. Call ignored.\n");
949 /***********************************************************************
950 * LoadKeyboardLayoutW (USER32.@)
952 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
956 WideCharToMultiByte( CP_ACP
, 0, pwszKLID
, -1, buf
, sizeof(buf
), NULL
, NULL
);
958 return LoadKeyboardLayoutA(buf
, Flags
);
962 typedef struct __TRACKINGLIST
{
964 POINT pos
; /* center of hover rectangle */
965 INT iHoverTime
; /* elapsed time the cursor has been inside of the hover rect */
968 static _TRACKINGLIST TrackingList
[10];
969 static int iTrackMax
= 0;
970 static UINT_PTR timer
;
971 static const INT iTimerInterval
= 50; /* msec for timer interval */
973 /* FIXME: need to implement WM_NCMOUSELEAVE and WM_NCMOUSEHOVER for */
974 /* TrackMouseEventProc and _TrackMouseEvent */
975 static void CALLBACK
TrackMouseEventProc(HWND hwndUnused
, UINT uMsg
, UINT_PTR idEvent
,
981 INT hoverwidth
= 0, hoverheight
= 0;
984 hwnd
= WindowFromPoint(pos
);
986 SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
987 SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
989 /* loop through tracking events we are processing */
990 while (i
< iTrackMax
) {
991 /* see if this tracking event is looking for TME_LEAVE and that the */
992 /* mouse has left the window */
993 if ((TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
) &&
994 (TrackingList
[i
].tme
.hwndTrack
!= hwnd
)) {
995 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
997 /* remove the TME_LEAVE flag */
998 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
1001 /* see if we are tracking hovering for this hwnd */
1002 if(TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) {
1003 /* add the timer interval to the hovering time */
1004 TrackingList
[i
].iHoverTime
+=iTimerInterval
;
1006 /* has the cursor moved outside the rectangle centered around pos? */
1007 if((abs(pos
.x
- TrackingList
[i
].pos
.x
) > (hoverwidth
/ 2.0))
1008 || (abs(pos
.y
- TrackingList
[i
].pos
.y
) > (hoverheight
/ 2.0)))
1010 /* record this new position as the current position and reset */
1011 /* the iHoverTime variable to 0 */
1012 TrackingList
[i
].pos
= pos
;
1013 TrackingList
[i
].iHoverTime
= 0;
1016 /* has the mouse hovered long enough? */
1017 if(TrackingList
[i
].iHoverTime
<= TrackingList
[i
].tme
.dwHoverTime
)
1019 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSEHOVER
, 0, 0);
1021 /* stop tracking mouse hover */
1022 TrackingList
[i
].tme
.dwFlags
^= TME_HOVER
;
1026 /* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
1027 if((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
1028 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)) {
1030 } else { /* remove this entry from the tracking list */
1031 TrackingList
[i
] = TrackingList
[--iTrackMax
];
1035 /* stop the timer if the tracking list is empty */
1036 if(iTrackMax
== 0) {
1037 KillTimer(0, timer
);
1043 /***********************************************************************
1044 * TrackMouseEvent [USER32]
1046 * Requests notification of mouse events
1048 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1049 * to the hwnd specified in the ptme structure. After the event message
1050 * is posted to the hwnd, the entry in the queue is removed.
1052 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1053 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1054 * immediately and the TME_LEAVE flag being ignored.
1057 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1066 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1070 BOOL cancel
= 0, hover
= 0, leave
= 0, query
= 0;
1077 TRACE("%lx, %lx, %x, %lx\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1079 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1080 WARN("wrong TRACKMOUSEEVENT size from app\n");
1081 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME not sure if this is correct */
1085 flags
= ptme
->dwFlags
;
1087 /* if HOVER_DEFAULT was specified replace this with the systems current value */
1088 if(ptme
->dwHoverTime
== HOVER_DEFAULT
)
1089 SystemParametersInfoA(SPI_GETMOUSEHOVERTIME
, 0, &(ptme
->dwHoverTime
), 0);
1092 hwnd
= WindowFromPoint(pos
);
1094 if ( flags
& TME_CANCEL
) {
1095 flags
&= ~ TME_CANCEL
;
1099 if ( flags
& TME_HOVER
) {
1100 flags
&= ~ TME_HOVER
;
1104 if ( flags
& TME_LEAVE
) {
1105 flags
&= ~ TME_LEAVE
;
1109 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1110 if ( flags
& TME_QUERY
) {
1111 flags
&= ~ TME_QUERY
;
1115 /* Find the tracking list entry with the matching hwnd */
1116 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1120 /* hwnd found, fill in the ptme struct */
1122 *ptme
= TrackingList
[i
].tme
;
1126 return TRUE
; /* return here, TME_QUERY is retrieving information */
1130 FIXME("Unknown flag(s) %08lx\n", flags
);
1133 /* find a matching hwnd if one exists */
1136 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
1141 TrackingList
[i
].tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1143 /* if we aren't tracking on hover or leave remove this entry */
1144 if(!((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
1145 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)))
1147 TrackingList
[i
] = TrackingList
[--iTrackMax
];
1149 if(iTrackMax
== 0) {
1150 KillTimer(0, timer
);
1156 /* see if hwndTrack isn't the current window */
1157 if(ptme
->hwndTrack
!= hwnd
) {
1159 PostMessageA(ptme
->hwndTrack
, WM_MOUSELEAVE
, 0, 0);
1162 /* See if this hwnd is already being tracked and update the tracking flags */
1163 for(i
= 0; i
< iTrackMax
; i
++) {
1164 if(TrackingList
[i
].tme
.hwndTrack
== ptme
->hwndTrack
) {
1166 TrackingList
[i
].tme
.dwFlags
|= TME_HOVER
;
1167 TrackingList
[i
].tme
.dwHoverTime
= ptme
->dwHoverTime
;
1171 TrackingList
[i
].tme
.dwFlags
|= TME_LEAVE
;
1173 /* reset iHoverTime as per winapi specs */
1174 TrackingList
[i
].iHoverTime
= 0;
1180 /* if the tracking list is full return FALSE */
1181 if (iTrackMax
== sizeof (TrackingList
) / sizeof(*TrackingList
)) {
1185 /* Adding new mouse event to the tracking list */
1186 TrackingList
[iTrackMax
].tme
= *ptme
;
1188 /* Initialize HoverInfo variables even if not hover tracking */
1189 TrackingList
[iTrackMax
].iHoverTime
= 0;
1190 TrackingList
[iTrackMax
].pos
= pos
;
1195 timer
= SetTimer(0, 0, iTimerInterval
, TrackMouseEventProc
);