|
1 /* |
|
2 * Copyright (c) 2003-2006 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: CPtiQwertyKeymappings class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "PtiKeyMappings.h" |
|
20 #include <PtiKeyMapData.h> |
|
21 |
|
22 // CONSTANTS |
|
23 |
|
24 #ifdef _DEBUG |
|
25 _LIT(KPtiNoQwertyKeyMapDataPanic, "PtiEngine: No qwerty keymap data set!"); |
|
26 _LIT(KPtiNoExtensionPanic, "PtiEngine: No extension class created!"); |
|
27 #endif |
|
28 |
|
29 const TUint16 KEmptyDeadKeySlotMarker = 0xf000; |
|
30 const TInt KPtiUWithAHorn = 0x01b0; |
|
31 const TInt KPtiQwertyLowCaseLetterBase = 97; |
|
32 |
|
33 const TInt KNumVietnameseToneMarks = 5; |
|
34 const TInt KNumVietnameseToneMarkDataEntries = 24; |
|
35 |
|
36 class TVietnameseToneMarkData |
|
37 { |
|
38 public: |
|
39 TUint16 iBaseChar; |
|
40 TUint16 iToneData[KNumVietnameseToneMarks]; |
|
41 }; |
|
42 |
|
43 |
|
44 const TVietnameseToneMarkData vietnameseToneMarkData[KNumVietnameseToneMarkDataEntries] = |
|
45 { |
|
46 // for A-based |
|
47 {0x0041, {0x00c1, 0x00c0, 0x1ea2, 0x00c3, 0x1ea0}}, |
|
48 {0x0061, {0x00e1, 0x00e0, 0x1ea3, 0x00e3, 0x1ea1}}, |
|
49 {0x0102, {0x1eae, 0x1eb0, 0x1eb2, 0x1eb4, 0x1eb6}}, |
|
50 {0x0103, {0x1eaf, 0x1eb1, 0x1eb3, 0x1eb5, 0x1eb7}}, |
|
51 {0x00c2, {0x1ea4, 0x1ea6, 0x1ea8, 0x1eaa, 0x1eac}}, |
|
52 {0x00e2, {0x1ea5, 0x1ea7, 0x1ea9, 0x1eab, 0x1ead}}, |
|
53 // for E-based |
|
54 {0x0045, {0x00c9, 0x00c8, 0x1eba, 0x1ebc, 0x1eb8}}, |
|
55 {0x0065, {0x00e9, 0x00e8, 0x1ebb, 0x1ebd, 0x1eb9}}, |
|
56 {0x00ca, {0x1ebe, 0x1ec0, 0x1ec2, 0x1ec4, 0x1ec6}}, |
|
57 {0x00ea, {0x1ebf, 0x1ec1, 0x1ec3, 0x1ec5, 0x1ec7}}, |
|
58 // for I-based |
|
59 {0x0049, {0x00cd, 0x00cc, 0x1ec8, 0x0128, 0x1eca}}, |
|
60 {0x0069, {0x00ed, 0x00ec, 0x1ec9, 0x0129, 0x1ecb}}, |
|
61 // for O-based |
|
62 {0x004f, {0x00d3, 0x00d2, 0x1ece, 0x00d5, 0x1ecc}}, |
|
63 {0x006f, {0x00f3, 0x00f2, 0x1ecf, 0x00f5, 0x1ecd}}, |
|
64 {0x00d4, {0x1ed0, 0x1ed2, 0x1ed4, 0x1ed6, 0x1ed8}}, |
|
65 {0x00f4, {0x1ed1, 0x1ed3, 0x1ed5, 0x1ed7, 0x1ed9}}, |
|
66 {0x01a0, {0x1eda, 0x1edc, 0x1ede, 0x1ee0, 0x1ee2}}, |
|
67 {0x01a1, {0x1edb, 0x1edd, 0x1edf, 0x1ee1, 0x1ee3}}, |
|
68 // for U-based |
|
69 {0x0055, {0x00da, 0x00d9, 0x1ee6, 0x0168, 0x1ee4}}, |
|
70 {0x0075, {0x00fa, 0x00f9, 0x1ee7, 0x0169, 0x1ee5}}, |
|
71 {0x01af, {0x1ee8, 0x1eea, 0x1eec, 0x1eee, 0x1ef0}}, |
|
72 {0x01b0, {0x1ee9, 0x1eeb, 0x1eed, 0x1eef, 0x1ef1}}, |
|
73 // for Y based |
|
74 {0x0059, {0x00dd, 0x1ef2, 0x1ef6, 0x1ef8, 0x1ef4}}, |
|
75 {0x0079, {0x00fd, 0x1ef3, 0x1ef7, 0x1ef9, 0x1ef5}} |
|
76 }; |
|
77 |
|
78 |
|
79 const TPtiKey vietnameseToneMarkKeys[KNumVietnameseToneMarks] = |
|
80 { |
|
81 EPtiKeyQwertyS, EPtiKeyQwertyF, EPtiKeyQwertyR, EPtiKeyQwertyX, EPtiKeyQwertyJ |
|
82 }; |
|
83 |
|
84 |
|
85 // |
|
86 // CPtiQwertyKeymappingsExtension |
|
87 // |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // CPtiQwertyKeymappingsExtension::NewL |
|
91 // |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 CPtiQwertyKeymappingsExtension* CPtiQwertyKeymappingsExtension::NewL() |
|
95 { |
|
96 return new (ELeave) CPtiQwertyKeymappingsExtension(); |
|
97 } |
|
98 |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CPtiQwertyKeymappingsExtension::CPtiQwertyKeymappingsExtension |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 CPtiQwertyKeymappingsExtension::CPtiQwertyKeymappingsExtension() |
|
106 { |
|
107 } |
|
108 |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CPtiQwertyKeymappingsExtension::CPtiQwertyKeymappingsExtension |
|
112 // |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 CPtiQwertyKeymappingsExtension::~CPtiQwertyKeymappingsExtension() |
|
116 { |
|
117 } |
|
118 |
|
119 // |
|
120 // CPtiQwertyKeymappingsExtension |
|
121 // |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CPtiQwertyKeyMappings::NewL |
|
125 // |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C CPtiQwertyKeyMappings* CPtiQwertyKeyMappings::NewL(TDesC& /*aData*/) |
|
129 { |
|
130 // DEPRECATED |
|
131 User::Leave(KErrNotSupported); |
|
132 return NULL; |
|
133 } |
|
134 |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CPtiQwertyKeyMappings::NewL |
|
138 // |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 EXPORT_C CPtiQwertyKeyMappings* CPtiQwertyKeyMappings::NewL(TInt16* /*aData*/) |
|
142 { |
|
143 // DEPRECATED |
|
144 User::Leave(KErrNotSupported); |
|
145 return NULL; |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CPtiQwertyKeyMappings::NewL |
|
151 // |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 EXPORT_C CPtiQwertyKeyMappings* CPtiQwertyKeyMappings::NewL(CPtiKeyMapData* aData) |
|
155 { |
|
156 CPtiQwertyKeyMappings* maps = new (ELeave) CPtiQwertyKeyMappings(aData); |
|
157 CleanupStack::PushL(maps); |
|
158 maps->ConstructL(); |
|
159 CleanupStack::Pop(); // maps |
|
160 return maps; |
|
161 } |
|
162 |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CPtiQwertyKeyMappings::CPtiQwertyKeyMappings |
|
166 // |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 CPtiQwertyKeyMappings::CPtiQwertyKeyMappings() |
|
170 { |
|
171 iKeyboardType = EPtiKeyboardQwerty4x12; |
|
172 } |
|
173 |
|
174 |
|
175 // --------------------------------------------------------------------------- |
|
176 // CPtiQwertyKeyMappings::CPtiQwertyKeyMappings |
|
177 // |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 CPtiQwertyKeyMappings::CPtiQwertyKeyMappings(CPtiKeyMapData* aData) : CPtiMappings(aData) |
|
181 { |
|
182 if(aData->HasKeyData(EPtiKeyboardQwerty4x12)) |
|
183 { |
|
184 iKeyboardType = EPtiKeyboardQwerty4x12; |
|
185 } |
|
186 else if(aData->HasKeyData(EPtiKeyboardQwerty4x10)) |
|
187 { |
|
188 iKeyboardType = EPtiKeyboardQwerty4x10; |
|
189 } |
|
190 else if(aData->HasKeyData(EPtiKeyboardQwerty3x11)) |
|
191 { |
|
192 iKeyboardType = EPtiKeyboardQwerty3x11; |
|
193 } |
|
194 else |
|
195 { |
|
196 iKeyboardType = EPtiKeyboardCustomQwerty; |
|
197 } |
|
198 } |
|
199 |
|
200 |
|
201 // --------------------------------------------------------------------------- |
|
202 // CPtiQwertyKeyMappings::~CPtiQwertyKeyMappings |
|
203 // |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 EXPORT_C CPtiQwertyKeyMappings::~CPtiQwertyKeyMappings() |
|
207 { |
|
208 iReservedArray.Close(); |
|
209 delete iExtension; |
|
210 } |
|
211 |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CPtiQwertyKeyMappings::ConstructL |
|
215 // |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CPtiQwertyKeyMappings::ConstructL() |
|
219 { |
|
220 iExtension = CPtiQwertyKeymappingsExtension::NewL(); |
|
221 } |
|
222 |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CPtiQwertyKeyMappings::StartMapping |
|
226 // |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C TUint16 CPtiQwertyKeyMappings::StartMapping(TPtiKey aKey, TPtiTextCase aCase, |
|
230 TPtiEngineInputMode aMode) |
|
231 { |
|
232 __ASSERT_DEBUG(iExtension, User::Panic(KPtiNoExtensionPanic, KErrCorrupt)); |
|
233 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
234 |
|
235 KeyCodeToInternal(aKey); |
|
236 |
|
237 ResetFlag(EDeadKeyRootFlag | EVowelSeqFlag); |
|
238 |
|
239 if (iDeadKey) |
|
240 { |
|
241 TUint16 deadChar = GetDeadKeyChar(iCurrentKey, aCase); |
|
242 iDeadKey = 0; |
|
243 if (deadChar) |
|
244 { |
|
245 return deadChar; |
|
246 } |
|
247 SetFlag(EDeadKeyRootFlag); |
|
248 return iDeadKeyRootChar; |
|
249 } |
|
250 |
|
251 iCurrentChar = 0; |
|
252 iExtension->iReplaced = 0; |
|
253 |
|
254 TPtrC keyData = DataForKeyLocal(aKey, aCase, EPtiEngineQwerty); |
|
255 |
|
256 TInt chrIndexOffset= 0 ; |
|
257 |
|
258 if (aCase == EPtiCaseChrLower) |
|
259 { |
|
260 if (IsChnSpecialCharKey(iCurrentKey)) |
|
261 { |
|
262 if (aMode == EPtiEnginePinyinQwerty || aMode == EPtiEnginePinyinPhraseQwerty) |
|
263 { |
|
264 chrIndexOffset = 2; |
|
265 } |
|
266 else if (aMode == EPtiEngineZhuyinQwerty || aMode == EPtiEngineZhuyinPhraseQwerty) |
|
267 { |
|
268 chrIndexOffset = 2; |
|
269 } |
|
270 else if (aMode == EPtiEngineStrokeQwerty || aMode == EPtiEngineStrokePhraseQwerty) |
|
271 { |
|
272 chrIndexOffset = 6; |
|
273 } |
|
274 } |
|
275 else if(aKey >= EPtiKeyQwerty0 && aKey <= EPtiKeyQwerty9) |
|
276 { |
|
277 if (aMode == EPtiEnginePinyinQwerty || aMode == EPtiEnginePinyinPhraseQwerty) |
|
278 { |
|
279 chrIndexOffset = 2; |
|
280 } |
|
281 else if (aMode == EPtiEngineZhuyinQwerty || aMode == EPtiEngineZhuyinPhraseQwerty) |
|
282 { |
|
283 chrIndexOffset = 2; |
|
284 } |
|
285 } |
|
286 } |
|
287 |
|
288 if (keyData.Length() <= chrIndexOffset) |
|
289 { |
|
290 return 0; |
|
291 } |
|
292 |
|
293 if (iFlags & ETrackVietnameseToneMarksAndVowels) |
|
294 { |
|
295 TUint toneMarked = VietnameseToneMark(iExtension->iLastChar, aKey); |
|
296 if (toneMarked) |
|
297 { |
|
298 /* In case of FnLower Case, Vowel Sequence shouldnt be constructed, instead we should clear the Vowel Sequence */ |
|
299 if (aCase != EPtiCaseFnLower) |
|
300 { |
|
301 iExtension->iLastToneKey = aKey; |
|
302 iVowelSeqResult = toneMarked; |
|
303 SetFlag(EVowelSeqFlag); |
|
304 iLastKey = EPtiKeyNone; |
|
305 return toneMarked; |
|
306 } |
|
307 else |
|
308 { |
|
309 ClearVowelSequence(); |
|
310 ClearLastChar(); |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 if (iExtension->iLastToneKey == aKey) |
|
316 { |
|
317 iExtension->iReplaced = iExtension->iLastChar; |
|
318 TChar lastCase = iExtension->iLastChar; |
|
319 iExtension->iVowelCase = EPtiCaseLower; |
|
320 if (lastCase.IsUpper()) |
|
321 { |
|
322 iExtension->iVowelCase = EPtiCaseUpper; |
|
323 } |
|
324 iVowelSeqResult = 0; |
|
325 } |
|
326 else if (iVowelSeqResult) |
|
327 { |
|
328 iExtension->iReplaced = RepeatingVowelSequence(aKey); |
|
329 if (!iExtension->iReplaced) |
|
330 { |
|
331 TPtiKey first = VowelSeqRootKey(iVowelSeqResult); |
|
332 iVowelSeqResult = VowelSequence(first, aKey, iExtension->iVowelCase); |
|
333 } |
|
334 else |
|
335 { |
|
336 iVowelSeqResult = 0; |
|
337 } |
|
338 } |
|
339 |
|
340 iExtension->iLastTone = 0; |
|
341 iExtension->iLastToneKey = EPtiKeyNone; |
|
342 |
|
343 TUint16 ret = GetCharForMode(aMode, keyData.Mid(chrIndexOffset), |
|
344 (aMode == EPtiEngineQwertyPredictive || |
|
345 aMode == EPtiEngineQwerty || aMode == EPtiEngineInputModeNone) |
|
346 && (aCase == EPtiCaseChrLower || aCase == EPtiCaseChrUpper)); |
|
347 |
|
348 if ((aKey == EPtiKey0) && |
|
349 (aCase == EPtiCaseChrLower) && |
|
350 (aMode == EPtiEngineZhuyinQwerty || aMode == EPtiEngineZhuyinPhraseQwerty )) |
|
351 { |
|
352 ret = 0; |
|
353 } |
|
354 |
|
355 if (ChineseChrModeConversionNeeded(aCase, aMode) && |
|
356 aKey >= EPtiKeyQwertyA && aKey <= EPtiKeyQwertyZ) |
|
357 { |
|
358 ret = KPtiQwertyLowCaseLetterBase + aKey - EPtiKeyQwertyA; |
|
359 } |
|
360 |
|
361 if (ret == KPtiGetAllMarker) |
|
362 { |
|
363 return ret; |
|
364 } |
|
365 |
|
366 if (IsDeadKeyCode(ret)) |
|
367 { |
|
368 iDeadKey = ret; |
|
369 if (keyData.Length() > 1) |
|
370 { |
|
371 iDeadKeyRootChar = keyData[1]; |
|
372 } |
|
373 |
|
374 return 0; |
|
375 } |
|
376 |
|
377 TPtiTextCase vowelCase = iExtension->iVowelCase; |
|
378 // Do not use vowel sequence if user is in Numeric mode (fnLower) |
|
379 if (aCase != EPtiCaseFnLower && iVowelSeqResult == 0 && (iFlags & ETrackVietnameseToneMarksAndVowels)) |
|
380 { |
|
381 vowelCase = (aCase == EPtiCaseUpper || |
|
382 (iFlags & EPrevKeyInUpperCase) ? EPtiCaseUpper : EPtiCaseLower); |
|
383 iVowelSeqResult = VowelSequence(iLastKey, aKey, vowelCase); |
|
384 } |
|
385 |
|
386 if (iVowelSeqResult) |
|
387 { |
|
388 iExtension->iVowelCase = vowelCase; |
|
389 iExtension->iLastChar = iVowelSeqResult; |
|
390 SetFlag(EVowelSeqFlag); |
|
391 iLastKey = EPtiKeyNone; |
|
392 } |
|
393 else |
|
394 { |
|
395 // This is for vietnamese, iReplaced can be non-zero only for vietnamese. |
|
396 if (iExtension->iReplaced != 0 && aKey == EPtiKeyQwertyW) |
|
397 { |
|
398 if (ret == KPtiUWithAHorn) |
|
399 { |
|
400 ret = 'w'; |
|
401 } |
|
402 else |
|
403 { |
|
404 ret = 'W'; |
|
405 } |
|
406 iLastKey = EPtiKeyNone; |
|
407 iExtension->iLastChar = 0; |
|
408 } |
|
409 else |
|
410 { |
|
411 /* In case of FnLower Case, Vowel Sequence shouldnt be constructed, instead we should clear the Vowel Sequence */ |
|
412 if(aCase != EPtiCaseFnLower) |
|
413 { |
|
414 iLastKey = aKey; |
|
415 iExtension->iLastChar = ret; |
|
416 } |
|
417 else |
|
418 { |
|
419 ClearVowelSequence(); |
|
420 ClearLastChar(); |
|
421 } |
|
422 } |
|
423 } |
|
424 |
|
425 if (aCase == EPtiCaseUpper || aCase == EPtiCaseChrUpper) |
|
426 { |
|
427 SetFlag(EPrevKeyInUpperCase); |
|
428 } |
|
429 else |
|
430 { |
|
431 ResetFlag(EPrevKeyInUpperCase); |
|
432 } |
|
433 |
|
434 return ret; |
|
435 } |
|
436 |
|
437 |
|
438 // --------------------------------------------------------------------------- |
|
439 // CPtiQwertyKeyMappings::GetDeadKeyChar |
|
440 // |
|
441 // --------------------------------------------------------------------------- |
|
442 // |
|
443 TUint16 CPtiQwertyKeyMappings::GetDeadKeyChar(TPtiKey aKey, TPtiTextCase aCase) |
|
444 { |
|
445 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
446 |
|
447 TUint deadIndex = DeadKeyIndex(iDeadKey); |
|
448 TPtrC deadKeyData = iKeyMapData->DeadKeyDataForKey(iKeyboardType, aKey, aCase); |
|
449 if (deadIndex > 0 && deadIndex <= deadKeyData.Length()) |
|
450 { |
|
451 if (deadKeyData[deadIndex - 1] != KEmptyDeadKeySlotMarker) |
|
452 { |
|
453 return deadKeyData[deadIndex - 1]; |
|
454 } |
|
455 } |
|
456 |
|
457 return 0; |
|
458 } |
|
459 |
|
460 |
|
461 // --------------------------------------------------------------------------- |
|
462 // CPtiQwertyKeyMappings::NextChar |
|
463 // |
|
464 // --------------------------------------------------------------------------- |
|
465 // |
|
466 TUint16 CPtiQwertyKeyMappings::NextChar(TPtiTextCase aCase) |
|
467 { |
|
468 __ASSERT_DEBUG(iExtension, User::Panic(KPtiNoExtensionPanic, KErrCorrupt)); |
|
469 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
470 |
|
471 TPtrC keyData = DataForKeyLocal(iCurrentKey, aCase, EPtiEngineQwerty); |
|
472 |
|
473 iCurrentChar++; |
|
474 if (iCurrentChar >= keyData.Length()) |
|
475 { |
|
476 iCurrentChar = 0; |
|
477 if (aCase == EPtiCaseChrLower || aCase == EPtiCaseChrUpper) |
|
478 { |
|
479 iCurrentChar++; |
|
480 if (iCurrentChar >= keyData.Length()) |
|
481 { |
|
482 iCurrentChar = 0; |
|
483 return 0; |
|
484 } |
|
485 } |
|
486 } |
|
487 |
|
488 if (keyData.Length() == 0) |
|
489 { |
|
490 return 0; |
|
491 } |
|
492 |
|
493 if (iFlags & ETrackVietnameseToneMarksAndVowels) |
|
494 { |
|
495 iExtension->iLastChar = keyData[iCurrentChar]; |
|
496 } |
|
497 |
|
498 return keyData[iCurrentChar]; |
|
499 } |
|
500 |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // CPtiQwertyKeyMappings::ReplaceKeyMapL |
|
504 // |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 EXPORT_C TInt CPtiQwertyKeyMappings::ReplaceKeyMapL(TPtiKey aKey, TDesC& aMap, |
|
508 TPtiTextCase aCase) |
|
509 { |
|
510 __ASSERT_DEBUG(iExtension, User::Panic(KPtiNoExtensionPanic, KErrCorrupt)); |
|
511 |
|
512 if (iCurrentKey == aKey) |
|
513 { |
|
514 iCurrentKey = EPtiKeyNone; |
|
515 iCurrentChar = 0; |
|
516 iDeadKey = 0; |
|
517 iVowelSeqResult = 0; |
|
518 iExtension->iLastToneKey = EPtiKeyNone; |
|
519 } |
|
520 |
|
521 if (aCase == EPtiCaseChrLower) |
|
522 { |
|
523 aCase = EPtiCaseLower; |
|
524 } |
|
525 else if (aCase == EPtiCaseChrUpper) |
|
526 { |
|
527 aCase = EPtiCaseUpper; |
|
528 } |
|
529 |
|
530 ReplaceKeyMapLocalL(aKey, aMap, aCase, EPtiEngineQwerty); |
|
531 |
|
532 return KErrNone; |
|
533 } |
|
534 |
|
535 |
|
536 // --------------------------------------------------------------------------- |
|
537 // CPtiQwertyKeyMappings::GetCharForMode |
|
538 // |
|
539 // --------------------------------------------------------------------------- |
|
540 // |
|
541 TUint16 CPtiQwertyKeyMappings::GetCharForMode(TPtiEngineInputMode aMode, TPtrC aChars, TBool aSkipFirst) |
|
542 { |
|
543 for (TInt i = 0; i < aChars.Length(); i++) |
|
544 { |
|
545 if (!IsModeControlChar(aChars[i])) |
|
546 { |
|
547 if (i == 0 && aSkipFirst && aChars.Length() > 1) |
|
548 { |
|
549 iCurrentChar++; |
|
550 continue; |
|
551 } |
|
552 return aChars[i]; |
|
553 } |
|
554 if (DoesModeCharMatchToInputMode(aChars[i], aMode)) |
|
555 { |
|
556 if (i + 1 >= aChars.Length()) |
|
557 { |
|
558 return 0; |
|
559 } |
|
560 return aChars[i + 1]; |
|
561 } |
|
562 i++; // Wrong mode, skip char |
|
563 } |
|
564 |
|
565 return 0; |
|
566 } |
|
567 |
|
568 |
|
569 // --------------------------------------------------------------------------- |
|
570 // CPtiQwertyKeyMappings::NextKey |
|
571 // |
|
572 // --------------------------------------------------------------------------- |
|
573 // |
|
574 EXPORT_C TUint16 CPtiQwertyKeyMappings::NextKey(TPtiKey aKey, TBool &aAppend, |
|
575 TPtiTextCase aCase) |
|
576 { |
|
577 if (CurrentKey() == aKey) |
|
578 { |
|
579 aAppend = EFalse; |
|
580 return NextChar(aCase); |
|
581 } |
|
582 |
|
583 return StartMapping(aKey, aCase); |
|
584 } |
|
585 |
|
586 |
|
587 // --------------------------------------------------------------------------- |
|
588 // CPtiQwertyKeyMappings::KeyForCharacter |
|
589 // |
|
590 // --------------------------------------------------------------------------- |
|
591 // |
|
592 EXPORT_C TPtiKey CPtiQwertyKeyMappings::KeyForCharacter(TUint16 aChar) |
|
593 { |
|
594 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
595 |
|
596 TInt numBindItems = 0; |
|
597 const TPtiKeyBinding* bindings = iKeyMapData->KeyBindingTable(iKeyboardType, numBindItems); |
|
598 |
|
599 TPtiTextCase textCase; |
|
600 TPtiKey key; |
|
601 for (TInt i = 0; i < numBindItems; i++) |
|
602 { |
|
603 key = iKeyMapData->KeyForBindingTableIndex(iKeyboardType, i, textCase); |
|
604 if (key != EPtiKeyNone) |
|
605 { |
|
606 TPtrC keyData = DataForKeyLocal(key, textCase, EPtiEngineQwerty); |
|
607 if (keyData.Locate(aChar) != KErrNotFound) |
|
608 { |
|
609 return key; |
|
610 } |
|
611 } |
|
612 } |
|
613 |
|
614 return EPtiKeyNone; |
|
615 } |
|
616 |
|
617 |
|
618 // --------------------------------------------------------------------------- |
|
619 // CPtiQwertyKeyMappings::KeyCodeToInternal |
|
620 // |
|
621 // --------------------------------------------------------------------------- |
|
622 // |
|
623 void CPtiQwertyKeyMappings::KeyCodeToInternal(TPtiKey aKey) |
|
624 { |
|
625 iCurrentKey = aKey; |
|
626 } |
|
627 |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // CPtiQwertyKeyMappings::GetDataForKey |
|
631 // |
|
632 // --------------------------------------------------------------------------- |
|
633 // |
|
634 EXPORT_C void CPtiQwertyKeyMappings::GetDataForKey(TPtiKey aKey, TDes& aResult, |
|
635 TPtiTextCase aCase) |
|
636 { |
|
637 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
638 |
|
639 aResult.Copy(DataForKeyLocal(aKey, aCase, EPtiEngineQwerty).Left(aResult.MaxLength())); |
|
640 } |
|
641 |
|
642 |
|
643 // --------------------------------------------------------------------------- |
|
644 // CPtiQwertyKeyMappings::DoesModeCharMatchToInputMode |
|
645 // |
|
646 // --------------------------------------------------------------------------- |
|
647 // |
|
648 TBool CPtiQwertyKeyMappings::DoesModeCharMatchToInputMode(TUint16 aChar, |
|
649 TPtiEngineInputMode aMode) const |
|
650 { |
|
651 switch (aMode) |
|
652 { |
|
653 case EPtiEnginePinyin: |
|
654 case EPtiEnginePinyinQwerty: |
|
655 case EPtiEnginePinyinPhraseQwerty: |
|
656 if (aChar == KPtiPinyinMarker) |
|
657 { |
|
658 return ETrue; |
|
659 } |
|
660 break; |
|
661 case EPtiEngineStroke: |
|
662 case EPtiEngineStrokeQwerty: |
|
663 case EPtiEngineStrokePhraseQwerty: |
|
664 if (aChar == KPtiStrokeMarker) |
|
665 { |
|
666 return ETrue; |
|
667 } |
|
668 break; |
|
669 case EPtiEngineZhuyin: |
|
670 case EPtiEngineZhuyinQwerty: |
|
671 case EPtiEngineZhuyinPhraseQwerty: |
|
672 case EPtiEngineInputModeZhuyinMiniQwertyFind: |
|
673 if (aChar == KPtiZhuyinMarker) |
|
674 { |
|
675 return ETrue; |
|
676 } |
|
677 break; |
|
678 case EPtiEngineNormalCangjieQwerty: |
|
679 case EPtiEngineEasyCangjieQwerty: |
|
680 case EPtiEngineAdvCangjieQwerty: |
|
681 if (aChar == KPtiCangjieMarker) |
|
682 { |
|
683 return ETrue; |
|
684 } |
|
685 break; |
|
686 default: |
|
687 break; |
|
688 } |
|
689 |
|
690 return EFalse; |
|
691 } |
|
692 |
|
693 |
|
694 // --------------------------------------------------------------------------- |
|
695 // CPtiQwertyKeyMappings::VowelSequence |
|
696 // |
|
697 // --------------------------------------------------------------------------- |
|
698 // |
|
699 TUint16 CPtiQwertyKeyMappings::VowelSequence(TPtiKey aKey1, TPtiKey aKey2, |
|
700 TPtiTextCase aCase) const |
|
701 { |
|
702 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
703 |
|
704 TPtrC keyData1 = DataForKeyLocal((TPtiKey)aKey1, aCase, EPtiEngineQwerty); |
|
705 TPtrC keyData2 = DataForKeyLocal((TPtiKey)aKey2, aCase, EPtiEngineQwerty); |
|
706 |
|
707 // This method tracks Vietnamese vowel sequences. |
|
708 TInt numVowelSeqs = 0; |
|
709 const TVowelSequence* vowelSeqs = iKeyMapData->VowelSequenceTable(iKeyboardType, numVowelSeqs); |
|
710 |
|
711 TInt shift = (aCase == EPtiCaseLower ? 0 : 1); |
|
712 |
|
713 // This loop is to support keylayouts which |
|
714 // can have numeric scancodes |
|
715 if( keyData1.Length() > 0 && keyData2.Length() > 0 ) |
|
716 { |
|
717 // convert to caps to compare with vowel data |
|
718 TChar data1 = keyData1[0]; |
|
719 data1 = data1.GetUpperCase(); |
|
720 |
|
721 TChar data2 = keyData2[0]; |
|
722 data2 = data2.GetUpperCase(); |
|
723 |
|
724 for (TInt i = 0; i < numVowelSeqs; i++) |
|
725 { |
|
726 if (((TPtiKey)(TUint)data1 == (TUint)vowelSeqs[i].iFirst) && |
|
727 ((TPtiKey)(TUint)data2 == (TUint)vowelSeqs[i].iSecond)) |
|
728 { |
|
729 return vowelSeqs[i].iChars[shift]; |
|
730 } |
|
731 } |
|
732 } |
|
733 |
|
734 return 0; |
|
735 } |
|
736 |
|
737 |
|
738 // --------------------------------------------------------------------------- |
|
739 // CPtiQwertyKeyMappings::RepeatingVowelSequence |
|
740 // |
|
741 // --------------------------------------------------------------------------- |
|
742 // |
|
743 TUint16 CPtiQwertyKeyMappings::RepeatingVowelSequence(TPtiKey aKey) |
|
744 { |
|
745 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
746 |
|
747 TPtrC keyData = DataForKeyLocal((TPtiKey)aKey, EPtiCaseUpper, EPtiEngineQwerty); |
|
748 if( keyData.Length() > 0 ) |
|
749 { |
|
750 TChar data = keyData[0]; |
|
751 aKey = (TPtiKey)(TUint)data; |
|
752 } |
|
753 |
|
754 TInt numVowelSeqs = 0; |
|
755 const TVowelSequence* vowelSeqs = iKeyMapData->VowelSequenceTable(iKeyboardType, numVowelSeqs); |
|
756 |
|
757 for (TInt i = 0; i < numVowelSeqs; i++) |
|
758 { |
|
759 if (vowelSeqs[i].iSecond == aKey) |
|
760 { |
|
761 if (iVowelSeqResult == vowelSeqs[i].iChars[0] || |
|
762 iVowelSeqResult == vowelSeqs[i].iChars[1]) |
|
763 { |
|
764 return vowelSeqs[i].iFirst; |
|
765 } |
|
766 } |
|
767 } |
|
768 |
|
769 return 0; |
|
770 } |
|
771 |
|
772 |
|
773 // --------------------------------------------------------------------------- |
|
774 // CPtiQwertyKeyMappings::VowelSeqRootKey |
|
775 // |
|
776 // --------------------------------------------------------------------------- |
|
777 // |
|
778 TPtiKey CPtiQwertyKeyMappings::VowelSeqRootKey(TUint16 aChar) |
|
779 { |
|
780 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
781 |
|
782 TInt numVowelSeqs = 0; |
|
783 const TVowelSequence* vowelSeqs = iKeyMapData->VowelSequenceTable(iKeyboardType, numVowelSeqs); |
|
784 |
|
785 for (TInt i = 0; i < numVowelSeqs; i++) |
|
786 { |
|
787 if (vowelSeqs[i].iChars[0] == aChar || |
|
788 vowelSeqs[i].iChars[1] == aChar) |
|
789 { |
|
790 return vowelSeqs[i].iFirst; |
|
791 } |
|
792 } |
|
793 |
|
794 return EPtiKeyNone; |
|
795 } |
|
796 |
|
797 |
|
798 // --------------------------------------------------------------------------- |
|
799 // CPtiQwertyKeyMappings::VietnameseToneMark |
|
800 // |
|
801 // --------------------------------------------------------------------------- |
|
802 // |
|
803 TUint16 CPtiQwertyKeyMappings::VietnameseToneMark(TUint16 aPrevChar, TPtiKey aKey) |
|
804 { |
|
805 __ASSERT_DEBUG(iExtension, User::Panic(KPtiNoExtensionPanic, KErrCorrupt)); |
|
806 |
|
807 TPtrC keyData = DataForKeyLocal((TPtiKey)aKey, EPtiCaseUpper, EPtiEngineQwerty); |
|
808 |
|
809 if( keyData.Length() > 0 ) |
|
810 { |
|
811 TChar data = keyData[0]; |
|
812 aKey = (TPtiKey)(TUint)data; |
|
813 } |
|
814 |
|
815 TInt toneIndex = 0; |
|
816 |
|
817 for (; toneIndex < KNumVietnameseToneMarks; toneIndex++) |
|
818 { |
|
819 if (aKey == vietnameseToneMarkKeys[toneIndex]) |
|
820 { |
|
821 if (aKey == (TPtiKey)iExtension->iLastTone) |
|
822 { |
|
823 return 0; |
|
824 } |
|
825 break; |
|
826 } |
|
827 } |
|
828 |
|
829 if (toneIndex >= KNumVietnameseToneMarks) |
|
830 { |
|
831 return 0; |
|
832 } |
|
833 |
|
834 for (TInt i = 0; i < KNumVietnameseToneMarkDataEntries; i++) |
|
835 { |
|
836 if (vietnameseToneMarkData[i].iBaseChar == aPrevChar) |
|
837 { |
|
838 iExtension->iLastTone = (TInt16)aKey; |
|
839 return vietnameseToneMarkData[i].iToneData[toneIndex]; |
|
840 } |
|
841 } |
|
842 |
|
843 return 0; |
|
844 } |
|
845 |
|
846 |
|
847 // --------------------------------------------------------------------------- |
|
848 // CPtiQwertyKeyMappings::GetAll |
|
849 // |
|
850 // --------------------------------------------------------------------------- |
|
851 // |
|
852 TPtrC CPtiQwertyKeyMappings::GetAll(TPtiTextCase aCase) |
|
853 { |
|
854 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
855 |
|
856 TPtrC keyData = DataForKeyLocal((TPtiKey)iCurrentKey, aCase, EPtiEngineQwerty); |
|
857 if (keyData.Length() >= 1) |
|
858 { |
|
859 // return all characters excluding the marker character. |
|
860 return TPtrC(keyData.Mid(1)); |
|
861 } |
|
862 |
|
863 return TPtrC(); |
|
864 } |
|
865 |
|
866 |
|
867 // --------------------------------------------------------------------------- |
|
868 // CPtiQwertyKeyMappings::GetNumericModeKeysFromDataL |
|
869 // |
|
870 // --------------------------------------------------------------------------- |
|
871 // |
|
872 void CPtiQwertyKeyMappings::GetNumericModeKeysFromDataL(RArray<TPtiNumericKeyBinding>& aResult) |
|
873 { |
|
874 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
875 |
|
876 TInt numEntries = 0; |
|
877 const TPtiNumericKeyBinding* dataEntries = iKeyMapData->NumericModeKeysTable(iKeyboardType, |
|
878 numEntries); |
|
879 |
|
880 for (TInt i = 0; i < numEntries; i++) |
|
881 { |
|
882 User::LeaveIfError(aResult.Append(dataEntries[i])); |
|
883 } |
|
884 } |
|
885 |
|
886 |
|
887 // --------------------------------------------------------------------------- |
|
888 // CPtiQwertyKeyMappings::WriteData (DEPRECATED) |
|
889 // |
|
890 // --------------------------------------------------------------------------- |
|
891 // |
|
892 TInt CPtiQwertyKeyMappings::WriteData(TInt16*) |
|
893 { |
|
894 return 0; |
|
895 } |
|
896 |
|
897 |
|
898 // --------------------------------------------------------------------------- |
|
899 // CPtiQwertyKeyMappings::ChunkDataSize (DEPRECATED) |
|
900 // |
|
901 // --------------------------------------------------------------------------- |
|
902 // |
|
903 TInt CPtiQwertyKeyMappings::ChunkDataSize() const |
|
904 { |
|
905 return 0; |
|
906 } |
|
907 |
|
908 |
|
909 // --------------------------------------------------------------------------- |
|
910 // CPtiQwertyKeyMappings::SetKeyboardType |
|
911 // |
|
912 // --------------------------------------------------------------------------- |
|
913 // |
|
914 EXPORT_C TInt CPtiQwertyKeyMappings::SetKeyboardType(TPtiKeyboardType aKeyboardType) |
|
915 { |
|
916 __ASSERT_DEBUG(iKeyMapData, User::Panic(KPtiNoQwertyKeyMapDataPanic, KErrCorrupt)); |
|
917 |
|
918 TInt sizeTmp = 0; |
|
919 if (!iKeyMapData->KeyData(aKeyboardType, sizeTmp)) |
|
920 { |
|
921 return KErrNotSupported; |
|
922 } |
|
923 |
|
924 iKeyboardType = aKeyboardType; |
|
925 return KErrNone; |
|
926 } |
|
927 |
|
928 |
|
929 // --------------------------------------------------------------------------- |
|
930 // CPtiQwertyKeyMappings::HasDataBlockForKeyboardType |
|
931 // |
|
932 // --------------------------------------------------------------------------- |
|
933 // |
|
934 EXPORT_C TBool CPtiQwertyKeyMappings::HasDataBlockForKeyboardType(TPtiKeyboardType aKeyboardType) const |
|
935 { |
|
936 TInt sizeTmp = 0; |
|
937 if (iKeyMapData->KeyData(aKeyboardType, sizeTmp)) |
|
938 { |
|
939 return ETrue; |
|
940 } |
|
941 |
|
942 return EFalse; |
|
943 } |
|
944 |
|
945 // End of file |