uifw/EikStd/coctlsrc/aknedwincustomdrawbase.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
    35 
    35 
    36 
    36 
    37 // CONSTANTS
    37 // CONSTANTS
    38 
    38 
    39 // This is the last character that will be treated as requiring higher underline
    39 // This is the last character that will be treated as requiring higher underline
    40 // const TText KMaxSpecialUnderliningChar = 0x0E5B;
    40 
    41 const TInt KWsBufferSize = 16000;
    41 const TInt KWsBufferSize = 16000;
       
    42 const TInt KOneHundred = 100;
    42 
    43 
    43 // MEMBER FUNCTIONS
    44 // MEMBER FUNCTIONS
    44 
    45 
    45 CAknEdwinCustomDrawBase::CAknEdwinCustomDrawBase(
    46 CAknEdwinCustomDrawBase::CAknEdwinCustomDrawBase(
    46     const MLafEnv& aEnv, const CEikEdwin& aEdwin ) :
    47     const MLafEnv& aEnv, const CEikEdwin& aEdwin ) :
    90     { // static
    91     { // static
    91     CAknEdwinCustomDrawBase* self =
    92     CAknEdwinCustomDrawBase* self =
    92         new( ELeave ) CAknEdwinCustomDrawBase( aEnv, aControl );
    93         new( ELeave ) CAknEdwinCustomDrawBase( aEnv, aControl );
    93     CleanupStack::PushL( self );
    94     CleanupStack::PushL( self );
    94     self->ConstructL();
    95     self->ConstructL();
    95     CleanupStack::Pop();
    96     CleanupStack::Pop( self );
    96     return self;
    97     return self;
    97     }
    98     }
    98 
    99 
    99 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   100 // CAknEdwinCustomDraw::NewL
   101 // CAknEdwinCustomDraw::NewL
   109     { // static
   110     { // static
   110     CAknEdwinCustomDrawBase* self = new( ELeave ) CAknEdwinCustomDrawBase(
   111     CAknEdwinCustomDrawBase* self = new( ELeave ) CAknEdwinCustomDrawBase(
   111         aEnv, aControl, aTextView, aSystemGc );
   112         aEnv, aControl, aTextView, aSystemGc );
   112     CleanupStack::PushL( self );
   113     CleanupStack::PushL( self );
   113     self->ConstructL();
   114     self->ConstructL();
   114     CleanupStack::Pop();
   115     CleanupStack::Pop( self );
   115     return self;
   116     return self;
   116     }
   117     }
   117 
   118 
   118 // Destructor
   119 // Destructor
   119 CAknEdwinCustomDrawBase::~CAknEdwinCustomDrawBase()
   120 CAknEdwinCustomDrawBase::~CAknEdwinCustomDrawBase()
   163         {
   164         {
   164         // Inhibit all excess pixels
   165         // Inhibit all excess pixels
   165         aExtraPixels = 0;
   166         aExtraPixels = 0;
   166 
   167 
   167         TInt underlinePos(0);
   168         TInt underlinePos(0);
   168         (void)TextNeedsCustomUnderline( aText, aParam, aFormat, underlinePos ) ;
   169         TextNeedsCustomUnderline( aText, aParam, aFormat, underlinePos ) ;
   169         // always perform custom underlining
   170         // always perform custom underlining
   170 
   171 
   171         TRect underlineRect(aParam.iDrawRect);
   172         TRect underlineRect(aParam.iDrawRect);
   172         TAknTextDecorationMetrics decoration( 0 ); // Give dummy font id for default decoration
   173         TAknTextDecorationMetrics decoration( 0 ); // Give dummy font id for default decoration
   173         // Note that underlinePos in scalable is a delta relative to normal baseline
   174         // Note that underlinePos in scalable is a delta relative to normal baseline
   189         aParam.iGc.SetUnderlineStyle( EUnderlineOff);  // and force it off in the GC
   190         aParam.iGc.SetUnderlineStyle( EUnderlineOff);  // and force it off in the GC
   190         }
   191         }
   191     CFont* font = NULL;
   192     CFont* font = NULL;
   192     aParam.iMap.GetNearestFontInTwips( font, aFormat.iFontSpec );
   193     aParam.iMap.GetNearestFontInTwips( font, aFormat.iFontSpec );
   193     RRegion rgn;
   194     RRegion rgn;
   194     if ( iEdwin.IsSmileyEnabled() && font )
   195     TBool drawSmiley( iEdwin.IsSmileyEnabled() && font && ( &aParam.iGc ==
   195         {
   196         static_cast<CGraphicsContext*>( iTextView->BitmapContext() ) ) );
       
   197     if ( drawSmiley )
       
   198         {
       
   199         TPoint startPt( aParam.iDrawRect.iTl );
       
   200         startPt.iY = aLineInfo.iBaseline;
       
   201         CBitmapContext* bitmapGc( iTextView->BitmapContext() );
       
   202         CEikEdwin& edwin = const_cast<CEikEdwin&>( iEdwin );
   196         rgn.AddRect( iEdwin.AdjustDrawRectForSmiley( aParam.iDrawRect ) );
   203         rgn.AddRect( iEdwin.AdjustDrawRectForSmiley( aParam.iDrawRect ) );
   197         iEdwin.GetClipRegionForSmiley( rgn, *font, aText, aTextOrigin, 
   204         TRAP_IGNORE( edwin.DrawSmileyInTextL( rgn, aParam.iDrawRect, *bitmapGc, 
   198             aParam.iDrawRect );
   205             *font, aText, startPt ) );
   199         aParam.iGc.SetClippingRegion( rgn );
   206         aParam.iGc.SetClippingRegion( rgn );
   200         }
   207         }
   201     CLafEdwinCustomDrawBase::DrawText( aParam, aLineInfo, alteredFormat, 
   208     CLafEdwinCustomDrawBase::DrawText( aParam, aLineInfo, alteredFormat, 
   202         aText, aTextOrigin, aExtraPixels );
   209         aText, aTextOrigin, aExtraPixels );
   203     if ( iEdwin.IsSmileyEnabled() )
   210     if ( drawSmiley )
   204         {
   211         {
   205         aParam.iGc.CancelClippingRegion();
   212         aParam.iGc.CancelClippingRegion();
   206         }
   213         }
   207     rgn.Close();
   214     rgn.Close();
   208     
       
   209     if ( iEdwin.IsSmileyEnabled() && font && ( &aParam.iGc ==
       
   210         static_cast<CGraphicsContext*>( iTextView->BitmapContext() ) ) )
       
   211         {
       
   212         CBitmapContext* bitmapGc( iTextView->BitmapContext() );
       
   213         CEikEdwin& edwin = const_cast<CEikEdwin&>( iEdwin );
       
   214         TPoint startPt( aParam.iDrawRect.iTl );
       
   215         startPt.iY = aLineInfo.iBaseline;
       
   216         TRAP_IGNORE( {
       
   217             edwin.HandleScrollForSmileyL();
       
   218             edwin.DrawSmileyInTextL( *bitmapGc, *font, aText, startPt );
       
   219             } );
       
   220         }
       
   221 
   215 
   222     // Draw pictographs if the feature is supported.
   216     // Draw pictographs if the feature is supported.
   223     // Character justification is not supported.
   217     // Character justification is not supported.
   224     if ( ( iPictographDrawer && !aExtraPixels ) )
   218     if ( ( iPictographDrawer && !aExtraPixels ) )
   225         {
   219         {
   321     {
   315     {
   322     CLafEdwinCustomDrawBase::DrawLineGraphics( aParam, aLineInfo ); // Base Call
   316     CLafEdwinCustomDrawBase::DrawLineGraphics( aParam, aLineInfo ); // Base Call
   323     }
   317     }
   324 
   318 
   325 
   319 
   326 TRgb CAknEdwinCustomDrawBase::SystemColor(TUint aColorIndex,TRgb aDefaultColor) const
   320 TRgb CAknEdwinCustomDrawBase::SystemColor( TUint aColorIndex, TRgb aDefaultColor ) const
   327     {
   321     {
   328     TRgb ret = aDefaultColor;
   322     TRgb ret = aDefaultColor;
       
   323     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   329     if (aColorIndex==TLogicalRgb::ESystemForegroundIndex)
   324     if (aColorIndex==TLogicalRgb::ESystemForegroundIndex)
   330         {
   325         {
   331         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   326         if ( skin && iEdwin.SkinColorId() != KErrNotFound )
   332         if (skin && iEdwin.SkinColorId() != KErrNotFound)
   327             {
   333             {
   328             AknsUtils::GetCachedColor( skin, ret, KAknsIIDQsnTextColors, 
   334             AknsUtils::GetCachedColor(skin, ret, KAknsIIDQsnTextColors, iEdwin.SkinColorId());
   329                     iEdwin.SkinColorId() );
   335             }
   330             }
   336         }
   331         }
   337     else if (aColorIndex==TLogicalRgb::ESystemBackgroundIndex)
   332     else if ( aColorIndex==TLogicalRgb::ESystemBackgroundIndex )
   338         {
   333         {
   339         // Only override aDefaultColor if SetBackgroundColorL was called:
   334         // Only override aDefaultColor if SetBackgroundColorL was called:
   340         (void)iEdwin.EditorBackgroundColor(ret);
   335         iEdwin.EditorBackgroundColor( ret );
   341         // Insist on opaque background
   336         // Insist on opaque background
   342         ret.SetAlpha(0xFF);
   337         ret.SetAlpha( 0xFF );
   343         }
   338         }
   344 
       
   345     else if (aColorIndex==TLogicalRgb::ESystemSelectionForegroundIndex)
   339     else if (aColorIndex==TLogicalRgb::ESystemSelectionForegroundIndex)
   346         {
   340         {
   347         ret = KRgbWhite;
   341         ret = KRgbWhite;
   348         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   342         if ( skin )
   349         if (skin)
       
   350             {
   343             {
   351             if ( iEdwin.HighlightStyle() == EEikEdwinHighlightLink )
   344             if ( iEdwin.HighlightStyle() == EEikEdwinHighlightLink )
   352                 {
   345                 {
   353                 AknsUtils::GetCachedColor(skin, ret, KAknsIIDQsnHighlightColors, EAknsCIQsnTextColorsCG3);
   346                 AknsUtils::GetCachedColor( skin, ret, KAknsIIDQsnHighlightColors,
       
   347                         EAknsCIQsnTextColorsCG3 );
   354                 }
   348                 }
   355             else // default
   349             else // default
   356                 {
   350                 {
   357                 AknsUtils::GetCachedColor(skin, ret, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG24);
   351                 AknsUtils::GetCachedColor( skin, ret, KAknsIIDQsnTextColors, 
   358                 }
   352                         EAknsCIQsnTextColorsCG24 );
   359             }
   353                 }
   360         }
   354             }
   361     else if (aColorIndex==TLogicalRgb::ESystemSelectionBackgroundIndex)
   355         }
       
   356     else if ( aColorIndex==TLogicalRgb::ESystemSelectionBackgroundIndex )
   362         {
   357         {
   363         ret = KRgbBlue;
   358         ret = KRgbBlue;
   364         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   359         if ( skin )
   365         if (skin)
       
   366             {
   360             {
   367             if ( iEdwin.HighlightStyle() == EEikEdwinHighlightLink )
   361             if ( iEdwin.HighlightStyle() == EEikEdwinHighlightLink )
   368                 {
   362                 {
   369                 AknsUtils::GetCachedColor(skin, ret, KAknsIIDQsnHighlightColors, EAknsCIQsnTextColorsCG1);
   363                 AknsUtils::GetCachedColor( skin, ret, KAknsIIDQsnHighlightColors, 
       
   364                         EAknsCIQsnTextColorsCG1 );
   370                 }
   365                 }
   371             else // default
   366             else // default
   372                 {
   367                 {
   373                 AknsUtils::GetCachedColor(skin, ret, KAknsIIDQsnHighlightColors, EAknsCIQsnHighlightColorsCG2);
   368                 AknsUtils::GetCachedColor( skin, ret, KAknsIIDQsnHighlightColors, 
       
   369                         EAknsCIQsnHighlightColorsCG2 );
   374                 }
   370                 }
   375             }
   371             }
   376         }
   372         }
   377 
   373 
   378     return ret;
   374     return ret;
   406             bitmapGc = &(iControl.SystemGc());
   402             bitmapGc = &(iControl.SystemGc());
   407 #endif //RD_UI_TRANSITION_EFFECTS_POPUPS
   403 #endif //RD_UI_TRANSITION_EFFECTS_POPUPS
   408         if ( bitmapGc && iEdwin.SkinEnabled() )
   404         if ( bitmapGc && iEdwin.SkinEnabled() )
   409             {
   405             {
   410             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   406             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   411             // Edwin manages the skin background
   407             if ( skin )
   412             MAknsControlContext* edCc = iEdwin.SkinBackgroundControlContext();
   408                 {
   413 
   409                 if ( AknsDrawUtils::DrawBackground( 
   414             TInt drawFlags = KAknsDrawParamDefault;
   410                         skin, 
   415             if( CAknEnv::Static()->TransparencyEnabled() )
   411                         iEdwin.SkinBackgroundControlContext(),
   416             {
   412                         &iControl,
   417                 drawFlags |= KAknsDrawParamNoClearUnderImage;
   413                         *bitmapGc,
   418             }
   414                         aRect.iTl,
   419 
   415                         aRect,
   420             if( AknsDrawUtils::DrawBackground( skin, edCc,
   416                         KAknsDrawParamNoClearUnderImage ) )
   421                     &iControl, *bitmapGc, aRect.iTl, aRect,
   417                     {
   422                     drawFlags ))
   418                     aDrawnRect = aRect;
   423                 {
   419                     drawn = ETrue;
   424                 aDrawnRect = aRect;
   420                     }
   425                 drawn = ETrue;
       
   426                 }
   421                 }
   427             }
   422             }
   428         else
   423         else
   429             {
   424             {
   430             // perform unoptimized draw of skin using bitmap brushstyle?
   425             // perform unoptimized draw of skin using bitmap brushstyle?
   724                     DrawLineAndRecord( aParam.iGc, aUnderlineRect, startPoint, lastPos+1, row, lengthDrawnOnThisLine, numberSegmentsDrawn);
   719                     DrawLineAndRecord( aParam.iGc, aUnderlineRect, startPoint, lastPos+1, row, lengthDrawnOnThisLine, numberSegmentsDrawn);
   725                     }
   720                     }
   726                 }
   721                 }
   727             }
   722             }
   728 
   723 
   729         maxPercentOfALineDrawn = Max( maxPercentOfALineDrawn, (lengthDrawnOnThisLine * 100 )/aUnderlineRect.Width()  );
   724         maxPercentOfALineDrawn = Max( maxPercentOfALineDrawn, 
       
   725                 ( lengthDrawnOnThisLine * KOneHundred )/aUnderlineRect.Width() );
   730         } // end of for loop over rows
   726         } // end of for loop over rows
   731 
   727 
   732     util.End();
   728     util.End();
   733 
   729 
   734     // Check criteria for whether to say this was successful or not.
   730     // Check criteria for whether to say this was successful or not.