idlehomescreen/widgetmanager/src/wmimageconverter.cpp
branchRCL_3
changeset 93 b01126ce0bec
parent 83 5456b4e8b3a8
child 102 ba63c83f4716
equal deleted inserted replaced
88:3321d3e205b6 93:b01126ce0bec
    99 //
    99 //
   100 TInt CWmImageConverter::HandleIconString( 
   100 TInt CWmImageConverter::HandleIconString( 
   101                             const TSize& aIconSize, 
   101                             const TSize& aIconSize, 
   102                             const TDesC& aIconStr,
   102                             const TDesC& aIconStr,
   103                             CFbsBitmap*& aBitmap,
   103                             CFbsBitmap*& aBitmap,
   104                             CFbsBitmap*& aMask )
   104                             CFbsBitmap*& aMask,
       
   105                             TBool aForceScale )
   105     {
   106     {
   106     delete aBitmap; aBitmap = NULL;
   107     delete aBitmap; aBitmap = NULL;
   107     delete aMask; aMask = NULL;
   108     delete aMask; aMask = NULL;
   108 
   109 
   109     TInt err( KErrNone );
   110     TInt err( KErrNone );
   110     TRAP( err, HandleIconStringL( aIconSize, aIconStr ); );
   111     TRAP( err, HandleIconStringL( aIconSize, aIconStr, aForceScale ); );
   111     if ( err == KErrNone && iBitmap && iMask )
   112     if ( err == KErrNone && iBitmap && iMask )
   112         {
   113         {
   113         // ownership transferred
   114         // ownership transferred
   114         aBitmap = iBitmap;
   115         aBitmap = iBitmap;
   115         iBitmap = NULL;
   116         iBitmap = NULL;
   137 // CWmImageConverter::HandleIconStringL
   138 // CWmImageConverter::HandleIconStringL
   138 // ---------------------------------------------------------
   139 // ---------------------------------------------------------
   139 //
   140 //
   140 void CWmImageConverter::HandleIconStringL( 
   141 void CWmImageConverter::HandleIconStringL( 
   141                             const TSize& aIconSize, 
   142                             const TSize& aIconSize, 
   142                             const TDesC& aIconStr )
   143                             const TDesC& aIconStr,
       
   144                             TBool aForceScale )
   143     {
   145     {
   144     if ( aIconStr.Length() )
   146     if ( aIconStr.Length() )
   145         {
   147         {
   146         TAknsItemID skinItemId;
   148         TAknsItemID skinItemId;
   147         skinItemId.iMajor = 0;
   149         skinItemId.iMajor = 0;
   158             CreateSkinOrMifIconL( 
   160             CreateSkinOrMifIconL( 
   159                     skinItemId, bitmapId, maskId, iFilename );
   161                     skinItemId, bitmapId, maskId, iFilename );
   160             }
   162             }
   161         else if ( ResolveUid( aIconStr, appUid ) )
   163         else if ( ResolveUid( aIconStr, appUid ) )
   162             {
   164             {
   163             CreateIconFromUidL( appUid );
   165             CreateIconFromUidL( appUid, aForceScale );
   164             }
   166             }
   165         else if ( EndsWith( aIconStr, KSvgExt ) )
   167         else if ( EndsWith( aIconStr, KSvgExt ) )
   166             {
   168             {
   167             // filename_with_full_path.svg
   169             // filename_with_full_path.svg
   168             CreateIconFromSvgL( aIconStr );
   170             CreateIconFromSvgL( aIconStr );
   169             }
   171             }
   170         else if ( BaflUtils::FileExists( iFs, aIconStr ) )
   172         else if ( BaflUtils::FileExists( iFs, aIconStr ) )
   171             {
   173             {
   172             // filename_with_full_path.png/jpg
   174             // filename_with_full_path.png/jpg
   173             CreateIconFromOtherL( aIconStr );
   175             CreateIconFromOtherL( aIconStr, aForceScale );
   174             }
   176             }
   175         else
   177         else
   176             {
   178             {
   177             User::Leave( KErrArgument );
   179             User::Leave( KErrArgument );
   178             }
   180             }
   185 
   187 
   186 // ---------------------------------------------------------
   188 // ---------------------------------------------------------
   187 // CWmImageConverter::CreateIconFromUidL
   189 // CWmImageConverter::CreateIconFromUidL
   188 // ---------------------------------------------------------
   190 // ---------------------------------------------------------
   189 //
   191 //
   190 void CWmImageConverter::CreateIconFromUidL( const TUid& aUid )
   192 void CWmImageConverter::CreateIconFromUidL( 
       
   193         const TUid& aUid, TBool aForceScale )
   191     {
   194     {
   192     CFbsBitmap* bitmap = NULL;
   195     CFbsBitmap* bitmap = NULL;
   193     CFbsBitmap* mask = NULL;
   196     CFbsBitmap* mask = NULL;
   194    
   197    
   195     if ( aUid.iUid >= KWidgetUidLowerBound &&
   198     if ( aUid.iUid >= KWidgetUidLowerBound &&
   218             if ( size == iSize ) { break; }
   221             if ( size == iSize ) { break; }
   219             }
   222             }
   220 
   223 
   221         CApaMaskedBitmap* maskedBmp = CApaMaskedBitmap::NewLC();
   224         CApaMaskedBitmap* maskedBmp = CApaMaskedBitmap::NewLC();
   222         User::LeaveIfError( lsSession.GetAppIcon( aUid, size, *maskedBmp ) );
   225         User::LeaveIfError( lsSession.GetAppIcon( aUid, size, *maskedBmp ) );
   223         
   226 
   224         // handle bitmap
   227         // handle bitmap
   225         iBitmap = new ( ELeave ) CFbsBitmap;       
   228         iBitmap = new ( ELeave ) CFbsBitmap;
   226         CopyBitmapL( *iBitmap, *maskedBmp );
   229         if ( aForceScale )
       
   230             {
       
   231             // copy and scale
       
   232             TRect scaledRect = TRect( iSize );
       
   233             iBitmap->Create( scaledRect.Size(), maskedBmp->DisplayMode() );
       
   234             CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( iBitmap );
       
   235             CleanupStack::PushL( bitmapDevice );
       
   236             CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
       
   237             CleanupStack::PushL( bitmapGc );
       
   238             bitmapGc->Activate( bitmapDevice );
       
   239             bitmapGc->DrawBitmap( scaledRect, maskedBmp );
       
   240             CleanupStack::PopAndDestroy( bitmapGc );
       
   241             CleanupStack::PopAndDestroy( bitmapDevice );
       
   242             }
       
   243         else
       
   244             {
       
   245             CopyBitmapL( *iBitmap, *maskedBmp );
       
   246             }
   227         
   247         
   228         // handle mask
   248         // handle mask
   229         if ( maskedBmp->Mask() )
   249         if ( maskedBmp->Mask() )
   230             {
   250             {
   231             iMask = new ( ELeave ) CFbsBitmap;
   251             iMask = new ( ELeave ) CFbsBitmap;
   232             CopyBitmapL( *iMask, *maskedBmp->Mask() );
   252             if ( aForceScale )
       
   253                 {
       
   254                 TRect scaledRect = TRect( iSize );
       
   255                 iMask->Create( scaledRect.Size(), maskedBmp->Mask()->DisplayMode() );
       
   256                 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( iMask );
       
   257                 CleanupStack::PushL( bitmapDevice );
       
   258                 CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
       
   259                 CleanupStack::PushL( bitmapGc );
       
   260                 bitmapGc->Activate( bitmapDevice );
       
   261                 bitmapGc->DrawBitmap( scaledRect, maskedBmp->Mask() );
       
   262                 CleanupStack::PopAndDestroy( bitmapGc );
       
   263                 CleanupStack::PopAndDestroy( bitmapDevice );
       
   264                 }
       
   265             else
       
   266                 {
       
   267                 CopyBitmapL( *iMask, *maskedBmp->Mask() );
       
   268                 }
   233             }
   269             }
   234         
   270         
   235         // cleanup
   271         // cleanup
   236         CleanupStack::PopAndDestroy( maskedBmp );
   272         CleanupStack::PopAndDestroy( maskedBmp );
   237         CleanupStack::PopAndDestroy( sizeArray ); 
   273         CleanupStack::PopAndDestroy( sizeArray );
   238         CleanupStack::PopAndDestroy( &lsSession );
   274         CleanupStack::PopAndDestroy( &lsSession );
   239         }
   275         }
   240     else if ( aUid.iUid != KNullUid.iUid )
   276     else if ( aUid.iUid != KNullUid.iUid )
   241         {
   277         {
   242         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   278         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   337 
   373 
   338 // ---------------------------------------------------------
   374 // ---------------------------------------------------------
   339 // CWmImageConverter::CreateIconFromOtherL
   375 // CWmImageConverter::CreateIconFromOtherL
   340 // ---------------------------------------------------------
   376 // ---------------------------------------------------------
   341 //
   377 //
   342 void CWmImageConverter::CreateIconFromOtherL( const TDesC& aFileName )
   378 void CWmImageConverter::CreateIconFromOtherL( 
       
   379         const TDesC& aFileName, TBool aForceScale )
   343     {
   380     {
   344     if (iBitmap) {delete iBitmap; iBitmap = NULL;}
   381     if (iBitmap) {delete iBitmap; iBitmap = NULL;}
   345     if (iMask) {delete iMask; iMask = NULL;}
   382     if (iMask) {delete iMask; iMask = NULL;}
   346     
   383     
   347     iFilename.Copy( aFileName );
   384     iFilename.Copy( aFileName );
   370         imageDecoder->ContinueConvert( &status );
   407         imageDecoder->ContinueConvert( &status );
   371         User::WaitForRequest( status );
   408         User::WaitForRequest( status );
   372         }
   409         }
   373     User::LeaveIfError( status.Int() );    
   410     User::LeaveIfError( status.Int() );    
   374     CleanupStack::PopAndDestroy( imageDecoder );
   411     CleanupStack::PopAndDestroy( imageDecoder );
       
   412     
       
   413     // do scaling
       
   414     if ( aForceScale )
       
   415         {
       
   416         // scale bitmap
       
   417         TRect scaledRect = TRect( iSize );
       
   418         CFbsBitmap* scaledBitmap = new (ELeave) CFbsBitmap();
       
   419         CleanupStack::PushL( scaledBitmap );
       
   420         User::LeaveIfError( 
       
   421                 scaledBitmap->Create( scaledRect.Size(), iBitmap->DisplayMode() ) );
       
   422         CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( scaledBitmap );
       
   423         CleanupStack::PushL( bitmapDevice );
       
   424         CFbsBitGc* bitmapGc = CFbsBitGc::NewL();
       
   425         CleanupStack::PushL( bitmapGc );
       
   426         bitmapGc->Activate( bitmapDevice );
       
   427         bitmapGc->DrawBitmap( scaledRect, iBitmap );
       
   428         CleanupStack::PopAndDestroy( bitmapGc );
       
   429         CleanupStack::PopAndDestroy( bitmapDevice );
       
   430         CleanupStack::Pop( scaledBitmap );
       
   431         // take ownership of scaled bitmap
       
   432         delete iBitmap; iBitmap = NULL;
       
   433         iBitmap = scaledBitmap; scaledBitmap = NULL;
       
   434         
       
   435         // scale mask
       
   436         CFbsBitmap* scaledMask = new (ELeave) CFbsBitmap();
       
   437         CleanupStack::PushL( scaledMask );
       
   438         User::LeaveIfError( 
       
   439                 scaledMask->Create( scaledRect.Size(), iMask->DisplayMode() ) );
       
   440         bitmapDevice = CFbsBitmapDevice::NewL( scaledMask );
       
   441         CleanupStack::PushL( bitmapDevice );
       
   442         bitmapGc = CFbsBitGc::NewL();
       
   443         CleanupStack::PushL( bitmapGc );
       
   444         bitmapGc->Activate( bitmapDevice );
       
   445         bitmapGc->DrawBitmap( scaledRect, iMask );
       
   446         CleanupStack::PopAndDestroy( bitmapGc );
       
   447         CleanupStack::PopAndDestroy( bitmapDevice );
       
   448         CleanupStack::Pop( scaledMask );
       
   449         // take ownership of scaled bitmap
       
   450         delete iMask; iMask = NULL;
       
   451         iMask = scaledMask; scaledMask = NULL;        
       
   452         }    
   375     }
   453     }
   376 
   454 
   377 // ---------------------------------------------------------------------------
   455 // ---------------------------------------------------------------------------
   378 // CWmImageConverter::CreateSkinOrMifIconL
   456 // CWmImageConverter::CreateSkinOrMifIconL
   379 // ---------------------------------------------------------------------------
   457 // ---------------------------------------------------------------------------
   506 // ---------------------------------------------------------------------------
   584 // ---------------------------------------------------------------------------
   507 // CWmImageConverter::ResolveUid
   585 // CWmImageConverter::ResolveUid
   508 // ---------------------------------------------------------------------------
   586 // ---------------------------------------------------------------------------
   509 //
   587 //
   510 TBool CWmImageConverter::ResolveUid( 
   588 TBool CWmImageConverter::ResolveUid( 
   511                 const TDesC& aPath, TUid& aUid )
   589                 const TDesC& aStr, TUid& aUid )
   512     {
   590     {
   513     // Syntax: uid(0x12345678)
   591     // Syntax: uid(0x12345678)
   514     TInt error = KErrNotFound;
   592     TInt error = KErrNotFound;
   515     TInt pos = aPath.FindF( KUid );
   593     TInt pos = aStr.FindF( KUid );
   516     if( pos == 0 )
   594     if( pos == 0 )
   517         {
   595         {
   518         // Skip uid token
   596         // Skip uid token
   519         pos += KUid().Length();
   597         pos += KUid().Length();
   520 
   598 
   521         // Initialize lexer
   599         // Initialize lexer
   522         TLex lex( aPath.Mid( pos ) );
   600         TLex lex( aStr.Mid( pos ) );
   523         lex.SkipSpaceAndMark();
   601         lex.SkipSpaceAndMark();
   524         
   602         
   525         // Check left parenthesis
   603         // Check left parenthesis
   526         if ( lex.Get() == KLeftParenthesis )
   604         if ( lex.Get() == KLeftParenthesis )
   527             {
   605             {
   535 // ---------------------------------------------------------------------------
   613 // ---------------------------------------------------------------------------
   536 // CWmImageConverter::ResolveSkinId
   614 // CWmImageConverter::ResolveSkinId
   537 // ---------------------------------------------------------------------------
   615 // ---------------------------------------------------------------------------
   538 //
   616 //
   539 TBool CWmImageConverter::ResolveSkinId( 
   617 TBool CWmImageConverter::ResolveSkinId( 
   540                 const TDesC& aPath, TAknsItemID& aItemId )
   618                 const TDesC& aStr, TAknsItemID& aItemId )
   541     {
   619     {
   542     // Syntax: skin(major minor)
   620     // Syntax: skin(major minor)
       
   621     aItemId = KAknsIIDNone;
   543     TInt error = KErrNotFound;
   622     TInt error = KErrNotFound;
   544     TInt pos = aPath.FindF( KSkin );
   623     TInt pos = aStr.FindF( KSkin );
   545     if( pos == 0 )
   624     if( pos == 0 )
   546         {
   625         {
   547         // Skip skin token
   626         // Skip skin token
   548         pos += KSkin().Length();
   627         pos += KSkin().Length();
   549 
   628 
   550         // Initialize lexer
   629         // Initialize lexer
   551         TLex lex( aPath.Mid( pos ) );
   630         TLex lex( aStr.Mid( pos ) );
   552         lex.SkipSpaceAndMark();
   631         lex.SkipSpaceAndMark();
   553         
   632         
   554         // Check left parenthesis
   633         // Check left parenthesis
   555         if ( lex.Get() == KLeftParenthesis )
   634         if ( lex.Get() == KLeftParenthesis )
   556            {
   635            {
   568 // ---------------------------------------------------------------------------
   647 // ---------------------------------------------------------------------------
   569 // CWmImageConverter::ResolveMifId
   648 // CWmImageConverter::ResolveMifId
   570 // ---------------------------------------------------------------------------
   649 // ---------------------------------------------------------------------------
   571 //
   650 //
   572 TBool CWmImageConverter::ResolveMifId( 
   651 TBool CWmImageConverter::ResolveMifId( 
   573                 const TDesC& aPath, TInt& aBitmapId,
   652                 const TDesC& aStr, TInt& aBitmapId,
   574                 TInt& aMaskId, TDes& aFileName )
   653                 TInt& aMaskId, TDes& aFileName )
   575     {
   654     {
   576     // Syntax: mif(filename bimapId maskId)
   655     // Syntax: mif(filename bimapId maskId)
       
   656    aBitmapId = KErrNotFound;
       
   657    aMaskId = KErrNotFound;
       
   658    aFileName.Copy( KNullDesC );
       
   659    
   577    TInt error = KErrNotFound;
   660    TInt error = KErrNotFound;
   578    TInt pos = aPath.FindF( KMif );
   661    TInt pos = aStr.FindF( KMif );
   579    if( pos == 0 )
   662    if( pos == 0 )
   580         {
   663         {
   581         // Skip mif token
   664         // Skip mif token
   582         pos += KMif().Length();
   665         pos += KMif().Length();
   583         // Initialize lexer
   666         // Initialize lexer
   584         TLex lex( aPath.Mid( pos ) );
   667         TLex lex( aStr.Mid( pos ) );
   585         lex.SkipSpaceAndMark();
   668         lex.SkipSpaceAndMark();
   586         
   669         
   587         // Check left parenthesis
   670         // Check left parenthesis
   588         if ( lex.Get() == KLeftParenthesis )
   671         if ( lex.Get() == KLeftParenthesis )
   589            {
   672            {
   607 // ---------------------------------------------------------------------------
   690 // ---------------------------------------------------------------------------
   608 // CWmImageConverter::ResolveSkinIdAndMifId
   691 // CWmImageConverter::ResolveSkinIdAndMifId
   609 // ---------------------------------------------------------------------------
   692 // ---------------------------------------------------------------------------
   610 //
   693 //
   611 TBool CWmImageConverter::ResolveSkinIdAndMifId( 
   694 TBool CWmImageConverter::ResolveSkinIdAndMifId( 
   612                 const TDesC& aPath, TAknsItemID& aItemId,
   695                 const TDesC& aStr, TAknsItemID& aItemId,
   613                 TInt& aBitmapId, TInt& aMaskId, TDes& aFileName )
   696                 TInt& aBitmapId, TInt& aMaskId, TDes& aFileName )
   614    {
   697    {
   615    // Syntax: skin(major minor):mif(filename bimapId maskId) 
   698    // Syntax: skin(major minor):mif(filename bimapId maskId) 
   616    TBool result = ResolveSkinId( aPath, aItemId );
   699    TBool result = ResolveSkinId( aStr, aItemId );
   617    if ( result )
   700    if ( result )
   618 	   {
   701 	   {
   619 	   TInt pos = aPath.FindF( KColon );
   702 	   TInt pos = aStr.FindF( KColon );
   620 	   if ( pos != KErrNotFound )
   703 	   if ( pos != KErrNotFound )
   621 	       {
   704 	       {
   622 	       TPtrC ptr = aPath.Mid( pos+1 );
   705 	       TPtrC ptr = aStr.Mid( pos+1 );
   623 	       result = ResolveMifId( ptr, aBitmapId, aMaskId, aFileName );
   706 	       result = ResolveMifId( ptr, aBitmapId, aMaskId, aFileName );
   624 	       }
   707 	       }
   625 	   }
   708 	   }
   626    else
   709    else
   627        {
   710        {
   628        result = ResolveMifId( aPath, aBitmapId, aMaskId, aFileName );
   711        result = ResolveMifId( aStr, aBitmapId, aMaskId, aFileName );
   629        }
   712        }
   630    return result;
   713    return result;
   631    }
   714    }
   632 
   715 
   633 // ---------------------------------------------------------------------------
   716 // ---------------------------------------------------------------------------
   746                 }            
   829                 }            
   747             }
   830             }
   748         }
   831         }
   749     }
   832     }
   750 
   833 
       
   834 // ---------------------------------------------------------------------------
       
   835 // CWmImageConverter::ParseIconString
       
   836 // ---------------------------------------------------------------------------
       
   837 //
       
   838 TBool CWmImageConverter::ParseIconString( 
       
   839         const TDesC& aIconStr, 
       
   840         TAknsItemID& aItemId,
       
   841         TInt& aBitmapId, 
       
   842         TInt& aMaskId, 
       
   843         TDes& aFileName )
       
   844     {
       
   845     return ResolveSkinIdAndMifId( 
       
   846             aIconStr, aItemId, aBitmapId, aMaskId, aFileName );
       
   847     }
       
   848 
   751 // End of file
   849 // End of file
   752 
   850