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