textinput/peninputhwrfscn/src/peninputhwrfscndatastore.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2005-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:  Implementation for chinese peninput full screen hwr
       
    15 *
       
    16 */
       
    17 
       
    18 //SYSTEM INCLUDE
       
    19 #include <centralrepository.h>
       
    20 #include <settingsinternalcrkeys.h>
       
    21 
       
    22 //FEP INCLUDE
       
    23 #include <aknfeppeninputenums.h>
       
    24 #include <AknFepGlobalEnums.h>
       
    25 #include <AknFepInternalCRKeys.h>
       
    26 
       
    27 //USER INCLUDE
       
    28 #include "peninputhwrfscndatastore.h"
       
    29 #include "peninputhwrtriggerstr.h"
       
    30 #include "peninputhwrengine.h"
       
    31 
       
    32 //CONSTANT DEFINATION HEADER
       
    33 #include "peninputhwrfscnstoreconstants.h"
       
    34 #include <peninputhwrfscreencn.rsg>
       
    35 #include "peninputpluginutils.h"
       
    36 
       
    37 // ----------------------------------------------------------------------------
       
    38 // Symbian constructor
       
    39 // ----------------------------------------------------------------------------
       
    40 //
       
    41 CPeninputHwrfscnDataStore* CPeninputHwrfscnDataStore::NewL( 
       
    42     CPtiEngine* aPtiEngine )
       
    43     {
       
    44     CPeninputHwrfscnDataStore* self = new ( ELeave ) 
       
    45         CPeninputHwrfscnDataStore();
       
    46     
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aPtiEngine );
       
    49     CleanupStack::Pop( self );//self
       
    50 
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // C++ constructor
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CPeninputHwrfscnDataStore::CPeninputHwrfscnDataStore()
       
    59     {
       
    60     iLanguage = ELangNone;
       
    61     iCurrentNumberMode = EAknEditorStandardNumberModeKeymap;
       
    62     }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // destructor
       
    66 // ----------------------------------------------------------------------------
       
    67 //
       
    68 CPeninputHwrfscnDataStore::~CPeninputHwrfscnDataStore()
       
    69     {
       
    70     iSubscriberList.Close();
       
    71     
       
    72     iCandidates.ResetAndDestroy();
       
    73     iCandidates.Close();
       
    74 
       
    75     iPredictives.ResetAndDestroy();
       
    76     iPredictives.Close();
       
    77     
       
    78     iRangeStartPos.Close();
       
    79     
       
    80     iPermittedRanges.Close();
       
    81 
       
    82     iKeyMappingIdList.Close();
       
    83     
       
    84     iKeyMappingStringList.ResetAndDestroy();
       
    85     iKeyMappingStringList.Close();
       
    86   
       
    87     delete iGSRepositoryWatcher;
       
    88 
       
    89     delete iRepositoryFep;
       
    90     delete iRepositorySetting;
       
    91 
       
    92     delete iTriggerStr;
       
    93     
       
    94     delete iHwrEngine;
       
    95     
       
    96     delete iUserDefinedResource;
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // Second phase constructor
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 void CPeninputHwrfscnDataStore::ConstructL( CPtiEngine* aPtiEngine )
       
   104     {
       
   105     //create the repository for fep settings    
       
   106     iRepositoryFep = CRepository::NewL( KCRUidAknFep );
       
   107 
       
   108     //create the repository for gereral settings
       
   109     iRepositorySetting = CRepository::NewL( KCRUidPersonalizationSettings );
       
   110 
       
   111     //create the repository watcher for general settings
       
   112     iGSRepositoryWatcher = CAknFepRepositoryWatcher::NewL( 
       
   113         KCRUidPersonalizationSettings, 
       
   114         TCallBack( HandleGSRepositoryCallBack, this ),
       
   115         iRepositorySetting );
       
   116     
       
   117     //create the trigger string
       
   118     iTriggerStr = new ( ELeave ) CAknFepHwrTriggerStr();
       
   119     
       
   120     //create the hwr engine
       
   121     iHwrEngine = CAknFepHwrEngine::NewL( aPtiEngine, this );
       
   122     
       
   123     //initialize the key mapping list
       
   124     InitKeyMappingListL();
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // Initialize the key mapping list
       
   129 // ----------------------------------------------------------------------------
       
   130 //   
       
   131 void CPeninputHwrfscnDataStore::InitKeyMappingListL()
       
   132     {
       
   133      //read the key maping string from resource
       
   134     TResourceReader reader;
       
   135     CCoeEnv::Static()->CreateResourceReaderLC( reader, 
       
   136         R_AKN_FEP_HWR_KEY_MAPPING_STRING_LIST ); 
       
   137     
       
   138     const TInt count = reader.ReadInt16();
       
   139    
       
   140     for ( TInt i = 0; i < count; i++ )
       
   141         {
       
   142         iKeyMappingIdList.Append( reader.ReadInt16() );
       
   143         TPtrC ptr = reader.ReadTPtrC();
       
   144         iKeyMappingStringList.Append( ptr.Alloc() );
       
   145         }
       
   146     iCurrentNumberMode = EAknEditorStandardNumberModeKeymap;
       
   147     CleanupStack::PopAndDestroy();
       
   148     }
       
   149     
       
   150 // ----------------------------------------------------------------------------
       
   151 // Is candidate in Chinese range
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 TBool CPeninputHwrfscnDataStore::IsChinese( TInt aCandidateIndex ) const
       
   155     {
       
   156     TUint16 candidate =  ( *iCandidates[aCandidateIndex] )[0];
       
   157     if( candidate >= 0x4E00 && candidate <= 0x9FA5 )
       
   158         {
       
   159         return ETrue;
       
   160         }
       
   161 
       
   162     return EFalse;
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // Is candidate in Chinese range
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 TBool CPeninputHwrfscnDataStore::IsValid( TInt aCandidateIndex ) const
       
   170     {
       
   171     return ( *iCandidates[aCandidateIndex] ).Length() > 0;
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // Is the language which has the homephonic effect.
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 TBool CPeninputHwrfscnDataStore::IsHomephonicLanguage()
       
   179 	{
       
   180 	if ( iLanguage == ELangPrcChinese || iLanguage == ELangTaiwanChinese )
       
   181 	    {
       
   182 	    return ETrue;
       
   183 	    }
       
   184 	
       
   185 	return EFalse;   	
       
   186 	}
       
   187 	
       
   188 // ----------------------------------------------------------------------------
       
   189 // Do recoginize by engine
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 void CPeninputHwrfscnDataStore::DoRecognizeL( const RArray<TPoint>& aTraceData )
       
   193     {
       
   194     iHwrEngine->DoRecognizeL( aTraceData, iCandidates );
       
   195     SetCandidatesL();
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // Do predictive using trigger string
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 void CPeninputHwrfscnDataStore::DoPredictiveL()
       
   203     {
       
   204     // clear the predictives
       
   205     iPredictives.ResetAndDestroy();
       
   206     
       
   207     //if the Primary range is chinese
       
   208     TInt primaryRange = iPermittedRanges[0];
       
   209     
       
   210     if( primaryRange == ERangeNative )
       
   211     	{
       
   212         GetPredictivesOfPriRangeAsChineseL();		
       
   213         }
       
   214     //if the Primary range is english
       
   215     else if( primaryRange == ERangeEnglish )
       
   216         {
       
   217         GetPredictivesOfPriRangeAsEnglishL();
       
   218         }
       
   219     //if the Primary range is number        
       
   220     else if( primaryRange == ERangeNumber )
       
   221         {
       
   222         GetPredictivesOfPriRangeAsNumberL();
       
   223         }                  
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // Get predictives of primary range as chinese
       
   228 // ----------------------------------------------------------------------------
       
   229 //    
       
   230 void CPeninputHwrfscnDataStore::GetPredictivesOfPriRangeAsChineseL()
       
   231     {
       
   232     TPtrC string = TriggerStr()->GetString();
       
   233     
       
   234     iHwrEngine->DoPredictiveL( string, iPredictives );
       
   235     if( PredictiveCount() == 0 )
       
   236     	{
       
   237     	TriggerStr()->SetLast();
       
   238     	iHwrEngine->DoPredictiveL( TriggerStr()->GetString(), iPredictives );            	
       
   239     	}
       
   240     
       
   241     SetPredictives();
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // Get predictives of primary range as Number
       
   246 // ----------------------------------------------------------------------------
       
   247 //    
       
   248 void CPeninputHwrfscnDataStore::GetPredictivesOfPriRangeAsNumberL()
       
   249     {
       
   250     if( iPermittedRanges.Count() == 1 )
       
   251         {
       
   252         if( iCurrentNumberMode != EAknEditorPlainNumberModeKeymap )
       
   253             {
       
   254             HBufC* keyMappingBuf = KeyMappingStringL();
       
   255             CleanupStack::PushL( keyMappingBuf );
       
   256             TInt strLen = keyMappingBuf->Length();
       
   257             if( strLen > KNumberCount )
       
   258                 {  
       
   259                 const TUint16* keyMapingPtr = keyMappingBuf->Ptr();
       
   260                 //keyMappingBuf always contains 0~9 number symbol
       
   261                 //move the pointer to 11th char, right after 0~9 numbers, 
       
   262                 //because we just need symbol not number
       
   263                 keyMapingPtr += KNumberCount;
       
   264                 
       
   265                 TInt length = strLen - KNumberCount;
       
   266                 for( TInt i = 0; i < length; i++ )
       
   267                     {
       
   268 	                TBuf<1> charBuf;
       
   269                     charBuf.Append( ( keyMapingPtr + i ), 1 );
       
   270                 
       
   271                     iPredictives.AppendL( charBuf.AllocL() );
       
   272                     }
       
   273                 
       
   274                 SetPredictives();
       
   275                 }
       
   276             CleanupStack::PopAndDestroy( keyMappingBuf );
       
   277             }
       
   278         }
       
   279     else
       
   280         {
       
   281         TInt symCount = sizeof( NumberPredictSymCode )/sizeof( TUint16 ); 	
       
   282         
       
   283         for( TInt i = 0; i < symCount; i++ )
       
   284             {
       
   285 	        TBuf<1> charBuf;
       
   286             charBuf.Append( NumberPredictSymCode[i] );
       
   287 
       
   288             iPredictives.AppendL( charBuf.AllocL() );
       
   289             }    
       
   290                     
       
   291         SetPredictives();
       
   292         }    
       
   293     } 
       
   294 
       
   295 // ----------------------------------------------------------------------------
       
   296 // Get predictives of primary range as English
       
   297 // ----------------------------------------------------------------------------
       
   298 //    
       
   299 void CPeninputHwrfscnDataStore::GetPredictivesOfPriRangeAsEnglishL()
       
   300     {
       
   301     TInt symCount = sizeof( EnglishPredictSymCode )/sizeof( TUint16 );
       
   302     
       
   303     for( TInt i = 0; i < symCount; i++ )
       
   304         {
       
   305 	    TBuf<1> charBuf;
       
   306         charBuf.Append( EnglishPredictSymCode[i] );
       
   307 
       
   308         iPredictives.AppendL( charBuf.AllocL() );
       
   309         }
       
   310     
       
   311     if( iPredictives.Count() > 0 )
       
   312     	{
       
   313 	    SetPredictives();    
       
   314     	}
       
   315     } 
       
   316                 
       
   317 // ----------------------------------------------------------------------------
       
   318 // Do homophonic using trigger string
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 void CPeninputHwrfscnDataStore::DoHomophonicL( const TDesC& aString )
       
   322     {
       
   323     iHwrEngine->DoHomophonicL( aString, iCandidates );
       
   324     SetHomephonicCandidatesL();
       
   325     }
       
   326     
       
   327     
       
   328 // ----------------------------------------------------------------------------
       
   329 // Get the predictive count
       
   330 // ----------------------------------------------------------------------------
       
   331 //
       
   332 TInt CPeninputHwrfscnDataStore::PredictiveCount() const
       
   333     {
       
   334     return iPredictives.Count();
       
   335     }
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // Add property subscriber
       
   339 // ----------------------------------------------------------------------------
       
   340 //
       
   341 void CPeninputHwrfscnDataStore::AddSubscriber( 
       
   342     MPeninputHwrfscnPropertySubscriber* aSubscriber )
       
   343     {
       
   344     if ( aSubscriber )
       
   345         {
       
   346         const TInt index = iSubscriberList.Find( aSubscriber );
       
   347       
       
   348         if ( index == KErrNotFound )
       
   349             {
       
   350             iSubscriberList.Append( aSubscriber );
       
   351             }
       
   352         }
       
   353     }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 // Get the trigger string
       
   357 // ----------------------------------------------------------------------------
       
   358 //
       
   359 CAknFepHwrTriggerStr* CPeninputHwrfscnDataStore::TriggerStr() const
       
   360     {
       
   361     return iTriggerStr;
       
   362     }
       
   363 
       
   364 // ----------------------------------------------------------------------------
       
   365 // Set permitted ranges
       
   366 // ----------------------------------------------------------------------------
       
   367 //
       
   368 void CPeninputHwrfscnDataStore::SetPermittedRanges( TInt aPermittedRanges )
       
   369     {
       
   370     iPermittedRanges.Reset();
       
   371     
       
   372     //order can not be changed
       
   373     if ( aPermittedRanges & ERangeNative )
       
   374         {
       
   375         iPermittedRanges.Append( ERangeNative );
       
   376         }
       
   377     if ( aPermittedRanges & ERangeEnglish )
       
   378         {
       
   379         iPermittedRanges.Append( ERangeEnglish );
       
   380         }
       
   381     if ( aPermittedRanges & ERangeNumber )
       
   382         {
       
   383         iPermittedRanges.Append( ERangeNumber );
       
   384         }
       
   385     if ( aPermittedRanges & ERangeSymbol )
       
   386         {
       
   387         iPermittedRanges.Append( ERangeSymbol );
       
   388         }
       
   389     
       
   390     iIntRange = aPermittedRanges;
       
   391     
       
   392     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   393         EPeninputHwrfscnPropertyPermittedRange );
       
   394     
       
   395     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   396         EPeninputHwrfscnPropertyRange );
       
   397     // set primary and auxiliary ranges for hwr engine
       
   398     iHwrEngine->SetRanges( iPermittedRanges );
       
   399     }
       
   400 
       
   401 // ----------------------------------------------------------------------------
       
   402 // Get the permitted ranges
       
   403 // ----------------------------------------------------------------------------
       
   404 //
       
   405 const RArray<TInt>& CPeninputHwrfscnDataStore::PermittedRanges() const
       
   406     {
       
   407     return iPermittedRanges;
       
   408     }
       
   409     
       
   410 // ----------------------------------------------------------------------------
       
   411 // Set permitted cases
       
   412 // ----------------------------------------------------------------------------
       
   413 //
       
   414 void CPeninputHwrfscnDataStore::SetPermittedCases( TInt aPermittedCases )
       
   415     {
       
   416     iPermittedCases = aPermittedCases;
       
   417     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   418         EPeninputHwrfscnPropertyPermittedCases );
       
   419     }
       
   420 
       
   421 // ----------------------------------------------------------------------------
       
   422 // Set Primary range
       
   423 // ----------------------------------------------------------------------------
       
   424 //
       
   425 void CPeninputHwrfscnDataStore::SetPrimaryRange( TInt aPrimaryRange )
       
   426     {
       
   427     const TInt oldIndex = iPermittedRanges.Find( aPrimaryRange );
       
   428 
       
   429     if ( oldIndex > 0 )
       
   430         {
       
   431         iPermittedRanges.Sort();
       
   432         const TInt index = iPermittedRanges.Find( aPrimaryRange );
       
   433         
       
   434         iPermittedRanges.Remove( index );
       
   435         iPermittedRanges.Insert( aPrimaryRange, 0 );
       
   436 
       
   437         NotifySubscriber( 
       
   438             MPeninputHwrfscnPropertySubscriber::
       
   439             EPeninputHwrfscnPropertyRange );
       
   440         
       
   441         // set primary and auxiliary ranges for hwr engine
       
   442         iHwrEngine->SetRanges( iPermittedRanges );
       
   443         }
       
   444     }
       
   445 
       
   446 // ----------------------------------------------------------------------------
       
   447 // get Primary range
       
   448 // ----------------------------------------------------------------------------
       
   449 //
       
   450 TInt CPeninputHwrfscnDataStore::PrimaryRange()
       
   451 	{
       
   452 	if( iPermittedRanges.Count() > 0 )
       
   453 		{
       
   454 	    return iPermittedRanges[0];			
       
   455 		}
       
   456 	return -1;
       
   457 	}
       
   458 	
       
   459 // ----------------------------------------------------------------------------
       
   460 // get Primary range
       
   461 // ----------------------------------------------------------------------------
       
   462 //	
       
   463 TBool CPeninputHwrfscnDataStore::IsChinesePrimaryRange()
       
   464     {
       
   465     return ( iPermittedRanges[0] == ERangeNative );
       
   466     }
       
   467     
       
   468 // ----------------------------------------------------------------------------
       
   469 // Set case
       
   470 // ----------------------------------------------------------------------------
       
   471 //
       
   472 void CPeninputHwrfscnDataStore::SetCase( TInt aCase )
       
   473     {
       
   474     iCase = aCase;
       
   475     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   476         EPeninputHwrfscnPropertyCase );
       
   477     iHwrEngine->SetCase( iCase );
       
   478     }
       
   479 
       
   480 // ----------------------------------------------------------------------------
       
   481 // Judge if a language is Chinese
       
   482 // ----------------------------------------------------------------------------
       
   483 //
       
   484 TBool CPeninputHwrfscnDataStore::LanguageIsChinese( TInt aLanguage )
       
   485     {
       
   486 	if ( ( aLanguage == ELangPrcChinese ) ||
       
   487 	    ( aLanguage == ELangHongKongChinese ) ||
       
   488 	    ( aLanguage == ELangTaiwanChinese ) )
       
   489 	    {
       
   490 		return ETrue;
       
   491 	    }
       
   492 	
       
   493 	return EFalse;    
       
   494     }
       
   495    
       
   496 // ----------------------------------------------------------------------------
       
   497 // Set real engine language
       
   498 // ----------------------------------------------------------------------------
       
   499 //
       
   500 void CPeninputHwrfscnDataStore::SetEngineLanguageL( TInt aLanguage )
       
   501     {
       
   502     SetLanguageShowText( aLanguage );       
       
   503     iHwrEngine->SetLanguageL( aLanguage );
       
   504     iHwrEngine->SetPrimaryCandidateNum( KCandidateCount );
       
   505     }
       
   506 
       
   507 // ----------------------------------------------------------------------------
       
   508 // Set language show text
       
   509 // ----------------------------------------------------------------------------
       
   510 //
       
   511 void CPeninputHwrfscnDataStore::SetLanguageShowText( TInt aLanguage )
       
   512 	{
       
   513     AknPenInputUtils::GetISOLanguageCode( TLanguage( aLanguage ), 
       
   514         iLanguageShowText );
       
   515     }
       
   516     
       
   517 // ----------------------------------------------------------------------------
       
   518 // Set stroke end mark
       
   519 // ----------------------------------------------------------------------------
       
   520 //
       
   521 void CPeninputHwrfscnDataStore::SetStrokeEndMark()
       
   522     {
       
   523     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   524         EPeninputHwrfscnPropertyStrokeEndMark );
       
   525     }
       
   526 
       
   527 // ----------------------------------------------------------------------------
       
   528 // get stroke end mark from hwr engine
       
   529 // ----------------------------------------------------------------------------
       
   530 //
       
   531 TPoint CPeninputHwrfscnDataStore::StrokeEndMark()
       
   532     {
       
   533     return iHwrEngine->StrokeEndMark();
       
   534     }
       
   535     
       
   536 // ----------------------------------------------------------------------------
       
   537 // stroke end mark from control
       
   538 // ----------------------------------------------------------------------------
       
   539 //
       
   540 TPoint CPeninputHwrfscnDataStore::StrokeEndMarkFromControl()
       
   541     {
       
   542 	return TPoint( KDefaultStrokeEndMarkX, KDefaultStrokeEndMarkY );
       
   543     }
       
   544 
       
   545 // ----------------------------------------------------------------------------
       
   546 // Set language
       
   547 // ----------------------------------------------------------------------------
       
   548 //
       
   549 void CPeninputHwrfscnDataStore::SetLanguageL( TInt aLanguage )
       
   550     {
       
   551     if( iLanguage == aLanguage )
       
   552         {
       
   553         return;
       
   554         }
       
   555         
       
   556     if ( !LanguageIsChinese( aLanguage ) && ( aLanguage != ELangEnglish ) )
       
   557         {
       
   558         return;
       
   559         }
       
   560         
       
   561     if ( aLanguage == ELangEnglish )
       
   562         {
       
   563         TLanguage displayLang = User::Language();
       
   564         
       
   565         // set real language to a Chinese
       
   566         if ( !LanguageIsChinese( iLanguage ) )
       
   567             {
       
   568             // original language is not Chinese
       
   569             if ( LanguageIsChinese( displayLang ) )
       
   570                 {
       
   571             	iLanguage = displayLang;
       
   572                 }
       
   573             else
       
   574                 {
       
   575                 iLanguage = ELangPrcChinese;	
       
   576                 }
       
   577                 
       
   578             SetEngineLanguageL( iLanguage );
       
   579             }   
       
   580         }
       
   581     else
       
   582         {
       
   583         // aLanguage is Chinese
       
   584         if ( iLanguage != aLanguage )
       
   585             {
       
   586         	iLanguage = aLanguage;
       
   587             
       
   588             SetEngineLanguageL( iLanguage );
       
   589             }
       
   590         }
       
   591 
       
   592     // make sure whole window is visible
       
   593     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   594         EPeninputHwrfscnPropertyLanguageChanged );
       
   595     }
       
   596 
       
   597 // ----------------------------------------------------------------------------
       
   598 // Get language
       
   599 // ----------------------------------------------------------------------------
       
   600 //
       
   601 TInt CPeninputHwrfscnDataStore::CurLanguage()
       
   602     {
       
   603     return iLanguage;
       
   604     }
       
   605     
       
   606 // ----------------------------------------------------------------------------
       
   607 // Set writting speed
       
   608 // ----------------------------------------------------------------------------
       
   609 //
       
   610 void CPeninputHwrfscnDataStore::SetWritingSpeed( TInt aWritingSpeed )
       
   611     {
       
   612     iWritingSpeed = aWritingSpeed;
       
   613     
       
   614     TTimeIntervalMicroSeconds32 speed;
       
   615     switch ( iWritingSpeed )
       
   616         {
       
   617         case EWritingSpeedVeryFast: 
       
   618             speed = EHwrWritingSpeedVeryFast;
       
   619             break;
       
   620         
       
   621         case EWritingSpeedFast: 
       
   622             speed = EHwrWritingSpeedFast;
       
   623             break;
       
   624         
       
   625         case EWritingSpeedNormal: 
       
   626             speed = EHwrWritingSpeedNormal;
       
   627             break;
       
   628         
       
   629         case EWritingSpeedSlow: 
       
   630             speed = EHwrWritingSpeedSlow;
       
   631             break;
       
   632         
       
   633         case EWritingSpeedVerySlow: 
       
   634             speed = EHwrWritingSpeedVerySlow;
       
   635             break;
       
   636         
       
   637         default:
       
   638             speed = EHwrWritingSpeedNormal;
       
   639             break;
       
   640         }
       
   641 
       
   642     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   643         EPeninputHwrfscnPropertyWriteSpeed );
       
   644     }
       
   645 
       
   646 // ----------------------------------------------------------------------------
       
   647 // get writting speed
       
   648 // ----------------------------------------------------------------------------
       
   649 //
       
   650 TTimeIntervalMicroSeconds32 CPeninputHwrfscnDataStore::WritingSpeed()
       
   651 	{
       
   652     TTimeIntervalMicroSeconds32 speed;
       
   653     switch ( iWritingSpeed )
       
   654         {
       
   655         case EWritingSpeedVeryFast: 
       
   656             speed = EHwrWritingSpeedVeryFast;
       
   657             break;
       
   658        
       
   659         case EWritingSpeedFast: 
       
   660             speed = EHwrWritingSpeedFast;
       
   661             break;
       
   662         
       
   663         case EWritingSpeedNormal: 
       
   664             speed = EHwrWritingSpeedNormal;
       
   665             break;
       
   666         
       
   667         case EWritingSpeedSlow: 
       
   668             speed = EHwrWritingSpeedSlow;
       
   669             break;
       
   670         
       
   671         case EWritingSpeedVerySlow: 
       
   672             speed = EHwrWritingSpeedVerySlow;
       
   673             break;
       
   674         
       
   675         default:
       
   676             speed = EHwrWritingSpeedNormal;
       
   677             break;
       
   678         }	    
       
   679 	return speed;	
       
   680 	}
       
   681 	
       
   682 // ----------------------------------------------------------------------------
       
   683 // Set trail drawing pen size
       
   684 // ----------------------------------------------------------------------------
       
   685 //
       
   686 void CPeninputHwrfscnDataStore::SetBoxPenSize( const TSize& aSize )
       
   687     {
       
   688     iPenSize = aSize;
       
   689 
       
   690     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   691         EPeninputHwrfscnPropertyPenSize );        
       
   692     }
       
   693 
       
   694 // ----------------------------------------------------------------------------
       
   695 // Set trail drawing pen size
       
   696 // ----------------------------------------------------------------------------
       
   697 //
       
   698 TSize CPeninputHwrfscnDataStore::PenSize()
       
   699 	{
       
   700 	return iPenSize;	
       
   701 	}
       
   702 	
       
   703 // ----------------------------------------------------------------------------
       
   704 // Set trail drawing pen color
       
   705 // ----------------------------------------------------------------------------
       
   706 //
       
   707 void CPeninputHwrfscnDataStore::SetBoxPenColor( const TRgb& aCol )
       
   708     {
       
   709     iPenColor = aCol;
       
   710 
       
   711     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   712         EPeninputHwrfscnPropertyPenColor );        
       
   713     }
       
   714 
       
   715 // ----------------------------------------------------------------------------
       
   716 // get trail drawing pen color
       
   717 // ----------------------------------------------------------------------------
       
   718 //
       
   719 
       
   720 TRgb& CPeninputHwrfscnDataStore::PenColor()
       
   721 	{
       
   722 	return iPenColor;	
       
   723 	}
       
   724 
       
   725 // ----------------------------------------------------------------------------
       
   726 // Set the candidate list
       
   727 // ----------------------------------------------------------------------------
       
   728 //
       
   729 void CPeninputHwrfscnDataStore::SetCandidatesL()
       
   730     {        
       
   731      //those special chars: backspace and enter char need sent to
       
   732      //app directly, not need to display candidate window
       
   733     
       
   734     if( !IsDirectlySentCandidate( *iCandidates[0] ) )
       
   735         {
       
   736         NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   737             EPeninputHwrfscnPropertyCandidates );
       
   738         iTriggerStr->Set( *iCandidates[0] );
       
   739         DoPredictiveL();	
       
   740         }
       
   741     }
       
   742 
       
   743 // ----------------------------------------------------------------------------
       
   744 // Set homephonic candidate list
       
   745 // ----------------------------------------------------------------------------
       
   746 //
       
   747 
       
   748 void CPeninputHwrfscnDataStore::SetHomephonicCandidatesL()
       
   749     {
       
   750     if ( iCandidates.Count() > 0 )
       
   751         {
       
   752         NotifySubscriber( MPeninputHwrfscnPropertySubscriber
       
   753                         ::EPeninputHwrfscnPropertyHomephonicCandidates ); 
       
   754         TriggerStr()->Set( *iCandidates[0] );
       
   755         DoPredictiveL();                 
       
   756         }
       
   757     }
       
   758 // ----------------------------------------------------------------------------
       
   759 // Set the predictive list
       
   760 // ----------------------------------------------------------------------------
       
   761 //
       
   762 void CPeninputHwrfscnDataStore::SetPredictives()
       
   763     {
       
   764     if( PredictiveCount() > 0 )
       
   765         {
       
   766         NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   767             EPeninputHwrfscnPropertyPredictives );
       
   768         }
       
   769     }
       
   770     
       
   771 // ----------------------------------------------------------------------------
       
   772 // Add new predictives to list
       
   773 // ----------------------------------------------------------------------------
       
   774 //
       
   775 void CPeninputHwrfscnDataStore::AddPredictives()
       
   776     {
       
   777     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   778         EPeninputHwrfscnPropertyAddPredictives );
       
   779     }
       
   780     
       
   781 // ----------------------------------------------------------------------------
       
   782 // Get the candidate
       
   783 // ----------------------------------------------------------------------------
       
   784 //    
       
   785 const RPointerArray<HBufC>& CPeninputHwrfscnDataStore::Candidate() 
       
   786     {
       
   787     return iCandidates;
       
   788     }
       
   789     
       
   790 // ----------------------------------------------------------------------------
       
   791 // Get the predictive
       
   792 // ----------------------------------------------------------------------------
       
   793 //
       
   794 const RPointerArray<HBufC>& CPeninputHwrfscnDataStore::Predictive()
       
   795     {
       
   796     return iPredictives;
       
   797     }
       
   798     
       
   799 // ----------------------------------------------------------------------------
       
   800 // Notify subscriber
       
   801 // ----------------------------------------------------------------------------
       
   802 //
       
   803 void CPeninputHwrfscnDataStore::NotifySubscriber( 
       
   804     const MPeninputHwrfscnPropertySubscriber::
       
   805     TPeninputHwrfscnProperty aPropertyName )
       
   806     {
       
   807     for ( TInt i = 0; i < iSubscriberList.Count(); i++ )
       
   808         {
       
   809         TRAP_IGNORE( iSubscriberList[i]->PropertyChangedL( aPropertyName ) );
       
   810         }
       
   811     }
       
   812 
       
   813 // ----------------------------------------------------------------------------
       
   814 // Callback method to notify repository change
       
   815 // ----------------------------------------------------------------------------
       
   816 //
       
   817 TInt CPeninputHwrfscnDataStore::HandleGSRepositoryCallBack( TAny* aPtr )
       
   818     {
       
   819     CPeninputHwrfscnDataStore *self = 
       
   820         static_cast<CPeninputHwrfscnDataStore*>( aPtr );
       
   821     
       
   822     CAknFepRepositoryWatcher* watcher = self->iGSRepositoryWatcher;
       
   823     if ( watcher )
       
   824         {
       
   825         TInt newValue = self->GetNewValue( watcher, watcher->ChangedKey() );
       
   826         
       
   827         switch ( watcher->ChangedKey() )
       
   828             {
       
   829             case KSettingsWritingSpeed:
       
   830                 self->SetWritingSpeed( newValue );
       
   831                 break;
       
   832             case KSettingsPenWidth:
       
   833                 self->SetBoxPenSize( TSize( newValue,newValue ) );
       
   834                 break;
       
   835             case KSettingsPenColor:
       
   836                 self->SetBoxPenColor( newValue );
       
   837                 break;
       
   838             default:
       
   839                 break;
       
   840             }
       
   841         }
       
   842     return KErrNone;
       
   843     }
       
   844 
       
   845 // ----------------------------------------------------------------------------
       
   846 // Set number mode for hwr engine
       
   847 // ----------------------------------------------------------------------------
       
   848 //
       
   849 void CPeninputHwrfscnDataStore::SetNumberMode( 
       
   850     const TAknEditorNumericKeymap aNumberMode )
       
   851     {
       
   852     iCurrentNumberMode = aNumberMode;
       
   853     NotifySubscriber( MPeninputHwrfscnPropertySubscriber::
       
   854         EPeninputHwrfscnPropertyNumberMode );
       
   855 
       
   856     iHwrEngine->SetNumberMode( aNumberMode );
       
   857     iHwrEngine->SetRanges( iPermittedRanges );       
       
   858     }
       
   859 
       
   860 // ----------------------------------------------------------------------------
       
   861 // Set number mode for hwr engine
       
   862 // ----------------------------------------------------------------------------
       
   863 //
       
   864 void CPeninputHwrfscnDataStore::SetNumberModeL( const TDesC& aCustomMode )
       
   865     {
       
   866     iHwrEngine->SetCustomKeymapL( aCustomMode );
       
   867     
       
   868     delete iUserDefinedResource;
       
   869     iUserDefinedResource = NULL;
       
   870     iUserDefinedResource = HBufC::NewL( aCustomMode.Length() );
       
   871     iUserDefinedResource->Des().Append( aCustomMode );
       
   872     }
       
   873 
       
   874 // ----------------------------------------------------------------------------
       
   875 // Get pen trail color
       
   876 // ----------------------------------------------------------------------------
       
   877 //
       
   878 TInt CPeninputHwrfscnDataStore::GetPenTrailColor()
       
   879     {
       
   880     TInt newValue = 0; 
       
   881     iRepositorySetting->Get( KSettingsPenColor, newValue );
       
   882     
       
   883     if (!AknPenInputTrailColorUtils::CheckColorInColorTable(newValue))
       
   884         {
       
   885         return AknPenInputTrailColorUtils::GetTrailColorByTheme();
       
   886         }
       
   887     return newValue;
       
   888     }
       
   889 // ----------------------------------------------------------------------------
       
   890 // LoadAndPublishDefault
       
   891 // ----------------------------------------------------------------------------
       
   892 //
       
   893 void CPeninputHwrfscnDataStore::LoadAndPublishDefaultL()
       
   894     {
       
   895     if ( iRepositorySetting )
       
   896         {
       
   897         TInt newValue;
       
   898 
       
   899         iRepositorySetting->Get( KSettingsWritingSpeed, newValue );
       
   900         SetWritingSpeed( newValue );
       
   901         
       
   902         iRepositorySetting->Get( KSettingsPenWidth, newValue );
       
   903         TInt width = newValue;
       
   904         TInt height = newValue;
       
   905         SetBoxPenSize( TSize( width,height ) );
       
   906 
       
   907         newValue = GetPenTrailColor();        
       
   908         SetBoxPenColor( newValue );
       
   909         
       
   910         iRepositorySetting->Get( KSettingsPenInputLang, newValue );
       
   911         SetLanguageL( newValue );
       
   912         }
       
   913     }
       
   914 
       
   915 // ----------------------------------------------------------------------------
       
   916 // save range to repository if english or chinese
       
   917 // ----------------------------------------------------------------------------
       
   918 //
       
   919 void CPeninputHwrfscnDataStore::SaveRange( TInt aRange )
       
   920     {
       
   921     if ( iRepositoryFep && ( aRange == ERangeNative || aRange == ERangeEnglish ) )
       
   922         {
       
   923         iRepositoryFep->Set( KAknFepLastUsedRange, aRange );
       
   924         }
       
   925     }
       
   926 
       
   927 // ----------------------------------------------------------------------------
       
   928 // Get rep value
       
   929 // ----------------------------------------------------------------------------
       
   930 //
       
   931 TInt CPeninputHwrfscnDataStore::GetNewValue( 
       
   932     CAknFepRepositoryWatcher* aWatcher, TInt aId )
       
   933     {
       
   934     TInt newValue = -1;
       
   935     
       
   936     if ( aWatcher == iGSRepositoryWatcher )
       
   937         {
       
   938         iRepositorySetting->Get( aId, newValue );
       
   939         }
       
   940         
       
   941     return newValue;
       
   942     }
       
   943 
       
   944 // ------------------------------------------------------------------
       
   945 // Get next predictive candidate page
       
   946 // -------------------------------------------------------------------
       
   947 //
       
   948 void CPeninputHwrfscnDataStore::GetNextPredictivePageL()
       
   949     {
       
   950     iHwrEngine->DoPredictiveL( KNullDesC, iPredictives, ETrue );
       
   951  
       
   952     TInt predictCount = PredictiveCount();
       
   953     if ( predictCount> 0 && predictCount < KMaxPredictiveCount )
       
   954         {
       
   955         AddPredictives();
       
   956         }
       
   957     }
       
   958     
       
   959 // --------------------------------------------------------------------
       
   960 // IsNumberOnly()
       
   961 // -------------------------------------------------------------------
       
   962 //  
       
   963 TBool CPeninputHwrfscnDataStore::IsNumberOnly()
       
   964     {
       
   965     return ( ( iPermittedRanges.Count()==1 ) && 
       
   966         ( iPermittedRanges[0]==ERangeNumber ) );
       
   967     }
       
   968     
       
   969 // --------------------------------------------------------------------
       
   970 // Get number keymapping string
       
   971 // --------------------------------------------------------------------
       
   972 //   
       
   973 HBufC* CPeninputHwrfscnDataStore::KeyMappingStringL() const
       
   974     {
       
   975     TLocale locale;
       
   976     TBuf<KMaxNumericString> rs = KNumberString();
       
   977     const TInt index = iKeyMappingIdList.Find( iCurrentNumberMode );
       
   978     
       
   979     if ( iCurrentNumberMode == EKeymapFromResource )
       
   980         {
       
   981         rs.Append( *iUserDefinedResource );
       
   982         }
       
   983     
       
   984     else if ( index != KErrNotFound )
       
   985         {
       
   986         HBufC* buf = iKeyMappingStringList[index];
       
   987         
       
   988         rs.Append( *buf );
       
   989         
       
   990         if ( ( iCurrentNumberMode == 
       
   991             EAknEditorCalculatorNumberModeKeymap ) ||
       
   992             ( iCurrentNumberMode == EAknEditorConverterNumberModeKeymap ) )
       
   993             {
       
   994             rs.Append( locale.DecimalSeparator() ); 
       
   995             }       
       
   996         }
       
   997         
       
   998     return rs.AllocL();          
       
   999     }
       
  1000 
       
  1001 // ------------------------------------------------------------------------
       
  1002 // CPeninputHwrfscnDataStore::IsSpecialDisplayChars
       
  1003 // ------------------------------------------------------------------------
       
  1004 //       
       
  1005 TBool CPeninputHwrfscnDataStore::IsSpecialDisplayChars( const TDesC& aChar )
       
  1006     {
       
  1007     
       
  1008     if( aChar.Compare( KGestureEnter ) == 0 
       
  1009        || aChar.Compare( KDisplayBackspace ) == 0
       
  1010        || aChar.Compare( KGestureSpace )== 0
       
  1011        || aChar.Compare( KSmileFontCode ) == 0
       
  1012        || aChar.Compare( KCryFontCode ) == 0 ) 
       
  1013         {
       
  1014         return ETrue;
       
  1015         }
       
  1016             
       
  1017     return EFalse;
       
  1018     }
       
  1019     
       
  1020 // ------------------------------------------------------------------------
       
  1021 // CPeninputHwrfscnDataStore::ConvertDisplayChars
       
  1022 // ------------------------------------------------------------------------
       
  1023 //   
       
  1024 HBufC* CPeninputHwrfscnDataStore::ConvertDisplayChars( const TDesC& aChar )    
       
  1025     {
       
  1026     HBufC* convertedCan = NULL;
       
  1027     TBuf<KSpecialConvertedCharCount> str;
       
  1028     if( aChar.Compare( KGestureEnter ) == 0 )
       
  1029         {
       
  1030         str.Append( EKeyEnter );
       
  1031         } 
       
  1032     else if( aChar.Compare( KDisplayBackspace ) == 0 )
       
  1033         {
       
  1034         str.Append( EKeyBackspace );
       
  1035         }
       
  1036     else if( aChar.Compare( KGestureSpace )== 0 )
       
  1037         {
       
  1038         str.Append( EKeySpace );
       
  1039         }
       
  1040     else if( aChar.Compare( KSmileFontCode ) == 0 )
       
  1041         {
       
  1042         str.Append( KColon );
       
  1043         str.Append( KHyphen );
       
  1044         str.Append( KRightParenthesis );
       
  1045         }
       
  1046     else if( aChar.Compare( KCryFontCode ) == 0 )
       
  1047         {
       
  1048         str.Append( KColon );
       
  1049         str.Append( KHyphen );
       
  1050         str.Append( KLeftParenthesis );
       
  1051         }
       
  1052                  
       
  1053     if( str.Length() > 0 )
       
  1054     	{
       
  1055     	convertedCan = str.Alloc();	
       
  1056     	}
       
  1057     	
       
  1058     return convertedCan;
       
  1059     }
       
  1060 
       
  1061 // ----------------------------------------------------------------------------
       
  1062 // Get language show text
       
  1063 // ----------------------------------------------------------------------------
       
  1064 //
       
  1065 const TDesC& CPeninputHwrfscnDataStore::LanguageShowText()
       
  1066     {
       
  1067     return iLanguageShowText;
       
  1068     }
       
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CPeninputHwrfscnDataStore::IsDirectlySentCandidate
       
  1072 // -----------------------------------------------------------------------------
       
  1073 //  
       
  1074 TBool CPeninputHwrfscnDataStore::IsDirectlySentCandidate( const TDesC& aChar )
       
  1075     {
       
  1076     
       
  1077     if( aChar.Compare( KGestureEnter ) == 0 
       
  1078       || aChar.Compare( KDisplayBackspace ) == 0 )
       
  1079        {
       
  1080        return ETrue;
       
  1081        }
       
  1082            
       
  1083     return EFalse;
       
  1084     }
       
  1085 TInt CPeninputHwrfscnDataStore::SetInputAreaSize(TSize& aSize)
       
  1086     {
       
  1087     return iHwrEngine->SetInputAreaSize(aSize);    
       
  1088     }      
       
  1089 TInt CPeninputHwrfscnDataStore::SetScreenSize(TSize& aSize)
       
  1090     {
       
  1091     return iHwrEngine->SetScreenSize(aSize);    
       
  1092     }      
       
  1093 // End Of File