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