Implementation of DragDetect. Based on Wine code (C) 1993, 1994 Alexandre Julliard.
[reactos.git] / reactos / lib / 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 #include <debug.h>
33 #include <wchar.h>
34
35 /* FUNCTIONS *****************************************************************/
36
37
38 /*
39 * @implemented
40 */
41 BOOL
42 STDCALL
43 DragDetect(
44 HWND hWnd,
45 POINT pt)
46 {
47 #if 0
48 return NtUserDragDetect(hWnd, pt.x, pt.y);
49 #else
50 MSG msg;
51 RECT rect;
52 POINT tmp;
53 ULONG dx = NtUserGetSystemMetrics(SM_CXDRAG);
54 ULONG dy = NtUserGetSystemMetrics(SM_CYDRAG);
55
56 rect.left = pt.x - dx;
57 rect.right = pt.x + dx;
58 rect.top = pt.y - dy;
59 rect.bottom = pt.y + dy;
60
61 SetCapture(hWnd);
62
63 for (;;)
64 {
65 while (PeekMessageW(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE))
66 {
67 if (msg.message == WM_LBUTTONUP)
68 {
69 ReleaseCapture();
70 return 0;
71 }
72 if (msg.message == WM_MOUSEMOVE)
73 {
74 tmp.x = LOWORD(msg.lParam);
75 tmp.y = HIWORD(msg.lParam);
76 if (!PtInRect(&rect, tmp))
77 {
78 ReleaseCapture();
79 return 1;
80 }
81 }
82 }
83 WaitMessage();
84 }
85 return 0;
86 #endif
87 }
88
89
90 /*
91 * @unimplemented
92 */
93 HKL STDCALL
94 ActivateKeyboardLayout(HKL hkl,
95 UINT Flags)
96 {
97 UNIMPLEMENTED;
98 return (HKL)0;
99 }
100
101
102 /*
103 * @implemented
104 */
105 BOOL STDCALL
106 BlockInput(BOOL fBlockIt)
107 {
108 return NtUserBlockInput(fBlockIt);
109 }
110
111
112 /*
113 * @implemented
114 */
115 BOOL STDCALL
116 EnableWindow(HWND hWnd,
117 BOOL bEnable)
118 {
119 LONG Style = NtUserGetWindowLong(hWnd, GWL_STYLE, FALSE);
120 Style = bEnable ? Style & ~WS_DISABLED : Style | WS_DISABLED;
121 NtUserSetWindowLong(hWnd, GWL_STYLE, Style, FALSE);
122
123 SendMessageA(hWnd, WM_ENABLE, (LPARAM) IsWindowEnabled(hWnd), 0);
124
125 // Return nonzero if it was disabled, or zero if it wasn't:
126 return IsWindowEnabled(hWnd);
127 }
128
129
130 /*
131 * @unimplemented
132 */
133 SHORT STDCALL
134 GetAsyncKeyState(int vKey)
135 {
136 UNIMPLEMENTED;
137 return 0;
138 }
139
140
141 /*
142 * @implemented
143 */
144 UINT
145 STDCALL
146 GetDoubleClickTime(VOID)
147 {
148 return NtUserGetDoubleClickTime();
149 }
150
151
152 /*
153 * @unimplemented
154 */
155 HKL STDCALL
156 GetKeyboardLayout(DWORD idThread)
157 {
158 UNIMPLEMENTED;
159 return (HKL)0;
160 }
161
162
163 /*
164 * @unimplemented
165 */
166 UINT STDCALL
167 GetKBCodePage(VOID)
168 {
169 UNIMPLEMENTED;
170 return 0;
171 }
172
173
174 /*
175 * @implemented
176 */
177 int STDCALL
178 GetKeyNameTextA(LONG lParam,
179 LPSTR lpString,
180 int nSize)
181 {
182 LPWSTR intermediateString =
183 HeapAlloc(GetProcessHeap(),0,nSize * sizeof(WCHAR));
184 int ret = 0;
185 UINT wstrLen = 0;
186 BOOL defChar = FALSE;
187
188 if( !intermediateString ) return 0;
189 ret = GetKeyNameTextW(lParam,intermediateString,nSize);
190 if( ret == 0 ) { lpString[0] = 0; return 0; }
191
192 wstrLen = wcslen( intermediateString );
193 ret = WideCharToMultiByte(CP_ACP, 0,
194 intermediateString, wstrLen,
195 lpString, nSize, ".", &defChar );
196 lpString[ret] = 0;
197 HeapFree(GetProcessHeap(),0,intermediateString);
198
199 return ret;
200 }
201
202 /*
203 * @implemented
204 */
205 int STDCALL
206 GetKeyNameTextW(LONG lParam,
207 LPWSTR lpString,
208 int nSize)
209 {
210 return NtUserGetKeyNameText( lParam, lpString, nSize );
211 }
212
213
214 /*
215 * @implemented
216 */
217 SHORT STDCALL
218 GetKeyState(int nVirtKey)
219 {
220 return (SHORT) NtUserGetKeyState((DWORD) nVirtKey);
221 }
222
223
224 /*
225 * @unimplemented
226 */
227 UINT STDCALL
228 GetKeyboardLayoutList(int nBuff,
229 HKL FAR *lpList)
230 {
231 UNIMPLEMENTED;
232 return 0;
233 }
234
235
236 /*
237 * @unimplemented
238 */
239 BOOL STDCALL
240 GetKeyboardLayoutNameA(LPSTR pwszKLID)
241 {
242 UNIMPLEMENTED;
243 return FALSE;
244 }
245
246
247 /*
248 * @unimplemented
249 */
250 BOOL STDCALL
251 GetKeyboardLayoutNameW(LPWSTR pwszKLID)
252 {
253 UNIMPLEMENTED;
254 return FALSE;
255 }
256
257
258 /*
259 * @unimplemented
260 */
261 BOOL STDCALL
262 GetKeyboardState(PBYTE lpKeyState)
263 {
264
265 return (BOOL) NtUserGetKeyboardState((LPBYTE) lpKeyState);
266 }
267
268
269 /*
270 * @unimplemented
271 */
272 int STDCALL
273 GetKeyboardType(int nTypeFlag)
274 {
275 UNIMPLEMENTED;
276 return 0;
277 }
278
279
280 /*
281 * @unimplemented
282 */
283 BOOL STDCALL
284 GetLastInputInfo(PLASTINPUTINFO plii)
285 {
286 UNIMPLEMENTED;
287 return FALSE;
288 }
289
290
291 /*
292 * @unimplemented
293 */
294 HKL STDCALL
295 LoadKeyboardLayoutA(LPCSTR pwszKLID,
296 UINT Flags)
297 {
298 UNIMPLEMENTED;
299 return (HKL)0;
300 }
301
302
303 /*
304 * @unimplemented
305 */
306 HKL STDCALL
307 LoadKeyboardLayoutW(LPCWSTR pwszKLID,
308 UINT Flags)
309 {
310 UNIMPLEMENTED;
311 return (HKL)0;
312 }
313
314
315 /*
316 * @implemented
317 */
318 UINT STDCALL
319 MapVirtualKeyA(UINT uCode,
320 UINT uMapType)
321 {
322 return MapVirtualKeyExA( uCode, uMapType, GetKeyboardLayout( 0 ) );
323 }
324
325
326 /*
327 * @implemented
328 */
329 UINT STDCALL
330 MapVirtualKeyExA(UINT uCode,
331 UINT uMapType,
332 HKL dwhkl)
333 {
334 return MapVirtualKeyExW( uCode, uMapType, dwhkl );
335 }
336
337
338 /*
339 * @implemented
340 */
341 UINT STDCALL
342 MapVirtualKeyExW(UINT uCode,
343 UINT uMapType,
344 HKL dwhkl)
345 {
346 return NtUserMapVirtualKeyEx( uCode, uMapType, 0, dwhkl );
347 }
348
349
350 /*
351 * @implemented
352 */
353 UINT STDCALL
354 MapVirtualKeyW(UINT uCode,
355 UINT uMapType)
356 {
357 return MapVirtualKeyExW( uCode, uMapType, GetKeyboardLayout( 0 ) );
358 }
359
360
361 /*
362 * @unimplemented
363 */
364 DWORD STDCALL
365 OemKeyScan(WORD wOemChar)
366 {
367 UNIMPLEMENTED;
368 return 0;
369 }
370
371
372 /*
373 * @implemented
374 */
375 BOOL STDCALL
376 RegisterHotKey(HWND hWnd,
377 int id,
378 UINT fsModifiers,
379 UINT vk)
380 {
381 return (BOOL)NtUserRegisterHotKey(hWnd,
382 id,
383 fsModifiers,
384 vk);
385 }
386
387
388 /*
389 * @implemented
390 */
391 BOOL STDCALL
392 SetDoubleClickTime(UINT uInterval)
393 {
394 return (BOOL)NtUserSystemParametersInfo(SPI_SETDOUBLECLICKTIME,
395 uInterval,
396 NULL,
397 0);
398 }
399
400
401 /*
402 * @unimplemented
403 */
404 HWND STDCALL
405 SetFocus(HWND hWnd)
406 {
407 return NtUserSetFocus(hWnd);
408 }
409
410
411 /*
412 * @unimplemented
413 */
414 BOOL STDCALL
415 SetKeyboardState(LPBYTE lpKeyState)
416 {
417 return (BOOL) NtUserSetKeyboardState((LPBYTE)lpKeyState);
418 }
419
420
421 /*
422 * @implemented
423 */
424 BOOL
425 STDCALL
426 SwapMouseButton(
427 BOOL fSwap)
428 {
429 return NtUserSwapMouseButton(fSwap);
430 }
431
432
433 /*
434 * @implemented
435 */
436 int STDCALL
437 ToAscii(UINT uVirtKey,
438 UINT uScanCode,
439 CONST PBYTE lpKeyState,
440 LPWORD lpChar,
441 UINT uFlags)
442 {
443 return ToAsciiEx(uVirtKey, uScanCode, lpKeyState, lpChar, uFlags, 0);
444 }
445
446
447 /*
448 * @implemented
449 */
450 int STDCALL
451 ToAsciiEx(UINT uVirtKey,
452 UINT uScanCode,
453 CONST PBYTE lpKeyState,
454 LPWORD lpChar,
455 UINT uFlags,
456 HKL dwhkl)
457 {
458 WCHAR UniChars[2];
459 int Ret, CharCount;
460
461 Ret = ToUnicodeEx(uVirtKey, uScanCode, lpKeyState, UniChars, 2, uFlags, dwhkl);
462 CharCount = (Ret < 0 ? 1 : Ret);
463 WideCharToMultiByte(CP_ACP, 0, UniChars, CharCount, (LPSTR) lpChar, 2, NULL, NULL);
464
465 return Ret;
466 }
467
468
469 /*
470 * @implemented
471 */
472 int STDCALL
473 ToUnicode(UINT wVirtKey,
474 UINT wScanCode,
475 CONST PBYTE lpKeyState,
476 LPWSTR pwszBuff,
477 int cchBuff,
478 UINT wFlags)
479 {
480 return ToUnicodeEx( wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff,
481 wFlags, 0 );
482 }
483
484
485 /*
486 * @unimplemented
487 */
488 int STDCALL
489 ToUnicodeEx(UINT wVirtKey,
490 UINT wScanCode,
491 CONST PBYTE lpKeyState,
492 LPWSTR pwszBuff,
493 int cchBuff,
494 UINT wFlags,
495 HKL dwhkl)
496 {
497 return NtUserToUnicodeEx( wVirtKey, wScanCode, lpKeyState, pwszBuff, cchBuff,
498 wFlags, dwhkl );
499 }
500
501
502 /*
503 * @unimplemented
504 */
505 BOOL STDCALL
506 UnloadKeyboardLayout(HKL hkl)
507 {
508 UNIMPLEMENTED;
509 return FALSE;
510 }
511
512
513 /*
514 * @implemented
515 */
516 BOOL STDCALL
517 UnregisterHotKey(HWND hWnd,
518 int id)
519 {
520 return (BOOL)NtUserUnregisterHotKey(hWnd, id);
521 }
522
523
524 /*
525 * @implemented
526 */
527 SHORT STDCALL
528 VkKeyScanA(CHAR ch)
529 {
530 WCHAR wChar;
531
532 if (IsDBCSLeadByte(ch)) return -1;
533
534 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wChar, 1);
535 return VkKeyScanW(wChar);
536 }
537
538
539 /*
540 * @implemented
541 */
542 SHORT STDCALL
543 VkKeyScanExA(CHAR ch,
544 HKL dwhkl)
545 {
546 WCHAR wChar;
547
548 if (IsDBCSLeadByte(ch)) return -1;
549
550 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wChar, 1);
551 return VkKeyScanExW(wChar, dwhkl);
552 }
553
554
555 /*
556 * @unimplemented
557 */
558 SHORT STDCALL
559 VkKeyScanExW(WCHAR ch,
560 HKL dwhkl)
561 {
562 UNIMPLEMENTED;
563 return -1;
564 }
565
566
567 /*
568 * @implemented
569 */
570 SHORT STDCALL
571 VkKeyScanW(WCHAR ch)
572 {
573 return VkKeyScanExW(ch, GetKeyboardLayout(0));
574 }
575
576
577 /*
578 * @implemented
579 */
580 UINT
581 STDCALL
582 SendInput(
583 UINT nInputs,
584 LPINPUT pInputs,
585 int cbSize)
586 {
587 return NtUserSendInput(nInputs, pInputs, cbSize);
588 }
589
590 /*
591 * Private call for CSRSS
592 */
593 VOID
594 STDCALL
595 PrivateCsrssRegisterPrimitive(VOID)
596 {
597 NtUserCallNoParam(NOPARAM_ROUTINE_REGISTER_PRIMITIVE);
598 }
599
600 /*
601 * Another private call for CSRSS
602 */
603 VOID
604 STDCALL
605 PrivateCsrssAcquireOrReleaseInputOwnership(BOOL Release)
606 {
607 NtUserAcquireOrReleaseInputOwnership(Release);
608 }
609
610 /*
611 * @implemented
612 */
613 VOID
614 STDCALL
615 keybd_event(
616 BYTE bVk,
617 BYTE bScan,
618 DWORD dwFlags,
619 ULONG_PTR dwExtraInfo)
620
621
622 {
623 INPUT Input;
624
625 Input.type = INPUT_KEYBOARD;
626 Input.ki.wVk = bVk;
627 Input.ki.wScan = bScan;
628 Input.ki.dwFlags = dwFlags;
629 Input.ki.time = 0;
630 Input.ki.dwExtraInfo = dwExtraInfo;
631
632 NtUserSendInput(1, &Input, sizeof(INPUT));
633 }
634
635
636 /*
637 * @implemented
638 */
639 VOID
640 STDCALL
641 mouse_event(
642 DWORD dwFlags,
643 DWORD dx,
644 DWORD dy,
645 DWORD dwData,
646 ULONG_PTR dwExtraInfo)
647 {
648 INPUT Input;
649
650 Input.type = INPUT_MOUSE;
651 Input.mi.dx = dx;
652 Input.mi.dy = dy;
653 Input.mi.mouseData = dwData;
654 Input.mi.dwFlags = dwFlags;
655 Input.mi.time = 0;
656 Input.mi.dwExtraInfo = dwExtraInfo;
657
658 NtUserSendInput(1, &Input, sizeof(INPUT));
659 }
660
661 /* EOF */