uigraphics/AknIcon/src/AknIconManager.cpp
changeset 0 05e9090e2422
child 2 abcbdabaa4c5
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:  Implementation of class CAknIconManager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <mifconvdefs.h>
       
    22 #include "AknIconManager.h"
       
    23 #include "AknIconSrvDef.h"
       
    24 #include "AknIconFormatHandler.h"
       
    25 #include "AknIconFormatHandlerFactory.h"
       
    26 #include "AknIconSrvClient.h"
       
    27 #include "AknBitmap.h"
       
    28 #include "AknIconSrv.h"
       
    29 #include "AknIconSrvTlsData.h"
       
    30 #include "AknIconLoader.h"
       
    31 #include "AknIconSrvUtils.h"
       
    32 #include "AknIconLocationInfo.h"
       
    33 #include "AknIconTraces.h"
       
    34 #include "AknIconFileNameCache.h"
       
    35 #include <bitdev.h>
       
    36 #include <e32math.h> // for Math::Frac()
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CAknIconManager::CAknIconManager
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CAknIconManager::CAknIconManager() : 
       
    49     iInitializedSize( -1, -1 ),
       
    50     iInitializedMode( -1 ),
       
    51     iInitializedColor(KColorNotDefined),
       
    52     iColor( KColorNotDefined ),
       
    53     iContentDimensions( -1, -1 ),
       
    54     iAppIcon(EFalse)
       
    55 	{
       
    56 	}
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CAknIconManager::ConstructL
       
    60 // Symbian 2nd phase constructor can leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 void CAknIconManager::ConstructL(
       
    64     const TDesC& aFileName, const TInt16 aBitmapId, const TInt16 aMaskId )
       
    65     {
       
    66     iBitmapId = aBitmapId;
       
    67     iMaskId = aMaskId;
       
    68     
       
    69 #ifdef __AKNICON_TRACES
       
    70     RDebug::Print( _L("AknIcon: %x CAknIconManager::ConstructL - iBitmapId=%d, iMaskId=%d"), this, iBitmapId, iMaskId);
       
    71 #endif    
       
    72 
       
    73     TFileName fileName;
       
    74     const TDesC* usedFileName = &aFileName;
       
    75 
       
    76     // This check is to support compatibility with CEikonEnv::CreateBitmapL
       
    77     if ( !aFileName.Length() )
       
    78         {
       
    79         usedFileName = &AknIconUtils::AvkonIconFileName();
       
    80         }
       
    81     // Drive not defined? If so, check in all drives, Z: first.
       
    82     else if ( aFileName.Length() < 2 || aFileName[1] != KDriveDelimiter )
       
    83         {
       
    84         fileName = aFileName;
       
    85         ChangeFileExtension( fileName );
       
    86 
       
    87         CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );
       
    88         TFindFile* find = new( ELeave ) TFindFile( data->FsSessionL() );
       
    89         CleanupStack::PushL( find );
       
    90         User::LeaveIfError( find->FindByDir( fileName, KDriveZ ) );
       
    91         fileName = find->File();
       
    92         CleanupStack::PopAndDestroy(); // find
       
    93         usedFileName = &fileName;
       
    94         }
       
    95                 
       
    96     InitIconFileNameL(*usedFileName);
       
    97     }
       
    98     
       
    99 // -----------------------------------------------------------------------------
       
   100 // CAknIconManager::InitIconFileNameL
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CAknIconManager::InitIconFileNameL( const TDesC& aFileName )
       
   104     {
       
   105     CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );
       
   106     
       
   107     TPtrC usedFileName = aFileName;
       
   108     
       
   109     // Check for the default icon dir. It is indicated with a flag, to save RAM.
       
   110     if ( usedFileName.Length() >= KAknIconDefaultDirLength &&
       
   111          usedFileName.Left( KAknIconDefaultDirLength ).CompareF( 
       
   112             KAknIconDefaultDir ) == 0 )
       
   113         {
       
   114         SetDefaultIconDirUsed();
       
   115         usedFileName.Set(usedFileName.Mid( KAknIconDefaultDirLength ));
       
   116         }
       
   117 
       
   118     // remove file extension to save RAM by eliminating storing redundant file names
       
   119     // in TLS data
       
   120     if (HasValidFileExtension(usedFileName))    
       
   121         {
       
   122         usedFileName.Set(usedFileName.Left( usedFileName.Length() - KExtensionLength ));
       
   123         SetFileExtRemoved();
       
   124         }
       
   125 
       
   126     // cache icon file name        
       
   127     iFileName = data->IconFileNameCache().CacheIconFileNameL(usedFileName);
       
   128     }
       
   129 
       
   130 CAknIconManager* CAknIconManager::NewL(
       
   131     const TDesC& aFileName, const TInt16 aBitmapId, const TInt16 aMaskId )
       
   132     {
       
   133     CAknIconManager* self = new( ELeave ) CAknIconManager();
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructL( aFileName, aBitmapId, aMaskId );
       
   136     CleanupStack::Pop();
       
   137     return self;
       
   138     }
       
   139 
       
   140 // Destructor
       
   141 CAknIconManager::~CAknIconManager()
       
   142     {
       
   143     DestroyIconData();
       
   144     delete iHandler;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CAknIconManager::PreinitializeIconL
       
   149 // Does the initializations that are done during AknIconUtils::CreateIconL(C)
       
   150 // calls, i.e. before AknIconUtils::SetSize has been called.
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CAknIconManager::PreinitializeIconL()
       
   154     {
       
   155     // Releases the icon file handle, if opened.
       
   156     CleanupStack::PushL( TCleanupItem( CleanupReleaseFileHandle, this ) );    
       
   157 
       
   158     RetrieveIconLocationInfoL();
       
   159     LoadIfBitmapIconL();
       
   160 
       
   161     CleanupStack::PopAndDestroy(); // CleanupReleaseFileHandle
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CAknIconManager::LoadIfBitmapIconL
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 void CAknIconManager::LoadIfBitmapIconL()
       
   169     {
       
   170     if ( IsMbmIcon() )
       
   171         {
       
   172         /**
       
   173         * CAknBitmap::Reset needs to be called always before calling
       
   174         * CFbsBitmap::Load or CFbsBitmap::Duplicate.
       
   175         */
       
   176         iBitmap->Reset();
       
   177         if ( iMask )
       
   178             {
       
   179             iMask->Reset();
       
   180             }
       
   181 
       
   182         LoadBitmapIconL(); // virtual function call
       
   183 
       
   184         // None of the scale modes was used - just plain load.
       
   185         iInitializedMode = -1; 
       
   186         iLoadedSize = iBitmap->SizeInPixels();
       
   187         }
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CAknIconManager::InitializeIcon
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 TInt CAknIconManager::InitializeIcon( const TSize& aSize, TScaleMode aMode )
       
   195     {
       
   196     return InitializeIcon( aSize, aMode, 0 );
       
   197     }
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CAknIconManager::InitializeIcon
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 // This method resizes both scalable and bitmap icons.
       
   204 //
       
   205 TInt CAknIconManager::InitializeIcon( 
       
   206     const TSize& aSize,
       
   207     TScaleMode aMode,
       
   208     TInt aAngle )
       
   209     {
       
   210 #ifdef __AKNICON_TRACES
       
   211     RDebug::Print( _L("AknIcon: %x Calling CAknIconManager::InitializeIcon - Icon size (%d,%d), Mode=%d, Angle=%d"),
       
   212                    this, aSize.iWidth, aSize.iHeight, aMode, aAngle);
       
   213 #endif    
       
   214     
       
   215     // If already initialized with the same parameters, do nothing.
       
   216     if ( iBitmap->Handle() )
       
   217         {
       
   218         // MBM icon
       
   219         if ( IsMbmIcon() )
       
   220             {
       
   221             if ( (iInitializedMode < 0 && iBitmap->SizeInPixels() == aSize && !iBitmap->IsAppIcon() && !aAngle && iColor == KColorNotDefined ) ||
       
   222                  (iInitializedMode == aMode &&
       
   223                   iInitializedSize == aSize && 
       
   224                   iInitializedAngle == aAngle &&
       
   225                   iInitializedColor == iColor) )
       
   226                 {
       
   227                 return KErrNone;
       
   228                 }
       
   229             }
       
   230         // MIF icon
       
   231         else
       
   232             {
       
   233             if ( iInitializedMode == aMode && 
       
   234                  iInitializedSize == aSize &&
       
   235                  iInitializedAngle == aAngle &&
       
   236                  iInitializedColor == iColor)
       
   237                 {
       
   238                 return KErrNone;
       
   239                 }
       
   240             }
       
   241         }
       
   242 
       
   243     // TRAP all leaving code and handle error in the end.
       
   244     TRAPD( err,
       
   245         {
       
   246         InitializeIconL(
       
   247             aSize,
       
   248             aMode,
       
   249             aAngle );
       
   250         } );
       
   251 
       
   252     HandleError( err );
       
   253 #ifdef __AKNICON_TRACES
       
   254     RDebug::Print( _L("AknIcon: %x CAknIconManager::InitializeIcon called - return: %d"), this, err);
       
   255 #endif    
       
   256     return err;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CAknIconManager::InitializeIconL
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CAknIconManager::InitializeIconL(
       
   264     const TSize& aSize,
       
   265     TScaleMode aMode,
       
   266     TInt aAngle )
       
   267     {
       
   268 #ifdef __AKNICON_TRACES
       
   269 
       
   270     TSize oldSize = iBitmap->SizeInPixels();
       
   271 
       
   272     if ( oldSize != TSize( 0, 0 ) &&
       
   273          oldSize != iLoadedSize )
       
   274         {
       
   275         HBufC* buf = HBufC::New( 1024 );
       
   276         if ( buf )
       
   277             {
       
   278             TPtr ptr = buf->Des();
       
   279             ptr.Copy( _L("AknIcon WARNING: icon size changed (") );            
       
   280             ptr.AppendNum( oldSize.iWidth );
       
   281             ptr.Append( _L(", ") );
       
   282             ptr.AppendNum( oldSize.iHeight );
       
   283             ptr.Append( _L(") -> (") );
       
   284             ptr.AppendNum( aSize.iWidth );
       
   285             ptr.Append( _L(", ") );
       
   286             ptr.AppendNum( aSize.iHeight );
       
   287             ptr.Append( _L(")") );
       
   288 
       
   289             RDebug::Print( ptr );
       
   290 
       
   291             ptr.Zero();
       
   292             if (iFileName)
       
   293             	{
       
   294             	GetFullFileName( ptr );
       
   295             	}
       
   296             ptr.Append( _L(", bitmap ID = ") );
       
   297             ptr.AppendNum( iBitmapId );
       
   298             ptr.Append( _L(", mask ID = ") );
       
   299             ptr.AppendNum( iMaskId );
       
   300 
       
   301             RDebug::Print( ptr );
       
   302 
       
   303             delete buf;
       
   304             }
       
   305         }
       
   306 #endif
       
   307 
       
   308     DoInitializeIconL( aSize, aMode, aAngle ); // virtual function call
       
   309     }
       
   310 
       
   311 // -----------------------------------------------------------------------------
       
   312 // CAknIconManager::GetContentDimensions
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 TInt CAknIconManager::GetContentDimensions( TAknContentDimensions& aContentDimensions )
       
   316     {
       
   317     TRAPD( ret, GetContentDimensionsL( aContentDimensions ) );
       
   318     return ret;
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CAknIconManager::GetContentDimensionsL
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CAknIconManager::GetContentDimensionsL( TAknContentDimensions& aContentDimensions )
       
   326     {
       
   327     // Releases the icon file handle, if opened.
       
   328     CleanupStack::PushL( TCleanupItem( CleanupReleaseFileHandle, this ) );
       
   329     
       
   330     // MBM icon
       
   331     if ( IsMbmIcon() )
       
   332         {
       
   333         // If not loaded at all yet, do it now.
       
   334         if ( !iBitmap->Handle() )
       
   335             {
       
   336             LoadIfBitmapIconL();
       
   337             }
       
   338         aContentDimensions.SetDimensions(iLoadedSize);
       
   339         }
       
   340     else if ( iContentDimensions.iWidth < 0 )
       
   341         {
       
   342 	    // Server-shared MIF icon (not animated)
       
   343 		if ( !IsAnimated() )
       
   344 			{
       
   345 		    // Never returns NULL.
       
   346 		    RAknIconSrvClient* client = RAknIconSrvClient::GetSession();
       
   347 		    TInt ret = client->GetContentDimensions( *iBitmap, aContentDimensions );
       
   348 
       
   349 		    if ( ret == KAknIconSrvCodeAnimated )
       
   350 		        {
       
   351 #ifdef __AKNICON_TRACES
       
   352 		    RDebug::Print( _L("AknIcon: %x In DoInitializeIconL animated icon"), this);
       
   353 #endif    	        
       
   354 		        SetAnimated();
       
   355 		        }
       
   356 		    else
       
   357 		        {
       
   358 		        User::LeaveIfError( ret );
       
   359 		        }
       
   360 	        }
       
   361 		// Animated MIF icon
       
   362 		if ( IsAnimated())
       
   363 		    {
       
   364 		        // Prepare icon if not done yet.
       
   365 		        if ( !iHandler )
       
   366 		            {
       
   367 					PrepareAnimatedIconL();
       
   368 		            }
       
   369 		        
       
   370 		        iHandler->GetContentDimensionsL( aContentDimensions );
       
   371 		        
       
   372 		        // free resources
       
   373 		        DeleteIconFormatHandler();
       
   374 		    }
       
   375 		// Store content dimensions in this class.
       
   376 		iContentDimensions = aContentDimensions;
       
   377 		}
       
   378     // Content dimensions already retrieved.
       
   379     else
       
   380         {
       
   381         aContentDimensions = iContentDimensions;
       
   382         }
       
   383        
       
   384     CleanupStack::PopAndDestroy(); // CleanupReleaseFileHandle
       
   385     }
       
   386 
       
   387 // -----------------------------------------------------------------------------
       
   388 // CAknIconManager::HandleError
       
   389 // Handles errors occurred in icon initialization (SetSize).
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CAknIconManager::HandleError( TInt aError )
       
   393     {
       
   394     if ( aError != KErrNone )
       
   395         {
       
   396         iBitmap->Reset();
       
   397         if ( iMask )
       
   398             {
       
   399             iMask->Reset();
       
   400             }
       
   401             
       
   402         // Clear the information of the
       
   403         // initialisation status parameters.    
       
   404         iInitializedMode = -1;
       
   405         iInitializedSize = ( TSize( -1, -1 ) );
       
   406         iInitializedAngle = 0;
       
   407         }
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CAknIconManager::PreserveIconData
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 void CAknIconManager::PreserveIconData()
       
   415     {
       
   416     if ( !IsMbmIcon() && !IsIconDataPreserved() )
       
   417         {
       
   418         // Never returns NULL.
       
   419         RAknIconSrvClient* client = RAknIconSrvClient::GetSession();
       
   420         TInt ret = client->PreserveIconData( *iBitmap->Manager() );
       
   421 
       
   422         // Release the icon file handle, if opened.
       
   423         ReleaseFileHandle();
       
   424 
       
   425         if ( ret == KErrNone )
       
   426             {
       
   427             SetIconDataPreserved();
       
   428             }
       
   429 
       
   430         else if ( ret == KAknIconSrvCodeAnimated )
       
   431             {
       
   432             SetAnimated();
       
   433             }
       
   434         }
       
   435     }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CAknIconManager::DestroyIconData
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 void CAknIconManager::DestroyIconData()
       
   442     {
       
   443     if ( IsIconDataPreserved() )
       
   444         {
       
   445         ClearIconDataPreserved();
       
   446 
       
   447         // Never returns NULL.
       
   448         RAknIconSrvClient* client = RAknIconSrvClient::GetSession();
       
   449         client->DestroyIconData( *this );
       
   450         }
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CAknIconManager::SetIconColor
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CAknIconManager::SetIconColor( const TRgb aColor )
       
   458     {
       
   459     iColor = aColor;
       
   460     }
       
   461 
       
   462 TRgb CAknIconManager::GetIconColor() const
       
   463     {
       
   464     return iColor;
       
   465     }
       
   466 
       
   467 
       
   468 // -----------------------------------------------------------------------------
       
   469 // CAknIconManager::GetFileName
       
   470 // -----------------------------------------------------------------------------
       
   471 //
       
   472 void CAknIconManager::GetFileName( TDes& aFileName ) const
       
   473     {
       
   474     aFileName = *iFileName;
       
   475     AppendFileExtension( aFileName );
       
   476     }
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CAknIconManager::GetFullFileName
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 void CAknIconManager::GetFullFileName( TDes& aFileName ) const
       
   483     {
       
   484     if ( IsDefaultIconDirUsed() )
       
   485         {
       
   486         aFileName = KAknIconDefaultDir;
       
   487         }
       
   488 
       
   489     aFileName.Append( *iFileName );
       
   490     AppendFileExtension( aFileName );
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // CAknIconManager::GetFullMifFileName
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CAknIconManager::GetFullMifFileName( TDes& aFileName ) const
       
   498     {
       
   499     if ( IsDefaultIconDirUsed() )
       
   500         {
       
   501         aFileName = KAknIconDefaultDir;
       
   502         }
       
   503 
       
   504     aFileName.Append( *iFileName );
       
   505     
       
   506     if ( IsFileExtRemoved())
       
   507         {                
       
   508         aFileName.Append( KMifExtension );
       
   509         }    
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CAknIconManager::Ref
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 void CAknIconManager::Ref()
       
   517     {
       
   518     iRefCount++;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CAknIconManager::Unref
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 void CAknIconManager::Unref(const CAknBitmap& aBitmap)
       
   526     {
       
   527     if ( --iRefCount == 0 )
       
   528         {
       
   529         delete this;
       
   530         }
       
   531     else
       
   532         {
       
   533         // If bitmap or mask is destroyed, delete icon format handler
       
   534         DeleteIconFormatHandler();
       
   535         // If mask is destroyed reset mask related info
       
   536         if (&aBitmap == iMask && iBitmap)
       
   537             {
       
   538             iMask = NULL;
       
   539             iOriginalMaskId = iMaskId;
       
   540             iMaskId = -1;
       
   541             iBitmap->SetMaskDestroyed();
       
   542             }
       
   543         else
       
   544             {
       
   545             iBitmap = NULL;
       
   546             }                  
       
   547         }
       
   548     }
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CAknIconManager::SetBitmap
       
   552 // -----------------------------------------------------------------------------
       
   553 //
       
   554 void CAknIconManager::SetBitmap( CAknBitmap* aBitmap )
       
   555     {
       
   556     iBitmap = aBitmap;
       
   557     }
       
   558 
       
   559 // -----------------------------------------------------------------------------
       
   560 // CAknIconManager::SetMask
       
   561 // -----------------------------------------------------------------------------
       
   562 //
       
   563 void CAknIconManager::SetMask( CAknBitmap* aMask )
       
   564     {
       
   565     iMask = aMask;
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CAknIconManager::InitializeAnimatedIconL
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CAknIconManager::InitializeAnimatedIconL( const TAknIconParams& aInfo )
       
   573     {
       
   574     CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );    
       
   575     
       
   576     CAknIconLoader* loader = NULL;
       
   577 
       
   578     if ( !iHandler )
       
   579         {
       
   580         loader = PrepareAnimatedIconLC();
       
   581         }
       
   582     else
       
   583         {
       
   584         TFileName name;
       
   585         GetFullFileName( name );
       
   586 
       
   587         RFile* file = FileHandleL();
       
   588         data->InitIconLoaderL( name, file );
       
   589         loader = data->IconLoader();
       
   590         // push 1 item to match other branch
       
   591         CleanupStack::PushL( (TAny*)NULL );
       
   592         }
       
   593     
       
   594     TDisplayMode bitmapDepth =
       
   595         (TDisplayMode)loader->IconDepthL( IconIdToIndex( iBitmapId ) );
       
   596 
       
   597     CleanupStack::PopAndDestroy(); // PrepareAnimatedIconLC or NULL
       
   598     
       
   599     iBitmap->Reset();
       
   600     if ( iMask )
       
   601         {
       
   602         iMask->Reset();
       
   603         }
       
   604 
       
   605     TBool MarginFlag = EFalse;
       
   606     
       
   607     if(iBitmap->IsAppIcon()&& !iBitmap->IsRomBitmap())
       
   608     MarginFlag = ETrue;
       
   609     
       
   610    
       
   611     AknIconSrvUtils::RenderPreparedIconL(
       
   612         *iHandler,
       
   613         iBitmap,
       
   614         iMask,
       
   615         bitmapDepth,
       
   616         data->InitData().iIconMode,
       
   617         aInfo.iSize,
       
   618         (TScaleMode)aInfo.iMode,
       
   619         aInfo.iRotationAngle,
       
   620         MarginFlag);
       
   621 
       
   622 	SetInitializedParams( aInfo );
       
   623 
       
   624     // No color icon support here currently.
       
   625 
       
   626     // No bitmap compression here, because SVG engine cannot handle compressed
       
   627     // frame buffer.
       
   628     }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 // CAknIconManager::SetObserver
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void CAknIconManager::SetObserver( MAknIconObserver* aObserver )
       
   635     {
       
   636     iObserver = aObserver;
       
   637     if ( iHandler )
       
   638         {
       
   639         iHandler->SetObserver( this );
       
   640         }
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // CAknIconManager::BitmapChanged
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 void CAknIconManager::BitmapChanged()
       
   648     {
       
   649     if ( iObserver )
       
   650         {
       
   651         iObserver->BitmapChanged( iBitmap );
       
   652         }
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // CAknIconManager::IsMbmIcon
       
   657 // This function does not work before PreinitializeIconL has been called.
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 TBool CAknIconManager::IsMbmIcon() const
       
   661     {
       
   662     return iBitmapId < KMifIdFirst;
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CAknIconManager::IconIdToIndex
       
   667 // This function does not work before PreinitializeIconL has been called.
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 TInt CAknIconManager::IconIdToIndex( TInt aId ) const
       
   671     {
       
   672     if ( IsMbmIcon() || aId < 0 )
       
   673         {
       
   674         return aId;
       
   675         }
       
   676     return aId - KMifIdFirst;
       
   677     }
       
   678 
       
   679 // -----------------------------------------------------------------------------
       
   680 // CAknIconManager::ChangeFileExtension
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 void CAknIconManager::ChangeFileExtension( TDes& aFileName ) const
       
   684     {
       
   685     // change file extension to .mif or .mbm depending on IsMbmIcon
       
   686     const TDesC& extension = IsMbmIcon() ? KMbmExtension : KMifExtension;
       
   687     
       
   688     if (HasValidFileExtension(aFileName))    
       
   689         {
       
   690         aFileName.SetLength( aFileName.Length() - KExtensionLength );
       
   691         aFileName.Append( extension );
       
   692         }
       
   693     }
       
   694 
       
   695 // -----------------------------------------------------------------------------
       
   696 // CAknIconManager::AppendFileExtension
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 void CAknIconManager::AppendFileExtension( TDes& aFileName ) const
       
   700     {
       
   701     // append file extension .mif or .mbm depending on IsMbmIcon
       
   702     const TDesC& extension = IsMbmIcon() ? KMbmExtension : KMifExtension;
       
   703     
       
   704     if ( IsFileExtRemoved())
       
   705         {                
       
   706         aFileName.Append( extension );
       
   707         }
       
   708     }  
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // CAknIconManager::PrepareAnimatedIconLC
       
   712 // -----------------------------------------------------------------------------
       
   713 //
       
   714 CAknIconLoader* CAknIconManager::PrepareAnimatedIconLC()
       
   715     {
       
   716     TFileName name;
       
   717     GetFullFileName( name );
       
   718 
       
   719     CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );
       
   720         
       
   721     RFile* file = FileHandleL();
       
   722     data->InitIconLoaderL( name, file );
       
   723     CAknIconLoader* loader = data->IconLoader();
       
   724 
       
   725     // Puts a cleanup item in CS, which makes sure that the icon data in memory
       
   726     // is released it is no longer needed.
       
   727     TPtrC8 iconData = AknIconSrvUtils::InitIconDataAndHandlerLC( 
       
   728         loader, iHandler, IconIdToIndex( iBitmapId ), ETrue );
       
   729 
       
   730 	// set observer if SetObserver is called
       
   731 	if ( iObserver )
       
   732     	{
       
   733         iHandler->SetObserver( this );
       
   734     	}
       
   735     TInt handle;
       
   736     iHandler->PrepareIconL( iconData, handle );
       
   737     iHandler->UsePreparedIconL( handle );
       
   738 
       
   739     return loader;
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CAknIconManager::PrepareAnimatedIconL
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CAknIconManager::PrepareAnimatedIconL(TBool bAnimationReady /*= EFalse*/)
       
   747 	{
       
   748 	// If PrepareAnimatedIconLC leaves the animated icon might not be fully prepared.
       
   749 	// We have to delete iHandler to ensure the state integrity of
       
   750 	// CAknIconManager object. This also causes that a new call to this function tries
       
   751 	// to prepare again the animated icon.
       
   752 	TRAPD(err,
       
   753 		{
       
   754 	    PrepareAnimatedIconLC();
       
   755 	    CleanupStack::PopAndDestroy(); // PrepareAnimatedIconLC
       
   756 		if (bAnimationReady)		
       
   757 			{
       
   758 			iHandler->RenderPreparedIconL(iBitmap,iMask);
       
   759 			}
       
   760 		});
       
   761 	if (err != KErrNone)
       
   762 		{
       
   763 #ifdef __AKNICON_TRACES
       
   764 	RDebug::Print( _L("AknIcon: %x In PrepareAnimatedIconL PrepareAnimatedIconLC/RenderPreparedIconL leaved - err: %d"), this, err);
       
   765 #endif    
       
   766 		DeleteIconFormatHandler();
       
   767 		User::Leave(err);
       
   768 		}
       
   769 		
       
   770 	}
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CAknIconManager::LoadBitmapIconL
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CAknIconManager::LoadBitmapIconL()
       
   777     {
       
   778     TFileName filename;
       
   779     GetFullFileName( filename );
       
   780 
       
   781     // CAknBitmap::Reset must always be called before calling CFbsBitmap::Load.
       
   782     __ASSERT_DEBUG( !iBitmap->Handle(), User::Invariant() );
       
   783 
       
   784     User::LeaveIfError( iBitmap->Load( filename, iBitmapId ) );
       
   785 
       
   786     if ( iMask )
       
   787         {
       
   788         // CAknBitmap::Reset must always be called before calling CFbsBitmap::Load.
       
   789         __ASSERT_DEBUG( !iMask->Handle(), User::Invariant() );
       
   790 
       
   791         User::LeaveIfError( iMask->Load( filename, iMaskId ) );
       
   792         }
       
   793     }
       
   794 
       
   795 // -----------------------------------------------------------------------------
       
   796 // CAknIconManager::FileHandleL
       
   797 // -----------------------------------------------------------------------------
       
   798 //
       
   799 RFile* CAknIconManager::FileHandleL(
       
   800     MAknIconFileProvider::TIconFileType /*aType*/ )
       
   801     {
       
   802     return NULL;
       
   803     }
       
   804 
       
   805 // -----------------------------------------------------------------------------
       
   806 // CAknIconManager::ReleaseFileHandle
       
   807 // -----------------------------------------------------------------------------
       
   808 //
       
   809 void CAknIconManager::ReleaseFileHandle()
       
   810     {
       
   811     CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );    
       
   812     if ( data )
       
   813         {
       
   814         CAknIconLoader* loader = data->IconLoader();
       
   815         if ( loader )
       
   816             {
       
   817             loader->CloseFile();
       
   818             }
       
   819         }
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CAknIconManager::CleanupReleaseFileHandle
       
   824 // -----------------------------------------------------------------------------
       
   825 //
       
   826 void CAknIconManager::CleanupReleaseFileHandle( TAny* aParam )
       
   827     {
       
   828     static_cast<CAknIconManager*>( aParam )->ReleaseFileHandle();
       
   829     }
       
   830 
       
   831 // -----------------------------------------------------------------------------
       
   832 // CAknIconManager::DoInitializeIconL
       
   833 // -----------------------------------------------------------------------------
       
   834 //
       
   835 void CAknIconManager::DoInitializeIconL(
       
   836     const TSize& aSize,
       
   837     TScaleMode aMode,
       
   838     TInt aAngle )
       
   839     {
       
   840     // Releases the icon file handle, if opened.
       
   841     CleanupStack::PushL( TCleanupItem( CleanupReleaseFileHandle, this ) );
       
   842     
       
   843     // In case of an MBM icon, load it normally here and be happy if it
       
   844     // matches the given size.
       
   845     LoadIfBitmapIconL();
       
   846 
       
   847     // Only condition not to proceed to server side in here is that
       
   848     // the loaded bitmap meets exactly the given parameters.
       
   849     if ( iBitmap->IsAppIcon() || !IsMbmIcon() || iBitmap->SizeInPixels() != aSize || aAngle || iColor != KColorNotDefined )
       
   850         {
       
   851         // Never returns NULL.
       
   852         RAknIconSrvClient* client = RAknIconSrvClient::GetSession();
       
   853 
       
   854         TAknIconParams info;
       
   855 
       
   856         GetFileName( info.iFileName );
       
   857         info.iBitmapId = IconIdToIndex( iBitmapId );
       
   858         info.iMaskId = IconIdToIndex( iMaskId );
       
   859         info.iSize = aSize;
       
   860         info.iMode = aMode;
       
   861         info.iRotationAngle = aAngle;
       
   862         info.iColor = iColor;
       
   863         info.iAppIcon = iBitmap->IsAppIcon();
       
   864         if (IsDefaultIconDirUsed())
       
   865             {
       
   866             info.SetDefaultIconDirUsed();
       
   867             }
       
   868             
       
   869         if (IsMbmIcon())
       
   870             {
       
   871             info.SetMbmIcon();
       
   872             }                    
       
   873 
       
   874         if (IsExcludedFromCache())
       
   875             {
       
   876             info.ExcludeFromCache();
       
   877             }      
       
   878             
       
   879         if (IsCompressionDisabled())
       
   880             {
       
   881             info.DisableCompression();
       
   882             }                                             
       
   883 
       
   884         RFile* file = FileHandleL();
       
   885         if ( file )
       
   886             {
       
   887             info.iFile = *file;
       
   888             }
       
   889         // Otherwise, info.iFile is initialized by RFile constructor.
       
   890 
       
   891         // Retrieve scaled icon from server side.
       
   892         TRAPD( err, 
       
   893             {
       
   894             client->InitializeIconL( *iBitmap, *iMask, iContentDimensions, info );
       
   895             } );
       
   896 
       
   897         // Animated icon? Those are not shared by the server.
       
   898         if ( err == KAknIconSrvCodeAnimated )
       
   899             {
       
   900 #ifdef __AKNICON_TRACES
       
   901 		    RDebug::Print( _L("AknIcon: %x In DoInitializeIconL animated icon"), this);
       
   902 #endif               
       
   903             SetAnimated();            
       
   904             // If InitializeAnimatedIconL leaves the animated icon might not be fully prepared.
       
   905             // We have to delete iHandler to ensure the state integrity of
       
   906             // CAknIconManager object. This also causes that a new call to this function tries
       
   907             // to prepare again the animated icon.
       
   908             TRAPD(err,InitializeAnimatedIconL( info ));
       
   909             
       
   910 			if (err != KErrNone )
       
   911 				{
       
   912 				// free resources
       
   913 				DeleteIconFormatHandler();
       
   914 #ifdef __AKNICON_TRACES
       
   915 			    RDebug::Print( _L("AknIcon: %x In DoInitializeIconL InitializeAnimatedIconL leaved - err: %d"), this, err);
       
   916 #endif    
       
   917 	            User::Leave( err );
       
   918 				}
       
   919 				
       
   920 			if (!iObserver)
       
   921 				{
       
   922 				// free resources if no observer is specified for the animation
       
   923 				DeleteIconFormatHandler();
       
   924 				}
       
   925             }
       
   926         else
       
   927             {
       
   928             User::LeaveIfError( err );
       
   929             }
       
   930         }
       
   931 
       
   932     CleanupStack::PopAndDestroy(); // CleanupReleaseFileHandle        
       
   933     }
       
   934 
       
   935 // -----------------------------------------------------------------------------
       
   936 // CAknIconManager::RetrieveIconLocationInfoL
       
   937 // -----------------------------------------------------------------------------
       
   938 //
       
   939 void CAknIconManager::RetrieveIconLocationInfoL()
       
   940     {
       
   941     // With MIF v1, bitmap IDs were in the range 0 ... KMifIdFirst-1.
       
   942     // In that case, we don't need to do anything.
       
   943     if ( iBitmapId >= KMifIdFirst )
       
   944         {
       
   945         // Try retrieve cached information of icon type from TLS
       
   946         CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );
       
   947         // If MBM icon, this stores new IDs in iBitmapId and iMaskId.
       
   948 
       
   949         TFileName name;
       
   950         GetFullMifFileName( name );
       
   951 
       
   952         TInt ret = data->GetIconLocationInfo(
       
   953             name, iBitmapId, iMaskId );
       
   954         
       
   955         if ( ret == KErrNotFound )
       
   956             {
       
   957             // Loads the icon type information from the MIF file and caches
       
   958             // it in TLS for all the icons in the same icon file.
       
   959             // Also, mapping from MBG IDs to the IDs used with MBM files is stored.
       
   960             LoadIconLocationInfoL( name );
       
   961             }
       
   962         }
       
   963     }
       
   964 
       
   965 // -----------------------------------------------------------------------------
       
   966 // CAknIconManager::LoadIconLocationInfoL
       
   967 // -----------------------------------------------------------------------------
       
   968 //
       
   969 void CAknIconManager::LoadIconLocationInfoL(
       
   970     const TDesC& aFileName )
       
   971     {
       
   972     // With CAknFileProviderIconManager, this call also initializes iFileName,
       
   973     // which is needed below in GetFullFileName call.
       
   974     RFile* file = FileHandleL( MAknIconFileProvider::EMifFile ); // virtual function call
       
   975 
       
   976     CAknIconSrvTlsData* data = static_cast<CAknIconSrvTlsData*>( Dll::Tls() );
       
   977     data->InitIconLoaderL( aFileName, file );
       
   978     CAknIconLoader* loader = data->IconLoader();
       
   979 
       
   980     CAknIconLocationInfo* info = loader->LoadIconLocationInfoL( aFileName );
       
   981     CleanupStack::PushL( info );
       
   982     // Store in TLS for further use.
       
   983     data->StoreIconLocationInfoL( info );
       
   984     CleanupStack::Pop(); // info
       
   985 
       
   986     User::LeaveIfError( info->GetIconLocation( iBitmapId, iMaskId ) );
       
   987     }
       
   988 
       
   989 // -----------------------------------------------------------------------------
       
   990 // CAknIconManager::FileHandleL
       
   991 // -----------------------------------------------------------------------------
       
   992 //
       
   993 RFile* CAknIconManager::FileHandleL()
       
   994     {
       
   995     MAknIconFileProvider::TIconFileType type =
       
   996         IsMbmIcon() ?
       
   997         MAknIconFileProvider::EMbmFile :
       
   998         MAknIconFileProvider::EMifFile;
       
   999         
       
  1000     return FileHandleL( type ); // Virtual function call
       
  1001     }
       
  1002 
       
  1003 
       
  1004    	
       
  1005  TInt CAknIconManager::ScaleMode() const  	
       
  1006  	{
       
  1007  	return iInitializedMode;
       
  1008  	}
       
  1009 
       
  1010 TInt CAknIconManager::Check(const TSize& aSize,TScaleMode aMode,TInt aAngle) 
       
  1011    {
       
  1012    
       
  1013     // If already initialized with the same parameters, do nothing.
       
  1014     if ( iBitmap->Handle() )
       
  1015         {
       
  1016         // MBM icon
       
  1017         if ( IsMbmIcon() )
       
  1018             {
       
  1019             if ( (iInitializedMode < 0 && iBitmap->SizeInPixels() == aSize && !aAngle && iColor == KColorNotDefined ) ||
       
  1020                  (iInitializedMode == aMode &&
       
  1021                   iInitializedSize == aSize && 
       
  1022                   iInitializedAngle == aAngle &&
       
  1023                   iInitializedColor == iColor) )
       
  1024                 {
       
  1025                 return KErrNone;
       
  1026                 }
       
  1027             }
       
  1028         // MIF icon
       
  1029         else
       
  1030             {
       
  1031             if ( iInitializedMode == aMode && 
       
  1032                  iInitializedSize == aSize &&
       
  1033                  iInitializedAngle == aAngle &&
       
  1034                  iInitializedColor == iColor)
       
  1035                 {
       
  1036                 return KErrNone;
       
  1037                 }
       
  1038             }
       
  1039         }
       
  1040    
       
  1041     return KErrGeneral;   
       
  1042    }
       
  1043    
       
  1044  
       
  1045    
       
  1046 //  End of File