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