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