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"
49 WINE_DEFAULT_DEBUG_CHANNEL(win);
50 WINE_DECLARE_DEBUG_CHANNEL(keyboard);
53 /***********************************************************************
56 static WORD get_key_state(void)
60 if (GetSystemMetrics( SM_SWAPBUTTON ))
62 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
63 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
67 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_LBUTTON;
68 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_RBUTTON;
70 if (GetAsyncKeyState(VK_MBUTTON) & 0x80) ret |= MK_MBUTTON;
71 if (GetAsyncKeyState(VK_SHIFT) & 0x80) ret |= MK_SHIFT;
72 if (GetAsyncKeyState(VK_CONTROL) & 0x80) ret |= MK_CONTROL;
73 if (GetAsyncKeyState(VK_XBUTTON1) & 0x80) ret |= MK_XBUTTON1;
74 if (GetAsyncKeyState(VK_XBUTTON2) & 0x80) ret |= MK_XBUTTON2;
79 /**********************************************************************
82 BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret )
88 if (gui_flags & GUI_INMENUMODE) flags |= CAPTURE_MENU;
89 if (gui_flags & GUI_INMOVESIZE) flags |= CAPTURE_MOVESIZE;
91 SERVER_START_REQ( set_capture_window )
95 if ((ret = !wine_server_call_err( req )))
97 previous = reply->previous;
98 hwnd = reply->full_handle;
103 USER_Driver->pSetCapture( hwnd, gui_flags );
105 if (previous && previous != hwnd)
106 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
108 if (prev_ret) *prev_ret = previous;
113 /***********************************************************************
114 * SendInput (USER32.@)
116 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
122 for (i = 0; i < count; i++)
124 switch(inputs[i].type)
127 TRACE("mouse: dx %d, dy %d, data %x, flags %x, time %u, info %lx\n",
128 inputs[i].u.mi.dx, inputs[i].u.mi.dy, inputs[i].u.mi.mouseData,
129 inputs[i].u.mi.dwFlags, inputs[i].u.mi.time, inputs[i].u.mi.dwExtraInfo);
133 TRACE("keyboard: vk %x, scan %x, flags %x, time %u, info %lx\n",
134 inputs[i].u.ki.wVk, inputs[i].u.ki.wScan, inputs[i].u.ki.dwFlags,
135 inputs[i].u.ki.time, inputs[i].u.ki.dwExtraInfo);
139 TRACE("hardware: msg %d, wParamL %x, wParamH %x\n",
140 inputs[i].u.hi.uMsg, inputs[i].u.hi.wParamL, inputs[i].u.hi.wParamH);
144 FIXME("unknown input type %u\n", inputs[i].type);
150 return USER_Driver->pSendInput( count, inputs, size );
154 /***********************************************************************
155 * keybd_event (USER32.@)
157 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
158 DWORD dwFlags, ULONG_PTR dwExtraInfo )
162 input.type = INPUT_KEYBOARD;
163 input.u.ki.wVk = bVk;
164 input.u.ki.wScan = bScan;
165 input.u.ki.dwFlags = dwFlags;
166 input.u.ki.time = GetTickCount();
167 input.u.ki.dwExtraInfo = dwExtraInfo;
168 SendInput( 1, &input, sizeof(input) );
172 /***********************************************************************
173 * mouse_event (USER32.@)
175 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
176 DWORD dwData, ULONG_PTR dwExtraInfo )
180 input.type = INPUT_MOUSE;
183 input.u.mi.mouseData = dwData;
184 input.u.mi.dwFlags = dwFlags;
185 input.u.mi.time = GetCurrentTime();
186 input.u.mi.dwExtraInfo = dwExtraInfo;
187 SendInput( 1, &input, sizeof(input) );
191 /***********************************************************************
192 * GetCursorPos (USER32.@)
194 BOOL WINAPI GetCursorPos( POINT *pt )
196 if (!pt) return FALSE;
197 return USER_Driver->pGetCursorPos( pt );
201 /***********************************************************************
202 * GetCursorInfo (USER32.@)
204 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
207 if (get_user_thread_info()->cursor_count >= 0) pci->flags = CURSOR_SHOWING;
209 GetCursorPos(&pci->ptScreenPos);
214 /***********************************************************************
215 * SetCursorPos (USER32.@)
217 BOOL WINAPI SetCursorPos( INT x, INT y )
219 return USER_Driver->pSetCursorPos( x, y );
223 /**********************************************************************
224 * SetCapture (USER32.@)
226 HWND WINAPI SetCapture( HWND hwnd )
230 set_capture_window( hwnd, 0, &previous );
235 /**********************************************************************
236 * ReleaseCapture (USER32.@)
238 BOOL WINAPI ReleaseCapture(void)
240 BOOL ret = set_capture_window( 0, 0, NULL );
242 /* Somebody may have missed some mouse movements */
243 mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
249 /**********************************************************************
250 * GetCapture (USER32.@)
252 HWND WINAPI GetCapture(void)
256 SERVER_START_REQ( get_thread_input )
258 req->tid = GetCurrentThreadId();
259 if (!wine_server_call_err( req )) ret = reply->capture;
266 /**********************************************************************
267 * GetAsyncKeyState (USER32.@)
269 * Determine if a key is or was pressed. retval has high-order
270 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
273 SHORT WINAPI GetAsyncKeyState(INT nKey)
275 return USER_Driver->pGetAsyncKeyState( nKey );
279 /***********************************************************************
280 * GetQueueStatus (USER32.@)
282 DWORD WINAPI GetQueueStatus( UINT flags )
286 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
288 SetLastError( ERROR_INVALID_FLAGS );
292 /* check for pending X events */
293 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
295 SERVER_START_REQ( get_queue_status )
298 wine_server_call( req );
299 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
306 /***********************************************************************
307 * GetInputState (USER32.@)
309 BOOL WINAPI GetInputState(void)
313 /* check for pending X events */
314 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
316 SERVER_START_REQ( get_queue_status )
319 wine_server_call( req );
320 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
327 /******************************************************************
328 * GetLastInputInfo (USER32.@)
330 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
336 if (plii->cbSize != sizeof (*plii) )
338 SetLastError(ERROR_INVALID_PARAMETER);
342 SERVER_START_REQ( get_last_input_time )
344 ret = !wine_server_call_err( req );
346 plii->dwTime = reply->time;
353 /******************************************************************
354 * GetRawInputDeviceList (USER32.@)
356 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
358 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
360 if(pRawInputDeviceList)
361 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
367 /******************************************************************
368 * RegisterRawInputDevices (USER32.@)
370 BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
372 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
378 /******************************************************************
379 * GetRawInputData (USER32.@)
381 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
383 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
384 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
390 /******************************************************************
391 * GetRawInputBuffer (USER32.@)
393 UINT WINAPI GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
395 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
401 /******************************************************************
402 * GetRawInputDeviceInfoA (USER32.@)
404 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
406 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
412 /******************************************************************
413 * GetRawInputDeviceInfoW (USER32.@)
415 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
417 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
423 /******************************************************************
424 * GetRegisteredRawInputDevices (USER32.@)
426 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
428 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
434 /******************************************************************
435 * DefRawInputProc (USER32.@)
437 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
439 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
445 /**********************************************************************
446 * AttachThreadInput (USER32.@)
448 * Attaches the input processing mechanism of one thread to that of
451 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
455 SERVER_START_REQ( attach_thread_input )
457 req->tid_from = from;
459 req->attach = attach;
460 ret = !wine_server_call_err( req );
467 /**********************************************************************
468 * GetKeyState (USER32.@)
470 * An application calls the GetKeyState function in response to a
471 * keyboard-input message. This function retrieves the state of the key
472 * at the time the input message was generated.
474 SHORT WINAPI GetKeyState(INT vkey)
478 SERVER_START_REQ( get_key_state )
480 req->tid = GetCurrentThreadId();
482 if (!wine_server_call( req )) retval = (signed char)reply->state;
485 TRACE("key (0x%x) -> %x\n", vkey, retval);
490 /**********************************************************************
491 * GetKeyboardState (USER32.@)
493 BOOL WINAPI GetKeyboardState( LPBYTE state )
497 TRACE("(%p)\n", state);
499 memset( state, 0, 256 );
500 SERVER_START_REQ( get_key_state )
502 req->tid = GetCurrentThreadId();
504 wine_server_set_reply( req, state, 256 );
505 ret = !wine_server_call_err( req );
512 /**********************************************************************
513 * SetKeyboardState (USER32.@)
515 BOOL WINAPI SetKeyboardState( LPBYTE state )
519 SERVER_START_REQ( set_key_state )
521 req->tid = GetCurrentThreadId();
522 wine_server_add_data( req, state, 256 );
523 ret = !wine_server_call_err( req );
530 /**********************************************************************
531 * VkKeyScanA (USER32.@)
533 * VkKeyScan translates an ANSI character to a virtual-key and shift code
534 * for the current keyboard.
535 * high-order byte yields :
539 * 3-5 Shift-key combinations that are not used for characters
542 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
543 * FIXME : works ok except for dead chars :
544 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
545 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
547 SHORT WINAPI VkKeyScanA(CHAR cChar)
551 if (IsDBCSLeadByte(cChar)) return -1;
553 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
554 return VkKeyScanW(wChar);
557 /******************************************************************************
558 * VkKeyScanW (USER32.@)
560 SHORT WINAPI VkKeyScanW(WCHAR cChar)
562 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
565 /**********************************************************************
566 * VkKeyScanExA (USER32.@)
568 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
572 if (IsDBCSLeadByte(cChar)) return -1;
574 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
575 return VkKeyScanExW(wChar, dwhkl);
578 /******************************************************************************
579 * VkKeyScanExW (USER32.@)
581 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
583 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
586 /**********************************************************************
587 * OemKeyScan (USER32.@)
589 DWORD WINAPI OemKeyScan(WORD wOemChar)
594 /******************************************************************************
595 * GetKeyboardType (USER32.@)
597 INT WINAPI GetKeyboardType(INT nTypeFlag)
599 TRACE_(keyboard)("(%d)\n", nTypeFlag);
602 case 0: /* Keyboard type */
603 return 4; /* AT-101 */
604 case 1: /* Keyboard Subtype */
605 return 0; /* There are no defined subtypes */
606 case 2: /* Number of F-keys */
607 return 12; /* We're doing an 101 for now, so return 12 F-keys */
609 WARN_(keyboard)("Unknown type\n");
610 return 0; /* The book says 0 here, so 0 */
614 /******************************************************************************
615 * MapVirtualKeyA (USER32.@)
617 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
619 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
622 /******************************************************************************
623 * MapVirtualKeyW (USER32.@)
625 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
627 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
630 /******************************************************************************
631 * MapVirtualKeyExA (USER32.@)
633 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
637 ret = MapVirtualKeyExW( code, maptype, hkl );
638 if (maptype == MAPVK_VK_TO_CHAR)
643 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
649 /******************************************************************************
650 * MapVirtualKeyExW (USER32.@)
652 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
654 TRACE_(keyboard)("(%d, %d, %p)\n", code, maptype, hkl);
656 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
659 /****************************************************************************
660 * GetKBCodePage (USER32.@)
662 UINT WINAPI GetKBCodePage(void)
667 /***********************************************************************
668 * GetKeyboardLayout (USER32.@)
670 * - device handle for keyboard layout defaulted to
671 * the language id. This is the way Windows default works.
672 * - the thread identifier (dwLayout) is also ignored.
674 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
676 return USER_Driver->pGetKeyboardLayout(dwLayout);
679 /****************************************************************************
680 * GetKeyboardLayoutNameA (USER32.@)
682 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
684 WCHAR buf[KL_NAMELENGTH];
686 if (GetKeyboardLayoutNameW(buf))
687 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
691 /****************************************************************************
692 * GetKeyboardLayoutNameW (USER32.@)
694 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
696 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
699 /****************************************************************************
700 * GetKeyNameTextA (USER32.@)
702 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
707 if (!GetKeyNameTextW(lParam, buf, 256))
712 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
721 /****************************************************************************
722 * GetKeyNameTextW (USER32.@)
724 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
726 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
729 /****************************************************************************
730 * ToUnicode (USER32.@)
732 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
733 LPWSTR lpwStr, int size, UINT flags)
735 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
738 /****************************************************************************
739 * ToUnicodeEx (USER32.@)
741 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
742 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
744 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
747 /****************************************************************************
750 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
751 LPWORD lpChar, UINT flags )
753 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
756 /****************************************************************************
757 * ToAsciiEx (USER32.@)
759 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
760 LPWORD lpChar, UINT flags, HKL dwhkl )
765 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
766 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
768 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
772 /**********************************************************************
773 * ActivateKeyboardLayout (USER32.@)
775 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
777 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
779 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
782 /**********************************************************************
783 * BlockInput (USER32.@)
785 BOOL WINAPI BlockInput(BOOL fBlockIt)
787 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
788 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
793 /***********************************************************************
794 * GetKeyboardLayoutList (USER32.@)
796 * Return number of values available if either input parm is
797 * 0, per MS documentation.
799 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
801 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
803 return USER_Driver->pGetKeyboardLayoutList(nBuff, layouts);
807 /***********************************************************************
808 * RegisterHotKey (USER32.@)
810 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
813 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
817 /***********************************************************************
818 * UnregisterHotKey (USER32.@)
820 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
823 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
827 /***********************************************************************
828 * LoadKeyboardLayoutW (USER32.@)
830 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
832 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
834 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
837 /***********************************************************************
838 * LoadKeyboardLayoutA (USER32.@)
840 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
843 UNICODE_STRING pwszKLIDW;
845 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
846 else pwszKLIDW.Buffer = NULL;
848 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
849 RtlFreeUnicodeString(&pwszKLIDW);
854 /***********************************************************************
855 * UnloadKeyboardLayout (USER32.@)
857 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
859 TRACE_(keyboard)("(%p)\n", hkl);
861 return USER_Driver->pUnloadKeyboardLayout(hkl);
864 typedef struct __TRACKINGLIST {
866 POINT pos; /* center of hover rectangle */
869 /* FIXME: move tracking stuff into a per thread data */
870 static _TRACKINGLIST tracking_info;
871 static UINT_PTR timer;
873 static void check_mouse_leave(HWND hwnd, int hittest)
875 if (tracking_info.tme.hwndTrack != hwnd)
877 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
878 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
880 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
882 /* remove the TME_LEAVE flag */
883 tracking_info.tme.dwFlags &= ~TME_LEAVE;
887 if (hittest == HTCLIENT)
889 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
891 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
892 /* remove the TME_LEAVE flag */
893 tracking_info.tme.dwFlags &= ~TME_LEAVE;
898 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
900 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
901 /* remove the TME_LEAVE flag */
902 tracking_info.tme.dwFlags &= ~TME_LEAVE;
908 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
912 INT hoverwidth = 0, hoverheight = 0, hittest;
914 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
917 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
919 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
921 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
922 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
924 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
925 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
926 hoverwidth, hoverheight);
928 /* see if this tracking event is looking for TME_LEAVE and that the */
929 /* mouse has left the window */
930 if (tracking_info.tme.dwFlags & TME_LEAVE)
932 check_mouse_leave(hwnd, hittest);
935 if (tracking_info.tme.hwndTrack != hwnd)
937 /* mouse is gone, stop tracking mouse hover */
938 tracking_info.tme.dwFlags &= ~TME_HOVER;
941 /* see if we are tracking hovering for this hwnd */
942 if (tracking_info.tme.dwFlags & TME_HOVER)
944 /* has the cursor moved outside the rectangle centered around pos? */
945 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
946 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
948 /* record this new position as the current position */
949 tracking_info.pos = pos;
953 if (hittest == HTCLIENT)
955 ScreenToClient(hwnd, &pos);
956 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
958 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
959 get_key_state(), MAKELPARAM( pos.x, pos.y ));
963 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
964 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
965 hittest, MAKELPARAM( pos.x, pos.y ));
968 /* stop tracking mouse hover */
969 tracking_info.tme.dwFlags &= ~TME_HOVER;
973 /* stop the timer if the tracking list is empty */
974 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
976 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
978 tracking_info.tme.hwndTrack = 0;
979 tracking_info.tme.dwFlags = 0;
980 tracking_info.tme.dwHoverTime = 0;
985 /***********************************************************************
986 * TrackMouseEvent [USER32]
988 * Requests notification of mouse events
990 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
991 * to the hwnd specified in the ptme structure. After the event message
992 * is posted to the hwnd, the entry in the queue is removed.
994 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
995 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
996 * immediately and the TME_LEAVE flag being ignored.
999 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1008 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1015 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1017 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1018 WARN("wrong TRACKMOUSEEVENT size from app\n");
1019 SetLastError(ERROR_INVALID_PARAMETER);
1023 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1024 if (ptme->dwFlags & TME_QUERY )
1026 *ptme = tracking_info.tme;
1027 /* set cbSize in the case it's not initialized yet */
1028 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1030 return TRUE; /* return here, TME_QUERY is retrieving information */
1033 if (!IsWindow(ptme->hwndTrack))
1035 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1039 hover_time = ptme->dwHoverTime;
1041 /* if HOVER_DEFAULT was specified replace this with the systems current value.
1042 * TME_LEAVE doesn't need to specify hover time so use default */
1043 if (hover_time == HOVER_DEFAULT || hover_time == 0 || !(ptme->dwHoverTime&TME_HOVER))
1044 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1047 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1048 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1050 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1051 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1053 if (ptme->dwFlags & TME_CANCEL)
1055 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1057 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1059 /* if we aren't tracking on hover or leave remove this entry */
1060 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1062 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1064 tracking_info.tme.hwndTrack = 0;
1065 tracking_info.tme.dwFlags = 0;
1066 tracking_info.tme.dwHoverTime = 0;
1070 /* In our implementation it's possible that another window will receive a
1071 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1072 * called. In such a situation post the WM_MOUSELEAVE now */
1073 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1074 check_mouse_leave(hwnd, hittest);
1078 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1080 tracking_info.tme.hwndTrack = 0;
1081 tracking_info.tme.dwFlags = 0;
1082 tracking_info.tme.dwHoverTime = 0;
1085 if (ptme->hwndTrack == hwnd)
1087 /* Adding new mouse event to the tracking list */
1088 tracking_info.tme = *ptme;
1089 tracking_info.tme.dwHoverTime = hover_time;
1091 /* Initialize HoverInfo variables even if not hover tracking */
1092 tracking_info.pos = pos;
1094 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1101 /***********************************************************************
1102 * GetMouseMovePointsEx [USER32]
1105 * Success: count of point set in the buffer
1108 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1110 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1111 SetLastError(ERROR_INVALID_PARAMETER);
1115 if(!ptin || !ptout) {
1116 SetLastError(ERROR_NOACCESS);
1120 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1122 SetLastError(ERROR_POINT_NOT_FOUND);