|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This is the implementation of application class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32svr.h> |
|
21 #include <ecom/ecom.h> |
|
22 #include "modifier.h" |
|
23 #include "layout.h" |
|
24 #include "decode.h" |
|
25 #include "codestore.h" |
|
26 #include "client.h" |
|
27 #include "debug.h" |
|
28 #include "hidvalues.h" |
|
29 |
|
30 // ---------------------------------------------------------------------- |
|
31 |
|
32 CKeyboardDecoder::CKeyboardDecoder() |
|
33 : iLayout(0), iAltGrSequence(EFalse), iNumKeysDown(0) |
|
34 { |
|
35 TRACE_INFO( ( |
|
36 _L("[HID]\tCKeyboardDecoder::CKeyboardDecoder at 0x%08x"), this)); |
|
37 } |
|
38 |
|
39 CKeyboardDecoder* CKeyboardDecoder::NewL() |
|
40 { |
|
41 CKeyboardDecoder* self = |
|
42 new (ELeave) CKeyboardDecoder; |
|
43 CleanupStack::PushL(self); |
|
44 self->ConstructL(); |
|
45 CleanupStack::Pop(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 void CKeyboardDecoder::ConstructL() |
|
50 { |
|
51 iScanCodes = CScanCodeStore::NewL(); |
|
52 } |
|
53 |
|
54 CKeyboardDecoder::~CKeyboardDecoder() |
|
55 { |
|
56 TRACE_INFO( (_L("[HID]\t~CKeyboardDecoder() 0x%08x"), this)); |
|
57 |
|
58 iLayout = 0; // (we don't own iLayout) |
|
59 |
|
60 delete iScanCodes; |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------- |
|
64 |
|
65 void CKeyboardDecoder::Event(const TKeyEventInfo &aEvent, |
|
66 TDecodedKeyInfo& aDecodedKeys) |
|
67 { |
|
68 aDecodedKeys.iCount = 0; |
|
69 aDecodedKeys.iScanCode = EStdKeyNull; |
|
70 |
|
71 iNumKeysDown += (aEvent.iIsKeyDown ? 1 : -1); |
|
72 // (NB. it is possible to get an up without a down just after a new |
|
73 // decoder goes into use when the keyboard layout is changed -- but |
|
74 // only if the Bluetooth keyboard is used to make the layout change.) |
|
75 if (iNumKeysDown < 0) |
|
76 iNumKeysDown = 0; |
|
77 |
|
78 if (iLayout) |
|
79 { |
|
80 if (!HandleRightAlt(aEvent, aDecodedKeys)) |
|
81 { |
|
82 if (aEvent.iIsKeyDown) |
|
83 { |
|
84 // Key down event: |
|
85 |
|
86 TInt rawCode = iLayout->RawScanCode(aEvent.iHidKey, |
|
87 aEvent.iUsagePage, aEvent.iModifiers); |
|
88 |
|
89 // Store the raw scan code, so that the scan code for |
|
90 // the "key up" event for this key will match the one |
|
91 // sent for the "key down" event. These could be |
|
92 // different, for example, if the scan code changes |
|
93 // depending on the current modifier state. |
|
94 // |
|
95 if (iScanCodes->Store(aEvent.iHidKey, aEvent.iUsagePage, |
|
96 rawCode) == KErrNone) |
|
97 { |
|
98 aDecodedKeys.iScanCode = rawCode; |
|
99 } |
|
100 else |
|
101 { |
|
102 // Store() may fail due to low memory. In that |
|
103 // case we don't send key down (or key up) events: |
|
104 // |
|
105 aDecodedKeys.iScanCode = EStdKeyNull; |
|
106 } |
|
107 |
|
108 // Decode any key press events: |
|
109 |
|
110 TUint16 unicodeKey = iLayout->TranslateKey(aEvent.iHidKey, |
|
111 aEvent.iUsagePage, aEvent.iModifiers, aEvent.iLockKeys); |
|
112 |
|
113 if (unicodeKey != 0) |
|
114 { |
|
115 ProcessDeadKeys(unicodeKey, aEvent.iHidKey, |
|
116 aEvent.iUsagePage, aDecodedKeys); |
|
117 } |
|
118 } |
|
119 else |
|
120 { |
|
121 // Key up event: |
|
122 |
|
123 aDecodedKeys.iScanCode = |
|
124 iScanCodes->Retrieve(aEvent.iHidKey, aEvent.iUsagePage); |
|
125 } |
|
126 } |
|
127 } |
|
128 } |
|
129 |
|
130 // ---------------------------------------------------------------------- |
|
131 |
|
132 TBool CKeyboardDecoder::HandleRightAlt(const TKeyEventInfo &aEvent, |
|
133 TDecodedKeyInfo& aDecodedKeys) |
|
134 { |
|
135 // A press and release of the right-alt (Alt Gr) key should cause |
|
136 // the S60 symbol selection dialog to appear, if no other keys are |
|
137 // pressed in between. |
|
138 |
|
139 TBool handledEvent = EFalse; |
|
140 |
|
141 const TInt KRightAltKey = 0xe6; |
|
142 |
|
143 if ((aEvent.iHidKey == KRightAltKey) && |
|
144 (aEvent.iUsagePage == EUsagePageKeyboard)) |
|
145 { |
|
146 if (aEvent.iIsKeyDown && (iNumKeysDown == 1)) |
|
147 { |
|
148 iAltGrSequence = ETrue; |
|
149 } |
|
150 |
|
151 if (!aEvent.iIsKeyDown && iAltGrSequence) |
|
152 { |
|
153 // We use EKeyApplication2 to indicate to the modified T9 |
|
154 // FEP that we wish it to produce the symbol selection dialog: |
|
155 // EKeyApplication2 is not passed to Fep anymore, but |
|
156 // it is converted to '*' in SendKeyPress() (keyboard.cpp) |
|
157 aDecodedKeys.iEvent[0] = TTranslatedKey(EKeyApplication2, |
|
158 EStdKeyApplication2, 0, 0, EFalse); |
|
159 aDecodedKeys.iCount = 1; |
|
160 |
|
161 handledEvent = ETrue; |
|
162 iAltGrSequence = EFalse; |
|
163 } |
|
164 } |
|
165 else |
|
166 { |
|
167 iAltGrSequence = EFalse; |
|
168 } |
|
169 |
|
170 return handledEvent; |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------- |
|
174 |
|
175 void CKeyboardDecoder::Reset() |
|
176 { |
|
177 iDeadKey.iUnicode = 0; |
|
178 iAltGrSequence = EFalse; |
|
179 iNumKeysDown = 0; |
|
180 } |
|
181 |
|
182 // ---------------------------------------------------------------------- |
|
183 |
|
184 void CKeyboardDecoder::SetLayout(CKeyboardLayout* aLayout) |
|
185 { |
|
186 TRACE_INFO( (_L("[HID]\tCKeyboardDecoder::SetLayout(0x%08x)"), aLayout)); |
|
187 |
|
188 iLayout = aLayout; |
|
189 Reset(); |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------- |
|
193 |
|
194 void CKeyboardDecoder::ProcessDeadKeys(TUint16 aUnicodeKey, |
|
195 TInt aHidKey, TInt aUsagePage, TDecodedKeyInfo &aDecodedKeys) |
|
196 { |
|
197 if (iDeadKey.iUnicode == 0) |
|
198 { |
|
199 // Check if the current key is a dead key: |
|
200 // |
|
201 if (iLayout->IsDeadKey(aUnicodeKey)) |
|
202 { |
|
203 // We've received a dead key event, so there's no key press |
|
204 // to issue -- just record the details for later: |
|
205 // |
|
206 TRACE_INFO( (_L("[HID]\tDeadkey 0x%04x (%d:%d)"), |
|
207 aUnicodeKey, aUsagePage, aHidKey)); |
|
208 |
|
209 iDeadKey = TTranslatedKey(aUnicodeKey, |
|
210 aDecodedKeys.iScanCode, aHidKey, aUsagePage, EFalse); |
|
211 aDecodedKeys.iCount = 0; |
|
212 } |
|
213 else |
|
214 { |
|
215 // No dead key processing to do, so just send a |
|
216 // normal key code: |
|
217 // |
|
218 TRACE_INFO( (_L("[HID]\tNo dead key processing, one event"))); |
|
219 |
|
220 aDecodedKeys.iEvent[0] = TTranslatedKey(aUnicodeKey, |
|
221 aDecodedKeys.iScanCode, aHidKey, aUsagePage, |
|
222 iLayout->IsRepeatingKey(aUnicodeKey)); |
|
223 aDecodedKeys.iCount = 1; |
|
224 } |
|
225 } |
|
226 else |
|
227 { |
|
228 // We've an active dead key, see if the current key produces |
|
229 // a combination character: |
|
230 // |
|
231 TUint16 comboChar = |
|
232 iLayout->FindCombiningChar(iDeadKey.iUnicode, aUnicodeKey); |
|
233 |
|
234 if (comboChar == 0) |
|
235 { |
|
236 TRACE_INFO( (_L("[HID]\tNo match for 0x%04x, sending after 0x%04x"), |
|
237 aUnicodeKey, iDeadKey.iUnicode)); |
|
238 |
|
239 // No match, so two key events to send: |
|
240 |
|
241 aDecodedKeys.iEvent[0] = iDeadKey; |
|
242 aDecodedKeys.iEvent[1] = TTranslatedKey(aUnicodeKey, |
|
243 aDecodedKeys.iScanCode, aHidKey, aUsagePage, |
|
244 iLayout->IsRepeatingKey(aUnicodeKey)); |
|
245 aDecodedKeys.iCount = 2; |
|
246 } |
|
247 else |
|
248 { |
|
249 TRACE_INFO( (_L("[HID]\tFound a match 0x%04x, one combo to send 0x%04x"), |
|
250 aUnicodeKey, comboChar)); |
|
251 |
|
252 // Found a match, so one combo key event to send: |
|
253 |
|
254 aDecodedKeys.iEvent[0] = TTranslatedKey(comboChar, |
|
255 aDecodedKeys.iScanCode, aHidKey, aUsagePage, |
|
256 iLayout->IsRepeatingKey(comboChar)); |
|
257 aDecodedKeys.iCount = 1; |
|
258 } |
|
259 |
|
260 // We've finished processing the dead key sequence: |
|
261 iDeadKey.iUnicode = 0; |
|
262 } |
|
263 } |
|
264 |
|
265 // ---------------------------------------------------------------------- |