skins/AknSkins/src/AknsFrameBackgroundControlContext.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2002-2008 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:  Context for frames.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AknsCppPreface.h"
       
    21 
       
    22 #include <AknsFrameBackgroundControlContext.h>
       
    23 #include <AknsItemData.h>
       
    24 #include <AknsUtils.h>
       
    25 #include <AknsDrawUtils.h>
       
    26 
       
    27 #include "AknsBackgroundLayout.h"
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CAknsFrameBackgroundControlContext::CAknsFrameBackgroundControlContext
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CAknsFrameBackgroundControlContext::CAknsFrameBackgroundControlContext() :
       
    38     CAknsLayeredBackgroundControlContext(),
       
    39     iInnerRect(0,0,1,1), iOuterRect(0,0,1,1), iSingleElementFrame( EFalse )
       
    40     {
       
    41     iFrameID = KAknsIIDNone;
       
    42     iCenterID = KAknsIIDDefault;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CAknsFrameBackgroundControlContext::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CAknsFrameBackgroundControlContext::ConstructL(
       
    51     const TAknsItemID& aFrameID, const TRect& aOuterRect,
       
    52     const TRect& aInnerRect, const TBool aParentAbsolute )
       
    53     {
       
    54     CAknsLayeredBackgroundControlContext::ConstructL( TRect(0,0,1,1),
       
    55         aParentAbsolute, KAknsIIDNone, EAknsFrameElementsN );
       
    56 
       
    57     SetFrameRects( aOuterRect, aInnerRect );
       
    58     SetFrame( aFrameID );
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CAknsFrameBackgroundControlContext::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 AKNS_EXPORTED_METHOD(CAknsFrameBackgroundControlContext::NewL)
       
    67 EXPORT_C CAknsFrameBackgroundControlContext*
       
    68     CAknsFrameBackgroundControlContext::NewL(
       
    69     const TAknsItemID& aFrameID, const TRect& aOuterRect,
       
    70     const TRect& aInnerRect, const TBool aParentAbsolute )
       
    71     {
       
    72     CAknsFrameBackgroundControlContext* self =
       
    73         new( ELeave ) CAknsFrameBackgroundControlContext();
       
    74 
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL( aFrameID, aOuterRect, aInnerRect, aParentAbsolute );
       
    77     CleanupStack::Pop( self );
       
    78 
       
    79     return self;
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CAknsFrameBackgroundControlContext::~CAknsFrameBackgroundControlContext
       
    84 // Destructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CAknsFrameBackgroundControlContext::~CAknsFrameBackgroundControlContext()
       
    88     {
       
    89     }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CAknsFrameBackgroundControlContext::SetFrame
       
    93 // (other items were commented in a header).
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CAknsFrameBackgroundControlContext::SetFrame(
       
    97     const TAknsItemID& aFrameID )
       
    98     {
       
    99     iFrameID = aFrameID;
       
   100     iCenterID = KAknsIIDDefault;
       
   101 
       
   102     TInt i;
       
   103 
       
   104     for( i=0; i<EAknsFrameElementsN; i++ )
       
   105         {
       
   106         SetLayerImage( i, KAknsIIDNone );
       
   107         }
       
   108 
       
   109     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   110     if( !skin )
       
   111         {
       
   112         return;
       
   113         }
       
   114 
       
   115     CAknsImageItemData* imgData = static_cast<CAknsImageItemData*>(
       
   116         skin->GetCachedItemData( aFrameID, EAknsITImage ) );
       
   117     if( !imgData )
       
   118         {
       
   119         return;
       
   120         }
       
   121 
       
   122     //lint --e{961} Valid logic
       
   123     if( AknsUtils::IsDerivedType( EAknsITBitmap, imgData->Type() ) )
       
   124         {
       
   125         iSingleElementFrame = ETrue;
       
   126 
       
   127         SetLayerImage( 0, aFrameID );
       
   128         }
       
   129     else if( AknsUtils::IsDerivedType( EAknsITImageTable, imgData->Type() ) )
       
   130         {
       
   131         iSingleElementFrame = EFalse;
       
   132 
       
   133         CAknsImageTableItemData* itData =
       
   134             static_cast<CAknsImageTableItemData*>(imgData);
       
   135         if( itData->NumberOfImages()!=9 )
       
   136             {
       
   137             return;
       
   138             }
       
   139 
       
   140         SetLayerImage( 0, itData->ImageIID( EAknsFrameIndexCenter ) );
       
   141         for( i=0; i<EAknsFrameElementsN-1; i++ )
       
   142             {
       
   143             SetLayerImage( i+1, itData->ImageIID( i ) );
       
   144             }
       
   145         }
       
   146     // Since we can not leave, just tolerate the unsupported type
       
   147 
       
   148     UpdateFrame();
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CAknsFrameBackgroundControlContext::SetFrameRects
       
   153 // (other items were commented in a header).
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 EXPORT_C void CAknsFrameBackgroundControlContext::SetFrameRects(
       
   157     const TRect& aOuterRect,
       
   158     const TRect& aInnerRect )
       
   159     {
       
   160     iOuterRect = aOuterRect;
       
   161     iInnerRect = aInnerRect;
       
   162 
       
   163     // Center
       
   164     // Center layer rectangle handled by UpdateFrame
       
   165 
       
   166     // Corners
       
   167     SetLayerRect( EAknsFrameIndexTl+1,
       
   168         TRect( aOuterRect.iTl, aInnerRect.iTl ) );
       
   169     SetLayerRect( EAknsFrameIndexTr+1,
       
   170         TRect( aInnerRect.iBr.iX, aOuterRect.iTl.iY,
       
   171         aOuterRect.iBr.iX, aInnerRect.iTl.iY ) );
       
   172     SetLayerRect( EAknsFrameIndexBl+1,
       
   173         TRect( aOuterRect.iTl.iX, aInnerRect.iBr.iY,
       
   174         aInnerRect.iTl.iX, aOuterRect.iBr.iY ) );
       
   175     SetLayerRect( EAknsFrameIndexBr+1,
       
   176         TRect( aInnerRect.iBr, aOuterRect.iBr ) );
       
   177 
       
   178     // Sides
       
   179     TRect sideRect( aInnerRect.iTl.iX, aOuterRect.iTl.iY,
       
   180         aInnerRect.iBr.iX, aInnerRect.iTl.iY );
       
   181     SetLayerRect( EAknsFrameIndexT+1, sideRect );
       
   182     sideRect.SetRect( aInnerRect.iTl.iX, aInnerRect.iBr.iY,
       
   183         aInnerRect.iBr.iX, aOuterRect.iBr.iY );
       
   184     SetLayerRect( EAknsFrameIndexB+1, sideRect );
       
   185     sideRect.SetRect( aOuterRect.iTl.iX, aInnerRect.iTl.iY,
       
   186         aInnerRect.iTl.iX, aInnerRect.iBr.iY );
       
   187     SetLayerRect( EAknsFrameIndexL+1, sideRect );
       
   188     sideRect.SetRect( aInnerRect.iBr.iX, aInnerRect.iTl.iY,
       
   189         aOuterRect.iBr.iX, aInnerRect.iBr.iY );
       
   190     SetLayerRect( EAknsFrameIndexR+1, sideRect );
       
   191 
       
   192     UpdateFrame();
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CAknsFrameBackgroundControlContext::SetCenter
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 AKNS_EXPORTED_METHOD(CAknsFrameBackgroundControlContext::SetCenter)
       
   201 EXPORT_C void CAknsFrameBackgroundControlContext::SetCenter(
       
   202     const TAknsItemID& aID )
       
   203     {
       
   204     iCenterID = aID;
       
   205     iLayout->iImageID = aID;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CAknsFrameBackgroundControlContext::SetFramePartRect
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 AKNS_EXPORTED_METHOD(CAknsFrameBackgroundControlContext::SetFramePartRect)
       
   214 EXPORT_C void CAknsFrameBackgroundControlContext::SetFramePartRect(
       
   215     const TRect& aRect,
       
   216     const TAknsFrameElementIndex aFrameElement )
       
   217     {
       
   218     if( aFrameElement == EAknsFrameIndexCenter )
       
   219         {
       
   220         iInnerRect = aRect;
       
   221         // Center layer rectangle handled by UpdateFrame
       
   222         }
       
   223     else
       
   224         {
       
   225         //lint --e{961} Valid logic
       
   226         if( aFrameElement == EAknsFrameIndexTl )
       
   227             {
       
   228             iOuterRect.iTl = aRect.iTl;
       
   229             }
       
   230         else if( aFrameElement == EAknsFrameIndexBr )
       
   231             {
       
   232             iOuterRect.iBr = aRect.iBr;
       
   233             }
       
   234         // None of the other cases change outer rect
       
   235 
       
   236         SetLayerRect( aFrameElement+1 , aRect );
       
   237         }
       
   238 
       
   239     UpdateFrame();
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CAknsFrameBackgroundControlContext::IsCompatibleWithType
       
   244 // (other items were commented in a header).
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TBool CAknsFrameBackgroundControlContext::IsCompatibleWithType(
       
   248     const TAknsControlContextType aType ) const
       
   249     {
       
   250     switch( aType )
       
   251         {
       
   252         case EAknsControlContextTypeUnknown:
       
   253         case EAknsControlContextTypeBasic:
       
   254         case EAknsControlContextTypeLayered:
       
   255         case EAknsControlContextTypeFrame:
       
   256             return ETrue;
       
   257 
       
   258         case EAknsControlContextTypeListBox:
       
   259             break;
       
   260         }
       
   261 
       
   262     return EFalse;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CAknsFrameBackgroundControlContext::UpdateContext
       
   267 // (other items were commented in a header).
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 TInt CAknsFrameBackgroundControlContext::UpdateContext()
       
   271     {
       
   272     SetFrame( iFrameID );
       
   273     if( (!iSingleElementFrame) && (iCenterID!=KAknsIIDDefault) )
       
   274         {
       
   275         SetCenter( iCenterID );
       
   276         }
       
   277 
       
   278     return 0;
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CAknsFrameBackgroundControlContext::UpdateFrame
       
   283 // (other items were commented in a header).
       
   284 // -----------------------------------------------------------------------------
       
   285 //
       
   286 void CAknsFrameBackgroundControlContext::UpdateFrame()
       
   287     {
       
   288     if( iSingleElementFrame )
       
   289         {
       
   290         iLayout->iNext = NULL;
       
   291         SetLayerRect( 0, iOuterRect );
       
   292         }
       
   293     else
       
   294         {
       
   295         iLayout->iNext = &(iLayoutArray[0]);
       
   296         SetLayerRect( 0, iInnerRect );
       
   297         }
       
   298 
       
   299     MAknsSkinInstance* skininstance = AknsUtils::SkinInstance();
       
   300     AknsDrawUtils::PrepareFrame( skininstance,
       
   301         iOuterRect, iInnerRect,
       
   302         iFrameID, iCenterID);
       
   303     }
       
   304 
       
   305 //  End of File