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 /***********************************************************************
80 * SendInput (USER32.@)
82 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
88 for (i = 0; i < count; i++)
90 switch(inputs[i].type)
93 TRACE("mouse: dx %d, dy %d, data %x, flags %x, time %u, info %lx\n",
94 inputs[i].u.mi.dx, inputs[i].u.mi.dy, inputs[i].u.mi.mouseData,
95 inputs[i].u.mi.dwFlags, inputs[i].u.mi.time, inputs[i].u.mi.dwExtraInfo);
99 TRACE("keyboard: vk %x, scan %x, flags %x, time %u, info %lx\n",
100 inputs[i].u.ki.wVk, inputs[i].u.ki.wScan, inputs[i].u.ki.dwFlags,
101 inputs[i].u.ki.time, inputs[i].u.ki.dwExtraInfo);
105 TRACE("hardware: msg %d, wParamL %x, wParamH %x\n",
106 inputs[i].u.hi.uMsg, inputs[i].u.hi.wParamL, inputs[i].u.hi.wParamH);
110 FIXME("unknown input type %u\n", inputs[i].type);
116 return USER_Driver->pSendInput( count, inputs, size );
120 /***********************************************************************
121 * keybd_event (USER32.@)
123 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
124 DWORD dwFlags, ULONG_PTR dwExtraInfo )
128 input.type = INPUT_KEYBOARD;
129 input.u.ki.wVk = bVk;
130 input.u.ki.wScan = bScan;
131 input.u.ki.dwFlags = dwFlags;
132 input.u.ki.time = GetTickCount();
133 input.u.ki.dwExtraInfo = dwExtraInfo;
134 SendInput( 1, &input, sizeof(input) );
138 /***********************************************************************
139 * mouse_event (USER32.@)
141 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
142 DWORD dwData, ULONG_PTR dwExtraInfo )
146 input.type = INPUT_MOUSE;
149 input.u.mi.mouseData = dwData;
150 input.u.mi.dwFlags = dwFlags;
151 input.u.mi.time = GetCurrentTime();
152 input.u.mi.dwExtraInfo = dwExtraInfo;
153 SendInput( 1, &input, sizeof(input) );
157 /***********************************************************************
158 * GetCursorPos (USER32.@)
160 BOOL WINAPI GetCursorPos( POINT *pt )
162 if (!pt) return FALSE;
163 return USER_Driver->pGetCursorPos( pt );
167 /***********************************************************************
168 * GetCursorInfo (USER32.@)
170 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
173 if (get_user_thread_info()->cursor_count >= 0) pci->flags = CURSOR_SHOWING;
175 GetCursorPos(&pci->ptScreenPos);
180 /***********************************************************************
181 * SetCursorPos (USER32.@)
183 BOOL WINAPI SetCursorPos( INT x, INT y )
185 return USER_Driver->pSetCursorPos( x, y );
189 /**********************************************************************
190 * SetCapture (USER32.@)
192 HWND WINAPI SetCapture( HWND hwnd )
196 SERVER_START_REQ( set_capture_window )
200 if (!wine_server_call_err( req ))
202 previous = reply->previous;
203 hwnd = reply->full_handle;
208 if (previous && previous != hwnd)
209 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
214 /**********************************************************************
215 * ReleaseCapture (USER32.@)
217 BOOL WINAPI ReleaseCapture(void)
222 SERVER_START_REQ( set_capture_window )
226 if ((ret = !wine_server_call_err( req ))) previous = reply->previous;
230 if (previous) SendMessageW( previous, WM_CAPTURECHANGED, 0, 0 );
232 /* Somebody may have missed some mouse movements */
233 mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
239 /**********************************************************************
240 * GetCapture (USER32.@)
242 HWND WINAPI GetCapture(void)
246 SERVER_START_REQ( get_thread_input )
248 req->tid = GetCurrentThreadId();
249 if (!wine_server_call_err( req )) ret = reply->capture;
256 /**********************************************************************
257 * GetAsyncKeyState (USER32.@)
259 * Determine if a key is or was pressed. retval has high-order
260 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
263 SHORT WINAPI GetAsyncKeyState(INT nKey)
265 return USER_Driver->pGetAsyncKeyState( nKey );
269 /***********************************************************************
270 * GetQueueStatus (USER32.@)
272 DWORD WINAPI GetQueueStatus( UINT flags )
276 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
278 SetLastError( ERROR_INVALID_FLAGS );
282 /* check for pending X events */
283 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
285 SERVER_START_REQ( get_queue_status )
288 wine_server_call( req );
289 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
296 /***********************************************************************
297 * GetInputState (USER32.@)
299 BOOL WINAPI GetInputState(void)
303 /* check for pending X events */
304 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
306 SERVER_START_REQ( get_queue_status )
309 wine_server_call( req );
310 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
317 /******************************************************************
318 * GetLastInputInfo (USER32.@)
320 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
326 if (plii->cbSize != sizeof (*plii) )
328 SetLastError(ERROR_INVALID_PARAMETER);
332 SERVER_START_REQ( get_last_input_time )
334 ret = !wine_server_call_err( req );
336 plii->dwTime = reply->time;
343 /******************************************************************
344 * GetRawInputDeviceList (USER32.@)
346 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
348 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
350 if(pRawInputDeviceList)
351 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
357 /******************************************************************
358 * RegisterRawInputDevices (USER32.@)
360 BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
362 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
368 /******************************************************************
369 * GetRawInputData (USER32.@)
371 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
373 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
374 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
380 /******************************************************************
381 * GetRawInputBuffer (USER32.@)
383 UINT WINAPI GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
385 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
391 /******************************************************************
392 * GetRawInputDeviceInfoA (USER32.@)
394 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
396 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
402 /******************************************************************
403 * GetRawInputDeviceInfoW (USER32.@)
405 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
407 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
413 /******************************************************************
414 * GetRegisteredRawInputDevices (USER32.@)
416 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
418 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
424 /******************************************************************
425 * DefRawInputProc (USER32.@)
427 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
429 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
435 /**********************************************************************
436 * AttachThreadInput (USER32.@)
438 * Attaches the input processing mechanism of one thread to that of
441 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
445 SERVER_START_REQ( attach_thread_input )
447 req->tid_from = from;
449 req->attach = attach;
450 ret = !wine_server_call_err( req );
457 /**********************************************************************
458 * GetKeyState (USER32.@)
460 * An application calls the GetKeyState function in response to a
461 * keyboard-input message. This function retrieves the state of the key
462 * at the time the input message was generated.
464 SHORT WINAPI GetKeyState(INT vkey)
468 SERVER_START_REQ( get_key_state )
470 req->tid = GetCurrentThreadId();
472 if (!wine_server_call( req )) retval = (signed char)reply->state;
475 TRACE("key (0x%x) -> %x\n", vkey, retval);
480 /**********************************************************************
481 * GetKeyboardState (USER32.@)
483 BOOL WINAPI GetKeyboardState( LPBYTE state )
487 TRACE("(%p)\n", state);
489 memset( state, 0, 256 );
490 SERVER_START_REQ( get_key_state )
492 req->tid = GetCurrentThreadId();
494 wine_server_set_reply( req, state, 256 );
495 ret = !wine_server_call_err( req );
502 /**********************************************************************
503 * SetKeyboardState (USER32.@)
505 BOOL WINAPI SetKeyboardState( LPBYTE state )
509 SERVER_START_REQ( set_key_state )
511 req->tid = GetCurrentThreadId();
512 wine_server_add_data( req, state, 256 );
513 ret = !wine_server_call_err( req );
520 /**********************************************************************
521 * VkKeyScanA (USER32.@)
523 * VkKeyScan translates an ANSI character to a virtual-key and shift code
524 * for the current keyboard.
525 * high-order byte yields :
529 * 3-5 Shift-key combinations that are not used for characters
532 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
533 * FIXME : works ok except for dead chars :
534 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
535 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
537 SHORT WINAPI VkKeyScanA(CHAR cChar)
541 if (IsDBCSLeadByte(cChar)) return -1;
543 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
544 return VkKeyScanW(wChar);
547 /******************************************************************************
548 * VkKeyScanW (USER32.@)
550 SHORT WINAPI VkKeyScanW(WCHAR cChar)
552 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
555 /**********************************************************************
556 * VkKeyScanExA (USER32.@)
558 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
562 if (IsDBCSLeadByte(cChar)) return -1;
564 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
565 return VkKeyScanExW(wChar, dwhkl);
568 /******************************************************************************
569 * VkKeyScanExW (USER32.@)
571 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
573 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
576 /**********************************************************************
577 * OemKeyScan (USER32.@)
579 DWORD WINAPI OemKeyScan(WORD wOemChar)
584 /******************************************************************************
585 * GetKeyboardType (USER32.@)
587 INT WINAPI GetKeyboardType(INT nTypeFlag)
589 TRACE_(keyboard)("(%d)\n", nTypeFlag);
592 case 0: /* Keyboard type */
593 return 4; /* AT-101 */
594 case 1: /* Keyboard Subtype */
595 return 0; /* There are no defined subtypes */
596 case 2: /* Number of F-keys */
597 return 12; /* We're doing an 101 for now, so return 12 F-keys */
599 WARN_(keyboard)("Unknown type\n");
600 return 0; /* The book says 0 here, so 0 */
604 /******************************************************************************
605 * MapVirtualKeyA (USER32.@)
607 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
609 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
612 /******************************************************************************
613 * MapVirtualKeyW (USER32.@)
615 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
617 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
620 /******************************************************************************
621 * MapVirtualKeyExA (USER32.@)
623 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
625 return MapVirtualKeyExW(code, maptype, hkl);
628 /******************************************************************************
629 * MapVirtualKeyExW (USER32.@)
631 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
633 TRACE_(keyboard)("(%d, %d, %p)\n", code, maptype, hkl);
635 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
638 /****************************************************************************
639 * GetKBCodePage (USER32.@)
641 UINT WINAPI GetKBCodePage(void)
646 /***********************************************************************
647 * GetKeyboardLayout (USER32.@)
649 * - device handle for keyboard layout defaulted to
650 * the language id. This is the way Windows default works.
651 * - the thread identifier (dwLayout) is also ignored.
653 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
655 return USER_Driver->pGetKeyboardLayout(dwLayout);
658 /****************************************************************************
659 * GetKeyboardLayoutNameA (USER32.@)
661 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
663 WCHAR buf[KL_NAMELENGTH];
665 if (GetKeyboardLayoutNameW(buf))
666 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
670 /****************************************************************************
671 * GetKeyboardLayoutNameW (USER32.@)
673 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
675 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
678 /****************************************************************************
679 * GetKeyNameTextA (USER32.@)
681 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
686 if (!GetKeyNameTextW(lParam, buf, 256))
691 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
700 /****************************************************************************
701 * GetKeyNameTextW (USER32.@)
703 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
705 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
708 /****************************************************************************
709 * ToUnicode (USER32.@)
711 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
712 LPWSTR lpwStr, int size, UINT flags)
714 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
717 /****************************************************************************
718 * ToUnicodeEx (USER32.@)
720 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
721 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
723 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
726 /****************************************************************************
729 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
730 LPWORD lpChar, UINT flags )
732 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
735 /****************************************************************************
736 * ToAsciiEx (USER32.@)
738 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
739 LPWORD lpChar, UINT flags, HKL dwhkl )
744 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
745 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
747 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
751 /**********************************************************************
752 * ActivateKeyboardLayout (USER32.@)
754 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
756 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
758 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
761 /**********************************************************************
762 * BlockInput (USER32.@)
764 BOOL WINAPI BlockInput(BOOL fBlockIt)
766 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
767 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
772 /***********************************************************************
773 * GetKeyboardLayoutList (USER32.@)
775 * Return number of values available if either input parm is
776 * 0, per MS documentation.
778 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
780 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
782 return USER_Driver->pGetKeyboardLayoutList(nBuff, layouts);
786 /***********************************************************************
787 * RegisterHotKey (USER32.@)
789 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
792 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
796 /***********************************************************************
797 * UnregisterHotKey (USER32.@)
799 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
802 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
806 /***********************************************************************
807 * LoadKeyboardLayoutW (USER32.@)
809 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
811 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
813 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
816 /***********************************************************************
817 * LoadKeyboardLayoutA (USER32.@)
819 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
822 UNICODE_STRING pwszKLIDW;
824 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
825 else pwszKLIDW.Buffer = NULL;
827 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
828 RtlFreeUnicodeString(&pwszKLIDW);
833 /***********************************************************************
834 * UnloadKeyboardLayout (USER32.@)
836 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
838 TRACE_(keyboard)("(%p)\n", hkl);
840 return USER_Driver->pUnloadKeyboardLayout(hkl);
843 typedef struct __TRACKINGLIST {
845 POINT pos; /* center of hover rectangle */
848 /* FIXME: move tracking stuff into a per thread data */
849 static _TRACKINGLIST tracking_info;
850 static UINT_PTR timer;
852 static void check_mouse_leave(HWND hwnd, int hittest)
854 if (tracking_info.tme.hwndTrack != hwnd)
856 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
857 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
859 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
861 /* remove the TME_LEAVE flag */
862 tracking_info.tme.dwFlags &= ~TME_LEAVE;
866 if (hittest == HTCLIENT)
868 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
870 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
871 /* remove the TME_LEAVE flag */
872 tracking_info.tme.dwFlags &= ~TME_LEAVE;
877 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
879 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
880 /* remove the TME_LEAVE flag */
881 tracking_info.tme.dwFlags &= ~TME_LEAVE;
887 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
891 INT hoverwidth = 0, hoverheight = 0, hittest;
893 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
896 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
898 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
900 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
901 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
903 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
904 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
905 hoverwidth, hoverheight);
907 /* see if this tracking event is looking for TME_LEAVE and that the */
908 /* mouse has left the window */
909 if (tracking_info.tme.dwFlags & TME_LEAVE)
911 check_mouse_leave(hwnd, hittest);
914 if (tracking_info.tme.hwndTrack != hwnd)
916 /* mouse is gone, stop tracking mouse hover */
917 tracking_info.tme.dwFlags &= ~TME_HOVER;
920 /* see if we are tracking hovering for this hwnd */
921 if (tracking_info.tme.dwFlags & TME_HOVER)
923 /* has the cursor moved outside the rectangle centered around pos? */
924 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
925 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
927 /* record this new position as the current position */
928 tracking_info.pos = pos;
932 if (hittest == HTCLIENT)
934 ScreenToClient(hwnd, &pos);
935 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
937 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
938 get_key_state(), MAKELPARAM( pos.x, pos.y ));
942 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
943 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
944 hittest, MAKELPARAM( pos.x, pos.y ));
947 /* stop tracking mouse hover */
948 tracking_info.tme.dwFlags &= ~TME_HOVER;
952 /* stop the timer if the tracking list is empty */
953 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
955 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
957 tracking_info.tme.hwndTrack = 0;
958 tracking_info.tme.dwFlags = 0;
959 tracking_info.tme.dwHoverTime = 0;
964 /***********************************************************************
965 * TrackMouseEvent [USER32]
967 * Requests notification of mouse events
969 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
970 * to the hwnd specified in the ptme structure. After the event message
971 * is posted to the hwnd, the entry in the queue is removed.
973 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
974 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
975 * immediately and the TME_LEAVE flag being ignored.
978 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
987 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
994 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
996 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
997 WARN("wrong TRACKMOUSEEVENT size from app\n");
998 SetLastError(ERROR_INVALID_PARAMETER);
1002 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1003 if (ptme->dwFlags & TME_QUERY )
1005 *ptme = tracking_info.tme;
1006 /* set cbSize in the case it's not initialized yet */
1007 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1009 return TRUE; /* return here, TME_QUERY is retrieving information */
1012 if (!IsWindow(ptme->hwndTrack))
1014 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1018 hover_time = ptme->dwHoverTime;
1020 /* if HOVER_DEFAULT was specified replace this with the systems current value.
1021 * TME_LEAVE doesn't need to specify hover time so use default */
1022 if (hover_time == HOVER_DEFAULT || hover_time == 0 || !(ptme->dwHoverTime&TME_HOVER))
1023 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1026 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1027 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1029 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1030 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1032 if (ptme->dwFlags & TME_CANCEL)
1034 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1036 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1038 /* if we aren't tracking on hover or leave remove this entry */
1039 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1041 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1043 tracking_info.tme.hwndTrack = 0;
1044 tracking_info.tme.dwFlags = 0;
1045 tracking_info.tme.dwHoverTime = 0;
1049 /* In our implementation it's possible that another window will receive a
1050 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1051 * called. In such a situation post the WM_MOUSELEAVE now */
1052 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1053 check_mouse_leave(hwnd, hittest);
1057 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1059 tracking_info.tme.hwndTrack = 0;
1060 tracking_info.tme.dwFlags = 0;
1061 tracking_info.tme.dwHoverTime = 0;
1064 if (ptme->hwndTrack == hwnd)
1066 /* Adding new mouse event to the tracking list */
1067 tracking_info.tme = *ptme;
1068 tracking_info.tme.dwHoverTime = hover_time;
1070 /* Initialize HoverInfo variables even if not hover tracking */
1071 tracking_info.pos = pos;
1073 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);