user: Use (win) debug channel by default, add a TRACE to SendInput.
[wine/multimedia.git] / dlls / user / input.c
blob46f4ae9958bc9f4ab9df05f0e618dc343e50918c
1 /*
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
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <ctype.h>
33 #include <assert.h>
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "wingdi.h"
40 #include "winuser.h"
41 #include "winnls.h"
42 #include "winternl.h"
43 #include "winerror.h"
44 #include "win.h"
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 /***********************************************************************
54 * get_key_state
56 static WORD get_key_state(void)
58 WORD ret = 0;
60 if (GetSystemMetrics( SM_SWAPBUTTON ))
62 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
63 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
65 else
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;
75 return ret;
79 /***********************************************************************
80 * SendInput (USER32.@)
82 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
84 if (TRACE_ON(win))
86 UINT i;
88 for (i = 0; i < count; i++)
90 switch(inputs[i].type)
92 case INPUT_MOUSE:
93 TRACE("mouse: dx %ld, dy %ld, data %lx, flags %lx, time %lu, 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);
96 break;
98 case INPUT_KEYBOARD:
99 TRACE("keyboard: vk %x, scan %x, flags %lx, time %lu, 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);
102 break;
104 case INPUT_HARDWARE:
105 TRACE("hardware: msg %ld, wParamL %x, wParamH %x\n",
106 inputs[i].u.hi.uMsg, inputs[i].u.hi.wParamL, inputs[i].u.hi.wParamH);
107 break;
109 default:
110 FIXME("unknown input type %lu\n", inputs[i].type);
111 break;
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 )
126 INPUT input;
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 )
144 INPUT input;
146 input.type = INPUT_MOUSE;
147 input.u.mi.dx = dx;
148 input.u.mi.dy = dy;
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 )
172 if (!pci) return 0;
173 if (get_user_thread_info()->cursor_count >= 0) pci->flags = CURSOR_SHOWING;
174 else pci->flags = 0;
175 GetCursorPos(&pci->ptScreenPos);
176 return 1;
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 )
194 HWND previous = 0;
196 SERVER_START_REQ( set_capture_window )
198 req->handle = hwnd;
199 req->flags = 0;
200 if (!wine_server_call_err( req ))
202 previous = reply->previous;
203 hwnd = reply->full_handle;
206 SERVER_END_REQ;
208 if (previous && previous != hwnd)
209 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
210 return previous;
214 /**********************************************************************
215 * ReleaseCapture (USER32.@)
217 BOOL WINAPI ReleaseCapture(void)
219 BOOL ret;
220 HWND previous = 0;
222 SERVER_START_REQ( set_capture_window )
224 req->handle = 0;
225 req->flags = 0;
226 if ((ret = !wine_server_call_err( req ))) previous = reply->previous;
228 SERVER_END_REQ;
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 );
235 return ret;
239 /**********************************************************************
240 * GetCapture (USER32.@)
242 HWND WINAPI GetCapture(void)
244 HWND ret = 0;
246 SERVER_START_REQ( get_thread_input )
248 req->tid = GetCurrentThreadId();
249 if (!wine_server_call_err( req )) ret = reply->capture;
251 SERVER_END_REQ;
252 return ret;
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
261 * been pressed.
263 SHORT WINAPI GetAsyncKeyState(INT nKey)
265 return USER_Driver->pGetAsyncKeyState( nKey );
269 /***********************************************************************
270 * GetQueueStatus (USER32.@)
272 DWORD WINAPI GetQueueStatus( UINT flags )
274 DWORD ret = 0;
276 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
278 SetLastError( ERROR_INVALID_FLAGS );
279 return 0;
282 /* check for pending X events */
283 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
285 SERVER_START_REQ( get_queue_status )
287 req->clear = 1;
288 wine_server_call( req );
289 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
291 SERVER_END_REQ;
292 return ret;
296 /***********************************************************************
297 * GetInputState (USER32.@)
299 BOOL WINAPI GetInputState(void)
301 DWORD ret = 0;
303 /* check for pending X events */
304 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
306 SERVER_START_REQ( get_queue_status )
308 req->clear = 0;
309 wine_server_call( req );
310 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
312 SERVER_END_REQ;
313 return ret;
317 /******************************************************************
318 * GetLastInputInfo (USER32.@)
320 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
322 BOOL ret;
324 TRACE("%p\n", plii);
326 if (plii->cbSize != sizeof (*plii) )
328 SetLastError(ERROR_INVALID_PARAMETER);
329 return FALSE;
332 SERVER_START_REQ( get_last_input_time )
334 ret = !wine_server_call_err( req );
335 if (ret)
336 plii->dwTime = reply->time;
338 SERVER_END_REQ;
339 return ret;
343 /**********************************************************************
344 * AttachThreadInput (USER32.@)
346 * Attaches the input processing mechanism of one thread to that of
347 * another thread.
349 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
351 BOOL ret;
353 SERVER_START_REQ( attach_thread_input )
355 req->tid_from = from;
356 req->tid_to = to;
357 req->attach = attach;
358 ret = !wine_server_call_err( req );
360 SERVER_END_REQ;
361 return ret;
365 /**********************************************************************
366 * GetKeyState (USER32.@)
368 * An application calls the GetKeyState function in response to a
369 * keyboard-input message. This function retrieves the state of the key
370 * at the time the input message was generated.
372 SHORT WINAPI GetKeyState(INT vkey)
374 SHORT retval = 0;
376 SERVER_START_REQ( get_key_state )
378 req->tid = GetCurrentThreadId();
379 req->key = vkey;
380 if (!wine_server_call( req )) retval = (signed char)reply->state;
382 SERVER_END_REQ;
383 TRACE("key (0x%x) -> %x\n", vkey, retval);
384 return retval;
388 /**********************************************************************
389 * GetKeyboardState (USER32.@)
391 BOOL WINAPI GetKeyboardState( LPBYTE state )
393 BOOL ret;
395 TRACE("(%p)\n", state);
397 memset( state, 0, 256 );
398 SERVER_START_REQ( get_key_state )
400 req->tid = GetCurrentThreadId();
401 req->key = -1;
402 wine_server_set_reply( req, state, 256 );
403 ret = !wine_server_call_err( req );
405 SERVER_END_REQ;
406 return ret;
410 /**********************************************************************
411 * SetKeyboardState (USER32.@)
413 BOOL WINAPI SetKeyboardState( LPBYTE state )
415 BOOL ret;
417 TRACE("(%p)\n", state);
419 SERVER_START_REQ( set_key_state )
421 req->tid = GetCurrentThreadId();
422 wine_server_add_data( req, state, 256 );
423 ret = !wine_server_call_err( req );
425 SERVER_END_REQ;
426 return ret;
430 /**********************************************************************
431 * VkKeyScanA (USER32.@)
433 * VkKeyScan translates an ANSI character to a virtual-key and shift code
434 * for the current keyboard.
435 * high-order byte yields :
436 * 0 Unshifted
437 * 1 Shift
438 * 2 Ctrl
439 * 3-5 Shift-key combinations that are not used for characters
440 * 6 Ctrl-Alt
441 * 7 Ctrl-Alt-Shift
442 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
443 * FIXME : works ok except for dead chars :
444 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
445 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
447 SHORT WINAPI VkKeyScanA(CHAR cChar)
449 WCHAR wChar;
451 if (IsDBCSLeadByte(cChar)) return -1;
453 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
454 return VkKeyScanW(wChar);
457 /******************************************************************************
458 * VkKeyScanW (USER32.@)
460 SHORT WINAPI VkKeyScanW(WCHAR cChar)
462 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
465 /**********************************************************************
466 * VkKeyScanExA (USER32.@)
468 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
470 WCHAR wChar;
472 if (IsDBCSLeadByte(cChar)) return -1;
474 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
475 return VkKeyScanExW(wChar, dwhkl);
478 /******************************************************************************
479 * VkKeyScanExW (USER32.@)
481 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
483 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
486 /**********************************************************************
487 * OemKeyScan (USER32.@)
489 DWORD WINAPI OemKeyScan(WORD wOemChar)
491 TRACE("(%d)\n", wOemChar);
492 return wOemChar;
495 /******************************************************************************
496 * GetKeyboardType (USER32.@)
498 INT WINAPI GetKeyboardType(INT nTypeFlag)
500 TRACE_(keyboard)("(%d)\n", nTypeFlag);
501 switch(nTypeFlag)
503 case 0: /* Keyboard type */
504 return 4; /* AT-101 */
505 case 1: /* Keyboard Subtype */
506 return 0; /* There are no defined subtypes */
507 case 2: /* Number of F-keys */
508 return 12; /* We're doing an 101 for now, so return 12 F-keys */
509 default:
510 WARN_(keyboard)("Unknown type\n");
511 return 0; /* The book says 0 here, so 0 */
515 /******************************************************************************
516 * MapVirtualKeyA (USER32.@)
518 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
520 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
523 /******************************************************************************
524 * MapVirtualKeyW (USER32.@)
526 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
528 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
531 /******************************************************************************
532 * MapVirtualKeyExA (USER32.@)
534 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
536 return MapVirtualKeyExW(code, maptype, hkl);
539 /******************************************************************************
540 * MapVirtualKeyExW (USER32.@)
542 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
544 TRACE_(keyboard)("(%d, %d, %p)\n", code, maptype, hkl);
546 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
549 /****************************************************************************
550 * GetKBCodePage (USER32.@)
552 UINT WINAPI GetKBCodePage(void)
554 return GetOEMCP();
557 /***********************************************************************
558 * GetKeyboardLayout (USER32.@)
560 * - device handle for keyboard layout defaulted to
561 * the language id. This is the way Windows default works.
562 * - the thread identifier (dwLayout) is also ignored.
564 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
566 return USER_Driver->pGetKeyboardLayout(dwLayout);
569 /****************************************************************************
570 * GetKeyboardLayoutNameA (USER32.@)
572 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
574 WCHAR buf[KL_NAMELENGTH];
576 if (GetKeyboardLayoutNameW(buf))
577 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
578 return FALSE;
581 /****************************************************************************
582 * GetKeyboardLayoutNameW (USER32.@)
584 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
586 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
589 /****************************************************************************
590 * GetKeyNameTextA (USER32.@)
592 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
594 WCHAR buf[256];
595 INT ret;
597 if (!GetKeyNameTextW(lParam, buf, 256))
598 return 0;
599 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
600 if (!ret && nSize)
602 ret = nSize - 1;
603 lpBuffer[ret] = 0;
605 return ret;
608 /****************************************************************************
609 * GetKeyNameTextW (USER32.@)
611 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
613 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
616 /****************************************************************************
617 * ToUnicode (USER32.@)
619 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
620 LPWSTR lpwStr, int size, UINT flags)
622 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
625 /****************************************************************************
626 * ToUnicodeEx (USER32.@)
628 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
629 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
631 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
634 /****************************************************************************
635 * ToAscii (USER32.@)
637 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
638 LPWORD lpChar, UINT flags )
640 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
643 /****************************************************************************
644 * ToAsciiEx (USER32.@)
646 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
647 LPWORD lpChar, UINT flags, HKL dwhkl )
649 WCHAR uni_chars[2];
650 INT ret, n_ret;
652 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
653 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
654 else n_ret = ret;
655 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
656 return ret;
659 /**********************************************************************
660 * ActivateKeyboardLayout (USER32.@)
662 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
664 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
666 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
670 /***********************************************************************
671 * GetKeyboardLayoutList (USER32.@)
673 * Return number of values available if either input parm is
674 * 0, per MS documentation.
676 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
678 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
680 return USER_Driver->pGetKeyboardLayoutList(nBuff, layouts);
684 /***********************************************************************
685 * RegisterHotKey (USER32.@)
687 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
689 FIXME_(keyboard)("(%p,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
690 return TRUE;
693 /***********************************************************************
694 * UnregisterHotKey (USER32.@)
696 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
698 FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
699 return TRUE;
702 /***********************************************************************
703 * LoadKeyboardLayoutW (USER32.@)
705 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
707 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
709 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
712 /***********************************************************************
713 * LoadKeyboardLayoutA (USER32.@)
715 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
717 HKL ret;
718 UNICODE_STRING pwszKLIDW;
720 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
721 else pwszKLIDW.Buffer = NULL;
723 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
724 RtlFreeUnicodeString(&pwszKLIDW);
725 return ret;
729 /***********************************************************************
730 * UnloadKeyboardLayout (USER32.@)
732 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
734 TRACE_(keyboard)("(%p)\n", hkl);
736 return USER_Driver->pUnloadKeyboardLayout(hkl);
739 typedef struct __TRACKINGLIST {
740 TRACKMOUSEEVENT tme;
741 POINT pos; /* center of hover rectangle */
742 } _TRACKINGLIST;
744 /* FIXME: move tracking stuff into a per thread data */
745 static _TRACKINGLIST tracking_info;
746 static UINT_PTR timer;
748 static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR idEvent,
749 DWORD dwTime)
751 POINT pos;
752 POINT posClient;
753 HWND hwnd;
754 INT hoverwidth = 0, hoverheight = 0;
755 RECT client;
757 GetCursorPos(&pos);
758 hwnd = WindowFromPoint(pos);
760 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
761 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
763 /* see if this tracking event is looking for TME_LEAVE and that the */
764 /* mouse has left the window */
765 if (tracking_info.tme.dwFlags & TME_LEAVE)
767 if (tracking_info.tme.hwndTrack != hwnd)
769 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
770 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
771 else
772 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
774 /* remove the TME_LEAVE flag */
775 tracking_info.tme.dwFlags &= ~TME_LEAVE;
777 else
779 GetClientRect(hwnd, &client);
780 MapWindowPoints(hwnd, NULL, (LPPOINT)&client, 2);
781 if (PtInRect(&client, pos))
783 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
785 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
786 /* remove the TME_LEAVE flag */
787 tracking_info.tme.dwFlags &= ~TME_LEAVE;
790 else
792 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
794 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
795 /* remove the TME_LEAVE flag */
796 tracking_info.tme.dwFlags &= ~TME_LEAVE;
802 /* see if we are tracking hovering for this hwnd */
803 if (tracking_info.tme.dwFlags & TME_HOVER)
805 /* has the cursor moved outside the rectangle centered around pos? */
806 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2.0)) ||
807 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2.0)))
809 /* record this new position as the current position and reset */
810 /* the iHoverTime variable to 0 */
811 tracking_info.pos = pos;
813 else
815 posClient.x = pos.x;
816 posClient.y = pos.y;
817 ScreenToClient(hwnd, &posClient);
819 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
820 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
821 get_key_state(), MAKELPARAM( posClient.x, posClient.y ));
822 else
823 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
824 get_key_state(), MAKELPARAM( posClient.x, posClient.y ));
826 /* stop tracking mouse hover */
827 tracking_info.tme.dwFlags &= ~TME_HOVER;
831 /* stop the timer if the tracking list is empty */
832 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
834 memset(&tracking_info, 0, sizeof(tracking_info));
836 KillSystemTimer(0, timer);
837 timer = 0;
842 /***********************************************************************
843 * TrackMouseEvent [USER32]
845 * Requests notification of mouse events
847 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
848 * to the hwnd specified in the ptme structure. After the event message
849 * is posted to the hwnd, the entry in the queue is removed.
851 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
852 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
853 * immediately and the TME_LEAVE flag being ignored.
855 * PARAMS
856 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
858 * RETURNS
859 * Success: non-zero
860 * Failure: zero
864 BOOL WINAPI
865 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
867 HWND hwnd;
868 POINT pos;
869 DWORD hover_time;
871 TRACE("%lx, %lx, %p, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
873 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
874 WARN("wrong TRACKMOUSEEVENT size from app\n");
875 SetLastError(ERROR_INVALID_PARAMETER);
876 return FALSE;
879 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
880 if (ptme->dwFlags & TME_QUERY )
882 *ptme = tracking_info.tme;
884 return TRUE; /* return here, TME_QUERY is retrieving information */
887 if (!IsWindow(ptme->hwndTrack))
889 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
890 return FALSE;
893 hover_time = ptme->dwHoverTime;
895 /* if HOVER_DEFAULT was specified replace this with the systems current value */
896 if (hover_time == HOVER_DEFAULT || hover_time == 0)
897 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
899 GetCursorPos(&pos);
900 hwnd = WindowFromPoint(pos);
902 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
903 FIXME("Unknown flag(s) %08lx\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
905 if (ptme->dwFlags & TME_CANCEL)
907 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
909 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
911 /* if we aren't tracking on hover or leave remove this entry */
912 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
914 memset(&tracking_info, 0, sizeof(tracking_info));
916 KillSystemTimer(0, timer);
917 timer = 0;
920 } else {
921 if (ptme->hwndTrack == hwnd)
923 /* Adding new mouse event to the tracking list */
924 tracking_info.tme = *ptme;
925 tracking_info.tme.dwHoverTime = hover_time;
927 /* Initialize HoverInfo variables even if not hover tracking */
928 tracking_info.pos = pos;
930 if (!timer)
931 timer = SetSystemTimer(0, 0, hover_time, TrackMouseEventProc);
935 return TRUE;