emailuis/emailui/src/ncseditorcustomdraw.cpp
changeset 0 8466d47a6819
child 19 b13141f05c3d
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Custom draw component for message editor.
       
    15 *
       
    16 */
       
    17 #include <aknlayoutscalable_apps.cdl.h>
       
    18 #include <AknLayoutFont.h>
       
    19 #include "emailtrace.h"
       
    20 #include "ncseditorcustomdraw.h"
       
    21 #include "ncseditor.h"
       
    22 #include "ncsconstants.h"
       
    23 
       
    24 const TInt KFSColorDarkeningDegree = 3;
       
    25 
       
    26 // ========================= MEMBER FUNCTIONS ==================================
       
    27 
       
    28 CNcsEditorCustomDraw* CNcsEditorCustomDraw::NewL( const MFormCustomDraw* aParentCustomDraw,
       
    29                                                   const CNcsEditor* aParentControl,
       
    30                                                   const TAknTextComponentLayout aLayout )
       
    31     {
       
    32     CNcsEditorCustomDraw* self = new (ELeave) CNcsEditorCustomDraw( aParentCustomDraw,
       
    33                                                                     aParentControl,
       
    34                                                                     aLayout );
       
    35     
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     
       
    40     return self;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CNcsEditorCustomDraw::CNcsEditorCustomDraw
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CNcsEditorCustomDraw::CNcsEditorCustomDraw( const MFormCustomDraw* aParentCustomDraw,
       
    48                                             const CNcsEditor* aParentControl,
       
    49                                             const TAknTextComponentLayout aLayout ) :
       
    50                                             iCustomDrawer( aParentCustomDraw ),
       
    51                                             iEditor( aParentControl )
       
    52     {
       
    53     FUNC_LOG;
       
    54     UpdateLayout( aLayout );
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CMsgEditorCustomDraw::ConstructL
       
    59 // ---------------------------------------------------------
       
    60 //
       
    61 void CNcsEditorCustomDraw::ConstructL()
       
    62     {
       
    63     FUNC_LOG;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CNcsEditorCustomDraw::~CNcsEditorCustomDraw
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CNcsEditorCustomDraw::~CNcsEditorCustomDraw()
       
    71     {
       
    72     FUNC_LOG;
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // CNcsEditorCustomDraw::DrawBackground
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 void CNcsEditorCustomDraw::DrawBackground(
       
    80     const TParam& aParam,
       
    81     const TRgb& aBackground,
       
    82     TRect& aDrawn ) const
       
    83     {
       
    84     FUNC_LOG;
       
    85     iCustomDrawer->DrawBackground( aParam, aBackground, aDrawn );
       
    86     TInt lineHeigth( 0 );
       
    87     TRAP_IGNORE( lineHeigth = iEditor->GetLineHeightL() );
       
    88 
       
    89     TAknTextDecorationMetrics decorationMetrics( iTextPaneLayout.LayoutLine().FontId() );
       
    90     TInt topMargin, bottomMargin;
       
    91     decorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin );
       
    92 
       
    93     TInt lineOffset = iTextPaneLayout.H() + topMargin + bottomMargin;
       
    94     
       
    95     TRgb lineColor = NcsUtility::CalculateMsgBodyLineColor( KFSColorDarkeningDegree, 
       
    96                                                             NcsUtility::SeparatorLineColor() );
       
    97     aParam.iGc.SetPenColor( lineColor );
       
    98 
       
    99     TInt margin( 0 );
       
   100     if ( aParam.iDrawRect.Height() < lineHeigth ||
       
   101          aParam.iDrawRect.Height() == lineOffset )
       
   102         {
       
   103         margin = 1;
       
   104         }
       
   105 
       
   106     TRect currentRect( aParam.iDrawRect.iTl , TPoint( aParam.iDrawRect.iBr.iX, aParam.iDrawRect.iTl.iY + lineOffset - margin ));
       
   107     
       
   108     while ( currentRect.iBr.iY <= aParam.iDrawRect.iBr.iY )
       
   109         {
       
   110         if ( currentRect.iTl.iY >= aParam.iDrawRect.iTl.iY  )
       
   111             {
       
   112             aParam.iGc.DrawLine( TPoint( currentRect.iTl.iX, currentRect.iBr.iY), currentRect.iBr );
       
   113             }
       
   114         currentRect.Move( 0, lineHeigth );
       
   115         }
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CNcsEditorCustomDraw::DrawLineGraphics
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CNcsEditorCustomDraw::DrawLineGraphics( const TParam& aParam,
       
   123                                              const TLineInfo& aLineInfo ) const
       
   124     {
       
   125     FUNC_LOG;
       
   126     iCustomDrawer->DrawLineGraphics( aParam, aLineInfo );
       
   127     }
       
   128 	
       
   129 // ---------------------------------------------------------------------------
       
   130 // CNcsEditorCustomDraw::DrawText
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CNcsEditorCustomDraw::DrawText( const TParam& aParam,
       
   134                                const TLineInfo& aLineInfo,
       
   135                                const TCharFormat& aFormat,
       
   136                                const TDesC& aText,
       
   137                                const TPoint& aTextOrigin,
       
   138                                TInt aExtraPixels ) const
       
   139     {
       
   140     FUNC_LOG;
       
   141     iCustomDrawer->DrawText( aParam,
       
   142                              aLineInfo,
       
   143                              aFormat,
       
   144                              aText,
       
   145                              aTextOrigin,
       
   146                              aExtraPixels );
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CNcsEditorCustomDraw::SystemColor
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 TRgb CNcsEditorCustomDraw::SystemColor( TUint aColorIndex, TRgb aDefaultColor ) const
       
   154     {
       
   155     FUNC_LOG;
       
   156     return iCustomDrawer->SystemColor( aColorIndex, aDefaultColor );
       
   157     }
       
   158 
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CNcsEditorCustomDraw::UpdateLayout
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 void CNcsEditorCustomDraw::UpdateLayout( TAknTextComponentLayout aLayout )
       
   165     {
       
   166     iTextPaneLayout = aLayout;
       
   167     }