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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
35 #define NONAMELESSUNION
36 #define NONAMELESSSTRUCT
42 #include "wine/server.h"
43 #include "user_private.h"
45 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(key
);
49 WINE_DECLARE_DEBUG_CHANNEL(keyboard
);
52 /***********************************************************************
55 static WORD
get_key_state(void)
59 if (GetSystemMetrics( SM_SWAPBUTTON
))
61 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
62 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
66 if (GetAsyncKeyState(VK_LBUTTON
) & 0x80) ret
|= MK_LBUTTON
;
67 if (GetAsyncKeyState(VK_RBUTTON
) & 0x80) ret
|= MK_RBUTTON
;
69 if (GetAsyncKeyState(VK_MBUTTON
) & 0x80) ret
|= MK_MBUTTON
;
70 if (GetAsyncKeyState(VK_SHIFT
) & 0x80) ret
|= MK_SHIFT
;
71 if (GetAsyncKeyState(VK_CONTROL
) & 0x80) ret
|= MK_CONTROL
;
72 if (GetAsyncKeyState(VK_XBUTTON1
) & 0x80) ret
|= MK_XBUTTON1
;
73 if (GetAsyncKeyState(VK_XBUTTON2
) & 0x80) ret
|= MK_XBUTTON2
;
78 /***********************************************************************
79 * SendInput (USER32.@)
81 UINT WINAPI
SendInput( UINT count
, LPINPUT inputs
, int size
)
83 return USER_Driver
->pSendInput( count
, inputs
, size
);
87 /***********************************************************************
88 * keybd_event (USER32.@)
90 void WINAPI
keybd_event( BYTE bVk
, BYTE bScan
,
91 DWORD dwFlags
, ULONG_PTR dwExtraInfo
)
95 input
.type
= INPUT_KEYBOARD
;
97 input
.u
.ki
.wScan
= bScan
;
98 input
.u
.ki
.dwFlags
= dwFlags
;
99 input
.u
.ki
.time
= GetTickCount();
100 input
.u
.ki
.dwExtraInfo
= dwExtraInfo
;
101 SendInput( 1, &input
, sizeof(input
) );
105 /***********************************************************************
106 * mouse_event (USER32.@)
108 void WINAPI
mouse_event( DWORD dwFlags
, DWORD dx
, DWORD dy
,
109 DWORD dwData
, ULONG_PTR dwExtraInfo
)
113 input
.type
= INPUT_MOUSE
;
116 input
.u
.mi
.mouseData
= dwData
;
117 input
.u
.mi
.dwFlags
= dwFlags
;
118 input
.u
.mi
.time
= GetCurrentTime();
119 input
.u
.mi
.dwExtraInfo
= dwExtraInfo
;
120 SendInput( 1, &input
, sizeof(input
) );
124 /***********************************************************************
125 * GetCursorPos (USER32.@)
127 BOOL WINAPI
GetCursorPos( POINT
*pt
)
129 if (!pt
) return FALSE
;
130 return USER_Driver
->pGetCursorPos( pt
);
134 /***********************************************************************
135 * GetCursorInfo (USER32.@)
137 BOOL WINAPI
GetCursorInfo( PCURSORINFO pci
)
140 if (get_user_thread_info()->cursor_count
>= 0) pci
->flags
= CURSOR_SHOWING
;
142 GetCursorPos(&pci
->ptScreenPos
);
147 /***********************************************************************
148 * SetCursorPos (USER32.@)
150 BOOL WINAPI
SetCursorPos( INT x
, INT y
)
152 return USER_Driver
->pSetCursorPos( x
, y
);
156 /**********************************************************************
157 * SetCapture (USER32.@)
159 HWND WINAPI
SetCapture( HWND hwnd
)
163 SERVER_START_REQ( set_capture_window
)
167 if (!wine_server_call_err( req
))
169 previous
= reply
->previous
;
170 hwnd
= reply
->full_handle
;
175 if (previous
&& previous
!= hwnd
)
176 SendMessageW( previous
, WM_CAPTURECHANGED
, 0, (LPARAM
)hwnd
);
181 /**********************************************************************
182 * ReleaseCapture (USER32.@)
184 BOOL WINAPI
ReleaseCapture(void)
186 return (SetCapture(0) != 0);
190 /**********************************************************************
191 * GetCapture (USER32.@)
193 HWND WINAPI
GetCapture(void)
197 SERVER_START_REQ( get_thread_input
)
199 req
->tid
= GetCurrentThreadId();
200 if (!wine_server_call_err( req
)) ret
= reply
->capture
;
207 /**********************************************************************
208 * GetAsyncKeyState (USER32.@)
210 * Determine if a key is or was pressed. retval has high-order
211 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
214 SHORT WINAPI
GetAsyncKeyState(INT nKey
)
216 return USER_Driver
->pGetAsyncKeyState( nKey
);
220 /***********************************************************************
221 * GetQueueStatus (USER32.@)
223 DWORD WINAPI
GetQueueStatus( UINT flags
)
227 /* check for pending X events */
228 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
230 SERVER_START_REQ( get_queue_status
)
233 wine_server_call( req
);
234 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
241 /***********************************************************************
242 * GetInputState (USER32.@)
244 BOOL WINAPI
GetInputState(void)
248 /* check for pending X events */
249 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_INPUT
, 0 );
251 SERVER_START_REQ( get_queue_status
)
254 wine_server_call( req
);
255 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
262 /******************************************************************
263 * GetLastInputInfo (USER32.@)
265 BOOL WINAPI
GetLastInputInfo(PLASTINPUTINFO plii
)
271 if (plii
->cbSize
!= sizeof (*plii
) )
273 SetLastError(ERROR_INVALID_PARAMETER
);
277 SERVER_START_REQ( get_last_input_time
)
279 ret
= !wine_server_call_err( req
);
281 plii
->dwTime
= reply
->time
;
288 /**********************************************************************
289 * AttachThreadInput (USER32.@)
291 * Attaches the input processing mechanism of one thread to that of
294 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
298 SERVER_START_REQ( attach_thread_input
)
300 req
->tid_from
= from
;
302 req
->attach
= attach
;
303 ret
= !wine_server_call_err( req
);
310 /**********************************************************************
311 * GetKeyState (USER32.@)
313 * An application calls the GetKeyState function in response to a
314 * keyboard-input message. This function retrieves the state of the key
315 * at the time the input message was generated.
317 SHORT WINAPI
GetKeyState(INT vkey
)
321 SERVER_START_REQ( get_key_state
)
323 req
->tid
= GetCurrentThreadId();
325 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
328 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
333 /**********************************************************************
334 * GetKeyboardState (USER32.@)
336 BOOL WINAPI
GetKeyboardState( LPBYTE state
)
340 TRACE("(%p)\n", state
);
342 memset( state
, 0, 256 );
343 SERVER_START_REQ( get_key_state
)
345 req
->tid
= GetCurrentThreadId();
347 wine_server_set_reply( req
, state
, 256 );
348 ret
= !wine_server_call_err( req
);
355 /**********************************************************************
356 * SetKeyboardState (USER32.@)
358 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
362 TRACE("(%p)\n", state
);
364 SERVER_START_REQ( set_key_state
)
366 req
->tid
= GetCurrentThreadId();
367 wine_server_add_data( req
, state
, 256 );
368 ret
= !wine_server_call_err( req
);
375 /**********************************************************************
376 * VkKeyScanA (USER32.@)
378 * VkKeyScan translates an ANSI character to a virtual-key and shift code
379 * for the current keyboard.
380 * high-order byte yields :
384 * 3-5 Shift-key combinations that are not used for characters
387 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
388 * FIXME : works ok except for dead chars :
389 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
390 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
392 SHORT WINAPI
VkKeyScanA(CHAR cChar
)
396 if (IsDBCSLeadByte(cChar
)) return -1;
398 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
399 return VkKeyScanW(wChar
);
402 /******************************************************************************
403 * VkKeyScanW (USER32.@)
405 SHORT WINAPI
VkKeyScanW(WCHAR cChar
)
407 return VkKeyScanExW(cChar
, GetKeyboardLayout(0));
410 /**********************************************************************
411 * VkKeyScanExA (USER32.@)
413 WORD WINAPI
VkKeyScanExA(CHAR cChar
, HKL dwhkl
)
417 if (IsDBCSLeadByte(cChar
)) return -1;
419 MultiByteToWideChar(CP_ACP
, 0, &cChar
, 1, &wChar
, 1);
420 return VkKeyScanExW(wChar
, dwhkl
);
423 /******************************************************************************
424 * VkKeyScanExW (USER32.@)
426 WORD WINAPI
VkKeyScanExW(WCHAR cChar
, HKL dwhkl
)
428 return USER_Driver
->pVkKeyScanEx(cChar
, dwhkl
);
431 /**********************************************************************
432 * OemKeyScan (USER32.@)
434 DWORD WINAPI
OemKeyScan(WORD wOemChar
)
436 TRACE("(%d)\n", wOemChar
);
440 /******************************************************************************
441 * GetKeyboardType (USER32.@)
443 INT WINAPI
GetKeyboardType(INT nTypeFlag
)
445 TRACE_(keyboard
)("(%d)\n", nTypeFlag
);
448 case 0: /* Keyboard type */
449 return 4; /* AT-101 */
450 case 1: /* Keyboard Subtype */
451 return 0; /* There are no defined subtypes */
452 case 2: /* Number of F-keys */
453 return 12; /* We're doing an 101 for now, so return 12 F-keys */
455 WARN_(keyboard
)("Unknown type\n");
456 return 0; /* The book says 0 here, so 0 */
460 /******************************************************************************
461 * MapVirtualKeyA (USER32.@)
463 UINT WINAPI
MapVirtualKeyA(UINT code
, UINT maptype
)
465 return MapVirtualKeyExA( code
, maptype
, GetKeyboardLayout(0) );
468 /******************************************************************************
469 * MapVirtualKeyW (USER32.@)
471 UINT WINAPI
MapVirtualKeyW(UINT code
, UINT maptype
)
473 return MapVirtualKeyExW(code
, maptype
, GetKeyboardLayout(0));
476 /******************************************************************************
477 * MapVirtualKeyExA (USER32.@)
479 UINT WINAPI
MapVirtualKeyExA(UINT code
, UINT maptype
, HKL hkl
)
481 return MapVirtualKeyExW(code
, maptype
, hkl
);
484 /******************************************************************************
485 * MapVirtualKeyExW (USER32.@)
487 UINT WINAPI
MapVirtualKeyExW(UINT code
, UINT maptype
, HKL hkl
)
489 TRACE_(keyboard
)("(%d, %d, %p)\n", code
, maptype
, hkl
);
491 return USER_Driver
->pMapVirtualKeyEx(code
, maptype
, hkl
);
494 /****************************************************************************
495 * GetKBCodePage (USER32.@)
497 UINT WINAPI
GetKBCodePage(void)
502 /***********************************************************************
503 * GetKeyboardLayout (USER32.@)
505 * - device handle for keyboard layout defaulted to
506 * the language id. This is the way Windows default works.
507 * - the thread identifier (dwLayout) is also ignored.
509 HKL WINAPI
GetKeyboardLayout(DWORD dwLayout
)
511 return USER_Driver
->pGetKeyboardLayout(dwLayout
);
514 /****************************************************************************
515 * GetKeyboardLayoutNameA (USER32.@)
517 BOOL WINAPI
GetKeyboardLayoutNameA(LPSTR pszKLID
)
519 WCHAR buf
[KL_NAMELENGTH
];
521 if (GetKeyboardLayoutNameW(buf
))
522 return WideCharToMultiByte( CP_ACP
, 0, buf
, -1, pszKLID
, KL_NAMELENGTH
, NULL
, NULL
) != 0;
526 /****************************************************************************
527 * GetKeyboardLayoutNameW (USER32.@)
529 BOOL WINAPI
GetKeyboardLayoutNameW(LPWSTR pwszKLID
)
531 return USER_Driver
->pGetKeyboardLayoutName(pwszKLID
);
534 /****************************************************************************
535 * GetKeyNameTextA (USER32.@)
537 INT WINAPI
GetKeyNameTextA(LONG lParam
, LPSTR lpBuffer
, INT nSize
)
542 if (!GetKeyNameTextW(lParam
, buf
, 256))
544 ret
= WideCharToMultiByte(CP_ACP
, 0, buf
, -1, lpBuffer
, nSize
, NULL
, NULL
);
553 /****************************************************************************
554 * GetKeyNameTextW (USER32.@)
556 INT WINAPI
GetKeyNameTextW(LONG lParam
, LPWSTR lpBuffer
, INT nSize
)
558 return USER_Driver
->pGetKeyNameText( lParam
, lpBuffer
, nSize
);
561 /****************************************************************************
562 * ToUnicode (USER32.@)
564 INT WINAPI
ToUnicode(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
565 LPWSTR lpwStr
, int size
, UINT flags
)
567 return ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, GetKeyboardLayout(0));
570 /****************************************************************************
571 * ToUnicodeEx (USER32.@)
573 INT WINAPI
ToUnicodeEx(UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
574 LPWSTR lpwStr
, int size
, UINT flags
, HKL hkl
)
576 return USER_Driver
->pToUnicodeEx(virtKey
, scanCode
, lpKeyState
, lpwStr
, size
, flags
, hkl
);
579 /****************************************************************************
582 INT WINAPI
ToAscii( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
583 LPWORD lpChar
, UINT flags
)
585 return ToAsciiEx(virtKey
, scanCode
, lpKeyState
, lpChar
, flags
, GetKeyboardLayout(0));
588 /****************************************************************************
589 * ToAsciiEx (USER32.@)
591 INT WINAPI
ToAsciiEx( UINT virtKey
, UINT scanCode
, LPBYTE lpKeyState
,
592 LPWORD lpChar
, UINT flags
, HKL dwhkl
)
597 ret
= ToUnicodeEx(virtKey
, scanCode
, lpKeyState
, uni_chars
, 2, flags
, dwhkl
);
598 if (ret
< 0) n_ret
= 1; /* FIXME: make ToUnicode return 2 for dead chars */
600 WideCharToMultiByte(CP_ACP
, 0, uni_chars
, n_ret
, (LPSTR
)lpChar
, 2, NULL
, NULL
);
604 /**********************************************************************
605 * ActivateKeyboardLayout (USER32.@)
607 HKL WINAPI
ActivateKeyboardLayout(HKL hLayout
, UINT flags
)
609 TRACE_(keyboard
)("(%p, %d)\n", hLayout
, flags
);
611 return USER_Driver
->pActivateKeyboardLayout(hLayout
, flags
);
615 /***********************************************************************
616 * GetKeyboardLayoutList (USER32.@)
618 * Return number of values available if either input parm is
619 * 0, per MS documentation.
621 UINT WINAPI
GetKeyboardLayoutList(INT nBuff
, HKL
*layouts
)
623 TRACE_(keyboard
)("(%d,%p)\n",nBuff
,layouts
);
625 return USER_Driver
->pGetKeyboardLayoutList(nBuff
, layouts
);
629 /***********************************************************************
630 * RegisterHotKey (USER32.@)
632 BOOL WINAPI
RegisterHotKey(HWND hwnd
,INT id
,UINT modifiers
,UINT vk
)
634 FIXME_(keyboard
)("(%p,%d,0x%08x,%d): stub\n",hwnd
,id
,modifiers
,vk
);
638 /***********************************************************************
639 * UnregisterHotKey (USER32.@)
641 BOOL WINAPI
UnregisterHotKey(HWND hwnd
,INT id
)
643 FIXME_(keyboard
)("(%p,%d): stub\n",hwnd
,id
);
647 /***********************************************************************
648 * LoadKeyboardLayoutW (USER32.@)
650 HKL WINAPI
LoadKeyboardLayoutW(LPCWSTR pwszKLID
, UINT Flags
)
652 TRACE_(keyboard
)("(%s, %d)\n", debugstr_w(pwszKLID
), Flags
);
654 return USER_Driver
->pLoadKeyboardLayout(pwszKLID
, Flags
);
657 /***********************************************************************
658 * LoadKeyboardLayoutA (USER32.@)
660 HKL WINAPI
LoadKeyboardLayoutA(LPCSTR pwszKLID
, UINT Flags
)
663 UNICODE_STRING pwszKLIDW
;
665 if (pwszKLID
) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW
, pwszKLID
);
666 else pwszKLIDW
.Buffer
= NULL
;
668 ret
= LoadKeyboardLayoutW(pwszKLIDW
.Buffer
, Flags
);
669 RtlFreeUnicodeString(&pwszKLIDW
);
674 /***********************************************************************
675 * UnloadKeyboardLayout (USER32.@)
677 BOOL WINAPI
UnloadKeyboardLayout(HKL hkl
)
679 TRACE_(keyboard
)("(%p)\n", hkl
);
681 return USER_Driver
->pUnloadKeyboardLayout(hkl
);
684 typedef struct __TRACKINGLIST
{
686 POINT pos
; /* center of hover rectangle */
687 INT iHoverTime
; /* elapsed time the cursor has been inside of the hover rect */
690 static _TRACKINGLIST TrackingList
[10];
691 static int iTrackMax
= 0;
692 static UINT_PTR timer
;
693 static const INT iTimerInterval
= 50; /* msec for timer interval */
695 static void CALLBACK
TrackMouseEventProc(HWND hwndUnused
, UINT uMsg
, UINT_PTR idEvent
,
703 INT hoverwidth
= 0, hoverheight
= 0;
707 hwnd
= WindowFromPoint(pos
);
709 SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH
, 0, &hoverwidth
, 0);
710 SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT
, 0, &hoverheight
, 0);
712 /* loop through tracking events we are processing */
713 while (i
< iTrackMax
) {
714 if (TrackingList
[i
].tme
.dwFlags
& TME_NONCLIENT
) {
721 /* see if this tracking event is looking for TME_LEAVE and that the */
722 /* mouse has left the window */
723 if (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
) {
724 if (TrackingList
[i
].tme
.hwndTrack
!= hwnd
) {
726 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
729 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
732 /* remove the TME_LEAVE flag */
733 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
736 GetClientRect(hwnd
, &client
);
737 MapWindowPoints(hwnd
, NULL
, (LPPOINT
)&client
, 2);
738 if(PtInRect(&client
, pos
)) {
740 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
741 /* remove the TME_LEAVE flag */
742 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
747 PostMessageA(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSELEAVE
, 0, 0);
748 /* remove the TME_LEAVE flag */
749 TrackingList
[i
].tme
.dwFlags
^= TME_LEAVE
;
755 /* see if we are tracking hovering for this hwnd */
756 if(TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) {
757 /* add the timer interval to the hovering time */
758 TrackingList
[i
].iHoverTime
+=iTimerInterval
;
760 /* has the cursor moved outside the rectangle centered around pos? */
761 if((abs(pos
.x
- TrackingList
[i
].pos
.x
) > (hoverwidth
/ 2.0))
762 || (abs(pos
.y
- TrackingList
[i
].pos
.y
) > (hoverheight
/ 2.0)))
764 /* record this new position as the current position and reset */
765 /* the iHoverTime variable to 0 */
766 TrackingList
[i
].pos
= pos
;
767 TrackingList
[i
].iHoverTime
= 0;
770 /* has the mouse hovered long enough? */
771 if(TrackingList
[i
].iHoverTime
<= TrackingList
[i
].tme
.dwHoverTime
)
775 ScreenToClient(hwnd
, &posClient
);
777 PostMessageW(TrackingList
[i
].tme
.hwndTrack
, WM_NCMOUSEHOVER
,
778 get_key_state(), MAKELPARAM( posClient
.x
, posClient
.y
));
781 PostMessageW(TrackingList
[i
].tme
.hwndTrack
, WM_MOUSEHOVER
,
782 get_key_state(), MAKELPARAM( posClient
.x
, posClient
.y
));
785 /* stop tracking mouse hover */
786 TrackingList
[i
].tme
.dwFlags
^= TME_HOVER
;
790 /* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
791 if((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
792 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)) {
794 } else { /* remove this entry from the tracking list */
795 TrackingList
[i
] = TrackingList
[--iTrackMax
];
799 /* stop the timer if the tracking list is empty */
807 /***********************************************************************
808 * TrackMouseEvent [USER32]
810 * Requests notification of mouse events
812 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
813 * to the hwnd specified in the ptme structure. After the event message
814 * is posted to the hwnd, the entry in the queue is removed.
816 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
817 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
818 * immediately and the TME_LEAVE flag being ignored.
821 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
830 TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
834 BOOL cancel
= 0, hover
= 0, leave
= 0, query
= 0, nonclient
= 0, inclient
= 0;
842 SetRectEmpty(&client
);
844 TRACE("%lx, %lx, %p, %lx\n", ptme
->cbSize
, ptme
->dwFlags
, ptme
->hwndTrack
, ptme
->dwHoverTime
);
846 if (ptme
->cbSize
!= sizeof(TRACKMOUSEEVENT
)) {
847 WARN("wrong TRACKMOUSEEVENT size from app\n");
848 SetLastError(ERROR_INVALID_PARAMETER
); /* FIXME not sure if this is correct */
852 flags
= ptme
->dwFlags
;
854 /* if HOVER_DEFAULT was specified replace this with the systems current value */
855 if(ptme
->dwHoverTime
== HOVER_DEFAULT
)
856 SystemParametersInfoA(SPI_GETMOUSEHOVERTIME
, 0, &(ptme
->dwHoverTime
), 0);
859 hwnd
= WindowFromPoint(pos
);
861 if ( flags
& TME_CANCEL
) {
862 flags
&= ~ TME_CANCEL
;
866 if ( flags
& TME_HOVER
) {
867 flags
&= ~ TME_HOVER
;
871 if ( flags
& TME_LEAVE
) {
872 flags
&= ~ TME_LEAVE
;
876 if ( flags
& TME_NONCLIENT
) {
877 flags
&= ~ TME_NONCLIENT
;
881 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
882 if ( flags
& TME_QUERY
) {
883 flags
&= ~ TME_QUERY
;
887 /* Find the tracking list entry with the matching hwnd */
888 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
892 /* hwnd found, fill in the ptme struct */
894 *ptme
= TrackingList
[i
].tme
;
898 return TRUE
; /* return here, TME_QUERY is retrieving information */
902 FIXME("Unknown flag(s) %08lx\n", flags
);
905 /* find a matching hwnd if one exists */
908 while((i
< iTrackMax
) && (TrackingList
[i
].tme
.hwndTrack
!= ptme
->hwndTrack
)) {
913 TrackingList
[i
].tme
.dwFlags
&= ~(ptme
->dwFlags
& ~TME_CANCEL
);
915 /* if we aren't tracking on hover or leave remove this entry */
916 if(!((TrackingList
[i
].tme
.dwFlags
& TME_HOVER
) ||
917 (TrackingList
[i
].tme
.dwFlags
& TME_LEAVE
)))
919 TrackingList
[i
] = TrackingList
[--iTrackMax
];
928 /* see if hwndTrack isn't the current window */
929 if(ptme
->hwndTrack
!= hwnd
) {
932 PostMessageA(ptme
->hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
935 PostMessageA(ptme
->hwndTrack
, WM_MOUSELEAVE
, 0, 0);
939 GetClientRect(ptme
->hwndTrack
, &client
);
940 MapWindowPoints(ptme
->hwndTrack
, NULL
, (LPPOINT
)&client
, 2);
941 if(PtInRect(&client
, pos
)) {
944 if(nonclient
&& inclient
) {
945 PostMessageA(ptme
->hwndTrack
, WM_NCMOUSELEAVE
, 0, 0);
948 else if(!nonclient
&& !inclient
) {
949 PostMessageA(ptme
->hwndTrack
, WM_MOUSELEAVE
, 0, 0);
953 /* See if this hwnd is already being tracked and update the tracking flags */
954 for(i
= 0; i
< iTrackMax
; i
++) {
955 if(TrackingList
[i
].tme
.hwndTrack
== ptme
->hwndTrack
) {
956 TrackingList
[i
].tme
.dwFlags
= 0;
959 TrackingList
[i
].tme
.dwFlags
|= TME_HOVER
;
960 TrackingList
[i
].tme
.dwHoverTime
= ptme
->dwHoverTime
;
964 TrackingList
[i
].tme
.dwFlags
|= TME_LEAVE
;
967 TrackingList
[i
].tme
.dwFlags
|= TME_NONCLIENT
;
969 /* reset iHoverTime as per winapi specs */
970 TrackingList
[i
].iHoverTime
= 0;
976 /* if the tracking list is full return FALSE */
977 if (iTrackMax
== sizeof (TrackingList
) / sizeof(*TrackingList
)) {
981 /* Adding new mouse event to the tracking list */
982 TrackingList
[iTrackMax
].tme
= *ptme
;
984 /* Initialize HoverInfo variables even if not hover tracking */
985 TrackingList
[iTrackMax
].iHoverTime
= 0;
986 TrackingList
[iTrackMax
].pos
= pos
;
991 timer
= SetTimer(0, 0, iTimerInterval
, TrackMouseEventProc
);