|
1 /* |
|
2 * Copyright (c) 2007 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 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <AknsUtils.h> |
|
21 #include <AknsSkinInstance.h> |
|
22 #include <AknsConstants.h> |
|
23 |
|
24 #include "ncscustomdraw.h" |
|
25 #include "ncseditor.h" |
|
26 |
|
27 // ========================= MEMBER FUNCTIONS ================================== |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CNcsCustomDraw::CNcsCustomDraw |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 CNcsCustomDraw::CNcsCustomDraw( |
|
34 const MLafEnv& aEnv, |
|
35 const CCoeControl& aControl, |
|
36 CLafEdwinCustomDrawBase* aCustomDrawer, |
|
37 CNcsEditor* aEditor, |
|
38 TBool aHeaderField ) : |
|
39 CLafEdwinCustomDrawBase( aEnv, aControl ), iCustomDrawer( aCustomDrawer ), |
|
40 iEditor( aEditor ), iHeaderField( aHeaderField ) |
|
41 { |
|
42 FUNC_LOG; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CNcsCustomDraw::~CNcsCustomDraw |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CNcsCustomDraw::~CNcsCustomDraw() |
|
50 { |
|
51 FUNC_LOG; |
|
52 delete iCustomDrawer; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CNcsCustomDraw::UpdateColors |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 void CNcsCustomDraw::UpdateColors() |
|
60 { |
|
61 FUNC_LOG; |
|
62 iColors = 0; |
|
63 |
|
64 TInt err = KErrNotFound; |
|
65 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
66 |
|
67 if ( iHeaderField ) |
|
68 { |
|
69 err = AknsUtils::GetCachedColor( |
|
70 skin, |
|
71 iBackgroundColor, |
|
72 KAknsIIDFsOtherColors, |
|
73 EAknsCIFsOtherColorsCG12 ); |
|
74 |
|
75 if ( err == KErrNone ) |
|
76 { |
|
77 SetHasColor( EColorBackground ); |
|
78 } |
|
79 } |
|
80 |
|
81 err = AknsUtils::GetCachedColor( |
|
82 skin, |
|
83 iSelectionTextColor, |
|
84 KAknsIIDFsTextColors, |
|
85 EAknsCIFsTextColorsCG5 ); |
|
86 |
|
87 if ( err == KErrNone ) |
|
88 { |
|
89 SetHasColor( EColorSelectionText ); |
|
90 } |
|
91 |
|
92 err = AknsUtils::GetCachedColor( |
|
93 skin, |
|
94 iSelectionBackgroundColor, |
|
95 KAknsIIDFsHighlightColors, |
|
96 EAknsCIFsHighlightColorsCG2 ); |
|
97 |
|
98 if ( err == KErrNone ) |
|
99 { |
|
100 SetHasColor( EColorSelectionBackground ); |
|
101 } |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CNcsCustomDraw::DrawBackground |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CNcsCustomDraw::DrawBackground( |
|
109 const TParam& aParam, |
|
110 const TRgb& aBackground, |
|
111 TRect& aDrawn ) const |
|
112 { |
|
113 FUNC_LOG; |
|
114 // Use custom drawing for fields with background color. Othwerwise use |
|
115 // the base implementation which draws white background. |
|
116 if ( HasColor( EColorBackground ) ) |
|
117 { |
|
118 iCustomDrawer->DrawBackground( aParam, iBackgroundColor, aDrawn ); |
|
119 } |
|
120 else |
|
121 { |
|
122 CLafEdwinCustomDrawBase::DrawBackground( aParam, aBackground, aDrawn ); |
|
123 } |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CNcsCustomDraw::DrawLineGraphics |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 void CNcsCustomDraw::DrawLineGraphics( |
|
131 const TParam& aParam, |
|
132 const TLineInfo& aLineInfo ) const |
|
133 { |
|
134 FUNC_LOG; |
|
135 iCustomDrawer->DrawLineGraphics( aParam, aLineInfo ); |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CNcsCustomDraw::DrawText |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 void CNcsCustomDraw::DrawText( |
|
143 const TParam& aParam, |
|
144 const TLineInfo& aLineInfo, |
|
145 const TCharFormat& aFormat, |
|
146 const TDesC& aText, |
|
147 const TPoint& aTextOrigin, |
|
148 TInt aExtraPixels ) const |
|
149 { |
|
150 FUNC_LOG; |
|
151 iCustomDrawer->DrawText( |
|
152 aParam, |
|
153 aLineInfo, |
|
154 aFormat, |
|
155 aText, |
|
156 aTextOrigin, |
|
157 aExtraPixels ); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CNcsCustomDraw::SystemColor |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 TRgb CNcsCustomDraw::SystemColor( TUint aColorIndex, TRgb aDefaultColor ) const |
|
165 { |
|
166 FUNC_LOG; |
|
167 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
168 |
|
169 TInt err = KErrNotFound; |
|
170 TRgb ret = aDefaultColor; |
|
171 |
|
172 if ( aColorIndex == TLogicalRgb::ESystemSelectionForegroundIndex ) |
|
173 { |
|
174 if ( HasColor( EColorSelectionText ) ) |
|
175 { |
|
176 err = KErrNone; |
|
177 ret = iSelectionTextColor; |
|
178 } |
|
179 } |
|
180 else if ( aColorIndex == TLogicalRgb::ESystemSelectionBackgroundIndex ) |
|
181 { |
|
182 if ( HasColor( EColorSelectionBackground ) ) |
|
183 { |
|
184 err = KErrNone; |
|
185 ret = iSelectionBackgroundColor; |
|
186 } |
|
187 } |
|
188 |
|
189 if ( err != KErrNone ) |
|
190 { |
|
191 return iCustomDrawer->SystemColor( aColorIndex, aDefaultColor ); |
|
192 } |
|
193 else |
|
194 { |
|
195 return ret; |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // CNcsCustomDraw::SetHasColor |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 void CNcsCustomDraw::SetHasColor( TColors aColor ) |
|
204 { |
|
205 FUNC_LOG; |
|
206 iColors |= ( TInt )aColor; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // CNcsCustomDraw::HasColor |
|
211 // --------------------------------------------------------------------------- |
|
212 // |
|
213 TBool CNcsCustomDraw::HasColor( TColors aColor ) const |
|
214 { |
|
215 FUNC_LOG; |
|
216 TInt color = ( TInt )aColor; |
|
217 return iColors & color; |
|
218 } |
|
219 |