uifw/AvKon/src/akndiscreetpopupdrawer.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
    23 #include <AknUtils.h>
    23 #include <AknUtils.h>
    24 #include <gulicon.h>
    24 #include <gulicon.h>
    25 
    25 
    26 
    26 
    27 #include "akndiscreetpopupdrawer.h"
    27 #include "akndiscreetpopupdrawer.h"
       
    28 #include "akntrace.h"
    28 
    29 
    29 const TInt KTextBufSize( 255 );
    30 const TInt KTextBufSize( 255 );
    30 const TInt KMaxNumOfLines( 2 );
    31 const TInt KMaxNumOfLines( 2 );
    31 
    32 
    32 // Help structure for layout data
    33 // Help structure for layout data
    74     const TDesC& aBitmapFile,
    75     const TDesC& aBitmapFile,
    75     const TInt& aBitmapId,
    76     const TInt& aBitmapId,
    76     const TInt& aMaskId,
    77     const TInt& aMaskId,
    77     const TBool& aAction )
    78     const TBool& aAction )
    78     {
    79     {
       
    80     _AKNTRACE_FUNC_ENTER;
    79     CAknDiscreetPopupDrawer* self = 
    81     CAknDiscreetPopupDrawer* self = 
    80         CAknDiscreetPopupDrawer::NewLC( aControl, 
    82         CAknDiscreetPopupDrawer::NewLC( aControl, 
    81                                         aTitleText, 
    83                                         aTitleText, 
    82                                         aBodyText, 
    84                                         aBodyText, 
    83                                         aIcon, 
    85                                         aIcon, 
    85                                         aBitmapFile, 
    87                                         aBitmapFile, 
    86                                         aBitmapId,
    88                                         aBitmapId,
    87                                         aMaskId,
    89                                         aMaskId,
    88                                         aAction );
    90                                         aAction );
    89     CleanupStack::Pop( self );
    91     CleanupStack::Pop( self );
       
    92     _AKNTRACE_FUNC_EXIT;
    90     return self;
    93     return self;
    91     }
    94     }
    92 
    95 
    93 
    96 
    94 // ---------------------------------------------------------------------------
    97 // ---------------------------------------------------------------------------
   123 // CAknDiscreetPopupDrawer::~CAknDiscreetPopupDrawer
   126 // CAknDiscreetPopupDrawer::~CAknDiscreetPopupDrawer
   124 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
   125 //
   128 //
   126 CAknDiscreetPopupDrawer::~CAknDiscreetPopupDrawer()
   129 CAknDiscreetPopupDrawer::~CAknDiscreetPopupDrawer()
   127     {
   130     {
   128     delete iPopupBitmap;
       
   129     delete iTransparentMask;
       
   130     delete iIcon;
   131     delete iIcon;
   131     delete iBodyText;
   132     delete iBodyText;
   132     delete iTitleText;
   133     delete iTitleText;
   133     }
   134     }
   134 
   135 
   207     return popupRect;
   208     return popupRect;
   208     }
   209     }
   209 
   210 
   210 
   211 
   211 // ---------------------------------------------------------------------------
   212 // ---------------------------------------------------------------------------
   212 // CAknDiscreetPopupDrawer::PopupBitmap
   213 // CAknDiscreetPopupDrawer::Draw
   213 // Provides popup bitmap.
   214 // Draws popup to given graphics context.
   214 // ---------------------------------------------------------------------------
   215 // ---------------------------------------------------------------------------
   215 //
   216 //
   216 CFbsBitmap* CAknDiscreetPopupDrawer::PopupBitmap( const TSize& aSize )
   217 void CAknDiscreetPopupDrawer::Draw( CWindowGc& aGc, 
   217     {
   218         const TRect& aRect ) const
   218     if ( !iPopupBitmap || aSize != iPopupBitmap->SizeInPixels() )
   219     {
   219         {
   220     // draw background of the popup 
   220         TRAP_IGNORE( CreatePopupBitmapL( TRect( TPoint(), aSize ) ) );
   221     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   221         }
   222     TAknLayoutRect innerLayout;
   222     return iPopupBitmap;
   223     // Use bg_popup_preview_window_pane_g1() for getting innerRect, 
   223     }
   224     // no need to create a new layout id for discreet popup.
   224 
   225     innerLayout.LayoutRect( aRect, 
   225 
   226             	AknLayoutScalable_Avkon::bg_popup_preview_window_pane_g1() );        
   226 // ---------------------------------------------------------------------------
   227     TRect innerRect = innerLayout.Rect();  
   227 // CAknDiscreetPopupDrawer::TransparentMask
   228     
   228 // Provides transparent mask for a bitmap.
   229     AknsDrawUtils::DrawFrame( skin, aGc, aRect, innerRect, 
   229 // ---------------------------------------------------------------------------
   230         KAknsIIDQsnFrPopupPreview, KAknsIIDDefault );
   230 //
   231     
   231 CFbsBitmap* CAknDiscreetPopupDrawer::TransparentMask( 
   232     // Draw the texts
   232     const TSize& aSize, const TInt& aAlpha )
   233     TRgb textColor( EikonEnv()->ControlColor( EColorControlText, *iControl ) );
   233     {
   234 
   234     if ( !iTransparentMask || aSize != iTransparentMask->SizeInPixels() )
   235     if ( iAction )
   235         {
   236         {
   236         TRAP_IGNORE( CreateTransparentMaskL( TRect( TPoint(), aSize ) ) );
   237         aGc.SetUnderlineStyle( EUnderlineOn );
   237         }
   238         AknsUtils::GetCachedColor( skin,
   238 
   239                                    textColor,
   239     TInt width( iTransparentMask->SizeInPixels().iWidth );
   240                                    KAknsIIDQsnHighlightColors,
   240     TInt height( iTransparentMask->SizeInPixels().iHeight ); 
   241                                    EAknsCIQsnHighlightColorsCG3 );
   241     TUint8* address( ( TUint8* ) iTransparentMask->DataAddress() );
   242         }
   242     TInt dataStride( iTransparentMask->DataStride() - width );
   243     else
   243     
   244         {
   244     for ( TInt i = 0; i < height; ++i )
   245         AknsUtils::GetCachedColor( skin,
   245         {
   246                                    textColor,
   246         for ( TInt j = 0; j < width; j++ )
   247                                    KAknsIIDQsnTextColors,
   247             {
   248                                    EAknsCIQsnTextColorsCG55 );
   248             *address = aAlpha;
   249         }
   249             ++address;
   250     aGc.SetPenColor( textColor );
   250             }
   251     DrawTexts( &aGc );
   251         address += dataStride; 
   252     aGc.SetUnderlineStyle( EUnderlineOff );
   252         }
   253 
   253     
   254     // draw the icon
   254     return iTransparentMask;
   255     if ( iIcon && iIcon->Bitmap() && iIcon->Mask() )
   255     }  
   256         {
       
   257         aGc.BitBltMasked( iIconRect.iTl,
       
   258                 iIcon->Bitmap(), 
       
   259                 iIcon->Bitmap()->SizeInPixels(), 
       
   260                 iIcon->Mask(), 
       
   261                 EFalse );
       
   262 
       
   263         }
       
   264     else if( iIcon && iIcon->Bitmap() )
       
   265         {
       
   266         aGc.BitBlt( iIconRect.iTl, iIcon->Bitmap() );
       
   267         }
       
   268     }
   256 
   269 
   257 
   270 
   258 // ---------------------------------------------------------------------------
   271 // ---------------------------------------------------------------------------
   259 // CAknDiscreetPopupDrawer::CAknDiscreetPopupDrawer
   272 // CAknDiscreetPopupDrawer::CAknDiscreetPopupDrawer
   260 // ---------------------------------------------------------------------------
   273 // ---------------------------------------------------------------------------
   266     :
   279     :
   267     iControl( aControl ),
   280     iControl( aControl ),
   268     iTitleText( NULL ),
   281     iTitleText( NULL ),
   269     iBodyText( NULL ),
   282     iBodyText( NULL ),
   270     iIcon( aIcon ),
   283     iIcon( aIcon ),
   271     iPopupBitmap( NULL ),
       
   272     iTransparentMask( NULL ),
       
   273     iPopupLayoutType( KLayoutUnresolved ),
   284     iPopupLayoutType( KLayoutUnresolved ),
   274     iAction( aAction )
   285     iAction( aAction )
   275     {
   286     {
   276     }
   287     }
   277 
   288 
   289     {
   300     {
   290     // Body text to title text if title text is empty
   301     // Body text to title text if title text is empty
   291     if ( aTitleText == KNullDesC && aBodyText != KNullDesC )
   302     if ( aTitleText == KNullDesC && aBodyText != KNullDesC )
   292         {
   303         {
   293         iTitleText = aBodyText.AllocL();
   304         iTitleText = aBodyText.AllocL();
       
   305         _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iTitleText : %S"), iTitleText );       
   294         }
   306         }
   295     else
   307     else
   296         {
   308         {
   297         iTitleText = aTitleText.AllocL();
   309         iTitleText = aTitleText.AllocL();
   298         iBodyText = aBodyText.AllocL();
   310         iBodyText = aBodyText.AllocL();
       
   311         _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iTitleText : %S"), iTitleText );
       
   312         _AKNTRACE( _L("CAknDiscreetPopupDrawer::ConstructL, iBodyText : %S"), iBodyText );
   299         }
   313         }
   300 
   314 
   301     if ( !iIcon )
   315     if ( !iIcon )
   302         {
   316         {
   303         iIcon = CreatePopupIconL( aSkinId, 
   317         iIcon = CreatePopupIconL( aSkinId, 
   307         }
   321         }
   308     }
   322     }
   309 
   323 
   310 
   324 
   311 // ---------------------------------------------------------------------------
   325 // ---------------------------------------------------------------------------
   312 // CAknDiscreetPopupDrawer::CreatePopupBitmap
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CAknDiscreetPopupDrawer::CreatePopupBitmapL( const TRect& aRect )
       
   316     {
       
   317     delete iPopupBitmap;
       
   318     iPopupBitmap = NULL;
       
   319     
       
   320     // create a bitmap to draw to
       
   321     CFbsBitmap* bitmap = new ( ELeave ) CFbsBitmap;
       
   322     CleanupStack::PushL( bitmap );
       
   323 
       
   324     bitmap->Create( 
       
   325         aRect.Size(), CCoeEnv::Static()->ScreenDevice()->DisplayMode() );
       
   326     CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
       
   327     CleanupStack::PushL( fbsBitGc );
       
   328     CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL( bitmap );
       
   329     CleanupStack::PushL( bmpDevice );
       
   330     fbsBitGc->Activate( bmpDevice );
       
   331 
       
   332     // draw background of the popup	
       
   333     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   334     AknsDrawUtils::DrawFrame( skin, *fbsBitGc, aRect, aRect, 
       
   335         KAknsIIDQsnFrPopupPreview, KAknsIIDDefault, KAknsDrawParamDefault );
       
   336     
       
   337     // Draw the texts
       
   338     TRgb textColor( EikonEnv()->ControlColor( EColorControlText, *iControl ) );
       
   339     if ( iAction )
       
   340         {
       
   341         fbsBitGc->SetUnderlineStyle( EUnderlineOn );
       
   342         AknsUtils::GetCachedColor( skin,
       
   343                                    textColor,
       
   344                                    KAknsIIDQsnHighlightColors,
       
   345                                    EAknsCIQsnHighlightColorsCG3 );
       
   346         }
       
   347     else
       
   348         {
       
   349         AknsUtils::GetCachedColor( skin,
       
   350                                    textColor,
       
   351                                    KAknsIIDQsnTextColors,
       
   352                                    EAknsCIQsnTextColorsCG55 );
       
   353         }
       
   354     fbsBitGc->SetPenColor( textColor );
       
   355     DrawTexts( fbsBitGc );
       
   356     fbsBitGc->SetUnderlineStyle( EUnderlineOff );
       
   357 
       
   358     // draw the icon
       
   359     if ( iIcon && iIcon->Bitmap() && iIcon->Mask() )
       
   360         {
       
   361         fbsBitGc->BitBltMasked( iIconRect.iTl,
       
   362                                 iIcon->Bitmap(), 
       
   363                                 iIcon->Bitmap()->SizeInPixels(), 
       
   364                                 iIcon->Mask(), 
       
   365                                 EFalse );
       
   366 
       
   367         }
       
   368     else if( iIcon && iIcon->Bitmap() )
       
   369         {
       
   370         fbsBitGc->BitBlt( iIconRect.iTl, iIcon->Bitmap() );
       
   371         }
       
   372 
       
   373     CleanupStack::PopAndDestroy( bmpDevice );
       
   374     CleanupStack::PopAndDestroy( fbsBitGc );
       
   375     CleanupStack::Pop( bitmap );
       
   376     
       
   377     iPopupBitmap = bitmap;
       
   378     }
       
   379 
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // CAknDiscreetPopupDrawer::CreateTransparentMaskL
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 void CAknDiscreetPopupDrawer::CreateTransparentMaskL( const TRect& aRect )
       
   386     {
       
   387     delete iTransparentMask;
       
   388     iTransparentMask = NULL;
       
   389     iTransparentMask = new ( ELeave ) CFbsBitmap;
       
   390     iTransparentMask->Create( aRect.Size(), EGray256 );
       
   391     }
       
   392 
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // CAknDiscreetPopupDrawer::DrawTexts
   326 // CAknDiscreetPopupDrawer::DrawTexts
   396 // ---------------------------------------------------------------------------
   327 // ---------------------------------------------------------------------------
   397 //
   328 //
   398 void CAknDiscreetPopupDrawer::DrawTexts( CFbsBitGc* aGc )
   329 void CAknDiscreetPopupDrawer::DrawTexts( CWindowGc* aGc ) const
   399     {
   330     {
   400     aGc->SetBrushStyle( CGraphicsContext::ENullBrush );
   331     aGc->SetBrushStyle( CGraphicsContext::ENullBrush );
   401 
   332 
   402     DrawBidiEnabledText( aGc, iTitleTextData, *iTitleText );
   333     DrawBidiEnabledText( aGc, iTitleTextData, *iTitleText );
   403     
   334     
   422         }
   353         }
   423     
   354     
   424     TBool withIcon( iIcon && iIcon->Bitmap() );
   355     TBool withIcon( iIcon && iIcon->Bitmap() );
   425     TBool twoRowsText( 
   356     TBool twoRowsText( 
   426         iTitleText->Des() != KNullDesC 
   357         iTitleText->Des() != KNullDesC 
   427         && iBodyText->Des() != KNullDesC );
   358         && iBodyText && iBodyText->Des() != KNullDesC );
   428 
   359 
   429     // Two rows of text
   360     // Two rows of text
   430     if ( twoRowsText )
   361     if ( twoRowsText )
   431         {
   362         {
   432         if ( withIcon )
   363         if ( withIcon )
   469 // ---------------------------------------------------------------------------
   400 // ---------------------------------------------------------------------------
   470 // CAknDiscreetPopupDrawer::EikonEnv
   401 // CAknDiscreetPopupDrawer::EikonEnv
   471 // Provides control eikon env.
   402 // Provides control eikon env.
   472 // ---------------------------------------------------------------------------
   403 // ---------------------------------------------------------------------------
   473 //
   404 //
   474 CEikonEnv* CAknDiscreetPopupDrawer::EikonEnv()
   405 CEikonEnv* CAknDiscreetPopupDrawer::EikonEnv() const
   475     {
   406     {
   476     if ( iControl )
   407     if ( iControl )
   477         {
   408         {
   478         return static_cast<CEikonEnv*>( iControl->ControlEnv() );
   409         return static_cast<CEikonEnv*>( iControl->ControlEnv() );
   479         }
   410         }
   555 // ---------------------------------------------------------------------------
   486 // ---------------------------------------------------------------------------
   556 // CAknDiscreetPopupDrawer::DrawBidiEnabledText
   487 // CAknDiscreetPopupDrawer::DrawBidiEnabledText
   557 // ---------------------------------------------------------------------------
   488 // ---------------------------------------------------------------------------
   558 //
   489 //
   559 void CAknDiscreetPopupDrawer::DrawBidiEnabledText(
   490 void CAknDiscreetPopupDrawer::DrawBidiEnabledText(
   560         CFbsBitGc* aGc,
   491         CWindowGc* aGc,
   561         TAknDiscreetPopupTextData& aTextData,
   492         const TAknDiscreetPopupTextData& aTextData,
   562         const TDesC& aText )
   493         const TDesC& aText ) const
   563     {
   494     {
   564     // Buffer for visually ordered text
   495     // Buffer for visually ordered text
   565     TBuf<KTextBufSize + KAknBidiExtraSpacePerLine> visualText; 
   496     TBuf<KTextBufSize + KAknBidiExtraSpacePerLine> visualText; 
   566     TInt clipWidth( aTextData.iTextRect.Width() );
   497     TInt clipWidth( aTextData.iTextRect.Width() );
   567 
   498