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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
45 #include "user_private.h"
46 #include "wine/server.h"
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(win
);
51 WINE_DECLARE_DEBUG_CHANNEL(keyboard
);
54 /***********************************************************************
57 static WORD
get_key_state(void)
61 if (GetSystemMetrics( SM_SWAPBUTTON
))
63 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
64 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
68 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
69 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
71 if (GetAsyncKeyState(VK_MBUTTON
) & 0x80) ret
|= MK_MBUTTON
;
72 if (GetAsyncKeyState(VK_SHIFT
) & 0x80) ret
|= MK_SHIFT
;
73 if (GetAsyncKeyState(VK_CONTROL
) & 0x80) ret
|= MK_CONTROL
;
74 if (GetAsyncKeyState(VK_XBUTTON1
) & 0x80) ret
|= MK_XBUTTON1
;
75 if (GetAsyncKeyState(VK_XBUTTON2
) & 0x80) ret
|= MK_XBUTTON2
;
80 /**********************************************************************
83 BOOL
set_capture_window( HWND hwnd
, UINT gui_flags
, HWND
*prev_ret
)
89 if (gui_flags
& GUI_INMENUMODE
) flags
|= CAPTURE_MENU
;
90 if (gui_flags
& GUI_INMOVESIZE
) flags
|= CAPTURE_MOVESIZE
;
92 SERVER_START_REQ( set_capture_window
)
94 req
->handle
= wine_server_user_handle( hwnd
);
96 if ((ret
= !wine_server_call_err( req
)))
98 previous
= wine_server_ptr_handle( reply
->previous
);
99 hwnd
= wine_server_ptr_handle( reply
->full_handle
);
106 USER_Driver
->pSetCapture( hwnd
, gui_flags
);
108 if (previous
&& previous
!= hwnd
)
109 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
111 if (prev_ret
) *prev_ret
= previous
;
117 /***********************************************************************
118 * SendInput (USER32.@)
120 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
126 for (i
= 0; i
< count
; i
++)
128 switch(inputs
[i
].type
)
131 TRACE("mouse: dx %d, dy %d, data %x, flags %x, time %u, info %lx\n",
132 inputs
[i
].u
.mi
.dx
, inputs
[i
].u
.mi
.dy
, inputs
[i
].u
.mi
.mouseData
,
133 inputs
[i
].u
.mi
.dwFlags
, inputs
[i
].u
.mi
.time
, inputs
[i
].u
.mi
.dwExtraInfo
);
137 TRACE("keyboard: vk %X, scan %x, flags %x, time %u, info %lx\n",
138 inputs
[i
].u
.ki
.wVk
, inputs
[i
].u
.ki
.wScan
, inputs
[i
].u
.ki
.dwFlags
,
139 inputs
[i
].u
.ki
.time
, inputs
[i
].u
.ki
.dwExtraInfo
);
143 TRACE("hardware: msg %d, wParamL %x, wParamH %x\n",
144 inputs
[i
].u
.hi
.uMsg
, inputs
[i
].u
.hi
.wParamL
, inputs
[i
].u
.hi
.wParamH
);
148 FIXME("unknown input type %u\n", inputs
[i
].type
);
154 return USER_Driver
->pSendInput( count
, inputs
, size
);
158 /***********************************************************************
159 * keybd_event (USER32.@)
161 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
162 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
166 input
.type
= INPUT_KEYBOARD
;
167 input
.u
.ki
.wVk
= bVk
;
168 input
.u
.ki
.wScan
= bScan
;
169 input
.u
.ki
.dwFlags
= dwFlags
;
170 input
.u
.ki
.time
= GetTickCount();
171 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
172 SendInput( 1, &input
, sizeof(input
) );
176 /***********************************************************************
177 * mouse_event (USER32.@)
179 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
180 DWORD dwData
, ULONG_PTR dwExtraInfo
)
184 input
.type
= INPUT_MOUSE
;
187 input
.u
.mi
.mouseData
= dwData
;
188 input
.u
.mi
.dwFlags
= dwFlags
;
189 input
.u
.mi
.time
= GetCurrentTime();
190 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
191 SendInput( 1, &input
, sizeof(input
) );
195 /***********************************************************************
196 * GetCursorPos (USER32.@)
198 BOOL WINAPI DECLSPEC_HOTPATCH
GetCursorPos( POINT
*pt
)
200 if (!pt
) return FALSE
;
201 return USER_Driver
->pGetCursorPos( pt
);
205 /***********************************************************************
206 * GetCursorInfo (USER32.@)
208 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
211 pci
->hCursor
= LoadCursorW( 0, (LPCWSTR
)IDC_ARROW
);
212 pci
->flags
= CURSOR_SHOWING
;
213 GetCursorPos(&pci
->ptScreenPos
);
218 /***********************************************************************
219 * SetCursorPos (USER32.@)
221 BOOL WINAPI DECLSPEC_HOTPATCH
SetCursorPos( INT x
, INT y
)
223 return USER_Driver
->pSetCursorPos( x
, y
);
227 /**********************************************************************
228 * SetCapture (USER32.@)
230 HWND WINAPI DECLSPEC_HOTPATCH
SetCapture( HWND hwnd
)
234 set_capture_window( hwnd
, 0, &previous
);
239 /**********************************************************************
240 * ReleaseCapture (USER32.@)
242 BOOL WINAPI DECLSPEC_HOTPATCH
ReleaseCapture(void)
244 BOOL ret
= set_capture_window( 0, 0, NULL
);
246 /* Somebody may have missed some mouse movements */
247 if (ret
) mouse_event( MOUSEEVENTF_MOVE
, 0, 0, 0, 0 );
253 /**********************************************************************
254 * GetCapture (USER32.@)
256 HWND WINAPI
GetCapture(void)
260 SERVER_START_REQ( get_thread_input
)
262 req
->tid
= GetCurrentThreadId();
263 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->capture
);
270 /**********************************************************************
271 * GetAsyncKeyState (USER32.@)
273 * Determine if a key is or was pressed. retval has high-order
274 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
277 SHORT WINAPI DECLSPEC_HOTPATCH
GetAsyncKeyState(INT nKey
)
279 if (nKey
< 0 || nKey
> 256)
281 return USER_Driver
->pGetAsyncKeyState( nKey
);
285 /***********************************************************************
286 * GetQueueStatus (USER32.@)
288 DWORD WINAPI
GetQueueStatus( UINT flags
)
292 if (flags
& ~(QS_ALLINPUT
| QS_ALLPOSTMESSAGE
| QS_SMRESULT
))
294 SetLastError( ERROR_INVALID_FLAGS
);
298 /* check for pending X events */
299 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, flags
, 0 );
301 SERVER_START_REQ( get_queue_status
)
304 wine_server_call( req
);
305 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
312 /***********************************************************************
313 * GetInputState (USER32.@)
315 BOOL WINAPI
GetInputState(void)
319 /* check for pending X events */
320 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_INPUT
, 0 );
322 SERVER_START_REQ( get_queue_status
)
325 wine_server_call( req
);
326 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
333 /******************************************************************
334 * GetLastInputInfo (USER32.@)
336 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
342 if (plii
->cbSize
!= sizeof (*plii
) )
344 SetLastError(ERROR_INVALID_PARAMETER
);
348 SERVER_START_REQ( get_last_input_time
)
350 ret
= !wine_server_call_err( req
);
352 plii
->dwTime
= reply
->time
;
359 /******************************************************************
360 * GetRawInputDeviceList (USER32.@)
362 UINT WINAPI
GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList
, PUINT puiNumDevices
, UINT cbSize
)
364 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList
, puiNumDevices
, cbSize
);
366 if(pRawInputDeviceList
)
367 memset(pRawInputDeviceList
, 0, sizeof *pRawInputDeviceList
);
373 /******************************************************************
374 * RegisterRawInputDevices (USER32.@)
376 BOOL WINAPI DECLSPEC_HOTPATCH
RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices
, UINT uiNumDevices
, UINT cbSize
)
378 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices
, uiNumDevices
, cbSize
);
384 /******************************************************************
385 * GetRawInputData (USER32.@)
387 UINT WINAPI
GetRawInputData(HRAWINPUT hRawInput
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
, UINT cbSizeHeader
)
389 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
390 hRawInput
, uiCommand
, pData
, pcbSize
, cbSizeHeader
);
396 /******************************************************************
397 * GetRawInputBuffer (USER32.@)
399 UINT WINAPI DECLSPEC_HOTPATCH
GetRawInputBuffer(PRAWINPUT pData
, PUINT pcbSize
, UINT cbSizeHeader
)
401 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData
, pcbSize
, cbSizeHeader
);
407 /******************************************************************
408 * GetRawInputDeviceInfoA (USER32.@)
410 UINT WINAPI
GetRawInputDeviceInfoA(HANDLE hDevice
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
)
412 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice
, uiCommand
, pData
, pcbSize
);
418 /******************************************************************
419 * GetRawInputDeviceInfoW (USER32.@)
421 UINT WINAPI
GetRawInputDeviceInfoW(HANDLE hDevice
, UINT uiCommand
, LPVOID pData
, PUINT pcbSize
)
423 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice
, uiCommand
, pData
, pcbSize
);
429 /******************************************************************
430 * GetRegisteredRawInputDevices (USER32.@)
432 UINT WINAPI
GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices
, PUINT puiNumDevices
, UINT cbSize
)
434 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices
, puiNumDevices
, cbSize
);
440 /******************************************************************
441 * DefRawInputProc (USER32.@)
443 LRESULT WINAPI
DefRawInputProc(PRAWINPUT
*paRawInput
, INT nInput
, UINT cbSizeHeader
)
445 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput
, nInput
, cbSizeHeader
);
451 /**********************************************************************
452 * AttachThreadInput (USER32.@)
454 * Attaches the input processing mechanism of one thread to that of
457 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
461 SERVER_START_REQ( attach_thread_input
)
463 req
->tid_from
= from
;
465 req
->attach
= attach
;
466 ret
= !wine_server_call_err( req
);
473 /**********************************************************************
474 * GetKeyState (USER32.@)
476 * An application calls the GetKeyState function in response to a
477 * keyboard-input message. This function retrieves the state of the key
478 * at the time the input message was generated.
480 SHORT WINAPI DECLSPEC_HOTPATCH
GetKeyState(INT vkey
)
484 SERVER_START_REQ( get_key_state
)
486 req
->tid
= GetCurrentThreadId();
488 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
491 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
496 /**********************************************************************
497 * GetKeyboardState (USER32.@)
499 BOOL WINAPI DECLSPEC_HOTPATCH
GetKeyboardState( LPBYTE state
)
503 TRACE("(%p)\n", state
);
505 memset( state
, 0, 256 );
506 SERVER_START_REQ( get_key_state
)
508 req
->tid
= GetCurrentThreadId();
510 wine_server_set_reply( req
, state
, 256 );
511 ret
= !wine_server_call_err( req
);
518 /**********************************************************************
519 * SetKeyboardState (USER32.@)
521 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
525 SERVER_START_REQ( set_key_state
)
527 req
->tid
= GetCurrentThreadId();
528 wine_server_add_data( req
, state
, 256 );
529 ret
= !wine_server_call_err( req
);
536 /**********************************************************************
537 * VkKeyScanA (USER32.@)
539 * VkKeyScan translates an ANSI character to a virtual-key and shift code
540 * for the current keyboard.
541 * high-order byte yields :
545 * 3-5 Shift-key combinations that are not used for characters
548 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
549 * FIXME : works ok except for dead chars :
550 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
551 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
553 SHORT WINAPI
VkKeyScanA(CHAR cChar
)
557 if (IsDBCSLeadByte(cChar
)) return -1;
559 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
560 return VkKeyScanW(wChar
);
563 /******************************************************************************
564 * VkKeyScanW (USER32.@)
566 SHORT WINAPI
VkKeyScanW(WCHAR cChar
)
568 return VkKeyScanExW(cChar
, GetKeyboardLayout(0));
571 /**********************************************************************
572 * VkKeyScanExA (USER32.@)
574 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
578 if (IsDBCSLeadByte(cChar
)) return -1;
580 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
581 return VkKeyScanExW(wChar
, dwhkl
);
584 /******************************************************************************
585 * VkKeyScanExW (USER32.@)
587 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
589 return USER_Driver
->pVkKeyScanEx(cChar
, dwhkl
);
592 /**********************************************************************
593 * OemKeyScan (USER32.@)
595 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
600 /******************************************************************************
601 * GetKeyboardType (USER32.@)
603 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
605 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
608 case 0: /* Keyboard type */
609 return 4; /* AT-101 */
610 case 1: /* Keyboard Subtype */
611 return 0; /* There are no defined subtypes */
612 case 2: /* Number of F-keys */
613 return 12; /* We're doing an 101 for now, so return 12 F-keys */
615 WARN_(keyboard
)("Unknown type\n");
616 return 0; /* The book says 0 here, so 0 */
620 /******************************************************************************
621 * MapVirtualKeyA (USER32.@)
623 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
625 return MapVirtualKeyExA( code
, maptype
, GetKeyboardLayout(0) );
628 /******************************************************************************
629 * MapVirtualKeyW (USER32.@)
631 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
633 return MapVirtualKeyExW(code
, maptype
, GetKeyboardLayout(0));
636 /******************************************************************************
637 * MapVirtualKeyExA (USER32.@)
639 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
643 ret
= MapVirtualKeyExW( code
, maptype
, hkl
);
644 if (maptype
== MAPVK_VK_TO_CHAR
)
649 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)&ch
, 1, NULL
, NULL
);
655 /******************************************************************************
656 * MapVirtualKeyExW (USER32.@)
658 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
660 TRACE_(keyboard
)("(%X, %d, %p)\n", code
, maptype
, hkl
);
662 return USER_Driver
->pMapVirtualKeyEx(code
, maptype
, hkl
);
665 /****************************************************************************
666 * GetKBCodePage (USER32.@)
668 UINT WINAPI
GetKBCodePage(void)
673 /***********************************************************************
674 * GetKeyboardLayout (USER32.@)
676 * - device handle for keyboard layout defaulted to
677 * the language id. This is the way Windows default works.
678 * - the thread identifier (dwLayout) is also ignored.
680 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
682 return USER_Driver
->pGetKeyboardLayout(dwLayout
);
685 /****************************************************************************
686 * GetKeyboardLayoutNameA (USER32.@)
688 BOOL WINAPI
GetKeyboardLayoutNameA(LPSTR pszKLID
)
690 WCHAR buf
[KL_NAMELENGTH
];
692 if (GetKeyboardLayoutNameW(buf
))
693 return WideCharToMultiByte( CP_ACP
, 0, buf
, -1, pszKLID
, KL_NAMELENGTH
, NULL
, NULL
) != 0;
697 /****************************************************************************
698 * GetKeyboardLayoutNameW (USER32.@)
700 BOOL WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
702 return USER_Driver
->pGetKeyboardLayoutName(pwszKLID
);
705 /****************************************************************************
706 * GetKeyNameTextA (USER32.@)
708 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
713 if (!GetKeyNameTextW(lParam
, buf
, 256))
718 ret
= WideCharToMultiByte(CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
, NULL
, NULL
);
727 /****************************************************************************
728 * GetKeyNameTextW (USER32.@)
730 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
732 return USER_Driver
->pGetKeyNameText( lParam
, lpBuffer
, nSize
);
735 /****************************************************************************
736 * ToUnicode (USER32.@)
738 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
739 LPWSTR lpwStr
, int size
, UINT flags
)
741 return ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, GetKeyboardLayout(0));
744 /****************************************************************************
745 * ToUnicodeEx (USER32.@)
747 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
748 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
750 return USER_Driver
->pToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, hkl
);
753 /****************************************************************************
756 INT WINAPI
ToAscii( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
757 LPWORD lpChar
, UINT flags
)
759 return ToAsciiEx(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
, GetKeyboardLayout(0));
762 /****************************************************************************
763 * ToAsciiEx (USER32.@)
765 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, const BYTE
*lpKeyState
,
766 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
771 ret
= ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
, dwhkl
);
772 if (ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
774 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
778 /**********************************************************************
779 * ActivateKeyboardLayout (USER32.@)
781 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
783 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
785 return USER_Driver
->pActivateKeyboardLayout(hLayout
, flags
);
788 /**********************************************************************
789 * BlockInput (USER32.@)
791 BOOL WINAPI
BlockInput(BOOL fBlockIt
)
793 FIXME_(keyboard
)("(%d): stub\n", fBlockIt
);
794 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
799 /***********************************************************************
800 * GetKeyboardLayoutList (USER32.@)
802 * Return number of values available if either input parm is
803 * 0, per MS documentation.
805 UINT WINAPI
GetKeyboardLayoutList(INT nBuff
, HKL
*layouts
)
810 ULONG_PTR baselayout
;
812 static const WCHAR szKeyboardReg
[] = {'S','y','s','t','e','m','\\','C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\','C','o','n','t','r','o','l','\\','K','e','y','b','o','a','r','d',' ','L','a','y','o','u','t','s',0};
814 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
816 baselayout
= GetUserDefaultLCID();
817 langid
= PRIMARYLANGID(LANGIDFROMLCID(baselayout
));
818 if (langid
== LANG_CHINESE
|| langid
== LANG_JAPANESE
|| langid
== LANG_KOREAN
)
819 baselayout
|= 0xe001 << 16; /* IME */
821 baselayout
|= baselayout
<< 16;
823 /* Enumerate the Registry */
824 rc
= RegOpenKeyW(HKEY_LOCAL_MACHINE
,szKeyboardReg
,&hKeyKeyboard
);
825 if (rc
== ERROR_SUCCESS
)
830 rc
= RegEnumKeyW(hKeyKeyboard
, count
, szKeyName
, 9);
831 if (rc
== ERROR_SUCCESS
)
833 layout
= (HKL
)strtoulW(szKeyName
,NULL
,16);
834 if (baselayout
!= 0 && layout
== (HKL
)baselayout
)
835 baselayout
= 0; /* found in the registry do not add again */
836 if (nBuff
&& layouts
)
838 if (count
>= nBuff
) break;
839 layouts
[count
] = layout
;
843 } while (rc
== ERROR_SUCCESS
);
844 RegCloseKey(hKeyKeyboard
);
847 /* make sure our base layout is on the list */
850 if (nBuff
&& layouts
)
854 layouts
[count
] = (HKL
)baselayout
;
866 /***********************************************************************
867 * RegisterHotKey (USER32.@)
869 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
)
872 if (!once
++) FIXME_(keyboard
)("(%p,%d,0x%08x,%X): stub\n",hwnd
,id
,modifiers
,vk
);
876 /***********************************************************************
877 * UnregisterHotKey (USER32.@)
879 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
)
882 if (!once
++) FIXME_(keyboard
)("(%p,%d): stub\n",hwnd
,id
);
886 /***********************************************************************
887 * LoadKeyboardLayoutW (USER32.@)
889 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
891 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
893 return USER_Driver
->pLoadKeyboardLayout(pwszKLID
, Flags
);
896 /***********************************************************************
897 * LoadKeyboardLayoutA (USER32.@)
899 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
902 UNICODE_STRING pwszKLIDW
;
904 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
905 else pwszKLIDW
.Buffer
= NULL
;
907 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
908 RtlFreeUnicodeString(&pwszKLIDW
);
913 /***********************************************************************
914 * UnloadKeyboardLayout (USER32.@)
916 BOOL WINAPI
UnloadKeyboardLayout(HKL hkl
)
918 TRACE_(keyboard
)("(%p)\n", hkl
);
920 return USER_Driver
->pUnloadKeyboardLayout(hkl
);
923 typedef struct __TRACKINGLIST
{
925 POINT pos
; /* center of hover rectangle */
928 /* FIXME: move tracking stuff into a per thread data */
929 static _TRACKINGLIST tracking_info
;
930 static UINT_PTR timer
;
932 static void check_mouse_leave(HWND hwnd
, int hittest
)
934 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
936 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
937 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
939 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
941 /* remove the TME_LEAVE flag */
942 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
946 if (hittest
== HTCLIENT
)
948 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
950 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
951 /* remove the TME_LEAVE flag */
952 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
957 if (!(tracking_info
.tme
.dwFlags
& TME_NONCLIENT
))
959 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
960 /* remove the TME_LEAVE flag */
961 tracking_info
.tme
.dwFlags
&= ~TME_LEAVE
;
967 static void CALLBACK
TrackMouseEventProc(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
,
971 INT hoverwidth
= 0, hoverheight
= 0, hittest
;
973 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd
, uMsg
, idEvent
, dwTime
);
976 hwnd
= WINPOS_WindowFromPoint(hwnd
, pos
, &hittest
);
978 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
980 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
981 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
983 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
984 wine_dbgstr_point(&tracking_info
.pos
), wine_dbgstr_point(&pos
),
985 hoverwidth
, hoverheight
);
987 /* see if this tracking event is looking for TME_LEAVE and that the */
988 /* mouse has left the window */
989 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
)
991 check_mouse_leave(hwnd
, hittest
);
994 if (tracking_info
.tme
.hwndTrack
!= hwnd
)
996 /* mouse is gone, stop tracking mouse hover */
997 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1000 /* see if we are tracking hovering for this hwnd */
1001 if (tracking_info
.tme
.dwFlags
& TME_HOVER
)
1003 /* has the cursor moved outside the rectangle centered around pos? */
1004 if ((abs(pos
.x
- tracking_info
.pos
.x
) > (hoverwidth
/ 2)) ||
1005 (abs(pos
.y
- tracking_info
.pos
.y
) > (hoverheight
/ 2)))
1007 /* record this new position as the current position */
1008 tracking_info
.pos
= pos
;
1012 if (hittest
== HTCLIENT
)
1014 ScreenToClient(hwnd
, &pos
);
1015 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos
));
1017 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_MOUSEHOVER
,
1018 get_key_state(), MAKELPARAM( pos
.x
, pos
.y
));
1022 if (tracking_info
.tme
.dwFlags
& TME_NONCLIENT
)
1023 PostMessageW(tracking_info
.tme
.hwndTrack
, WM_NCMOUSEHOVER
,
1024 hittest
, MAKELPARAM( pos
.x
, pos
.y
));
1027 /* stop tracking mouse hover */
1028 tracking_info
.tme
.dwFlags
&= ~TME_HOVER
;
1032 /* stop the timer if the tracking list is empty */
1033 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1035 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1037 tracking_info
.tme
.hwndTrack
= 0;
1038 tracking_info
.tme
.dwFlags
= 0;
1039 tracking_info
.tme
.dwHoverTime
= 0;
1044 /***********************************************************************
1045 * TrackMouseEvent [USER32]
1047 * Requests notification of mouse events
1049 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1050 * to the hwnd specified in the ptme structure. After the event message
1051 * is posted to the hwnd, the entry in the queue is removed.
1053 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1054 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1055 * immediately and the TME_LEAVE flag being ignored.
1058 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1067 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1074 TRACE("%x, %x, %p, %u\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
1076 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
1077 WARN("wrong TRACKMOUSEEVENT size from app\n");
1078 SetLastError(ERROR_INVALID_PARAMETER
);
1082 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1083 if (ptme
->dwFlags
& TME_QUERY
)
1085 *ptme
= tracking_info
.tme
;
1086 /* set cbSize in the case it's not initialized yet */
1087 ptme
->cbSize
= sizeof(TRACKMOUSEEVENT
);
1089 return TRUE
; /* return here, TME_QUERY is retrieving information */
1092 if (!IsWindow(ptme
->hwndTrack
))
1094 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1098 hover_time
= ptme
->dwHoverTime
;
1100 /* if HOVER_DEFAULT was specified replace this with the systems current value.
1101 * TME_LEAVE doesn't need to specify hover time so use default */
1102 if (hover_time
== HOVER_DEFAULT
|| hover_time
== 0 || !(ptme
->dwHoverTime
&TME_HOVER
))
1103 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME
, 0, &hover_time
, 0);
1106 hwnd
= WINPOS_WindowFromPoint(ptme
->hwndTrack
, pos
, &hittest
);
1107 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos
), hwnd
, hittest
);
1109 if (ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
))
1110 FIXME("Unknown flag(s) %08x\n", ptme
->dwFlags
& ~(TME_CANCEL
| TME_HOVER
| TME_LEAVE
| TME_NONCLIENT
));
1112 if (ptme
->dwFlags
& TME_CANCEL
)
1114 if (tracking_info
.tme
.hwndTrack
== ptme
->hwndTrack
)
1116 tracking_info
.tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
1118 /* if we aren't tracking on hover or leave remove this entry */
1119 if (!(tracking_info
.tme
.dwFlags
& (TME_HOVER
| TME_LEAVE
)))
1121 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1123 tracking_info
.tme
.hwndTrack
= 0;
1124 tracking_info
.tme
.dwFlags
= 0;
1125 tracking_info
.tme
.dwHoverTime
= 0;
1129 /* In our implementation it's possible that another window will receive a
1130 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1131 * called. In such a situation post the WM_MOUSELEAVE now */
1132 if (tracking_info
.tme
.dwFlags
& TME_LEAVE
&& tracking_info
.tme
.hwndTrack
!= NULL
)
1133 check_mouse_leave(hwnd
, hittest
);
1137 KillSystemTimer(tracking_info
.tme
.hwndTrack
, timer
);
1139 tracking_info
.tme
.hwndTrack
= 0;
1140 tracking_info
.tme
.dwFlags
= 0;
1141 tracking_info
.tme
.dwHoverTime
= 0;
1144 if (ptme
->hwndTrack
== hwnd
)
1146 /* Adding new mouse event to the tracking list */
1147 tracking_info
.tme
= *ptme
;
1148 tracking_info
.tme
.dwHoverTime
= hover_time
;
1150 /* Initialize HoverInfo variables even if not hover tracking */
1151 tracking_info
.pos
= pos
;
1153 timer
= SetSystemTimer(tracking_info
.tme
.hwndTrack
, (UINT_PTR
)&tracking_info
.tme
, hover_time
, TrackMouseEventProc
);
1160 /***********************************************************************
1161 * GetMouseMovePointsEx [USER32]
1164 * Success: count of point set in the buffer
1167 int WINAPI
GetMouseMovePointsEx(UINT size
, LPMOUSEMOVEPOINT ptin
, LPMOUSEMOVEPOINT ptout
, int count
, DWORD res
) {
1169 if((size
!= sizeof(MOUSEMOVEPOINT
)) || (count
< 0) || (count
> 64)) {
1170 SetLastError(ERROR_INVALID_PARAMETER
);
1174 if(!ptin
|| (!ptout
&& count
)) {
1175 SetLastError(ERROR_NOACCESS
);
1179 FIXME("(%d %p %p %d %d) stub\n", size
, ptin
, ptout
, count
, res
);
1181 SetLastError(ERROR_POINT_NOT_FOUND
);