textinput/peninputfingerhwrar/src/peninputfingerhwarvkbutility.cpp
branchRCL_3
changeset 19 ac7e4d1d9209
equal deleted inserted replaced
18:b1ea1642412e 19:ac7e4d1d9209
       
     1 /*
       
     2 * Copyright (c) 2010 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 virtual key ctrl utility for arabic hwr.
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE
       
    19 #include <e32std.h>
       
    20 #include <barsread.h>
       
    21 #include <coemain.h>
       
    22 
       
    23 #include "peninputfingerhwarvkbutility.h"
       
    24 #include "peninputlayoutvkb.h"
       
    25 #include "peninputpluginutils.h"
       
    26 #include "hbufcarrayar.h"
       
    27 #include "peninputfingerhwrarstoreconstants.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Load virtual keys image
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 void PeninputFingerHwrArVkbUtility::LoadVirtualKeypadKeyL(CVirtualKeyboard& aVkbCtrl, const TInt aResId, const RArray<TRect>& aCellRects)        
       
    34     {
       
    35     aVkbCtrl.SetResourceId(aResId);
       
    36 	
       
    37 	TResourceReader reader;
       
    38     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );
       
    39 
       
    40     // construct keys
       
    41     TInt resKeyCount = reader.ReadInt16();
       
    42     TInt existsKeyCount = aVkbCtrl.KeyArray().Count();
       
    43     TInt rectCount = aCellRects.Count();
       
    44     
       
    45     for ( TInt i = 0; i < resKeyCount; i++ )
       
    46         {
       
    47         if ( i < existsKeyCount )
       
    48             {
       
    49             CVirtualKey* vk = aVkbCtrl.KeyArray()[i];
       
    50             UpdateVkbKeyL( vk, reader, aCellRects[i%rectCount] );
       
    51             }
       
    52         else
       
    53             {
       
    54             CVirtualKey* vk = CreateVkbKeyL( reader, aCellRects[i%rectCount] );
       
    55             CleanupStack::PushL( vk );
       
    56             aVkbCtrl.AddKeyL( vk );
       
    57             
       
    58             CleanupStack::Pop( vk );
       
    59             }
       
    60         }
       
    61     
       
    62     CleanupStack::PopAndDestroy( 1 ); // reader
       
    63     
       
    64     aVkbCtrl.Draw();
       
    65     aVkbCtrl.UpdateArea( aVkbCtrl.Rect() );
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // Create the virtual key
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CVirtualKey* PeninputFingerHwrArVkbUtility::CreateVkbKeyL(TResourceReader& aReader,const TRect& aKeyRect)
       
    73 	{
       
    74 	CHBufCArray* keytexts = CHBufCArray::NewL();
       
    75     CleanupStack::PushL( keytexts );
       
    76     
       
    77     for ( TInt i = 0; i <= EPosLast; i++ )
       
    78         {
       
    79         HBufC* unicode = aReader.ReadHBufCL();
       
    80         keytexts->Array().AppendL( unicode );
       
    81         }
       
    82 
       
    83     TInt keyscancode = aReader.ReadInt16();
       
    84 
       
    85     HBufC* text = keytexts->Array()[0];
       
    86     
       
    87     CVirtualKey* vk = NULL;
       
    88     if ( text )
       
    89         {
       
    90         vk = CVirtualKey::NewL( *text, keyscancode, aKeyRect, aKeyRect, 0 );
       
    91         }
       
    92     else 
       
    93         {
       
    94         vk = CVirtualKey::NewL( KNullDesC, keyscancode, aKeyRect, aKeyRect, 0 );
       
    95         }
       
    96 
       
    97     CleanupStack::PopAndDestroy( keytexts ); //keytexts
       
    98 
       
    99     
       
   100     TRect innerrect = aKeyRect;
       
   101     innerrect.Shrink( TSize(10, 10) );
       
   102     vk->SetInnerRect( innerrect );
       
   103     
       
   104     return vk;
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // Load virtual keys image
       
   109 // ---------------------------------------------------------------------------
       
   110 //	
       
   111 void PeninputFingerHwrArVkbUtility::LoadVkbKeyImageL(CVirtualKeyboard& aVkbCtrl, TInt aResId, const TSize& aKeySize)
       
   112     {
       
   113 	TResourceReader reader;    
       
   114     CCoeEnv::Static()->CreateResourceReaderLC( reader, aResId );      
       
   115     
       
   116     TPtrC bmpFileName = reader.ReadTPtrC();
       
   117     TInt32 imgMajorSkinId = reader.ReadInt32();
       
   118     TAknsItemID id;
       
   119     
       
   120     TSize keySize = aKeySize;
       
   121     
       
   122     for ( TInt index = 0; index <= EKeyBmpLastType ; index += 2 )
       
   123         { 
       
   124         // Get the image ids and mask ids from resource
       
   125         TInt bmpId = reader.ReadInt16(); 
       
   126         TInt bmpMskId = reader.ReadInt16();
       
   127         
       
   128         // read skin item id
       
   129         const TInt skinitemid = reader.ReadInt16();
       
   130         id.Set( TInt( imgMajorSkinId ), skinitemid );
       
   131         
       
   132         if ( bmpId != KInvalidImg )
       
   133             {
       
   134             CFbsBitmap* bmp = NULL;
       
   135             CFbsBitmap* maskbmp = NULL;
       
   136 
       
   137             if ( bmpMskId != KInvalidImg )
       
   138                 {
       
   139                 AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   140                    id, bmp, maskbmp, bmpFileName, bmpId, bmpMskId );
       
   141                 
       
   142                 // set maskbmp and size
       
   143                 AknIconUtils::SetSize( maskbmp, keySize, EAspectRatioNotPreserved );
       
   144                 aVkbCtrl.SetNonIrregularKeyBitmapL(TVirtualKeyBmpType(EKeyBmpNormal + index + 1 ),maskbmp);
       
   145                 }
       
   146             else
       
   147                 {
       
   148                 AknsUtils::CreateIconL( AknsUtils::SkinInstance(), id, 
       
   149                     bmp, bmpFileName, bmpId );
       
   150                 }
       
   151             // set bmp and size
       
   152             AknIconUtils::SetSize( bmp, keySize, EAspectRatioNotPreserved );
       
   153             aVkbCtrl.SetNonIrregularKeyBitmapL(TVirtualKeyBmpType( EKeyBmpNormal + index ),bmp);
       
   154             }       
       
   155         }
       
   156     // Pop and destroy reader
       
   157     CleanupStack::PopAndDestroy( 1 );        
       
   158 	}
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // update virtual key info.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void PeninputFingerHwrArVkbUtility::UpdateVkbKeyL(CVirtualKey* aVirtualKey, TResourceReader& aReader, const TRect& aKeyRect)
       
   165     {
       
   166     CHBufCArray* keytexts = CHBufCArray::NewL();
       
   167     CleanupStack::PushL( keytexts );
       
   168     
       
   169     for ( TInt i = 0; i <= EPosLast; i++ )
       
   170         {
       
   171         HBufC* unicode = aReader.ReadHBufCL();
       
   172         keytexts->Array().AppendL( unicode );
       
   173         }
       
   174 
       
   175     TInt keyscancode = aReader.ReadInt16();
       
   176 
       
   177     HBufC* text = keytexts->Array()[0];
       
   178     if ( text )
       
   179         {
       
   180         aVirtualKey->SetKeyData( *text );
       
   181         }
       
   182     else
       
   183         {
       
   184         aVirtualKey->SetKeyData( KNullDesC );
       
   185         }
       
   186     
       
   187     aVirtualKey->SetKeyScancode( keyscancode );
       
   188 
       
   189     CleanupStack::PopAndDestroy( keytexts ); //keytexts
       
   190 
       
   191     aVirtualKey->SetRect(aKeyRect);
       
   192     TRect innerrect = aKeyRect;
       
   193     innerrect.Shrink( TSize(2,2) );
       
   194     aVirtualKey->SetInnerRect( innerrect );
       
   195     }
       
   196           
       
   197 //  End Of File