uifw/AvKon/src/akndiscreetpopupdrawer.cpp
branchRCL_3
changeset 55 aecbbf00d063
parent 15 08e69e956a8c
child 56 d48ab3b357f1
--- a/uifw/AvKon/src/akndiscreetpopupdrawer.cpp	Thu Aug 19 10:11:06 2010 +0300
+++ b/uifw/AvKon/src/akndiscreetpopupdrawer.cpp	Tue Aug 31 15:28:30 2010 +0300
@@ -25,7 +25,6 @@
 
 
 #include "akndiscreetpopupdrawer.h"
-#include "akntrace.h"
 
 const TInt KTextBufSize( 255 );
 const TInt KMaxNumOfLines( 2 );
@@ -77,7 +76,6 @@
     const TInt& aMaskId,
     const TBool& aAction )
     {
-    _AKNTRACE_FUNC_ENTER;
     CAknDiscreetPopupDrawer* self = 
         CAknDiscreetPopupDrawer::NewLC( aControl, 
                                         aTitleText, 
@@ -89,7 +87,6 @@
                                         aMaskId,
                                         aAction );
     CleanupStack::Pop( self );
-    _AKNTRACE_FUNC_EXIT;
     return self;
     }
 
@@ -128,6 +125,8 @@
 //
 CAknDiscreetPopupDrawer::~CAknDiscreetPopupDrawer()
     {
+    delete iPopupBitmap;
+    delete iTransparentMask;
     delete iIcon;
     delete iBodyText;
     delete iTitleText;
@@ -210,62 +209,50 @@
 
 
 // ---------------------------------------------------------------------------
-// CAknDiscreetPopupDrawer::Draw
-// Draws popup to given graphics context.
+// CAknDiscreetPopupDrawer::PopupBitmap
+// Provides popup bitmap.
+// ---------------------------------------------------------------------------
+//
+CFbsBitmap* CAknDiscreetPopupDrawer::PopupBitmap( const TSize& aSize )
+    {
+    if ( !iPopupBitmap || aSize != iPopupBitmap->SizeInPixels() )
+        {
+        TRAP_IGNORE( CreatePopupBitmapL( TRect( TPoint(), aSize ) ) );
+        }
+    return iPopupBitmap;
+    }
+
+
+// ---------------------------------------------------------------------------
+// CAknDiscreetPopupDrawer::TransparentMask
+// Provides transparent mask for a bitmap.
 // ---------------------------------------------------------------------------
 //
-void CAknDiscreetPopupDrawer::Draw( CWindowGc& aGc, 
-        const TRect& aRect ) const
+CFbsBitmap* CAknDiscreetPopupDrawer::TransparentMask( 
+    const TSize& aSize, const TInt& aAlpha )
     {
-    // draw background of the popup 
-    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
-    TAknLayoutRect innerLayout;
-    // Use bg_popup_preview_window_pane_g1() for getting innerRect, 
-    // no need to create a new layout id for discreet popup.
-    innerLayout.LayoutRect( aRect, 
-            	AknLayoutScalable_Avkon::bg_popup_preview_window_pane_g1() );        
-    TRect innerRect = innerLayout.Rect();  
-    
-    AknsDrawUtils::DrawFrame( skin, aGc, aRect, innerRect, 
-        KAknsIIDQsnFrPopupPreview, KAknsIIDDefault );
-    
-    // Draw the texts
-    TRgb textColor( EikonEnv()->ControlColor( EColorControlText, *iControl ) );
-
-    if ( iAction )
+    if ( !iTransparentMask || aSize != iTransparentMask->SizeInPixels() )
         {
-        aGc.SetUnderlineStyle( EUnderlineOn );
-        AknsUtils::GetCachedColor( skin,
-                                   textColor,
-                                   KAknsIIDQsnHighlightColors,
-                                   EAknsCIQsnHighlightColorsCG3 );
+        TRAP_IGNORE( CreateTransparentMaskL( TRect( TPoint(), aSize ) ) );
         }
-    else
+
+    TInt width( iTransparentMask->SizeInPixels().iWidth );
+    TInt height( iTransparentMask->SizeInPixels().iHeight ); 
+    TUint8* address( ( TUint8* ) iTransparentMask->DataAddress() );
+    TInt dataStride( iTransparentMask->DataStride() - width );
+    
+    for ( TInt i = 0; i < height; ++i )
         {
-        AknsUtils::GetCachedColor( skin,
-                                   textColor,
-                                   KAknsIIDQsnTextColors,
-                                   EAknsCIQsnTextColorsCG55 );
+        for ( TInt j = 0; j < width; j++ )
+            {
+            *address = aAlpha;
+            ++address;
+            }
+        address += dataStride; 
         }
-    aGc.SetPenColor( textColor );
-    DrawTexts( &aGc );
-    aGc.SetUnderlineStyle( EUnderlineOff );
-
-    // draw the icon
-    if ( iIcon && iIcon->Bitmap() && iIcon->Mask() )
-        {
-        aGc.BitBltMasked( iIconRect.iTl,
-                iIcon->Bitmap(), 
-                iIcon->Bitmap()->SizeInPixels(), 
-                iIcon->Mask(), 
-                EFalse );
-
-        }
-    else if( iIcon && iIcon->Bitmap() )
-        {
-        aGc.BitBlt( iIconRect.iTl, iIcon->Bitmap() );
-        }
-    }
+    
+    return iTransparentMask;
+    }  
 
 
 // ---------------------------------------------------------------------------
@@ -281,6 +268,8 @@
     iTitleText( NULL ),
     iBodyText( NULL ),
     iIcon( aIcon ),
+    iPopupBitmap( NULL ),
+    iTransparentMask( NULL ),
     iPopupLayoutType( KLayoutUnresolved ),
     iAction( aAction )
     {
@@ -302,14 +291,11 @@
     if ( aTitleText == KNullDesC && aBodyText != KNullDesC )
         {
         iTitleText = aBodyText.AllocL();
-        _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iTitleText : %S"), iTitleText );       
         }
     else
         {
         iTitleText = aTitleText.AllocL();
         iBodyText = aBodyText.AllocL();
-        _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iTitleText : %S"), iTitleText );
-        _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iBodyText : %S"), iBodyText );
         }
 
     if ( !iIcon )
@@ -323,10 +309,93 @@
 
 
 // ---------------------------------------------------------------------------
+// CAknDiscreetPopupDrawer::CreatePopupBitmap
+// ---------------------------------------------------------------------------
+//
+void CAknDiscreetPopupDrawer::CreatePopupBitmapL( const TRect& aRect )
+    {
+    delete iPopupBitmap;
+    iPopupBitmap = NULL;
+    
+    // create a bitmap to draw to
+    CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
+    CleanupStack::PushL( bitmap );
+
+    bitmap->Create( 
+        aRect.Size(), CCoeEnv::Static()->ScreenDevice()->DisplayMode() );
+    CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
+    CleanupStack::PushL( fbsBitGc );
+    CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( bitmap );
+    CleanupStack::PushL( bmpDevice );
+    fbsBitGc->Activate( bmpDevice );
+
+    // draw background of the popup	
+    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
+    AknsDrawUtils::DrawFrame( skin, *fbsBitGc, aRect, aRect, 
+        KAknsIIDQsnFrPopupPreview, KAknsIIDDefault, KAknsDrawParamDefault );
+    
+    // Draw the texts
+    TRgb textColor( EikonEnv()->ControlColor( EColorControlText, *iControl ) );
+    if ( iAction )
+        {
+        fbsBitGc->SetUnderlineStyle( EUnderlineOn );
+        AknsUtils::GetCachedColor( skin,
+                                   textColor,
+                                   KAknsIIDQsnHighlightColors,
+                                   EAknsCIQsnHighlightColorsCG3 );
+        }
+    else
+        {
+        AknsUtils::GetCachedColor( skin,
+                                   textColor,
+                                   KAknsIIDQsnTextColors,
+                                   EAknsCIQsnTextColorsCG55 );
+        }
+    fbsBitGc->SetPenColor( textColor );
+    DrawTexts( fbsBitGc );
+    fbsBitGc->SetUnderlineStyle( EUnderlineOff );
+
+    // draw the icon
+    if ( iIcon && iIcon->Bitmap() && iIcon->Mask() )
+        {
+        fbsBitGc->BitBltMasked( iIconRect.iTl,
+                                iIcon->Bitmap(), 
+                                iIcon->Bitmap()->SizeInPixels(), 
+                                iIcon->Mask(), 
+                                EFalse );
+
+        }
+    else if( iIcon && iIcon->Bitmap() )
+        {
+        fbsBitGc->BitBlt( iIconRect.iTl, iIcon->Bitmap() );
+        }
+
+    CleanupStack::PopAndDestroy( bmpDevice );
+    CleanupStack::PopAndDestroy( fbsBitGc );
+    CleanupStack::Pop( bitmap );
+    
+    iPopupBitmap = bitmap;
+    }
+
+
+// ---------------------------------------------------------------------------
+// CAknDiscreetPopupDrawer::CreateTransparentMaskL
+// ---------------------------------------------------------------------------
+//
+void CAknDiscreetPopupDrawer::CreateTransparentMaskL( const TRect& aRect )
+    {
+    delete iTransparentMask;
+    iTransparentMask = NULL;
+    iTransparentMask = new ( ELeave ) CFbsBitmap;
+    iTransparentMask->Create( aRect.Size(), EGray256 );
+    }
+
+
+// ---------------------------------------------------------------------------
 // CAknDiscreetPopupDrawer::DrawTexts
 // ---------------------------------------------------------------------------
 //
-void CAknDiscreetPopupDrawer::DrawTexts( CWindowGc* aGc ) const
+void CAknDiscreetPopupDrawer::DrawTexts( CFbsBitGc* aGc )
     {
     aGc->SetBrushStyle( CGraphicsContext::ENullBrush );
 
@@ -355,7 +424,7 @@
     TBool withIcon( iIcon && iIcon->Bitmap() );
     TBool twoRowsText( 
         iTitleText->Des() != KNullDesC 
-        && iBodyText && iBodyText->Des() != KNullDesC );
+        && iBodyText->Des() != KNullDesC );
 
     // Two rows of text
     if ( twoRowsText )
@@ -402,7 +471,7 @@
 // Provides control eikon env.
 // ---------------------------------------------------------------------------
 //
-CEikonEnv* CAknDiscreetPopupDrawer::EikonEnv() const
+CEikonEnv* CAknDiscreetPopupDrawer::EikonEnv()
     {
     if ( iControl )
         {
@@ -488,9 +557,9 @@
 // ---------------------------------------------------------------------------
 //
 void CAknDiscreetPopupDrawer::DrawBidiEnabledText(
-        CWindowGc* aGc,
-        const TAknDiscreetPopupTextData& aTextData,
-        const TDesC& aText ) const
+        CFbsBitGc* aGc,
+        TAknDiscreetPopupTextData& aTextData,
+        const TDesC& aText )
     {
     // Buffer for visually ordered text
     TBuf<KTextBufSize + KAknBidiExtraSpacePerLine> visualText;