meetingrequest/mrgui/mrfieldbuildercommon/src/cmrbackground.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  Background/focus component for fields.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cmrbackground.h"
       
    19 #include <AknUtils.h>
       
    20 
       
    21 
       
    22 // unnamed namespace for local definitions
       
    23 namespace // codescanner::namespace 
       
    24     { 
       
    25     const TInt KEdge (8);
       
    26     const TInt KGranularity( 9 );
       
    27     
       
    28     #ifdef _DEBUG
       
    29         enum TPanic
       
    30             {
       
    31             EErrorItemCount = 1
       
    32             };
       
    33         
       
    34         void Panic( TPanic aPanic )
       
    35             {
       
    36             _LIT( KCategory, "CMRBackground" );
       
    37             User::Panic( KCategory(), aPanic );
       
    38             }
       
    39     #endif // _DEBUG
       
    40     }//namespace
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CMRBackground::NewL
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C 
       
    49 CMRBackground* CMRBackground::NewL( CESMRLayoutManager& aLayoutManager )
       
    50     {
       
    51     CMRBackground* self = new (ELeave) CMRBackground( aLayoutManager );
       
    52     CleanupStack::PushL( self );
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CMRBackground::CMRBackground
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CMRBackground::CMRBackground( CESMRLayoutManager& aLayoutManager )
       
    62     : iLayoutManager( aLayoutManager )
       
    63     {
       
    64     // Do nothing
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CMRBackground::~CMRBackground
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CMRBackground::~CMRBackground()
       
    72     {
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CMRBackground::Draw
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 EXPORT_C void CMRBackground::Draw(
       
    80         CWindowGc& aGc,
       
    81         const CCoeControl& aControl,
       
    82         const TRect& /*aRect*/ ) const
       
    83     {
       
    84     const CESMRField& ctrl = 
       
    85             static_cast<const CESMRField&> ( aControl );
       
    86     TBool hasOutlineFocus = ctrl.HasOutlineFocus();
       
    87     TESMRFieldFocusType focusType = ctrl.GetFocusType();
       
    88     // highlight bitmap target rect:
       
    89     TRect rect( ctrl.GetFocusRect() );
       
    90     rect.Move( ctrl.Position() );
       
    91     
       
    92     if ( hasOutlineFocus )
       
    93         {
       
    94         if( focusType == EESMRHighlightFocus )
       
    95             {
       
    96             if( ctrl.FieldMode() == EESMRFieldModeView )
       
    97                 {
       
    98                 // Focused viewer field
       
    99                 DrawFocus( aGc, rect, aControl, EViewerFieldWithFocus );
       
   100                 }            
       
   101             }
       
   102         }
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CMRBackground::IconSkinIdL
       
   107 // ---------------------------------------------------------------------------
       
   108 // 
       
   109 CArrayFixFlat<NMRBitmapManager::TMRBitmapId>* 
       
   110 CMRBackground::IconSkinIdL( TBgType aType ) const
       
   111     {
       
   112     CArrayFixFlat<NMRBitmapManager::TMRBitmapId>* array = 
       
   113         new (ELeave) CArrayFixFlat<NMRBitmapManager::TMRBitmapId>( KGranularity );
       
   114     CleanupStack::PushL( array );
       
   115     if( aType == EViewerFieldWithFocus )
       
   116         {
       
   117         array->AppendL( NMRBitmapManager::EMRBitmapListTopLeft );
       
   118         array->AppendL( NMRBitmapManager::EMRBitmapListLeft );
       
   119         array->AppendL( NMRBitmapManager::EMRBitmapListBottomLeft );
       
   120         array->AppendL( NMRBitmapManager::EMRBitmapListTop );
       
   121         array->AppendL( NMRBitmapManager::EMRBitmapListCenter );
       
   122         array->AppendL( NMRBitmapManager::EMRBitmapListBottom );
       
   123         array->AppendL( NMRBitmapManager::EMRBitmapListTopRight );
       
   124         array->AppendL( NMRBitmapManager::EMRBitmapListRight );
       
   125         array->AppendL( NMRBitmapManager::EMRBitmapListBottomRight );   
       
   126         }
       
   127     else
       
   128         {
       
   129         array->AppendL( NMRBitmapManager::EMRBitmapSetOptTopLeft );
       
   130         array->AppendL( NMRBitmapManager::EMRBitmapSetOptLeft );
       
   131         array->AppendL( NMRBitmapManager::EMRBitmapSetOptBottomLeft );
       
   132         array->AppendL( NMRBitmapManager::EMRBitmapSetOptTop );
       
   133         array->AppendL( NMRBitmapManager::EMRBitmapSetOptCenter );
       
   134         array->AppendL( NMRBitmapManager::EMRBitmapSetOptBottom );
       
   135         array->AppendL( NMRBitmapManager::EMRBitmapSetOptTopRight );
       
   136         array->AppendL( NMRBitmapManager::EMRBitmapSetOptRight );
       
   137         array->AppendL( NMRBitmapManager::EMRBitmapSetOptBottomRight );    
       
   138         }
       
   139  
       
   140     CleanupStack::Pop( array );
       
   141     return array;
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // CMRBackground::DrawFocus
       
   146 // ---------------------------------------------------------------------------
       
   147 //    
       
   148 void CMRBackground::DrawFocus( 
       
   149         CWindowGc& aGc, 
       
   150         TRect aRect, 
       
   151         const CCoeControl& aControl, 
       
   152         TBgType aType ) const
       
   153         {
       
   154         CFbsBitmap* selector = NULL;
       
   155         CFbsBitmap* selectorMask = NULL;
       
   156         
       
   157         CArrayFixFlat<NMRBitmapManager::TMRBitmapId>* iconIds = NULL;
       
   158         // Error does not matter, we'll check that array is created and 
       
   159         // it contains all items.
       
   160         TRAP_IGNORE( iconIds = IconSkinIdL( aType ) );
       
   161         
       
   162         if( iconIds )
       
   163             {
       
   164             __ASSERT_DEBUG( 
       
   165                     iconIds->Count() == KGranularity, 
       
   166                     Panic(EErrorItemCount) );
       
   167             TSize corner(KEdge, KEdge);
       
   168             TInt error = NMRBitmapManager::GetSkinBasedBitmap( 
       
   169                     (*iconIds)[0], selector, selectorMask, corner );
       
   170     
       
   171             if( selector && selectorMask && error == KErrNone )
       
   172                 {
       
   173                 //corner TL
       
   174                 aGc.BitBltMasked( 
       
   175                         aRect.iTl, selector, corner, selectorMask, EFalse );
       
   176     
       
   177                 //side L
       
   178                 TSize side(KEdge, (aRect.Height() - 2 * KEdge) );
       
   179                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   180                         (*iconIds)[1], selector, selectorMask, side );
       
   181                 aGc.BitBltMasked( TPoint(aRect.iTl.iX, aRect.iTl.iY + KEdge),
       
   182                                   selector, side, selectorMask, EFalse );
       
   183     
       
   184                 //corner BL
       
   185                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   186                         (*iconIds)[2], selector, selectorMask, corner );
       
   187                 aGc.BitBltMasked( 
       
   188                         TPoint(aRect.iTl.iX, 
       
   189                                 aRect.iTl.iY + KEdge + side.iHeight),
       
   190                         selector, corner, selectorMask, EFalse );
       
   191     
       
   192                 //top
       
   193                 TSize top( (aRect.Width() - 2 * KEdge) , KEdge);
       
   194                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   195                         (*iconIds)[3], selector, selectorMask, top );
       
   196                 aGc.BitBltMasked( TPoint(aRect.iTl.iX + KEdge, aRect.iTl.iY),
       
   197                                   selector, top, selectorMask, EFalse );
       
   198     
       
   199                 //center
       
   200                 TSize center( top.iWidth, side.iHeight);
       
   201                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   202                         (*iconIds)[4], selector, selectorMask, center );
       
   203                 aGc.BitBltMasked( 
       
   204                         TPoint(aRect.iTl.iX + KEdge, aRect.iTl.iY + KEdge),
       
   205                             selector, center, selectorMask, EFalse );
       
   206     
       
   207                 //bottom
       
   208                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   209                         (*iconIds)[5], selector, selectorMask, top );
       
   210                 aGc.BitBltMasked( 
       
   211                 TPoint(aRect.iTl.iX + KEdge, 
       
   212                         aRect.iTl.iY + side.iHeight + KEdge),
       
   213                 selector, top, selectorMask, EFalse );
       
   214     
       
   215                 //corner TR
       
   216                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   217                         (*iconIds)[6], selector, selectorMask, corner );
       
   218                 aGc.BitBltMasked( 
       
   219                         TPoint(aRect.iTl.iX + KEdge + top.iWidth, 
       
   220                                 aRect.iTl.iY),
       
   221                         selector, corner, selectorMask, EFalse );
       
   222     
       
   223                 //side R
       
   224                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   225                         (*iconIds)[7], selector, selectorMask, side );
       
   226                 aGc.BitBltMasked( 
       
   227                         TPoint(aRect.iTl.iX + KEdge + top.iWidth, 
       
   228                                 aRect.iTl.iY + KEdge),
       
   229                  selector, side, selectorMask, EFalse );
       
   230     
       
   231                 //corner Br
       
   232                 NMRBitmapManager::GetSkinBasedBitmap( 
       
   233                         (*iconIds)[8], selector, selectorMask, corner );
       
   234                 aGc.BitBltMasked( 
       
   235                         TPoint(aRect.iTl.iX + KEdge + top.iWidth, 
       
   236                                 aRect.iTl.iY + KEdge + side.iHeight),
       
   237                                     selector, corner, selectorMask, EFalse );        
       
   238                 }
       
   239             else // This should NOT be called ever.
       
   240                 {
       
   241                 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   242                 aGc.SetPenStyle( CGraphicsContext::ENullPen );
       
   243                 aGc.SetBrushColor( KRgbGreen );
       
   244                 aGc.DrawRect( aControl.Rect() );
       
   245                 }
       
   246 
       
   247             delete selector;
       
   248             delete selectorMask;
       
   249             }
       
   250         delete iconIds;
       
   251         }
       
   252 // EOF