textinput/peninputcommonctrls/src/peninputvkbctrl/peninputvkbctrlext.cpp
branchRCL_3
changeset 21 ecbabf52600f
equal deleted inserted replaced
20:ebd48d2de13c 21:ecbabf52600f
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  vkb control extension
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <barsread.h>
       
    21 #include <peninputlayout.h>
       
    22 #include <AknIconUtils.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <coemain.h>
       
    25 
       
    26 // User includes
       
    27 #include "peninputvkbctrlext.h"
       
    28 #include "peninputvkbctrllayout.h"
       
    29 
       
    30 // Constants
       
    31 const TUint32 KDefaultTextColor = 0x000000;
       
    32 const TInt32 KInvalidResId = -1;
       
    33 const TInt KInvalidImg = -1 ;
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CPeninputVkbCtrlExt::CPeninputVkbCtrlExt
       
    40 // (other items were commented in a header)
       
    41 // --------------------------------------------------------------------------
       
    42 //
       
    43 EXPORT_C CPeninputVkbCtrlExt::CPeninputVkbCtrlExt( const TRect& aRect,
       
    44     CFepUiLayout* aUiLayout, TInt aControlId, const TFontSpec& aFontSpec,TBool aIrregular )
       
    45     : CVirtualKeyboard( aRect, aUiLayout, aControlId, aFontSpec, aIrregular )
       
    46     {
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CPeninputVkbCtrlExt::NewL
       
    51 // (other items were commented in a header)
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 EXPORT_C CPeninputVkbCtrlExt* CPeninputVkbCtrlExt::NewL( const TRect& aRect,
       
    55     CFepUiLayout* aUiLayout, TInt aControlId, const CFont* aFont,TBool aIrregular)
       
    56     {
       
    57     TFontSpec fontSpec;
       
    58     
       
    59     CPeninputVkbCtrlExt* vkb = new (ELeave)  
       
    60         CPeninputVkbCtrlExt( aRect, aUiLayout, aControlId, fontSpec,aIrregular );
       
    61     CleanupStack::PushL( vkb );
       
    62     vkb->ConstructL();
       
    63     vkb->SetFont( aFont );
       
    64     CleanupStack::Pop( vkb );
       
    65     
       
    66     return vkb;
       
    67     }
       
    68             
       
    69 // --------------------------------------------------------------------------
       
    70 // CPeninputVkbCtrlExt::~CPeninputVkbCtrlExt
       
    71 // (other items were commented in a header)
       
    72 // --------------------------------------------------------------------------
       
    73 //
       
    74 EXPORT_C CPeninputVkbCtrlExt::~CPeninputVkbCtrlExt()
       
    75     {
       
    76     Reset();
       
    77     if( iResourceId == KInvalidImg )
       
    78     	{
       
    79 		SetBackgroundBmp( NULL );
       
    80 		SetBackgroundMaskBmp( NULL );    		
       
    81     	}
       
    82     }
       
    83 
       
    84 // --------------------------------------------------------------------------
       
    85 // CPeninputVkbCtrlExt::SizeChanged
       
    86 // (other items were commented in a header)
       
    87 // --------------------------------------------------------------------------
       
    88 //
       
    89 EXPORT_C void CPeninputVkbCtrlExt::SizeChanged( const TInt aUnitWidth,
       
    90                                                 const TInt aUnitHeight,
       
    91                                                 const TPoint& aLeftTopPoint )
       
    92     {
       
    93     iUnitWidth = aUnitWidth;
       
    94     iUnitHeight = aUnitHeight;
       
    95     iLeftTopPoint = aLeftTopPoint;
       
    96     
       
    97     if ( iVkbLayoutInfo )
       
    98         {        
       
    99         // 1.Reset the size and position of Vkb ctrl and keys
       
   100         TRect rect = TRect( iLeftTopPoint, TSize( iUnitWidth * iVkbLayoutInfo->Columns(),
       
   101                                                   iUnitHeight * iVkbLayoutInfo->Rows() ) );
       
   102         SetRect( rect );
       
   103             
       
   104         // 2.Move all keys(Needn't change size, because it has been 
       
   105         }
       
   106     }
       
   107     
       
   108 // --------------------------------------------------------------------------
       
   109 // CPeninputVkbCtrlExt::SizeChanged
       
   110 // (other items were commented in a header)
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C void CPeninputVkbCtrlExt::SizeChanged( const TRect& aRect )
       
   114     {
       
   115     SetRect( aRect );
       
   116     }
       
   117     
       
   118     
       
   119 // CPeninputVkbCtrlExt::ReorganizeVkbKeys
       
   120 // (other items were commented in a header)
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CPeninputVkbCtrlExt::ReorganizeVkbKeys(
       
   124     CPeninputVkbLayoutInfo* aVkbLayoutInfo )
       
   125     {           
       
   126     Reset();
       
   127 
       
   128     iVkbLayoutInfo = aVkbLayoutInfo;
       
   129 
       
   130     TRect rect = TRect( iLeftTopPoint, TSize( iUnitWidth * iVkbLayoutInfo->Columns(),
       
   131                                               iUnitHeight * iVkbLayoutInfo->Rows() ) );
       
   132 	if( iResourceId != KInvalidImg )
       
   133 		{
       
   134 		if( BackgroundBmp() && BackgroundBmp()->SizeInPixels() != Rect().Size() )                                              
       
   135 			AknIconUtils::SetSize(BackgroundBmp(), Rect().Size(), EAspectRatioNotPreserved);
       
   136 		if( BkMaskBmp() && BkMaskBmp()->SizeInPixels() != Rect().Size() ) 
       
   137 			AknIconUtils::SetSize(BkMaskBmp(), Rect().Size(), EAspectRatioNotPreserved);
       
   138 		}
       
   139 	else
       
   140 		{		
       
   141 	    if ( iVkbLayoutInfo->BgBmp() )
       
   142 	        {	        
       
   143 	        SetBackgroundBmp( iVkbLayoutInfo->BgBmp() ) ;
       
   144 	        }
       
   145 	    
       
   146 	    if ( iVkbLayoutInfo->BgMaskBmp() )
       
   147 	        {
       
   148 	        SetBackgroundMaskBmp( iVkbLayoutInfo->BgMaskBmp() );
       
   149 	        }			
       
   150 		}	                                       
       
   151 //    SetRect( rect );
       
   152             
       
   153     // According the information in vkbLayout to construct all keys and
       
   154     // then add into the keys.
       
   155 /*    
       
   156     if ( iVkbLayoutInfo->BgBmp() )
       
   157         {
       
   158         TRAP_IGNORE( SetBackgroundBitmapL( iVkbLayoutInfo->BgBmp() ) );
       
   159         }
       
   160     
       
   161     if ( iVkbLayoutInfo->BgMaskBmp() )
       
   162         {
       
   163         TRAP_IGNORE( SetBackgroundMaskBitmapL( iVkbLayoutInfo->BgMaskBmp() ) );
       
   164         }
       
   165 */
       
   166     if ( iVkbLayoutInfo->DimBmp() )
       
   167         {
       
   168         SetDimKeyBmp( iVkbLayoutInfo->DimBmp() );
       
   169         }
       
   170     
       
   171     if ( iVkbLayoutInfo->DimMaskBmp() )
       
   172         {
       
   173         SetDimKeyMaskBmp( iVkbLayoutInfo->DimMaskBmp() );
       
   174         }
       
   175 
       
   176     TInt count = iVkbLayoutInfo->HighlightBmps().Count();
       
   177     
       
   178     TRAP_IGNORE(
       
   179     for ( TInt i = 0; i < count; i++ )
       
   180         {
       
   181         AddKeyHighLightBitmapL(iVkbLayoutInfo->HighlightBmps()[i]);
       
   182         }
       
   183         );
       
   184         
       
   185     count = iVkbLayoutInfo->HighlightMaskBmps().Count();
       
   186 
       
   187     TRAP_IGNORE(
       
   188         for ( TInt i = 0; i < count; i++ )
       
   189             {
       
   190             AddKeyHighLightMaskBitmapL(iVkbLayoutInfo->HighlightMaskBmps()[i]);
       
   191             }
       
   192         );
       
   193     
       
   194     count = iVkbLayoutInfo->KeyInfoList().Count();
       
   195     TRAP_IGNORE(
       
   196     for ( TInt i = 0; i < count; i++ )
       
   197         {
       
   198         iVkbLayoutInfo->KeyInfoList()[i]->Key()->SetDimmed( EFalse );
       
   199         AddKeyL( iVkbLayoutInfo->KeyInfoList()[i]->Key() );
       
   200         }
       
   201     );
       
   202    
       
   203     TRgb textColor;
       
   204     TInt error = AknsUtils::GetCachedColor(AknsUtils::SkinInstance(),
       
   205                                            textColor,
       
   206                                            KAknsIIDQsnTextColors,
       
   207                                            EAknsCIQsnTextColorsCG59);
       
   208     if (error != KErrNone)
       
   209         {
       
   210     	textColor = TRgb( KDefaultTextColor );
       
   211         }  
       
   212     SetFontColor( textColor );
       
   213     
       
   214     // Remove that draw operation to improve performance
       
   215     //Draw();
       
   216     }
       
   217 
       
   218 // --------------------------------------------------------------------------
       
   219 // CPeninputVkbCtrlExt::Reset
       
   220 // (other items were commented in a header)
       
   221 // --------------------------------------------------------------------------
       
   222 //
       
   223 EXPORT_C void CPeninputVkbCtrlExt::Reset()
       
   224     {
       
   225     const RPointerArray<CVirtualKey>& keys = KeyArray();
       
   226     for(TInt i = keys.Count() - 1 ; i >= 0 ; --i)    
       
   227         {
       
   228         RemoveKey(keys[i]);
       
   229         }
       
   230     
       
   231     const RPointerArray<CFbsBitmap>& bmps = KeyHighlightBmpList();
       
   232     for(TInt i = bmps.Count() - 1 ; i >= 0 ; --i)
       
   233         {
       
   234         RemoveKeyHighLightBitmap(i);
       
   235         }
       
   236 
       
   237     const RPointerArray<CFbsBitmap>& maskbmps = KeyHighlightMaskBmpList();    
       
   238     for(TInt i = maskbmps.Count() - 1 ; i >= 0 ; --i)
       
   239         {
       
   240         RemoveKeyHighLightMaskBitmap(i);
       
   241         }    
       
   242             
       
   243     SetDimKeyBmp( NULL );
       
   244     SetDimKeyMaskBmp( NULL );    
       
   245     
       
   246     iVkbLayoutInfo = NULL;
       
   247     }
       
   248 
       
   249 // --------------------------------------------------------------------------
       
   250 // CPeninputVkbCtrlExt::Move
       
   251 // (other items were commented in a header)
       
   252 // --------------------------------------------------------------------------
       
   253 //
       
   254 EXPORT_C void CPeninputVkbCtrlExt::Move( const TPoint& aOffset )
       
   255     {
       
   256     TRect rect = Rect();
       
   257     rect.Move( aOffset );
       
   258     SetRect( rect );     
       
   259     }
       
   260     
       
   261 // --------------------------------------------------------------------------
       
   262 // CPeninputVkbCtrlExt::DimKeys
       
   263 // (other items were commented in a header)
       
   264 // --------------------------------------------------------------------------
       
   265 //
       
   266 EXPORT_C void CPeninputVkbCtrlExt::DimKeys( const HBufC* aPermitted )
       
   267     {
       
   268     TInt count = iVkbLayoutInfo->KeyInfoList().Count();
       
   269     
       
   270     for ( TInt i = 0; i < count ; i++ )
       
   271         {
       
   272         TChar ch = TChar( (TUint)( KeyArray()[i]->KeyCode() ) );
       
   273         TInt index = aPermitted->Locate( ch ) ;
       
   274         
       
   275         if ( index == KErrNotFound )
       
   276             {
       
   277             DimKey( KeyArray()[i], ETrue );
       
   278             }     
       
   279         }
       
   280     }
       
   281 
       
   282 // --------------------------------------------------------------------------
       
   283 // CPeninputVkbCtrlExt::DimKeySet
       
   284 // (other items were commented in a header)
       
   285 // --------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C void CPeninputVkbCtrlExt::DimKeySet( const HBufC* aSet, TBool aDim )
       
   288     {
       
   289     TInt keyCount = iVkbLayoutInfo->KeyInfoList().Count();
       
   290     TInt setCount = const_cast<HBufC*>(aSet)->Des().Length();
       
   291     TInt findNum = 0;
       
   292     
       
   293     for ( TInt i = 0; i < keyCount ; i++ )
       
   294         {
       
   295         TChar ch = TChar( (TUint)( KeyArray()[i]->KeyCode() ) );
       
   296         TInt index = aSet->Locate( ch ) ;
       
   297         
       
   298         if ( index != KErrNotFound )
       
   299             {
       
   300             findNum++;
       
   301             DimKey( KeyArray()[i], aDim );
       
   302             }     
       
   303         
       
   304         if ( findNum == setCount )
       
   305             {
       
   306             break;
       
   307             }
       
   308         }
       
   309     }
       
   310 
       
   311 // --------------------------------------------------------------------------
       
   312 // CPeninputVkbCtrlExt::CancelDims
       
   313 // (other items were commented in a header)
       
   314 // --------------------------------------------------------------------------
       
   315 //
       
   316 EXPORT_C void CPeninputVkbCtrlExt::CancelDims()
       
   317     {
       
   318     TInt count = iVkbLayoutInfo->KeyInfoList().Count();
       
   319     
       
   320     for ( TInt i = 0; i < count ; i++ )
       
   321         {
       
   322         DimKey( KeyArray()[i], EFalse );
       
   323         }
       
   324     }
       
   325 
       
   326 // --------------------------------------------------------------------------
       
   327 // CPeninputVkbCtrlExt::ConstructFromResourceL
       
   328 // (other items were commented in a header)
       
   329 // --------------------------------------------------------------------------
       
   330 //
       
   331 EXPORT_C void CPeninputVkbCtrlExt::ConstructFromResourceL()
       
   332 	{
       
   333 	if (iResourceId == KInvalidResId)
       
   334 		{
       
   335 	    return;
       
   336 		}
       
   337 	
       
   338 	// Release original resource
       
   339     if( BackgroundBmp() )
       
   340     	{
       
   341     	CFbsBitmap* bkBmp = BackgroundBmp();
       
   342     	delete bkBmp;	
       
   343     	SetBackgroundBmp( NULL );
       
   344     	}
       
   345     if( BkMaskBmp() )
       
   346     	{
       
   347     	CFbsBitmap* bkMaskBmp = BkMaskBmp();
       
   348     	delete bkMaskBmp;
       
   349 		SetBackgroundMaskBmp( NULL );
       
   350     	}    
       
   351     		
       
   352     TResourceReader resReader;
       
   353     CCoeEnv::Static()->CreateResourceReaderLC( resReader, iResourceId );                                             
       
   354      
       
   355     TPtrC bmpFileName = resReader.ReadTPtrC();
       
   356     TInt32 imgMajorSkinId = resReader.ReadInt32();
       
   357 
       
   358     TAknsItemID id;
       
   359     TInt skinitemid;
       
   360     
       
   361     MAknsSkinInstance* skininstance = AknsUtils::SkinInstance();
       
   362     const TInt16 bmpId = resReader.ReadInt16();
       
   363     const TInt16 bmpMskId = resReader.ReadInt16();
       
   364     skinitemid = resReader.ReadInt16();   
       
   365     id.Set(TInt(imgMajorSkinId), skinitemid);
       
   366 	
       
   367     if (bmpId != KInvalidImg)
       
   368     	{
       
   369     	CFbsBitmap* backgroundImg = NULL;
       
   370     	CFbsBitmap* backgroundMaskImg = NULL;
       
   371         if (bmpMskId != KInvalidImg)
       
   372             {
       
   373             AknsUtils::CreateIconL(skininstance, 
       
   374                                    id,
       
   375                                    backgroundImg,
       
   376                                    backgroundMaskImg,
       
   377                                    bmpFileName,
       
   378                                    bmpId,
       
   379                                    bmpMskId);
       
   380             }
       
   381         else
       
   382             {
       
   383             AknsUtils::CreateIconL(skininstance,
       
   384                                    id,
       
   385                                    backgroundImg,
       
   386                                    bmpFileName,
       
   387                                    bmpId);
       
   388             }
       
   389        
       
   390         SetBackgroundBmp( backgroundImg );
       
   391         SetBackgroundMaskBmp( backgroundMaskImg );           
       
   392     	}
       
   393     CleanupStack::PopAndDestroy( 1 );		
       
   394 	}
       
   395 	
       
   396 EXPORT_C void CPeninputVkbCtrlExt::HandleResourceChange(TInt aType)
       
   397     {
       
   398     CVirtualKeyboard::HandleResourceChange(aType);
       
   399     }