idlehomescreen/xmluirendering/uiengine/src/xncontroladapterimpl.cpp
branchRCL_3
changeset 23 7be2816dbabd
parent 18 d05a55b217df
child 25 137ebc85284b
equal deleted inserted replaced
19:79311d856354 23:7be2816dbabd
  3293     CleanupStack::Pop( node );
  3293     CleanupStack::Pop( node );
  3294     return node;
  3294     return node;
  3295     }
  3295     }
  3296 
  3296 
  3297 // -----------------------------------------------------------------------------
  3297 // -----------------------------------------------------------------------------
  3298 // Create scaled bitmap from source bitmap.
       
  3299 // -----------------------------------------------------------------------------
       
  3300 //
       
  3301 void CreateScaledBitmapL(
       
  3302     const TRect& aRect,
       
  3303     CFbsBitmap*& aTrgBitmap,
       
  3304     CFbsBitmap* aSrcBitmap,
       
  3305     TBool aPreserveAspectRatio,
       
  3306     TBool aForceFallBack )
       
  3307     {
       
  3308     TRect destRect = aRect;
       
  3309 
       
  3310     if ( aPreserveAspectRatio )
       
  3311         {
       
  3312         // Calculate the bitmap image dimensions so that it uses maximum space
       
  3313         // of the given rectangle and maintains aspect ratio.
       
  3314         TInt srcHeight = aSrcBitmap->SizeInPixels().iHeight;
       
  3315         TInt srcWidth = aSrcBitmap->SizeInPixels().iWidth;
       
  3316         TReal scaleRatio( 1 ); //no scale as defaul
       
  3317 
       
  3318         //If any dimension is 0, then we do not bother to scale
       
  3319         if ( aRect.Width() > 0 && aRect.Height() > 0 )
       
  3320             {
       
  3321             TReal xRatio = ( ( TReal )srcWidth / ( TReal )aRect.Width() );
       
  3322             TReal yRatio = ( ( TReal )srcHeight / ( TReal )aRect.Height() );
       
  3323             //Find out appropriate scaling factor
       
  3324             xRatio > yRatio ? ( scaleRatio = xRatio ) : ( scaleRatio = yRatio );
       
  3325             }
       
  3326 
       
  3327         //Scale the size for target bitmap
       
  3328         destRect.SetHeight( srcHeight / scaleRatio );
       
  3329         destRect.SetWidth( srcWidth / scaleRatio );
       
  3330         }
       
  3331 
       
  3332     // see if there's a need to scale. If source and destination size are the same,
       
  3333     // then we don't need to duplicate the bitmap. aTrgBitmap will be null.
       
  3334     TSize srcSize = aSrcBitmap->SizeInPixels();
       
  3335     TSize destSize = destRect.Size();
       
  3336     if ( srcSize == destSize )
       
  3337         {
       
  3338         return;
       
  3339         }
       
  3340 
       
  3341     aTrgBitmap = new ( ELeave ) CFbsBitmap;
       
  3342     CleanupStack::PushL( aTrgBitmap );
       
  3343     //It is allowed to create zero height or width bitmap.
       
  3344     TInt err( aTrgBitmap->Create( destRect.Size(), aSrcBitmap->DisplayMode() ) );
       
  3345 
       
  3346     if ( err == KErrNone )
       
  3347         {
       
  3348         CXnUtils::ScaleBitmapExtL( destRect, aTrgBitmap, aSrcBitmap, aForceFallBack );
       
  3349         }
       
  3350 
       
  3351     //we do not own the bitmap so just Pop.
       
  3352     CleanupStack::Pop( aTrgBitmap );
       
  3353     }
       
  3354 
       
  3355 // -----------------------------------------------------------------------------
       
  3356 // SoftkeyNode
  3298 // SoftkeyNode
  3357 // Gets the node of softkey according to pointer location
  3299 // Gets the node of softkey according to pointer location
  3358 // -----------------------------------------------------------------------------
  3300 // -----------------------------------------------------------------------------
  3359 //
  3301 //
  3360 static CXnNode* SoftkeyNode( CXnNode* aMenuBarNode, const TPoint aPosition )
  3302 static CXnNode* SoftkeyNode( CXnNode* aMenuBarNode, const TPoint aPosition )
  3598     delete iBackgroundMask;
  3540     delete iBackgroundMask;
  3599     delete iBorderBitmap;
  3541     delete iBorderBitmap;
  3600     delete iContentBitmap;
  3542     delete iContentBitmap;
  3601     delete iContentMask;
  3543     delete iContentMask;
  3602 
  3544 
  3603     delete iScaledContentBitmap;
       
  3604     delete iScaledContentMask;
       
  3605 
       
  3606     delete iScaledTransparentColor;
       
  3607     delete iScaledBackgroundSkin;
       
  3608     delete iScaledBackgroundImage;
       
  3609 
       
  3610     iChildren.Reset();
  3545     iChildren.Reset();
  3611 
  3546 
  3612     if ( iAnimation )
  3547     if ( iAnimation )
  3613         {
  3548         {
  3614         iAnimation->Stop();
  3549         iAnimation->Stop();
  3622 // CXnControlAdapterImpl::CXnControlAdapterImpl
  3557 // CXnControlAdapterImpl::CXnControlAdapterImpl
  3623 // C++ default constructor. Must not leave.
  3558 // C++ default constructor. Must not leave.
  3624 // -----------------------------------------------------------------------------
  3559 // -----------------------------------------------------------------------------
  3625 //
  3560 //
  3626 CXnControlAdapterImpl::CXnControlAdapterImpl( CXnNodePluginIf& aNode )
  3561 CXnControlAdapterImpl::CXnControlAdapterImpl( CXnNodePluginIf& aNode )
  3627     : iNode( aNode )
  3562     : iNode( aNode ), 
       
  3563       iBackgrondInitialized ( EFalse ),
       
  3564       iBorderInitialized ( EFalse )
  3628     {
  3565     {
  3629     }
  3566     }
  3630 
  3567 
  3631 // -----------------------------------------------------------------------------
  3568 // -----------------------------------------------------------------------------
  3632 // CXnControlAdapterImpl::SetComponent
  3569 // CXnControlAdapterImpl::SetComponent
  3703         return EKeyWasNotConsumed;
  3640         return EKeyWasNotConsumed;
  3704         }
  3641         }
  3705 
  3642 
  3706     if ( aKeyEvent.iScanCode == EStdKeyDevice0 || // RSK
  3643     if ( aKeyEvent.iScanCode == EStdKeyDevice0 || // RSK
  3707          aKeyEvent.iScanCode == EStdKeyDevice1 || // LSK
  3644          aKeyEvent.iScanCode == EStdKeyDevice1 || // LSK
  3708          aKeyEvent.iScanCode == EStdKeyDevice3 )  // MSK
  3645          aKeyEvent.iScanCode == EStdKeyDevice3 || // MSK
       
  3646          aKeyEvent.iCode == EKeyEnter )
  3709         {
  3647         {
  3710         if ( aType == EEventKeyDown )
  3648         if ( aType == EEventKeyDown )
  3711             {            
  3649             {            
  3712             iLongtap = EFalse;
  3650             iLongtap = EFalse;
  3713             
  3651             
  3714             if ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
  3652             if ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
  3715                 aKeyEvent.iScanCode == EStdKeyEnter )
  3653                  aKeyEvent.iCode == EKeyEnter )
  3716                 {
  3654                 {
  3717                 if ( node->IsStateSet( XnPropertyNames::style::common::KFocus ) )
  3655                 if ( node->IsStateSet( XnPropertyNames::style::common::KFocus ) )
  3718                     {
  3656                     {
  3719                     // Set "pressed down"
  3657                     // Set "pressed down"
  3720                     node->SetStateL( 
  3658                     node->SetStateL( 
  3785                     CleanupStack::PopAndDestroy( keyup );                    
  3723                     CleanupStack::PopAndDestroy( keyup );                    
  3786                     }
  3724                     }
  3787                 }
  3725                 }
  3788             
  3726             
  3789             if ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
  3727             if ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
  3790                 aKeyEvent.iScanCode == EStdKeyEnter )
  3728                  aKeyEvent.iCode == EKeyEnter )
  3791                 {
  3729                 {
  3792                 // Reset "pressed down"
  3730                 // Reset "pressed down"
  3793                 node->UnsetStateL( 
  3731                 node->UnsetStateL( 
  3794                     XnPropertyNames::style::common::KPressedDown );
  3732                     XnPropertyNames::style::common::KPressedDown );
  3795                 
  3733                 
  4196         CXnDomPropertyValue* value =
  4134         CXnDomPropertyValue* value =
  4197             static_cast< CXnDomPropertyValue* >(
  4135             static_cast< CXnDomPropertyValue* >(
  4198                 colorProperty->Property()->PropertyValueList().Item( 0 ) );
  4136                 colorProperty->Property()->PropertyValueList().Item( 0 ) );
  4199 
  4137 
  4200         if ( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
  4138         if ( value->PrimitiveValueType() == CXnDomPropertyValue::ERgbColor )
  4201             {
  4139             {            
  4202 	        TRect paddingRect = aNode.PaddingRect();    
  4140             CFbsBitmap* bitmap( NULL );
  4203             aMask->SetDisplayMode( EGray256 );
  4141             TRgb rgb( value->RgbColorValueL() );
  4204 
  4142             bitmap = CreateBitmapFromColorL( aMask->SizeInPixels(), rgb );
  4205             aGc.SetBrushColor( NULL );
  4143             
  4206             aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  4144             aGc.DrawBitmapMasked( 
  4207 
  4145                 aNode.PaddingRect(),
  4208             if ( !iScaledTransparentColor )
  4146                 bitmap,
  4209                 {
  4147                 TRect( TPoint( 0, 0 ), bitmap->SizeInPixels() ),
  4210                 CFbsBitmap* bitmap( NULL );
  4148                 aMask,
  4211                 CFbsBitmap* mask( NULL );
       
  4212 
       
  4213                 mask = new ( ELeave ) CFbsBitmap;
       
  4214                 CleanupStack::PushL( mask );
       
  4215 
       
  4216                 mask->Create( paddingRect.Size(), EGray256 );
       
  4217 
       
  4218                 CXnUtils::ScaleBitmapL(
       
  4219                     TRect( 0, 0, paddingRect.Width(), paddingRect.Height() ),
       
  4220                     mask, aMask );
       
  4221 
       
  4222                 CXnDomPropertyValue* value =
       
  4223                     static_cast< CXnDomPropertyValue* >(
       
  4224                         colorProperty->Property()->PropertyValueList().Item( 0 ) );
       
  4225 
       
  4226                 TRgb rgb( value->RgbColorValueL() );
       
  4227 
       
  4228                 bitmap = CreateBitmapFromColorL( paddingRect.Size(), rgb );
       
  4229                 CleanupStack::PushL( bitmap );
       
  4230 
       
  4231                 iScaledTransparentColor = CGulIcon::NewL( bitmap, mask );
       
  4232 
       
  4233                 CleanupStack::Pop( 2 );
       
  4234                 }
       
  4235 
       
  4236             aGc.DrawBitmapMasked( paddingRect,
       
  4237                 iScaledTransparentColor->Bitmap(),
       
  4238                 TRect( TPoint( 0, 0 ), paddingRect.Size() ),
       
  4239                 iScaledTransparentColor->Mask(),
       
  4240                 EFalse );
  4149                 EFalse );
  4241             }
  4150             
  4242         }
  4151             delete bitmap;
  4243     }
  4152             }
  4244 
  4153         }
  4245 // -----------------------------------------------------------------------------
  4154     }
  4246 // CXnControlAdapterImpl::DrawBackgroundSkinL
  4155 
       
  4156 // -----------------------------------------------------------------------------
       
  4157 // CXnControlAdapterImpl::DrawBackgroundSkin
  4247 // Draws a skin item to the given rect
  4158 // Draws a skin item to the given rect
  4248 // -----------------------------------------------------------------------------
  4159 // -----------------------------------------------------------------------------
  4249 //
  4160 //
  4250 void CXnControlAdapterImpl::DrawBackgroundSkin(const TAknsItemID& aSkinId, 
  4161 void CXnControlAdapterImpl::DrawBackgroundSkin(const TAknsItemID& aSkinId, 
  4251     CWindowGc& aGc, TRect aRect)
  4162     CWindowGc& aGc, TRect aRect)
  4293                     TRect outerRect = TRect( paddingRect.Size() );
  4204                     TRect outerRect = TRect( paddingRect.Size() );
  4294                     TRect innerRect = outerRect;
  4205                     TRect innerRect = outerRect;
  4295                     innerRect.Shrink(
  4206                     innerRect.Shrink(
  4296                         KSkinGfxInnerRectShrink,
  4207                         KSkinGfxInnerRectShrink,
  4297                         KSkinGfxInnerRectShrink );
  4208                         KSkinGfxInnerRectShrink );
  4298 
  4209                     
  4299                     if ( !iScaledBackgroundSkin )
  4210                     if ( !iBackgroundBitmap )
  4300                         {
  4211                         {
  4301                         CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
  4212                         iBackgroundBitmap = new ( ELeave ) CFbsBitmap;
  4302                         CleanupStack::PushL( bitmap );
  4213                         iBackgroundBitmap->Create( aMask->SizeInPixels(), 
  4303 
  4214                                 aGc.Device()->DisplayMode() );
  4304                         CFbsBitmap* mask = new ( ELeave ) CFbsBitmap;
  4215                         
  4305                         CleanupStack::PushL( mask );
  4216                         CFbsBitmapDevice* device = 
  4306 
  4217                                 CFbsBitmapDevice::NewL( iBackgroundBitmap );
  4307                         bitmap->Create( outerRect.Size(), aGc.Device()->DisplayMode() );
       
  4308 
       
  4309                         CFbsBitmapDevice* device = CFbsBitmapDevice::NewL( bitmap );
       
  4310                         CleanupStack::PushL( device );
  4218                         CleanupStack::PushL( device );
  4311 
  4219 
  4312                         CBitmapContext* bc( NULL );
  4220                         CBitmapContext* bc( NULL );
  4313 
  4221 
  4314                         User::LeaveIfError( device->CreateBitmapContext( bc ) );
  4222                         User::LeaveIfError( device->CreateBitmapContext( bc ) );
  4321 
  4229 
  4322                         AknsDrawUtils::Background( AknsUtils::SkinInstance(),
  4230                         AknsDrawUtils::Background( AknsUtils::SkinInstance(),
  4323                             frameContext, NULL,
  4231                             frameContext, NULL,
  4324                             static_cast< CWindowGc& >( *bc ),
  4232                             static_cast< CWindowGc& >( *bc ),
  4325                             outerRect, KAknsDrawParamNoClearUnderImage );
  4233                             outerRect, KAknsDrawParamNoClearUnderImage );
  4326 
  4234                         
  4327                         aMask->SetDisplayMode( EGray256 );
  4235                         CleanupStack::PopAndDestroy( 3, device );
  4328 
       
  4329                         aGc.SetBrushColor( NULL );
       
  4330                         aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
       
  4331 
       
  4332                         mask->Create( paddingRect.Size(), EGray256 );
       
  4333 
       
  4334                         CXnUtils::ScaleBitmapL( outerRect, mask, aMask );
       
  4335 
       
  4336                         CleanupStack::PopAndDestroy( 3 );
       
  4337 
       
  4338                         iScaledBackgroundSkin = CGulIcon::NewL( bitmap, mask );
       
  4339 
       
  4340                         CleanupStack::Pop( 2 );
       
  4341                         }
  4236                         }
  4342 
  4237 
  4343                     CFbsBitmap* bitmap( iScaledBackgroundSkin->Bitmap() );
  4238                     aGc.DrawBitmapMasked( paddingRect, 
  4344                     CFbsBitmap* mask( iScaledBackgroundSkin->Mask() );
  4239                         iBackgroundBitmap, 
  4345 
  4240                         TRect(TPoint(0, 0), iBackgroundBitmap->SizeInPixels()), 
  4346                     aGc.BitBltMasked( paddingRect.iTl, bitmap, outerRect, mask, ETrue );
  4241                         aMask, 
       
  4242                         ETrue );
  4347                     }
  4243                     }
  4348                 else // draw background skin graphics without mask
  4244                 else // draw background skin graphics without mask
  4349                     {
  4245                     {
  4350 	                TRect paddingRect = aRect;
  4246 	                TRect paddingRect = aRect;
  4351                     TRect shrunkRect = paddingRect;
  4247                     TRect shrunkRect = paddingRect;
  4474                 rect.iTl.iX + imageRect.Width(),
  4370                 rect.iTl.iX + imageRect.Width(),
  4475                 rect.iTl.iY + imageRect.Height() ) );
  4371                 rect.iTl.iY + imageRect.Height() ) );
  4476         aGc.SetClippingRect( aRect );
  4372         aGc.SetClippingRect( aRect );
  4477 
  4373 
  4478         if ( aMask )
  4374         if ( aMask )
  4479             {
  4375             {           
  4480             aMask->SetDisplayMode( EGray256 );
  4376             aGc.DrawBitmapMasked( newRect, 
  4481 
  4377                 aBitmap, 
  4482             aGc.SetBrushColor( NULL );
  4378                 TRect(TPoint(0, 0), aBitmap->SizeInPixels()), 
  4483             aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  4379                 aMask, 
  4484 
  4380                 EFalse );
  4485             if ( !iScaledBackgroundImage )
       
  4486                 {
       
  4487                 CFbsBitmap* mask( NULL );
       
  4488 
       
  4489                 mask = new ( ELeave ) CFbsBitmap;
       
  4490                 CleanupStack::PushL( mask );
       
  4491 
       
  4492                 mask->Create( bitmapRect.Size(), EGray256 );
       
  4493 
       
  4494                 CXnUtils::ScaleBitmapL(
       
  4495                     TRect(
       
  4496                         0,
       
  4497                         0,
       
  4498                         bitmapRect.Width(),
       
  4499                         bitmapRect.Height() ),
       
  4500                     mask,
       
  4501                     aMask );
       
  4502 
       
  4503                 iScaledBackgroundImage = mask;
       
  4504 
       
  4505                 CleanupStack::Pop( mask );
       
  4506                 }
       
  4507 
       
  4508             aGc.DrawBitmapMasked( newRect, aBitmap, bitmapRect,
       
  4509                 iScaledBackgroundImage, EFalse );
       
  4510             }
  4381             }
  4511         else
  4382         else
  4512             {
  4383             {
  4513             TRect newRect = TRect(
  4384             TRect newRect = TRect(
  4514                 rect.iTl,
  4385                 rect.iTl,
  4982     iContentBitmap = NULL;
  4853     iContentBitmap = NULL;
  4983 
  4854 
  4984     delete iContentMask;
  4855     delete iContentMask;
  4985     iContentMask = NULL;
  4856     iContentMask = NULL;
  4986 
  4857 
  4987     delete iScaledContentBitmap;
       
  4988     iScaledContentBitmap = NULL;
       
  4989 
       
  4990     delete iScaledContentMask;
       
  4991     iScaledContentMask = NULL;
       
  4992 
       
  4993     iContentBitmap = aBitmap;
  4858     iContentBitmap = aBitmap;
  4994     iContentMask = aMask;
  4859     iContentMask = aMask;
  4995     }
  4860     }
  4996 
  4861 
  4997 // -----------------------------------------------------------------------------
  4862 // -----------------------------------------------------------------------------
  5005     delete iContentBitmap;
  4870     delete iContentBitmap;
  5006     iContentBitmap = NULL;
  4871     iContentBitmap = NULL;
  5007 
  4872 
  5008     delete iContentMask;
  4873     delete iContentMask;
  5009     iContentMask = NULL;
  4874     iContentMask = NULL;
  5010 
       
  5011     delete iScaledContentBitmap;
       
  5012     iScaledContentBitmap = NULL;
       
  5013 
       
  5014     delete iScaledContentMask;
       
  5015     iScaledContentMask = NULL;
       
  5016 
  4875 
  5017     CXnNode& node( iNode.Node() );
  4876     CXnNode& node( iNode.Node() );
  5018     CXnUiEngine* engine( node.UiEngine() );
  4877     CXnUiEngine* engine( node.UiEngine() );
  5019 
  4878 
  5020     TRect rect( node.Rect() );
  4879     TRect rect( node.Rect() );
  5081         }
  4940         }
  5082 
  4941 
  5083     TRect rect = iComponent->Node()->Node().Rect();
  4942     TRect rect = iComponent->Node()->Node().Rect();
  5084 
  4943 
  5085     // Check if the node has a property "preserve image aspect ratio".
  4944     // Check if the node has a property "preserve image aspect ratio".
  5086     TBool preserveAspectRatio = EFalse;
  4945     TBool preserveAspectRatio = ETrue;
  5087     CXnNode& currentNode = iComponent->Node()->Node();
  4946     CXnNode& currentNode = iComponent->Node()->Node();
  5088 
  4947 
  5089     CXnProperty* aspectProperty = currentNode.GetPropertyL(
  4948     CXnProperty* aspectProperty = currentNode.GetPropertyL(
  5090         XnPropertyNames::image::KS60AspectRatio );
  4949         XnPropertyNames::image::KS60AspectRatio );
  5091     if ( aspectProperty )
  4950     if ( aspectProperty )
  5092         {
  4951         {
  5093         const TDesC8& value = aspectProperty->StringValue();
  4952         const TDesC8& value = aspectProperty->StringValue();
  5094 
  4953 
  5095         if ( value.CompareF( XnPropertyNames::image::KPreserve ) == 0 )
  4954         if ( value.CompareF( XnPropertyNames::image::KNone ) == 0 )
  5096             {
  4955             {
  5097             preserveAspectRatio = ETrue;
  4956             preserveAspectRatio = EFalse;
  5098             }
  4957             }
  5099         }
  4958         }
  5100 
  4959 
  5101     TRect bitmapRect = rect;
  4960     TRect bitmapRect = rect;
  5102     bitmapRect.Move( -rect.iTl.iX, -rect.iTl.iY );
  4961     bitmapRect.Move( -rect.iTl.iX, -rect.iTl.iY );
  5103 
       
  5104     if ( AknIconUtils::IsMifIcon( iContentBitmap ) )
  4962     if ( AknIconUtils::IsMifIcon( iContentBitmap ) )
  5105         {
  4963         {
  5106         if ( preserveAspectRatio )
  4964         if ( preserveAspectRatio )
  5107             {
  4965             {
  5108             AknIconUtils::SetSize(
  4966             AknIconUtils::SetSize(
  5109                 iContentBitmap, bitmapRect.Size(), EAspectRatioPreserved );
  4967                 iContentBitmap, bitmapRect.Size(), EAspectRatioPreserved );
       
  4968             AknIconUtils::SetSize(
       
  4969                 iContentMask, bitmapRect.Size(), EAspectRatioPreserved );
  5110             }
  4970             }
  5111         else
  4971         else
  5112             {
  4972             {
  5113             AknIconUtils::SetSize(
  4973             AknIconUtils::SetSize(
  5114                 iContentBitmap, bitmapRect.Size(), EAspectRatioNotPreserved );
  4974                 iContentBitmap, bitmapRect.Size(), EAspectRatioNotPreserved );
  5115             }
  4975             AknIconUtils::SetSize(
  5116         //Calculate new point to start draw in order to center bitmap to drawing area
  4976                 iContentMask, bitmapRect.Size(), EAspectRatioNotPreserved );
  5117         rect.iTl.iY +=
  4977             }
  5118             ( rect.Height() - iContentBitmap->SizeInPixels().iHeight ) / 2;
  4978         }
  5119         rect.iTl.iX +=
  4979     
  5120             ( rect.Width() - iContentBitmap->SizeInPixels().iWidth ) / 2;
  4980     // Calculate new point to start draw 
  5121 
  4981     // in order to center bitmap to drawing area
  5122         if ( iContentMask )
  4982     rect.iTl.iY +=
  5123             {
  4983         ( rect.Height() - bitmapRect.Height() ) / 2;
  5124             // Based on the avkon's assumtion that mask is always inverted, the
  4984     rect.iTl.iX +=
  5125             // value of aInvertMask parameter is set to 'ETrue'
  4985         ( rect.Width() - bitmapRect.Width() ) / 2;
  5126             aGc.BitBltMasked( rect.iTl, iContentBitmap, bitmapRect, iContentMask,
  4986     
  5127                 ETrue );
  4987     if ( iContentBitmap && iContentMask )
  5128             }
  4988         {
  5129         else
  4989         aGc.DrawBitmapMasked( rect, 
  5130             {
  4990             iContentBitmap, 
  5131             aGc.BitBlt( rect.iTl, iContentBitmap, bitmapRect );
  4991             TRect(TPoint(0, 0), iContentBitmap->SizeInPixels()), 
  5132             }
  4992             iContentMask, 
  5133         }
  4993             ETrue );
  5134     else
  4994         }
  5135         {
  4995     else if ( iContentBitmap )
  5136         if ( !iScaledContentBitmap )
  4996         {
  5137             {
  4997         aGc.DrawBitmap( rect, iContentBitmap );
  5138             TBool forceFallBack = CXnUtils::DoesScaleBitmapUseFallBack(
  4998         }
  5139                 iContentBitmap );
  4999     }
  5140 
       
  5141             TRAPD( err, CreateScaledBitmapL( bitmapRect,
       
  5142                 iScaledContentBitmap,
       
  5143                 iContentBitmap,
       
  5144                 preserveAspectRatio,
       
  5145                 forceFallBack ) );
       
  5146             if ( err )
       
  5147                 {
       
  5148                 // return if CreateScaledBitmapL() leaves. This prevents the
       
  5149                 // drawing of the original content bitmap which is wrong size.
       
  5150                 return;
       
  5151                 }
       
  5152             }
       
  5153         if ( iContentMask && !iScaledContentMask )
       
  5154             {
       
  5155             TBool forceFallBack = CXnUtils::DoesScaleBitmapUseFallBack(
       
  5156                 iContentMask );
       
  5157 
       
  5158             TRAPD( err, CreateScaledBitmapL( bitmapRect,
       
  5159                 iScaledContentMask,
       
  5160                 iContentMask,
       
  5161                 preserveAspectRatio,
       
  5162                 forceFallBack ) );
       
  5163             if ( err )
       
  5164                 {
       
  5165                 // return if CreateScaledBitmapL() leaves. This prevents the
       
  5166                 // drawing of the original content mask which is wrong size
       
  5167                 // (and may distort the image).
       
  5168                 return;
       
  5169                 }
       
  5170             }
       
  5171 
       
  5172         CFbsBitmap* bitmap( 0 );
       
  5173         CFbsBitmap* mask( 0 );
       
  5174 
       
  5175         if ( iScaledContentBitmap )
       
  5176             {
       
  5177             bitmap = iScaledContentBitmap;
       
  5178             }
       
  5179         else
       
  5180             {
       
  5181             bitmap = iContentBitmap;
       
  5182             }
       
  5183 
       
  5184         if ( iScaledContentMask )
       
  5185             {
       
  5186             mask = iScaledContentMask;
       
  5187             }
       
  5188         else
       
  5189             {
       
  5190             mask = iContentMask;
       
  5191             }
       
  5192 
       
  5193         if ( bitmap && mask )
       
  5194             {
       
  5195             //Calculate new point to start draw in order to center bitmap to
       
  5196             // drawing area
       
  5197             rect.iTl.iY +=
       
  5198                 ( rect.Height() - bitmap->SizeInPixels().iHeight ) / 2;
       
  5199             rect.iTl.iX +=
       
  5200                 ( rect.Width() - bitmap->SizeInPixels().iWidth ) / 2;
       
  5201 
       
  5202             // Based on the avkon's assumtion that mask is always inverted, the
       
  5203             // value of aInvertMask parameter is set to 'ETrue'
       
  5204             aGc.BitBltMasked( rect.iTl, bitmap, bitmapRect, mask, ETrue );
       
  5205             }
       
  5206         else if ( bitmap )
       
  5207             {
       
  5208             //Calculate new point to start draw in order to center bitmap to
       
  5209             // drawing area
       
  5210             rect.iTl.iY +=
       
  5211                 ( rect.Height() - bitmap->SizeInPixels().iHeight ) / 2;
       
  5212             rect.iTl.iX +=
       
  5213                 ( rect.Width() - bitmap->SizeInPixels().iWidth ) / 2;
       
  5214 
       
  5215             aGc.BitBlt( rect.iTl, bitmap );
       
  5216             }
       
  5217         }
       
  5218    }
       
  5219 
  5000 
  5220 // -----------------------------------------------------------------------------
  5001 // -----------------------------------------------------------------------------
  5221 // CXnControlAdapterImpl::SizeChanged
  5002 // CXnControlAdapterImpl::SizeChanged
  5222 // -----------------------------------------------------------------------------
  5003 // -----------------------------------------------------------------------------
  5223 //
  5004 //
  5224 void CXnControlAdapterImpl::SizeChanged()
  5005 void CXnControlAdapterImpl::SizeChanged()
  5225     {
  5006     {
  5226     delete iScaledContentBitmap;
       
  5227     iScaledContentBitmap = NULL;
       
  5228 
       
  5229     delete iScaledContentMask;
       
  5230     iScaledContentMask = NULL;
       
  5231 
       
  5232     delete iScaledTransparentColor;
       
  5233     iScaledTransparentColor = NULL;
       
  5234 
       
  5235     delete iScaledBackgroundSkin;
       
  5236     iScaledBackgroundSkin = NULL;
       
  5237 
       
  5238     delete iScaledBackgroundImage;
       
  5239     iScaledBackgroundImage = NULL;
       
  5240 
       
  5241     TRAP_IGNORE( InitializeBackgroundAndBorderBitmapsL() );
  5007     TRAP_IGNORE( InitializeBackgroundAndBorderBitmapsL() );
  5242     }
  5008     }
  5243 
  5009 
  5244 // -----------------------------------------------------------------------------
  5010 // -----------------------------------------------------------------------------
  5245 // CXnControlAdapterImpl::SkinChanged
  5011 // CXnControlAdapterImpl::SkinChanged
  5246 // -----------------------------------------------------------------------------
  5012 // -----------------------------------------------------------------------------
  5247 //
  5013 //
  5248 void CXnControlAdapterImpl::SkinChanged()
  5014 void CXnControlAdapterImpl::SkinChanged()
  5249     {
  5015     {
  5250     delete iScaledContentBitmap;
  5016     TRAP_IGNORE( InitializeBackgroundAndBorderBitmapsL( ETrue ) );
  5251     iScaledContentBitmap = NULL;
       
  5252 
       
  5253     delete iScaledContentMask;
       
  5254     iScaledContentMask = NULL;
       
  5255 
       
  5256     delete iScaledTransparentColor;
       
  5257     iScaledTransparentColor = NULL;
       
  5258 
       
  5259     delete iScaledBackgroundSkin;
       
  5260     iScaledBackgroundSkin = NULL;
       
  5261 
       
  5262     delete iScaledBackgroundImage;
       
  5263     iScaledBackgroundImage = NULL;
       
  5264 
       
  5265     TRAP_IGNORE( InitializeBackgroundAndBorderBitmapsL() );
       
  5266     }
  5017     }
  5267 
  5018 
  5268 // -----------------------------------------------------------------------------
  5019 // -----------------------------------------------------------------------------
  5269 // CXnControlAdapterImpl::FocusChangedL
  5020 // CXnControlAdapterImpl::FocusChangedL
  5270 // -----------------------------------------------------------------------------
  5021 // -----------------------------------------------------------------------------
  5396 
  5147 
  5397 // -----------------------------------------------------------------------------
  5148 // -----------------------------------------------------------------------------
  5398 // CXnControlAdapterImpl::InitializeBackgroundandBorderBitmapsL
  5149 // CXnControlAdapterImpl::InitializeBackgroundandBorderBitmapsL
  5399 // -----------------------------------------------------------------------------
  5150 // -----------------------------------------------------------------------------
  5400 //
  5151 //
  5401 void CXnControlAdapterImpl::InitializeBackgroundAndBorderBitmapsL()
  5152 void CXnControlAdapterImpl::InitializeBackgroundAndBorderBitmapsL(
       
  5153         TBool aForceRecreate )
  5402     {
  5154     {
  5403     CXnNode& node( iNode.Node() );
  5155     CXnNode& node( iNode.Node() );
  5404     CXnUiEngine* engine( node.UiEngine() );
  5156     CXnUiEngine* engine( node.UiEngine() );
  5405 
  5157 
  5406     CXnProperty* backgroundImageProperty( node.BackgroundImageL() );
  5158     CXnProperty* backgroundImageProperty( node.BackgroundImageL() );
  5407 
  5159 
  5408     if ( backgroundImageProperty )
  5160     // if skin changed we need recreate icons
       
  5161     if ( backgroundImageProperty && aForceRecreate )
       
  5162         {
       
  5163         iBackgrondInitialized = EFalse;
       
  5164         }
       
  5165     
       
  5166     if ( backgroundImageProperty && !iBackgrondInitialized )
  5409         {
  5167         {
  5410         delete iBackgroundBitmap;
  5168         delete iBackgroundBitmap;
  5411         iBackgroundBitmap = NULL;
  5169         iBackgroundBitmap = NULL;
  5412 
  5170 
  5413         delete iBackgroundMask;
  5171         delete iBackgroundMask;
  5414         iBackgroundMask = NULL;
  5172         iBackgroundMask = NULL;
  5415 
  5173 
  5416         delete iScaledTransparentColor;
       
  5417         iScaledTransparentColor = NULL;
       
  5418 
       
  5419         delete iScaledBackgroundSkin;
       
  5420         iScaledBackgroundSkin = NULL;
       
  5421 
       
  5422         delete iScaledBackgroundImage;
       
  5423         iScaledBackgroundImage = NULL;
       
  5424 
       
  5425         InitializeBackgroundBitmapL( *engine, node, iBackgroundBitmapIndex,
  5174         InitializeBackgroundBitmapL( *engine, node, iBackgroundBitmapIndex,
  5426             iBackgroundBitmap, iBackgroundMask, iIconProvider, FsSession() );
  5175             iBackgroundBitmap, iBackgroundMask, iIconProvider, FsSession() );
  5427 
  5176 
  5428         HBufC* bgPath( GetBackgroundImagePathLC( node ) );
  5177         HBufC* bgPath( GetBackgroundImagePathLC( node ) );
  5429 
  5178 
  5430         if ( *bgPath != KNullDesC )
  5179         if ( *bgPath != KNullDesC )
  5431             {
  5180             {
  5432             iAnimIDResolved = CXnUtils::ResolveSkinItemIDL( *bgPath, iAnimIID );
  5181             iAnimIDResolved = CXnUtils::ResolveSkinItemIDL( *bgPath, iAnimIID );
  5433             }
  5182             }
  5434 
       
  5435         CleanupStack::PopAndDestroy( bgPath );
  5183         CleanupStack::PopAndDestroy( bgPath );
       
  5184         iBackgrondInitialized = ETrue;
  5436         }
  5185         }
  5437 
  5186 
  5438     CXnProperty* borderImageProperty( node.BorderImageL() );
  5187     CXnProperty* borderImageProperty( node.BorderImageL() );
  5439 
  5188 
  5440     if ( borderImageProperty )
  5189     // if skin changed we need recreate icons
       
  5190     if ( borderImageProperty && aForceRecreate )
       
  5191         {
       
  5192         iBorderInitialized = EFalse;
       
  5193         }
       
  5194     
       
  5195     if ( borderImageProperty && !iBorderInitialized )
  5441         {
  5196         {
  5442         delete iBorderBitmap;
  5197         delete iBorderBitmap;
  5443         iBorderBitmap = NULL;
  5198         iBorderBitmap = NULL;
  5444 
  5199 
  5445         iBorderBitmap = InitializeBorderBitmapL(
  5200         iBorderBitmap = InitializeBorderBitmapL(
  5446             *engine, node,
  5201             *engine, node,
  5447             iBorderBitmapIndex, iBorderBitmapDividerTop,
  5202             iBorderBitmapIndex, iBorderBitmapDividerTop,
  5448             iBorderBitmapDividerRight,
  5203             iBorderBitmapDividerRight,
  5449             iBorderBitmapDividerBottom, iBorderBitmapDividerLeft,
  5204             iBorderBitmapDividerBottom, iBorderBitmapDividerLeft,
  5450             iIconProvider, FsSession() );
  5205             iIconProvider, FsSession() );
       
  5206         
       
  5207         iBorderInitialized = ETrue;
  5451         }
  5208         }
  5452     }
  5209     }
  5453 
  5210 
  5454 // -----------------------------------------------------------------------------
  5211 // -----------------------------------------------------------------------------
  5455 // CXnControlAdapterImpl::ConstructL
  5212 // CXnControlAdapterImpl::ConstructL
  5749             delete iBackgroundBitmap;
  5506             delete iBackgroundBitmap;
  5750             iBackgroundBitmap = NULL;
  5507             iBackgroundBitmap = NULL;
  5751 
  5508 
  5752             delete iBackgroundMask;
  5509             delete iBackgroundMask;
  5753             iBackgroundMask = NULL;
  5510             iBackgroundMask = NULL;
  5754 
       
  5755             delete iScaledTransparentColor;
       
  5756             iScaledTransparentColor = NULL;
       
  5757 
       
  5758             delete iScaledBackgroundSkin;
       
  5759             iScaledBackgroundSkin = NULL;
       
  5760 
       
  5761             delete iScaledBackgroundImage;
       
  5762             iScaledBackgroundImage = NULL;
       
  5763 
  5511 
  5764             InitializeBackgroundBitmapL( *( iNode.Node().UiEngine() ), iNode.Node(),
  5512             InitializeBackgroundBitmapL( *( iNode.Node().UiEngine() ), iNode.Node(),
  5765                 iBackgroundBitmapIndex, iBackgroundBitmap, iBackgroundMask,
  5513                 iBackgroundBitmapIndex, iBackgroundBitmap, iBackgroundMask,
  5766                 iIconProvider, FsSession());
  5514                 iIconProvider, FsSession());
  5767 
  5515