textinput/peninputcommonlayout/src/peninputdatamgr.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     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:  Implementation of the common layout data manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <aknfeppeninputenums.h>
       
    21 #include <PtiEngine.h>
       
    22 #include <peninputpluginutils.h>   // Use resource utils,laf env,rep notifier
       
    23 #include <centralrepository.h>
       
    24 #include <AknFepInternalCRKeys.h>
       
    25 #include <settingsinternalcrkeys.h>
       
    26 
       
    27 // User includes
       
    28 #include "peninputdatamgr.h"
       
    29 #include "peninputdataprovider.h"
       
    30 #include "peninputlayoutcontext.h"
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CPeninputDataMgr::NewL
       
    37 // (other items were commented in a header)
       
    38 // --------------------------------------------------------------------------
       
    39 //           
       
    40 EXPORT_C CPeninputDataMgr* CPeninputDataMgr::NewL( 
       
    41     MPeninputLayoutContext* aContext )
       
    42     {
       
    43     CPeninputDataMgr* self = NewLC( aContext );
       
    44     CleanupStack::Pop( self );
       
    45 
       
    46     return self;
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CPeninputDataMgr::NewLC
       
    51 // (other items were commented in a header)
       
    52 // --------------------------------------------------------------------------
       
    53 //           
       
    54 EXPORT_C CPeninputDataMgr* CPeninputDataMgr::NewLC( 
       
    55     MPeninputLayoutContext* aContext )
       
    56     {
       
    57     CPeninputDataMgr* self = new ( ELeave ) CPeninputDataMgr( aContext );
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL(); 
       
    60 
       
    61     return self;        
       
    62     } 
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 // CPeninputDataMgr::~CPeninputDataMgr
       
    66 // (other items were commented in a header)
       
    67 // --------------------------------------------------------------------------
       
    68 //           
       
    69 EXPORT_C CPeninputDataMgr::~CPeninputDataMgr()
       
    70     {    
       
    71     delete iGSRepositoryWatcher;
       
    72     delete iGSRepository;
       
    73     delete iAknFepRepository;
       
    74     delete iUserDefinedResource;
       
    75     } 
       
    76 
       
    77 // --------------------------------------------------------------------------
       
    78 // CPeninputDataMgr::CPeninputDataMgr
       
    79 // (other items were commented in a header).
       
    80 // --------------------------------------------------------------------------
       
    81 //      
       
    82 EXPORT_C CPeninputDataMgr::CPeninputDataMgr( 
       
    83     MPeninputLayoutContext* aContext ) 
       
    84     : iContext(aContext),
       
    85       iUnitWidthSet(EFalse),
       
    86       iUnitHeightSet(EFalse)
       
    87     {
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPeninputDataMgr::ConstructL
       
    92 // (other items were commented in a header)
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 EXPORT_C void CPeninputDataMgr::ConstructL()
       
    96     {
       
    97     TInt ret = 0;
       
    98     
       
    99     // Construct aknfep CenRep
       
   100     TRAP( ret, iAknFepRepository = CRepository::NewL( KCRUidAknFep ) );
       
   101 
       
   102     // Construct GS CenRep
       
   103     TRAP( ret, iGSRepository = 
       
   104           CRepository::NewL( KCRUidPersonalizationSettings ) );
       
   105 
       
   106     if ( iGSRepository )
       
   107         {
       
   108         // Read Language
       
   109         iGSRepository->Get( KSettingsPenInputLang, iInputLanguage );       
       
   110         }
       
   111     
       
   112     // Add GS Watcher
       
   113     if ( ret == KErrNone )
       
   114         {
       
   115         iGSRepositoryWatcher = CAknFepRepositoryWatcher::NewL( 
       
   116             KCRUidPersonalizationSettings, 
       
   117             TCallBack( HandleGSRepositoryCallBack, this ),
       
   118             iGSRepository );
       
   119         }
       
   120 
       
   121     // Call init function, which is virutal function
       
   122     InitMore();
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CPeninputDataMgr::IsShiftPermitted
       
   127 // (other items were commented in a header).
       
   128 // ---------------------------------------------------------------------------
       
   129 //           
       
   130 EXPORT_C TBool CPeninputDataMgr::IsShiftPermitted()
       
   131     {
       
   132     if( !iAllowCaseChange && iCurrentRange == ERangeNative )
       
   133         {
       
   134         return EFalse;
       
   135         }
       
   136         
       
   137     return (iPermittedCase & ECaseText) ||
       
   138            (iPermittedCase & ECaseInverseText);
       
   139     }
       
   140     
       
   141 // ---------------------------------------------------------------------------
       
   142 // CPeninputDataMgr::IsCapsLockPermitted
       
   143 // (other items were commented in a header).
       
   144 // ---------------------------------------------------------------------------
       
   145 //  
       
   146 EXPORT_C TBool CPeninputDataMgr::IsCapsLockPermitted()
       
   147     {
       
   148     if( !iAllowCaseChange && iCurrentRange == ERangeNative )
       
   149         {
       
   150         return EFalse;
       
   151         }
       
   152         
       
   153     return iPermittedCase & ECaseUpper;
       
   154     }
       
   155     
       
   156 // --------------------------------------------------------------------------
       
   157 // CPeninputDataMgr::SetData
       
   158 // (other items were commented in a header)
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 EXPORT_C void CPeninputDataMgr::SetData( TPeninputDataType aDataType, 
       
   162                                          TAny* aData )
       
   163     {
       
   164     switch ( aDataType )
       
   165         {
       
   166         case EPeninputDataTypeCase:
       
   167             {
       
   168             iCase = *( ( TInt* ) aData );
       
   169             }
       
   170             break;
       
   171         case EPeninputDataTypeInputLanguage:
       
   172             {
       
   173             iInputLanguage = *( ( TInt* ) aData );
       
   174             }
       
   175             break;
       
   176         case EPeninputDataTypePermittedRange:
       
   177             {
       
   178             iPermittedRange = *( ( TInt* ) aData );
       
   179             }
       
   180             break;
       
   181         case EAkninputDataTypeAllowCaseChange:
       
   182             {
       
   183             iAllowCaseChange = *((TBool*)aData);    
       
   184             }
       
   185             break;
       
   186         case EPeninputDataTypePermittedCase:
       
   187             {
       
   188             iPermittedCase = *( (TInt* ) aData );
       
   189             }
       
   190             break;
       
   191         case EPeninputDataTypeCurrentRange:
       
   192             {
       
   193             iCurrentRange = *( ( TInt* ) aData );
       
   194             }
       
   195             break;
       
   196         case EPeninputDataTypeClientLayout:
       
   197             {
       
   198             iClientLayout = *( ( TInt* ) aData );
       
   199             }
       
   200             break;
       
   201         case EPeninputDataTypeVkbLayout:
       
   202             {
       
   203             iVkbLayoutId = *( ( TInt* ) aData );
       
   204             }
       
   205             break;
       
   206         case EPeninputDataTypeNumericKeymap:
       
   207             {
       
   208             iEditorNumericKeymap = *( ( TInt* ) aData );
       
   209             }
       
   210             break;
       
   211         case EPeninputDataTypeShiftDown:
       
   212             {
       
   213             iShiftDown = *( ( TInt* ) aData );
       
   214             }
       
   215             break;
       
   216         case EPeninputDataTypeCapslockDown:
       
   217             {
       
   218             iCapslockDown = *( ( TInt* ) aData );
       
   219             }
       
   220             break;
       
   221         case EPeninputDataTypeCurrentAccent:
       
   222             {
       
   223             iCurrentAccent = *( ( TInt* ) aData );
       
   224             }
       
   225             break;
       
   226         case EPeninputDataTypeScreenMode:
       
   227             {
       
   228             SetScreenMode( *( ( TPixelsTwipsAndRotation* ) aData ) );
       
   229             }
       
   230             break;
       
   231         case EPeninputDataTypeScreenSize:
       
   232             {
       
   233             iScreenSize = *( ( TSize* ) aData );  
       
   234             }
       
   235             break;
       
   236         case EPeninputDataTypeWindowPosition:
       
   237             {
       
   238             iWindowPosition = *( ( TInt* ) aData );
       
   239             }
       
   240             break;
       
   241         case EPeninputDataTypeUnitWidth:
       
   242             {
       
   243             iUnitWidth = *( ( TInt* ) aData );
       
   244             iUnitWidthSet = ETrue;
       
   245             }
       
   246             break;
       
   247         case EPeninputDataTypeUnitHeight:
       
   248             {
       
   249             iUnitHeight = *( ( TInt* ) aData );
       
   250             iUnitHeightSet = ETrue;
       
   251             }
       
   252             break;
       
   253         case EPeninputDataTypeDataQueryDlgRect:
       
   254             {
       
   255             iDataQueryDlgRect = *( ( TRect* ) aData );
       
   256             }
       
   257             break;        
       
   258         case EAknFepDataTypeUseDefinedResource:
       
   259             {
       
   260             delete iUserDefinedResource;
       
   261             TInt* len = (TInt*)((TUint8*)aData - 4);
       
   262             TPtrC16 keymapRes((const TUint16*)aData, *len/2);  
       
   263             iUserDefinedResource = keymapRes.Alloc();
       
   264             }
       
   265             break;
       
   266         case EPeninputDataTypeReserve_1:
       
   267             {
       
   268             iReserve_1 = aData;
       
   269             }
       
   270             break;
       
   271         case EAkninputDataTypeSizeChanging:
       
   272             {
       
   273             iLayoutSizeChanging =  *((TBool*)aData);	
       
   274             }
       
   275             break;
       
   276         case EAkninputDataTypeLatchedSet:
       
   277             {
       
   278             iLatched = *((TBool*)aData);
       
   279             }
       
   280             break;
       
   281         default:
       
   282             break;
       
   283         }
       
   284         
       
   285     NotifyEngine( aDataType, aData ) ;
       
   286     } 
       
   287 
       
   288     
       
   289 // --------------------------------------------------------------------------
       
   290 // CPeninputDataMgr::RequestData
       
   291 // (other items were commented in a header)
       
   292 // --------------------------------------------------------------------------
       
   293 //
       
   294 EXPORT_C TAny* CPeninputDataMgr::RequestData( TPeninputDataType aDataType )  
       
   295     {
       
   296     switch ( aDataType )
       
   297         {
       
   298         case EPeninputDataTypeCase:
       
   299             return &iCase;
       
   300         case EPeninputDataTypeInputLanguage:
       
   301             return &iInputLanguage;
       
   302         case EPeninputDataTypePermittedRange:
       
   303             return &iPermittedRange;
       
   304         case EPeninputDataTypePermittedCase:
       
   305             return &iPermittedCase;
       
   306         case EPeninputDataTypeCurrentRange:
       
   307             return &iCurrentRange;
       
   308         case EPeninputDataTypeClientLayout:
       
   309             return &iClientLayout;
       
   310         case EPeninputDataTypeVkbLayout:
       
   311             return &iVkbLayoutId;
       
   312         case EPeninputDataTypeNumericKeymap:
       
   313             return &iEditorNumericKeymap;
       
   314         case EPeninputDataTypeShiftDown:
       
   315             return &iShiftDown;
       
   316         case EPeninputDataTypeCapslockDown:
       
   317             return &iCapslockDown;
       
   318         case EPeninputDataTypeCurrentAccent:
       
   319             return &iCurrentAccent;
       
   320         case EPeninputDataTypeScreenMode:
       
   321             return &iScreenMode;
       
   322         case EPeninputDataTypeScreenSize:
       
   323             return &iScreenSize;        
       
   324         case EPeninputDataTypeWindowPosition:
       
   325             return &iWindowPosition;
       
   326         case EPeninputDataTypePositionSettingId:
       
   327             return &iPositionSettingId;
       
   328         case EPeninputDataTypeUnitWidth:
       
   329             return &iUnitWidth;
       
   330         case EPeninputDataTypeUnitHeight:
       
   331             return &iUnitHeight;
       
   332         case EPeninputDataTypeDataQueryDlgRect:
       
   333             return &iDataQueryDlgRect;
       
   334         case EAknFepDataTypeUseDefinedResource:
       
   335             return iUserDefinedResource;
       
   336         case EPeninputDataTypeReserve_1:
       
   337             return iReserve_1;
       
   338         case EAkninputDataTypeGuideLineTop:
       
   339             return &iGuideLineTop;
       
   340         case EAkninputDataTypeGuideLineBottom:
       
   341             return &iGuideLineBottom;
       
   342         case EAkninputDataTypeSizeChanging:
       
   343             return &iLayoutSizeChanging;
       
   344         case EAkninputDataTypeLatchedSet:
       
   345             return &iLatched;
       
   346         case EAkninputDataTypeUnitSizeSet:
       
   347              {
       
   348              iUnitSizeSet = (iUnitWidthSet & iUnitHeightSet);
       
   349              return &iUnitSizeSet;	
       
   350              }
       
   351         default:
       
   352             break;
       
   353         }
       
   354 
       
   355     return NULL;
       
   356     }
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CPeninputDataMgr::Reset
       
   360 // (other items were commented in a header)
       
   361 // --------------------------------------------------------------------------
       
   362 //           
       
   363 EXPORT_C void CPeninputDataMgr::Reset()
       
   364     { 
       
   365     }        
       
   366 
       
   367 // --------------------------------------------------------------------------
       
   368 // CPeninputDataMgr::HandleGSRepositoryCallBack
       
   369 // (other items were commented in a header)
       
   370 // --------------------------------------------------------------------------
       
   371 // 
       
   372 EXPORT_C TInt CPeninputDataMgr::HandleGSRepositoryCallBack( TAny* aPtr )
       
   373     {
       
   374     CPeninputDataMgr* self = static_cast<CPeninputDataMgr*>( aPtr );
       
   375     
       
   376     CAknFepRepositoryWatcher* watcher = self->iGSRepositoryWatcher;
       
   377     if ( watcher )
       
   378         {        
       
   379         self->HandleGSRepositoryChange( watcher->ChangedKey() );
       
   380         }
       
   381 
       
   382     return KErrNone;
       
   383     }
       
   384 
       
   385 // --------------------------------------------------------------------------
       
   386 // CPeninputDataMgr::SaveKey
       
   387 // (other items were commented in a header)
       
   388 // --------------------------------------------------------------------------
       
   389 // 
       
   390 EXPORT_C void CPeninputDataMgr::SaveKey( TInt aKey, TInt aValue )
       
   391     {
       
   392     if ( iAknFepRepository )
       
   393         {
       
   394         iAknFepRepository->Set( aKey, aValue );
       
   395         }
       
   396     }
       
   397 
       
   398 // --------------------------------------------------------------------------
       
   399 // CPeninputDataMgr::SetScreenMode
       
   400 // (other items were commented in a header).
       
   401 // --------------------------------------------------------------------------
       
   402 // 
       
   403 void CPeninputDataMgr::SetScreenMode(
       
   404     const TPixelsTwipsAndRotation& aScreenMode )
       
   405     {
       
   406     switch ( aScreenMode.iRotation )
       
   407         {
       
   408         case CFbsBitGc::EGraphicsOrientationNormal:
       
   409             {
       
   410             iPositionSettingId = KAknFepHwrWindowPosition0;
       
   411             }
       
   412             break;
       
   413         case CFbsBitGc::EGraphicsOrientationRotated90:
       
   414             {
       
   415             iPositionSettingId = KAknFepHwrWindowPosition1;
       
   416             }
       
   417             break;
       
   418         case CFbsBitGc::EGraphicsOrientationRotated180:
       
   419             {
       
   420             iPositionSettingId = KAknFepHwrWindowPosition2;
       
   421             }
       
   422             break;
       
   423         case CFbsBitGc::EGraphicsOrientationRotated270:
       
   424             {
       
   425             iPositionSettingId = KAknFepHwrWindowPosition3;
       
   426             }
       
   427             break;
       
   428         default:
       
   429             break;
       
   430         }
       
   431         
       
   432     iScreenSize = aScreenMode.iPixelSize;    
       
   433     iScreenMode = aScreenMode;
       
   434     if ( iAknFepRepository )
       
   435         {
       
   436         iAknFepRepository->Get( iPositionSettingId, iWindowPosition );        
       
   437         }               
       
   438     }         
       
   439 
       
   440 // --------------------------------------------------------------------------
       
   441 // CPeninputDataMgr::InitMore
       
   442 // (other items were commented in a header)
       
   443 // --------------------------------------------------------------------------
       
   444 //   
       
   445 EXPORT_C void CPeninputDataMgr::InitMore()
       
   446     {
       
   447     }
       
   448 
       
   449 // --------------------------------------------------------------------------
       
   450 // CPeninputDataMgr::HandleGSRepositoryChange
       
   451 // (other items were commented in a header)
       
   452 // --------------------------------------------------------------------------
       
   453 // 
       
   454 EXPORT_C void CPeninputDataMgr::HandleGSRepositoryChange( TInt /*aChangedKey*/ )
       
   455   {
       
   456   }
       
   457 
       
   458 // --------------------------------------------------------------------------
       
   459 // CPeninputDataMgr::NotifyEngine
       
   460 // (other items were commented in a header).
       
   461 // --------------------------------------------------------------------------
       
   462 // 
       
   463 EXPORT_C void CPeninputDataMgr::NotifyEngine( TPeninputDataType aType, 
       
   464                                               TAny*  aData )
       
   465     {
       
   466     TInt data = *( (TInt*) aData );
       
   467     switch ( aType )
       
   468         {
       
   469         case EPeninputDataTypeCurrentRange:
       
   470             if (iAknFepRepository)
       
   471                 {
       
   472                 if ( ( data == ERangeEnglish ) || ( data == ERangeNative ) )
       
   473                     {
       
   474                     iAknFepRepository->Set(KAknFepLastUsedRange, data );
       
   475                     }                
       
   476                 }          
       
   477             break;
       
   478         case EPeninputDataTypeWindowPosition:
       
   479             if (iAknFepRepository)
       
   480                 {
       
   481                 iAknFepRepository->Set(iPositionSettingId, data );
       
   482                 }
       
   483             break;
       
   484         default:
       
   485             break;
       
   486         }
       
   487     }
       
   488