push 3cf4bc9cdb38c4fc36232fe19b9b904fd4d068e9
[wine/hacks.git] / dlls / user32 / input.c
blob625ecdcbae67d0499c2a073eb5b11ed2c83aa7ef
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 * set_capture_window
82 BOOL set_capture_window( HWND hwnd, UINT gui_flags, HWND *prev_ret )
84 HWND previous = 0;
85 UINT flags = 0;
86 BOOL ret;
88 if (gui_flags & GUI_INMENUMODE) flags |= CAPTURE_MENU;
89 if (gui_flags & GUI_INMOVESIZE) flags |= CAPTURE_MOVESIZE;
91 SERVER_START_REQ( set_capture_window )
93 req->handle = wine_server_user_handle( hwnd );
94 req->flags = flags;
95 if ((ret = !wine_server_call_err( req )))
97 previous = wine_server_ptr_handle( reply->previous );
98 hwnd = wine_server_ptr_handle( reply->full_handle );
101 SERVER_END_REQ;
103 USER_Driver->pSetCapture( hwnd, gui_flags );
105 if (previous && previous != hwnd)
106 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
108 if (prev_ret) *prev_ret = previous;
109 return ret;
113 /***********************************************************************
114 * SendInput (USER32.@)
116 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
118 if (TRACE_ON(win))
120 UINT i;
122 for (i = 0; i < count; i++)
124 switch(inputs[i].type)
126 case INPUT_MOUSE:
127 TRACE("mouse: dx %d, dy %d, data %x, flags %x, time %u, info %lx\n",
128 inputs[i].u.mi.dx, inputs[i].u.mi.dy, inputs[i].u.mi.mouseData,
129 inputs[i].u.mi.dwFlags, inputs[i].u.mi.time, inputs[i].u.mi.dwExtraInfo);
130 break;
132 case INPUT_KEYBOARD:
133 TRACE("keyboard: vk %x, scan %x, flags %x, time %u, info %lx\n",
134 inputs[i].u.ki.wVk, inputs[i].u.ki.wScan, inputs[i].u.ki.dwFlags,
135 inputs[i].u.ki.time, inputs[i].u.ki.dwExtraInfo);
136 break;
138 case INPUT_HARDWARE:
139 TRACE("hardware: msg %d, wParamL %x, wParamH %x\n",
140 inputs[i].u.hi.uMsg, inputs[i].u.hi.wParamL, inputs[i].u.hi.wParamH);
141 break;
143 default:
144 FIXME("unknown input type %u\n", inputs[i].type);
145 break;
150 return USER_Driver->pSendInput( count, inputs, size );
154 /***********************************************************************
155 * keybd_event (USER32.@)
157 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
158 DWORD dwFlags, ULONG_PTR dwExtraInfo )
160 INPUT input;
162 input.type = INPUT_KEYBOARD;
163 input.u.ki.wVk = bVk;
164 input.u.ki.wScan = bScan;
165 input.u.ki.dwFlags = dwFlags;
166 input.u.ki.time = GetTickCount();
167 input.u.ki.dwExtraInfo = dwExtraInfo;
168 SendInput( 1, &input, sizeof(input) );
172 /***********************************************************************
173 * mouse_event (USER32.@)
175 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
176 DWORD dwData, ULONG_PTR dwExtraInfo )
178 INPUT input;
180 input.type = INPUT_MOUSE;
181 input.u.mi.dx = dx;
182 input.u.mi.dy = dy;
183 input.u.mi.mouseData = dwData;
184 input.u.mi.dwFlags = dwFlags;
185 input.u.mi.time = GetCurrentTime();
186 input.u.mi.dwExtraInfo = dwExtraInfo;
187 SendInput( 1, &input, sizeof(input) );
191 /***********************************************************************
192 * GetCursorPos (USER32.@)
194 BOOL WINAPI GetCursorPos( POINT *pt )
196 if (!pt) return FALSE;
197 return USER_Driver->pGetCursorPos( pt );
201 /***********************************************************************
202 * GetCursorInfo (USER32.@)
204 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
206 if (!pci) return 0;
207 if (get_user_thread_info()->cursor_count >= 0) pci->flags = CURSOR_SHOWING;
208 else pci->flags = 0;
209 GetCursorPos(&pci->ptScreenPos);
210 return 1;
214 /***********************************************************************
215 * SetCursorPos (USER32.@)
217 BOOL WINAPI SetCursorPos( INT x, INT y )
219 return USER_Driver->pSetCursorPos( x, y );
223 /**********************************************************************
224 * SetCapture (USER32.@)
226 HWND WINAPI SetCapture( HWND hwnd )
228 HWND previous;
230 set_capture_window( hwnd, 0, &previous );
231 return previous;
235 /**********************************************************************
236 * ReleaseCapture (USER32.@)
238 BOOL WINAPI ReleaseCapture(void)
240 BOOL ret = set_capture_window( 0, 0, NULL );
242 /* Somebody may have missed some mouse movements */
243 mouse_event( MOUSEEVENTF_MOVE, 0, 0, 0, 0 );
245 return ret;
249 /**********************************************************************
250 * GetCapture (USER32.@)
252 HWND WINAPI GetCapture(void)
254 HWND ret = 0;
256 SERVER_START_REQ( get_thread_input )
258 req->tid = GetCurrentThreadId();
259 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->capture );
261 SERVER_END_REQ;
262 return ret;
266 /**********************************************************************
267 * GetAsyncKeyState (USER32.@)
269 * Determine if a key is or was pressed. retval has high-order
270 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
271 * been pressed.
273 SHORT WINAPI GetAsyncKeyState(INT nKey)
275 if (nKey < 0 || nKey > 256)
276 return 0;
277 return USER_Driver->pGetAsyncKeyState( nKey );
281 /***********************************************************************
282 * GetQueueStatus (USER32.@)
284 DWORD WINAPI GetQueueStatus( UINT flags )
286 DWORD ret = 0;
288 if (flags & ~(QS_ALLINPUT | QS_ALLPOSTMESSAGE | QS_SMRESULT))
290 SetLastError( ERROR_INVALID_FLAGS );
291 return 0;
294 /* check for pending X events */
295 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, flags, 0 );
297 SERVER_START_REQ( get_queue_status )
299 req->clear = 1;
300 wine_server_call( req );
301 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
303 SERVER_END_REQ;
304 return ret;
308 /***********************************************************************
309 * GetInputState (USER32.@)
311 BOOL WINAPI GetInputState(void)
313 DWORD ret = 0;
315 /* check for pending X events */
316 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_INPUT, 0 );
318 SERVER_START_REQ( get_queue_status )
320 req->clear = 0;
321 wine_server_call( req );
322 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
324 SERVER_END_REQ;
325 return ret;
329 /******************************************************************
330 * GetLastInputInfo (USER32.@)
332 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
334 BOOL ret;
336 TRACE("%p\n", plii);
338 if (plii->cbSize != sizeof (*plii) )
340 SetLastError(ERROR_INVALID_PARAMETER);
341 return FALSE;
344 SERVER_START_REQ( get_last_input_time )
346 ret = !wine_server_call_err( req );
347 if (ret)
348 plii->dwTime = reply->time;
350 SERVER_END_REQ;
351 return ret;
355 /******************************************************************
356 * GetRawInputDeviceList (USER32.@)
358 UINT WINAPI GetRawInputDeviceList(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize)
360 FIXME("(pRawInputDeviceList=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDeviceList, puiNumDevices, cbSize);
362 if(pRawInputDeviceList)
363 memset(pRawInputDeviceList, 0, sizeof *pRawInputDeviceList);
364 *puiNumDevices = 0;
365 return 0;
369 /******************************************************************
370 * RegisterRawInputDevices (USER32.@)
372 BOOL WINAPI RegisterRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize)
374 FIXME("(pRawInputDevices=%p, uiNumDevices=%d, cbSize=%d) stub!\n", pRawInputDevices, uiNumDevices, cbSize);
376 return TRUE;
380 /******************************************************************
381 * GetRawInputData (USER32.@)
383 UINT WINAPI GetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader)
385 FIXME("(hRawInput=%p, uiCommand=%d, pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n",
386 hRawInput, uiCommand, pData, pcbSize, cbSizeHeader);
388 return 0;
392 /******************************************************************
393 * GetRawInputBuffer (USER32.@)
395 UINT WINAPI GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader)
397 FIXME("(pData=%p, pcbSize=%p, cbSizeHeader=%d) stub!\n", pData, pcbSize, cbSizeHeader);
399 return 0;
403 /******************************************************************
404 * GetRawInputDeviceInfoA (USER32.@)
406 UINT WINAPI GetRawInputDeviceInfoA(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
408 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
410 return 0;
414 /******************************************************************
415 * GetRawInputDeviceInfoW (USER32.@)
417 UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize)
419 FIXME("(hDevice=%p, uiCommand=%d, pData=%p, pcbSize=%p) stub!\n", hDevice, uiCommand, pData, pcbSize);
421 return 0;
425 /******************************************************************
426 * GetRegisteredRawInputDevices (USER32.@)
428 UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize)
430 FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize);
432 return 0;
436 /******************************************************************
437 * DefRawInputProc (USER32.@)
439 LRESULT WINAPI DefRawInputProc(PRAWINPUT *paRawInput, INT nInput, UINT cbSizeHeader)
441 FIXME("(paRawInput=%p, nInput=%d, cbSizeHeader=%d) stub!\n", *paRawInput, nInput, cbSizeHeader);
443 return 0;
447 /**********************************************************************
448 * AttachThreadInput (USER32.@)
450 * Attaches the input processing mechanism of one thread to that of
451 * another thread.
453 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
455 BOOL ret;
457 SERVER_START_REQ( attach_thread_input )
459 req->tid_from = from;
460 req->tid_to = to;
461 req->attach = attach;
462 ret = !wine_server_call_err( req );
464 SERVER_END_REQ;
465 return ret;
469 /**********************************************************************
470 * GetKeyState (USER32.@)
472 * An application calls the GetKeyState function in response to a
473 * keyboard-input message. This function retrieves the state of the key
474 * at the time the input message was generated.
476 SHORT WINAPI GetKeyState(INT vkey)
478 SHORT retval = 0;
480 SERVER_START_REQ( get_key_state )
482 req->tid = GetCurrentThreadId();
483 req->key = vkey;
484 if (!wine_server_call( req )) retval = (signed char)reply->state;
486 SERVER_END_REQ;
487 TRACE("key (0x%x) -> %x\n", vkey, retval);
488 return retval;
492 /**********************************************************************
493 * GetKeyboardState (USER32.@)
495 BOOL WINAPI GetKeyboardState( LPBYTE state )
497 BOOL ret;
499 TRACE("(%p)\n", state);
501 memset( state, 0, 256 );
502 SERVER_START_REQ( get_key_state )
504 req->tid = GetCurrentThreadId();
505 req->key = -1;
506 wine_server_set_reply( req, state, 256 );
507 ret = !wine_server_call_err( req );
509 SERVER_END_REQ;
510 return ret;
514 /**********************************************************************
515 * SetKeyboardState (USER32.@)
517 BOOL WINAPI SetKeyboardState( LPBYTE state )
519 BOOL ret;
521 SERVER_START_REQ( set_key_state )
523 req->tid = GetCurrentThreadId();
524 wine_server_add_data( req, state, 256 );
525 ret = !wine_server_call_err( req );
527 SERVER_END_REQ;
528 return ret;
532 /**********************************************************************
533 * VkKeyScanA (USER32.@)
535 * VkKeyScan translates an ANSI character to a virtual-key and shift code
536 * for the current keyboard.
537 * high-order byte yields :
538 * 0 Unshifted
539 * 1 Shift
540 * 2 Ctrl
541 * 3-5 Shift-key combinations that are not used for characters
542 * 6 Ctrl-Alt
543 * 7 Ctrl-Alt-Shift
544 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
545 * FIXME : works ok except for dead chars :
546 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
547 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
549 SHORT WINAPI VkKeyScanA(CHAR cChar)
551 WCHAR wChar;
553 if (IsDBCSLeadByte(cChar)) return -1;
555 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
556 return VkKeyScanW(wChar);
559 /******************************************************************************
560 * VkKeyScanW (USER32.@)
562 SHORT WINAPI VkKeyScanW(WCHAR cChar)
564 return VkKeyScanExW(cChar, GetKeyboardLayout(0));
567 /**********************************************************************
568 * VkKeyScanExA (USER32.@)
570 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
572 WCHAR wChar;
574 if (IsDBCSLeadByte(cChar)) return -1;
576 MultiByteToWideChar(CP_ACP, 0, &cChar, 1, &wChar, 1);
577 return VkKeyScanExW(wChar, dwhkl);
580 /******************************************************************************
581 * VkKeyScanExW (USER32.@)
583 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
585 return USER_Driver->pVkKeyScanEx(cChar, dwhkl);
588 /**********************************************************************
589 * OemKeyScan (USER32.@)
591 DWORD WINAPI OemKeyScan(WORD wOemChar)
593 return wOemChar;
596 /******************************************************************************
597 * GetKeyboardType (USER32.@)
599 INT WINAPI GetKeyboardType(INT nTypeFlag)
601 TRACE_(keyboard)("(%d)\n", nTypeFlag);
602 switch(nTypeFlag)
604 case 0: /* Keyboard type */
605 return 4; /* AT-101 */
606 case 1: /* Keyboard Subtype */
607 return 0; /* There are no defined subtypes */
608 case 2: /* Number of F-keys */
609 return 12; /* We're doing an 101 for now, so return 12 F-keys */
610 default:
611 WARN_(keyboard)("Unknown type\n");
612 return 0; /* The book says 0 here, so 0 */
616 /******************************************************************************
617 * MapVirtualKeyA (USER32.@)
619 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
621 return MapVirtualKeyExA( code, maptype, GetKeyboardLayout(0) );
624 /******************************************************************************
625 * MapVirtualKeyW (USER32.@)
627 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
629 return MapVirtualKeyExW(code, maptype, GetKeyboardLayout(0));
632 /******************************************************************************
633 * MapVirtualKeyExA (USER32.@)
635 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
637 UINT ret;
639 ret = MapVirtualKeyExW( code, maptype, hkl );
640 if (maptype == MAPVK_VK_TO_CHAR)
642 BYTE ch = 0;
643 WCHAR wch = ret;
645 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
646 ret = ch;
648 return ret;
651 /******************************************************************************
652 * MapVirtualKeyExW (USER32.@)
654 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
656 TRACE_(keyboard)("(%d, %d, %p)\n", code, maptype, hkl);
658 return USER_Driver->pMapVirtualKeyEx(code, maptype, hkl);
661 /****************************************************************************
662 * GetKBCodePage (USER32.@)
664 UINT WINAPI GetKBCodePage(void)
666 return GetOEMCP();
669 /***********************************************************************
670 * GetKeyboardLayout (USER32.@)
672 * - device handle for keyboard layout defaulted to
673 * the language id. This is the way Windows default works.
674 * - the thread identifier (dwLayout) is also ignored.
676 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
678 return USER_Driver->pGetKeyboardLayout(dwLayout);
681 /****************************************************************************
682 * GetKeyboardLayoutNameA (USER32.@)
684 BOOL WINAPI GetKeyboardLayoutNameA(LPSTR pszKLID)
686 WCHAR buf[KL_NAMELENGTH];
688 if (GetKeyboardLayoutNameW(buf))
689 return WideCharToMultiByte( CP_ACP, 0, buf, -1, pszKLID, KL_NAMELENGTH, NULL, NULL ) != 0;
690 return FALSE;
693 /****************************************************************************
694 * GetKeyboardLayoutNameW (USER32.@)
696 BOOL WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
698 return USER_Driver->pGetKeyboardLayoutName(pwszKLID);
701 /****************************************************************************
702 * GetKeyNameTextA (USER32.@)
704 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
706 WCHAR buf[256];
707 INT ret;
709 if (!GetKeyNameTextW(lParam, buf, 256))
711 lpBuffer[0] = 0;
712 return 0;
714 ret = WideCharToMultiByte(CP_ACP, 0, buf, -1, lpBuffer, nSize, NULL, NULL);
715 if (!ret && nSize)
717 ret = nSize - 1;
718 lpBuffer[ret] = 0;
720 return ret;
723 /****************************************************************************
724 * GetKeyNameTextW (USER32.@)
726 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
728 return USER_Driver->pGetKeyNameText( lParam, lpBuffer, nSize );
731 /****************************************************************************
732 * ToUnicode (USER32.@)
734 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
735 LPWSTR lpwStr, int size, UINT flags)
737 return ToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, GetKeyboardLayout(0));
740 /****************************************************************************
741 * ToUnicodeEx (USER32.@)
743 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
744 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
746 return USER_Driver->pToUnicodeEx(virtKey, scanCode, lpKeyState, lpwStr, size, flags, hkl);
749 /****************************************************************************
750 * ToAscii (USER32.@)
752 INT WINAPI ToAscii( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
753 LPWORD lpChar, UINT flags )
755 return ToAsciiEx(virtKey, scanCode, lpKeyState, lpChar, flags, GetKeyboardLayout(0));
758 /****************************************************************************
759 * ToAsciiEx (USER32.@)
761 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, const BYTE *lpKeyState,
762 LPWORD lpChar, UINT flags, HKL dwhkl )
764 WCHAR uni_chars[2];
765 INT ret, n_ret;
767 ret = ToUnicodeEx(virtKey, scanCode, lpKeyState, uni_chars, 2, flags, dwhkl);
768 if (ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
769 else n_ret = ret;
770 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
771 return ret;
774 /**********************************************************************
775 * ActivateKeyboardLayout (USER32.@)
777 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
779 TRACE_(keyboard)("(%p, %d)\n", hLayout, flags);
781 return USER_Driver->pActivateKeyboardLayout(hLayout, flags);
784 /**********************************************************************
785 * BlockInput (USER32.@)
787 BOOL WINAPI BlockInput(BOOL fBlockIt)
789 FIXME_(keyboard)("(%d): stub\n", fBlockIt);
790 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
792 return FALSE;
795 /***********************************************************************
796 * GetKeyboardLayoutList (USER32.@)
798 * Return number of values available if either input parm is
799 * 0, per MS documentation.
801 UINT WINAPI GetKeyboardLayoutList(INT nBuff, HKL *layouts)
803 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
805 return USER_Driver->pGetKeyboardLayoutList(nBuff, layouts);
809 /***********************************************************************
810 * RegisterHotKey (USER32.@)
812 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk)
814 static int once;
815 if (!once++) FIXME_(keyboard)("(%p,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
816 return TRUE;
819 /***********************************************************************
820 * UnregisterHotKey (USER32.@)
822 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id)
824 static int once;
825 if (!once++) FIXME_(keyboard)("(%p,%d): stub\n",hwnd,id);
826 return TRUE;
829 /***********************************************************************
830 * LoadKeyboardLayoutW (USER32.@)
832 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
834 TRACE_(keyboard)("(%s, %d)\n", debugstr_w(pwszKLID), Flags);
836 return USER_Driver->pLoadKeyboardLayout(pwszKLID, Flags);
839 /***********************************************************************
840 * LoadKeyboardLayoutA (USER32.@)
842 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
844 HKL ret;
845 UNICODE_STRING pwszKLIDW;
847 if (pwszKLID) RtlCreateUnicodeStringFromAsciiz(&pwszKLIDW, pwszKLID);
848 else pwszKLIDW.Buffer = NULL;
850 ret = LoadKeyboardLayoutW(pwszKLIDW.Buffer, Flags);
851 RtlFreeUnicodeString(&pwszKLIDW);
852 return ret;
856 /***********************************************************************
857 * UnloadKeyboardLayout (USER32.@)
859 BOOL WINAPI UnloadKeyboardLayout(HKL hkl)
861 TRACE_(keyboard)("(%p)\n", hkl);
863 return USER_Driver->pUnloadKeyboardLayout(hkl);
866 typedef struct __TRACKINGLIST {
867 TRACKMOUSEEVENT tme;
868 POINT pos; /* center of hover rectangle */
869 } _TRACKINGLIST;
871 /* FIXME: move tracking stuff into a per thread data */
872 static _TRACKINGLIST tracking_info;
873 static UINT_PTR timer;
875 static void check_mouse_leave(HWND hwnd, int hittest)
877 if (tracking_info.tme.hwndTrack != hwnd)
879 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
880 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
881 else
882 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
884 /* remove the TME_LEAVE flag */
885 tracking_info.tme.dwFlags &= ~TME_LEAVE;
887 else
889 if (hittest == HTCLIENT)
891 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
893 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSELEAVE, 0, 0);
894 /* remove the TME_LEAVE flag */
895 tracking_info.tme.dwFlags &= ~TME_LEAVE;
898 else
900 if (!(tracking_info.tme.dwFlags & TME_NONCLIENT))
902 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
903 /* remove the TME_LEAVE flag */
904 tracking_info.tme.dwFlags &= ~TME_LEAVE;
910 static void CALLBACK TrackMouseEventProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent,
911 DWORD dwTime)
913 POINT pos;
914 INT hoverwidth = 0, hoverheight = 0, hittest;
916 TRACE("hwnd %p, msg %04x, id %04lx, time %u\n", hwnd, uMsg, idEvent, dwTime);
918 GetCursorPos(&pos);
919 hwnd = WINPOS_WindowFromPoint(hwnd, pos, &hittest);
921 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
923 SystemParametersInfoW(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
924 SystemParametersInfoW(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
926 TRACE("tracked pos %s, current pos %s, hover width %d, hover height %d\n",
927 wine_dbgstr_point(&tracking_info.pos), wine_dbgstr_point(&pos),
928 hoverwidth, hoverheight);
930 /* see if this tracking event is looking for TME_LEAVE and that the */
931 /* mouse has left the window */
932 if (tracking_info.tme.dwFlags & TME_LEAVE)
934 check_mouse_leave(hwnd, hittest);
937 if (tracking_info.tme.hwndTrack != hwnd)
939 /* mouse is gone, stop tracking mouse hover */
940 tracking_info.tme.dwFlags &= ~TME_HOVER;
943 /* see if we are tracking hovering for this hwnd */
944 if (tracking_info.tme.dwFlags & TME_HOVER)
946 /* has the cursor moved outside the rectangle centered around pos? */
947 if ((abs(pos.x - tracking_info.pos.x) > (hoverwidth / 2)) ||
948 (abs(pos.y - tracking_info.pos.y) > (hoverheight / 2)))
950 /* record this new position as the current position */
951 tracking_info.pos = pos;
953 else
955 if (hittest == HTCLIENT)
957 ScreenToClient(hwnd, &pos);
958 TRACE("client cursor pos %s\n", wine_dbgstr_point(&pos));
960 PostMessageW(tracking_info.tme.hwndTrack, WM_MOUSEHOVER,
961 get_key_state(), MAKELPARAM( pos.x, pos.y ));
963 else
965 if (tracking_info.tme.dwFlags & TME_NONCLIENT)
966 PostMessageW(tracking_info.tme.hwndTrack, WM_NCMOUSEHOVER,
967 hittest, MAKELPARAM( pos.x, pos.y ));
970 /* stop tracking mouse hover */
971 tracking_info.tme.dwFlags &= ~TME_HOVER;
975 /* stop the timer if the tracking list is empty */
976 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
978 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
979 timer = 0;
980 tracking_info.tme.hwndTrack = 0;
981 tracking_info.tme.dwFlags = 0;
982 tracking_info.tme.dwHoverTime = 0;
987 /***********************************************************************
988 * TrackMouseEvent [USER32]
990 * Requests notification of mouse events
992 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
993 * to the hwnd specified in the ptme structure. After the event message
994 * is posted to the hwnd, the entry in the queue is removed.
996 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
997 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
998 * immediately and the TME_LEAVE flag being ignored.
1000 * PARAMS
1001 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1003 * RETURNS
1004 * Success: non-zero
1005 * Failure: zero
1009 BOOL WINAPI
1010 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1012 HWND hwnd;
1013 POINT pos;
1014 DWORD hover_time;
1015 INT hittest;
1017 TRACE("%x, %x, %p, %u\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1019 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1020 WARN("wrong TRACKMOUSEEVENT size from app\n");
1021 SetLastError(ERROR_INVALID_PARAMETER);
1022 return FALSE;
1025 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1026 if (ptme->dwFlags & TME_QUERY )
1028 *ptme = tracking_info.tme;
1029 /* set cbSize in the case it's not initialized yet */
1030 ptme->cbSize = sizeof(TRACKMOUSEEVENT);
1032 return TRUE; /* return here, TME_QUERY is retrieving information */
1035 if (!IsWindow(ptme->hwndTrack))
1037 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1038 return FALSE;
1041 hover_time = ptme->dwHoverTime;
1043 /* if HOVER_DEFAULT was specified replace this with the systems current value.
1044 * TME_LEAVE doesn't need to specify hover time so use default */
1045 if (hover_time == HOVER_DEFAULT || hover_time == 0 || !(ptme->dwHoverTime&TME_HOVER))
1046 SystemParametersInfoW(SPI_GETMOUSEHOVERTIME, 0, &hover_time, 0);
1048 GetCursorPos(&pos);
1049 hwnd = WINPOS_WindowFromPoint(ptme->hwndTrack, pos, &hittest);
1050 TRACE("point %s hwnd %p hittest %d\n", wine_dbgstr_point(&pos), hwnd, hittest);
1052 if (ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT))
1053 FIXME("Unknown flag(s) %08x\n", ptme->dwFlags & ~(TME_CANCEL | TME_HOVER | TME_LEAVE | TME_NONCLIENT));
1055 if (ptme->dwFlags & TME_CANCEL)
1057 if (tracking_info.tme.hwndTrack == ptme->hwndTrack)
1059 tracking_info.tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1061 /* if we aren't tracking on hover or leave remove this entry */
1062 if (!(tracking_info.tme.dwFlags & (TME_HOVER | TME_LEAVE)))
1064 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1065 timer = 0;
1066 tracking_info.tme.hwndTrack = 0;
1067 tracking_info.tme.dwFlags = 0;
1068 tracking_info.tme.dwHoverTime = 0;
1071 } else {
1072 /* In our implementation it's possible that another window will receive a
1073 * WM_MOUSEMOVE and call TrackMouseEvent before TrackMouseEventProc is
1074 * called. In such a situation post the WM_MOUSELEAVE now */
1075 if (tracking_info.tme.dwFlags & TME_LEAVE && tracking_info.tme.hwndTrack != NULL)
1076 check_mouse_leave(hwnd, hittest);
1078 if (timer)
1080 KillSystemTimer(tracking_info.tme.hwndTrack, timer);
1081 timer = 0;
1082 tracking_info.tme.hwndTrack = 0;
1083 tracking_info.tme.dwFlags = 0;
1084 tracking_info.tme.dwHoverTime = 0;
1087 if (ptme->hwndTrack == hwnd)
1089 /* Adding new mouse event to the tracking list */
1090 tracking_info.tme = *ptme;
1091 tracking_info.tme.dwHoverTime = hover_time;
1093 /* Initialize HoverInfo variables even if not hover tracking */
1094 tracking_info.pos = pos;
1096 timer = SetSystemTimer(tracking_info.tme.hwndTrack, (UINT_PTR)&tracking_info.tme, hover_time, TrackMouseEventProc);
1100 return TRUE;
1103 /***********************************************************************
1104 * GetMouseMovePointsEx [USER32]
1106 * RETURNS
1107 * Success: count of point set in the buffer
1108 * Failure: -1
1110 int WINAPI GetMouseMovePointsEx(UINT size, LPMOUSEMOVEPOINT ptin, LPMOUSEMOVEPOINT ptout, int count, DWORD res) {
1112 if((size != sizeof(MOUSEMOVEPOINT)) || (count < 0) || (count > 64)) {
1113 SetLastError(ERROR_INVALID_PARAMETER);
1114 return -1;
1117 if(!ptin || !ptout) {
1118 SetLastError(ERROR_NOACCESS);
1119 return -1;
1122 FIXME("(%d %p %p %d %d) stub\n", size, ptin, ptout, count, res);
1124 SetLastError(ERROR_POINT_NOT_FOUND);
1125 return -1;