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