uigraphics/AknIcon/srvsrc/AknIconDataPreserver.cpp
changeset 0 05e9090e2422
child 50 c6286dcf6040
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2002 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:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <mifconvdefs.h>
       
    24 #include "AknIconDataPreserver.h"
       
    25 #include "AknIconFormatHandlerFactory.h"
       
    26 #include "AknIconFormatHandler.h"
       
    27 #include "AknIconDataItem.h"
       
    28 #include "AknIconSrvDef.h"
       
    29 #include "AknIconSrv.h"
       
    30 #include "AknIconSrvIconItem.h"
       
    31 #include "AknIconLoader.h"
       
    32 #include "AknIconSrvPanic.h"
       
    33 #include "AknIconSrvUtils.h"
       
    34 #include "AknIconPanic.h"
       
    35 
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KIconDataItemGranularity = 1;
       
    39 
       
    40 // ================= MEMBER FUNCTIONS ==========================================
       
    41 
       
    42 CAknIconDataPreserver::CAknIconDataPreserver( CAknIconServer& aServer ) : 
       
    43     iServer( aServer ),
       
    44     iItems( KIconDataItemGranularity )
       
    45     {
       
    46     }
       
    47 
       
    48 CAknIconDataPreserver::~CAknIconDataPreserver()
       
    49     {
       
    50     iItems.ResetAndDestroy();
       
    51     }
       
    52 
       
    53 CAknIconDataPreserver* CAknIconDataPreserver::NewL( CAknIconServer& aServer )
       
    54     {
       
    55     return new( ELeave ) CAknIconDataPreserver( aServer );
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CAknIconDataPreserver::CreateIconL
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CAknIconSrvIconItem* CAknIconDataPreserver::CreateIconL(
       
    63     const TAknIconParams& aParams )
       
    64     {
       
    65     CAknIconSrvIconItem* iconItem = NULL;
       
    66 
       
    67     // Can be instantiated in stack with this constructor.
       
    68     CAknIconDataItem compareItem( aParams );
       
    69 
       
    70     TInt index = iItems.FindInOrder( 
       
    71         &compareItem, CAknIconDataItem::LinearOrder );
       
    72 
       
    73     if ( index >= 0 )
       
    74         {
       
    75         CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
       
    76         CleanupStack::PushL( bitmap );
       
    77 
       
    78         CFbsBitmap* mask = NULL;
       
    79 
       
    80         if ( aParams.iMaskId >= 0 )
       
    81             {
       
    82             mask = new (ELeave) CFbsBitmap;
       
    83             CleanupStack::PushL( mask );
       
    84             }
       
    85 
       
    86         iHandler->UsePreparedIconL( iItems[index]->iHandle );
       
    87 
       
    88         TAknContentDimensions dimensions = AknIconSrvUtils::RenderPreparedIconL(
       
    89             *iHandler,
       
    90             bitmap,
       
    91             mask,
       
    92             iItems[index]->iBitmapDepth,
       
    93             iServer.IconDepth(),
       
    94             aParams.iSize,
       
    95             (TScaleMode)aParams.iMode,
       
    96             aParams.iRotationAngle, aParams.iColor, aParams.iAppIcon );
       
    97 
       
    98         iconItem = CAknIconSrvIconItem::NewL( aParams,
       
    99                                               bitmap,
       
   100                                               mask,
       
   101                                               dimensions,
       
   102                                               iServer.IconFileNameCache() );
       
   103         CleanupStack::Pop(); // bitmap
       
   104         if ( mask )
       
   105             {
       
   106             CleanupStack::Pop(); // mask
       
   107             }
       
   108         }
       
   109 
       
   110     return iconItem;
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CAknIconDataPreserver::PreserveIconDataL
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 const CAknIconDataItem* CAknIconDataPreserver::PreserveIconDataL(
       
   118     const TAknIconParams& aParams )
       
   119     {
       
   120     CAknIconDataItem* item = NULL;
       
   121 
       
   122     CAknIconDataItem compareItem( aParams );
       
   123 
       
   124     TInt index = iItems.FindInOrder( 
       
   125         &compareItem, CAknIconDataItem::LinearOrder );
       
   126 
       
   127     if ( index >= 0 )
       
   128         {
       
   129         item = iItems[index];
       
   130         item->iUserCount++;
       
   131         }
       
   132     else
       
   133         {
       
   134         CAknIconLoader* loader;
       
   135         TPtrC8 iconData = iServer.InitIconDataAndHandlerLC(
       
   136             aParams, loader, iHandler );
       
   137         
       
   138         // Do not perform preserving for NVG as 
       
   139         // NVG does not need preserving data
       
   140         if (loader->IconTypeL( aParams.iBitmapId ) == EIconFormatNVG )
       
   141             {
       
   142             CleanupStack::PopAndDestroy(); // InitIconDataAndHandlerLC
       
   143             User::Leave( KErrGeneral );
       
   144             }
       
   145 
       
   146         item = CAknIconDataItem::NewL( aParams, iServer.IconFileNameCache() );
       
   147         CleanupStack::PushL( item );
       
   148 
       
   149         // Makes sure that the icon loader is released when required.
       
   150         CleanupStack::PushL( 
       
   151             TCleanupItem( CAknIconServer::CleanupIconLoader, &iServer ) );
       
   152 
       
   153 
       
   154 
       
   155         item->iBitmapDepth = (TDisplayMode)loader->IconDepthL( aParams.iBitmapId );
       
   156         item->iMaskDepth = (TDisplayMode)loader->MaskDepthL( aParams.iBitmapId );
       
   157 
       
   158         iHandler->PrepareIconL( iconData, item->iHandle );
       
   159 
       
   160         // CleanupIconLoader, InitIconDataAndHandlerLC
       
   161         CleanupStack::PopAndDestroy(); // CleanupIconLoader, 
       
   162 
       
   163         User::LeaveIfError( iItems.InsertInOrder(
       
   164             item, CAknIconDataItem::LinearOrder ) );
       
   165 
       
   166         CleanupStack::Pop(); // item
       
   167         CleanupStack::PopAndDestroy(); // InitIconDataAndHandlerLC
       
   168         }
       
   169 
       
   170     return item;
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CAknIconDataPreserver::UnpreserveIconData
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 const CAknIconDataItem* CAknIconDataPreserver::UnpreserveIconData(
       
   178     const TAknIconParams& aParams, TInt aCount, const RMessage2& /*aMessage*/)
       
   179     {
       
   180     CAknIconDataItem compareItem( aParams );
       
   181 
       
   182     TInt index = iItems.FindInOrder( 
       
   183         &compareItem, CAknIconDataItem::LinearOrder );
       
   184 
       
   185     CAknIconDataItem* item = 0;
       
   186     if (index >= 0)
       
   187         {
       
   188         item = iItems[index];
       
   189         item->iUserCount -= aCount;
       
   190     
       
   191         if ( item->iUserCount == 0 )
       
   192             {
       
   193             iHandler->UnprepareIcon( item->iHandle );
       
   194             delete item;
       
   195             iItems.Remove( index );
       
   196             }
       
   197         }
       
   198     // OK to return also a pointer to a deleted item.
       
   199     return item;
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CAknIconDataPreserver::GetContentDimensionsL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 void CAknIconDataPreserver::GetContentDimensionsL( 
       
   207     const TAknIconParams& aParams,
       
   208     TAknContentDimensions& aContentDimensions )
       
   209     {
       
   210     CAknIconDataItem compareItem( aParams );
       
   211 
       
   212     TInt index = iItems.FindInOrder( 
       
   213         &compareItem, CAknIconDataItem::LinearOrder );
       
   214 
       
   215     if ( index >= 0 )
       
   216         {
       
   217         iHandler->UsePreparedIconL( iItems[index]->iHandle );
       
   218         iHandler->GetContentDimensionsL( aContentDimensions );
       
   219         }
       
   220     else
       
   221         {
       
   222         CAknIconLoader* loader;
       
   223         TPtrC8 iconData = iServer.InitIconDataAndHandlerLC(
       
   224             aParams, loader, iHandler );
       
   225 
       
   226         TInt handle;
       
   227         iHandler->PrepareIconL( iconData, handle );
       
   228         TRAPD( err,
       
   229             {
       
   230             iHandler->UsePreparedIconL( handle );
       
   231             iHandler->GetContentDimensionsL( aContentDimensions );
       
   232             } );
       
   233         iHandler->UnprepareIcon( handle );
       
   234         User::LeaveIfError( err );
       
   235         CleanupStack::PopAndDestroy(); // InitIconDataAndHandlerLC
       
   236         }
       
   237     }
       
   238 
       
   239 //  End of File