Replace strcasecmp() with lstrcmpiA() to help compilation with Windows
[wine] / windows / keyboard.c
1 /*
2  * KEYBOARD driver
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "win.h"
35 #include "user.h"
36 #include "message.h"
37 #include "wine/debug.h"
38 #include "winerror.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(keyboard);
41
42 #include "pshpack1.h"
43 typedef struct _KBINFO
44 {
45     BYTE Begin_First_Range;
46     BYTE End_First_Range;
47     BYTE Begin_Second_Range;
48     BYTE End_Second_Range;
49     WORD StateSize;
50 } KBINFO, *LPKBINFO;
51 #include "poppack.h"
52
53 static FARPROC16 DefKeybEventProc;
54 static LPBYTE pKeyStateTable;
55
56 /***********************************************************************
57  *              Inquire (KEYBOARD.1)
58  */
59 WORD WINAPI KEYBOARD_Inquire(LPKBINFO kbInfo)
60 {
61   kbInfo->Begin_First_Range = 0;
62   kbInfo->End_First_Range = 0;
63   kbInfo->Begin_Second_Range = 0;
64   kbInfo->End_Second_Range = 0;
65   kbInfo->StateSize = 16;
66
67   return sizeof(KBINFO);
68 }
69
70 /***********************************************************************
71  *              Enable (KEYBOARD.2)
72  */
73 VOID WINAPI KEYBOARD_Enable( FARPROC16 proc, LPBYTE lpKeyState )
74 {
75     DefKeybEventProc = proc;
76     pKeyStateTable = lpKeyState;
77
78     memset( lpKeyState, 0, 256 ); /* all states to false */
79 }
80
81 /***********************************************************************
82  *              Disable (KEYBOARD.3)
83  */
84 VOID WINAPI KEYBOARD_Disable(VOID)
85 {
86     DefKeybEventProc = NULL;
87     pKeyStateTable = NULL;
88 }
89
90
91 /**********************************************************************
92  *              SetSpeed (KEYBOARD.7)
93  */
94 WORD WINAPI SetSpeed16(WORD unused)
95 {
96     FIXME("(%04x): stub\n", unused);
97     return 0xffff;
98 }
99
100 /**********************************************************************
101  *              ScreenSwitchEnable (KEYBOARD.100)
102  */
103 VOID WINAPI ScreenSwitchEnable16(WORD unused)
104 {
105   FIXME("(%04x): stub\n", unused);
106 }
107
108 /**********************************************************************
109  *              OemKeyScan (KEYBOARD.128)
110  *              OemKeyScan (USER32.@)
111  */
112 DWORD WINAPI OemKeyScan(WORD wOemChar)
113 {
114   TRACE("(%d)\n", wOemChar);
115
116   return wOemChar;
117 }
118
119 /**********************************************************************
120  *              VkKeyScan (KEYBOARD.129)
121  */
122 WORD WINAPI VkKeyScan16(CHAR cChar)
123 {
124     return VkKeyScanA( cChar );
125 }
126
127 /******************************************************************************
128  *              GetKeyboardType (KEYBOARD.130)
129  */
130 INT16 WINAPI GetKeyboardType16(INT16 nTypeFlag)
131 {
132     return GetKeyboardType( nTypeFlag );
133 }
134
135 /******************************************************************************
136  *              MapVirtualKey (KEYBOARD.131)
137  *
138  * MapVirtualKey translates keycodes from one format to another
139  */
140 UINT16 WINAPI MapVirtualKey16(UINT16 wCode, UINT16 wMapType)
141 {
142     return MapVirtualKeyA(wCode,wMapType);
143 }
144
145 /****************************************************************************
146  *              GetKBCodePage (KEYBOARD.132)
147  */
148 INT16 WINAPI GetKBCodePage16(void)
149 {
150     return GetKBCodePage();
151 }
152
153 /****************************************************************************
154  *              GetKeyNameText (KEYBOARD.133)
155  */
156 INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
157 {
158     return GetKeyNameTextA( lParam, lpBuffer, nSize );
159 }
160
161 /****************************************************************************
162  *              ToAscii (KEYBOARD.4)
163  *
164  * The ToAscii function translates the specified virtual-key code and keyboard
165  * state to the corresponding Windows character or characters.
166  *
167  * If the specified key is a dead key, the return value is negative. Otherwise,
168  * it is one of the following values:
169  * Value        Meaning
170  * 0    The specified virtual key has no translation for the current state of the keyboard.
171  * 1    One Windows character was copied to the buffer.
172  * 2    Two characters were copied to the buffer. This usually happens when a
173  *      dead-key character (accent or diacritic) stored in the keyboard layout cannot
174  *      be composed with the specified virtual key to form a single character.
175  *
176  * FIXME : should do the above (return 2 for non matching deadchar+char combinations)
177  *
178  */
179 INT16 WINAPI ToAscii16(UINT16 virtKey,UINT16 scanCode, LPBYTE lpKeyState,
180                        LPVOID lpChar, UINT16 flags)
181 {
182     return ToAscii( virtKey, scanCode, lpKeyState, lpChar, flags );
183 }
184
185 /***********************************************************************
186  *              MessageBeep (USER.104)
187  */
188 void WINAPI MessageBeep16( UINT16 i )
189 {
190     MessageBeep( i );
191 }
192
193 /***********************************************************************
194  *              MessageBeep (USER32.@)
195  */
196 BOOL WINAPI MessageBeep( UINT i )
197 {
198     BOOL active = TRUE;
199     SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
200     if (active) USER_Driver.pBeep();
201     return TRUE;
202 }