2 * USER Input processing
4 * Copyright 1993 Bob Amstadt
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1997 David Faure
7 * Copyright 1998 Morten Welinder
8 * Copyright 1998 Ulrich Weigand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
45 #include "user_private.h"
46 #include "wine/server.h"
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(win);
51 WINE_DECLARE_DEBUG_CHANNEL(keyboard);
54 /***********************************************************************
57 static WORD get_key_state(void)
61 if (GetSystemMetrics( SM_SWAPBUTTON ))
63 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
64 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
68 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_LBUTTON;
69 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_RBUTTON;
71 if (GetAsyncKeyState(VK_MBUTTON) & 0x80) ret |= MK_MBUTTON;
72 if (GetAsyncKeyState(VK_SHIFT) & 0x80) ret |= MK_SHIFT;
73 if (GetAsyncKeyState(VK_CONTROL) & 0x80) ret |= MK_CONTROL;
74 if (GetAsyncKeyState(VK_XBUTTON1) & 0x80) ret |= MK_XBUTTON1;
75 if (GetAsyncKeyState(VK_XBUTTON2) & 0x80) ret |= MK_XBUTTON2;
80 /**********************************************************************
83 BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret )
89 if (gui_flags & GUI_INMENUMODE) flags |= CAPTURE_MENU;
90 if (gui_flags & GUI_INMOVESIZE) flags |= CAPTURE_MOVESIZE;
92 SERVER_START_REQ( set_capture_window )
94 req->handle = wine_server_user_handle( hwnd );
96 if ((ret = !wine_server_call_err( req )))
98 previous = wine_server_ptr_handle( reply->previous );
99 hwnd = wine_server_ptr_handle( reply->full_handle );
106 USER_Driver->pSetCapture( hwnd, gui_flags );
108 if (previous && previous != hwnd)
109 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
111 if (prev_ret) *prev_ret = previous;
117 /***********************************************************************
118 * SendInput (USER32.@)
120 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
126 for (i = 0; i < count; i++)
128 switch(inputs[i].type)
131 TRACE("mouse: dx %d, dy %d, data %x, flags %x, time %u, info %lx\n",
132 inputs[i].u.mi.dx, inputs[i].u.mi.dy, inputs[i].u.mi.mouseData,
133 inputs[i].u.mi.dwFlags, inputs[i].u.mi.time, inputs[i].u.mi.dwExtraInfo);
137 TRACE("keyboard: vk %X, scan %x, flags %x, time %u, info %lx\n",
138 inputs[i].u.ki.wVk, inputs[i].u.ki.wScan, inputs[i].u.ki.dwFlags,
139 inputs[i].u.ki.time, inputs[i].u.ki.dwExtraInfo);
143 TRACE("hardware: msg %d, wParamL %x, wParamH %x\n",
144 inputs[i].u.hi.uMsg, inputs[i].u.hi.wParamL, inputs[i].u.hi.wParamH);
148 FIXME("unknown input type %u\n", inputs[i].type);
154 return USER_Driver->pSendInput( count, inputs, size );
158 /***********************************************************************
159 * keybd_event (USER32.@)
161 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
162 DWORD dwFlags, ULONG_PTR dwExtraInfo )
166 input.type = INPUT_KEYBOARD;
167 input.u.ki.wVk = bVk;
168 input.u.ki.wScan = bScan;
169 input.u.ki.dwFlags = dwFlags;
170 input.u.ki.time = GetTickCount();
171 input.u.ki.dwExtraInfo = dwExtraInfo;
172 SendInput( 1, &input, sizeof(input) );
176 /***********************************************************************
177 * mouse_event (USER32.@)
179 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
180 DWORD dwData, ULONG_PTR dwExtraInfo )
184 input.type = INPUT_MOUSE;
187 input.u.mi.mouseData = dwData;
188 input.u.mi.dwFlags = dwFlags;
189 input.u.mi.time = GetCurrentTime();
190 input.u.mi.dwExtraInfo = dwExtraInfo;
191 SendInput( 1, &input, sizeof(input) );
195 /***********************************************************************
196 * GetCursorPos (USER32.@)
198 BOOL WINAPI DECLSPEC_HOTPATCH GetCursorPos( POINT *pt )
200 if (!pt) return FALSE;
201 return USER_Driver->pGetCursorPos( pt );
205 /***********************************************************************
206 * GetCursorInfo (USER32.@)
208 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
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 )
234 return USER_Driver->pSetCursorPos( x, y );
238 /**********************************************************************
239 * SetCapture (USER32.@)
241 HWND WINAPI DECLSPEC_HOTPATCH SetCapture( HWND hwnd )
245 set_capture_window( hwnd, 0, &previous );
250 /**********************************************************************
251 * ReleaseCapture (USER32.@)
253 BOOL WINAPI DECLSPEC_HOTPATCH ReleaseCapture(void)
255 BOOL ret = set_capture_window( 0, 0, NULL );
257 /* Somebody may have missed some mouse movements */
258 if (ret) mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
264 /**********************************************************************
265 * GetCapture (USER32.@)
267 HWND WINAPI GetCapture(void)
271 SERVER_START_REQ( get_thread_input )
273 req->tid = GetCurrentThreadId();
274 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->capture );
281 /**********************************************************************
282 * GetAsyncKeyState (USER32.@)
284 * Determine if a key is or was pressed. retval has high-order
285 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
288 SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState(INT nKey)
290 if (nKey < 0 || nKey > 256)
292 return USER_Driver->pGetAsyncKeyState( nKey );
296 /***********************************************************************
297 * GetQueueStatus (USER32.@)
299 DWORD WINAPI GetQueueStatus( UINT flags )
303 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
305 SetLastError( ERROR_INVALID_FLAGS );
309 /* check for pending X events */
310 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
312 SERVER_START_REQ( get_queue_status )
315 wine_server_call( req );
316 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
323 /***********************************************************************
324 * GetInputState (USER32.@)
326 BOOL WINAPI GetInputState(void)
330 /* check for pending X events */
331 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
333 SERVER_START_REQ( get_queue_status )
336 wine_server_call( req );
337 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
344 /******************************************************************
345 * GetLastInputInfo (USER32.@)
347 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
353 if (plii->cbSize != sizeof (*plii) )
355 SetLastError(ERROR_INVALID_PARAMETER);
359 SERVER_START_REQ( get_last_input_time )
361 ret = !wine_server_call_err( req );
363 plii->dwTime = reply->time;
370 /******************************************************************
371 * GetRawInputDeviceList (USER32.@)
373 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
375 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
377 if(pRawInputDeviceList)
378 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
384 /******************************************************************
385 * RegisterRawInputDevices (USER32.@)
387 BOOL WINAPI DECLSPEC_HOTPATCH RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
389 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
395 /******************************************************************
396 * GetRawInputData (USER32.@)
398 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
400 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
401 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
407 /******************************************************************
408 * GetRawInputBuffer (USER32.@)
410 UINT WINAPI DECLSPEC_HOTPATCH GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
412 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
418 /******************************************************************
419 * GetRawInputDeviceInfoA (USER32.@)
421 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
423 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
429 /******************************************************************
430 * GetRawInputDeviceInfoW (USER32.@)
432 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
434 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
440 /******************************************************************
441 * GetRegisteredRawInputDevices (USER32.@)
443 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
445 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
451 /******************************************************************
452 * DefRawInputProc (USER32.@)
454 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
456 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
462 /**********************************************************************
463 * AttachThreadInput (USER32.@)
465 * Attaches the input processing mechanism of one thread to that of
468 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
472 SERVER_START_REQ( attach_thread_input )
474 req->tid_from = from;
476 req->attach = attach;
477 ret = !wine_server_call_err( req );
484 /**********************************************************************
485 * GetKeyState (USER32.@)
487 * An application calls the GetKeyState function in response to a
488 * keyboard-input message. This function retrieves the state of the key
489 * at the time the input message was generated.
491 SHORT WINAPI DECLSPEC_HOTPATCH GetKeyState(INT vkey)
495 SERVER_START_REQ( get_key_state )
497 req->tid = GetCurrentThreadId();
499 if (!wine_server_call( req )) retval = (signed char)reply->state;
502 TRACE("key (0x%x) -> %x\n", vkey, retval);
507 /**********************************************************************
508 * GetKeyboardState (USER32.@)
510 BOOL WINAPI DECLSPEC_HOTPATCH GetKeyboardState( LPBYTE state )
514 TRACE("(%p)\n", state);
516 memset( state, 0, 256 );
517 SERVER_START_REQ( get_key_state )
519 req->tid = GetCurrentThreadId();
521 wine_server_set_reply( req, state, 256 );
522 ret = !wine_server_call_err( req );
529 /**********************************************************************
530 * SetKeyboardState (USER32.@)
532 BOOL WINAPI SetKeyboardState( LPBYTE state )
536 SERVER_START_REQ( set_key_state )
538 req->tid = GetCurrentThreadId();
539 wine_server_add_data( req, state, 256 );
540 ret = !wine_server_call_err( req );
547 /**********************************************************************
548 * VkKeyScanA (USER32.@)
550 * VkKeyScan translates an ANSI character to a virtual-key and shift code
551 * for the current keyboard.
552 * high-order byte yields :
556 * 3-5 Shift-key combinations that are not used for characters
559 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
560 * FIXME : works ok except for dead chars :
561 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
562 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
564 SHORT WINAPI VkKeyScanA(CHAR cChar)
568 if (IsDBCSLeadByte(cChar)) return -1;
570 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
571 return VkKeyScanW(wChar);
574 /******************************************************************************
575 * VkKeyScanW (USER32.@)
577 SHORT WINAPI VkKeyScanW(WCHAR cChar)
579 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
582 /**********************************************************************
583 * VkKeyScanExA (USER32.@)
585 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
589 if (IsDBCSLeadByte(cChar)) return -1;
591 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
592 return VkKeyScanExW(wChar, dwhkl);
595 /******************************************************************************
596 * VkKeyScanExW (USER32.@)
598 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
600 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
603 /**********************************************************************
604 * OemKeyScan (USER32.@)
606 DWORD WINAPI OemKeyScan(WORD wOemChar)
611 /******************************************************************************
612 * GetKeyboardType (USER32.@)
614 INT WINAPI GetKeyboardType(INT nTypeFlag)
616 TRACE_(keyboard)("(%d)\n", nTypeFlag);
619 case 0: /* Keyboard type */
620 return 4; /* AT-101 */
621 case 1: /* Keyboard Subtype */
622 return 0; /* There are no defined subtypes */
623 case 2: /* Number of F-keys */
624 return 12; /* We're doing an 101 for now, so return 12 F-keys */
626 WARN_(keyboard)("Unknown type\n");
627 return 0; /* The book says 0 here, so 0 */
631 /******************************************************************************
632 * MapVirtualKeyA (USER32.@)
634 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
636 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
639 /******************************************************************************
640 * MapVirtualKeyW (USER32.@)
642 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
644 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
647 /******************************************************************************
648 * MapVirtualKeyExA (USER32.@)
650 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
654 ret = MapVirtualKeyExW( code, maptype, hkl );
655 if (maptype == MAPVK_VK_TO_CHAR)
660 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
666 /******************************************************************************
667 * MapVirtualKeyExW (USER32.@)
669 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
671 TRACE_(keyboard)("(%X, %d, %p)\n", code, maptype, hkl);
673 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
676 /****************************************************************************
677 * GetKBCodePage (USER32.@)
679 UINT WINAPI GetKBCodePage(void)
684 /***********************************************************************
685 * GetKeyboardLayout (USER32.@)
687 * - device handle for keyboard layout defaulted to
688 * the language id. This is the way Windows default works.
689 * - the thread identifier (dwLayout) is also ignored.
691 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
693 return USER_Driver->pGetKeyboardLayout(dwLayout);
696 /****************************************************************************
697 * GetKeyboardLayoutNameA (USER32.@)
699 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
701 WCHAR buf[KL_NAMELENGTH];
703 if (GetKeyboardLayoutNameW(buf))
704 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
708 /****************************************************************************
709 * GetKeyboardLayoutNameW (USER32.@)
711 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
713 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
716 /****************************************************************************
717 * GetKeyNameTextA (USER32.@)
719 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
724 if (!GetKeyNameTextW(lParam, buf, 256))
729 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
738 /****************************************************************************
739 * GetKeyNameTextW (USER32.@)
741 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
743 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
746 /****************************************************************************
747 * ToUnicode (USER32.@)
749 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
750 LPWSTR lpwStr, int size, UINT flags)
752 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
755 /****************************************************************************
756 * ToUnicodeEx (USER32.@)
758 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
759 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
761 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
764 /****************************************************************************
767 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
768 LPWORD lpChar, UINT flags )
770 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
773 /****************************************************************************
774 * ToAsciiEx (USER32.@)
776 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
777 LPWORD lpChar, UINT flags, HKL dwhkl )
782 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
783 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
785 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
789 /**********************************************************************
790 * ActivateKeyboardLayout (USER32.@)
792 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
794 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
796 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
799 /**********************************************************************
800 * BlockInput (USER32.@)
802 BOOL WINAPI BlockInput(BOOL fBlockIt)
804 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
805 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
810 /***********************************************************************
811 * GetKeyboardLayoutList (USER32.@)
813 * Return number of values available if either input parm is
814 * 0, per MS documentation.
816 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
821 ULONG_PTR baselayout;
823 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};
825 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
827 baselayout = GetUserDefaultLCID();
828 langid = PRIMARYLANGID(LANGIDFROMLCID(baselayout));
829 if (langid == LANG_CHINESE || langid == LANG_JAPANESE || langid == LANG_KOREAN)
830 baselayout |= 0xe001 << 16; /* IME */
832 baselayout |= baselayout << 16;
834 /* Enumerate the Registry */
835 rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,szKeyboardReg,&hKeyKeyboard);
836 if (rc == ERROR_SUCCESS)
841 rc = RegEnumKeyW(hKeyKeyboard, count, szKeyName, 9);
842 if (rc == ERROR_SUCCESS)
844 layout = (HKL)strtoulW(szKeyName,NULL,16);
845 if (baselayout != 0 && layout == (HKL)baselayout)
846 baselayout = 0; /* found in the registry do not add again */
847 if (nBuff && layouts)
849 if (count >= nBuff ) break;
850 layouts[count] = layout;
854 } while (rc == ERROR_SUCCESS);
855 RegCloseKey(hKeyKeyboard);
858 /* make sure our base layout is on the list */
861 if (nBuff && layouts)
865 layouts[count] = (HKL)baselayout;
877 /***********************************************************************
878 * RegisterHotKey (USER32.@)
880 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
883 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%X): stub\n",hwnd,id,modifiers,vk);
887 /***********************************************************************
888 * UnregisterHotKey (USER32.@)
890 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
893 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
897 /***********************************************************************
898 * LoadKeyboardLayoutW (USER32.@)
900 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
902 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
904 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
907 /***********************************************************************
908 * LoadKeyboardLayoutA (USER32.@)
910 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
913 UNICODE_STRING pwszKLIDW;
915 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
916 else pwszKLIDW.Buffer = NULL;
918 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
919 RtlFreeUnicodeString(&pwszKLIDW);
924 /***********************************************************************
925 * UnloadKeyboardLayout (USER32.@)
927 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
929 TRACE_(keyboard)("(%p)\n", hkl);
931 return USER_Driver->pUnloadKeyboardLayout(hkl);
934 typedef struct __TRACKINGLIST {
936 POINT pos; /* center of hover rectangle */
939 /* FIXME: move tracking stuff into a per thread data */
940 static _TRACKINGLIST tracking_info;
941 static UINT_PTR timer;
943 static void check_mouse_leave(HWND hwnd, int hittest)
945 if (tracking_info.tme.hwndTrack != hwnd)
947 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
948 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
950 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
952 /* remove the TME_LEAVE flag */
953 tracking_info.tme.dwFlags &= ~TME_LEAVE;
957 if (hittest == HTCLIENT)
959 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
961 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
962 /* remove the TME_LEAVE flag */
963 tracking_info.tme.dwFlags &= ~TME_LEAVE;
968 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
970 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
971 /* remove the TME_LEAVE flag */
972 tracking_info.tme.dwFlags &= ~TME_LEAVE;
978 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
982 INT hoverwidth = 0, hoverheight = 0, hittest;
984 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
987 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
989 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
991 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
992 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
994 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
995 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
996 hoverwidth, hoverheight);
998 /* see if this tracking event is looking for TME_LEAVE and that the */
999 /* mouse has left the window */
1000 if (tracking_info.tme.dwFlags & TME_LEAVE)
1002 check_mouse_leave(hwnd, hittest);
1005 if (tracking_info.tme.hwndTrack != hwnd)
1007 /* mouse is gone, stop tracking mouse hover */
1008 tracking_info.tme.dwFlags &= ~TME_HOVER;
1011 /* see if we are tracking hovering for this hwnd */
1012 if (tracking_info.tme.dwFlags & TME_HOVER)
1014 /* has the cursor moved outside the rectangle centered around pos? */
1015 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
1016 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
1018 /* record this new position as the current position */
1019 tracking_info.pos = pos;
1023 if (hittest == HTCLIENT)
1025 ScreenToClient(hwnd, &pos);
1026 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
1028 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
1029 get_key_state(), MAKELPARAM( pos.x, pos.y ));
1033 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
1034 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
1035 hittest, MAKELPARAM( pos.x, pos.y ));
1038 /* stop tracking mouse hover */
1039 tracking_info.tme.dwFlags &= ~TME_HOVER;
1043 /* stop the timer if the tracking list is empty */
1044 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1046 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1048 tracking_info.tme.hwndTrack = 0;
1049 tracking_info.tme.dwFlags = 0;
1050 tracking_info.tme.dwHoverTime = 0;
1055 /***********************************************************************
1056 * TrackMouseEvent [USER32]
1058 * Requests notification of mouse events
1060 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1061 * to the hwnd specified in the ptme structure. After the event message
1062 * is posted to the hwnd, the entry in the queue is removed.
1064 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1065 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1066 * immediately and the TME_LEAVE flag being ignored.
1069 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1078 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1085 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1087 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1088 WARN("wrong TRACKMOUSEEVENT size from app\n");
1089 SetLastError(ERROR_INVALID_PARAMETER);
1093 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1094 if (ptme->dwFlags & TME_QUERY )
1096 *ptme = tracking_info.tme;
1097 /* set cbSize in the case it's not initialized yet */
1098 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1100 return TRUE; /* return here, TME_QUERY is retrieving information */
1103 if (!IsWindow(ptme->hwndTrack))
1105 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1109 hover_time = ptme->dwHoverTime;
1111 /* if HOVER_DEFAULT was specified replace this with the systems current value.
1112 * TME_LEAVE doesn't need to specify hover time so use default */
1113 if (hover_time == HOVER_DEFAULT || hover_time == 0 || !(ptme->dwHoverTime&TME_HOVER))
1114 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1117 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1118 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1120 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1121 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1123 if (ptme->dwFlags & TME_CANCEL)
1125 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1127 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1129 /* if we aren't tracking on hover or leave remove this entry */
1130 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1132 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1134 tracking_info.tme.hwndTrack = 0;
1135 tracking_info.tme.dwFlags = 0;
1136 tracking_info.tme.dwHoverTime = 0;
1140 /* In our implementation it's possible that another window will receive a
1141 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1142 * called. In such a situation post the WM_MOUSELEAVE now */
1143 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1144 check_mouse_leave(hwnd, hittest);
1148 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1150 tracking_info.tme.hwndTrack = 0;
1151 tracking_info.tme.dwFlags = 0;
1152 tracking_info.tme.dwHoverTime = 0;
1155 if (ptme->hwndTrack == hwnd)
1157 /* Adding new mouse event to the tracking list */
1158 tracking_info.tme = *ptme;
1159 tracking_info.tme.dwHoverTime = hover_time;
1161 /* Initialize HoverInfo variables even if not hover tracking */
1162 tracking_info.pos = pos;
1164 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1171 /***********************************************************************
1172 * GetMouseMovePointsEx [USER32]
1175 * Success: count of point set in the buffer
1178 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1180 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1181 SetLastError(ERROR_INVALID_PARAMETER);
1185 if(!ptin || (!ptout && count)) {
1186 SetLastError(ERROR_NOACCESS);
1190 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1192 SetLastError(ERROR_POINT_NOT_FOUND);