textinput/peninputcommonlayout/src/peninputnumerickeymappingmgr.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:  number keymapping manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <eikon.hrh>
       
    21 
       
    22 // User includes
       
    23 #include "peninputnumerickeymappingmgr.h"
       
    24 
       
    25 // Constants
       
    26 _LIT( KNumberString, "0123456789" );
       
    27 const TInt KMaxNumericString = 32;
       
    28 
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ------------------------------------------------------------------------
       
    33 // CPeninputNumericKepMappingMgr::NewL
       
    34 // (other items were commented in a header)
       
    35 // ------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CPeninputNumericKepMappingMgr* CPeninputNumericKepMappingMgr::NewL(
       
    38     TResourceReader aReader )
       
    39     {
       
    40     CPeninputNumericKepMappingMgr* self = NewLC( aReader );
       
    41     CleanupStack::Pop( self );
       
    42 
       
    43     return self;        
       
    44     }
       
    45  
       
    46 // ------------------------------------------------------------------------
       
    47 // CPeninputNumericKepMappingMgr::NewLC
       
    48 // (other items were commented in a header)
       
    49 // ------------------------------------------------------------------------
       
    50 //    
       
    51 EXPORT_C CPeninputNumericKepMappingMgr* CPeninputNumericKepMappingMgr::NewLC(
       
    52     TResourceReader aReader )
       
    53     {
       
    54     CPeninputNumericKepMappingMgr* self = 
       
    55         new ( ELeave ) CPeninputNumericKepMappingMgr();
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL( aReader );
       
    58 
       
    59     return self;        
       
    60     }
       
    61 
       
    62 // ------------------------------------------------------------------------
       
    63 // CPeninputNumericKepMappingMgr::ConstructL
       
    64 // (other items were commented in a header)
       
    65 // ------------------------------------------------------------------------
       
    66 //   
       
    67 void CPeninputNumericKepMappingMgr::ConstructL( TResourceReader aReader ) 
       
    68     {
       
    69     const TInt count = aReader.ReadInt16();
       
    70     
       
    71     for ( TInt i = 0; i < count; i++ )
       
    72         {
       
    73         iKeyMappingIdList.Append( aReader.ReadInt16() );
       
    74         TPtrC ptr = aReader.ReadTPtrC();
       
    75         iKeyMappingStringList.Append( ptr.AllocL() );
       
    76         }
       
    77     }
       
    78 
       
    79 // ------------------------------------------------------------------------
       
    80 // CPeninputNumericKepMappingMgr::~CPeninputNumericKepMappingMgr
       
    81 // (other items were commented in a header)
       
    82 // ------------------------------------------------------------------------
       
    83 //         
       
    84 EXPORT_C CPeninputNumericKepMappingMgr::~CPeninputNumericKepMappingMgr()    
       
    85     {
       
    86     iKeyMappingIdList.Reset();
       
    87     iKeyMappingIdList.Close();
       
    88     
       
    89     iKeyMappingStringList.ResetAndDestroy();
       
    90     iKeyMappingStringList.Close();
       
    91     }
       
    92 
       
    93 // ------------------------------------------------------------------------
       
    94 // CPeninputNumericKepMappingMgr::KeyMappingStringL
       
    95 // (other items were commented in a header)
       
    96 // ------------------------------------------------------------------------
       
    97 //   
       
    98 EXPORT_C HBufC* CPeninputNumericKepMappingMgr::KeyMappingStringL( 
       
    99     const TInt aKeyMappingId ) const
       
   100     {
       
   101     TLocale locale;
       
   102     TBuf<KMaxNumericString> rs = KNumberString();
       
   103     const TInt index = iKeyMappingIdList.Find( aKeyMappingId );
       
   104     
       
   105     if ( index != KErrNotFound )
       
   106         {
       
   107         HBufC* buf = iKeyMappingStringList[index];
       
   108         
       
   109         rs.Append( *buf );
       
   110         
       
   111         if ( ( aKeyMappingId == EAknEditorCalculatorNumberModeKeymap )
       
   112             || ( aKeyMappingId == EAknEditorConverterNumberModeKeymap ) )
       
   113             {
       
   114             rs.Append( locale.DecimalSeparator() ); 
       
   115             }       
       
   116         }
       
   117         
       
   118     return rs.AllocL();          
       
   119     }
       
   120 
       
   121 // ------------------------------------------------------------------------
       
   122 // CPeninputNumericKepMappingMgr::ArabicKeyMappingStringL
       
   123 // (other items were commented in a header)
       
   124 // ------------------------------------------------------------------------
       
   125 //       
       
   126 EXPORT_C HBufC* CPeninputNumericKepMappingMgr::KeyMappingStringL( 
       
   127     const TInt aKeyMappingId, const TInt aLang ) const
       
   128     {
       
   129     
       
   130     TLocale locale;
       
   131     TBuf<KMaxNumericString> rs;
       
   132     if( aLang == ELangArabic )
       
   133         {
       
   134         rs.Format( _L("%c%c%c%c%c%c%c%c%c%c"),
       
   135         0x0660, 0x0661, 0x0662,
       
   136         0x0663, 0x0664, 0x0665,
       
   137         0x0666, 0x0667, 0x0668, 0x0669 );
       
   138         }
       
   139     else if( aLang == ELangFarsi || aLang == ELangUrdu )
       
   140         {
       
   141         rs.Format( _L("%c%c%c%c%c%c%c%c%c%c"),
       
   142         0x06F0, 0x06F1, 0x06F2,
       
   143         0x06F3, 0x06F4, 0x06F5,
       
   144         0x06F6, 0x06F7, 0x06F8, 0x06F9 );
       
   145         }
       
   146     else if( aLang == ELangHindi )
       
   147         {
       
   148         rs.Format( _L("%c%c%c%c%c%c%c%c%c%c"),
       
   149         0x0966, 0x0967, 0x0968,
       
   150         0x0969, 0x096a, 0x096b,
       
   151         0x096c, 0x096d, 0x096e, 0x096f );
       
   152         }
       
   153     else if( aLang == ELangThai )
       
   154         {
       
   155         rs.Format( _L("%c%c%c%c%c%c%c%c%c%c"),
       
   156         0x0E50, 0x0E51, 0x0E52,
       
   157         0x0E53, 0x0E54, 0x0E55,
       
   158         0x0E56, 0x0E57, 0x0E58, 0x0E59 );        
       
   159         }
       
   160     else 
       
   161         {
       
   162         rs = KNumberString();   
       
   163         }
       
   164     
       
   165     const TInt index = iKeyMappingIdList.Find( aKeyMappingId );
       
   166     
       
   167     if ( index != KErrNotFound )
       
   168         {
       
   169         HBufC* buf = iKeyMappingStringList[index];
       
   170         
       
   171         rs.Append( *buf );
       
   172         
       
   173         if ( ( aKeyMappingId == EAknEditorCalculatorNumberModeKeymap )
       
   174             || ( aKeyMappingId == EAknEditorConverterNumberModeKeymap ) )
       
   175             {
       
   176             rs.Append( locale.DecimalSeparator() ); 
       
   177             }       
       
   178         }
       
   179         
       
   180     return rs.AllocL();          
       
   181     }
       
   182 
       
   183 // ------------------------------------------------------------------------
       
   184 // CPeninputNumericKepMappingMgr::Count
       
   185 // (other items were commented in a header)
       
   186 // ------------------------------------------------------------------------
       
   187 // 
       
   188 EXPORT_C TInt CPeninputNumericKepMappingMgr::Count() const
       
   189     {
       
   190     return iKeyMappingIdList.Count();
       
   191     }
       
   192 
       
   193 // ------------------------------------------------------------------------
       
   194 // CPeninputNumericKepMappingMgr::Reset
       
   195 // (other items were commented in a header)    
       
   196 // ------------------------------------------------------------------------
       
   197 // 
       
   198 EXPORT_C void CPeninputNumericKepMappingMgr::Reset()
       
   199     {
       
   200     iKeyMappingIdList.Reset();
       
   201     iKeyMappingStringList.ResetAndDestroy();
       
   202     }