textinput/peninputgenerichwr/src/peninputhwrarabicdatamgr.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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 <peninputdataconverter.h>
       
    21 #include <centralrepository.h>
       
    22 #include <settingsinternalcrkeys.h>
       
    23 #include <peninputlayoutcontext.h>
       
    24 #include <peninputcommonlayoutglobalenum.h>
       
    25 
       
    26 // User includes
       
    27 #include "peninputhwrarabic.hrh"
       
    28 #include "peninputhwrarabicengine.h"
       
    29 #include "peninputhwrarabicdatamgr.h"
       
    30 #include "peninputpluginutils.h"
       
    31 
       
    32 // Constants
       
    33 const TInt KGuideLineOn = 1;
       
    34 enum
       
    35     {
       
    36     EHwrWritingSpeedVeryFast    = 300 * 1000,
       
    37     EHwrWritingSpeedFast        = 400 * 1000,
       
    38     EHwrWritingSpeedNormal      = 550 * 1000,
       
    39     EHwrWritingSpeedSlow        = 700 * 1000,
       
    40     EHwrWritingSpeedVerySlow    = 1000 * 1000
       
    41     };
       
    42 
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CPeninputGenericHwrDataMgr::NewL
       
    48 // (other items were commented in a header)
       
    49 // ---------------------------------------------------------------------------
       
    50 //    
       
    51 CPeninputHwrBxAbDataMgr* CPeninputHwrBxAbDataMgr::NewL( 
       
    52     MPeninputLayoutContext* aContext ,CPtiEngine* aPtiEngine)
       
    53     {
       
    54     CPeninputHwrBxAbDataMgr* self = NewLC( aContext ,aPtiEngine );
       
    55     CleanupStack::Pop( self );
       
    56       
       
    57     return self;
       
    58     }
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // CPeninputHwrBxAbDataMgr::NewLC
       
    62 // (other items were commented in a header)
       
    63 // ---------------------------------------------------------------------------
       
    64 //  
       
    65 CPeninputHwrBxAbDataMgr* CPeninputHwrBxAbDataMgr::NewLC( 
       
    66     MPeninputLayoutContext* aContext ,CPtiEngine* aPtiEngine)
       
    67     {
       
    68     CPeninputHwrBxAbDataMgr* self = 
       
    69         new ( ELeave ) CPeninputHwrBxAbDataMgr( aContext );
       
    70     self->iPtiEngine = aPtiEngine;
       
    71     CleanupStack::PushL( self );
       
    72     self->ConstructL(); 
       
    73 
       
    74     return self;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // CPeninputHwrBxAbDataMgr::CPeninputHwrBxAbDataMgr
       
    79 // (other items were commented in a header)
       
    80 // ---------------------------------------------------------------------------
       
    81 //  
       
    82 CPeninputHwrBxAbDataMgr::CPeninputHwrBxAbDataMgr( 
       
    83     MPeninputLayoutContext* aContext ) 
       
    84     : CPeninputDataMgr( aContext )
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CPeninputHwrBxAbDataMgr::~CPeninputHwrBxAbDataMgr
       
    90 // (other items were commented in a header)
       
    91 // ---------------------------------------------------------------------------
       
    92 //      
       
    93 CPeninputHwrBxAbDataMgr::~CPeninputHwrBxAbDataMgr()
       
    94     {
       
    95     if( iOwnPtiEngine )
       
    96         {
       
    97         delete iPtiEngine;
       
    98         }
       
    99     delete iPenData.iRecognizer; 
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CPeninputHwrBxAbDataMgr::GetPenTrailColor
       
   104 // (other items were commented in a header)
       
   105 // ---------------------------------------------------------------------------
       
   106 //   
       
   107 TRgb CPeninputHwrBxAbDataMgr::GetPenTrailColor()
       
   108     {
       
   109     TInt newValue = 0; 
       
   110     iGSRepository->Get( KSettingsPenColor, newValue );
       
   111     
       
   112     if (!AknPenInputTrailColorUtils::CheckColorInColorTable(newValue))
       
   113         {
       
   114         newValue = AknPenInputTrailColorUtils::GetTrailColorByTheme();
       
   115         }
       
   116     return TRgb(newValue);
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CPeninputHwrBxAbDataMgr::InitMore
       
   121 // (other items were commented in a header)
       
   122 // ---------------------------------------------------------------------------
       
   123 //  
       
   124 void CPeninputHwrBxAbDataMgr::InitMore()
       
   125     {
       
   126     // Read pen data
       
   127     if ( iGSRepository )
       
   128         {
       
   129         TInt newValue;                
       
   130         // Read guide line on/off flag, don't remove these code
       
   131         newValue = KGuideLineOn;
       
   132         iPenData.iGuideLineOn = iGSRepository->Get( KSettingsPenInputGuideLine, newValue );
       
   133         iPenData.iGuideLineOn = newValue;
       
   134         
       
   135         iPenData.iPenColor = GetPenTrailColor();
       
   136         
       
   137         newValue = 1;
       
   138         iGSRepository->Get( KSettingsPenWidth, newValue );        
       
   139         iPenData.iPenSize = TSize( newValue, newValue );
       
   140         
       
   141         newValue = 2;
       
   142         iGSRepository->Get( KSettingsWritingSpeed, newValue );        
       
   143         iPenData.iFadingSpeed = newValue;
       
   144         iPenData.iWritingSpeed = TransferWritingSpeed( newValue );
       
   145         }
       
   146     
       
   147     if( !iPtiEngine )    
       
   148         {
       
   149         TRAP_IGNORE( iPtiEngine = CPtiEngine::NewL( ETrue ));
       
   150         iOwnPtiEngine = ETrue; 
       
   151         }
       
   152         
       
   153     TRAP_IGNORE( iPenData.iRecognizer = CPeninputHwrBxAbEngine::NewL(iPtiEngine) );
       
   154     iPenData.iRecognizer->EnableWordRecognition( ETrue );    
       
   155     iReserve_1 = &iPenData;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CPeninputHwrBxAbDataMgr::HandleGSRepositoryChange
       
   160 // (other items were commented in a header)
       
   161 // ---------------------------------------------------------------------------
       
   162 //  
       
   163 void CPeninputHwrBxAbDataMgr::HandleGSRepositoryChange( TInt aChangedKey )
       
   164     {
       
   165     TInt newValue = 0;
       
   166     
       
   167     switch ( aChangedKey )
       
   168         {
       
   169         case KSettingsPenColor:
       
   170         	  {
       
   171             iGSRepository->Get( KSettingsPenColor, newValue ); 
       
   172             iPenData.iPenColor = newValue;           
       
   173             iContext->SendEventToWindow( EPeninputLayoutHwrEventPenColorChange, 
       
   174                 NULL ); 
       
   175             }
       
   176             break;
       
   177         case KSettingsPenWidth:
       
   178         	  {
       
   179             iGSRepository->Get( KSettingsPenWidth, newValue );        
       
   180             iPenData.iPenSize = TSize( newValue, newValue );            
       
   181             iContext->SendEventToWindow( EPeninputLayoutHwrEventPenSizeChange, 
       
   182                 NULL );
       
   183             }
       
   184             break; 
       
   185         case KSettingsWritingSpeed:
       
   186         	  {
       
   187             iGSRepository->Get( KSettingsWritingSpeed, newValue );                    
       
   188             iPenData.iFadingSpeed = newValue;
       
   189             iPenData.iWritingSpeed = TransferWritingSpeed( newValue );
       
   190             iContext->SendEventToWindow
       
   191                 ( EPeninputLayoutHwrEventWritingSpeedChange, NULL );
       
   192             }
       
   193             break;
       
   194         case KSettingsPenInputGuideLine:
       
   195         	  {
       
   196             iGSRepository->Get( KSettingsPenInputGuideLine, newValue ); 
       
   197             if ( newValue != iPenData.iGuideLineOn )
       
   198                 {
       
   199                 iPenData.iGuideLineOn = newValue;
       
   200                 iContext->SendEventToWindow
       
   201                     ( EPeninputLayoutHwrEventGuideLineChanged, NULL );
       
   202                 }        
       
   203             }
       
   204             break;
       
   205         default:
       
   206             break;
       
   207         }
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CPeninputHwrBxAbDataMgr::Reset
       
   212 // (other items were commented in a header)
       
   213 // ---------------------------------------------------------------------------
       
   214 //  
       
   215 void CPeninputHwrBxAbDataMgr::Reset()
       
   216     {
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------------------------
       
   220 // CPeninputHwrBxAbDataMgr::TransferWritingSpeed
       
   221 // (other items were commented in a header)
       
   222 // ---------------------------------------------------------------------------
       
   223 //  
       
   224 TInt CPeninputHwrBxAbDataMgr::TransferWritingSpeed( TInt aWritingSpeed )
       
   225     {
       
   226     TInt speed;
       
   227     
       
   228     switch ( aWritingSpeed )
       
   229         {
       
   230         case 1: 
       
   231             {
       
   232             speed = EHwrWritingSpeedVeryFast;
       
   233             }
       
   234             break;
       
   235         case 2: 
       
   236             {
       
   237             speed = EHwrWritingSpeedFast;
       
   238             }
       
   239             break;
       
   240         case 3: 
       
   241             {
       
   242             speed = EHwrWritingSpeedNormal;
       
   243             }
       
   244             break;
       
   245         case 4: 
       
   246             {
       
   247             speed = EHwrWritingSpeedSlow;
       
   248             }
       
   249             break;
       
   250         case 5:
       
   251             { 
       
   252             speed = EHwrWritingSpeedVerySlow;
       
   253             }
       
   254             break;
       
   255         default:
       
   256             {
       
   257             speed = EHwrWritingSpeedNormal;
       
   258             }
       
   259             break;
       
   260         }
       
   261         
       
   262     return speed;    
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CPeninputHwrBxAbDataMgr::SetData
       
   267 // (other items were commented in a header)
       
   268 // ---------------------------------------------------------------------------
       
   269 //   
       
   270 void CPeninputHwrBxAbDataMgr::SetData( TPeninputDataType aDataType, 
       
   271                                          TAny* aData )
       
   272     {
       
   273     switch ( aDataType )
       
   274         {
       
   275         case EAkninputDataTypeInputArea:
       
   276             {
       
   277             iInputArea = *(TSize*)aData;
       
   278             }   
       
   279             break;
       
   280          default:
       
   281             {
       
   282             CPeninputDataMgr::SetData( aDataType, aData );
       
   283             }
       
   284         }
       
   285     NotifyEngine( aDataType, aData ) ;    
       
   286     }
       
   287 
       
   288  
       
   289  // ---------------------------------------------------------------------------
       
   290 // CPeninputHwrBxAbDataMgr::NotifyEngine
       
   291 // (other items were commented in a header)
       
   292 // ---------------------------------------------------------------------------
       
   293 //   
       
   294 TAny* CPeninputHwrBxAbDataMgr::RequestData( TPeninputDataType aDataType )
       
   295     {
       
   296     switch ( aDataType )
       
   297         {
       
   298         case EAkninputDataTypeGuideLineTop: 
       
   299             {
       
   300             iPenData.iRecognizer->GetTopGuideLinePos( iHelpLine );
       
   301             return &iHelpLine;
       
   302             }
       
   303         case EAkninputDataTypeGuideLineBottom:
       
   304             {
       
   305             iPenData.iRecognizer->GetBottomGuideLinePos( iBaseLine );
       
   306             return &iBaseLine;
       
   307             }
       
   308         case EPeninputDataTypePenTailColor:
       
   309             {
       
   310             iPenData.iPenColor = GetPenTrailColor();
       
   311             return &iPenData.iPenColor;   
       
   312             }            
       
   313          default:
       
   314             {
       
   315             return CPeninputDataMgr::RequestData( aDataType );
       
   316             }
       
   317         }
       
   318     }
       
   319     
       
   320 // ---------------------------------------------------------------------------
       
   321 // CPeninputHwrBxAbDataMgr::NotifyEngine
       
   322 // (other items were commented in a header)
       
   323 // ---------------------------------------------------------------------------
       
   324 //      
       
   325 void CPeninputHwrBxAbDataMgr::NotifyEngine( TPeninputDataType aType, 
       
   326                                                TAny* aData )
       
   327     {
       
   328     // Call the function in base class, which will store data to CenRep
       
   329     CPeninputDataMgr::NotifyEngine( aType, aData );
       
   330       
       
   331     TInt* data = ( TInt* ) aData;
       
   332     
       
   333     // Notify engine, when language, range, case changed
       
   334     switch ( aType )
       
   335         {
       
   336         case EPeninputDataTypeCase: 
       
   337             {
       
   338             iPenData.iRecognizer->SetCase( *data );
       
   339             }
       
   340             break;
       
   341         case EPeninputDataTypeInputLanguage: 
       
   342             {
       
   343             iPenData.iRecognizer->SetLanguage( *data );
       
   344             }
       
   345             break;
       
   346         case EPeninputDataTypeCurrentRange: 
       
   347             {
       
   348             iPenData.iRecognizer->SetMode( *data );
       
   349             }
       
   350             break;
       
   351         case EPeninputDataTypeNumericKeymap:
       
   352             {
       
   353             iPenData.iRecognizer->SetNumberMode
       
   354                 ( ( TAknEditorNumericKeymap )*data );
       
   355             }
       
   356             break;     
       
   357         case EAknFepDataTypeUseDefinedResource:
       
   358             {
       
   359             HBufC* res = (HBufC*)RequestData(EAknFepDataTypeUseDefinedResource);
       
   360             iPenData.iRecognizer->SetPermittedCharSet(*res);
       
   361             }
       
   362             break;
       
   363         case EAkninputDataTypeInputArea:
       
   364             {
       
   365             iPenData.iRecognizer->SetInputAreaSize( *(TSize*)data );
       
   366             }   
       
   367         break;
       
   368         default:
       
   369             break;
       
   370         }    
       
   371     }