|
1 /* |
|
2 * Copyright (c) 2007 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: Retrieves the character map for each of the numeric keys. |
|
15 * Uses services provided by the PTI Engine. |
|
16 * |
|
17 */ |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "CPcsAlgorithm2.h" |
|
22 #include "CPcsAlgorithm2Utils.h" |
|
23 #include "FindUtilChineseECE.h" |
|
24 #include "CPcsDebug.h" |
|
25 #include "CPcsKeyMap.h" |
|
26 #include "CPsQueryItem.h" |
|
27 #include <PtiEngine.h> |
|
28 #include <PtiKeyMapData.h> |
|
29 #include <bldvariant.hrh> |
|
30 #include <AknFepInternalCRKeys.h> |
|
31 |
|
32 |
|
33 // Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 #ifdef _DEBUG |
|
37 enum TPanicCode |
|
38 { |
|
39 EPanicPreCond_MultipleSingleCharMatching = 1, |
|
40 EPanicPreCond_MultipleUIPriorityMatching = 2, |
|
41 EPanicPreCond_MultipleEnglishPriorityMatching = 3, |
|
42 EPanicPreCond_MultipleOthersPriorityMatching = 4, |
|
43 EPanic_OverflowInPoolIndex = 5, |
|
44 EPanic_InvalidKeyboardType = 6 |
|
45 }; |
|
46 |
|
47 void Panic(TInt aReason) |
|
48 { |
|
49 _LIT(KPanicText, "CPcsKeyMap"); |
|
50 User::Panic(KPanicText, aReason); |
|
51 } |
|
52 #endif // DEBUG |
|
53 |
|
54 } // namespace |
|
55 |
|
56 |
|
57 // ============================== MEMBER FUNCTIONS ============================ |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CPcsKeyMap::NewL |
|
61 // Two Phase Construction |
|
62 // ---------------------------------------------------------------------------- |
|
63 CPcsKeyMap* CPcsKeyMap::NewL(CPcsAlgorithm2* aAlgorithm) |
|
64 { |
|
65 PRINT ( _L("Enter CPcsKeyMap::NewL") ); |
|
66 |
|
67 CPcsKeyMap* self = new (ELeave) CPcsKeyMap(); |
|
68 CleanupStack::PushL(self); |
|
69 self->ConstructL(aAlgorithm); |
|
70 CleanupStack::Pop(self); |
|
71 |
|
72 PRINT ( _L("End CPcsKeyMap::NewL") ); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CPcsKeyMap::CPcsKeyMap |
|
79 // Constructor |
|
80 // ---------------------------------------------------------------------------- |
|
81 CPcsKeyMap::CPcsKeyMap() |
|
82 { |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CPcsKeyMap::ConstructL |
|
87 // 2nd Phase Constructor |
|
88 // ---------------------------------------------------------------------------- |
|
89 void CPcsKeyMap::ConstructL(CPcsAlgorithm2* aAlgorithm) |
|
90 { |
|
91 iLanguageNotSupported.Append(ELangJapanese); |
|
92 iLanguageNotSupported.Append(ELangKorean); |
|
93 |
|
94 iAlgorithm = aAlgorithm; |
|
95 iPtiEngine = CPtiEngine::NewL(); |
|
96 |
|
97 SetupKeyboardTypesL(); |
|
98 ConstructKeymapL(); |
|
99 SetSpaceAndZeroOnSameKey(); |
|
100 } |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CPcsKeyMap::ReconstructKeymapL |
|
104 // When the writing language is changed, the keymap needs reconstruct. |
|
105 // ---------------------------------------------------------------------------- |
|
106 void CPcsKeyMap::ReconstructKeymapL() |
|
107 { |
|
108 // Clear the keymap data array first when reconstruct the keymap. |
|
109 ResetKeyMap(); |
|
110 |
|
111 // Always add English mappings first |
|
112 AddKeyMapforConcreteKeyboardL( ELangEnglish ); |
|
113 |
|
114 // Then append the mappings of the current input language |
|
115 TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage(); |
|
116 if ( lang != ELangEnglish && IsLanguageSupportedL(lang) ) |
|
117 { |
|
118 AddKeyMapforConcreteKeyboardL( lang ); |
|
119 } |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CPcsKeyMap::ConstructKeymapL |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 void CPcsKeyMap::ConstructKeymapL() |
|
127 { |
|
128 ConstructConcreteKeyMapL(); |
|
129 |
|
130 // Always add English mappings first |
|
131 AddKeyMapforConcreteKeyboardL( ELangEnglish ); |
|
132 |
|
133 // Then append the mappings of the current input language |
|
134 TLanguage lang = iAlgorithm->FindUtilECE()->CurrentInputLanguage(); |
|
135 if ( lang != ELangEnglish && IsLanguageSupportedL(lang) ) |
|
136 { |
|
137 AddKeyMapforConcreteKeyboardL( lang ); |
|
138 } |
|
139 |
|
140 PRINT ( _L("----------------------------------------")); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // CPcsKeyMap::SetupKeyboardTypesL |
|
145 // Initialise the keyboard type variables |
|
146 // ---------------------------------------------------------------------------- |
|
147 void CPcsKeyMap::SetupKeyboardTypesL() |
|
148 { |
|
149 TInt physicalKeyboard = 0; |
|
150 CRepository* aknFepRepository = CRepository::NewL( KCRUidAknFep ); |
|
151 aknFepRepository->Get( KAknFepPhysicalKeyboards, physicalKeyboard ); |
|
152 delete aknFepRepository; |
|
153 |
|
154 PRINT1 ( _L("CPcsKeyMap::ConstructL: Physical keyboard support flag = 0x%02X"), physicalKeyboard ); |
|
155 |
|
156 // Constants follow the definition of KAknFepPhysicalKeyboards |
|
157 const TInt KPtiKeyboard12Key = 0x01; |
|
158 const TInt KPtiKeyboardQwerty4x12 = 0x02; |
|
159 const TInt KPtiKeyboardQwerty4x10 = 0x04; |
|
160 const TInt KPtiKeyboardQwerty3x11 = 0x08; |
|
161 const TInt KPtiKeyboardHalfQwerty = 0x10; |
|
162 const TInt KPtiKeyboardCustomQwerty = 0x20; |
|
163 |
|
164 // Setup ITU-T mode first. |
|
165 // Use always 12-key mode since all the supported devices should have at least |
|
166 // virtual ITU-T available. |
|
167 iItutKeyboardType = EPtiKeyboard12Key; |
|
168 // TODO: ITU-T type could be set to "none" if device does not have either |
|
169 // virtual keypad or hardware ITU-T available. This could be decided according |
|
170 // some cenrep value, feature flag, device model, or platform version. |
|
171 |
|
172 // Then setup QWERTY mode. On real-life devices there should never |
|
173 // be more than one QWERTY keyboard available but on emulator there can be several. |
|
174 // Use the first one found in the following precedence |
|
175 if ( physicalKeyboard & KPtiKeyboardQwerty3x11 ) |
|
176 { |
|
177 iQwertyKeyboardType = EPtiKeyboardQwerty3x11; |
|
178 } |
|
179 else if ( physicalKeyboard & KPtiKeyboardQwerty4x10 ) |
|
180 { |
|
181 iQwertyKeyboardType = EPtiKeyboardQwerty4x10; |
|
182 } |
|
183 else if ( physicalKeyboard & KPtiKeyboardQwerty4x12 ) |
|
184 { |
|
185 iQwertyKeyboardType = EPtiKeyboardQwerty4x12; |
|
186 } |
|
187 else if ( physicalKeyboard & KPtiKeyboardCustomQwerty ) |
|
188 { |
|
189 iQwertyKeyboardType = EPtiKeyboardCustomQwerty; |
|
190 } |
|
191 else if ( physicalKeyboard & KPtiKeyboardHalfQwerty ) |
|
192 { |
|
193 iQwertyKeyboardType = EPtiKeyboardHalfQwerty; |
|
194 } |
|
195 else |
|
196 { |
|
197 iQwertyKeyboardType = EPtiKeyboardNone; |
|
198 } |
|
199 |
|
200 // Decide, which keyboard is used for the "default" matching mode. |
|
201 // If there is physical ITU-T available, or there's no physical QWERTY, |
|
202 // then ITU-T is default. |
|
203 iItutIsDefault = (physicalKeyboard & KPtiKeyboard12Key) || |
|
204 (iQwertyKeyboardType == EPtiKeyboardNone); |
|
205 |
|
206 PRINT1 ( _L("CPcsKeyMap::ConstructL: ITU-T Keyboard chosen for Predictive Search = %d"), iItutKeyboardType ); |
|
207 PRINT1 ( _L("CPcsKeyMap::ConstructL: QWERTY Keyboard chosen for Predictive Search = %d"), iQwertyKeyboardType ); |
|
208 } |
|
209 |
|
210 |
|
211 // ---------------------------------------------------------------------------- |
|
212 // CPcsKeyMap::ConstructConcreteKeyMapL |
|
213 // |
|
214 // ---------------------------------------------------------------------------- |
|
215 void CPcsKeyMap::ConstructConcreteKeyMapL() |
|
216 { |
|
217 if ( iItutKeyboardType != EPtiKeyboardNone ) |
|
218 { |
|
219 // Construct for Itut keyboard by default |
|
220 PRINT ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for ITU-T")); |
|
221 ConstructForItutKeyboardL(); |
|
222 } |
|
223 if ( iQwertyKeyboardType != EPtiKeyboardNone ) |
|
224 { |
|
225 // Construct for any QWERTY keyboard |
|
226 PRINT1 ( _L("CPcsKeyMap::ConstructConcreteKeyMapL: Construct keymap for QWERTY keyboard type %d"), |
|
227 iQwertyKeyboardType ); |
|
228 ConstructForQwertyKeyboardL( iQwertyKeyboardType ); |
|
229 } |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // CPcsKeyMap::AddKeyMapforConcreteKeyboardL |
|
234 // |
|
235 // ---------------------------------------------------------------------------- |
|
236 void CPcsKeyMap::AddKeyMapforConcreteKeyboardL( TLanguage aLanguage ) |
|
237 { |
|
238 if ( iItutKeyboardType != EPtiKeyboardNone ) |
|
239 { |
|
240 AddKeyMapforItutL( aLanguage ); |
|
241 } |
|
242 |
|
243 if ( iQwertyKeyboardType != EPtiKeyboardNone ) |
|
244 { |
|
245 AddKeyMapForQwertyKeyboardL( aLanguage, iQwertyKeyboardType ); |
|
246 } |
|
247 } |
|
248 |
|
249 // ---------------------------------------------------------------------------- |
|
250 // CPcsKeyMap::ResetKeyMap |
|
251 // |
|
252 // ---------------------------------------------------------------------------- |
|
253 void CPcsKeyMap::ResetKeyMap() |
|
254 { |
|
255 const TInt ItutKeyMappingsCount = iItutKeyMappings.Count(); |
|
256 const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count(); |
|
257 for (TInt i = 0; i < ItutKeyMappingsCount; i++) |
|
258 { |
|
259 iItutKeyMappings[i]->iKeyMappingArray.Reset(); |
|
260 } |
|
261 for (TInt i = 0; i < qwertyKeyMappingsCount; i++) |
|
262 { |
|
263 iQwertyKeyMappings[i]->iKeyMappingArray.Reset(); |
|
264 } |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // CPcsKeyMap::~CPcsKeyMap |
|
269 // Destructor |
|
270 // ---------------------------------------------------------------------------- |
|
271 CPcsKeyMap::~CPcsKeyMap() |
|
272 { |
|
273 ResetKeyMap(); |
|
274 |
|
275 // Cleanup local arrays |
|
276 iLanguageNotSupported.Reset(); |
|
277 iItutKeyMappings.ResetAndDestroy(); |
|
278 iItutKeys.Close(); |
|
279 iQwertyKeyMappings.ResetAndDestroy(); |
|
280 iQwertyKeys.Close(); |
|
281 delete iPtiEngine; |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // CPcsKeyMap::GetMixedKeyStringForQueryL |
|
286 // aDestStr will have the length as the number of items in aSrcQuery. |
|
287 // ---------------------------------------------------------------------------- |
|
288 void CPcsKeyMap::GetMixedKeyStringForQueryL( |
|
289 CPsQuery& aSrcQuery, TDes& aDestStr) const |
|
290 { |
|
291 PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForQueryL") ); |
|
292 |
|
293 GetMixedKeyStringForDataL( aSrcQuery, aSrcQuery.QueryAsStringLC(), aDestStr ); |
|
294 CleanupStack::PopAndDestroy(); //result of QueryAsStringLC |
|
295 |
|
296 PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForQueryL") ); |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // CPcsKeyMap::GetMixedKeyStringForDataL |
|
301 // aDestStr will have the same length as aSrcData. aSrcQuery can be shorter. |
|
302 // ---------------------------------------------------------------------------- |
|
303 void CPcsKeyMap::GetMixedKeyStringForDataL( |
|
304 CPsQuery& aSrcQuery, const TDesC& aSrcData, TDes& aDestStr) const |
|
305 { |
|
306 PRINT ( _L("Enter CPcsKeyMap::GetMixedKeyStringForDataL") ); |
|
307 |
|
308 const TInt srcDataLength = aSrcData.Length(); |
|
309 for ( TInt i = 0; i < srcDataLength; ++i ) |
|
310 { |
|
311 TChar character( aSrcData[i] ); |
|
312 character.LowerCase(); |
|
313 if ( i < aSrcQuery.Count() ) |
|
314 { |
|
315 CPsQueryItem& currentItem = aSrcQuery.GetItemAtL(i); |
|
316 TKeyboardModes curMode = ResolveKeyboardMode( currentItem.Mode() ); |
|
317 TPtiKey key = KeyForCharacter( aSrcData[i], curMode ); |
|
318 // If a character is not mapped to any key or it's entered in non-predictive mode, |
|
319 // then append the character as exact. |
|
320 if ( EPtiKeyNone == key ) |
|
321 { |
|
322 aDestStr.Append( character ); |
|
323 } |
|
324 else |
|
325 { |
|
326 aDestStr.Append( DefaultCharForKey(key, curMode) ); |
|
327 } |
|
328 } |
|
329 else |
|
330 { |
|
331 // characters over query length are taken as exact |
|
332 aDestStr.Append( character ); |
|
333 } |
|
334 } |
|
335 |
|
336 PRINT1 ( _L("CPcsKeyMap::GetMixedKeyStringForDataL: Return string: \"%S\""), |
|
337 &aDestStr ); |
|
338 |
|
339 PRINT ( _L("End CPcsKeyMap::GetMixedKeyStringForDataL") ); |
|
340 } |
|
341 |
|
342 // ---------------------------------------------------------------------------- |
|
343 // CPcsKeyMap::KeyForCharacter |
|
344 // |
|
345 // ---------------------------------------------------------------------------- |
|
346 TPtiKey CPcsKeyMap::KeyForCharacter(TText aChar, TKeyboardModes aKbMode) const |
|
347 { |
|
348 const RPointerArray<TKeyMappingData>* keyMappings = KeyMappings( aKbMode ); |
|
349 |
|
350 // Don't return any key in the exact mode |
|
351 if ( !keyMappings ) |
|
352 { |
|
353 return EPtiKeyNone; |
|
354 } |
|
355 |
|
356 TInt index = KErrNotFound; |
|
357 |
|
358 TText lChar = User::LowerCase(aChar); |
|
359 |
|
360 const TInt count = keyMappings->Count() - 1; |
|
361 |
|
362 for (TInt i = 0; i < count; i++) |
|
363 { |
|
364 index = (*keyMappings)[i]->iKeyMappingArray.Find(lChar); |
|
365 if (index != KErrNotFound) |
|
366 { |
|
367 return (*keyMappings)[i]->iKey; |
|
368 } |
|
369 } |
|
370 |
|
371 return EPtiKeyNone; |
|
372 } |
|
373 |
|
374 // ---------------------------------------------------------------------------- |
|
375 // CPcsKeyMap::AddKeyMapForQwertyKeyboardL |
|
376 // |
|
377 // ---------------------------------------------------------------------------- |
|
378 void CPcsKeyMap::AddKeyMapForQwertyKeyboardL(TLanguage aLanguage, TPtiKeyboardType aKbType) |
|
379 { |
|
380 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
381 iPtiEngine->ActivateLanguageL(aLanguage); |
|
382 iPtiEngine->SetKeyboardType(aKbType); |
|
383 |
|
384 // Make a language object based on current language |
|
385 CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( aLanguage )); |
|
386 |
|
387 //Perfrom the key mappings only if the corelanguage is available |
|
388 if (coreLanguage) |
|
389 { |
|
390 // Get the keyboard mappings for the language |
|
391 CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData(); |
|
392 |
|
393 const TInt qwertyKeyMappingsCount = iQwertyKeyMappings.Count() - 1; |
|
394 for (TInt i = 0; i < qwertyKeyMappingsCount; i++) |
|
395 { |
|
396 AddDataForQwertyKeyboardL( ptiKeyMapData, aKbType, |
|
397 iQwertyKeys[i], *(iQwertyKeyMappings[i]) ); |
|
398 } |
|
399 } |
|
400 #endif // RD_INTELLIGENT_TEXT_INPUT |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // CPcsKeyMap::ConstructForQwertyKeyboardL |
|
405 // Destructor |
|
406 // ---------------------------------------------------------------------------- |
|
407 void CPcsKeyMap::ConstructForQwertyKeyboardL(TPtiKeyboardType aKbType) |
|
408 { |
|
409 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
410 CreateKeyListFromKeyBindingTable( iQwertyKeys, aKbType ); |
|
411 |
|
412 // Now add the keymap arrays to hold the keymap data |
|
413 const TInt qwertyKeysCount = iQwertyKeys.Count(); |
|
414 for (TInt i = 0; i < qwertyKeysCount; i++) |
|
415 { |
|
416 TKeyMappingData* keyData = new (ELeave) TKeyMappingData; |
|
417 keyData->iKey = iQwertyKeys[i]; |
|
418 iQwertyKeyMappings.Append(keyData); |
|
419 } |
|
420 |
|
421 PRINT ( _L("----------------------------------------")); |
|
422 #endif //RD_INTELLIGENT_TEXT_INPUT |
|
423 } |
|
424 |
|
425 // ---------------------------------------------------------------------------- |
|
426 // CPcsKeyMap::AddDataForQwertyKeyboardL |
|
427 // |
|
428 // ---------------------------------------------------------------------------- |
|
429 void CPcsKeyMap::AddDataForQwertyKeyboardL(CPtiKeyMapData* aPtiKeyMapData, |
|
430 TPtiKeyboardType aKbType, |
|
431 TPtiKey aKey, |
|
432 TKeyMappingData& aKeyDataList) |
|
433 { |
|
434 #ifdef RD_INTELLIGENT_TEXT_INPUT |
|
435 TPtiTextCase caseArray[] = |
|
436 { |
|
437 EPtiCaseUpper, |
|
438 EPtiCaseLower, |
|
439 EPtiCaseFnLower, |
|
440 EPtiCaseFnUpper, |
|
441 EPtiCaseChrLower, |
|
442 EPtiCaseChrUpper |
|
443 }; |
|
444 |
|
445 for (TInt i = 0; i < sizeof(caseArray) / sizeof(TPtiTextCase); i++) |
|
446 { |
|
447 TPtrC result = aPtiKeyMapData->DataForKey(aKbType, aKey, caseArray[i]); |
|
448 |
|
449 const TInt resultLength = result.Length(); |
|
450 for (TInt j = 0; j < resultLength; j++) |
|
451 aKeyDataList.iKeyMappingArray.Append(result[j]); |
|
452 |
|
453 PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey, &result) |
|
454 } |
|
455 #endif //RD_INTELLIGENT_TEXT_INPUT |
|
456 } |
|
457 |
|
458 // ---------------------------------------------------------------------------- |
|
459 // CPcsKeyMap::ContructForItutKeyboardL |
|
460 // |
|
461 // ---------------------------------------------------------------------------- |
|
462 void CPcsKeyMap::ConstructForItutKeyboardL() |
|
463 { |
|
464 // Add the keys for Pool formation |
|
465 iItutKeys.Append(EPtiKey0); |
|
466 iItutKeys.Append(EPtiKey1); |
|
467 iItutKeys.Append(EPtiKey2); |
|
468 iItutKeys.Append(EPtiKey3); |
|
469 iItutKeys.Append(EPtiKey4); |
|
470 iItutKeys.Append(EPtiKey5); |
|
471 iItutKeys.Append(EPtiKey6); |
|
472 iItutKeys.Append(EPtiKey7); |
|
473 iItutKeys.Append(EPtiKey8); |
|
474 iItutKeys.Append(EPtiKey9); |
|
475 // one additional pool for special characters not mapped too any keys. |
|
476 // This should always be the last one in the arrary |
|
477 iItutKeys.Append(EPtiKeyNone); |
|
478 |
|
479 // Now add the keymap arrays to hold the keymap data |
|
480 const TInt ltutKeysCount = iItutKeys.Count(); |
|
481 for (TInt i = 0; i < ltutKeysCount; i++) |
|
482 { |
|
483 TKeyMappingData *keyData = new (ELeave) TKeyMappingData; |
|
484 keyData->iKey = iItutKeys[i]; |
|
485 iItutKeyMappings.Append(keyData); |
|
486 } |
|
487 |
|
488 PRINT ( _L("----------------------------------------")); |
|
489 } |
|
490 |
|
491 // ---------------------------------------------------------------------------- |
|
492 // CPcsKeyMap::AddKeyMapforItutLanguageL |
|
493 // |
|
494 // ---------------------------------------------------------------------------- |
|
495 void CPcsKeyMap::AddKeyMapforItutL(TLanguage aLanguage) |
|
496 { |
|
497 // Activate given language and get corresponding language object |
|
498 iPtiEngine->ActivateLanguageL(aLanguage); |
|
499 CPtiCoreLanguage* coreLanguage = static_cast<CPtiCoreLanguage*> (iPtiEngine->GetLanguage(aLanguage)); |
|
500 |
|
501 //Perfrom the key mappings only if the corelanguage is available |
|
502 if (coreLanguage) |
|
503 { |
|
504 // Get the keyboard mappings for the language |
|
505 CPtiKeyMapData* ptiKeyMapData = coreLanguage->RawKeyMapData(); |
|
506 |
|
507 const TInt ltutKeyMappingsCount = iItutKeyMappings.Count() - 1; |
|
508 for (TInt i = 0; i < ltutKeyMappingsCount; i++) |
|
509 { |
|
510 AddDataForItutKeyboardL(ptiKeyMapData, iItutKeys[i], *(iItutKeyMappings[i])); |
|
511 } |
|
512 } |
|
513 |
|
514 if ( (aLanguage == ELangPrcChinese || aLanguage == ELangTaiwanChinese || aLanguage == ELangHongKongChinese) && |
|
515 (iAlgorithm->FindUtilECE()->CurrentSearchMethod() == EAdptSearchStroke) ) |
|
516 { |
|
517 (*(iItutKeyMappings[1])).iKeyMappingArray.Append(0x4E00); //heng |
|
518 (*(iItutKeyMappings[2])).iKeyMappingArray.Append(0x4E28); //shu |
|
519 (*(iItutKeyMappings[3])).iKeyMappingArray.Append(0x4E3F); //pie |
|
520 (*(iItutKeyMappings[4])).iKeyMappingArray.Append(0x4E36); //dian |
|
521 (*(iItutKeyMappings[5])).iKeyMappingArray.Append(0x4E5B); //zhe |
|
522 } |
|
523 |
|
524 } |
|
525 // ---------------------------------------------------------------------------- |
|
526 // CPcsKeyMap::AddDataForItutKeyboardL |
|
527 // |
|
528 // ---------------------------------------------------------------------------- |
|
529 void CPcsKeyMap::AddDataForItutKeyboardL(CPtiKeyMapData* aPtiKeyMapData, TPtiKey aKey, TKeyMappingData& aKeyDataList) |
|
530 { |
|
531 TPtiTextCase caseArray[] = { EPtiCaseUpper, EPtiCaseLower }; |
|
532 for (TInt i = 0; i< sizeof(caseArray) / sizeof(TPtiTextCase); i++) |
|
533 { |
|
534 TPtrC result = aPtiKeyMapData->DataForKey(EPtiKeyboard12Key, aKey, caseArray[i]); |
|
535 const TInt resultLength = result.Length(); |
|
536 for (TInt j = 0; j < resultLength; j++) |
|
537 aKeyDataList.iKeyMappingArray.Append(result[j]); |
|
538 PRINT2 ( _L("CPcsKeyMap: Mapping for Key %c = %S"), aKey,&result) |
|
539 } |
|
540 } |
|
541 |
|
542 // ---------------------------------------------------------------------------- |
|
543 // CPcsKeyMap::CreateKeyMapFromKeyBindingTable |
|
544 // |
|
545 // ---------------------------------------------------------------------------- |
|
546 void CPcsKeyMap::CreateKeyListFromKeyBindingTable( RArray<TPtiKey>& aKeyArray, |
|
547 TPtiKeyboardType aKbType ) |
|
548 { |
|
549 PRINT ( _L("Enter CPcsKeyMap::CreateKeyListFromKeyBindingTable") ); |
|
550 |
|
551 // Use Eglish mappings to list the keys on the keyboard |
|
552 TRAP_IGNORE( iPtiEngine->ActivateLanguageL( ELangEnglish ) ); |
|
553 CPtiCoreLanguage* ptiLang = |
|
554 static_cast<CPtiCoreLanguage*>(iPtiEngine->GetLanguage( ELangEnglish )); |
|
555 |
|
556 if (ptiLang) |
|
557 { |
|
558 const CPtiKeyMapData* keyMapData = ptiLang->RawKeyMapData(); |
|
559 const TPtiKeyBinding* table = NULL; |
|
560 TInt numItems = 0; |
|
561 if ( keyMapData ) |
|
562 { |
|
563 table = keyMapData->KeyBindingTable(aKbType, numItems); |
|
564 } |
|
565 else |
|
566 { |
|
567 PRINT( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: #### Failed to get RawKeyMapData ####") ); |
|
568 } |
|
569 |
|
570 PRINT1 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Num of Items in KeyBindingTable is %d"), numItems ); |
|
571 |
|
572 // Get from the key table the keys for constructing the pools |
|
573 if (table) |
|
574 { |
|
575 for (TInt i = 0; i < numItems; i++) |
|
576 { |
|
577 TPtiKey key = (TPtiKey) table[i].iScanCode; |
|
578 // Get all keys with same EPtiCaseLower or EPtiCaseUpper case |
|
579 // Only for one of the casing to avoid repetitions |
|
580 if ( (EPtiKeyNone != key) && (EPtiCaseLower == table[i].iCase) ) |
|
581 { |
|
582 PRINT3 ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: Adding pool %d with key '%c' (0x%02X)"), |
|
583 aKeyArray.Count(), key, key ); |
|
584 aKeyArray.Append( key ); |
|
585 } |
|
586 } |
|
587 } |
|
588 else |
|
589 { |
|
590 PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (KeyBindingTable) #####") ); |
|
591 } |
|
592 } |
|
593 else |
|
594 { |
|
595 PRINT ( _L("CPcsKeyMap::CreateKeyListFromKeyBindingTable: ##### Failed to create Key List (Language) #####") ); |
|
596 } |
|
597 |
|
598 // one additional pool for special characters not mapped too any keys. |
|
599 // This should always be the last one in the arrary |
|
600 aKeyArray.Append(EPtiKeyNone); |
|
601 |
|
602 PRINT ( _L("End CPcsKeyMap::CreateKeyListFromKeyBindingTable") ); |
|
603 } |
|
604 |
|
605 // ---------------------------------------------------------------------------- |
|
606 // CPcsKeyMap::IsLanguageSupportedL |
|
607 // Returns ETrue if this language is supported |
|
608 // ---------------------------------------------------------------------------- |
|
609 TBool CPcsKeyMap::IsLanguageSupportedL(TUint32 aLang) |
|
610 { |
|
611 |
|
612 TBool flag = ETrue; |
|
613 const TInt languageNotSupportedCount = iLanguageNotSupported.Count(); |
|
614 for (TInt i = 0; i < languageNotSupportedCount; i++) |
|
615 { |
|
616 if (iLanguageNotSupported[i] == aLang) |
|
617 { |
|
618 flag = EFalse; |
|
619 } |
|
620 } |
|
621 |
|
622 return flag; |
|
623 } |
|
624 |
|
625 // ---------------------------------------------------------------------------- |
|
626 // CPcsKeyMap::PoolIdForKey |
|
627 // |
|
628 // ---------------------------------------------------------------------------- |
|
629 TInt CPcsKeyMap::PoolIdForKey(TPtiKey aKey, TKeyboardModes aKbMode) const |
|
630 { |
|
631 __ASSERT_DEBUG( (aKbMode==EPredictiveItuT || aKbMode==EPredictiveQwerty), |
|
632 Panic(EPanic_InvalidKeyboardType) ); |
|
633 |
|
634 // From logical point of view, the Pool ID is an index of the key in |
|
635 // an array which is formed by concatenating QWERTY keys array in the end |
|
636 // of the ITU-T keys array. |
|
637 TInt poolId = KErrNotFound; |
|
638 if ( aKbMode == EPredictiveItuT && iItutKeys.Count() ) |
|
639 { |
|
640 poolId = iItutKeys.Find(aKey); |
|
641 // IF the key is not found, then it should go to the special pool, |
|
642 // which is the pool of the dummy key in the ITU-T keys array |
|
643 if (KErrNotFound == poolId) |
|
644 { |
|
645 poolId = iItutKeys.Count() - 1; |
|
646 } |
|
647 } |
|
648 else if ( aKbMode == EPredictiveQwerty && iQwertyKeys.Count() ) |
|
649 { |
|
650 poolId = iQwertyKeys.Find(aKey); |
|
651 // IF the key is not found, then it should go to the special pool, |
|
652 // which is the pool of the dummy key in the QWERTY keys array |
|
653 if (KErrNotFound == poolId) |
|
654 { |
|
655 poolId = iQwertyKeys.Count() - 1; |
|
656 } |
|
657 // Pools of QWERTY keys come after pools of ITU-T keys |
|
658 poolId += iItutKeys.Count(); |
|
659 } |
|
660 |
|
661 // Pool ID must never exceed value 63, because CPcsCache class |
|
662 // stores these values as bitmask into 64 bit variable. |
|
663 __ASSERT_DEBUG( poolId < 64, Panic(EPanic_OverflowInPoolIndex) ); |
|
664 return poolId; |
|
665 } |
|
666 |
|
667 // ---------------------------------------------------------------------------- |
|
668 // CPcsKeyMap::PoolIdForCharacter |
|
669 // |
|
670 // ---------------------------------------------------------------------------- |
|
671 TInt CPcsKeyMap::PoolIdForCharacter( TChar aChar, TKeyboardModes aKbMode ) |
|
672 { |
|
673 // Pools are formed according the predictive keyboard mapping(s). |
|
674 // When selecting pool for non-predictive mode, we use the pool of the |
|
675 // default keyboard. The non-predictive matches should be a sub set of the |
|
676 // predictive matches of the default keyboard, although strictly speaking, |
|
677 // there' no guarantee for this. |
|
678 if ( aKbMode == ENonPredictive || aKbMode == EPredictiveDefaultKeyboard ) |
|
679 { |
|
680 aKbMode = ( iItutIsDefault ? EPredictiveItuT : EPredictiveQwerty ); |
|
681 } |
|
682 |
|
683 // If character is a Chinese word character, then we select the |
|
684 // pool ID according the first character of the first spelling of the word. |
|
685 TRAP_IGNORE( aChar = FirstCharFromSpellingL( aChar ) ); |
|
686 |
|
687 TPtiKey key = KeyForCharacter( aChar, aKbMode ); |
|
688 TInt poolId = PoolIdForKey( key, aKbMode ); |
|
689 |
|
690 return poolId; |
|
691 } |
|
692 |
|
693 // ---------------------------------------------------------------------------- |
|
694 // CPcsKeyMap::PoolCount |
|
695 // |
|
696 // ---------------------------------------------------------------------------- |
|
697 TInt CPcsKeyMap::PoolCount() |
|
698 { |
|
699 return iItutKeyMappings.Count() + iQwertyKeyMappings.Count(); |
|
700 } |
|
701 |
|
702 // ---------------------------------------------------------------------------- |
|
703 // CPcsKeyMap::GetSpaceAndZeroOnSameKey |
|
704 // |
|
705 // ---------------------------------------------------------------------------- |
|
706 TBool CPcsKeyMap::GetSpaceAndZeroOnSameKey( TKeyboardModes aMode ) |
|
707 { |
|
708 // Resolve ambiguous keyboard mode |
|
709 aMode = ResolveKeyboardMode( aMode ); |
|
710 |
|
711 if ( aMode == EPredictiveItuT ) |
|
712 { |
|
713 return iSpaceAndZeroOnSameKeyOnItut; |
|
714 } |
|
715 else if ( aMode == EPredictiveQwerty ) |
|
716 { |
|
717 return iSpaceAndZeroOnSameKeyOnQwerty; |
|
718 } |
|
719 else |
|
720 { |
|
721 return EFalse; |
|
722 } |
|
723 } |
|
724 |
|
725 // ---------------------------------------------------------------------------- |
|
726 // CPcsKeyMap::SetSpaceAndZeroOnSameKey |
|
727 // |
|
728 // ---------------------------------------------------------------------------- |
|
729 void CPcsKeyMap::SetSpaceAndZeroOnSameKey() |
|
730 { |
|
731 static const TInt KSpace = 0x20; // ASCII for " " |
|
732 static const TInt KZero = 0x30; // ASCII for "0" |
|
733 |
|
734 TChar charSpace(KSpace); |
|
735 TChar charZero(KZero); |
|
736 |
|
737 TPtiKey keySpace; |
|
738 TPtiKey keyZero; |
|
739 |
|
740 // ITU-T mode |
|
741 keySpace = KeyForCharacter(charSpace, EPredictiveItuT); |
|
742 keyZero = KeyForCharacter(charZero, EPredictiveItuT); |
|
743 iSpaceAndZeroOnSameKeyOnItut = (keySpace == keyZero); |
|
744 |
|
745 // QWERTY mode |
|
746 keySpace = KeyForCharacter(charSpace, EPredictiveQwerty); |
|
747 keyZero = KeyForCharacter(charZero, EPredictiveQwerty); |
|
748 iSpaceAndZeroOnSameKeyOnQwerty = (keySpace == keyZero); |
|
749 } |
|
750 |
|
751 // ---------------------------------------------------------------------------- |
|
752 // CPcsKeyMap::CPcsKeyMap::FirstCharFromSpellingL |
|
753 // |
|
754 // ---------------------------------------------------------------------------- |
|
755 TChar CPcsKeyMap::FirstCharFromSpellingL( TChar aChar ) const |
|
756 { |
|
757 TChar translated( aChar ); |
|
758 TBuf<1> temp; |
|
759 temp.Append( aChar ); |
|
760 if ( iAlgorithm->FindUtilECE()->IsChineseWordIncluded( temp ) ) |
|
761 { |
|
762 RPointerArray<HBufC> spellList; |
|
763 CleanupResetAndDestroyPushL( spellList ); |
|
764 if (iAlgorithm->FindUtilECE()->DoTranslationL(aChar, spellList)) |
|
765 { |
|
766 translated = (*spellList[0])[0]; |
|
767 } |
|
768 CleanupStack::PopAndDestroy( &spellList ); // ResetAndDestroy |
|
769 } |
|
770 return translated; |
|
771 } |
|
772 |
|
773 // ---------------------------------------------------------------------------- |
|
774 // CPcsKeyMap::KeyMappings |
|
775 // |
|
776 // ---------------------------------------------------------------------------- |
|
777 const RPointerArray<TKeyMappingData>* CPcsKeyMap::KeyMappings( TKeyboardModes aMode ) const |
|
778 { |
|
779 const RPointerArray<TKeyMappingData>* mappings = NULL; |
|
780 |
|
781 if ( aMode == EPredictiveItuT ) |
|
782 { |
|
783 mappings = &iItutKeyMappings; |
|
784 } |
|
785 else if ( aMode == EPredictiveQwerty ) |
|
786 { |
|
787 mappings = &iQwertyKeyMappings; |
|
788 } |
|
789 else if ( aMode == ENonPredictive ) |
|
790 { |
|
791 mappings = NULL; |
|
792 } |
|
793 else |
|
794 { |
|
795 mappings = NULL; |
|
796 __ASSERT_DEBUG( EFalse, Panic( EPanic_InvalidKeyboardType ) ); |
|
797 } |
|
798 |
|
799 return mappings; |
|
800 } |
|
801 |
|
802 // ---------------------------------------------------------------------------- |
|
803 // CPcsKeyMap::ResolveKeyboardMode |
|
804 // |
|
805 // ---------------------------------------------------------------------------- |
|
806 TKeyboardModes CPcsKeyMap::ResolveKeyboardMode( TKeyboardModes aKbMode ) const |
|
807 { |
|
808 TKeyboardModes resolvedMode = aKbMode; |
|
809 |
|
810 // Substitute "default predictive" mode with actual mode |
|
811 if ( resolvedMode == EPredictiveDefaultKeyboard ) |
|
812 { |
|
813 resolvedMode = ( iItutIsDefault ? EPredictiveItuT : EPredictiveQwerty ); |
|
814 } |
|
815 |
|
816 // Substitute predictive mode with non-predictive mode if corresponding |
|
817 // keyboard mappings are not available. |
|
818 if ( ( resolvedMode == EPredictiveItuT && iItutKeyboardType == EPtiKeyboardNone ) || |
|
819 ( resolvedMode == EPredictiveQwerty && iQwertyKeyboardType == EPtiKeyboardNone ) ) |
|
820 { |
|
821 PRINT1( _L("CPcsKeyMap::ResolveKeyboardMode: Mappings for requested mode %d unavailable. Falling back to non-predictive mode!"), aKbMode ); |
|
822 resolvedMode = ENonPredictive; |
|
823 } |
|
824 |
|
825 return resolvedMode; |
|
826 } |
|
827 |
|
828 // ---------------------------------------------------------------------------- |
|
829 // CPcsKeyMap::DefaultCharForKey |
|
830 // |
|
831 // ---------------------------------------------------------------------------- |
|
832 TText CPcsKeyMap::DefaultCharForKey( TPtiKey aKey, TKeyboardModes aKbMode ) const |
|
833 { |
|
834 // On ITU-T, the Pti key code can be directly interpreted as unicode character. |
|
835 // Thus, default characters for keys are 1,2,3,4,5,6,7,8,9,0,*,#. |
|
836 TText defChar = aKey; |
|
837 |
|
838 // On QWERTY, using PtiKey values directly is not safe since all PtiKey values are |
|
839 // not codepoints of printable Unicode characters. |
|
840 // Treating these arbitrary numerical values as Unicode characters could break |
|
841 // the uniqueness of keys when collated comparison is used. Also, converting same |
|
842 // data multiple times to "compare format" would then break the data. |
|
843 if ( aKbMode == EPredictiveQwerty ) |
|
844 { |
|
845 // Take first mapped character of the key and convert it to upper case. |
|
846 TInt index = iQwertyKeys.Find( aKey ); |
|
847 if ( index != KErrNotFound ) |
|
848 { |
|
849 const RArray<TInt>& mappings = iQwertyKeyMappings[index]->iKeyMappingArray; |
|
850 if ( mappings.Count() ) |
|
851 { |
|
852 defChar = User::UpperCase( mappings[0] ); |
|
853 } |
|
854 } |
|
855 } |
|
856 |
|
857 return defChar; |
|
858 } |
|
859 // End of file |