/** This function tests application's icon. It is called from TestAppInfoL function. */ void CT_LocaleStep::TestAppIconL(TSize aSize) { CApaMaskedBitmap* icon = CApaMaskedBitmap::NewLC(); TSize lastSize(0,0); TInt ret = iLs.GetAppIcon(KUidTestApp, aSize, *icon); TEST(ret == KErrNone); // Returned icon size should be exactly same as asked. TEST(icon->SizeInPixels().iWidth * icon->SizeInPixels().iHeight == aSize.iWidth * aSize.iHeight); CleanupStack::PopAndDestroy(icon); }
EXPORT_C TInt AknsUtils::GetAppIcon( MAknsSkinInstance* aInstance, TUid aAppUid, TSize aSize, CApaMaskedBitmap& aAppBitmap ) { AKNS_TRACE_OBSOLETE("AknsUtils::GetAppIcon (4 param)"); __ASSERT_DEBUG( aAppBitmap.Mask(), AKNS_DEBUG_PANIC( EAknsDPanicInvalidParameter ) ); CFbsBitmap* bitmap = NULL; CFbsBitmap* mask = NULL; TInt ret = KErrNone; TBool configuredIcon = EFalse; if ( !configuredIcon ) { ret = GetAppIconFromSkin( aInstance, aAppUid, aSize, bitmap, mask ); if( ret == KErrNone ) { if( bitmap && mask && bitmap->Handle() && mask->Handle() ) { ret = aAppBitmap.Duplicate( bitmap->Handle() ); ret |= aAppBitmap.Mask()->Duplicate( mask->Handle() ); delete bitmap; delete mask; return ret; } else { // Delete bitmaps and proceed delete bitmap; bitmap = NULL; delete mask; mask = NULL; } } } RApaLsSession lsSession; ret = lsSession.Connect(); if( ret == KErrNone ) { ret = lsSession.GetAppIcon( aAppUid, aSize, aAppBitmap ); lsSession.Close(); if(ret == KErrNone) //icon case AknInternalIconUtils::SetAppIcon(bitmap); //icon case } return ret; } //lint !e1746 GetAppIcon syntax
CApaMaskedBitmap* CInstallDialogCmdHandler::DecodeBitmapL(const TDesC8& aBitmapData) { CApaMaskedBitmap* ret = NULL; #ifdef SWI_TEXTSHELL_ROM (void) aBitmapData; #else RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); CImageDecoder* imgDecoder=CImageDecoder::DataNewL(fs, aBitmapData); CleanupStack::PushL(imgDecoder); // Get frame info needed to create bitmaps of the right size. TFrameInfo info=imgDecoder->FrameInfo(); ret = CApaMaskedBitmap::NewLC(); // Create placeholder bitmaps. TInt err=ret->Create(info.iOverallSizeInPixels, info.iFrameDisplayMode); User::LeaveIfError(err); CFbsBitmap* mask=new(ELeave) CFbsBitmap; CleanupStack::PushL(mask); err=mask->Create(info.iOverallSizeInPixels, (info.iFlags & TFrameInfo::EAlphaChannel) ? EGray256 : EGray2); User::LeaveIfError(err); // Set logo mask. ret->SetMaskBitmap(mask); // transfer ownership to the logo bitmap CleanupStack::Pop(mask); // Convert image to bitmaps. iListener=new(ELeave) CActiveListener; iListener->InitialiseActiveListener(); imgDecoder->Convert(&iListener->iStatus, *ret, *mask, 0); CActiveScheduler::Start(); delete iListener; iListener = NULL; CleanupStack::Pop(ret); CleanupStack::PopAndDestroy(2, &fs); // imgDecoder #endif return ret; }
CGulIcon* CTap2MenuAppUi::LoadAppIconHard(TUid aUid) { RApaLsSession ls; ls.Connect(); CGulIcon *retval = NULL; CArrayFixFlat<TSize> *array = new CArrayFixFlat<TSize>(3); CleanupStack::PushL(array); TInt err = ls.GetAppIconSizes(aUid, *array); if(err == KErrNone && array->Count() > 0) { CApaMaskedBitmap *bitmap = CApaMaskedBitmap::NewLC(); err = ls.GetAppIcon(aUid, (*array)[0], *bitmap); if(err == KErrNone) { CFbsBitmap* bmp = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bmp); CFbsBitmap* bmp_mask = new (ELeave) CFbsBitmap(); CleanupStack::PushL(bmp_mask); User::LeaveIfError(bmp->Create(bitmap->SizeInPixels(), bitmap->DisplayMode())); User::LeaveIfError(bmp_mask->Create(bitmap->Mask()->SizeInPixels(), bitmap->Mask()->DisplayMode())); CopyBitmapL(bitmap, bmp); CopyBitmapL(bitmap->Mask(), bmp_mask); retval = CGulIcon::NewL(bmp, bmp_mask); CleanupStack::Pop(2); // bmp, bmp_mask } CleanupStack::PopAndDestroy(bitmap); } CleanupStack::PopAndDestroy(array); ls.Close(); return retval; }
// ----------------------------------------------------------------------------- // AknsUtils::CreateMaskedBitmapL // ----------------------------------------------------------------------------- // EXPORT_C CApaMaskedBitmap* AknsUtils::CreateMaskedBitmapL( MAknsSkinInstance* aInstance, const TAknsItemID& aID, const TDesC& aFilename, const TInt aFileIndex, const TInt aFileMaskIndex ) { AKNS_TRACE_OBSOLETE("AknsUtils::CreateMaskedBitmapL (5 param)"); CFbsBitmap* bitmap = NULL; CFbsBitmap* mask = NULL; CreateIconLC( aInstance, aID, bitmap, mask, aFilename, aFileIndex, aFileMaskIndex ); // Bitmap and mask always exist here CApaMaskedBitmap* maskedBitmap = CApaMaskedBitmap::NewLC(); // Note that these calls leave with SVG-originating icons User::LeaveIfError( maskedBitmap->Duplicate( bitmap->Handle() ) ); User::LeaveIfError( maskedBitmap->Mask()->Duplicate( mask->Handle() ) ); CleanupStack::Pop( maskedBitmap ); CleanupStack::PopAndDestroy( 2 ); // bitmap, mask return maskedBitmap; }
EXPORT_C void AknsUtils::CreateAppIconLC( MAknsSkinInstance* aInstance, TUid aAppUid, TAknsAppIconType aType, CFbsBitmap*& aBitmap, CFbsBitmap*& aMask ) { aBitmap = NULL; aMask = NULL; if (!aInstance) { User::Leave(KErrArgument); } TSize legacySize( 42, 29 ); TInt bitmapIndex( 0 ); TInt maskIndex( 1 ); if( aType == EAknsAppIconTypeContext ) { legacySize = TSize( 44, 44 ); bitmapIndex = 2; maskIndex = 3; } else if( aType != EAknsAppIconTypeList ) { User::Leave( KErrArgument ); } // Make the forthcoming pushes safe (up to level 2) CleanupStack::PushL( static_cast<TAny*>(NULL) ); CleanupStack::PushL( static_cast<TAny*>(NULL) ); CleanupStack::Pop( 2 ); // 1. Check if the icon has been configured. TInt ret = KErrNone; TBool configuredIcon = EFalse; // CAknsAppSkinInstance* apskin = static_cast<CAknsAppSkinInstance*>(aInstance); if ( apskin ) { TInt config = apskin->IsIconConfiguredL( aAppUid ); if ( config > 0 ) configuredIcon = ETrue; } if ( !configuredIcon ) { // 2. Skin-originating icon ret = GetAppIconFromSkin( aInstance, aAppUid, legacySize, aBitmap, aMask ); if( ret == KErrNone ) { // These pushes are safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) return; } } // Cache connected apparc session for future reuse, if not already cached // This is done per appskininstance when necessary... if (!apskin->iCachedApaSession) { apskin->iCachedApaSession = new (ELeave) RApaLsSession; User::LeaveIfError(apskin->iCachedApaSession->Connect()); } RApaLsSession* lsSession = apskin->iCachedApaSession; TBool forceDefaultIcon = EFalse; TApaAppInfo appInfo; TFileName filename; // 3. New appicon framework HBufC* filenameBuf = NULL; TBool javaIcon = EFalse; ret = lsSession->GetAppIcon( aAppUid, filenameBuf ); if( filenameBuf ) { filename.Copy( *filenameBuf ); delete filenameBuf; } if( ret == KErrNone ) { ret = lsSession->GetAppInfo( appInfo, aAppUid ); } if( (ret==KErrNone) && (filename.Length()>2) && (appInfo.iFullName.Length()>2) ) { // Correct drive letter, if necessary if( appInfo.iFullName[1]==':' ) { if( filename[1]==':' ) { filename[0] = appInfo.iFullName[0]; } else if( filename[0]=='\\' ) { filename.Insert( 0, appInfo.iFullName.Left(2) ); } } // check if the icon is java icon javaIcon = AknsJavaUtils::IsJavaIcon(filename); if( AknIconUtils::IsMifFile( filename ) ) { // SVG icon // SVG always has only one icon bitmapIndex = 0; maskIndex = 1; AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); if (javaIcon) { AknsJavaUtils::CreateIconLC(*lsSession, aAppUid, aBitmap, aMask, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } else { AknIconUtils::CreateIconLC( aBitmap, aMask, filename, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } AknInternalIconUtils::SetAppIcon(aBitmap); //icon case return; } else { // MBM icon AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); TRAP( ret, AknIconUtils::CreateIconL( aBitmap, aMask, filename, bitmapIndex, maskIndex ) ); if( ret == KErrNone ) { // These pushes are safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) } else { bitmapIndex = 0; maskIndex = 1; AknIconUtils::ValidateLogicalAppIconId( filename, bitmapIndex, maskIndex ); AknIconUtils::CreateIconLC( aBitmap, aMask, filename, bitmapIndex, maskIndex ); // aBitmap, aMask (2) } AknInternalIconUtils::SetAppIcon(aBitmap); //icon case return; } } else if( ret!=KErrNotSupported ) { // New framework, but no icon defined forceDefaultIcon = ETrue; } CApaMaskedBitmap* apaBmp = CApaMaskedBitmap::NewLC(); // apaBmp (1) // 3. Old (AIF-based) framework if( !forceDefaultIcon ) { TInt apaErr = lsSession->GetAppIcon( aAppUid, legacySize, *apaBmp ); // Use default icon if APPARC did not initialize icon bitmaps if( apaErr || (!apaBmp) || (!apaBmp->Mask()) || (!apaBmp->Handle()) || (!apaBmp->Mask()->Handle()) ) { forceDefaultIcon = ETrue; } } if( forceDefaultIcon ) { // Default icon CleanupStack::PopAndDestroy( 1 ); // apaBmp (0) TAknsItemID iid = KAknsIIDQgnMenuUnknownLst; bitmapIndex = EMbmAvkonQgn_menu_unknown_lst; maskIndex = EMbmAvkonQgn_menu_unknown_lst_mask; if( aType == EAknsAppIconTypeContext ) { iid = KAknsIIDQgnMenuUnknownCxt; bitmapIndex = EMbmAvkonQgn_menu_unknown_cxt; maskIndex = EMbmAvkonQgn_menu_unknown_cxt_mask; } AknsUtils::CreateIconLC( aInstance, iid, aBitmap, aMask, AknIconUtils::AvkonIconFileName(), bitmapIndex, maskIndex ); // aBitmap, aMask (2) } else { // AIF-based icon CFbsBitmap* iconOwnedBitmap = new (ELeave) CFbsBitmap(); CleanupStack::PushL( iconOwnedBitmap ); // iob (3) CFbsBitmap* iconOwnedMask = new (ELeave) CFbsBitmap(); CleanupStack::PushL( iconOwnedMask ); // iom (4) User::LeaveIfError( iconOwnedBitmap->Duplicate( apaBmp->Handle() ) ); User::LeaveIfError( iconOwnedMask->Duplicate( apaBmp->Mask()->Handle() ) ); CAknIcon* tmpIcon = CAknIcon::NewL(); CleanupStack::Pop( 2 ); // iom, iob (2) CleanupStack::PopAndDestroy( 1 ); // apaBmp (0) // Ownership is transferred tmpIcon->SetBitmap( iconOwnedBitmap ); tmpIcon->SetMask( iconOwnedMask ); // Ownership of tmpIcon is transferred CAknIcon* appIcon = AknIconUtils::CreateIconL( tmpIcon ); aBitmap = appIcon->Bitmap(); aMask = appIcon->Mask(); // Detach and delete appIcon->SetBitmap( NULL ); appIcon->SetMask( NULL ); delete appIcon; // These are both safe CleanupStack::PushL( aBitmap ); // (1) CleanupStack::PushL( aMask ); // (2) } }