uigraphics/AknIcon/src/AknIconUtils.cpp
changeset 0 05e9090e2422
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 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include <fbs.h>
       
    24 #include <e32math.h>
       
    25 #include <bitdev.h>
       
    26 #include <mifconvdefs.h>
       
    27 #include "AknIconUtils.h"
       
    28 #include "AknIconManager.h"
       
    29 #include "AknSourceBitmapIconManager.h"
       
    30 #include "AknFileHandleIconManager.h"
       
    31 #include "AknFileProviderIconManager.h"
       
    32 #include "AknBitmap.h"
       
    33 #include "AknIconSrvTlsData.h"
       
    34 #include "AknIconPanic.h"
       
    35 #include "AknIconTraces.h"
       
    36 #include "AknInternalIconUtils.h"
       
    37 
       
    38 
       
    39 // CONSTANTS
       
    40 
       
    41 _LIT( KAvkonIconFileName, "Z:\\Resource\\Apps\\avkon2.mbm" );
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 EXPORT_C CAknIcon* CAknIcon::NewL()
       
    46     {
       
    47     return new( ELeave ) CAknIcon;
       
    48     }
       
    49 
       
    50 CAknIcon::~CAknIcon()
       
    51     {
       
    52     delete iBitmap;
       
    53     delete iMask;
       
    54     }
       
    55 
       
    56 EXPORT_C CFbsBitmap* CAknIcon::Bitmap() const
       
    57     {
       
    58     return iBitmap;
       
    59     }
       
    60 
       
    61 EXPORT_C CFbsBitmap* CAknIcon::Mask() const
       
    62     {
       
    63     return iMask;
       
    64     }
       
    65 
       
    66 EXPORT_C void CAknIcon::SetBitmap( CFbsBitmap* aBitmap )
       
    67     {
       
    68     iBitmap = aBitmap;
       
    69     }
       
    70 
       
    71 EXPORT_C void CAknIcon::SetMask( CFbsBitmap* aMask )
       
    72     {
       
    73     iMask = aMask;
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // AknIconUtils::CreateIconL
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C void AknIconUtils::CreateIconL(
       
    81     CFbsBitmap*& aBitmap,
       
    82     CFbsBitmap*& aMask,
       
    83     const TDesC& aFileName,
       
    84     TInt aBitmapId,
       
    85     TInt aMaskId )
       
    86     {
       
    87     CreateIconLC(
       
    88         aBitmap,
       
    89         aMask,
       
    90         aFileName,
       
    91         aBitmapId,
       
    92         aMaskId );
       
    93 
       
    94     CleanupStack::Pop( 2 );
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // AknIconUtils::CreateIconLC
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C void AknIconUtils::CreateIconLC(
       
   102     CFbsBitmap*& aBitmap,
       
   103     CFbsBitmap*& aMask,
       
   104     const TDesC& aFileName,
       
   105     TInt aBitmapId,
       
   106     TInt aMaskId )
       
   107     {    
       
   108     CreateIconLC(
       
   109         aBitmap,
       
   110         aMask,
       
   111         aFileName,
       
   112         aBitmapId,
       
   113         aMaskId,
       
   114         NULL );
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // AknIconUtils::CreateIconL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C CFbsBitmap* AknIconUtils::CreateIconL(
       
   122     const TDesC& aFileName,
       
   123     TInt aBitmapId )
       
   124     {
       
   125     CFbsBitmap* bitmap;
       
   126     CFbsBitmap* mask;
       
   127 
       
   128     AknIconUtils::CreateIconL(
       
   129         bitmap,
       
   130         mask,
       
   131         aFileName,
       
   132         aBitmapId,
       
   133         -1 );
       
   134 
       
   135     return bitmap;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // AknIconUtils::CreateIconL
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void AknIconUtils::CreateIconL(
       
   143     CFbsBitmap*& aBitmap,
       
   144     CFbsBitmap*& aMask,
       
   145     MAknIconFileProvider& aFileProvider,
       
   146     TInt aBitmapId,
       
   147     TInt aMaskId )
       
   148     {
       
   149     CreateIconLC(
       
   150         aBitmap,
       
   151         aMask,
       
   152         aFileProvider,
       
   153         aBitmapId,
       
   154         aMaskId );
       
   155 
       
   156     CleanupStack::Pop( 2 );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // AknIconUtils::CreateIconL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C void AknIconUtils::CreateIconLC(
       
   164     CFbsBitmap*& aBitmap,
       
   165     CFbsBitmap*& aMask,
       
   166     MAknIconFileProvider& aFileProvider,
       
   167     TInt aBitmapId,
       
   168     TInt aMaskId )
       
   169     {
       
   170     __ASSERT_ALWAYS( &aFileProvider,
       
   171         User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
   172     
       
   173     CreateIconLC(
       
   174         aBitmap,
       
   175         aMask,
       
   176         KNullDesC(), // filename comes from aFile,
       
   177         aBitmapId,
       
   178         aMaskId,
       
   179         &aFileProvider );
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // AknIconUtils::CreateIconL
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 EXPORT_C CFbsBitmap* AknIconUtils::CreateIconL(
       
   187     MAknIconFileProvider& aFileProvider,
       
   188     TInt aBitmapId )
       
   189     {
       
   190     CFbsBitmap* bitmap;
       
   191     CFbsBitmap* mask;
       
   192 
       
   193     CreateIconL(
       
   194         bitmap,
       
   195         mask,
       
   196         aFileProvider,
       
   197         aBitmapId,
       
   198         -1 );
       
   199 
       
   200     return bitmap;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // AknIconUtils::PreserveIconData
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C void AknIconUtils::PreserveIconData( CFbsBitmap* aBitmap )
       
   208     {
       
   209     if ( IsAknBitmap( aBitmap ) )
       
   210         {
       
   211         static_cast<CAknBitmap*>( aBitmap )->Manager()->PreserveIconData();
       
   212         }
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // AknIconUtils::DestroyIconData
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 EXPORT_C void AknIconUtils::DestroyIconData( CFbsBitmap* aBitmap )
       
   220     {
       
   221     if ( IsAknBitmap( aBitmap ) )
       
   222         {
       
   223         static_cast<CAknBitmap*>( aBitmap )->Manager()->DestroyIconData();
       
   224         }
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // AknIconUtils::SetSize
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 EXPORT_C TInt AknIconUtils::SetSize(
       
   232     CFbsBitmap* aBitmap,
       
   233     const TSize& aSize,
       
   234     TScaleMode aMode )
       
   235     {
       
   236     TInt ret = KErrNone;
       
   237     
       
   238 #ifdef __AKNICON_TRACES
       
   239     RDebug::Print( _L("AknIcon: aBitmap=%x Calling AknIconUtils::SetSize - Icon size (%d,%d), Mode=%d"),
       
   240                    aBitmap, aSize.iWidth, aSize.iHeight, aMode);
       
   241 #endif    
       
   242 
       
   243     if ( IsAknBitmap( aBitmap ) )
       
   244         {
       
   245         CAknBitmap* bmp = static_cast<CAknBitmap*>(aBitmap);
       
   246         CAknIconManager* man = bmp->Manager();
       
   247         ret = man->InitializeIcon(
       
   248                 aSize, aMode );
       
   249         }
       
   250 
       
   251 #ifdef __AKNICON_TRACES
       
   252     RDebug::Print( _L("AknIcon: aBitmap=%x AknIconUtils::SetSize called - return: %d"), aBitmap, ret);
       
   253 #endif           
       
   254     return ret;
       
   255     }
       
   256 
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // AknIconUtils::SetSizeAndRotation
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 EXPORT_C TInt AknIconUtils::SetSizeAndRotation(
       
   263     CFbsBitmap* aBitmap,
       
   264     const TSize& aSize,
       
   265     TScaleMode aMode,
       
   266     TInt aAngle )
       
   267     {
       
   268     TInt ret = KErrNone;
       
   269     
       
   270 #ifdef __AKNICON_TRACES
       
   271     RDebug::Print( _L("AknIcon: aBitmap=%x Calling AknIconUtils::SetSizeAndRotation - Icon size (%d,%d), Mode=%d, Angle=%d"),
       
   272                    aBitmap, aSize.iWidth, aSize.iHeight, aMode, aAngle);
       
   273 #endif 
       
   274 
       
   275     if ( IsAknBitmap( aBitmap ) )
       
   276         {
       
   277         ret = static_cast<CAknBitmap*>( aBitmap )->Manager()->InitializeIcon(
       
   278             aSize, aMode, aAngle );
       
   279         }
       
   280         
       
   281 #ifdef __AKNICON_TRACES
       
   282     RDebug::Print( _L("AknIcon: aBitmap=%x AknIconUtils::SetSizeAndRotation called - return: %d"), aBitmap, ret);
       
   283 #endif 
       
   284     return ret;
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // AknIconUtils::SetObserver
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 EXPORT_C void AknIconUtils::SetObserver(
       
   292     CFbsBitmap* aBitmap,
       
   293     MAknIconObserver* aObserver )
       
   294     {
       
   295     if ( IsAknBitmap( aBitmap ) )
       
   296         {
       
   297         static_cast<CAknBitmap*>( aBitmap )->Manager()->SetObserver( aObserver );
       
   298         }
       
   299     }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // AknIconUtils::AvkonIconFileName
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 EXPORT_C const TDesC& AknIconUtils::AvkonIconFileName()
       
   306     {
       
   307     return KAvkonIconFileName();
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // AknIconUtils::ValidateLogicalAppIconId
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 EXPORT_C void AknIconUtils::ValidateLogicalAppIconId( 
       
   315     const TDesC& aIconFileName,
       
   316     TInt& aBitmapId,
       
   317     TInt& aMaskId )
       
   318     {
       
   319     if ( IsMifFile( aIconFileName ) )
       
   320         {
       
   321         aBitmapId += KMifIdFirst;
       
   322         aMaskId += KMifIdFirst;
       
   323         }
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // AknIconUtils::IsMifFile
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 EXPORT_C TBool AknIconUtils::IsMifFile( const TDesC& aIconFileName )
       
   331     {
       
   332     return aIconFileName.Right( KExtensionLength ).CompareF( KMifExtension ) == 0;
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // AknIconUtils::IsMifIcon
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C TBool AknIconUtils::IsMifIcon( const CFbsBitmap* aBitmap )
       
   340     {
       
   341     TBool ret = EFalse;
       
   342     if ( IsAknBitmap( aBitmap ) )
       
   343         {
       
   344         ret = !(static_cast<const CAknBitmap*>(aBitmap)->Manager()->IsMbmIcon());
       
   345         }
       
   346     return ret;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // AknIconUtils::GetContentDimensions
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TInt AknIconUtils::GetContentDimensions(
       
   354     CFbsBitmap* aBitmap,
       
   355     TSize& aContentDimensions )
       
   356     {
       
   357     TAknContentDimensions contentDimensions;
       
   358    	TInt ret = GetContentDimensions(aBitmap,contentDimensions);
       
   359    	aContentDimensions.SetSize(contentDimensions.iWidth,contentDimensions.iHeight);
       
   360     return ret;
       
   361     }
       
   362     
       
   363 // -----------------------------------------------------------------------------
       
   364 // AknIconUtils::GetContentDimensions
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 EXPORT_C TInt AknIconUtils::GetContentDimensions(
       
   368     CFbsBitmap* aBitmap,
       
   369     TAknContentDimensions& aContentDimensions )
       
   370     {
       
   371     __ASSERT_DEBUG( aBitmap, 
       
   372         User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
   373 
       
   374     TInt ret = KErrNone;
       
   375 
       
   376     if ( IsAknBitmap( aBitmap ) )
       
   377         {
       
   378         ret = static_cast<CAknBitmap*>( aBitmap )->Manager()->
       
   379             GetContentDimensions( aContentDimensions );
       
   380         }
       
   381     else
       
   382         {
       
   383         aContentDimensions.SetDimensions(aBitmap->SizeInPixels());
       
   384         }
       
   385 
       
   386     return ret;
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // AknIconUtils::CreateIconL
       
   391 // -----------------------------------------------------------------------------
       
   392 //
       
   393 EXPORT_C CAknIcon* AknIconUtils::CreateIconL( CAknIcon* aSourceIcon )
       
   394     {
       
   395     // Take ownership of aSourceIcon
       
   396     CleanupStack::PushL( aSourceIcon );
       
   397     TBool masked = reinterpret_cast<TBool>( aSourceIcon->Mask() );
       
   398 
       
   399     CAknIconManager* manager =
       
   400         new( ELeave ) CAknSourceBitmapIconManager( aSourceIcon );
       
   401     CleanupStack::Pop(); // aSourceIcon
       
   402     CleanupStack::PushL( manager );
       
   403 
       
   404     CFbsBitmap* bitmap = CAknBitmap::NewL( *manager );
       
   405     CleanupStack::Pop(); // manager - deleted from bitmap destructor from now on.
       
   406     CleanupStack::PushL( bitmap );
       
   407 
       
   408     CFbsBitmap* mask = NULL;
       
   409 
       
   410     if ( masked )
       
   411         {
       
   412         mask = CAknBitmap::NewL( *manager );
       
   413         }
       
   414 
       
   415     // Push also mask in cleanup stack always, even if NULL.
       
   416     CleanupStack::PushL( mask );
       
   417 
       
   418     manager->SetBitmap( static_cast<CAknBitmap*>( bitmap ) );
       
   419     manager->SetMask( static_cast<CAknBitmap*>( mask ) );
       
   420 
       
   421     // Bitmap icons are loaded during this call.
       
   422     // Scalable icons are set to valid CFbsBitmap handles of empty bitmaps.
       
   423     manager->PreinitializeIconL();
       
   424 
       
   425     CAknIcon* resultIcon = CAknIcon::NewL();
       
   426     resultIcon->SetBitmap( bitmap );
       
   427     resultIcon->SetMask( mask );
       
   428     
       
   429     CleanupStack::Pop( 2 ); // bitmap, mask
       
   430     return resultIcon;
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // AknIconUtils::CreateIconL
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 EXPORT_C CFbsBitmap* AknIconUtils::CreateIconL( CFbsBitmap* aSourceBitmap )
       
   438     {
       
   439     CleanupStack::PushL( aSourceBitmap );
       
   440     CAknIcon* sourceIcon = CAknIcon::NewL();
       
   441     CleanupStack::Pop(); // aSourceBitmap
       
   442     sourceIcon->SetBitmap( aSourceBitmap );
       
   443 
       
   444     CAknIcon* resultIcon = CreateIconL( sourceIcon );
       
   445     CFbsBitmap* resultBitmap = resultIcon->Bitmap();
       
   446     resultIcon->SetBitmap( NULL );
       
   447     delete resultIcon;
       
   448     return resultBitmap;
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // AknIconUtils::SetIconColor
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 EXPORT_C void AknIconUtils::SetIconColor( CFbsBitmap* aBitmap, const TRgb aColor )
       
   456     {
       
   457     __ASSERT_DEBUG( aBitmap,
       
   458         User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
   459 
       
   460     // If value 0xFF000000 is supplied, change it to 0x00000000 (same RGB value),
       
   461     // since 0xFF000000 is reserved to indicate that the color is not defined.
       
   462     if ( aColor == KColorNotDefined ) // 0xFF000000
       
   463         {
       
   464         *const_cast<TRgb*>( &aColor ) = TRgb( 0x00000000 );
       
   465         }
       
   466 
       
   467     if ( IsAknBitmap( aBitmap ) )
       
   468         {
       
   469         static_cast<CAknBitmap*>( aBitmap )->Manager()->SetIconColor( aColor );
       
   470         }
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // AknIconUtils::ExcludeFromCache
       
   475 // -----------------------------------------------------------------------------
       
   476 //
       
   477 EXPORT_C void AknIconUtils::ExcludeFromCache( CFbsBitmap* aBitmap )
       
   478     {
       
   479     __ASSERT_DEBUG( aBitmap,
       
   480         User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
   481         
       
   482     if ( IsAknBitmap( aBitmap ) )
       
   483         {
       
   484         static_cast<CAknBitmap*>( aBitmap )->Manager()->ExcludeFromCache();
       
   485         }
       
   486     }
       
   487     
       
   488 // -----------------------------------------------------------------------------
       
   489 // AknIconUtils::DisableCompression
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 EXPORT_C  void AknIconUtils::DisableCompression( CFbsBitmap* aBitmap )
       
   493     {
       
   494   __ASSERT_DEBUG( aBitmap,
       
   495         User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
   496         
       
   497     if ( IsAknBitmap( aBitmap ) )
       
   498         {
       
   499         static_cast<CAknBitmap*>( aBitmap )->Manager()->DisableCompression();
       
   500         }  
       
   501     }
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // AknIconUtils::IsAknBitmap
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 TBool AknIconUtils::IsAknBitmap( const CFbsBitmap* aBitmap )
       
   508     {
       
   509     return AknInternalIconUtils::IsAknBitmap(aBitmap);
       
   510     }
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // AknIconUtils::RotateAndScaleBitmapL
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 void AknIconUtils::RotateAndScaleBitmapL(
       
   517     const TRect& aTrgRect,
       
   518     CFbsBitmap* aTrgBitmap, 
       
   519     CFbsBitmap* aSrcBitmap,
       
   520     TInt aAngle )
       
   521     {
       
   522     aAngle = aAngle % 360;
       
   523     if (aAngle < 0)
       
   524         {
       
   525         aAngle+=360;
       
   526         }
       
   527     
       
   528     if( !aSrcBitmap ) User::Leave( KErrArgument );
       
   529     if( !aTrgBitmap ) User::Leave( KErrArgument );
       
   530     if( aSrcBitmap->DisplayMode() != aTrgBitmap->DisplayMode() ) 
       
   531         User::Leave( KErrArgument );
       
   532     
       
   533     TSize trgBitmapSize = aTrgBitmap->SizeInPixels();
       
   534 
       
   535     // calculate the valid drawing area
       
   536     TRect drawRect = aTrgRect;
       
   537     drawRect.Intersection(TRect(TPoint(0,0),trgBitmapSize));
       
   538     
       
   539     if( drawRect.IsEmpty() ) return;
       
   540 
       
   541 
       
   542     TSize srcSize = aSrcBitmap->SizeInPixels();
       
   543 
       
   544     const TInt centerX = srcSize.iWidth / 2;
       
   545     const TInt centerY = srcSize.iHeight / 2;
       
   546 
       
   547     const TInt trgWidth = aTrgRect.Width();
       
   548     const TInt trgHeight = aTrgRect.Height();
       
   549 
       
   550     TInt scalefactor;
       
   551     const TInt xscalefactor = (srcSize.iWidth << 16) / trgWidth;
       
   552     const TInt yscalefactor = (srcSize.iHeight << 16) / trgHeight;
       
   553     
       
   554     if (xscalefactor < yscalefactor)
       
   555         {
       
   556         scalefactor = yscalefactor;
       
   557         }
       
   558     else
       
   559         {
       
   560         scalefactor = xscalefactor;
       
   561         }
       
   562     
       
   563     TBool srcTemporary = EFalse;
       
   564     TBool hardMask = EFalse;
       
   565     
       
   566     if( aSrcBitmap->IsRomBitmap() )
       
   567         {
       
   568         srcTemporary = ETrue;
       
   569         }
       
   570         
       
   571     TBool fallbackOnly = EFalse;
       
   572     TDisplayMode displayMode = aSrcBitmap->DisplayMode();
       
   573     TUint8 fillColor = 0;
       
   574     switch( displayMode )
       
   575         {
       
   576         case EGray2:
       
   577             srcTemporary = ETrue;
       
   578             hardMask = ETrue;
       
   579             fillColor = 0xff; // white
       
   580             break;
       
   581         case EGray4:
       
   582         case EGray16:
       
   583         case EColor16:
       
   584         case EColor16M:
       
   585         case ERgb:
       
   586             fallbackOnly = ETrue;
       
   587             break;
       
   588         case EColor256:
       
   589             fillColor = 0xff; // should be black in our indexed palette....
       
   590         case EGray256:
       
   591         case EColor4K:
       
   592         case EColor64K:
       
   593         case EColor16MA:
       
   594         case EColor16MU:
       
   595             // These are the supported modes
       
   596             break;
       
   597         default:
       
   598             fallbackOnly = ETrue;
       
   599         }
       
   600         
       
   601     if( fallbackOnly )
       
   602         {
       
   603         User::Leave(KErrNotSupported);
       
   604         }
       
   605         
       
   606     // Heap lock for FBServ large chunk to prevent background
       
   607     // compression of aSrcBitmap after if IsCompressedInRAM returns EFalse
       
   608     aSrcBitmap->LockHeapLC( ETrue ); // fbsheaplock
       
   609     TBool fbsHeapLock = ETrue;
       
   610     if( aSrcBitmap->IsCompressedInRAM() )
       
   611         {
       
   612         srcTemporary = ETrue;
       
   613         }    
       
   614     
       
   615     CFbsBitmap* realSource = aSrcBitmap;
       
   616     CFbsBitmap* realTarget = aTrgBitmap;
       
   617     if( srcTemporary )
       
   618         {
       
   619         CleanupStack::PopAndDestroy(); // fbsheaplock
       
   620         fbsHeapLock = EFalse;
       
   621 
       
   622         realSource = new (ELeave) CFbsBitmap();
       
   623         CleanupStack::PushL( realSource );
       
   624         if (hardMask)
       
   625             {
       
   626             realTarget = new (ELeave) CFbsBitmap();
       
   627             CleanupStack::PushL(realTarget);
       
   628             User::LeaveIfError( realSource->Create( srcSize, EGray256 ) );
       
   629             displayMode = EGray256;
       
   630             User::LeaveIfError( realTarget->Create( aTrgBitmap->SizeInPixels(), EGray256));
       
   631             }
       
   632         else
       
   633             {
       
   634             User::LeaveIfError( realSource->Create( srcSize, aSrcBitmap->DisplayMode() ) );
       
   635             }
       
   636         
       
   637         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( realSource );
       
   638         CleanupStack::PushL( dev );
       
   639         CFbsBitGc* gc = NULL;
       
   640         User::LeaveIfError( dev->CreateContext( gc ) );
       
   641         CleanupStack::PushL( gc );
       
   642         gc->BitBlt( TPoint(0,0), aSrcBitmap );
       
   643         CleanupStack::PopAndDestroy(2); // dev, gc
       
   644         }
       
   645         
       
   646     if (!fbsHeapLock)
       
   647         {
       
   648         // Heap lock for FBServ large chunk is only needed with large bitmaps.
       
   649         if ( realSource->IsLargeBitmap() || realTarget->IsLargeBitmap() )
       
   650             {
       
   651             realTarget->LockHeapLC( ETrue ); // fbsheaplock
       
   652             }
       
   653         else
       
   654             {
       
   655             CleanupStack::PushL( (TAny*)NULL );
       
   656             }
       
   657         }
       
   658         
       
   659     TUint32* srcAddress = realSource->DataAddress();
       
   660     TUint32* trgAddress = realTarget->DataAddress();
       
   661     
       
   662     TReal realsin;
       
   663     TReal realcos;
       
   664     
       
   665     User::LeaveIfError(Math::Sin( realsin, ((2*KPi)/360)*aAngle));
       
   666     User::LeaveIfError(Math::Cos( realcos, ((2*KPi)/360)*aAngle));
       
   667     
       
   668     const TInt sin = ((TInt)(realsin*scalefactor));
       
   669     const TInt cos = ((TInt)(realcos*scalefactor));
       
   670     
       
   671     
       
   672     const TInt xx = trgWidth/2;
       
   673     const TInt yy = trgHeight/2;
       
   674     
       
   675     TInt x = 0;
       
   676     TInt y = 0;
       
   677     TInt u = 0;
       
   678     TInt v = 0;
       
   679     
       
   680     const TInt drawWidth  = drawRect.Width();
       
   681     const TInt drawHeight = drawRect.Height();
       
   682     
       
   683     TRect offsetRect(aTrgRect.iTl,drawRect.iTl);
       
   684     const TInt yOffset = offsetRect.Height();
       
   685     const TInt vOffset = -sin * offsetRect.Width();
       
   686     const TInt uOffset = cos * offsetRect.Width();
       
   687 
       
   688     
       
   689     if( (displayMode==EGray256) || (displayMode==EColor256) )
       
   690         {
       
   691         TInt srcScanLen8 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode);
       
   692         TInt trgScanLen8 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode);
       
   693         TUint8* srcAddr8 = reinterpret_cast<TUint8*>(srcAddress);
       
   694         TUint8* trgAddr8 = reinterpret_cast<TUint8*>(trgAddress);
       
   695 
       
   696         // skip left and top margins in the beginning
       
   697         trgAddr8 += trgScanLen8 * drawRect.iTl.iY + drawRect.iTl.iX;
       
   698 
       
   699         for (y = 0; y < drawHeight; y++)
       
   700             {
       
   701             u = (-xx) * cos + (y + yOffset - yy) * sin + (centerX<<16) + uOffset;
       
   702             v = (y + yOffset - yy) * cos - (-xx) * sin + (centerY<<16) + vOffset;
       
   703             for (x = 0; x < drawWidth; x++)
       
   704                 {
       
   705                 if ( ((u>>16)>=srcSize.iWidth) || ((v>>16)>=srcSize.iHeight) || ((u>>16)<0) || ((v>>16)<0)) 
       
   706                     {
       
   707                     *trgAddr8++ = fillColor;
       
   708                     }
       
   709                 else
       
   710                     {            	
       
   711                     *trgAddr8++ = srcAddr8[(u>>16)+(((v>>16))*srcScanLen8)];
       
   712                     }
       
   713                 u+=cos;
       
   714                 v-=sin;
       
   715                 }
       
   716             trgAddr8 += trgScanLen8 - drawWidth;
       
   717             }
       
   718         }
       
   719     else if( displayMode == EColor64K || displayMode == EColor4K)
       
   720         {
       
   721         TInt srcScanLen16 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode) /2;
       
   722         TInt trgScanLen16 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode) /2;
       
   723         TUint16* srcAddr16 = reinterpret_cast<TUint16*>(srcAddress);
       
   724         TUint16* trgAddr16 = reinterpret_cast<TUint16*>(trgAddress);
       
   725 
       
   726         // skip left and top margins in the beginning
       
   727         trgAddr16 += trgScanLen16 * drawRect.iTl.iY + drawRect.iTl.iX;
       
   728 
       
   729         for (y = 0; y <drawHeight; y++)
       
   730             {
       
   731             u = (-xx) * cos + (y + yOffset - yy) * sin + (centerX<<16) + uOffset;
       
   732             v = (y + yOffset - yy) * cos - (-xx) * sin + (centerY<<16) + vOffset;
       
   733             for (x = 0; x < drawWidth; x++)
       
   734                 {
       
   735                 if ( ((u>>16)>=srcSize.iWidth) || ((v>>16)>=srcSize.iHeight) || ((u>>16)<0) || ((v>>16)<0)) 
       
   736                     {
       
   737                     *trgAddr16++ = 0;
       
   738                     }
       
   739                 else
       
   740                     {
       
   741                     *trgAddr16++ = srcAddr16[(u>>16)+(((v>>16))*srcScanLen16)];
       
   742                     }
       
   743                 u+=cos;
       
   744                 v-=sin;
       
   745                 }
       
   746             trgAddr16 += trgScanLen16 - drawWidth;
       
   747             }        
       
   748         }
       
   749     else if( displayMode == EColor16MU || displayMode == EColor16MA)
       
   750         {
       
   751         TInt srcScanLen32 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode) /4;
       
   752         TInt trgScanLen32 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode) /4;
       
   753         TUint32* srcAddr32 = srcAddress;
       
   754         TUint32* trgAddr32 = trgAddress;
       
   755         
       
   756         // skip left and top margins in the beginning
       
   757         trgAddr32 += trgScanLen32 * drawRect.iTl.iY + drawRect.iTl.iX;
       
   758 
       
   759         for (y = 0; y < drawHeight; y++)
       
   760             {
       
   761             u = (-xx) * cos + (y + yOffset - yy) * sin + (centerX<<16) + uOffset;
       
   762             v = (y + yOffset - yy) * cos - (-xx) * sin + (centerY<<16) + vOffset;
       
   763             for (x = 0; x < drawWidth; x++)
       
   764                 {
       
   765                 if ( ((u>>16)>=srcSize.iWidth) || ((v>>16)>=srcSize.iHeight) || ((u>>16)<0) || ((v>>16)<0)) 
       
   766                     {
       
   767                     *trgAddr32++ = 0;
       
   768                     }
       
   769                 else
       
   770                     {
       
   771                     *trgAddr32++ = srcAddr32[(u>>16)+(((v>>16))*srcScanLen32)];
       
   772                     } 
       
   773                 u+=cos;
       
   774                 v-=sin;
       
   775                 }
       
   776             trgAddr32 += trgScanLen32 - drawWidth;
       
   777             }
       
   778         }
       
   779     else
       
   780         {
       
   781         User::Leave( KErrUnknown );
       
   782         }
       
   783     
       
   784     CleanupStack::PopAndDestroy(); // fbsheaplock
       
   785     
       
   786     if( srcTemporary )
       
   787         {
       
   788         if (hardMask)
       
   789             {
       
   790             CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTrgBitmap );
       
   791             CleanupStack::PushL( dev );
       
   792             CFbsBitGc* gc = NULL;
       
   793             User::LeaveIfError( dev->CreateContext( gc ) );
       
   794             CleanupStack::PushL( gc );  
       
   795             gc->BitBlt( TPoint(0,0), realTarget );
       
   796             CleanupStack::PopAndDestroy(3); // dev, gc, realtarget
       
   797             }
       
   798         CleanupStack::PopAndDestroy(); // realSource
       
   799         }
       
   800     }
       
   801 
       
   802 // -----------------------------------------------------------------------------
       
   803 // AknIconUtils::ScaleBitmapL
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 EXPORT_C void AknIconUtils::ScaleBitmapL(
       
   807     const TRect& aTrgRect,
       
   808     CFbsBitmap* aTrgBitmap, 
       
   809     CFbsBitmap* aSrcBitmap )
       
   810     {
       
   811     AknIconUtils::ScaleBitmapExtL( aTrgRect, aTrgBitmap, aSrcBitmap, EFalse );
       
   812     }
       
   813         
       
   814 // -----------------------------------------------------------------------------
       
   815 // AknIconUtils::DoesScaleBitmapUseFallBack
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 TBool AknIconUtils::DoesScaleBitmapUseFallBack( 
       
   819         CFbsBitmap* aSrcBitmap )
       
   820     {
       
   821     if ( !aSrcBitmap  )
       
   822         {
       
   823         return EFalse;
       
   824         }
       
   825 
       
   826     TBool fallbackOnly = EFalse;
       
   827     TDisplayMode displayMode = aSrcBitmap->DisplayMode();
       
   828     switch( displayMode )
       
   829         {
       
   830         case EGray2:
       
   831         case EGray4:
       
   832         case EGray16:
       
   833         case EColor16:
       
   834         case EColor16M:
       
   835         case ERgb:
       
   836             fallbackOnly = ETrue;
       
   837             break;
       
   838         case EGray256:
       
   839         case EColor4K:
       
   840         case EColor64K:
       
   841         case EColor256:
       
   842         case EColor16MU:
       
   843        	case EColor16MA:
       
   844             // These are the supported modes
       
   845             break;
       
   846         default:
       
   847             fallbackOnly = ETrue;
       
   848         }
       
   849     return fallbackOnly;
       
   850     }
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // AknIconUtils::ScaleBitmapExtL
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void AknIconUtils::ScaleBitmapExtL(
       
   857     const TRect& aTrgRect,
       
   858     CFbsBitmap* aTrgBitmap, 
       
   859     CFbsBitmap* aSrcBitmap,
       
   860     TBool aForceFallBack )
       
   861     {
       
   862     if( !aSrcBitmap ) User::Leave( KErrArgument );
       
   863     if( !aTrgBitmap ) User::Leave( KErrArgument );
       
   864     if( aSrcBitmap->DisplayMode() != aTrgBitmap->DisplayMode() ) 
       
   865         User::Leave( KErrArgument );
       
   866 
       
   867     TSize trgBitmapSize = aTrgBitmap->SizeInPixels();
       
   868     
       
   869     // calculate the valid drawing area
       
   870     TRect drawRect = aTrgRect;
       
   871     drawRect.Intersection(TRect(TPoint(0,0),trgBitmapSize));
       
   872     
       
   873     if( drawRect.IsEmpty() ) return;
       
   874     
       
   875     TSize srcSize = aSrcBitmap->SizeInPixels();
       
   876 
       
   877 
       
   878     TBool srcTemporary = EFalse;
       
   879     if( aSrcBitmap->IsRomBitmap() )
       
   880         {
       
   881         srcTemporary = ETrue;
       
   882         }
       
   883         
       
   884     TBool fallbackOnly = 
       
   885         aForceFallBack || 
       
   886         DoesScaleBitmapUseFallBack( aSrcBitmap );
       
   887         
       
   888     TDisplayMode displayMode = aSrcBitmap->DisplayMode();
       
   889 
       
   890     // VRa: This line always forces fallback
       
   891     // fallbackOnly = ETrue;
       
   892 
       
   893     if( fallbackOnly )
       
   894         {
       
   895         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTrgBitmap );
       
   896         CleanupStack::PushL( dev );
       
   897         CFbsBitGc* gc = NULL;
       
   898         User::LeaveIfError( dev->CreateContext( gc ) );
       
   899         CleanupStack::PushL( gc );
       
   900         // aTrgRect is used because DrawBitmap handles clipping automatically
       
   901         gc->DrawBitmap( aTrgRect, aSrcBitmap ); 
       
   902         CleanupStack::PopAndDestroy(2); // dev, gc
       
   903         return;
       
   904         }
       
   905        
       
   906     // Heap lock for FBServ large chunk to prevent background
       
   907     // compression of aSrcBitmap after if IsCompressedInRAM returns EFalse
       
   908     aSrcBitmap->LockHeapLC( ETrue ); // fbsheaplock
       
   909     TBool fbsHeapLock = ETrue;        
       
   910     if( aSrcBitmap->IsCompressedInRAM() )
       
   911         {
       
   912         srcTemporary = ETrue;
       
   913         }
       
   914     
       
   915     CFbsBitmap* realSource = aSrcBitmap;
       
   916     if( srcTemporary )
       
   917         {
       
   918         CleanupStack::PopAndDestroy(); // fbsheaplock
       
   919         fbsHeapLock = EFalse;
       
   920         
       
   921         realSource = new (ELeave) CFbsBitmap();
       
   922         CleanupStack::PushL( realSource );
       
   923         User::LeaveIfError( realSource->Create( srcSize, aSrcBitmap->DisplayMode() ) );
       
   924         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( realSource );
       
   925         CleanupStack::PushL( dev );
       
   926         CFbsBitGc* gc = NULL;
       
   927         User::LeaveIfError( dev->CreateContext( gc ) );
       
   928         CleanupStack::PushL( gc );
       
   929         gc->BitBlt( TPoint(0,0), aSrcBitmap );
       
   930         CleanupStack::PopAndDestroy(2); // dev, gc
       
   931         }
       
   932         
       
   933     if (!fbsHeapLock)
       
   934         {
       
   935         // Heap lock for FBServ large chunk is only needed with large bitmaps.
       
   936         if ( realSource->IsLargeBitmap() || aTrgBitmap->IsLargeBitmap() )
       
   937             {
       
   938             aTrgBitmap->LockHeapLC( ETrue ); // fbsheaplock
       
   939             }
       
   940         else
       
   941             {
       
   942             CleanupStack::PushL( (TAny*)NULL );
       
   943             }
       
   944         }
       
   945 
       
   946     TUint32* srcAddress = realSource->DataAddress();
       
   947     TUint32* trgAddress = aTrgBitmap->DataAddress();
       
   948  
       
   949     const TInt xSkip = (srcSize.iWidth << 8) / aTrgRect.Width();
       
   950     const TInt ySkip = (srcSize.iHeight << 8) / aTrgRect.Height();
       
   951     
       
   952     const TInt drawWidth  = drawRect.Width();
       
   953     const TInt drawHeight = drawRect.Height();
       
   954     
       
   955     TRect offsetRect(aTrgRect.iTl,drawRect.iTl);
       
   956     const TInt yPosOffset = ySkip * offsetRect.Height();
       
   957     const TInt xPosOffset = xSkip * offsetRect.Width();
       
   958 
       
   959 
       
   960     if( (displayMode==EGray256) || (displayMode==EColor256) )
       
   961         {
       
   962         TInt srcScanLen8 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode);
       
   963         TInt trgScanLen8 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode);
       
   964 
       
   965         TUint8* trgAddress8 = reinterpret_cast<TUint8*>(trgAddress);
       
   966 
       
   967         TInt yPos = yPosOffset;
       
   968         // skip left and top margins in the beginning
       
   969         trgAddress8 += trgScanLen8 * drawRect.iTl.iY + drawRect.iTl.iX;
       
   970 
       
   971         for( TInt y=0; y<drawHeight; y++ ) 
       
   972             {
       
   973             TUint8* srcAddress8 = reinterpret_cast<TUint8*>(srcAddress) +
       
   974                 (srcScanLen8*(yPos>>8));
       
   975 
       
   976             TInt xPos = xPosOffset;
       
   977             for( TInt x=0; x<drawWidth; x++ )
       
   978                 {
       
   979                 *(trgAddress8++) = srcAddress8[xPos>>8];
       
   980                 xPos += xSkip;
       
   981                 }
       
   982 
       
   983             yPos += ySkip;
       
   984 
       
   985             trgAddress8 += trgScanLen8 - drawWidth;
       
   986             }
       
   987         }
       
   988     else if ( displayMode == EColor4K || displayMode == EColor64K )
       
   989         {
       
   990         TInt srcScanLen16 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode) /2;
       
   991         TInt trgScanLen16 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode) /2;
       
   992 
       
   993         TUint16* trgAddress16 = reinterpret_cast<TUint16*>(trgAddress);
       
   994 
       
   995         TInt yPos = yPosOffset;
       
   996         // skip left and top margins in the beginning
       
   997         trgAddress16 += trgScanLen16 * drawRect.iTl.iY + drawRect.iTl.iX;
       
   998 
       
   999         for( TInt y=0; y<drawHeight; y++ ) 
       
  1000             {
       
  1001             TUint16* srcAddress16 = reinterpret_cast<TUint16*>(srcAddress) +
       
  1002                 (srcScanLen16*(yPos>>8));
       
  1003 
       
  1004             TInt xPos = xPosOffset;
       
  1005             for( TInt x=0; x<drawWidth; x++ )
       
  1006                 {
       
  1007                 *(trgAddress16++) = srcAddress16[xPos>>8];
       
  1008                 xPos += xSkip;
       
  1009                 }
       
  1010 
       
  1011             yPos += ySkip;
       
  1012 
       
  1013             trgAddress16 += trgScanLen16 - drawWidth;
       
  1014             }
       
  1015         }
       
  1016     else if( displayMode == EColor16MU || displayMode == EColor16MA)
       
  1017         {
       
  1018         TInt srcScanLen32 = CFbsBitmap::ScanLineLength(srcSize.iWidth, displayMode) /4;
       
  1019         TInt trgScanLen32 = CFbsBitmap::ScanLineLength(trgBitmapSize.iWidth, displayMode) /4;
       
  1020 
       
  1021         TUint32* trgAddress32 = reinterpret_cast<TUint32*>(trgAddress);
       
  1022 
       
  1023         TInt yPos = yPosOffset;
       
  1024         // skip left and top margins in the beginning
       
  1025         trgAddress32 += trgScanLen32 * drawRect.iTl.iY + drawRect.iTl.iX;
       
  1026         
       
  1027         for( TInt y=0; y<drawHeight; y++ ) 
       
  1028             {
       
  1029             TUint32* srcAddress32 = reinterpret_cast<TUint32*>(srcAddress) +
       
  1030                 (srcScanLen32*(yPos>>8));
       
  1031 
       
  1032             TInt xPos = xPosOffset;
       
  1033             for( TInt x=0; x<drawWidth; x++ )
       
  1034                 {
       
  1035                 *(trgAddress32++) = srcAddress32[xPos>>8];
       
  1036                 xPos += xSkip;
       
  1037                 }
       
  1038 
       
  1039             yPos += ySkip;
       
  1040 
       
  1041             trgAddress32 += trgScanLen32 - drawWidth;
       
  1042             }
       
  1043         }
       
  1044     else
       
  1045         {
       
  1046         User::Leave( KErrUnknown );
       
  1047         }
       
  1048 
       
  1049     CleanupStack::PopAndDestroy(); // fbsheaplock
       
  1050 
       
  1051     if( srcTemporary )
       
  1052         {
       
  1053         CleanupStack::PopAndDestroy(); // realSource
       
  1054         }
       
  1055     }
       
  1056 
       
  1057 // -----------------------------------------------------------------------------
       
  1058 // AknIconUtils::CreateIconLC
       
  1059 // -----------------------------------------------------------------------------
       
  1060 //
       
  1061 void AknIconUtils::CreateIconLC(
       
  1062     CFbsBitmap*& aBitmap,
       
  1063     CFbsBitmap*& aMask,
       
  1064     const TDesC& aFileName,
       
  1065     TInt aBitmapId,
       
  1066     TInt aMaskId,
       
  1067     MAknIconFileProvider* aFileProvider )
       
  1068     {
       
  1069     // Assert that given parameters are valid.
       
  1070 
       
  1071     __ASSERT_DEBUG( aBitmapId >= 0 && 
       
  1072         aBitmapId <= KMaxTInt16 && aMaskId <= KMaxTInt16,
       
  1073             User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
  1074 
       
  1075 #ifdef _DEBUG
       
  1076     if ( aBitmapId >= KMifIdFirst )
       
  1077         {
       
  1078         // If bitmap id is in MIF range, also mask id must be there.
       
  1079         __ASSERT_DEBUG( aMaskId >= KMifIdFirst || aMaskId < 0,
       
  1080             User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
  1081         }
       
  1082     else
       
  1083         {
       
  1084         // If bitmap id is in MBM range, also mask id must be there.
       
  1085         __ASSERT_DEBUG( aMaskId < KMifIdFirst || aMaskId < 0,
       
  1086             User::Panic( KAknIconPanicCategory, EInvalidParameter ) );
       
  1087         }
       
  1088 #endif // _DEBUG
       
  1089 
       
  1090 #ifdef __AKNICON_TRACES
       
  1091     RDebug::Print( _L("AknIcon: AknIconUtils::CreateIconLC - aFileName=%S aBitmapId=%d, aMaskId=%d "), &aFileName, aBitmapId, aMaskId);
       
  1092 #endif
       
  1093 
       
  1094     CAknIconManager* manager = NULL;
       
  1095     
       
  1096     // Currently, no leaving code allowed in this function before this point,
       
  1097     // because that could cause aFileProvider->Finished() not being called and
       
  1098     // could cause a memory leak.
       
  1099     
       
  1100     if ( aFileProvider )
       
  1101         {
       
  1102         manager = CAknFileProviderIconManager::NewL(
       
  1103             *aFileProvider, (TInt16)aBitmapId, (TInt16)aMaskId );
       
  1104         }
       
  1105     else
       
  1106         {
       
  1107         manager = CAknIconManager::NewL(
       
  1108             aFileName, (TInt16)aBitmapId, (TInt16)aMaskId );
       
  1109         }
       
  1110         
       
  1111     CleanupStack::PushL( manager );
       
  1112     CFbsBitmap* bitmap = CAknBitmap::NewL( *manager );
       
  1113 
       
  1114     CleanupStack::Pop(); // manager - deleted from bitmap destructor from now on.
       
  1115     CleanupStack::PushL( bitmap );
       
  1116 
       
  1117     CFbsBitmap* mask = NULL;
       
  1118 
       
  1119     if ( aMaskId >= 0 )
       
  1120         {
       
  1121         mask = CAknBitmap::NewL( *manager );
       
  1122         }
       
  1123 
       
  1124     // Push also mask in cleanup stack always, even if NULL.
       
  1125     CleanupStack::PushL( mask );
       
  1126 
       
  1127     manager->SetBitmap( static_cast<CAknBitmap*>( bitmap ) );
       
  1128     manager->SetMask( static_cast<CAknBitmap*>( mask ) );
       
  1129     
       
  1130     // Bitmap icons are loaded during this call.
       
  1131     // Scalable icons are set to valid CFbsBitmap handles of empty bitmaps.
       
  1132     manager->PreinitializeIconL();
       
  1133 
       
  1134     aBitmap = bitmap;
       
  1135     aMask = mask;
       
  1136     }
       
  1137 
       
  1138 EXPORT_C void AknInternalIconUtils::SetAppIcon(CFbsBitmap* aBmp)
       
  1139 	{
       
  1140 	CAknBitmap* bmp = CAknBitmap::DynamicCast(aBmp);
       
  1141 	if(bmp != NULL)
       
  1142 		{
       
  1143 		CAknIconManager* man = bmp->Manager();
       
  1144 		if ( !man->IsDefaultIconDirUsed() )
       
  1145 		    {
       
  1146 		    bmp->SetAppIcon();    
       
  1147 		    }
       
  1148 		}
       
  1149 	}
       
  1150 
       
  1151 TBool AknInternalIconUtils::IsAknBitmap( const CFbsBitmap* aBitmap )
       
  1152     {
       
  1153    	return CAknBitmap::DynamicCast(const_cast<CFbsBitmap*>(aBitmap)) != NULL;                   
       
  1154     }
       
  1155 
       
  1156 //  End of File