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
38 #define WIN32_NO_STATUS
47 #include "user_private.h"
48 #include "wine/server.h"
49 #include "wine/debug.h"
50 #include "wine/unicode.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(win);
53 WINE_DECLARE_DEBUG_CHANNEL(keyboard);
55 static DWORD last_mouse_event;
57 /***********************************************************************
60 static WORD get_key_state(void)
64 if (GetSystemMetrics( SM_SWAPBUTTON ))
66 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
67 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
71 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_LBUTTON;
72 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_RBUTTON;
74 if (GetAsyncKeyState(VK_MBUTTON) & 0x80) ret |= MK_MBUTTON;
75 if (GetAsyncKeyState(VK_SHIFT) & 0x80) ret |= MK_SHIFT;
76 if (GetAsyncKeyState(VK_CONTROL) & 0x80) ret |= MK_CONTROL;
77 if (GetAsyncKeyState(VK_XBUTTON1) & 0x80) ret |= MK_XBUTTON1;
78 if (GetAsyncKeyState(VK_XBUTTON2) & 0x80) ret |= MK_XBUTTON2;
83 /**********************************************************************
86 BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret )
92 if (gui_flags & GUI_INMENUMODE) flags |= CAPTURE_MENU;
93 if (gui_flags & GUI_INMOVESIZE) flags |= CAPTURE_MOVESIZE;
95 SERVER_START_REQ( set_capture_window )
97 req->handle = wine_server_user_handle( hwnd );
99 if ((ret = !wine_server_call_err( req )))
101 previous = wine_server_ptr_handle( reply->previous );
102 hwnd = wine_server_ptr_handle( reply->full_handle );
109 USER_Driver->pSetCapture( hwnd, gui_flags );
111 if (previous && previous != hwnd)
112 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
114 if (prev_ret) *prev_ret = previous;
120 /***********************************************************************
121 * __wine_send_input (USER32.@)
123 * Internal SendInput function to allow the graphics driver to inject real events.
125 BOOL CDECL __wine_send_input( HWND hwnd, const INPUT *input )
129 if (input->type == INPUT_MOUSE) last_mouse_event = GetTickCount();
130 status = send_hardware_message( hwnd, input, 0 );
131 if (status) SetLastError( RtlNtStatusToDosError(status) );
136 /***********************************************************************
137 * update_mouse_coords
139 * Helper for SendInput.
141 static void update_mouse_coords( INPUT *input )
143 if (!(input->u.mi.dwFlags & MOUSEEVENTF_MOVE)) return;
145 if (input->u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE)
147 input->u.mi.dx = (input->u.mi.dx * GetSystemMetrics( SM_CXSCREEN )) >> 16;
148 input->u.mi.dy = (input->u.mi.dy * GetSystemMetrics( SM_CYSCREEN )) >> 16;
154 /* dx and dy can be negative numbers for relative movements */
155 SystemParametersInfoW(SPI_GETMOUSE, 0, accel, 0);
157 if (!accel[2]) return;
159 if (abs(input->u.mi.dx) > accel[0])
162 if ((abs(input->u.mi.dx) > accel[1]) && (accel[2] == 2)) input->u.mi.dx *= 2;
164 if (abs(input->u.mi.dy) > accel[0])
167 if ((abs(input->u.mi.dy) > accel[1]) && (accel[2] == 2)) input->u.mi.dy *= 2;
172 /***********************************************************************
173 * SendInput (USER32.@)
175 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
180 for (i = 0; i < count; i++)
182 if (inputs[i].type == INPUT_MOUSE)
184 /* we need to update the coordinates to what the server expects */
185 INPUT input = inputs[i];
186 last_mouse_event = GetTickCount();
187 update_mouse_coords( &input );
188 if (!(status = send_hardware_message( 0, &input, SEND_HWMSG_INJECTED )))
190 if ((input.u.mi.dwFlags & MOUSEEVENTF_MOVE) &&
191 ((input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE) || input.u.mi.dx || input.u.mi.dy))
193 /* we have to actually move the cursor */
196 if (!(input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE) ||
197 pt.x != input.u.mi.dx || pt.y != input.u.mi.dy)
198 USER_Driver->pSetCursorPos( pt.x, pt.y );
202 else status = send_hardware_message( 0, &inputs[i], SEND_HWMSG_INJECTED );
206 SetLastError( RtlNtStatusToDosError(status) );
215 /***********************************************************************
216 * keybd_event (USER32.@)
218 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
219 DWORD dwFlags, ULONG_PTR dwExtraInfo )
223 input.type = INPUT_KEYBOARD;
224 input.u.ki.wVk = bVk;
225 input.u.ki.wScan = bScan;
226 input.u.ki.dwFlags = dwFlags;
228 input.u.ki.dwExtraInfo = dwExtraInfo;
229 SendInput( 1, &input, sizeof(input) );
233 /***********************************************************************
234 * mouse_event (USER32.@)
236 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
237 DWORD dwData, ULONG_PTR dwExtraInfo )
241 input.type = INPUT_MOUSE;
244 input.u.mi.mouseData = dwData;
245 input.u.mi.dwFlags = dwFlags;
247 input.u.mi.dwExtraInfo = dwExtraInfo;
248 SendInput( 1, &input, sizeof(input) );
252 /***********************************************************************
253 * GetCursorPos (USER32.@)
255 BOOL WINAPI DECLSPEC_HOTPATCH GetCursorPos( POINT *pt )
259 if (!pt) return FALSE;
261 /* query new position from graphics driver if we haven't updated recently */
262 if (GetTickCount() - last_mouse_event > 100) ret = USER_Driver->pGetCursorPos( pt );
264 SERVER_START_REQ( set_cursor )
266 if (ret) /* update it */
268 req->flags = SET_CURSOR_POS;
272 if ((ret = !wine_server_call( req )))
274 pt->x = reply->new_x;
275 pt->y = reply->new_y;
283 /***********************************************************************
284 * GetCursorInfo (USER32.@)
286 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
292 SERVER_START_REQ( get_thread_input )
295 if ((ret = !wine_server_call( req )))
297 pci->hCursor = wine_server_ptr_handle( reply->cursor );
298 pci->flags = (reply->show_count >= 0) ? CURSOR_SHOWING : 0;
302 GetCursorPos(&pci->ptScreenPos);
307 /***********************************************************************
308 * SetCursorPos (USER32.@)
310 BOOL WINAPI DECLSPEC_HOTPATCH SetCursorPos( INT x, INT y )
314 SERVER_START_REQ( set_cursor )
316 req->flags = SET_CURSOR_POS;
319 if ((ret = !wine_server_call( req )))
326 if (ret) USER_Driver->pSetCursorPos( x, y );
331 /**********************************************************************
332 * SetCapture (USER32.@)
334 HWND WINAPI DECLSPEC_HOTPATCH SetCapture( HWND hwnd )
338 set_capture_window( hwnd, 0, &previous );
343 /**********************************************************************
344 * ReleaseCapture (USER32.@)
346 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseCapture(void)
348 BOOL ret = set_capture_window( 0, 0, NULL );
350 /* Somebody may have missed some mouse movements */
351 if (ret) mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
357 /**********************************************************************
358 * GetCapture (USER32.@)
360 HWND WINAPI GetCapture(void)
364 SERVER_START_REQ( get_thread_input )
366 req->tid = GetCurrentThreadId();
367 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->capture );
374 /**********************************************************************
375 * GetAsyncKeyState (USER32.@)
377 * Determine if a key is or was pressed. retval has high-order
378 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
381 SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
385 if (key < 0 || key >= 256) return 0;
387 if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1)
390 SERVER_START_REQ( get_key_state )
394 if (!wine_server_call( req ))
396 if (reply->state & 0x40) ret |= 0x0001;
397 if (reply->state & 0x80) ret |= 0x8000;
406 /***********************************************************************
407 * GetQueueStatus (USER32.@)
409 DWORD WINAPI GetQueueStatus( UINT flags )
413 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
415 SetLastError( ERROR_INVALID_FLAGS );
419 /* check for pending X events */
420 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
422 SERVER_START_REQ( get_queue_status )
425 wine_server_call( req );
426 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
433 /***********************************************************************
434 * GetInputState (USER32.@)
436 BOOL WINAPI GetInputState(void)
440 /* check for pending X events */
441 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
443 SERVER_START_REQ( get_queue_status )
446 wine_server_call( req );
447 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
454 /******************************************************************
455 * GetLastInputInfo (USER32.@)
457 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
463 if (plii->cbSize != sizeof (*plii) )
465 SetLastError(ERROR_INVALID_PARAMETER);
469 SERVER_START_REQ( get_last_input_time )
471 ret = !wine_server_call_err( req );
473 plii->dwTime = reply->time;
480 /******************************************************************
481 * GetRawInputDeviceList (USER32.@)
483 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
485 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
487 if(pRawInputDeviceList)
488 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
494 /******************************************************************
495 * RegisterRawInputDevices (USER32.@)
497 BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
499 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
505 /******************************************************************
506 * GetRawInputData (USER32.@)
508 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
510 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
511 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
517 /******************************************************************
518 * GetRawInputBuffer (USER32.@)
520 UINT WINAPI DECLSPEC_HOTPATCH GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
522 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
528 /******************************************************************
529 * GetRawInputDeviceInfoA (USER32.@)
531 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
533 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
539 /******************************************************************
540 * GetRawInputDeviceInfoW (USER32.@)
542 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
544 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
550 /******************************************************************
551 * GetRegisteredRawInputDevices (USER32.@)
553 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
555 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
561 /******************************************************************
562 * DefRawInputProc (USER32.@)
564 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
566 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
572 /**********************************************************************
573 * AttachThreadInput (USER32.@)
575 * Attaches the input processing mechanism of one thread to that of
578 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
582 SERVER_START_REQ( attach_thread_input )
584 req->tid_from = from;
586 req->attach = attach;
587 ret = !wine_server_call_err( req );
594 /**********************************************************************
595 * GetKeyState (USER32.@)
597 * An application calls the GetKeyState function in response to a
598 * keyboard-input message. This function retrieves the state of the key
599 * at the time the input message was generated.
601 SHORT WINAPI DECLSPEC_HOTPATCH GetKeyState(INT vkey)
605 SERVER_START_REQ( get_key_state )
607 req->tid = GetCurrentThreadId();
609 if (!wine_server_call( req )) retval = (signed char)reply->state;
612 TRACE("key (0x%x) -> %x\n", vkey, retval);
617 /**********************************************************************
618 * GetKeyboardState (USER32.@)
620 BOOL WINAPI DECLSPEC_HOTPATCH GetKeyboardState( LPBYTE state )
624 TRACE("(%p)\n", state);
626 memset( state, 0, 256 );
627 SERVER_START_REQ( get_key_state )
629 req->tid = GetCurrentThreadId();
631 wine_server_set_reply( req, state, 256 );
632 ret = !wine_server_call_err( req );
639 /**********************************************************************
640 * SetKeyboardState (USER32.@)
642 BOOL WINAPI SetKeyboardState( LPBYTE state )
646 SERVER_START_REQ( set_key_state )
648 req->tid = GetCurrentThreadId();
649 wine_server_add_data( req, state, 256 );
650 ret = !wine_server_call_err( req );
657 /**********************************************************************
658 * VkKeyScanA (USER32.@)
660 * VkKeyScan translates an ANSI character to a virtual-key and shift code
661 * for the current keyboard.
662 * high-order byte yields :
666 * 3-5 Shift-key combinations that are not used for characters
669 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
670 * FIXME : works ok except for dead chars :
671 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
672 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
674 SHORT WINAPI VkKeyScanA(CHAR cChar)
678 if (IsDBCSLeadByte(cChar)) return -1;
680 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
681 return VkKeyScanW(wChar);
684 /******************************************************************************
685 * VkKeyScanW (USER32.@)
687 SHORT WINAPI VkKeyScanW(WCHAR cChar)
689 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
692 /**********************************************************************
693 * VkKeyScanExA (USER32.@)
695 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
699 if (IsDBCSLeadByte(cChar)) return -1;
701 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
702 return VkKeyScanExW(wChar, dwhkl);
705 /******************************************************************************
706 * VkKeyScanExW (USER32.@)
708 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
710 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
713 /**********************************************************************
714 * OemKeyScan (USER32.@)
716 DWORD WINAPI OemKeyScan(WORD wOemChar)
721 /******************************************************************************
722 * GetKeyboardType (USER32.@)
724 INT WINAPI GetKeyboardType(INT nTypeFlag)
726 TRACE_(keyboard)("(%d)\n", nTypeFlag);
729 case 0: /* Keyboard type */
730 return 4; /* AT-101 */
731 case 1: /* Keyboard Subtype */
732 return 0; /* There are no defined subtypes */
733 case 2: /* Number of F-keys */
734 return 12; /* We're doing an 101 for now, so return 12 F-keys */
736 WARN_(keyboard)("Unknown type\n");
737 return 0; /* The book says 0 here, so 0 */
741 /******************************************************************************
742 * MapVirtualKeyA (USER32.@)
744 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
746 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
749 /******************************************************************************
750 * MapVirtualKeyW (USER32.@)
752 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
754 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
757 /******************************************************************************
758 * MapVirtualKeyExA (USER32.@)
760 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
764 ret = MapVirtualKeyExW( code, maptype, hkl );
765 if (maptype == MAPVK_VK_TO_CHAR)
770 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
776 /******************************************************************************
777 * MapVirtualKeyExW (USER32.@)
779 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
781 TRACE_(keyboard)("(%X, %d, %p)\n", code, maptype, hkl);
783 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
786 /****************************************************************************
787 * GetKBCodePage (USER32.@)
789 UINT WINAPI GetKBCodePage(void)
794 /***********************************************************************
795 * GetKeyboardLayout (USER32.@)
797 * - device handle for keyboard layout defaulted to
798 * the language id. This is the way Windows default works.
799 * - the thread identifier is also ignored.
801 HKL WINAPI GetKeyboardLayout(DWORD thread_id)
803 return USER_Driver->pGetKeyboardLayout(thread_id);
806 /****************************************************************************
807 * GetKeyboardLayoutNameA (USER32.@)
809 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
811 WCHAR buf[KL_NAMELENGTH];
813 if (GetKeyboardLayoutNameW(buf))
814 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
818 /****************************************************************************
819 * GetKeyboardLayoutNameW (USER32.@)
821 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
823 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
826 /****************************************************************************
827 * GetKeyNameTextA (USER32.@)
829 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
834 if (!GetKeyNameTextW(lParam, buf, 256))
839 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
848 /****************************************************************************
849 * GetKeyNameTextW (USER32.@)
851 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
853 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
856 /****************************************************************************
857 * ToUnicode (USER32.@)
859 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
860 LPWSTR lpwStr, int size, UINT flags)
862 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
865 /****************************************************************************
866 * ToUnicodeEx (USER32.@)
868 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
869 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
871 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
874 /****************************************************************************
877 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
878 LPWORD lpChar, UINT flags )
880 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
883 /****************************************************************************
884 * ToAsciiEx (USER32.@)
886 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
887 LPWORD lpChar, UINT flags, HKL dwhkl )
892 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
893 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
895 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
899 /**********************************************************************
900 * ActivateKeyboardLayout (USER32.@)
902 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
904 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
906 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
909 /**********************************************************************
910 * BlockInput (USER32.@)
912 BOOL WINAPI BlockInput(BOOL fBlockIt)
914 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
915 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
920 /***********************************************************************
921 * GetKeyboardLayoutList (USER32.@)
923 * Return number of values available if either input parm is
924 * 0, per MS documentation.
926 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
931 ULONG_PTR baselayout;
933 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};
935 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
937 baselayout = GetUserDefaultLCID();
938 langid = PRIMARYLANGID(LANGIDFROMLCID(baselayout));
939 if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
940 baselayout |= 0xe001 << 16; /* IME */
942 baselayout |= baselayout << 16;
944 /* Enumerate the Registry */
945 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,szKeyboardReg,&hKeyKeyboard);
946 if (rc == ERROR_SUCCESS)
951 rc = RegEnumKeyW(hKeyKeyboard, count, szKeyName, 9);
952 if (rc == ERROR_SUCCESS)
954 layout = (HKL)strtoulW(szKeyName,NULL,16);
955 if (baselayout != 0 && layout == (HKL)baselayout)
956 baselayout = 0; /* found in the registry do not add again */
957 if (nBuff && layouts)
959 if (count >= nBuff ) break;
960 layouts[count] = layout;
964 } while (rc == ERROR_SUCCESS);
965 RegCloseKey(hKeyKeyboard);
968 /* make sure our base layout is on the list */
971 if (nBuff && layouts)
975 layouts[count] = (HKL)baselayout;
987 /***********************************************************************
988 * RegisterHotKey (USER32.@)
990 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
993 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%X): stub\n",hwnd,id,modifiers,vk);
997 /***********************************************************************
998 * UnregisterHotKey (USER32.@)
1000 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
1003 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
1007 /***********************************************************************
1008 * LoadKeyboardLayoutW (USER32.@)
1010 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1012 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
1014 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
1017 /***********************************************************************
1018 * LoadKeyboardLayoutA (USER32.@)
1020 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
1023 UNICODE_STRING pwszKLIDW;
1025 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
1026 else pwszKLIDW.Buffer = NULL;
1028 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
1029 RtlFreeUnicodeString(&pwszKLIDW);
1034 /***********************************************************************
1035 * UnloadKeyboardLayout (USER32.@)
1037 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
1039 TRACE_(keyboard)("(%p)\n", hkl);
1041 return USER_Driver->pUnloadKeyboardLayout(hkl);
1044 typedef struct __TRACKINGLIST {
1045 TRACKMOUSEEVENT tme;
1046 POINT pos; /* center of hover rectangle */
1049 /* FIXME: move tracking stuff into a per thread data */
1050 static _TRACKINGLIST tracking_info;
1051 static UINT_PTR timer;
1053 static void check_mouse_leave(HWND hwnd, int hittest)
1055 if (tracking_info.tme.hwndTrack != hwnd)
1057 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1058 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
1060 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
1062 /* remove the TME_LEAVE flag */
1063 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1067 if (hittest == HTCLIENT)
1069 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1071 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
1072 /* remove the TME_LEAVE flag */
1073 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1078 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
1080 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
1081 /* remove the TME_LEAVE flag */
1082 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1088 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
1092 INT hoverwidth = 0, hoverheight = 0, hittest;
1094 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
1097 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
1099 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1101 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
1102 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
1104 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1105 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
1106 hoverwidth, hoverheight);
1108 /* see if this tracking event is looking for TME_LEAVE and that the */
1109 /* mouse has left the window */
1110 if (tracking_info.tme.dwFlags & TME_LEAVE)
1112 check_mouse_leave(hwnd, hittest);
1115 if (tracking_info.tme.hwndTrack != hwnd)
1117 /* mouse is gone, stop tracking mouse hover */
1118 tracking_info.tme.dwFlags &= ~TME_HOVER;
1121 /* see if we are tracking hovering for this hwnd */
1122 if (tracking_info.tme.dwFlags & TME_HOVER)
1124 /* has the cursor moved outside the rectangle centered around pos? */
1125 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
1126 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
1128 /* record this new position as the current position */
1129 tracking_info.pos = pos;
1133 if (hittest == HTCLIENT)
1135 ScreenToClient(hwnd, &pos);
1136 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
1138 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
1139 get_key_state(), MAKELPARAM( pos.x, pos.y ));
1143 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1144 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
1145 hittest, MAKELPARAM( pos.x, pos.y ));
1148 /* stop tracking mouse hover */
1149 tracking_info.tme.dwFlags &= ~TME_HOVER;
1153 /* stop the timer if the tracking list is empty */
1154 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1156 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1158 tracking_info.tme.hwndTrack = 0;
1159 tracking_info.tme.dwFlags = 0;
1160 tracking_info.tme.dwHoverTime = 0;
1165 /***********************************************************************
1166 * TrackMouseEvent [USER32]
1168 * Requests notification of mouse events
1170 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1171 * to the hwnd specified in the ptme structure. After the event message
1172 * is posted to the hwnd, the entry in the queue is removed.
1174 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1175 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1176 * immediately and the TME_LEAVE flag being ignored.
1179 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1188 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1195 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1197 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1198 WARN("wrong TRACKMOUSEEVENT size from app\n");
1199 SetLastError(ERROR_INVALID_PARAMETER);
1203 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1204 if (ptme->dwFlags & TME_QUERY )
1206 *ptme = tracking_info.tme;
1207 /* set cbSize in the case it's not initialized yet */
1208 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1210 return TRUE; /* return here, TME_QUERY is retrieving information */
1213 if (!IsWindow(ptme->hwndTrack))
1215 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1219 hover_time = (ptme->dwFlags & TME_HOVER) ? ptme->dwHoverTime : HOVER_DEFAULT;
1221 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1222 * TME_LEAVE doesn't need to specify hover time so use default */
1223 if (hover_time == HOVER_DEFAULT || hover_time == 0)
1224 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1227 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1228 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1230 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1231 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1233 if (ptme->dwFlags & TME_CANCEL)
1235 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1237 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1239 /* if we aren't tracking on hover or leave remove this entry */
1240 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1242 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1244 tracking_info.tme.hwndTrack = 0;
1245 tracking_info.tme.dwFlags = 0;
1246 tracking_info.tme.dwHoverTime = 0;
1250 /* In our implementation it's possible that another window will receive a
1251 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1252 * called. In such a situation post the WM_MOUSELEAVE now */
1253 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1254 check_mouse_leave(hwnd, hittest);
1258 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1260 tracking_info.tme.hwndTrack = 0;
1261 tracking_info.tme.dwFlags = 0;
1262 tracking_info.tme.dwHoverTime = 0;
1265 if (ptme->hwndTrack == hwnd)
1267 /* Adding new mouse event to the tracking list */
1268 tracking_info.tme = *ptme;
1269 tracking_info.tme.dwHoverTime = hover_time;
1271 /* Initialize HoverInfo variables even if not hover tracking */
1272 tracking_info.pos = pos;
1274 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1281 /***********************************************************************
1282 * GetMouseMovePointsEx [USER32]
1285 * Success: count of point set in the buffer
1288 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1290 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1291 SetLastError(ERROR_INVALID_PARAMETER);
1295 if(!ptin || (!ptout && count)) {
1296 SetLastError(ERROR_NOACCESS);
1300 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1302 SetLastError(ERROR_POINT_NOT_FOUND);