Sync to trunk r38200
[reactos.git] / reactos / dll / win32 / user32 / windows / input.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
23 * PURPOSE: Input
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <user32.h>
32
33 #include <wine/debug.h>
34 WINE_DEFAULT_DEBUG_CHANNEL(user32);
35
36 /* GLOBALS *******************************************************************/
37
38
39
40 /* FUNCTIONS *****************************************************************/
41
42
43 /*
44 * @implemented
45 */
46 BOOL
47 WINAPI
48 DragDetect(
49 HWND hWnd,
50 POINT pt)
51 {
52 #if 0
53 return NtUserDragDetect(hWnd, pt);
54 #else
55 MSG msg;
56 RECT rect;
57 POINT tmp;
58 ULONG dx = GetSystemMetrics(SM_CXDRAG);
59 ULONG dy = GetSystemMetrics(SM_CYDRAG);
60
61 rect.left = pt.x - dx;
62 rect.right = pt.x + dx;
63 rect.top = pt.y - dy;
64 rect.bottom = pt.y + dy;
65
66 SetCapture(hWnd);
67
68 for (;;)
69 {
70 while (
71 PeekMessageW(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE) ||
72 PeekMessageW(&msg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)
73 )
74 {
75 if (msg.message == WM_LBUTTONUP)
76 {
77 ReleaseCapture();
78 return FALSE;
79 }
80 if (msg.message == WM_MOUSEMOVE)
81 {
82 tmp.x = LOWORD(msg.lParam);
83 tmp.y = HIWORD(msg.lParam);
84 if (!PtInRect(&rect, tmp))
85 {
86 ReleaseCapture();
87 return TRUE;
88 }
89 }
90 if (msg.message == WM_KEYDOWN)
91 {
92 if (msg.wParam == VK_ESCAPE)
93 {
94 ReleaseCapture();
95 return TRUE;
96 }
97 }
98 }
99 WaitMessage();
100 }
101 return 0;
102 #endif
103 }
104
105
106 /*
107 * @implemented
108 */
109 BOOL WINAPI
110 BlockInput(BOOL fBlockIt)
111 {
112 return NtUserBlockInput(fBlockIt);
113 }
114
115
116 /*
117 * @implemented
118 */
119 BOOL WINAPI
120 EnableWindow(HWND hWnd,
121 BOOL bEnable)
122 {
123 LONG Style = GetWindowLongW(hWnd, GWL_STYLE);
124 /* check if updating is needed */
125 UINT bIsDisabled = (Style & WS_DISABLED);
126 if ( (bIsDisabled && bEnable) || (!bIsDisabled && !bEnable) )
127 {
128 if (bEnable)
129 {
130 Style &= ~WS_DISABLED;
131 }
132 else
133 {
134 Style |= WS_DISABLED;
135 /* Remove keyboard focus from that window if it had focus */
136 if (hWnd == GetFocus())
137 {
138 SetFocus(NULL);
139 }
140 }
141 NtUserSetWindowLong(hWnd, GWL_STYLE, Style, FALSE);
142
143 SendMessageA(hWnd, WM_ENABLE, (LPARAM) IsWindowEnabled(hWnd), 0);
144 }
145 // Return nonzero if it was disabled, or zero if it wasn't:
146 return IsWindowEnabled(hWnd);
147 }
148
149
150 /*
151 * @implemented
152 */
153 SHORT WINAPI
154 GetAsyncKeyState(int vKey)
155 {
156 if (vKey < 0 || vKey > 256)
157 return 0;
158 return (SHORT) NtUserGetAsyncKeyState((DWORD) vKey);
159 }
160
161
162 /*
163 * @implemented
164 */
165 UINT
166 WINAPI
167 GetDoubleClickTime(VOID)
168 {
169 return NtUserGetDoubleClickTime();
170 }
171
172
173 /*
174 * @implemented
175 */
176 HKL WINAPI
177 GetKeyboardLayout(DWORD idThread)
178 {
179 return (HKL)NtUserCallOneParam((DWORD) idThread, ONEPARAM_ROUTINE_GETKEYBOARDLAYOUT);
180 }
181
182
183 /*
184 * @implemented
185 */
186 UINT WINAPI
187 GetKBCodePage(VOID)
188 {
189 return GetOEMCP();
190 }
191
192
193 /*
194 * @implemented
195 */
196 int WINAPI
197 GetKeyNameTextA(LONG lParam,
198 LPSTR lpString,
199 int nSize)
200 {
201 LPWSTR intermediateString =
202 HeapAlloc(GetProcessHeap(),0,nSize * sizeof(WCHAR));
203 int ret = 0;
204 UINT wstrLen = 0;
205 BOOL defChar = FALSE;
206
207 if( !intermediateString ) return 0;
208 ret = GetKeyNameTextW(lParam,intermediateString,nSize);
209 if( ret == 0 ) { lpString[0] = 0; return 0; }
210
211 wstrLen = wcslen( intermediateString );
212 ret = WideCharToMultiByte(CP_ACP, 0,
213 intermediateString, wstrLen,
214 lpString, nSize, ".", &defChar );
215 lpString[ret] = 0;
216 HeapFree(GetProcessHeap(),0,intermediateString);
217
218 return ret;
219 }
220
221 /*
222 * @implemented
223 */
224 int WINAPI
225 GetKeyNameTextW(LONG lParam,
226 LPWSTR lpString,
227 int nSize)
228 {
229 return NtUserGetKeyNameText( lParam, lpString, nSize );
230 }
231
232
233 /*
234 * @implemented
235 */
236 SHORT WINAPI
237 GetKeyState(int nVirtKey)
238 {
239 return (SHORT) NtUserGetKeyState((DWORD) nVirtKey);
240 }
241
242
243 /*
244 * @implemented
245 */
246 BOOL WINAPI
247 GetKeyboardLayoutNameA(LPSTR pwszKLID)
248 {
249 WCHAR buf[KL_NAMELENGTH];
250
251 if (GetKeyboardLayoutNameW(buf))
252 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pwszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
253 return FALSE;
254 }
255
256
257 /*
258 * @implemented
259 */
260 BOOL WINAPI
261 GetKeyboardLayoutNameW(LPWSTR pwszKLID)
262 {
263 return NtUserGetKeyboardLayoutName( pwszKLID );
264 }
265
266
267 /*
268 * @implemented
269 */
270 BOOL WINAPI
271 GetKeyboardState(PBYTE lpKeyState)
272 {
273
274 return (BOOL) NtUserGetKeyboardState((LPBYTE) lpKeyState);
275 }
276
277
278 /*
279 * @implemented
280 */
281 int WINAPI
282 GetKeyboardType(int nTypeFlag)
283 {
284 return (int)NtUserCallOneParam((DWORD) nTypeFlag, ONEPARAM_ROUTINE_GETKEYBOARDTYPE);
285 }
286
287
288 /*
289 * @implemented
290 */
291 BOOL WINAPI
292 GetLastInputInfo(PLASTINPUTINFO plii)
293 {
294 return NtUserGetLastInputInfo(plii);
295 }
296
297
298 /*
299 * @implemented
300 */
301 HKL WINAPI
302 LoadKeyboardLayoutA(LPCSTR pwszKLID,
303 UINT Flags)
304 {
305 return NtUserLoadKeyboardLayoutEx( NULL, 0, NULL, NULL, NULL,
306 strtoul(pwszKLID, NULL, 16),
307 Flags);
308 }
309
310
311 /*
312 * @implemented
313 */
314 HKL WINAPI
315 LoadKeyboardLayoutW(LPCWSTR pwszKLID,
316 UINT Flags)
317 {
318 // Look at revision 25596 to see how it's done in windows.
319 // We will do things our own way. Also be compatible too!
320 return NtUserLoadKeyboardLayoutEx( NULL, 0, NULL, NULL, NULL,
321 wcstoul(pwszKLID, NULL, 16),
322 Flags);
323 }
324
325
326 /*
327 * @implemented
328 */
329 UINT WINAPI
330 MapVirtualKeyA(UINT uCode,
331 UINT uMapType)
332 {
333 return MapVirtualKeyExA( uCode, uMapType, GetKeyboardLayout( 0 ) );
334 }
335
336
337 /*
338 * @implemented
339 */
340 UINT WINAPI
341 MapVirtualKeyExA(UINT uCode,
342 UINT uMapType,
343 HKL dwhkl)
344 {
345 return MapVirtualKeyExW( uCode, uMapType, dwhkl );
346 }
347
348
349 /*
350 * @implemented
351 */
352 UINT WINAPI
353 MapVirtualKeyExW(UINT uCode,
354 UINT uMapType,
355 HKL dwhkl)
356 {
357 return NtUserMapVirtualKeyEx( uCode, uMapType, 0, dwhkl );
358 }
359
360
361 /*
362 * @implemented
363 */
364 UINT WINAPI
365 MapVirtualKeyW(UINT uCode,
366 UINT uMapType)
367 {
368 return MapVirtualKeyExW( uCode, uMapType, GetKeyboardLayout( 0 ) );
369 }
370
371
372 /*
373 * @implemented
374 */
375 DWORD WINAPI
376 OemKeyScan(WORD wOemChar)
377 {
378 WCHAR p;
379 SHORT Vk;
380 UINT Scan;
381
382 MultiByteToWideChar(CP_OEMCP, 0, (PCSTR)&wOemChar, 1, &p, 1);
383 Vk = VkKeyScanW(p);
384 Scan = MapVirtualKeyW((Vk & 0x00ff), 0);
385 if(!Scan) return -1;
386 /*
387 Page 450-1, MS W2k SuperBible by SAMS. Return, low word has the
388 scan code and high word has the shift state.
389 */
390 return ((Vk & 0xff00) << 8) | Scan;
391 }
392
393
394 /*
395 * @implemented
396 */
397 BOOL WINAPI
398 RegisterHotKey(HWND hWnd,
399 int id,
400 UINT fsModifiers,
401 UINT vk)
402 {
403 return (BOOL)NtUserRegisterHotKey(hWnd,
404 id,
405 fsModifiers,
406 vk);
407 }
408
409
410 /*
411 * @implemented
412 */
413 BOOL WINAPI
414 SetDoubleClickTime(UINT uInterval)
415 {
416 return (BOOL)NtUserSystemParametersInfo(SPI_SETDOUBLECLICKTIME,
417 uInterval,
418 NULL,
419 0);
420 }
421
422
423 /*
424 * @implemented
425 */
426 HWND WINAPI
427 SetFocus(HWND hWnd)
428 {
429 return NtUserSetFocus(hWnd);
430 }
431
432
433 /*
434 * @implemented
435 */
436 BOOL WINAPI
437 SetKeyboardState(LPBYTE lpKeyState)
438 {
439 return (BOOL) NtUserSetKeyboardState((LPBYTE)lpKeyState);
440 }
441
442
443 /*
444 * @implemented
445 */
446 BOOL
447 WINAPI
448 SwapMouseButton(
449 BOOL fSwap)
450 {
451 return NtUserSwapMouseButton(fSwap);
452 }
453
454
455 /*
456 * @implemented
457 */
458 int WINAPI
459 ToAscii(UINT uVirtKey,
460 UINT uScanCode,
461 CONST PBYTE lpKeyState,
462 LPWORD lpChar,
463 UINT uFlags)
464 {
465 return ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, 0);
466 }
467
468
469 /*
470 * @implemented
471 */
472 int WINAPI
473 ToAsciiEx(UINT uVirtKey,
474 UINT uScanCode,
475 CONST PBYTE lpKeyState,
476 LPWORD lpChar,
477 UINT uFlags,
478 HKL dwhkl)
479 {
480 WCHAR UniChars[2];
481 int Ret, CharCount;
482
483 Ret = ToUnicodeEx(uVirtKey, uScanCode, lpKeyState, UniChars, 2, uFlags, dwhkl);
484 CharCount = (Ret < 0 ? 1 : Ret);
485 WideCharToMultiByte(CP_ACP, 0, UniChars, CharCount, (LPSTR) lpChar, 2, NULL, NULL);
486
487 return Ret;
488 }
489
490
491 /*
492 * @implemented
493 */
494 int WINAPI
495 ToUnicode(UINT wVirtKey,
496 UINT wScanCode,
497 CONST PBYTE lpKeyState,
498 LPWSTR pwszBuff,
499 int cchBuff,
500 UINT wFlags)
501 {
502 return ToUnicodeEx( wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff,
503 wFlags, 0 );
504 }
505
506
507 /*
508 * @implemented
509 */
510 int WINAPI
511 ToUnicodeEx(UINT wVirtKey,
512 UINT wScanCode,
513 CONST PBYTE lpKeyState,
514 LPWSTR pwszBuff,
515 int cchBuff,
516 UINT wFlags,
517 HKL dwhkl)
518 {
519 return NtUserToUnicodeEx( wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff,
520 wFlags, dwhkl );
521 }
522
523
524
525 /*
526 * @implemented
527 */
528 SHORT WINAPI
529 VkKeyScanA(CHAR ch)
530 {
531 WCHAR wChar;
532
533 if (IsDBCSLeadByte(ch)) return -1;
534
535 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wChar, 1);
536 return VkKeyScanW(wChar);
537 }
538
539
540 /*
541 * @implemented
542 */
543 SHORT WINAPI
544 VkKeyScanExA(CHAR ch,
545 HKL dwhkl)
546 {
547 WCHAR wChar;
548
549 if (IsDBCSLeadByte(ch)) return -1;
550
551 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wChar, 1);
552 return VkKeyScanExW(wChar, dwhkl);
553 }
554
555
556 /*
557 * @implemented
558 */
559 SHORT WINAPI
560 VkKeyScanExW(WCHAR ch,
561 HKL dwhkl)
562 {
563 return (SHORT) NtUserVkKeyScanEx(ch, dwhkl, 0);
564 }
565
566
567 /*
568 * @implemented
569 */
570 SHORT WINAPI
571 VkKeyScanW(WCHAR ch)
572 {
573 return VkKeyScanExW(ch, GetKeyboardLayout(0));
574 }
575
576
577 /*
578 * @implemented
579 */
580 UINT
581 WINAPI
582 SendInput(
583 UINT nInputs,
584 LPINPUT pInputs,
585 int cbSize)
586 {
587 return NtUserSendInput(nInputs, pInputs, cbSize);
588 }
589
590
591 /*
592 * @implemented
593 */
594 VOID
595 WINAPI
596 keybd_event(
597 BYTE bVk,
598 BYTE bScan,
599 DWORD dwFlags,
600 ULONG_PTR dwExtraInfo)
601
602
603 {
604 INPUT Input;
605
606 Input.type = INPUT_KEYBOARD;
607 Input.ki.wVk = bVk;
608 Input.ki.wScan = bScan;
609 Input.ki.dwFlags = dwFlags;
610 Input.ki.time = 0;
611 Input.ki.dwExtraInfo = dwExtraInfo;
612
613 NtUserSendInput(1, &Input, sizeof(INPUT));
614 }
615
616
617 /*
618 * @implemented
619 */
620 VOID
621 WINAPI
622 mouse_event(
623 DWORD dwFlags,
624 DWORD dx,
625 DWORD dy,
626 DWORD dwData,
627 ULONG_PTR dwExtraInfo)
628 {
629 INPUT Input;
630
631 Input.type = INPUT_MOUSE;
632 Input.mi.dx = dx;
633 Input.mi.dy = dy;
634 Input.mi.mouseData = dwData;
635 Input.mi.dwFlags = dwFlags;
636 Input.mi.time = 0;
637 Input.mi.dwExtraInfo = dwExtraInfo;
638
639 NtUserSendInput(1, &Input, sizeof(INPUT));
640 }
641
642
643 /***********************************************************************
644 * get_key_state
645 */
646 static WORD get_key_state(void)
647 {
648 WORD ret = 0;
649
650 if (GetSystemMetrics( SM_SWAPBUTTON ))
651 {
652 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_LBUTTON;
653 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_RBUTTON;
654 }
655 else
656 {
657 if (GetAsyncKeyState(VK_LBUTTON) & 0x80) ret |= MK_LBUTTON;
658 if (GetAsyncKeyState(VK_RBUTTON) & 0x80) ret |= MK_RBUTTON;
659 }
660 if (GetAsyncKeyState(VK_MBUTTON) & 0x80) ret |= MK_MBUTTON;
661 if (GetAsyncKeyState(VK_SHIFT) & 0x80) ret |= MK_SHIFT;
662 if (GetAsyncKeyState(VK_CONTROL) & 0x80) ret |= MK_CONTROL;
663 if (GetAsyncKeyState(VK_XBUTTON1) & 0x80) ret |= MK_XBUTTON1;
664 if (GetAsyncKeyState(VK_XBUTTON2) & 0x80) ret |= MK_XBUTTON2;
665 return ret;
666 }
667
668 static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR idEvent,
669 DWORD dwTime)
670 {
671 POINT pos;
672 POINT posClient;
673 HWND hwnd;
674 INT hoverwidth = 0, hoverheight = 0;
675 RECT client;
676 PUSER32_TRACKINGLIST ptracking_info;
677
678 ptracking_info = & User32GetThreadData()->tracking_info;
679
680 GetCursorPos(&pos);
681 hwnd = WindowFromPoint(pos);
682
683 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
684 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
685
686 /* see if this tracking event is looking for TME_LEAVE and that the */
687 /* mouse has left the window */
688 if (ptracking_info->tme.dwFlags & TME_LEAVE)
689 {
690 if (ptracking_info->tme.hwndTrack != hwnd)
691 {
692 if (ptracking_info->tme.dwFlags & TME_NONCLIENT)
693 {
694 PostMessageW(ptracking_info->tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
695 }
696 else
697 {
698 PostMessageW(ptracking_info->tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
699 }
700
701 /* remove the TME_LEAVE flag */
702 ptracking_info->tme.dwFlags &= ~TME_LEAVE;
703 }
704 else
705 {
706 GetClientRect(hwnd, &client);
707 MapWindowPoints(hwnd, NULL, (LPPOINT)&client, 2);
708 if (PtInRect(&client, pos))
709 {
710 if (ptracking_info->tme.dwFlags & TME_NONCLIENT)
711 {
712 PostMessageW(ptracking_info->tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
713 /* remove the TME_LEAVE flag */
714 ptracking_info->tme.dwFlags &= ~TME_LEAVE;
715 }
716 }
717 else
718 {
719 if (!(ptracking_info->tme.dwFlags & TME_NONCLIENT))
720 {
721 PostMessageW(ptracking_info->tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
722 /* remove the TME_LEAVE flag */
723 ptracking_info->tme.dwFlags &= ~TME_LEAVE;
724 }
725 }
726 }
727 }
728
729 /* see if we are tracking hovering for this hwnd */
730 if (ptracking_info->tme.dwFlags & TME_HOVER)
731 {
732 /* has the cursor moved outside the rectangle centered around pos? */
733 if ((abs(pos.x - ptracking_info->pos.x) > (hoverwidth / 2.0)) ||
734 (abs(pos.y - ptracking_info->pos.y) > (hoverheight / 2.0)))
735 {
736 /* record this new position as the current position and reset */
737 /* the iHoverTime variable to 0 */
738 ptracking_info->pos = pos;
739 }
740 else
741 {
742 posClient.x = pos.x;
743 posClient.y = pos.y;
744 ScreenToClient(hwnd, &posClient);
745
746 if (ptracking_info->tme.dwFlags & TME_NONCLIENT)
747 {
748 PostMessageW(ptracking_info->tme.hwndTrack, WM_NCMOUSEHOVER,
749 get_key_state(), MAKELPARAM( posClient.x, posClient.y ));
750 }
751 else
752 {
753 PostMessageW(ptracking_info->tme.hwndTrack, WM_MOUSEHOVER,
754 get_key_state(), MAKELPARAM( posClient.x, posClient.y ));
755 }
756
757 /* stop tracking mouse hover */
758 ptracking_info->tme.dwFlags &= ~TME_HOVER;
759 }
760 }
761
762 /* stop the timer if the tracking list is empty */
763 if (!(ptracking_info->tme.dwFlags & (TME_HOVER | TME_LEAVE)))
764 {
765 KillTimer(0, ptracking_info->timer);
766 RtlZeroMemory(ptracking_info,sizeof(USER32_TRACKINGLIST));
767 }
768 }
769
770
771 /***********************************************************************
772 * TrackMouseEvent [USER32]
773 *
774 * Requests notification of mouse events
775 *
776 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
777 * to the hwnd specified in the ptme structure. After the event message
778 * is posted to the hwnd, the entry in the queue is removed.
779 *
780 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
781 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
782 * immediately and the TME_LEAVE flag being ignored.
783 *
784 * PARAMS
785 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
786 *
787 * RETURNS
788 * Success: non-zero
789 * Failure: zero
790 *
791 */
792 /*
793 * @implemented
794 */
795 BOOL
796 WINAPI
797 TrackMouseEvent(
798 LPTRACKMOUSEEVENT ptme)
799 {
800 HWND hwnd;
801 POINT pos;
802 DWORD hover_time;
803 PUSER32_TRACKINGLIST ptracking_info;
804
805 TRACE("%lx, %lx, %p, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
806
807 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
808 WARN("wrong TRACKMOUSEEVENT size from app\n");
809 SetLastError(ERROR_INVALID_PARAMETER);
810 return FALSE;
811 }
812
813 ptracking_info = & User32GetThreadData()->tracking_info;
814
815 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
816 if (ptme->dwFlags & TME_QUERY )
817 {
818 *ptme = ptracking_info->tme;
819 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
820
821 return TRUE; /* return here, TME_QUERY is retrieving information */
822 }
823
824 if (!IsWindow(ptme->hwndTrack))
825 {
826 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
827 return FALSE;
828 }
829
830 hover_time = ptme->dwHoverTime;
831
832 /* if HOVER_DEFAULT was specified replace this with the systems current value */
833 if (hover_time == HOVER_DEFAULT || hover_time == 0)
834 {
835 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
836 }
837
838 GetCursorPos(&pos);
839 hwnd = WindowFromPoint(pos);
840
841 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
842 {
843 FIXME("Unknown flag(s) %08lx\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
844 }
845
846 if (ptme->dwFlags & TME_CANCEL)
847 {
848 if (ptracking_info->tme.hwndTrack == ptme->hwndTrack)
849 {
850 ptracking_info->tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
851
852 /* if we aren't tracking on hover or leave remove this entry */
853 if (!(ptracking_info->tme.dwFlags & (TME_HOVER | TME_LEAVE)))
854 {
855 KillTimer(0, ptracking_info->timer);
856 RtlZeroMemory(ptracking_info,sizeof(USER32_TRACKINGLIST));
857 }
858 }
859 } else {
860 if (ptme->hwndTrack == hwnd)
861 {
862 /* Adding new mouse event to the tracking list */
863 ptracking_info->tme = *ptme;
864 ptracking_info->tme.dwHoverTime = hover_time;
865
866 /* Initialize HoverInfo variables even if not hover tracking */
867 ptracking_info->pos = pos;
868
869 if (!ptracking_info->timer)
870 {
871 ptracking_info->timer = SetTimer(0, 0, hover_time, TrackMouseEventProc);
872 }
873 }
874 }
875
876 return TRUE;
877
878 }
879
880 /* EOF */