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;
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;
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 )
214 SERVER_START_REQ( get_thread_input )
217 if ((ret = !wine_server_call( req )))
219 pci->hCursor = wine_server_ptr_handle( reply->cursor );
220 pci->flags = (reply->show_count >= 0) ? CURSOR_SHOWING : 0;
224 GetCursorPos(&pci->ptScreenPos);
229 /***********************************************************************
230 * SetCursorPos (USER32.@)
232 BOOL WINAPI DECLSPEC_HOTPATCH SetCursorPos( INT x, INT y )
236 SERVER_START_REQ( set_cursor )
238 req->flags = SET_CURSOR_POS;
241 if ((ret = !wine_server_call( req )))
248 if (ret) ret = USER_Driver->pSetCursorPos( x, y );
253 /**********************************************************************
254 * SetCapture (USER32.@)
256 HWND WINAPI DECLSPEC_HOTPATCH SetCapture( HWND hwnd )
260 set_capture_window( hwnd, 0, &previous );
265 /**********************************************************************
266 * ReleaseCapture (USER32.@)
268 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseCapture(void)
270 BOOL ret = set_capture_window( 0, 0, NULL );
272 /* Somebody may have missed some mouse movements */
273 if (ret) mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
279 /**********************************************************************
280 * GetCapture (USER32.@)
282 HWND WINAPI GetCapture(void)
286 SERVER_START_REQ( get_thread_input )
288 req->tid = GetCurrentThreadId();
289 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->capture );
296 /**********************************************************************
297 * GetAsyncKeyState (USER32.@)
299 * Determine if a key is or was pressed. retval has high-order
300 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
303 SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState(INT nKey)
305 if (nKey < 0 || nKey > 256)
307 return USER_Driver->pGetAsyncKeyState( nKey );
311 /***********************************************************************
312 * GetQueueStatus (USER32.@)
314 DWORD WINAPI GetQueueStatus( UINT flags )
318 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
320 SetLastError( ERROR_INVALID_FLAGS );
324 /* check for pending X events */
325 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
327 SERVER_START_REQ( get_queue_status )
330 wine_server_call( req );
331 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
338 /***********************************************************************
339 * GetInputState (USER32.@)
341 BOOL WINAPI GetInputState(void)
345 /* check for pending X events */
346 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
348 SERVER_START_REQ( get_queue_status )
351 wine_server_call( req );
352 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
359 /******************************************************************
360 * GetLastInputInfo (USER32.@)
362 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
368 if (plii->cbSize != sizeof (*plii) )
370 SetLastError(ERROR_INVALID_PARAMETER);
374 SERVER_START_REQ( get_last_input_time )
376 ret = !wine_server_call_err( req );
378 plii->dwTime = reply->time;
385 /******************************************************************
386 * GetRawInputDeviceList (USER32.@)
388 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
390 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
392 if(pRawInputDeviceList)
393 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
399 /******************************************************************
400 * RegisterRawInputDevices (USER32.@)
402 BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
404 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
410 /******************************************************************
411 * GetRawInputData (USER32.@)
413 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
415 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
416 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
422 /******************************************************************
423 * GetRawInputBuffer (USER32.@)
425 UINT WINAPI DECLSPEC_HOTPATCH GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
427 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
433 /******************************************************************
434 * GetRawInputDeviceInfoA (USER32.@)
436 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
438 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
444 /******************************************************************
445 * GetRawInputDeviceInfoW (USER32.@)
447 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
449 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
455 /******************************************************************
456 * GetRegisteredRawInputDevices (USER32.@)
458 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
460 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
466 /******************************************************************
467 * DefRawInputProc (USER32.@)
469 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
471 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
477 /**********************************************************************
478 * AttachThreadInput (USER32.@)
480 * Attaches the input processing mechanism of one thread to that of
483 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
487 SERVER_START_REQ( attach_thread_input )
489 req->tid_from = from;
491 req->attach = attach;
492 ret = !wine_server_call_err( req );
499 /**********************************************************************
500 * GetKeyState (USER32.@)
502 * An application calls the GetKeyState function in response to a
503 * keyboard-input message. This function retrieves the state of the key
504 * at the time the input message was generated.
506 SHORT WINAPI DECLSPEC_HOTPATCH GetKeyState(INT vkey)
510 SERVER_START_REQ( get_key_state )
512 req->tid = GetCurrentThreadId();
514 if (!wine_server_call( req )) retval = (signed char)reply->state;
517 TRACE("key (0x%x) -> %x\n", vkey, retval);
522 /**********************************************************************
523 * GetKeyboardState (USER32.@)
525 BOOL WINAPI DECLSPEC_HOTPATCH GetKeyboardState( LPBYTE state )
529 TRACE("(%p)\n", state);
531 memset( state, 0, 256 );
532 SERVER_START_REQ( get_key_state )
534 req->tid = GetCurrentThreadId();
536 wine_server_set_reply( req, state, 256 );
537 ret = !wine_server_call_err( req );
544 /**********************************************************************
545 * SetKeyboardState (USER32.@)
547 BOOL WINAPI SetKeyboardState( LPBYTE state )
551 SERVER_START_REQ( set_key_state )
553 req->tid = GetCurrentThreadId();
554 wine_server_add_data( req, state, 256 );
555 ret = !wine_server_call_err( req );
562 /**********************************************************************
563 * VkKeyScanA (USER32.@)
565 * VkKeyScan translates an ANSI character to a virtual-key and shift code
566 * for the current keyboard.
567 * high-order byte yields :
571 * 3-5 Shift-key combinations that are not used for characters
574 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
575 * FIXME : works ok except for dead chars :
576 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
577 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
579 SHORT WINAPI VkKeyScanA(CHAR cChar)
583 if (IsDBCSLeadByte(cChar)) return -1;
585 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
586 return VkKeyScanW(wChar);
589 /******************************************************************************
590 * VkKeyScanW (USER32.@)
592 SHORT WINAPI VkKeyScanW(WCHAR cChar)
594 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
597 /**********************************************************************
598 * VkKeyScanExA (USER32.@)
600 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
604 if (IsDBCSLeadByte(cChar)) return -1;
606 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
607 return VkKeyScanExW(wChar, dwhkl);
610 /******************************************************************************
611 * VkKeyScanExW (USER32.@)
613 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
615 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
618 /**********************************************************************
619 * OemKeyScan (USER32.@)
621 DWORD WINAPI OemKeyScan(WORD wOemChar)
626 /******************************************************************************
627 * GetKeyboardType (USER32.@)
629 INT WINAPI GetKeyboardType(INT nTypeFlag)
631 TRACE_(keyboard)("(%d)\n", nTypeFlag);
634 case 0: /* Keyboard type */
635 return 4; /* AT-101 */
636 case 1: /* Keyboard Subtype */
637 return 0; /* There are no defined subtypes */
638 case 2: /* Number of F-keys */
639 return 12; /* We're doing an 101 for now, so return 12 F-keys */
641 WARN_(keyboard)("Unknown type\n");
642 return 0; /* The book says 0 here, so 0 */
646 /******************************************************************************
647 * MapVirtualKeyA (USER32.@)
649 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
651 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
654 /******************************************************************************
655 * MapVirtualKeyW (USER32.@)
657 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
659 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
662 /******************************************************************************
663 * MapVirtualKeyExA (USER32.@)
665 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
669 ret = MapVirtualKeyExW( code, maptype, hkl );
670 if (maptype == MAPVK_VK_TO_CHAR)
675 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
681 /******************************************************************************
682 * MapVirtualKeyExW (USER32.@)
684 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
686 TRACE_(keyboard)("(%X, %d, %p)\n", code, maptype, hkl);
688 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
691 /****************************************************************************
692 * GetKBCodePage (USER32.@)
694 UINT WINAPI GetKBCodePage(void)
699 /***********************************************************************
700 * GetKeyboardLayout (USER32.@)
702 * - device handle for keyboard layout defaulted to
703 * the language id. This is the way Windows default works.
704 * - the thread identifier is also ignored.
706 HKL WINAPI GetKeyboardLayout(DWORD thread_id)
708 return USER_Driver->pGetKeyboardLayout(thread_id);
711 /****************************************************************************
712 * GetKeyboardLayoutNameA (USER32.@)
714 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
716 WCHAR buf[KL_NAMELENGTH];
718 if (GetKeyboardLayoutNameW(buf))
719 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
723 /****************************************************************************
724 * GetKeyboardLayoutNameW (USER32.@)
726 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
728 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
731 /****************************************************************************
732 * GetKeyNameTextA (USER32.@)
734 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
739 if (!GetKeyNameTextW(lParam, buf, 256))
744 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
753 /****************************************************************************
754 * GetKeyNameTextW (USER32.@)
756 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
758 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
761 /****************************************************************************
762 * ToUnicode (USER32.@)
764 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
765 LPWSTR lpwStr, int size, UINT flags)
767 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
770 /****************************************************************************
771 * ToUnicodeEx (USER32.@)
773 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
774 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
776 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
779 /****************************************************************************
782 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
783 LPWORD lpChar, UINT flags )
785 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
788 /****************************************************************************
789 * ToAsciiEx (USER32.@)
791 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
792 LPWORD lpChar, UINT flags, HKL dwhkl )
797 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
798 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
800 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
804 /**********************************************************************
805 * ActivateKeyboardLayout (USER32.@)
807 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
809 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
811 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
814 /**********************************************************************
815 * BlockInput (USER32.@)
817 BOOL WINAPI BlockInput(BOOL fBlockIt)
819 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
820 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
825 /***********************************************************************
826 * GetKeyboardLayoutList (USER32.@)
828 * Return number of values available if either input parm is
829 * 0, per MS documentation.
831 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
836 ULONG_PTR baselayout;
838 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};
840 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
842 baselayout = GetUserDefaultLCID();
843 langid = PRIMARYLANGID(LANGIDFROMLCID(baselayout));
844 if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
845 baselayout |= 0xe001 << 16; /* IME */
847 baselayout |= baselayout << 16;
849 /* Enumerate the Registry */
850 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,szKeyboardReg,&hKeyKeyboard);
851 if (rc == ERROR_SUCCESS)
856 rc = RegEnumKeyW(hKeyKeyboard, count, szKeyName, 9);
857 if (rc == ERROR_SUCCESS)
859 layout = (HKL)strtoulW(szKeyName,NULL,16);
860 if (baselayout != 0 && layout == (HKL)baselayout)
861 baselayout = 0; /* found in the registry do not add again */
862 if (nBuff && layouts)
864 if (count >= nBuff ) break;
865 layouts[count] = layout;
869 } while (rc == ERROR_SUCCESS);
870 RegCloseKey(hKeyKeyboard);
873 /* make sure our base layout is on the list */
876 if (nBuff && layouts)
880 layouts[count] = (HKL)baselayout;
892 /***********************************************************************
893 * RegisterHotKey (USER32.@)
895 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
898 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%X): stub\n",hwnd,id,modifiers,vk);
902 /***********************************************************************
903 * UnregisterHotKey (USER32.@)
905 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
908 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
912 /***********************************************************************
913 * LoadKeyboardLayoutW (USER32.@)
915 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
917 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
919 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
922 /***********************************************************************
923 * LoadKeyboardLayoutA (USER32.@)
925 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
928 UNICODE_STRING pwszKLIDW;
930 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
931 else pwszKLIDW.Buffer = NULL;
933 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
934 RtlFreeUnicodeString(&pwszKLIDW);
939 /***********************************************************************
940 * UnloadKeyboardLayout (USER32.@)
942 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
944 TRACE_(keyboard)("(%p)\n", hkl);
946 return USER_Driver->pUnloadKeyboardLayout(hkl);
949 typedef struct __TRACKINGLIST {
951 POINT pos; /* center of hover rectangle */
954 /* FIXME: move tracking stuff into a per thread data */
955 static _TRACKINGLIST tracking_info;
956 static UINT_PTR timer;
958 static void check_mouse_leave(HWND hwnd, int hittest)
960 if (tracking_info.tme.hwndTrack != hwnd)
962 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
963 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
965 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
967 /* remove the TME_LEAVE flag */
968 tracking_info.tme.dwFlags &= ~TME_LEAVE;
972 if (hittest == HTCLIENT)
974 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
976 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
977 /* remove the TME_LEAVE flag */
978 tracking_info.tme.dwFlags &= ~TME_LEAVE;
983 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
985 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
986 /* remove the TME_LEAVE flag */
987 tracking_info.tme.dwFlags &= ~TME_LEAVE;
993 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
997 INT hoverwidth = 0, hoverheight = 0, hittest;
999 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
1002 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
1004 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1006 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
1007 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
1009 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
1010 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
1011 hoverwidth, hoverheight);
1013 /* see if this tracking event is looking for TME_LEAVE and that the */
1014 /* mouse has left the window */
1015 if (tracking_info.tme.dwFlags & TME_LEAVE)
1017 check_mouse_leave(hwnd, hittest);
1020 if (tracking_info.tme.hwndTrack != hwnd)
1022 /* mouse is gone, stop tracking mouse hover */
1023 tracking_info.tme.dwFlags &= ~TME_HOVER;
1026 /* see if we are tracking hovering for this hwnd */
1027 if (tracking_info.tme.dwFlags & TME_HOVER)
1029 /* has the cursor moved outside the rectangle centered around pos? */
1030 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
1031 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
1033 /* record this new position as the current position */
1034 tracking_info.pos = pos;
1038 if (hittest == HTCLIENT)
1040 ScreenToClient(hwnd, &pos);
1041 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
1043 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
1044 get_key_state(), MAKELPARAM( pos.x, pos.y ));
1048 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1049 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
1050 hittest, MAKELPARAM( pos.x, pos.y ));
1053 /* stop tracking mouse hover */
1054 tracking_info.tme.dwFlags &= ~TME_HOVER;
1058 /* stop the timer if the tracking list is empty */
1059 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1061 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1063 tracking_info.tme.hwndTrack = 0;
1064 tracking_info.tme.dwFlags = 0;
1065 tracking_info.tme.dwHoverTime = 0;
1070 /***********************************************************************
1071 * TrackMouseEvent [USER32]
1073 * Requests notification of mouse events
1075 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1076 * to the hwnd specified in the ptme structure. After the event message
1077 * is posted to the hwnd, the entry in the queue is removed.
1079 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1080 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1081 * immediately and the TME_LEAVE flag being ignored.
1084 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1093 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1100 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1102 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1103 WARN("wrong TRACKMOUSEEVENT size from app\n");
1104 SetLastError(ERROR_INVALID_PARAMETER);
1108 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1109 if (ptme->dwFlags & TME_QUERY )
1111 *ptme = tracking_info.tme;
1112 /* set cbSize in the case it's not initialized yet */
1113 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1115 return TRUE; /* return here, TME_QUERY is retrieving information */
1118 if (!IsWindow(ptme->hwndTrack))
1120 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1124 hover_time = (ptme->dwFlags & TME_HOVER) ? ptme->dwHoverTime : HOVER_DEFAULT;
1126 /* if HOVER_DEFAULT was specified replace this with the system's current value.
1127 * TME_LEAVE doesn't need to specify hover time so use default */
1128 if (hover_time == HOVER_DEFAULT || hover_time == 0)
1129 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1132 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1133 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1135 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1136 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1138 if (ptme->dwFlags & TME_CANCEL)
1140 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1142 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1144 /* if we aren't tracking on hover or leave remove this entry */
1145 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1147 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1149 tracking_info.tme.hwndTrack = 0;
1150 tracking_info.tme.dwFlags = 0;
1151 tracking_info.tme.dwHoverTime = 0;
1155 /* In our implementation it's possible that another window will receive a
1156 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1157 * called. In such a situation post the WM_MOUSELEAVE now */
1158 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1159 check_mouse_leave(hwnd, hittest);
1163 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1165 tracking_info.tme.hwndTrack = 0;
1166 tracking_info.tme.dwFlags = 0;
1167 tracking_info.tme.dwHoverTime = 0;
1170 if (ptme->hwndTrack == hwnd)
1172 /* Adding new mouse event to the tracking list */
1173 tracking_info.tme = *ptme;
1174 tracking_info.tme.dwHoverTime = hover_time;
1176 /* Initialize HoverInfo variables even if not hover tracking */
1177 tracking_info.pos = pos;
1179 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1186 /***********************************************************************
1187 * GetMouseMovePointsEx [USER32]
1190 * Success: count of point set in the buffer
1193 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1195 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1196 SetLastError(ERROR_INVALID_PARAMETER);
1200 if(!ptin || (!ptout && count)) {
1201 SetLastError(ERROR_NOACCESS);
1205 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1207 SetLastError(ERROR_POINT_NOT_FOUND);