emailuis/emailui/src/OverlayControl.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 3 a4d6f1ea0416
child 12 f5907b1a1053
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    28 
    28 
    29 COverlayControl::~COverlayControl()
    29 COverlayControl::~COverlayControl()
    30 	{
    30 	{
    31     delete iBitmap;
    31     delete iBitmap;
    32     delete iMask;
    32     delete iMask;
    33     delete iSolidMask;
       
    34 	}
    33 	}
    35 
    34 
    36 COverlayControl* COverlayControl::NewL( CCoeControl* aParent, MOverlayControlObserver* aObserver, 
    35 COverlayControl* COverlayControl::NewL( CCoeControl* aParent, MOverlayControlObserver* aObserver, 
    37         const TRect& aRect, TInt aBitmapId, TInt aMaskId )
    36         const TRect& aRect, TInt aBitmapId, TInt aMaskId )
    38 	{
    37 	{
    43 	return self;
    42 	return self;
    44 	}
    43 	}
    45 
    44 
    46 void COverlayControl::ConstructL( CCoeControl* aParent, const TRect& aRect, TInt aBitmapId, TInt aMaskId )
    45 void COverlayControl::ConstructL( CCoeControl* aParent, const TRect& aRect, TInt aBitmapId, TInt aMaskId )
    47 	{
    46 	{
    48 	iSolidMask = new(ELeave) CFbsBitmap();
       
    49 
    47 
    50     CreateWindowL( aParent );
    48     SetContainerWindowL( *aParent );
    51 	
    49 	
    52 	TFileName iconFileName;
    50 	TFileName iconFileName;
    53 	TFsEmailUiUtility::GetFullIconFileNameL( iconFileName );
    51 	TFsEmailUiUtility::GetFullIconFileNameL( iconFileName );
    54 	AknIconUtils::CreateIconL( iBitmap,
    52 	AknIconUtils::CreateIconL( iBitmap,
    55 							   iMask,
    53 							   iMask,
    70         AknIconUtils::SetSize( iBitmap, aRect.Size() );
    68         AknIconUtils::SetSize( iBitmap, aRect.Size() );
    71         }
    69         }
    72     if( iMask )
    70     if( iMask )
    73         {
    71         {
    74         AknIconUtils::SetSize( iMask, aRect.Size() );
    72         AknIconUtils::SetSize( iMask, aRect.Size() );
    75         
       
    76         // Create a solid version of the mask, too
       
    77         TRAP_IGNORE(
       
    78             CopyBitmapL( *iMask, *iSolidMask );
       
    79             AdjustAlpha( *iSolidMask, KSolidTransparencyFactor );
       
    80             );
       
    81         
       
    82         UpdateMask();
       
    83         }
    73         }
    84     CCoeControl::SetRect( aRect );
    74     CCoeControl::SetRect( aRect );
    85     }
       
    86 
       
    87 void COverlayControl::CopyBitmapL( const CFbsBitmap& aSource, CFbsBitmap& aDest )
       
    88     {
       
    89     TSize size = aSource.SizeInPixels();
       
    90     TInt dataSize = aSource.DataStride() * size.iHeight;
       
    91     User::LeaveIfError( aDest.Create( size, aSource.DisplayMode() ) );
       
    92     
       
    93     CFbsBitGc* bitCtx;
       
    94     CFbsBitmapDevice* bitDev = CFbsBitmapDevice::NewL( &aDest );
       
    95     CleanupStack::PushL( bitDev );
       
    96     User::LeaveIfError( bitDev->CreateContext( bitCtx ) );
       
    97     CleanupStack::PushL( bitCtx );
       
    98     bitCtx->BitBlt( TRect( size ).iTl, &aSource );
       
    99     CleanupStack::PopAndDestroy( 2 ); // bitCtx, bitDev
       
   100     }
       
   101 
       
   102 void COverlayControl::AdjustAlpha( CFbsBitmap& aBitmap, TReal aFactor )
       
   103     {
       
   104     aBitmap.LockHeap();
       
   105     TUint8* data = (TUint8*)aBitmap.DataAddress();
       
   106     TSize size = aBitmap.SizeInPixels();
       
   107     TInt dataSize = aBitmap.DataStride() * size.iHeight;
       
   108     for( TInt i = 0; i<dataSize; i++ )
       
   109         {
       
   110         // multiply each pixel by aFactor
       
   111         if( data[i] ) 
       
   112             {
       
   113             TInt value = aFactor * data[ i ];
       
   114             if( value > KMaxTUint8 ) 
       
   115                 {
       
   116                 value = KMaxTUint8;
       
   117                 }
       
   118             data[ i ] = value;
       
   119             }
       
   120         }
       
   121     aBitmap.UnlockHeap();   
       
   122     }
    75     }
   123 
    76 
   124 void COverlayControl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
    77 void COverlayControl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
   125     {
    78     {
   126     CCoeControl::HandlePointerEventL( aPointerEvent );
    79     CCoeControl::HandlePointerEventL( aPointerEvent );
   127 
       
   128     // Do hit test for the pointer event
       
   129     TBool hit = EFalse;
       
   130     
    80     
   131     TSize size = Size();
    81     if( iObserver )
   132     if( aPointerEvent.iPosition.iX >= 0 && 
       
   133          aPointerEvent.iPosition.iY >= 0 &&
       
   134          aPointerEvent.iPosition.iX < size.iWidth && 
       
   135          aPointerEvent.iPosition.iY < size.iHeight )
       
   136         {
    82         {
   137         hit = ETrue;
    83         // Do not let leaves disturb the system
       
    84         TRAP_IGNORE(
       
    85             iObserver->HandleOverlayPointerEventL( this, aPointerEvent ));
   138         }
    86         }
   139     
    87      }
   140     if( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   141         {
       
   142         SetPointerCapture( EFalse );
       
   143         UpdateButtonState( EFalse );
       
   144         
       
   145         // Notify the events only if released on top of the control 
       
   146         if( iObserver && hit )
       
   147             {
       
   148             // Do not let leaves disturb the system
       
   149             TRAP_IGNORE(
       
   150                 iObserver->HandleOverlayPointerEventL( this, aPointerEvent );
       
   151                 );
       
   152             }
       
   153         }
       
   154     else if( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   155         {
       
   156         UpdateButtonState( ETrue );
       
   157         SetGloballyCapturing( ETrue );
       
   158         SetPointerCapture( ETrue );
       
   159         }
       
   160     else if( aPointerEvent.iType == TPointerEvent::EDrag )
       
   161         {
       
   162         // Update the button UI according to hit result
       
   163         UpdateButtonState( hit );
       
   164         }
       
   165     }
       
   166 
       
   167 void COverlayControl::UpdateButtonState( TBool aButtonDown )
       
   168     {
       
   169     if( iDownState != aButtonDown )
       
   170         {
       
   171         iDownState = aButtonDown;
       
   172         UpdateMask();
       
   173         }
       
   174     }
       
   175 
    88 
   176 void COverlayControl::MakeVisible( TBool aVisible )
    89 void COverlayControl::MakeVisible( TBool aVisible )
   177     {
    90     {
   178     if( !aVisible )
    91     if( !aVisible )
   179         {
    92         {
   180         UpdateButtonState( EFalse );
       
   181         SetPointerCapture( EFalse );
    93         SetPointerCapture( EFalse );
   182         }
    94         }
       
    95     else
       
    96         {
       
    97         DrawDeferred();
       
    98         }
   183     CCoeControl::MakeVisible( aVisible );
    99     CCoeControl::MakeVisible( aVisible );
   184     }
       
   185 
       
   186 void COverlayControl::UpdateMask()
       
   187     {
       
   188     CFbsBitmap* mask = iMask;
       
   189     if( iDownState )
       
   190         {
       
   191         mask = iSolidMask;
       
   192         }
       
   193     if( mask )
       
   194         {
       
   195         Window().SetTransparencyBitmap( *mask );
       
   196         }
       
   197     }
   100     }
   198 
   101 
   199 void COverlayControl::Draw( const TRect& ) const 
   102 void COverlayControl::Draw( const TRect& ) const 
   200 	{
   103 	{
   201 	CWindowGc& gc = SystemGc();
   104 	CWindowGc& gc = SystemGc();
   202 
       
   203 	if( iBitmap )
   105 	if( iBitmap )
   204 	    {
   106 	    {
   205         TSize size = iBitmap->SizeInPixels();
   107         TSize size = iBitmap->SizeInPixels();
   206         gc.BitBlt( TPoint( 0, 0 ), iBitmap );
   108         gc.BitBltMasked(Position(),iBitmap,TRect( TPoint(0,0), size),iMask, ETrue);
   207 	    }
   109         }
   208 	}
   110 	}