|
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 TRect drawRect( aParam.iDrawRect ); |
|
86 |
|
87 if ( iPrevBrX == 0 ) |
|
88 { |
|
89 const_cast<CNcsEditorCustomDraw*>(this)->iPrevBrX = drawRect.iBr.iX; |
|
90 } |
|
91 |
|
92 // draw background if text selection is ongoing |
|
93 if ( !iEditor->IsPhysicsEmulationOngoing() ) |
|
94 { |
|
95 iCustomDrawer->DrawBackground( aParam, aBackground, aDrawn ); |
|
96 } |
|
97 else |
|
98 { |
|
99 aDrawn = aParam.iDrawRect; |
|
100 } |
|
101 |
|
102 if ( drawRect.iTl.iY == 0 ) |
|
103 { |
|
104 drawRect.iTl.iY = drawRect.Height() - iLineHeigth; |
|
105 } |
|
106 |
|
107 if ( drawRect.iTl.iX < iPrevBrX ) |
|
108 { |
|
109 aParam.iGc.SetPenColor( iLineColor ); |
|
110 |
|
111 TInt margin( 0 ); |
|
112 if ( drawRect.Height() < iLineHeigth || |
|
113 drawRect.Height() == iLineOffset ) |
|
114 { |
|
115 margin = 1; |
|
116 } |
|
117 |
|
118 TRect currentRect( drawRect.iTl , TPoint( drawRect.iBr.iX, drawRect.iTl.iY + iLineOffset - margin )); |
|
119 |
|
120 while ( currentRect.iBr.iY <= drawRect.iBr.iY ) |
|
121 { |
|
122 if ( currentRect.iTl.iY >= drawRect.iTl.iY ) |
|
123 { |
|
124 aParam.iGc.DrawLine( TPoint( currentRect.iTl.iX, currentRect.iBr.iY), currentRect.iBr ); |
|
125 } |
|
126 currentRect.Move( 0, iLineHeigth ); |
|
127 } |
|
128 const_cast<CNcsEditorCustomDraw*>(this)->iPrevBrX = drawRect.iBr.iX; |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CNcsEditorCustomDraw::DrawLineGraphics |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void CNcsEditorCustomDraw::DrawLineGraphics( const TParam& aParam, |
|
137 const TLineInfo& aLineInfo ) const |
|
138 { |
|
139 FUNC_LOG; |
|
140 iCustomDrawer->DrawLineGraphics( aParam, aLineInfo ); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CNcsEditorCustomDraw::DrawText |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CNcsEditorCustomDraw::DrawText( const TParam& aParam, |
|
148 const TLineInfo& aLineInfo, |
|
149 const TCharFormat& aFormat, |
|
150 const TDesC& aText, |
|
151 const TPoint& aTextOrigin, |
|
152 TInt aExtraPixels ) const |
|
153 { |
|
154 FUNC_LOG; |
|
155 iCustomDrawer->DrawText( aParam, |
|
156 aLineInfo, |
|
157 aFormat, |
|
158 aText, |
|
159 aTextOrigin, |
|
160 aExtraPixels ); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------------------------- |
|
164 // CNcsEditorCustomDraw::SystemColor |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 TRgb CNcsEditorCustomDraw::SystemColor( TUint aColorIndex, TRgb aDefaultColor ) const |
|
168 { |
|
169 FUNC_LOG; |
|
170 return iCustomDrawer->SystemColor( aColorIndex, aDefaultColor ); |
|
171 } |
|
172 |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // CNcsEditorCustomDraw::UpdateLayout |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 void CNcsEditorCustomDraw::UpdateLayout( TAknTextComponentLayout aLayout ) |
|
179 { |
|
180 iTextPaneLayout = aLayout; |
|
181 TRAP_IGNORE( iLineHeigth = iEditor->GetLineHeightL() ); |
|
182 iLineColor = NcsUtility::CalculateMsgBodyLineColor( KFSColorDarkeningDegree, |
|
183 NcsUtility::SeparatorLineColor() ); |
|
184 TAknTextDecorationMetrics decorationMetrics( iTextPaneLayout.LayoutLine().FontId() ); |
|
185 TInt topMargin, bottomMargin; |
|
186 decorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin ); |
|
187 |
|
188 iLineOffset = iTextPaneLayout.H() + topMargin + bottomMargin; |
|
189 } |