wvuing/wvvariant/Src/CCASkinVariant20.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Active implementation of skin feature.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCASkinVariant20.h"
       
    22 #include    "CABitmapMapping.h"     // defines the skinned bitmap ids
       
    23 #include    "ccaiconfileprovider.h"
       
    24 #include	"MCAOpBrandVariant.h"
       
    25 #include    "ChatDebugPrint.h"
       
    26 #include    "ChatDebugAssert.h"
       
    27 #include	<aknappui.h>
       
    28 #include	<AknsSkinInstance.h>	// skins 
       
    29 #include	<AknsUtils.h>
       
    30 #include	<AknUtils.h>
       
    31 #include	<AknsDrawUtils.h>
       
    32 #include	<AknsBasicBackgroundControlContext.h>
       
    33 #include	<gulicon.h>
       
    34 #include    <akniconutils.h>
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CCASkinVariant20::CCASkinVariant20
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CCASkinVariant20::CCASkinVariant20()
       
    45         : iFs( CCoeEnv::Static()->FsSession() )
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CCASkinVariant20::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CCASkinVariant20::ConstructL( MCAOpBrandVariant* aOpBrandVariant )
       
    55     {
       
    56     User::LeaveIfError( iFs.ShareProtected() );
       
    57 
       
    58     iOpBrandVariant = aOpBrandVariant;
       
    59     TRect mainPane( 0, 0, 0, 0 );
       
    60 
       
    61     // Return value can be safely ignored.
       
    62     // from AknLayoutUtils::LayoutMetricsRect documentation:
       
    63     //
       
    64     // Returns EFalse for status pane descendants if requested
       
    65     // layout component is not available in current layout. For
       
    66     // other components returns always ETrue (returned rectangle is
       
    67     // from layout definition).
       
    68     //
       
    69     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, mainPane );
       
    70 
       
    71     iBgContext = CAknsBasicBackgroundControlContext::NewL(
       
    72                      KAknsIIDQsnBgAreaMain, mainPane, EFalse );
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CCASkinVariant20::NewL
       
    77 // Two-phased constructor.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 CCASkinVariant20* CCASkinVariant20::NewL( MCAOpBrandVariant* aOpBrandVariant )
       
    81     {
       
    82     CCASkinVariant20* self = new( ELeave ) CCASkinVariant20;
       
    83 
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL( aOpBrandVariant );
       
    86     CleanupStack::Pop( self );
       
    87     return self;
       
    88     }
       
    89 
       
    90 // Destructor
       
    91 CCASkinVariant20::~CCASkinVariant20()
       
    92     {
       
    93     delete iBgContext;
       
    94     delete iBitmapFile;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCASkinVariant20::SkinFlag
       
    99 // returns skins-enabled flag
       
   100 // (other items were commented in a header).
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 TInt CCASkinVariant20::SkinFlag() const
       
   104     {
       
   105     return CAknAppUi::EAknEnableSkin;
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CCASkinVariant20::ClearChatListBoxBackGround
       
   110 // (other items were commented in a header).
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void CCASkinVariant20::ClearChatListBoxBackGround( CWindowGc& aGc,
       
   114                                                    const TRect& aUsedPortionOfViewRect,
       
   115                                                    MAknsControlContext* aContext )
       
   116     {
       
   117     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   118     AknsDrawUtils::Background( skin, aContext, NULL, aGc,
       
   119                                aUsedPortionOfViewRect );
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CCASkinVariant20::MainPaneBackgroundContext
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 MAknsControlContext* CCASkinVariant20::MainPaneBackgroundContext() const
       
   128     {
       
   129     return iBgContext;
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CCASkinVariant20::UpdateLayout
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CCASkinVariant20::UpdateLayout()
       
   138     {
       
   139     TRect screen( 0, 0, 0, 0 );
       
   140     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   141     iBgContext->SetRect( screen );
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CCASkinVariant20::DrawSkinnedEditor
       
   146 // (other items were commented in a header).
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TBool CCASkinVariant20::DrawSkinnedEditor( const CCoeControl* aControl,
       
   150                                            CWindowGc& aGc,
       
   151                                            TRect& /*aParentRect*/,
       
   152                                            TRect& aEditorRect,
       
   153                                            TRect& aOutlineRect )
       
   154     {
       
   155     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   156 
       
   157     // draw editor surroundings
       
   158     AknsDrawUtils::BackgroundBetweenRects( skin, MainPaneBackgroundContext(),
       
   159                                            aControl, aGc, aOutlineRect,
       
   160                                            aEditorRect );
       
   161 
       
   162     TRect innerRect( aOutlineRect );
       
   163     //why 6 ? don't ask me. It was 3x3 for 176x208.
       
   164     innerRect.Shrink( TSize( 6, 6 ) );
       
   165     // draw editor frames
       
   166     return  AknsDrawUtils::DrawFrame( skin, aGc, aOutlineRect, innerRect,
       
   167                                       KAknsIIDQsnFrInput, KAknsIIDQsnFrInputCenter );
       
   168 
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CCASkinVariant20::LoadBitmapL
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 CGulIcon* CCASkinVariant20::LoadBitmapL( TInt aBitmapId, TInt aMaskId,
       
   177                                          const TDesC& aFullPath, TBool aOverrideBrand,
       
   178                                          TRgb* aCustomColor )
       
   179     {
       
   180     CHAT_DP_TXT( "CCASkinVariant20::LoadBitmapL - start" );
       
   181 
       
   182     CFbsBitmap* bitmap = NULL;
       
   183     CFbsBitmap* mask = NULL;
       
   184 
       
   185     if ( iOpBrandVariant )
       
   186         {
       
   187         // brand overrides skinned bitmaps if bitmap is not forced to be
       
   188         // read through skins (aOverrideBrand)
       
   189         if ( iOpBrandVariant->BrandBitmapsActivatedL() && !aOverrideBrand )
       
   190             {
       
   191             CHAT_DP_TXT( "CCASkinVariant20::LoadBitmapL - \
       
   192                           returning branded icon" );
       
   193 
       
   194             // get a copy of filename
       
   195             HBufC* temp = aFullPath.AllocL();
       
   196             delete iBitmapFile;
       
   197             iBitmapFile = temp;
       
   198 
       
   199             // icon server take ownership of of icon file provider
       
   200             CCAIconFileProvider* ifp = CCAIconFileProvider::NewL( iFs, *iBitmapFile );
       
   201             CleanupStack::PushL( ifp );
       
   202 
       
   203             AknIconUtils::CreateIconLC( bitmap, mask, *ifp, aBitmapId,
       
   204                                         aMaskId );
       
   205 
       
   206             CleanupStack::Pop( 3, ifp ); // bitmap, mask, ifp
       
   207 
       
   208             CGulIcon* gulIcon = CGulIcon::NewL( bitmap, mask );
       
   209             return gulIcon;
       
   210             }
       
   211 
       
   212         }
       
   213 
       
   214     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   215 
       
   216     TAknsItemID itemId( KAknsIIDNone );
       
   217     TInt colorGroupId( 0 );
       
   218     MapFromBitmapIdToAknsItemId( aBitmapId, itemId, colorGroupId );
       
   219 
       
   220     if ( colorGroupId != 0 )
       
   221         {
       
   222         CHAT_DP_TXT( "CCASkinVariant20::LoadBitmapL - color change group" );
       
   223 
       
   224         if ( aBitmapId == EMbmChatngQgn_prop_im_tome
       
   225              || aBitmapId == EMbmChatngQgn_prop_im_from )
       
   226             {
       
   227             // Special case, these icons are using the same color
       
   228             // and color group as text
       
   229             if ( aCustomColor )
       
   230                 {
       
   231                 // If user has set a special color for text
       
   232                 AknIconUtils::CreateIconLC( bitmap, mask, aFullPath,
       
   233                                             aBitmapId, aMaskId );
       
   234                 AknIconUtils::SetIconColor( bitmap, *aCustomColor );
       
   235                 }
       
   236             else
       
   237                 {
       
   238                 AknsUtils::CreateColorIconLC( skin,
       
   239                                               itemId, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6,
       
   240                                               bitmap, mask, aFullPath, aBitmapId, aMaskId, KRgbBlack );
       
   241                 }
       
   242             }
       
   243         else
       
   244             {
       
   245             AknsUtils::CreateColorIconLC( skin,
       
   246                                           itemId, KAknsIIDQsnIconColors, colorGroupId,
       
   247                                           bitmap, mask, aFullPath, aBitmapId, aMaskId, KRgbBlack );
       
   248             }
       
   249         }
       
   250     else
       
   251         {
       
   252         AknsUtils::CreateIconLC( skin,
       
   253                                  itemId,
       
   254                                  bitmap, mask, aFullPath, aBitmapId, aMaskId );
       
   255         }
       
   256 
       
   257     CGulIcon* gulIcon = CGulIcon::NewL( bitmap, mask );
       
   258     CleanupStack::Pop( 2 ); // bitmap, mask
       
   259 
       
   260     CHAT_DP_TXT( "CCASkinVariant20::LoadBitmapL - returning skinned or default \
       
   261                   icon" );
       
   262     return gulIcon;
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CCASkinVariant20::MapFromBitmapIdToAknsItemId
       
   267 // (other items were commented in a header).
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CCASkinVariant20::MapFromBitmapIdToAknsItemId( TInt aBitmapId,
       
   271                                                     TAknsItemID& aItemId, TInt& aColorGroupId )
       
   272     {
       
   273     for ( TInt i( 0 ); KCABitmaps[i].iBitmapId != KErrNotFound; i++ )
       
   274         {
       
   275         if ( KCABitmaps[ i ].iBitmapId == aBitmapId )
       
   276             {
       
   277             // found it
       
   278             CHAT_DP( D_CHAT_LIT( "CCASkinVariant20::MapFromBitmapIdToAknsItemId \
       
   279                                   - id found for %d!" ), aBitmapId );
       
   280             aItemId = *( KCABitmaps[ i ].iItemId );
       
   281             aColorGroupId = KCABitmaps[ i ].iColorGroupId;
       
   282             return;
       
   283             }
       
   284         }
       
   285 
       
   286     // not found
       
   287     CHAT_DP( D_CHAT_LIT( "CCASkinVariant20::MapFromBitmapIdToAknsItemId - \
       
   288                           id not found for %d!" ), aBitmapId );
       
   289     CHAT_DP_TXT( "!!!!!!!! every bitmap enumeration should be found from \
       
   290                   CABitmapMapping.h !!!!!!!! " );
       
   291 
       
   292     __CHAT_ASSERT_DEBUG( EFalse );
       
   293     }
       
   294 
       
   295 
       
   296 //  End of File