textinput/peninputcommonlayout/src/peninputlayoutconfig.cpp
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     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:  common layout config management
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <peninputpluginutils.h>
       
    21 #include <coemain.h>
       
    22 #include <peninputctrlpool.h>
       
    23 
       
    24 // User includes
       
    25 #include "peninputlayoutconfig.h"
       
    26 #include "peninputrangebarinfo.h"
       
    27 #include <peninputlayoutvkb.h>
       
    28 #include "peninputclientlayoutinfo.h"
       
    29 #include "peninputshiftcapsInfo.h"
       
    30 
       
    31 
       
    32 // Constants
       
    33 const TInt KPeninputLayoutConfigInvalidId = -1;
       
    34 
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CPeninputLayoutConfig::NewL
       
    40 // (other items were commented in a header)
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 EXPORT_C CPeninputLayoutConfig* CPeninputLayoutConfig::NewL( 
       
    44     CAknFepCtrlVkbLayout& aVkblayout, TResourceReader& aReader )
       
    45     {
       
    46     CPeninputLayoutConfig* self = new ( ELeave ) CPeninputLayoutConfig();
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL( aVkblayout, aReader );
       
    49     CleanupStack::Pop( self );
       
    50     
       
    51     return self;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CPeninputLayoutConfig::CPeninputLayoutConfig
       
    56 // (other items were commented in a header)
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CPeninputLayoutConfig::CPeninputLayoutConfig()
       
    60     : iLanguageString( NULL ), iRangeBarInfo( NULL )
       
    61     {
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CPeninputLayoutConfig::ConstructL
       
    66 // (other items were commented in a header)
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 void CPeninputLayoutConfig::ConstructL( CAknFepCtrlVkbLayout& aVkblayout,
       
    70                                         TResourceReader& aReader )
       
    71     {
       
    72     TResourceReader reader;
       
    73     TInt count = 0;
       
    74     TInt i = 0;
       
    75 
       
    76     iLanguage = aReader.ReadInt16();
       
    77     iLanguageString = aReader.ReadHBufCL();
       
    78     
       
    79     if ( aReader.ReadInt16() != 0 )
       
    80         {
       
    81         iCaseSensitive = ETrue;
       
    82         }
       
    83     else
       
    84         {
       
    85         iCaseSensitive = EFalse;
       
    86         }
       
    87 
       
    88     iGuideLine = aReader.ReadInt16();
       
    89     iPositionTopLine = aReader.ReadInt16();
       
    90     iPositionBottomLine = aReader.ReadInt16();
       
    91 
       
    92     const TInt32 clientLayoutInfoListResId = aReader.ReadInt32();
       
    93     const TInt32 vkbLayoutInfoListResId = aReader.ReadInt32();
       
    94     const TInt32 rangeBarInfoResId = aReader.ReadInt32();
       
    95     const TInt32 shiftCapsInfoResId = aReader.ReadInt32();
       
    96 
       
    97     iRangeBarResId = aReader.ReadInt32();
       
    98     
       
    99     // Create client layout list
       
   100     if ( clientLayoutInfoListResId > 0 )
       
   101         {
       
   102         CCoeEnv::Static()->CreateResourceReaderLC( reader, clientLayoutInfoListResId );
       
   103 
       
   104         count = reader.ReadInt16();
       
   105         for ( i = 0; i < count; i++ )
       
   106             {
       
   107             CPeninputClientLayoutInfo* clientLayoutInfo = 
       
   108                 CPeninputClientLayoutInfo::NewL( reader );
       
   109             iClientLayoutInfoList.Append( clientLayoutInfo );
       
   110             }
       
   111         // Pop and destroy reader
       
   112         CleanupStack::PopAndDestroy( 1 );            
       
   113         }
       
   114         
       
   115     // Create vkb layout list 
       
   116     if ( vkbLayoutInfoListResId > 0 )
       
   117         {     
       
   118         aVkblayout.SetResourceId( vkbLayoutInfoListResId );
       
   119         aVkblayout.ConstructFromResourceL();
       
   120         iVkbLayoutInfoList = aVkblayout.VkbLayoutInfoList();
       
   121         }
       
   122         
       
   123     // Create range bar
       
   124     if ( rangeBarInfoResId > 0 )
       
   125         {     
       
   126         CCoeEnv::Static()->CreateResourceReaderLC( reader, rangeBarInfoResId );        
       
   127         iRangeBarInfo = CPeninputRangeBarInfo::NewL( reader );
       
   128         // Pop and destroy reader
       
   129         CleanupStack::PopAndDestroy( 1 ); 
       
   130         }
       
   131         
       
   132     // Create shift & caps
       
   133     if ( shiftCapsInfoResId > 0 )
       
   134         {  
       
   135         CCoeEnv::Static()->CreateResourceReaderLC( reader, shiftCapsInfoResId );           
       
   136         count = reader.ReadInt16();
       
   137         for ( i = 0; i < count; i++ )
       
   138             {
       
   139             CPeninputShiftCapsInfo* shiftCapsInfo = 
       
   140                 CPeninputShiftCapsInfo::NewL( reader );
       
   141             iShiftCapsInfoList.Append( shiftCapsInfo );
       
   142             }
       
   143         // Pop and destroy reader
       
   144         CleanupStack::PopAndDestroy( 1 );
       
   145         }
       
   146     }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CPeninputLayoutConfig::~CPeninputLayoutConfig
       
   150 // (other items were commented in a header)
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C CPeninputLayoutConfig::~CPeninputLayoutConfig()
       
   154     {
       
   155     delete iLanguageString;
       
   156     delete iRangeBarInfo;
       
   157     iClientLayoutInfoList.ResetAndDestroy();
       
   158     iShiftCapsInfoList.ResetAndDestroy();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // CPeninputLayoutConfig::FindClientLayoutInfo
       
   163 // (other items were commented in a header)
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C CPeninputClientLayoutInfo* 
       
   167     CPeninputLayoutConfig::FindClientLayoutInfo( TInt aLayoutId )
       
   168     {
       
   169     const TInt count = iClientLayoutInfoList.Count();
       
   170 
       
   171     for ( TInt i = 0; i < count; i++ )
       
   172         {
       
   173         if ( iClientLayoutInfoList[i]->LayoutID() == aLayoutId )
       
   174             {
       
   175             return iClientLayoutInfoList[i];
       
   176             }
       
   177         }
       
   178 
       
   179     return NULL;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CPeninputLayoutConfig::FindVkbLayoutInfo
       
   184 // (other items were commented in a header)
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C CPeninputVkbLayoutInfo*  
       
   188     CPeninputLayoutConfig::FindVkbLayoutInfo( TInt aLayoutId )
       
   189     {
       
   190     const TInt count = iVkbLayoutInfoList.Count();
       
   191 
       
   192     for ( TInt i = 0; i < count; i++ )
       
   193         {
       
   194         if ( iVkbLayoutInfoList[i]->LayoutID() == aLayoutId )
       
   195             {
       
   196             return iVkbLayoutInfoList[i];
       
   197             }
       
   198         }
       
   199 
       
   200     return NULL;
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CPeninputLayoutConfig::FindShiftCapsInfo
       
   205 // (other items were commented in a header)
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 EXPORT_C CPeninputShiftCapsInfo*  
       
   209     CPeninputLayoutConfig::FindShiftCapsInfo( TInt aRangeId )
       
   210     {
       
   211     const TInt count = iShiftCapsInfoList.Count();
       
   212 
       
   213     for ( TInt i = 0; i < count; i++ )
       
   214         {
       
   215         if ( iShiftCapsInfoList[i]->RangeId() == aRangeId )
       
   216             {
       
   217             return iShiftCapsInfoList[i];
       
   218             }
       
   219         }
       
   220 
       
   221     return NULL;
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CPeninputLayoutConfig::ShiftCapsSingleVkbLayoutId
       
   226 // (other items were commented in a header)
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TInt CPeninputLayoutConfig::ShiftCapsSingleVkbLayoutId( 
       
   230     TInt aRangeId, TInt aShiftCapsSingleId )
       
   231     {
       
   232     CPeninputShiftCapsInfo* shiftCapsInfo = FindShiftCapsInfo( aRangeId );
       
   233 
       
   234     if ( !shiftCapsInfo )
       
   235         {
       
   236         return KPeninputLayoutConfigInvalidId;
       
   237         }
       
   238     else
       
   239         {
       
   240         CPeninputShiftCapsInfo::TPeninputShiftCapsSingle* shiftCapsSingle = 
       
   241             shiftCapsInfo->FindShiftCapsSingleById( aShiftCapsSingleId );
       
   242         if ( shiftCapsSingle )
       
   243             {
       
   244             return shiftCapsSingle->iVkbLayoutId;
       
   245             }
       
   246         else
       
   247             {
       
   248             return KPeninputLayoutConfigInvalidId;    
       
   249             }
       
   250         }
       
   251     }
       
   252 
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CPeninputLayoutConfig::FindVkbLayoutIdByCase
       
   256 // (other items were commented in a header)
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C TInt CPeninputLayoutConfig::ShiftCapsSingleVkbLayoutByCase( 
       
   260     TInt aRangeId, TInt aCase )
       
   261     {
       
   262     CPeninputShiftCapsInfo* shiftCapsInfo = FindShiftCapsInfo( aRangeId );
       
   263 
       
   264     if ( !shiftCapsInfo )
       
   265         {
       
   266         return KPeninputLayoutConfigInvalidId;
       
   267         }
       
   268     else
       
   269         {
       
   270         CPeninputShiftCapsInfo::TPeninputShiftCapsSingle* shiftCapsSingle = 
       
   271             shiftCapsInfo->FindShiftCapsSingleByCase( aCase );
       
   272         if ( shiftCapsSingle )
       
   273             {
       
   274             return shiftCapsSingle->iVkbLayoutId;
       
   275             }
       
   276         else
       
   277             {
       
   278             return KPeninputLayoutConfigInvalidId;    
       
   279             }
       
   280         }
       
   281     }