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);
56 /***********************************************************************
59 static WORD get_key_state(void)
63 if (GetSystemMetrics( SM_SWAPBUTTON ))
65 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
66 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
70 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_LBUTTON;
71 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_RBUTTON;
73 if (GetAsyncKeyState(VK_MBUTTON) & 0x80) ret |= MK_MBUTTON;
74 if (GetAsyncKeyState(VK_SHIFT) & 0x80) ret |= MK_SHIFT;
75 if (GetAsyncKeyState(VK_CONTROL) & 0x80) ret |= MK_CONTROL;
76 if (GetAsyncKeyState(VK_XBUTTON1) & 0x80) ret |= MK_XBUTTON1;
77 if (GetAsyncKeyState(VK_XBUTTON2) & 0x80) ret |= MK_XBUTTON2;
82 /**********************************************************************
85 BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret )
91 if (gui_flags & GUI_INMENUMODE) flags |= CAPTURE_MENU;
92 if (gui_flags & GUI_INMOVESIZE) flags |= CAPTURE_MOVESIZE;
94 SERVER_START_REQ( set_capture_window )
96 req->handle = wine_server_user_handle( hwnd );
98 if ((ret = !wine_server_call_err( req )))
100 previous = wine_server_ptr_handle( reply->previous );
101 hwnd = wine_server_ptr_handle( reply->full_handle );
108 USER_Driver->pSetCapture( hwnd, gui_flags );
110 if (previous && previous != hwnd)
111 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
113 if (prev_ret) *prev_ret = previous;
119 /***********************************************************************
120 * __wine_send_input (USER32.@)
122 * Internal SendInput function to allow the graphics driver to inject real events.
124 BOOL CDECL __wine_send_input( HWND hwnd, const INPUT *input )
126 NTSTATUS status = send_hardware_message( hwnd, input, 0 );
127 if (status) SetLastError( RtlNtStatusToDosError(status) );
132 /***********************************************************************
133 * update_mouse_coords
135 * Helper for SendInput.
137 static void update_mouse_coords( INPUT *input )
139 if (!(input->u.mi.dwFlags & MOUSEEVENTF_MOVE)) return;
141 if (input->u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE)
143 input->u.mi.dx = (input->u.mi.dx * GetSystemMetrics( SM_CXSCREEN )) >> 16;
144 input->u.mi.dy = (input->u.mi.dy * GetSystemMetrics( SM_CYSCREEN )) >> 16;
150 /* dx and dy can be negative numbers for relative movements */
151 SystemParametersInfoW(SPI_GETMOUSE, 0, accel, 0);
153 if (!accel[2]) return;
155 if (abs(input->u.mi.dx) > accel[0])
158 if ((abs(input->u.mi.dx) > accel[1]) && (accel[2] == 2)) input->u.mi.dx *= 2;
160 if (abs(input->u.mi.dy) > accel[0])
163 if ((abs(input->u.mi.dy) > accel[1]) && (accel[2] == 2)) input->u.mi.dy *= 2;
168 /***********************************************************************
169 * SendInput (USER32.@)
171 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
176 for (i = 0; i < count; i++)
178 if (inputs[i].type == INPUT_MOUSE)
180 /* we need to update the coordinates to what the server expects */
181 INPUT input = inputs[i];
182 update_mouse_coords( &input );
183 if (!(status = send_hardware_message( 0, &input, SEND_HWMSG_INJECTED )))
185 if ((input.u.mi.dwFlags & MOUSEEVENTF_MOVE) &&
186 ((input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE) || input.u.mi.dx || input.u.mi.dy))
188 /* we have to actually move the cursor */
191 if (!(input.u.mi.dwFlags & MOUSEEVENTF_ABSOLUTE) ||
192 pt.x != input.u.mi.dx || pt.y != input.u.mi.dy)
193 USER_Driver->pSetCursorPos( pt.x, pt.y );
197 else status = send_hardware_message( 0, &inputs[i], SEND_HWMSG_INJECTED );
201 SetLastError( RtlNtStatusToDosError(status) );
210 /***********************************************************************
211 * keybd_event (USER32.@)
213 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
214 DWORD dwFlags, ULONG_PTR dwExtraInfo )
218 input.type = INPUT_KEYBOARD;
219 input.u.ki.wVk = bVk;
220 input.u.ki.wScan = bScan;
221 input.u.ki.dwFlags = dwFlags;
223 input.u.ki.dwExtraInfo = dwExtraInfo;
224 SendInput( 1, &input, sizeof(input) );
228 /***********************************************************************
229 * mouse_event (USER32.@)
231 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
232 DWORD dwData, ULONG_PTR dwExtraInfo )
236 input.type = INPUT_MOUSE;
239 input.u.mi.mouseData = dwData;
240 input.u.mi.dwFlags = dwFlags;
242 input.u.mi.dwExtraInfo = dwExtraInfo;
243 SendInput( 1, &input, sizeof(input) );
247 /***********************************************************************
248 * GetCursorPos (USER32.@)
250 BOOL WINAPI DECLSPEC_HOTPATCH GetCursorPos( POINT *pt )
255 if (!pt) return FALSE;
257 SERVER_START_REQ( set_cursor )
259 if ((ret = !wine_server_call( req )))
261 pt->x = reply->new_x;
262 pt->y = reply->new_y;
263 last_change = reply->last_change;
268 /* query new position from graphics driver if we haven't updated recently */
269 if (ret && GetTickCount() - last_change > 100) ret = USER_Driver->pGetCursorPos( pt );
274 /***********************************************************************
275 * GetCursorInfo (USER32.@)
277 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
283 SERVER_START_REQ( get_thread_input )
286 if ((ret = !wine_server_call( req )))
288 pci->hCursor = wine_server_ptr_handle( reply->cursor );
289 pci->flags = (reply->show_count >= 0) ? CURSOR_SHOWING : 0;
293 GetCursorPos(&pci->ptScreenPos);
298 /***********************************************************************
299 * SetCursorPos (USER32.@)
301 BOOL WINAPI DECLSPEC_HOTPATCH SetCursorPos( INT x, INT y )
304 INT prev_x, prev_y, new_x, new_y;
306 SERVER_START_REQ( set_cursor )
308 req->flags = SET_CURSOR_POS;
311 if ((ret = !wine_server_call( req )))
313 prev_x = reply->prev_x;
314 prev_y = reply->prev_y;
315 new_x = reply->new_x;
316 new_y = reply->new_y;
320 if (ret && (prev_x != new_x || prev_y != new_y)) USER_Driver->pSetCursorPos( new_x, new_y );
325 /**********************************************************************
326 * SetCapture (USER32.@)
328 HWND WINAPI DECLSPEC_HOTPATCH SetCapture( HWND hwnd )
332 set_capture_window( hwnd, 0, &previous );
337 /**********************************************************************
338 * ReleaseCapture (USER32.@)
340 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseCapture(void)
342 BOOL ret = set_capture_window( 0, 0, NULL );
344 /* Somebody may have missed some mouse movements */
345 if (ret) mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
351 /**********************************************************************
352 * GetCapture (USER32.@)
354 HWND WINAPI GetCapture(void)
358 SERVER_START_REQ( get_thread_input )
360 req->tid = GetCurrentThreadId();
361 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->capture );
368 /**********************************************************************
369 * GetAsyncKeyState (USER32.@)
371 * Determine if a key is or was pressed. retval has high-order
372 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
375 SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
377 struct user_thread_info *thread_info = get_user_thread_info();
380 if (key < 0 || key >= 256) return 0;
382 if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1)
384 if (thread_info->key_state)
386 if (GetTickCount() - thread_info->key_state_time < 50)
387 return (thread_info->key_state[key] & 0x80) ? 0x8000 : 0;
389 else thread_info->key_state = HeapAlloc( GetProcessHeap(), 0, 256 );
392 SERVER_START_REQ( get_key_state )
396 if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
397 if (!wine_server_call( req ))
399 if (reply->state & 0x40) ret |= 0x0001;
400 if (reply->state & 0x80) ret |= 0x8000;
401 thread_info->key_state_time = GetTickCount();
410 /***********************************************************************
411 * GetQueueStatus (USER32.@)
413 DWORD WINAPI GetQueueStatus( UINT flags )
417 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
419 SetLastError( ERROR_INVALID_FLAGS );
423 /* check for pending X events */
424 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
426 SERVER_START_REQ( get_queue_status )
429 wine_server_call( req );
430 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
437 /***********************************************************************
438 * GetInputState (USER32.@)
440 BOOL WINAPI GetInputState(void)
444 /* check for pending X events */
445 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
447 SERVER_START_REQ( get_queue_status )
450 wine_server_call( req );
451 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
458 /******************************************************************
459 * GetLastInputInfo (USER32.@)
461 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
467 if (plii->cbSize != sizeof (*plii) )
469 SetLastError(ERROR_INVALID_PARAMETER);
473 SERVER_START_REQ( get_last_input_time )
475 ret = !wine_server_call_err( req );
477 plii->dwTime = reply->time;
484 /******************************************************************
485 * GetRawInputDeviceList (USER32.@)
487 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
489 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
491 if(pRawInputDeviceList)
492 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
498 /******************************************************************
499 * RegisterRawInputDevices (USER32.@)
501 BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
503 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
509 /******************************************************************
510 * GetRawInputData (USER32.@)
512 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
514 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
515 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
521 /******************************************************************
522 * GetRawInputBuffer (USER32.@)
524 UINT WINAPI DECLSPEC_HOTPATCH GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
526 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
532 /******************************************************************
533 * GetRawInputDeviceInfoA (USER32.@)
535 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
537 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
543 /******************************************************************
544 * GetRawInputDeviceInfoW (USER32.@)
546 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
548 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
554 /******************************************************************
555 * GetRegisteredRawInputDevices (USER32.@)
557 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
559 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
565 /******************************************************************
566 * DefRawInputProc (USER32.@)
568 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
570 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
576 /**********************************************************************
577 * AttachThreadInput (USER32.@)
579 * Attaches the input processing mechanism of one thread to that of
582 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
586 SERVER_START_REQ( attach_thread_input )
588 req->tid_from = from;
590 req->attach = attach;
591 ret = !wine_server_call_err( req );
598 /**********************************************************************
599 * GetKeyState (USER32.@)
601 * An application calls the GetKeyState function in response to a
602 * keyboard-input message. This function retrieves the state of the key
603 * at the time the input message was generated.
605 SHORT WINAPI DECLSPEC_HOTPATCH GetKeyState(INT vkey)
609 SERVER_START_REQ( get_key_state )
611 req->tid = GetCurrentThreadId();
613 if (!wine_server_call( req )) retval = (signed char)reply->state;
616 TRACE("key (0x%x) -> %x\n", vkey, retval);
621 /**********************************************************************
622 * GetKeyboardState (USER32.@)
624 BOOL WINAPI DECLSPEC_HOTPATCH GetKeyboardState( LPBYTE state )
628 TRACE("(%p)\n", state);
630 memset( state, 0, 256 );
631 SERVER_START_REQ( get_key_state )
633 req->tid = GetCurrentThreadId();
635 wine_server_set_reply( req, state, 256 );
636 ret = !wine_server_call_err( req );
643 /**********************************************************************
644 * SetKeyboardState (USER32.@)
646 BOOL WINAPI SetKeyboardState( LPBYTE state )
650 SERVER_START_REQ( set_key_state )
652 req->tid = GetCurrentThreadId();
653 wine_server_add_data( req, state, 256 );
654 ret = !wine_server_call_err( req );
661 /**********************************************************************
662 * VkKeyScanA (USER32.@)
664 * VkKeyScan translates an ANSI character to a virtual-key and shift code
665 * for the current keyboard.
666 * high-order byte yields :
670 * 3-5 Shift-key combinations that are not used for characters
673 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
674 * FIXME : works ok except for dead chars :
675 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
676 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
678 SHORT WINAPI VkKeyScanA(CHAR cChar)
682 if (IsDBCSLeadByte(cChar)) return -1;
684 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
685 return VkKeyScanW(wChar);
688 /******************************************************************************
689 * VkKeyScanW (USER32.@)
691 SHORT WINAPI VkKeyScanW(WCHAR cChar)
693 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
696 /**********************************************************************
697 * VkKeyScanExA (USER32.@)
699 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
703 if (IsDBCSLeadByte(cChar)) return -1;
705 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
706 return VkKeyScanExW(wChar, dwhkl);
709 /******************************************************************************
710 * VkKeyScanExW (USER32.@)
712 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
714 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
717 /**********************************************************************
718 * OemKeyScan (USER32.@)
720 DWORD WINAPI OemKeyScan(WORD wOemChar)
725 /******************************************************************************
726 * GetKeyboardType (USER32.@)
728 INT WINAPI GetKeyboardType(INT nTypeFlag)
730 TRACE_(keyboard)("(%d)\n", nTypeFlag);
733 case 0: /* Keyboard type */
734 return 4; /* AT-101 */
735 case 1: /* Keyboard Subtype */
736 return 0; /* There are no defined subtypes */
737 case 2: /* Number of F-keys */
738 return 12; /* We're doing an 101 for now, so return 12 F-keys */
740 WARN_(keyboard)("Unknown type\n");
741 return 0; /* The book says 0 here, so 0 */
745 /******************************************************************************
746 * MapVirtualKeyA (USER32.@)
748 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
750 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
753 /******************************************************************************
754 * MapVirtualKeyW (USER32.@)
756 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
758 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
761 /******************************************************************************
762 * MapVirtualKeyExA (USER32.@)
764 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
768 ret = MapVirtualKeyExW( code, maptype, hkl );
769 if (maptype == MAPVK_VK_TO_CHAR)
774 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
780 /******************************************************************************
781 * MapVirtualKeyExW (USER32.@)
783 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
785 TRACE_(keyboard)("(%X, %d, %p)\n", code, maptype, hkl);
787 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
790 /****************************************************************************
791 * GetKBCodePage (USER32.@)
793 UINT WINAPI GetKBCodePage(void)
798 /***********************************************************************
799 * GetKeyboardLayout (USER32.@)
801 * - device handle for keyboard layout defaulted to
802 * the language id. This is the way Windows default works.
803 * - the thread identifier is also ignored.
805 HKL WINAPI GetKeyboardLayout(DWORD thread_id)
807 return USER_Driver->pGetKeyboardLayout(thread_id);
810 /****************************************************************************
811 * GetKeyboardLayoutNameA (USER32.@)
813 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
815 WCHAR buf[KL_NAMELENGTH];
817 if (GetKeyboardLayoutNameW(buf))
818 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
822 /****************************************************************************
823 * GetKeyboardLayoutNameW (USER32.@)
825 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
827 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
830 /****************************************************************************
831 * GetKeyNameTextA (USER32.@)
833 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
838 if (!GetKeyNameTextW(lParam, buf, 256))
843 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
852 /****************************************************************************
853 * GetKeyNameTextW (USER32.@)
855 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
857 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
860 /****************************************************************************
861 * ToUnicode (USER32.@)
863 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
864 LPWSTR lpwStr, int size, UINT flags)
866 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
869 /****************************************************************************
870 * ToUnicodeEx (USER32.@)
872 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
873 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
875 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
878 /****************************************************************************
881 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
882 LPWORD lpChar, UINT flags )
884 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
887 /****************************************************************************
888 * ToAsciiEx (USER32.@)
890 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
891 LPWORD lpChar, UINT flags, HKL dwhkl )
896 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
897 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
899 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
903 /**********************************************************************
904 * ActivateKeyboardLayout (USER32.@)
906 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
908 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
910 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
913 /**********************************************************************
914 * BlockInput (USER32.@)
916 BOOL WINAPI BlockInput(BOOL fBlockIt)
918 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
919 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
924 /***********************************************************************
925 * GetKeyboardLayoutList (USER32.@)
927 * Return number of values available if either input parm is
928 * 0, per MS documentation.
930 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
935 ULONG_PTR baselayout;
937 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};
939 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
941 baselayout = GetUserDefaultLCID();
942 langid = PRIMARYLANGID(LANGIDFROMLCID(baselayout));
943 if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
944 baselayout |= 0xe001 << 16; /* IME */
946 baselayout |= baselayout << 16;
948 /* Enumerate the Registry */
949 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,szKeyboardReg,&hKeyKeyboard);
950 if (rc == ERROR_SUCCESS)
955 rc = RegEnumKeyW(hKeyKeyboard, count, szKeyName, 9);
956 if (rc == ERROR_SUCCESS)
958 layout = (HKL)strtoulW(szKeyName,NULL,16);
959 if (baselayout != 0 && layout == (HKL)baselayout)
960 baselayout = 0; /* found in the registry do not add again */
961 if (nBuff && layouts)
963 if (count >= nBuff ) break;
964 layouts[count] = layout;
968 } while (rc == ERROR_SUCCESS);
969 RegCloseKey(hKeyKeyboard);
972 /* make sure our base layout is on the list */
975 if (nBuff && layouts)
979 layouts[count] = (HKL)baselayout;
991 /***********************************************************************
992 * RegisterHotKey (USER32.@)
994 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
999 TRACE_(keyboard)("(%p,%d,0x%08x,%X)\n",hwnd,id,modifiers,vk);
1001 if ((hwnd == NULL || WIN_IsCurrentThread(hwnd)) &&
1002 !USER_Driver->pRegisterHotKey(hwnd, modifiers, vk))
1005 SERVER_START_REQ( register_hotkey )
1007 req->window = wine_server_user_handle( hwnd );
1009 req->flags = modifiers;
1011 if ((ret = !wine_server_call_err( req )))
1013 replaced = reply->replaced;
1014 modifiers = reply->flags;
1020 if (ret && replaced)
1021 USER_Driver->pUnregisterHotKey(hwnd, modifiers, vk);
1026 /***********************************************************************
1027 * UnregisterHotKey (USER32.@)
1029 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
1034 TRACE_(keyboard)("(%p,%d)\n",hwnd,id);
1036 SERVER_START_REQ( unregister_hotkey )
1038 req->window = wine_server_user_handle( hwnd );
1040 if ((ret = !wine_server_call_err( req )))
1042 modifiers = reply->flags;
1049 USER_Driver->pUnregisterHotKey(hwnd, modifiers, vk);
1054 /***********************************************************************
1055 * LoadKeyboardLayoutW (USER32.@)
1057 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
1059 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
1061 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
1064 /***********************************************************************
1065 * LoadKeyboardLayoutA (USER32.@)
1067 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
1070 UNICODE_STRING pwszKLIDW;
1072 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
1073 else pwszKLIDW.Buffer = NULL;
1075 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
1076 RtlFreeUnicodeString(&pwszKLIDW);
1081 /***********************************************************************
1082 * UnloadKeyboardLayout (USER32.@)
1084 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
1086 TRACE_(keyboard)("(%p)\n", hkl);
1088 return USER_Driver->pUnloadKeyboardLayout(hkl);
1091 typedef struct __TRACKINGLIST {
1092 TRACKMOUSEEVENT tme;
1093 POINT pos; /* center of hover rectangle */
1096 /* FIXME: move tracking stuff into a per thread data */
1097 static _TRACKINGLIST tracking_info;
1098 static UINT_PTR timer;
1100 static void check_mouse_leave(HWND hwnd, int hittest)
1102 if (tracking_info.tme.hwndTrack != hwnd)
1104 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1105 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
1107 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
1109 /* remove the TME_LEAVE flag */
1110 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1114 if (hittest == HTCLIENT)
1116 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1118 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
1119 /* remove the TME_LEAVE flag */
1120 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1125 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
1127 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
1128 /* remove the TME_LEAVE flag */
1129 tracking_info.tme.dwFlags &= ~TME_LEAVE;
1135 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
1139 INT hoverwidth = 0, hoverheight = 0, hittest;
1141 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
1144 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
1146 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1148 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
1149 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
1151 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1152 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
1153 hoverwidth, hoverheight);
1155 /* see if this tracking event is looking for TME_LEAVE and that the */
1156 /* mouse has left the window */
1157 if (tracking_info.tme.dwFlags & TME_LEAVE)
1159 check_mouse_leave(hwnd, hittest);
1162 if (tracking_info.tme.hwndTrack != hwnd)
1164 /* mouse is gone, stop tracking mouse hover */
1165 tracking_info.tme.dwFlags &= ~TME_HOVER;
1168 /* see if we are tracking hovering for this hwnd */
1169 if (tracking_info.tme.dwFlags & TME_HOVER)
1171 /* has the cursor moved outside the rectangle centered around pos? */
1172 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
1173 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
1175 /* record this new position as the current position */
1176 tracking_info.pos = pos;
1180 if (hittest == HTCLIENT)
1182 ScreenToClient(hwnd, &pos);
1183 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
1185 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
1186 get_key_state(), MAKELPARAM( pos.x, pos.y ));
1190 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1191 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
1192 hittest, MAKELPARAM( pos.x, pos.y ));
1195 /* stop tracking mouse hover */
1196 tracking_info.tme.dwFlags &= ~TME_HOVER;
1200 /* stop the timer if the tracking list is empty */
1201 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1203 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1205 tracking_info.tme.hwndTrack = 0;
1206 tracking_info.tme.dwFlags = 0;
1207 tracking_info.tme.dwHoverTime = 0;
1212 /***********************************************************************
1213 * TrackMouseEvent [USER32]
1215 * Requests notification of mouse events
1217 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1218 * to the hwnd specified in the ptme structure. After the event message
1219 * is posted to the hwnd, the entry in the queue is removed.
1221 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1222 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1223 * immediately and the TME_LEAVE flag being ignored.
1226 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1235 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1242 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1244 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1245 WARN("wrong TRACKMOUSEEVENT size from app\n");
1246 SetLastError(ERROR_INVALID_PARAMETER);
1250 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1251 if (ptme->dwFlags & TME_QUERY )
1253 *ptme = tracking_info.tme;
1254 /* set cbSize in the case it's not initialized yet */
1255 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1257 return TRUE; /* return here, TME_QUERY is retrieving information */
1260 if (!IsWindow(ptme->hwndTrack))
1262 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1266 hover_time = (ptme->dwFlags & TME_HOVER) ? ptme->dwHoverTime : HOVER_DEFAULT;
1268 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1269 * TME_LEAVE doesn't need to specify hover time so use default */
1270 if (hover_time == HOVER_DEFAULT || hover_time == 0)
1271 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1274 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1275 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1277 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1278 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1280 if (ptme->dwFlags & TME_CANCEL)
1282 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1284 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1286 /* if we aren't tracking on hover or leave remove this entry */
1287 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1289 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1291 tracking_info.tme.hwndTrack = 0;
1292 tracking_info.tme.dwFlags = 0;
1293 tracking_info.tme.dwHoverTime = 0;
1297 /* In our implementation it's possible that another window will receive a
1298 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1299 * called. In such a situation post the WM_MOUSELEAVE now */
1300 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1301 check_mouse_leave(hwnd, hittest);
1305 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1307 tracking_info.tme.hwndTrack = 0;
1308 tracking_info.tme.dwFlags = 0;
1309 tracking_info.tme.dwHoverTime = 0;
1312 if (ptme->hwndTrack == hwnd)
1314 /* Adding new mouse event to the tracking list */
1315 tracking_info.tme = *ptme;
1316 tracking_info.tme.dwHoverTime = hover_time;
1318 /* Initialize HoverInfo variables even if not hover tracking */
1319 tracking_info.pos = pos;
1321 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1328 /***********************************************************************
1329 * GetMouseMovePointsEx [USER32]
1332 * Success: count of point set in the buffer
1335 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1337 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1338 SetLastError(ERROR_INVALID_PARAMETER);
1342 if(!ptin || (!ptout && count)) {
1343 SetLastError(ERROR_NOACCESS);
1347 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1349 SetLastError(ERROR_POINT_NOT_FOUND);