textinput/peninputhwrboxjp/src/peninputhwrboxdatamgr.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002-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:  peninput hwr data manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <peninputhwrwindowjp.rsg>
       
    21 #include <centralrepository.h>
       
    22 #include <settingsinternalcrkeys.h>
       
    23 #include <peninputlayoutcontext.h> // MPeninputLayoutContext
       
    24 #include <aknfeppeninputenums.h>    // ERangeHiraganaKanji, ...
       
    25 #include <PtiEngine.h>
       
    26 
       
    27 // User includes
       
    28 #include "peninputhwrevent.h"  // EPeninputLayoutHwrEventCandidates, ....
       
    29 #include "peninputhwrboxdatamgr.h"
       
    30 #include "peninputhwrboxrecognizer.h"
       
    31 
       
    32 // Constants
       
    33 const TInt KPremaryCandidateCount = 36;
       
    34 const TInt KCandidateCount = 10;
       
    35 enum
       
    36     {
       
    37     EHwrWritingSpeedVeryFast    = 300 * 1000,
       
    38     EHwrWritingSpeedFast        = 400 * 1000,
       
    39     EHwrWritingSpeedNormal      = 550 * 1000,
       
    40     EHwrWritingSpeedSlow        = 700 * 1000,
       
    41     EHwrWritingSpeedVerySlow    = 1000 * 1000
       
    42     };
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CPeninputHwrBoxDataMgr::NewL
       
    49 // (other items were commented in a header)
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CPeninputHwrBoxDataMgr* CPeninputHwrBoxDataMgr::NewL(MPeninputLayoutContext* aContext)
       
    53     {
       
    54     CPeninputHwrBoxDataMgr* self = NewLC(aContext);
       
    55     CleanupStack::Pop( self );
       
    56 
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CPeninputHwrBoxDataMgr::NewLC
       
    62 // (other items were commented in a header)
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CPeninputHwrBoxDataMgr* CPeninputHwrBoxDataMgr::NewLC(MPeninputLayoutContext* aContext)
       
    66     {
       
    67     CPeninputHwrBoxDataMgr* self =
       
    68         new ( ELeave ) CPeninputHwrBoxDataMgr( aContext );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71 
       
    72     return self;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CPeninputHwrBoxDataMgr::~CPeninputHwrBoxDataMgr
       
    77 // (other items were commented in a header)
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CPeninputHwrBoxDataMgr::~CPeninputHwrBoxDataMgr()
       
    81     {
       
    82     iCandidates.ResetAndDestroy();
       
    83     iCandidates.Close();
       
    84 
       
    85     iRangeStartPos.Close();
       
    86 
       
    87     iPermittedRanges.Close();
       
    88 
       
    89     delete iHwrBoxRecognizer;
       
    90     delete iPtiEngine;
       
    91     delete iCharacterRangeArray;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // Do recoginize by engine
       
    96 // ---------------------------------------------------------
       
    97 //
       
    98 void CPeninputHwrBoxDataMgr::DoRecognize(const RArray<TPoint>& aTraceData)
       
    99     {
       
   100     if (iHwrBoxRecognizer)
       
   101         {
       
   102         iHwrBoxRecognizer->DoRecognize(aTraceData, iCandidates, iRangeStartPos);
       
   103         }
       
   104 
       
   105     SetCandidates();
       
   106     }
       
   107 
       
   108 // ---------------------------------------------------------
       
   109 // Get the candidate count
       
   110 // ---------------------------------------------------------
       
   111 //
       
   112 TInt CPeninputHwrBoxDataMgr::CandidateCount() const
       
   113     {
       
   114     return iCandidates.Count();
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // Set permitted ranges
       
   119 // ---------------------------------------------------------
       
   120 //
       
   121 void CPeninputHwrBoxDataMgr::SetPermittedRanges(TInt aPermittedRanges)
       
   122     {
       
   123     iPermittedRanges.Reset();
       
   124 
       
   125     if (aPermittedRanges & ERangeNative)
       
   126         {
       
   127         iPermittedRanges.Append(ERangeNative);
       
   128         }
       
   129     if ((aPermittedRanges & ERangeEnglish) && !FullHalf())
       
   130         {
       
   131         iPermittedRanges.Append(ERangeEnglish);
       
   132         }
       
   133 
       
   134     if ((aPermittedRanges & ERangeNumber) && !FullHalf())
       
   135         {
       
   136         iPermittedRanges.Append(ERangeNumber);
       
   137         }
       
   138 
       
   139     if (aPermittedRanges & ERangeSymbol)
       
   140         {
       
   141         iPermittedRanges.Append(ERangeSymbol);
       
   142         }
       
   143 
       
   144     if (aPermittedRanges & ERangeHiraganaKanji)
       
   145         {
       
   146         iPermittedRanges.Append(ERangeHiraganaKanji);
       
   147         }
       
   148 
       
   149     if ((aPermittedRanges & ERangeKatakana) && !FullHalf())
       
   150         {
       
   151         iPermittedRanges.Append(ERangeKatakana);
       
   152         }
       
   153 
       
   154     if ((aPermittedRanges & ERangeFullWidthKatakana) && FullHalf())
       
   155         {
       
   156         iPermittedRanges.Append(ERangeFullWidthKatakana);
       
   157         }
       
   158 
       
   159     if ((aPermittedRanges & ERangeFullWidthEnglish) && FullHalf())
       
   160         {
       
   161         iPermittedRanges.Append(ERangeFullWidthEnglish);
       
   162         }
       
   163 
       
   164     if ((aPermittedRanges & ERangeFullWidthNumeric) && FullHalf())
       
   165         {
       
   166         iPermittedRanges.Append(ERangeFullWidthNumeric);
       
   167         }
       
   168 
       
   169     if (aPermittedRanges & ERangeHiraganaOnly)
       
   170         {
       
   171         iPermittedRanges.Append(ERangeHiraganaOnly);
       
   172         }
       
   173 
       
   174     // set primary and auxiliary ranges for hwr engine
       
   175     if (iHwrBoxRecognizer)
       
   176         {
       
   177         iHwrBoxRecognizer->SetRanges(iPermittedRanges);
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // Get the permitted ranges count
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 TInt CPeninputHwrBoxDataMgr::PermittedRangesCount() const
       
   186     {
       
   187     return iPermittedRanges.Count();
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------
       
   191 // Set premary range
       
   192 // ---------------------------------------------------------
       
   193 //
       
   194 void CPeninputHwrBoxDataMgr::SetPremaryRange(TInt aPremaryRange)
       
   195     {
       
   196     const TInt oldIndex = iPermittedRanges.Find(aPremaryRange);
       
   197 
       
   198     if (oldIndex > 0)
       
   199         {
       
   200         iPermittedRanges.Sort();
       
   201         const TInt index = iPermittedRanges.Find(aPremaryRange);
       
   202 
       
   203         iPermittedRanges.Remove(index);
       
   204         iPermittedRanges.Insert(aPremaryRange, 0);
       
   205         }
       
   206 
       
   207     iContext->SendEventToWindow(EPeninputLayoutEventSetCharacterRangeText,NULL,KNullDesC);
       
   208 
       
   209     // set primary and auxiliary ranges for hwr engine
       
   210     if (iHwrBoxRecognizer)
       
   211         {
       
   212         iHwrBoxRecognizer->SetRanges(iPermittedRanges);
       
   213         }
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------
       
   217 // Set the candidate list
       
   218 // ---------------------------------------------------------
       
   219 //
       
   220 void CPeninputHwrBoxDataMgr::SetCandidates()
       
   221     {
       
   222     TPtrC ptr;
       
   223     ptr.Set(reinterpret_cast<TText*>(&iCandidates), sizeof(iCandidates)/sizeof(TUint16));
       
   224     iContext->SendEventToWindow(EPeninputLayoutHwrEventCandidates, NULL, ptr);
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // Get WritingSpeed
       
   229 // ---------------------------------------------------------
       
   230 //
       
   231 TInt CPeninputHwrBoxDataMgr::WritingSpeed() const
       
   232     {
       
   233     return iWritingSpeed;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // Get PenSize
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 TSize CPeninputHwrBoxDataMgr::PenSize() const
       
   241     {
       
   242     return iPenSize;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // Get PenColor
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 TRgb CPeninputHwrBoxDataMgr::PenColor() const
       
   250     {
       
   251     return iPenColor;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // Get the candidate
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 void CPeninputHwrBoxDataMgr::GetCandidate(TInt aIndex, TDes& aCharCode) const
       
   259     {
       
   260     aCharCode.Zero();
       
   261     if (aIndex >=0 && aIndex < iCandidates.Count())
       
   262         {
       
   263         aCharCode = *iCandidates[aIndex];
       
   264         }
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // Clear the candidate list
       
   269 // ---------------------------------------------------------
       
   270 //
       
   271 void CPeninputHwrBoxDataMgr::ClearCandidates()
       
   272     {
       
   273     iCandidates.ResetAndDestroy();
       
   274 
       
   275     TPtrC ptr;
       
   276     ptr.Set(reinterpret_cast<TText*>(&iCandidates), sizeof(iCandidates)/sizeof(TUint16));
       
   277     iContext->SendEventToWindow(EPeninputLayoutHwrEventCandidates, NULL, ptr);
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CPeninputHwrBoxDataMgr::InitMoreJpL
       
   282 // instesd of "void InitMore();"
       
   283 // (other items were commented in a header)
       
   284 // ---------------------------------------------------------------------------
       
   285 void CPeninputHwrBoxDataMgr::InitMoreJpL()
       
   286     {
       
   287     // Read pen data
       
   288     if ( iGSRepository )
       
   289         {
       
   290         TInt newValue;
       
   291         newValue = 0;
       
   292         iGSRepository->Get( KSettingsPenColor, newValue );
       
   293         iPenColor = newValue;
       
   294 
       
   295         newValue = 1;
       
   296         iGSRepository->Get( KSettingsPenWidth, newValue );
       
   297         iPenSize = TSize( newValue, newValue );
       
   298 
       
   299         newValue = 2;
       
   300         iGSRepository->Get( KSettingsWritingSpeed, newValue );
       
   301         iWritingSpeed = TransferWritingSpeed( newValue );
       
   302         }
       
   303 
       
   304     iPtiEngine = CPtiEngine::NewL( ETrue );
       
   305     iPtiEngine->ActivateLanguageL(ELangJapanese, EPtiEngineHiraganaKanjiPredictiveHwr);
       
   306 
       
   307     iHwrBoxRecognizer = CPeninputHwrBoxRecognizer::NewL(iPtiEngine);
       
   308     iCharacterRangeArray = new(ELeave) CDesCArrayFlat(1);
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // CPeninputHwrBoxDataMgr::HandleGSRepositoryChange
       
   313 // (other items were commented in a header)
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 void CPeninputHwrBoxDataMgr::HandleGSRepositoryChange( TInt aChangedKey )
       
   317     {
       
   318     TInt newValue = 0;
       
   319 
       
   320     switch ( aChangedKey )
       
   321         {
       
   322         case KSettingsPenColor:
       
   323             {
       
   324             iGSRepository->Get( KSettingsPenColor, newValue );
       
   325             iPenColor = newValue;
       
   326             TPtr ptr((TUint16*)&iPenColor,sizeof(TRgb)/sizeof(TUint16));
       
   327             iContext->SendEventToWindow(EPeninputLayoutHwrEventPenColorChange, NULL, ptr);
       
   328             }
       
   329             break;
       
   330         case KSettingsPenWidth:
       
   331             {
       
   332             iGSRepository->Get( KSettingsPenWidth, newValue );
       
   333             iPenSize = TSize( newValue, newValue );
       
   334             TPtr ptr((TUint16*)&iPenSize,sizeof(TSize)/sizeof(TUint16));
       
   335             iContext->SendEventToWindow(EPeninputLayoutHwrEventPenSizeChange, NULL, ptr);
       
   336             }
       
   337             break;
       
   338         case KSettingsWritingSpeed:
       
   339             {
       
   340             iGSRepository->Get( KSettingsWritingSpeed, newValue );
       
   341             iWritingSpeed = TransferWritingSpeed( newValue );
       
   342             TPtr ptr((TUint16*)&iWritingSpeed,sizeof(TInt)/sizeof(TUint16));
       
   343             iContext->SendEventToWindow(EPeninputLayoutHwrEventWritingSpeedChange, NULL, ptr);
       
   344             }
       
   345             break;
       
   346         default:
       
   347             break;
       
   348         }
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // CPeninputHwrBoxDataMgr::PtiEngine
       
   353 // (other items were commented in a header).
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 CPtiEngine* CPeninputHwrBoxDataMgr::PtiEngine()
       
   357     {
       
   358     return iPtiEngine;
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CPeninputHwrBoxDataMgr::Predictive
       
   363 // (other items were commented in a header).
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 TBool CPeninputHwrBoxDataMgr::Predictive() const
       
   367     {
       
   368     return iPredictive;
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CPeninputHwrBoxDataMgr::FullHalf
       
   373 // (other items were commented in a header).
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 TInt CPeninputHwrBoxDataMgr::FullHalf() const
       
   377     {
       
   378     return iFullHalf;
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // CPeninputHwrBoxDataMgr::Conversion
       
   383 // (other items were commented in a header).
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 TBool CPeninputHwrBoxDataMgr::Conversion() const
       
   387     {
       
   388     return iConversion;
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // CPeninputHwrBoxDataMgr::Conversion
       
   393 // (other items were commented in a header).
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 CDesCArrayFlat* CPeninputHwrBoxDataMgr::CharacterRangeArray()
       
   397     {
       
   398     return iCharacterRangeArray;
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CPeninputHwrBoxDataMgr::CharacterRangeId
       
   403 // (other items were commented in a header).
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 TInt CPeninputHwrBoxDataMgr::CharacterRangeId() const
       
   407     {
       
   408     TInt rangeId = EPeninutCharacterRangeIdAll;
       
   409     if (0 <= iCurrentCharacterRangeIndex && iCurrentCharacterRangeIndex < KCharacterRangePopupMaxRow)
       
   410         {
       
   411         rangeId = iCharacterRangeIdArray.At(iCurrentCharacterRangeIndex);
       
   412         }
       
   413     return rangeId;
       
   414     }
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // CPeninputHwrBoxDataMgr::CurrentCharacterRangeIndex
       
   418 // (other items were commented in a header).
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 TInt CPeninputHwrBoxDataMgr::CurrentCharacterRangeIndex() const
       
   422     {
       
   423     return iCurrentCharacterRangeIndex;
       
   424     }
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // CPeninputHwrBoxDataMgr::SetEngineInputMode
       
   428 // (other items were commented in a header).
       
   429 // ---------------------------------------------------------------------------
       
   430 void CPeninputHwrBoxDataMgr::SetEngineInputMode(TInt aRange)
       
   431     {
       
   432     if (iPermittedRange & aRange)
       
   433         {
       
   434         TInt clearDirection = iClear;   // 1:delete 0:backspace
       
   435         TPtiEngineInputMode mode = EPtiEngineInputModeNone;
       
   436         if (ERangeHiraganaKanji == aRange && Conversion())
       
   437             {
       
   438             mode = (Predictive())? EPtiEngineHiraganaKanjiPredictiveHwr
       
   439                                  : EPtiEngineHiraganaKanjiHwr;
       
   440             }
       
   441         iPtiEngine->SetInputMode(mode);
       
   442         TRAP_IGNORE(iPtiEngine->HandleCommandL(EPtiCommandSetClearFunction, &clearDirection));
       
   443         }
       
   444     }
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 // CPeninputHwrBoxDataMgr::SetPredictive
       
   448 // (other items were commented in a header).
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void CPeninputHwrBoxDataMgr::SetPredictive(TBool aPredictive)
       
   452     {
       
   453     iPredictive = aPredictive;
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CPeninputHwrBoxDataMgr::SetFullHalf
       
   458 // (other items were commented in a header).
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 void CPeninputHwrBoxDataMgr::SetFullHalf(TInt aFullHalf)
       
   462     {
       
   463     iFullHalf = aFullHalf;
       
   464     }
       
   465 
       
   466 // ---------------------------------------------------------------------------
       
   467 // CPeninputHwrBoxDataMgr::SetClear
       
   468 // (other items were commented in a header).
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 void CPeninputHwrBoxDataMgr::SetClear(TInt aClear)
       
   472     {
       
   473     iClear = aClear;
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------------------------
       
   477 // CPeninputHwrBoxDataMgr::SetConversion
       
   478 // (other items were commented in a header).
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CPeninputHwrBoxDataMgr::SetConversion(TBool aConversion)
       
   482     {
       
   483     iConversion = aConversion;
       
   484    }
       
   485 
       
   486 // ---------------------------------------------------------------------------
       
   487 // CPeninputHwrBoxDataMgr::SetCurrentCharacterRangeIndex
       
   488 // (other items were commented in a header).
       
   489 // ---------------------------------------------------------------------------
       
   490 //
       
   491 void CPeninputHwrBoxDataMgr::SetCurrentCharacterRangeIndex(TInt aIndex)
       
   492     {
       
   493     iCurrentCharacterRangeIndex = aIndex;
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // CPeninputHwrBoxDataMgr::Reset
       
   498 // (other items were commented in a header)
       
   499 // ---------------------------------------------------------------------------
       
   500 //
       
   501 void CPeninputHwrBoxDataMgr::Reset()
       
   502     {
       
   503     iPermittedRange = 0;
       
   504     iPermittedCase = 0;
       
   505     iCurrentRange = 0;
       
   506     iCase = 0;
       
   507     }
       
   508 
       
   509 // --------------------------------------------------------------------------
       
   510 // CPeninputHwrBoxDataMgr::SetInputAreaSize
       
   511 // (other items were commented in a header)
       
   512 // --------------------------------------------------------------------------
       
   513 //
       
   514 void CPeninputHwrBoxDataMgr::SetInputAreaSize( const TSize& aSize )
       
   515     {
       
   516     if ( iHwrBoxRecognizer )
       
   517         {
       
   518         iHwrBoxRecognizer->SetInputAreaSize( aSize );
       
   519         }
       
   520     }
       
   521 
       
   522 // ---------------------------------------------------------
       
   523 // Return the clear direction
       
   524 // ---------------------------------------------------------
       
   525 //
       
   526 TInt CPeninputHwrBoxDataMgr::ClearDirection() const
       
   527     {
       
   528     return iClear;   // 1:delete 0:backspace
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 // CPeninputHwrBoxDataMgr::CPeninputHwrBoxDataMgr
       
   533 // (other items were commented in a header)
       
   534 // ---------------------------------------------------------------------------
       
   535 //
       
   536 CPeninputHwrBoxDataMgr::CPeninputHwrBoxDataMgr(
       
   537     MPeninputLayoutContext* aContext )
       
   538     : CPeninputDataMgr( aContext ),
       
   539      iPredictive(ETrue),
       
   540      iConversion(ETrue)
       
   541     {
       
   542     iInputLanguage = ELangJapanese;
       
   543     }
       
   544 
       
   545 // --------------------------------------------------------------------------
       
   546 // CPeninputHwrBoxDataMgr::ConstructL
       
   547 // (other items were commented in a header)
       
   548 // --------------------------------------------------------------------------
       
   549 //
       
   550 void CPeninputHwrBoxDataMgr::ConstructL()
       
   551     {
       
   552     CPeninputDataMgr::ConstructL();
       
   553     InitMoreJpL();
       
   554     }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 // CPeninputHwrBoxDataMgr::TransferWritingSpeed
       
   558 // (other items were commented in a header)
       
   559 // ---------------------------------------------------------------------------
       
   560 //
       
   561 TInt CPeninputHwrBoxDataMgr::TransferWritingSpeed( TInt aWritingSpeed ) const
       
   562     {
       
   563     TInt speed;
       
   564 
       
   565     switch ( aWritingSpeed )
       
   566         {
       
   567         case 0:
       
   568             {
       
   569             speed = EHwrWritingSpeedVeryFast;
       
   570             }
       
   571             break;
       
   572         case 1:
       
   573             {
       
   574             speed = EHwrWritingSpeedFast;
       
   575             }
       
   576             break;
       
   577         case 2:
       
   578             {
       
   579             speed = EHwrWritingSpeedNormal;
       
   580             }
       
   581             break;
       
   582         case 3:
       
   583             {
       
   584             speed = EHwrWritingSpeedSlow;
       
   585             }
       
   586             break;
       
   587         case 4:
       
   588             {
       
   589             speed = EHwrWritingSpeedVerySlow;
       
   590             }
       
   591             break;
       
   592         default:
       
   593             {
       
   594             speed = EHwrWritingSpeedNormal;
       
   595             }
       
   596             break;
       
   597         }
       
   598 
       
   599     return speed;
       
   600     }
       
   601 
       
   602 // ---------------------------------------------------------------------------
       
   603 // CPeninputHwrBoxDataMgr::NotifyEngine
       
   604 // (other items were commented in a header)
       
   605 // ---------------------------------------------------------------------------
       
   606 //
       
   607 void CPeninputHwrBoxDataMgr::NotifyEngine( TPeninputDataType aType,
       
   608                                                TAny* aData )
       
   609     {
       
   610     // Call the function in base class, which will store data to CenRep
       
   611     CPeninputDataMgr::NotifyEngine( aType, aData );
       
   612 
       
   613     TInt* data = ( TInt* ) aData;
       
   614 
       
   615     // Notify engine, when language, range, case changed
       
   616     switch ( aType )
       
   617         {
       
   618         case EPeninputDataTypePermittedRange:
       
   619             {
       
   620             SetPermittedRanges(*data);
       
   621             TRAP_IGNORE(SetCharacterRangePopupL(*data));
       
   622             }
       
   623             break;
       
   624         case EPeninputDataTypeCase:
       
   625             {
       
   626             iHwrBoxRecognizer->SetCase( *data );
       
   627             }
       
   628             break;
       
   629         case EPeninputDataTypeInputLanguage:
       
   630             {
       
   631             // select suitable hwr recognizer according to language
       
   632             if (iHwrBoxRecognizer)
       
   633                 {
       
   634                 TRAP_IGNORE(iHwrBoxRecognizer->SetLanguageL(*data));
       
   635                 iHwrBoxRecognizer->SetPrimaryCandidateNum(KPremaryCandidateCount);
       
   636                 iHwrBoxRecognizer->SetCandidateNum(KCandidateCount);
       
   637 
       
   638                 TPoint strokeEndMark = iHwrBoxRecognizer->StrokeEndMark();
       
   639                 TPtr ptr((TUint16*)&strokeEndMark,sizeof(TPoint)/sizeof(TUint16));
       
   640                 iContext->SendEventToWindow(EPeninputLayoutHwrEventStrokeEndMark, NULL, ptr);
       
   641                 }
       
   642             }
       
   643             break;
       
   644         case EPeninputDataTypeCurrentRange:
       
   645             {
       
   646             SetPremaryRange( *data );
       
   647             }
       
   648             break;
       
   649         case EPeninputDataTypeNumericKeymap:
       
   650             {
       
   651             iHwrBoxRecognizer->SetNumberMode((TAknEditorNumericKeymap)*data);
       
   652             iHwrBoxRecognizer->SetRanges(iPermittedRanges);
       
   653             }
       
   654             break;
       
   655         default:
       
   656             break;
       
   657         }
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------
       
   661 // Set Character range popup
       
   662 // ---------------------------------------------------------
       
   663 //
       
   664 void CPeninputHwrBoxDataMgr::SetCharacterRangePopupL(TInt aPermittedRanges)
       
   665     {
       
   666     // Read resource
       
   667     TResourceReader reader;
       
   668     TInt index = 0;
       
   669     iCharacterRangeArray->Reset();
       
   670     iCharacterRangeIdArray.Reset();
       
   671     iCurrentCharacterRangeIndex = 0;
       
   672     if ((aPermittedRanges & ERangeHiraganaOnly) == aPermittedRanges)
       
   673         {
       
   674         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_HIRAGANA );
       
   675         TPtrC p2 = reader.ReadTPtrC();
       
   676         iCharacterRangeArray->AppendL(p2);
       
   677         CleanupStack::PopAndDestroy( 1 );
       
   678         iCharacterRangeIdArray.At(0) = EPeninutCharacterRangeIdKanaKanji;  // not used
       
   679         return;
       
   680         }
       
   681     if ((aPermittedRanges & ERangeHiraganaKanji)
       
   682         && (aPermittedRanges & (ERangeHiraganaKanji | ERangeKatakana | ERangeFullWidthKatakana)) == aPermittedRanges)
       
   683         {
       
   684         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_KANAKANJI );
       
   685         TPtrC p2 = reader.ReadTPtrC();
       
   686         iCharacterRangeArray->AppendL(p2);
       
   687         CleanupStack::PopAndDestroy( 1 );
       
   688         iCharacterRangeIdArray.At(0) = EPeninutCharacterRangeIdKanaKanji;
       
   689         return;
       
   690         }
       
   691     if ((aPermittedRanges & (ERangeEnglish | ERangeFullWidthEnglish)) == aPermittedRanges)
       
   692         {
       
   693         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_LATIN );
       
   694         TPtrC p3 = reader.ReadTPtrC();
       
   695         iCharacterRangeArray->AppendL(p3);
       
   696         CleanupStack::PopAndDestroy( 1 );
       
   697         iCharacterRangeIdArray.At(0) = EPeninutCharacterRangeIdLatin;
       
   698         return;
       
   699         }
       
   700     if ((aPermittedRanges & (ERangeNumber | ERangeFullWidthNumeric)) == aPermittedRanges)
       
   701         {
       
   702         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_NUMBER );
       
   703         TPtrC p4 = reader.ReadTPtrC();
       
   704         iCharacterRangeArray->AppendL(p4);
       
   705         CleanupStack::PopAndDestroy( 1 );
       
   706         iCharacterRangeIdArray.At(0) = EPeninutCharacterRangeIdNumber;
       
   707         return;
       
   708         }
       
   709     if ((aPermittedRanges & (ERangeKatakana | ERangeFullWidthKatakana)) == aPermittedRanges)
       
   710         {
       
   711         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_KATAKANA );
       
   712         TPtrC p4 = reader.ReadTPtrC();
       
   713         iCharacterRangeArray->AppendL(p4);
       
   714         CleanupStack::PopAndDestroy( 1 );
       
   715         iCharacterRangeIdArray.At(0) = EPeninutCharacterRangeIdKanaKanji;  // not used
       
   716         return;
       
   717         }
       
   718     CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_ALL );
       
   719     TPtrC p1 = reader.ReadTPtrC();
       
   720     iCharacterRangeArray->AppendL(p1);
       
   721     CleanupStack::PopAndDestroy( 1 );
       
   722     iCharacterRangeIdArray.At(index++) = EPeninutCharacterRangeIdAll;
       
   723     if (aPermittedRanges & (ERangeHiraganaKanji | ERangeKatakana | ERangeFullWidthKatakana))
       
   724         {
       
   725         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_KANAKANJI );
       
   726         TPtrC p2 = reader.ReadTPtrC();
       
   727         iCharacterRangeArray->AppendL(p2);
       
   728         CleanupStack::PopAndDestroy( 1 );
       
   729         iCharacterRangeIdArray.At(index++) = EPeninutCharacterRangeIdKanaKanji;
       
   730         }
       
   731     if (aPermittedRanges & (ERangeEnglish | ERangeFullWidthEnglish))
       
   732         {
       
   733         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_LATIN );
       
   734         TPtrC p3 = reader.ReadTPtrC();
       
   735         iCharacterRangeArray->AppendL(p3);
       
   736         CleanupStack::PopAndDestroy( 1 );
       
   737         iCharacterRangeIdArray.At(index++) = EPeninutCharacterRangeIdLatin;
       
   738         }
       
   739     if (aPermittedRanges & (ERangeNumber | ERangeFullWidthNumeric))
       
   740         {
       
   741         CCoeEnv::Static()->CreateResourceReaderLC( reader, R_PENINPUT_HWR_CHARACTER_NUMBER );
       
   742         TPtrC p4 = reader.ReadTPtrC();
       
   743         iCharacterRangeArray->AppendL(p4);
       
   744         CleanupStack::PopAndDestroy( 1 );
       
   745         iCharacterRangeIdArray.At(index++) = EPeninutCharacterRangeIdNumber;
       
   746         }
       
   747     }
       
   748