meetingrequest/mrgui/mrfieldbuildercommon/src/cesmriconfield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Base class for icon fields
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <AknIconUtils.h>
       
    21 #include <fbs.h>
       
    22 #include <eikimage.h>
       
    23 #include <layoutmetadata.cdl.h>
       
    24 #include <AknsItemID.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 
       
    28 #include "cesmriconfield.h"
       
    29 #include "cesmrborderlayer.h"
       
    30 #include "esmrhelper.h"
       
    31 #include "cesmrlayoutmgr.h"
       
    32 
       
    33 using namespace ESMRLayout;
       
    34 
       
    35 // ======== MEMBER FUNCTIONS ========
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // CESMRIconField::CESMRIconField
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 EXPORT_C CESMRIconField::CESMRIconField()
       
    42     {
       
    43     FUNC_LOG;
       
    44     // Do nothing
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // CESMRIconField::~CESMRIconField
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C CESMRIconField::~CESMRIconField()
       
    52     {
       
    53     FUNC_LOG;
       
    54     delete iIcon;
       
    55     delete iBitmap;
       
    56     delete iBitmapMask;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRIconField::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C void CESMRIconField::ConstructL( 
       
    64 		TAknsItemID aIconID,
       
    65         CCoeControl* aControl,
       
    66         TESMRFieldFocusType aFocusType )
       
    67     {
       
    68     FUNC_LOG;
       
    69     IconL( aIconID );
       
    70     iIconID = aIconID;
       
    71     CESMRField::ConstructL( aControl, aFocusType );
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CESMRIconField::SetContainerWindowL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void CESMRIconField::SetContainerWindowL(
       
    79 		const CCoeControl& aContainer )
       
    80     {
       
    81     FUNC_LOG;
       
    82     CESMRField::SetContainerWindowL( aContainer );
       
    83 
       
    84     if ( iIcon )
       
    85         {
       
    86         iIcon->SetContainerWindowL( aContainer );
       
    87         }
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CESMRIconField::IconL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C void CESMRIconField::IconL( TAknsItemID aIconID )
       
    95     {
       
    96     FUNC_LOG;
       
    97 
       
    98     // update the icon id:
       
    99     iIconID = aIconID;
       
   100 
       
   101     delete iIcon;
       
   102     iIcon = NULL;
       
   103     delete iBitmap;
       
   104     iBitmap = NULL;
       
   105     delete iBitmapMask;
       
   106     iBitmapMask = NULL;
       
   107 
       
   108     TInt fileIndex(-1);
       
   109     TInt fileMaskIndex(-1);
       
   110 
       
   111     CESMRLayoutManager::SetBitmapFallback( aIconID, fileIndex, fileMaskIndex );
       
   112 
       
   113     TFileName bitmapFilePath;
       
   114     ESMRHelper::LocateResourceFile(
       
   115             KESMRMifFile,
       
   116             KDC_APP_BITMAP_DIR,
       
   117             bitmapFilePath);
       
   118 
       
   119     AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   120                             aIconID,
       
   121                             iBitmap,
       
   122                             iBitmapMask,
       
   123                             bitmapFilePath,
       
   124                             fileIndex,
       
   125                             fileMaskIndex
       
   126                             );
       
   127 
       
   128 
       
   129     // Even if creating mask failed, bitmap can be used 
       
   130     // (background is just not displayed correctly)
       
   131     if( iBitmap )
       
   132         {
       
   133         AknIconUtils::SetSize( iBitmap, KIconSize, EAspectRatioPreserved );
       
   134         iIcon = new (ELeave) CEikImage;
       
   135         iIcon->SetPictureOwnedExternally(ETrue);
       
   136         iIcon->SetBrushStyle( CWindowGc::ENullBrush );
       
   137         iIcon->SetPicture( iBitmap, iBitmapMask );
       
   138         }
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CESMRIconField::CountComponentControls
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 EXPORT_C TInt CESMRIconField::CountComponentControls() const
       
   146     {
       
   147     FUNC_LOG;
       
   148     TInt count( 0 );
       
   149     if ( iBorder )
       
   150     	{
       
   151         ++count;
       
   152     	}
       
   153 
       
   154     if ( iIcon )
       
   155     	{
       
   156         ++count;
       
   157     	}
       
   158 
       
   159     return count;
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // CESMRIconField::ComponentControl
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C CCoeControl* CESMRIconField::ComponentControl( TInt aInd ) const
       
   167     {
       
   168     FUNC_LOG;
       
   169     switch( aInd )
       
   170     	{
       
   171     	case 0:
       
   172     		{
       
   173     		return iIcon;    		
       
   174     		}
       
   175     	case 1:
       
   176     		{
       
   177     		return iBorder;
       
   178     		}
       
   179     	default:
       
   180     		{
       
   181     		return NULL;
       
   182     		}
       
   183     	}
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CESMRIconField::SizeChanged
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 EXPORT_C void CESMRIconField::SizeChanged()
       
   191     {
       
   192     FUNC_LOG;
       
   193     TRect rect = Rect();
       
   194     TPoint iconPos( 
       
   195     		TPoint( rect.iTl.iX, rect.iTl.iY + iLayout->IconTopMargin() ));
       
   196     TPoint borderPos( 
       
   197     		iconPos.iX + KIconSize.iWidth + KIconBorderMargin, rect.iTl.iY );
       
   198     TSize borderSize( 
       
   199     	rect.Width() - (KIconSize.iWidth + KIconBorderMargin ), rect.Height() );
       
   200 
       
   201     TRAPD( error, IconL( iIconID ) );
       
   202 
       
   203     if ( CESMRLayoutManager::IsMirrored() )
       
   204         {
       
   205         CCoeControl* parent = Parent();
       
   206         TRect r = parent->Rect();
       
   207 
       
   208         iconPos.iX = r.iBr.iX - KIconSize.iWidth - KMirroredIconMargin;
       
   209         borderPos.iX = iconPos.iX - (borderSize.iWidth + KIconBorderMargin );
       
   210         }
       
   211 
       
   212     if ( iIcon && error == KErrNone )
       
   213         {
       
   214         iIcon->SetPosition( iconPos );
       
   215         iIcon->SetSize( KIconSize );
       
   216         }
       
   217 
       
   218     if ( iBorder && error == KErrNone )
       
   219         {
       
   220         // reserve icon rect.
       
   221         iBorder->SetExtent( borderPos, BorderSize() );
       
   222         }
       
   223         }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // CESMRIconField::BorderSize
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 EXPORT_C TSize CESMRIconField::BorderSize() const
       
   230     {
       
   231     FUNC_LOG;
       
   232     TSize borderSize( Rect().Width() - ( KIconSize.iWidth + 
       
   233             KIconBorderMargin ), Rect().Height() );
       
   234     
       
   235     return borderSize;
       
   236     }
       
   237