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
36 #include "wine/winbase16.h"
37 #include "wine/winuser16.h"
38 #include "wine/server.h"
43 #include "wine/debug.h"
46 WINE_DECLARE_DEBUG_CHANNEL(key);
47 WINE_DECLARE_DEBUG_CHANNEL(keyboard);
48 WINE_DECLARE_DEBUG_CHANNEL(win);
49 WINE_DEFAULT_DEBUG_CHANNEL(event);
51 static BOOL InputEnabled = TRUE;
52 static BOOL SwappedButtons;
54 BYTE InputKeyStateTable[256];
55 BYTE AsyncKeyStateTable[256];
57 /* Storage for the USER-maintained mouse positions */
58 static DWORD PosX, PosY;
64 unsigned long count : 16;
65 unsigned long code : 8;
66 unsigned long extended : 1;
67 unsigned long unused : 2;
68 unsigned long win_internal : 2;
69 unsigned long context : 1;
70 unsigned long previous : 1;
71 unsigned long transition : 1;
77 /***********************************************************************
80 static WORD get_key_state(void)
86 if (InputKeyStateTable[VK_RBUTTON] & 0x80) ret |= MK_LBUTTON;
87 if (InputKeyStateTable[VK_LBUTTON] & 0x80) ret |= MK_RBUTTON;
91 if (InputKeyStateTable[VK_LBUTTON] & 0x80) ret |= MK_LBUTTON;
92 if (InputKeyStateTable[VK_RBUTTON] & 0x80) ret |= MK_RBUTTON;
94 if (InputKeyStateTable[VK_MBUTTON] & 0x80) ret |= MK_MBUTTON;
95 if (InputKeyStateTable[VK_SHIFT] & 0x80) ret |= MK_SHIFT;
96 if (InputKeyStateTable[VK_CONTROL] & 0x80) ret |= MK_CONTROL;
97 if (InputKeyStateTable[VK_XBUTTON1] & 0x80) ret |= MK_XBUTTON1;
98 if (InputKeyStateTable[VK_XBUTTON2] & 0x80) ret |= MK_XBUTTON2;
103 /***********************************************************************
104 * queue_raw_hardware_message
106 * Add a message to the raw hardware queue.
107 * Note: the position is relative to the desktop window.
109 static void queue_raw_hardware_message( UINT message, WPARAM wParam, LPARAM lParam,
110 int xPos, int yPos, DWORD time, ULONG_PTR extraInfo )
112 SERVER_START_REQ( send_message )
114 req->id = GetCurrentThreadId();
115 req->type = MSG_HARDWARE_RAW;
118 req->wparam = wParam;
119 req->lparam = lParam;
123 req->info = extraInfo;
125 wine_server_call( req );
131 /***********************************************************************
134 * Put a keyboard event into a thread queue
136 static void queue_kbd_event( const KEYBDINPUT *ki, UINT injected_flags )
140 KBDLLHOOKSTRUCT hook;
144 keylp.lp1.code = ki->wScan;
145 keylp.lp1.extended = (ki->dwFlags & KEYEVENTF_EXTENDEDKEY) != 0;
146 keylp.lp1.win_internal = 0; /* this has something to do with dialogs,
147 * don't remember where I read it - AK */
148 /* it's '1' under windows, when a dialog box appears
149 * and you press one of the underlined keys - DF*/
151 if (ki->dwFlags & KEYEVENTF_KEYUP )
153 BOOL sysKey = (InputKeyStateTable[VK_MENU] & 0x80) &&
154 !(InputKeyStateTable[VK_CONTROL] & 0x80);
155 InputKeyStateTable[ki->wVk] &= ~0x80;
156 keylp.lp1.previous = 1;
157 keylp.lp1.transition = 1;
158 message = sysKey ? WM_SYSKEYUP : WM_KEYUP;
162 keylp.lp1.previous = (InputKeyStateTable[ki->wVk] & 0x80) != 0;
163 keylp.lp1.transition = 0;
164 if (!(InputKeyStateTable[ki->wVk] & 0x80)) InputKeyStateTable[ki->wVk] ^= 0x01;
165 InputKeyStateTable[ki->wVk] |= 0x80;
166 AsyncKeyStateTable[ki->wVk] |= 0x80;
168 message = (InputKeyStateTable[VK_MENU] & 0x80) && !(InputKeyStateTable[VK_CONTROL] & 0x80)
169 ? WM_SYSKEYDOWN : WM_KEYDOWN;
172 if (message == WM_SYSKEYDOWN || message == WM_SYSKEYUP )
173 keylp.lp1.context = (InputKeyStateTable[VK_MENU] & 0x80) != 0; /* 1 if alt */
175 TRACE_(key)(" wParam=%04x, lParam=%08lx, InputKeyState=%x\n",
176 ki->wVk, keylp.lp2, InputKeyStateTable[ki->wVk] );
178 hook.vkCode = ki->wVk;
179 hook.scanCode = ki->wScan;
180 hook.flags = (keylp.lp2 >> 24) | injected_flags;
181 hook.time = ki->time;
182 hook.dwExtraInfo = ki->dwExtraInfo;
183 if (!HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, message, (LPARAM)&hook, TRUE ))
184 queue_raw_hardware_message( message, ki->wVk, keylp.lp2,
185 PosX, PosY, ki->time, ki->dwExtraInfo );
189 /***********************************************************************
190 * queue_raw_mouse_message
192 static void queue_raw_mouse_message( UINT message, UINT flags, INT x, INT y, const MOUSEINPUT *mi )
198 hook.mouseData = MAKELONG( 0, mi->mouseData );
200 hook.time = mi->time;
201 hook.dwExtraInfo = mi->dwExtraInfo;
203 if (!HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, message, (LPARAM)&hook, TRUE ))
204 queue_raw_hardware_message( message, MAKEWPARAM( get_key_state(), mi->mouseData ),
205 0, x, y, mi->time, mi->dwExtraInfo );
209 /***********************************************************************
212 static void queue_mouse_event( const MOUSEINPUT *mi, UINT flags )
214 if (mi->dwFlags & MOUSEEVENTF_ABSOLUTE)
216 PosX = (mi->dx * GetSystemMetrics(SM_CXSCREEN)) >> 16;
217 PosY = (mi->dy * GetSystemMetrics(SM_CYSCREEN)) >> 16;
219 else if (mi->dwFlags & MOUSEEVENTF_MOVE)
221 int width = GetSystemMetrics(SM_CXSCREEN);
222 int height = GetSystemMetrics(SM_CYSCREEN);
223 long posX = (long) PosX, posY = (long) PosY;
227 /* dx and dy can be negative numbers for relative movements */
228 SystemParametersInfoA(SPI_GETMOUSE, 0, accel, 0);
231 if (mi->dx > accel[0] && accel[2] != 0)
234 if ((mi->dx > accel[1]) && (accel[2] == 2))
239 posX += (long)mi->dx * accelMult;
242 if (mi->dy > accel[0] && accel[2] != 0)
245 if ((mi->dy > accel[1]) && (accel[2] == 2))
250 posY += (long)mi->dy * accelMult;
252 /* Clip to the current screen size */
253 if (posX < 0) PosX = 0;
254 else if (posX >= width) PosX = width - 1;
257 if (posY < 0) PosY = 0;
258 else if (posY >= height) PosY = height - 1;
262 if (mi->dwFlags & MOUSEEVENTF_MOVE)
264 queue_raw_mouse_message( WM_MOUSEMOVE, flags, PosX, PosY, mi );
266 if (mi->dwFlags & MOUSEEVENTF_LEFTDOWN)
268 InputKeyStateTable[VK_LBUTTON] |= 0x80;
269 AsyncKeyStateTable[VK_LBUTTON] |= 0x80;
270 queue_raw_mouse_message( SwappedButtons ? WM_RBUTTONDOWN : WM_LBUTTONDOWN,
271 flags, PosX, PosY, mi );
273 if (mi->dwFlags & MOUSEEVENTF_LEFTUP)
275 InputKeyStateTable[VK_LBUTTON] &= ~0x80;
276 queue_raw_mouse_message( SwappedButtons ? WM_RBUTTONUP : WM_LBUTTONUP,
277 flags, PosX, PosY, mi );
279 if (mi->dwFlags & MOUSEEVENTF_RIGHTDOWN)
281 InputKeyStateTable[VK_RBUTTON] |= 0x80;
282 AsyncKeyStateTable[VK_RBUTTON] |= 0x80;
283 queue_raw_mouse_message( SwappedButtons ? WM_LBUTTONDOWN : WM_RBUTTONDOWN,
284 flags, PosX, PosY, mi );
286 if (mi->dwFlags & MOUSEEVENTF_RIGHTUP)
288 InputKeyStateTable[VK_RBUTTON] &= ~0x80;
289 queue_raw_mouse_message( SwappedButtons ? WM_LBUTTONUP : WM_RBUTTONUP,
290 flags, PosX, PosY, mi );
292 if (mi->dwFlags & MOUSEEVENTF_MIDDLEDOWN)
294 InputKeyStateTable[VK_MBUTTON] |= 0x80;
295 AsyncKeyStateTable[VK_MBUTTON] |= 0x80;
296 queue_raw_mouse_message( WM_MBUTTONDOWN, flags, PosX, PosY, mi );
298 if (mi->dwFlags & MOUSEEVENTF_MIDDLEUP)
300 InputKeyStateTable[VK_MBUTTON] &= ~0x80;
301 queue_raw_mouse_message( WM_MBUTTONUP, flags, PosX, PosY, mi );
303 if (mi->dwFlags & MOUSEEVENTF_WHEEL)
305 queue_raw_mouse_message( WM_MOUSEWHEEL, flags, PosX, PosY, mi );
307 if (flags & LLMHF_INJECTED) /* we have to actually move the cursor */
308 SetCursorPos( PosX, PosY );
312 /***********************************************************************
313 * SendInput (USER32.@)
315 UINT WINAPI SendInput( UINT count, LPINPUT inputs, int size )
319 if (!InputEnabled) return 0;
321 for (i = 0; i < count; i++, inputs++)
326 queue_mouse_event( &inputs->u.mi, LLMHF_INJECTED );
328 case WINE_INTERNAL_INPUT_MOUSE:
329 queue_mouse_event( &inputs->u.mi, 0 );
332 queue_kbd_event( &inputs->u.ki, LLKHF_INJECTED );
334 case WINE_INTERNAL_INPUT_KEYBOARD:
335 queue_kbd_event( &inputs->u.ki, 0 );
338 FIXME( "INPUT_HARDWARE not supported\n" );
346 /***********************************************************************
347 * keybd_event (USER32.@)
349 void WINAPI keybd_event( BYTE bVk, BYTE bScan,
350 DWORD dwFlags, ULONG_PTR dwExtraInfo )
354 input.type = INPUT_KEYBOARD;
355 input.u.ki.wVk = bVk;
356 input.u.ki.wScan = bScan;
357 input.u.ki.dwFlags = dwFlags;
358 input.u.ki.time = GetTickCount();
359 input.u.ki.dwExtraInfo = dwExtraInfo;
360 SendInput( 1, &input, sizeof(input) );
364 /***********************************************************************
365 * keybd_event (USER.289)
367 void WINAPI keybd_event16( CONTEXT86 *context )
371 if (HIBYTE(context->Eax) & 0x80) dwFlags |= KEYEVENTF_KEYUP;
372 if (HIBYTE(context->Ebx) & 0x01) dwFlags |= KEYEVENTF_EXTENDEDKEY;
374 keybd_event( LOBYTE(context->Eax), LOBYTE(context->Ebx),
375 dwFlags, MAKELONG(LOWORD(context->Esi), LOWORD(context->Edi)) );
379 /***********************************************************************
380 * mouse_event (USER32.@)
382 void WINAPI mouse_event( DWORD dwFlags, DWORD dx, DWORD dy,
383 DWORD dwData, ULONG_PTR dwExtraInfo )
387 input.type = INPUT_MOUSE;
390 input.u.mi.mouseData = dwData;
391 input.u.mi.dwFlags = dwFlags;
392 input.u.mi.time = GetCurrentTime();
393 input.u.mi.dwExtraInfo = dwExtraInfo;
394 SendInput( 1, &input, sizeof(input) );
398 /***********************************************************************
399 * mouse_event (USER.299)
401 void WINAPI mouse_event16( CONTEXT86 *context )
403 mouse_event( LOWORD(context->Eax), LOWORD(context->Ebx), LOWORD(context->Ecx),
404 LOWORD(context->Edx), MAKELONG(context->Esi, context->Edi) );
407 /***********************************************************************
408 * GetMouseEventProc (USER.337)
410 FARPROC16 WINAPI GetMouseEventProc16(void)
412 HMODULE16 hmodule = GetModuleHandle16("USER");
413 return GetProcAddress16( hmodule, "mouse_event" );
417 /**********************************************************************
418 * EnableHardwareInput (USER.331)
420 BOOL16 WINAPI EnableHardwareInput16(BOOL16 bEnable)
422 BOOL16 bOldState = InputEnabled;
423 FIXME_(event)("(%d) - stub\n", bEnable);
424 InputEnabled = bEnable;
429 /***********************************************************************
430 * SwapMouseButton (USER.186)
432 BOOL16 WINAPI SwapMouseButton16( BOOL16 fSwap )
434 BOOL16 ret = SwappedButtons;
435 SwappedButtons = fSwap;
440 /***********************************************************************
441 * SwapMouseButton (USER32.@)
443 BOOL WINAPI SwapMouseButton( BOOL fSwap )
445 BOOL ret = SwappedButtons;
446 SwappedButtons = fSwap;
451 /***********************************************************************
452 * GetCursorPos (USER.17)
454 BOOL16 WINAPI GetCursorPos16( POINT16 *pt )
465 /***********************************************************************
466 * GetCursorPos (USER32.@)
468 BOOL WINAPI GetCursorPos( POINT *pt )
473 if (USER_Driver.pGetCursorPos) USER_Driver.pGetCursorPos( pt );
478 /***********************************************************************
479 * GetCursorInfo (USER32.@)
481 BOOL WINAPI GetCursorInfo( PCURSORINFO pci )
483 MESSAGEQUEUE *queue = QUEUE_Current();
486 if (queue->cursor_count >= 0) pci->flags = CURSOR_SHOWING;
488 GetCursorPos(&pci->ptScreenPos);
493 /***********************************************************************
494 * SetCursorPos (USER.70)
496 void WINAPI SetCursorPos16( INT16 x, INT16 y )
498 SetCursorPos( x, y );
502 /***********************************************************************
503 * SetCursorPos (USER32.@)
505 BOOL WINAPI SetCursorPos( INT x, INT y )
507 if (USER_Driver.pSetCursorPos) USER_Driver.pSetCursorPos( x, y );
514 /**********************************************************************
515 * SetCapture (USER32.@)
517 HWND WINAPI SetCapture( HWND hwnd )
521 SERVER_START_REQ( set_capture_window )
525 if (!wine_server_call_err( req ))
527 previous = reply->previous;
528 hwnd = reply->full_handle;
533 if (previous && previous != hwnd)
534 SendMessageW( previous, WM_CAPTURECHANGED, 0, (LPARAM)hwnd );
539 /**********************************************************************
540 * ReleaseCapture (USER32.@)
542 BOOL WINAPI ReleaseCapture(void)
544 return (SetCapture(0) != 0);
548 /**********************************************************************
549 * GetCapture (USER32.@)
551 HWND WINAPI GetCapture(void)
555 SERVER_START_REQ( get_thread_input )
557 req->tid = GetCurrentThreadId();
558 if (!wine_server_call_err( req )) ret = reply->capture;
565 /**********************************************************************
566 * GetAsyncKeyState (USER32.@)
568 * Determine if a key is or was pressed. retval has high-order
569 * bit set to 1 if currently pressed, low-order bit set to 1 if key has
572 * This uses the variable AsyncMouseButtonsStates and
573 * AsyncKeyStateTable (set in event.c) which have the mouse button
574 * number or key number (whichever is applicable) set to true if the
575 * mouse or key had been depressed since the last call to
578 SHORT WINAPI GetAsyncKeyState(INT nKey)
580 SHORT retval = ((AsyncKeyStateTable[nKey] & 0x80) ? 0x0001 : 0) |
581 ((InputKeyStateTable[nKey] & 0x80) ? 0x8000 : 0);
582 AsyncKeyStateTable[nKey] = 0;
583 TRACE_(key)("(%x) -> %x\n", nKey, retval);
587 /**********************************************************************
588 * GetAsyncKeyState (USER.249)
590 INT16 WINAPI GetAsyncKeyState16(INT16 nKey)
592 return GetAsyncKeyState(nKey);
595 /***********************************************************************
596 * IsUserIdle (USER.333)
598 BOOL16 WINAPI IsUserIdle16(void)
600 if ( GetAsyncKeyState( VK_LBUTTON ) & 0x8000 )
603 if ( GetAsyncKeyState( VK_RBUTTON ) & 0x8000 )
606 if ( GetAsyncKeyState( VK_MBUTTON ) & 0x8000 )
609 /* Should check for screen saver activation here ... */
614 /**********************************************************************
615 * VkKeyScanA (USER32.@)
617 * VkKeyScan translates an ANSI character to a virtual-key and shift code
618 * for the current keyboard.
619 * high-order byte yields :
623 * 3-5 Shift-key combinations that are not used for characters
626 * I.e. : Shift = 1, Ctrl = 2, Alt = 4.
627 * FIXME : works ok except for dead chars :
628 * VkKeyScan '^'(0x5e, 94) ... got keycode 00 ... returning 00
629 * VkKeyScan '`'(0x60, 96) ... got keycode 00 ... returning 00
631 WORD WINAPI VkKeyScanA(CHAR cChar)
633 return USER_Driver.pVkKeyScan( cChar );
636 /******************************************************************************
637 * VkKeyScanW (USER32.@)
639 WORD WINAPI VkKeyScanW(WCHAR cChar)
641 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
644 /**********************************************************************
645 * VkKeyScanExA (USER32.@)
647 WORD WINAPI VkKeyScanExA(CHAR cChar, HKL dwhkl)
649 /* FIXME: complete workaround this is */
650 return VkKeyScanA(cChar);
653 /******************************************************************************
654 * VkKeyScanExW (USER32.@)
656 WORD WINAPI VkKeyScanExW(WCHAR cChar, HKL dwhkl)
658 /* FIXME: complete workaround this is */
659 return VkKeyScanA((CHAR)cChar); /* FIXME: check unicode */
662 /******************************************************************************
663 * GetKeyboardType (USER32.@)
665 INT WINAPI GetKeyboardType(INT nTypeFlag)
667 TRACE_(keyboard)("(%d)\n", nTypeFlag);
670 case 0: /* Keyboard type */
671 return 4; /* AT-101 */
672 case 1: /* Keyboard Subtype */
673 return 0; /* There are no defined subtypes */
674 case 2: /* Number of F-keys */
675 return 12; /* We're doing an 101 for now, so return 12 F-keys */
677 WARN_(keyboard)("Unknown type\n");
678 return 0; /* The book says 0 here, so 0 */
682 /******************************************************************************
683 * MapVirtualKeyA (USER32.@)
685 UINT WINAPI MapVirtualKeyA(UINT code, UINT maptype)
687 return USER_Driver.pMapVirtualKey( code, maptype );
690 /******************************************************************************
691 * MapVirtualKeyW (USER32.@)
693 UINT WINAPI MapVirtualKeyW(UINT code, UINT maptype)
695 return MapVirtualKeyA(code,maptype);
698 /******************************************************************************
699 * MapVirtualKeyExA (USER32.@)
701 UINT WINAPI MapVirtualKeyExA(UINT code, UINT maptype, HKL hkl)
704 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
705 return MapVirtualKeyA(code,maptype);
708 /******************************************************************************
709 * MapVirtualKeyExW (USER32.@)
711 UINT WINAPI MapVirtualKeyExW(UINT code, UINT maptype, HKL hkl)
714 FIXME_(keyboard)("(%d,%d,0x%08lx), hkl unhandled!\n",code,maptype,(DWORD)hkl);
715 return MapVirtualKeyA(code,maptype);
718 /****************************************************************************
719 * GetKBCodePage (USER32.@)
721 UINT WINAPI GetKBCodePage(void)
726 /****************************************************************************
727 * GetKeyboardLayoutName (USER.477)
729 INT16 WINAPI GetKeyboardLayoutName16(LPSTR pwszKLID)
731 return GetKeyboardLayoutNameA(pwszKLID);
734 /***********************************************************************
735 * GetKeyboardLayout (USER32.@)
737 * FIXME: - device handle for keyboard layout defaulted to
738 * the language id. This is the way Windows default works.
739 * - the thread identifier (dwLayout) is also ignored.
741 HKL WINAPI GetKeyboardLayout(DWORD dwLayout)
744 layout = GetSystemDefaultLCID(); /* FIXME */
745 layout |= (layout<<16); /* FIXME */
746 TRACE_(keyboard)("returning %08x\n",layout);
750 /****************************************************************************
751 * GetKeyboardLayoutNameA (USER32.@)
753 INT WINAPI GetKeyboardLayoutNameA(LPSTR pwszKLID)
755 sprintf(pwszKLID, "%08x",GetKeyboardLayout(0));
759 /****************************************************************************
760 * GetKeyboardLayoutNameW (USER32.@)
762 INT WINAPI GetKeyboardLayoutNameW(LPWSTR pwszKLID)
764 char buf[KL_NAMELENGTH];
765 int res = GetKeyboardLayoutNameA(buf);
766 MultiByteToWideChar( CP_ACP, 0, buf, -1, pwszKLID, KL_NAMELENGTH );
770 /****************************************************************************
771 * GetKeyNameTextA (USER32.@)
773 INT WINAPI GetKeyNameTextA(LONG lParam, LPSTR lpBuffer, INT nSize)
775 return USER_Driver.pGetKeyNameText( lParam, lpBuffer, nSize );
778 /****************************************************************************
779 * GetKeyNameTextW (USER32.@)
781 INT WINAPI GetKeyNameTextW(LONG lParam, LPWSTR lpBuffer, INT nSize)
784 LPSTR buf = HeapAlloc( GetProcessHeap(), 0, nSize );
785 if(buf == NULL) return 0; /* FIXME: is this the correct failure value?*/
786 res = GetKeyNameTextA(lParam,buf,nSize);
788 if (nSize > 0 && !MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nSize ))
789 lpBuffer[nSize-1] = 0;
790 HeapFree( GetProcessHeap(), 0, buf );
794 /****************************************************************************
795 * ToUnicode (USER32.@)
797 INT WINAPI ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
798 LPWSTR lpwStr, int size, UINT flags)
800 return USER_Driver.pToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
803 /****************************************************************************
804 * ToUnicodeEx (USER32.@)
806 INT WINAPI ToUnicodeEx(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
807 LPWSTR lpwStr, int size, UINT flags, HKL hkl)
809 /* FIXME: need true implementation */
810 return ToUnicode(virtKey, scanCode, lpKeyState, lpwStr, size, flags);
813 /****************************************************************************
816 INT WINAPI ToAscii( UINT virtKey,UINT scanCode,LPBYTE lpKeyState,
817 LPWORD lpChar,UINT flags )
822 ret = ToUnicode(virtKey, scanCode, lpKeyState, uni_chars, 2, flags);
823 if(ret < 0) n_ret = 1; /* FIXME: make ToUnicode return 2 for dead chars */
825 WideCharToMultiByte(CP_ACP, 0, uni_chars, n_ret, (LPSTR)lpChar, 2, NULL, NULL);
829 /****************************************************************************
830 * ToAsciiEx (USER32.@)
832 INT WINAPI ToAsciiEx( UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
833 LPWORD lpChar, UINT flags, HKL dwhkl )
835 /* FIXME: need true implementation */
836 return ToAscii(virtKey, scanCode, lpKeyState, lpChar, flags);
839 /**********************************************************************
840 * ActivateKeyboardLayout (USER32.@)
842 * Call ignored. WINE supports only system default keyboard layout.
844 HKL WINAPI ActivateKeyboardLayout(HKL hLayout, UINT flags)
846 TRACE_(keyboard)("(%d, %d)\n", hLayout, flags);
847 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
852 /***********************************************************************
853 * GetKeyboardLayoutList (USER32.@)
855 * FIXME: Supports only the system default language and layout and
856 * returns only 1 value.
858 * Return number of values available if either input parm is
859 * 0, per MS documentation.
862 INT WINAPI GetKeyboardLayoutList(INT nBuff,HKL *layouts)
864 TRACE_(keyboard)("(%d,%p)\n",nBuff,layouts);
865 if (!nBuff || !layouts)
868 layouts[0] = GetKeyboardLayout(0);
873 /***********************************************************************
874 * RegisterHotKey (USER32.@)
876 BOOL WINAPI RegisterHotKey(HWND hwnd,INT id,UINT modifiers,UINT vk) {
877 FIXME_(keyboard)("(0x%08x,%d,0x%08x,%d): stub\n",hwnd,id,modifiers,vk);
881 /***********************************************************************
882 * UnregisterHotKey (USER32.@)
884 BOOL WINAPI UnregisterHotKey(HWND hwnd,INT id) {
885 FIXME_(keyboard)("(0x%08x,%d): stub\n",hwnd,id);
889 /***********************************************************************
890 * LoadKeyboardLayoutA (USER32.@)
891 * Call ignored. WINE supports only system default keyboard layout.
893 HKL WINAPI LoadKeyboardLayoutA(LPCSTR pwszKLID, UINT Flags)
895 TRACE_(keyboard)("(%s, %d)\n", pwszKLID, Flags);
896 ERR_(keyboard)("Only default system keyboard layout supported. Call ignored.\n");
900 /***********************************************************************
901 * LoadKeyboardLayoutW (USER32.@)
903 HKL WINAPI LoadKeyboardLayoutW(LPCWSTR pwszKLID, UINT Flags)
907 WideCharToMultiByte( CP_ACP, 0, pwszKLID, -1, buf, sizeof(buf), NULL, NULL );
909 return LoadKeyboardLayoutA(buf, Flags);
913 typedef struct __TRACKINGLIST {
915 POINT pos; /* center of hover rectangle */
916 INT iHoverTime; /* elapsed time the cursor has been inside of the hover rect */
919 static _TRACKINGLIST TrackingList[10];
920 static int iTrackMax = 0;
921 static UINT_PTR timer;
922 static const INT iTimerInterval = 50; /* msec for timer interval */
924 /* FIXME: need to implement WM_NCMOUSELEAVE and WM_NCMOUSEHOVER for */
925 /* TrackMouseEventProc and _TrackMouseEvent */
926 static void CALLBACK TrackMouseEventProc(HWND hwndUnused, UINT uMsg, UINT_PTR idEvent,
932 INT hoverwidth = 0, hoverheight = 0;
935 hwnd = WindowFromPoint(pos);
937 SystemParametersInfoA(SPI_GETMOUSEHOVERWIDTH, 0, &hoverwidth, 0);
938 SystemParametersInfoA(SPI_GETMOUSEHOVERHEIGHT, 0, &hoverheight, 0);
940 /* loop through tracking events we are processing */
941 while (i < iTrackMax) {
942 /* see if this tracking event is looking for TME_LEAVE and that the */
943 /* mouse has left the window */
944 if ((TrackingList[i].tme.dwFlags & TME_LEAVE) &&
945 (TrackingList[i].tme.hwndTrack != hwnd)) {
946 PostMessageA(TrackingList[i].tme.hwndTrack, WM_MOUSELEAVE, 0, 0);
948 /* remove the TME_LEAVE flag */
949 TrackingList[i].tme.dwFlags ^= TME_LEAVE;
952 /* see if we are tracking hovering for this hwnd */
953 if(TrackingList[i].tme.dwFlags & TME_HOVER) {
954 /* add the timer interval to the hovering time */
955 TrackingList[i].iHoverTime+=iTimerInterval;
957 /* has the cursor moved outside the rectangle centered around pos? */
958 if((abs(pos.x - TrackingList[i].pos.x) > (hoverwidth / 2.0))
959 || (abs(pos.y - TrackingList[i].pos.y) > (hoverheight / 2.0)))
961 /* record this new position as the current position and reset */
962 /* the iHoverTime variable to 0 */
963 TrackingList[i].pos = pos;
964 TrackingList[i].iHoverTime = 0;
967 /* has the mouse hovered long enough? */
968 if(TrackingList[i].iHoverTime <= TrackingList[i].tme.dwHoverTime)
970 PostMessageA(TrackingList[i].tme.hwndTrack, WM_MOUSEHOVER, 0, 0);
972 /* stop tracking mouse hover */
973 TrackingList[i].tme.dwFlags ^= TME_HOVER;
977 /* see if we are still tracking TME_HOVER or TME_LEAVE for this entry */
978 if((TrackingList[i].tme.dwFlags & TME_HOVER) ||
979 (TrackingList[i].tme.dwFlags & TME_LEAVE)) {
981 } else { /* remove this entry from the tracking list */
982 TrackingList[i] = TrackingList[--iTrackMax];
986 /* stop the timer if the tracking list is empty */
994 /***********************************************************************
995 * TrackMouseEvent [USER32]
997 * Requests notification of mouse events
999 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1000 * to the hwnd specified in the ptme structure. After the event message
1001 * is posted to the hwnd, the entry in the queue is removed.
1003 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1004 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1005 * immediately and the TME_LEAVE flag being ignored.
1008 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1017 TrackMouseEvent (TRACKMOUSEEVENT *ptme)
1021 BOOL cancel = 0, hover = 0, leave = 0, query = 0;
1028 TRACE("%lx, %lx, %x, %lx\n", ptme->cbSize, ptme->dwFlags, ptme->hwndTrack, ptme->dwHoverTime);
1030 if (ptme->cbSize != sizeof(TRACKMOUSEEVENT)) {
1031 WARN("wrong TRACKMOUSEEVENT size from app\n");
1032 SetLastError(ERROR_INVALID_PARAMETER); /* FIXME not sure if this is correct */
1036 flags = ptme->dwFlags;
1038 /* if HOVER_DEFAULT was specified replace this with the systems current value */
1039 if(ptme->dwHoverTime == HOVER_DEFAULT)
1040 SystemParametersInfoA(SPI_GETMOUSEHOVERTIME, 0, &(ptme->dwHoverTime), 0);
1043 hwnd = WindowFromPoint(pos);
1045 if ( flags & TME_CANCEL ) {
1046 flags &= ~ TME_CANCEL;
1050 if ( flags & TME_HOVER ) {
1051 flags &= ~ TME_HOVER;
1055 if ( flags & TME_LEAVE ) {
1056 flags &= ~ TME_LEAVE;
1060 /* fill the TRACKMOUSEEVENT struct with the current tracking for the given hwnd */
1061 if ( flags & TME_QUERY ) {
1062 flags &= ~ TME_QUERY;
1066 /* Find the tracking list entry with the matching hwnd */
1067 while((i < iTrackMax) && (TrackingList[i].tme.hwndTrack != ptme->hwndTrack)) {
1071 /* hwnd found, fill in the ptme struct */
1073 *ptme = TrackingList[i].tme;
1077 return TRUE; /* return here, TME_QUERY is retrieving information */
1081 FIXME("Unknown flag(s) %08lx\n", flags );
1084 /* find a matching hwnd if one exists */
1087 while((i < iTrackMax) && (TrackingList[i].tme.hwndTrack != ptme->hwndTrack)) {
1092 TrackingList[i].tme.dwFlags &= ~(ptme->dwFlags & ~TME_CANCEL);
1094 /* if we aren't tracking on hover or leave remove this entry */
1095 if(!((TrackingList[i].tme.dwFlags & TME_HOVER) ||
1096 (TrackingList[i].tme.dwFlags & TME_LEAVE)))
1098 TrackingList[i] = TrackingList[--iTrackMax];
1100 if(iTrackMax == 0) {
1101 KillTimer(0, timer);
1107 /* see if hwndTrack isn't the current window */
1108 if(ptme->hwndTrack != hwnd) {
1110 PostMessageA(ptme->hwndTrack, WM_MOUSELEAVE, 0, 0);
1113 /* See if this hwnd is already being tracked and update the tracking flags */
1114 for(i = 0; i < iTrackMax; i++) {
1115 if(TrackingList[i].tme.hwndTrack == ptme->hwndTrack) {
1117 TrackingList[i].tme.dwFlags |= TME_HOVER;
1118 TrackingList[i].tme.dwHoverTime = ptme->dwHoverTime;
1122 TrackingList[i].tme.dwFlags |= TME_LEAVE;
1124 /* reset iHoverTime as per winapi specs */
1125 TrackingList[i].iHoverTime = 0;
1131 /* if the tracking list is full return FALSE */
1132 if (iTrackMax == sizeof (TrackingList) / sizeof(*TrackingList)) {
1136 /* Adding new mouse event to the tracking list */
1137 TrackingList[iTrackMax].tme = *ptme;
1139 /* Initialize HoverInfo variables even if not hover tracking */
1140 TrackingList[iTrackMax].iHoverTime = 0;
1141 TrackingList[iTrackMax].pos = pos;
1146 timer = SetTimer(0, 0, iTimerInterval, TrackMouseEventProc);