|
1 /* |
|
2 * Copyright (c) 2003-2006 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: Implementation class for TextBoxEdwinCustomDraw |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ========== INCLUDE FILES ================================ |
|
21 |
|
22 // using CGulIcon API for iIcon |
|
23 #include <gulicon.h> |
|
24 // constants from TMifAvkon enumeration used when creating iIcon |
|
25 #include <avkon.mbg> |
|
26 #include <avkon.hrh> |
|
27 // CLafEdwinCustomDrawBase |
|
28 #include <eikedwin.h> |
|
29 // AknsUtils::CreateGulIconL |
|
30 // AknIconUtils::SetSize |
|
31 // MAknsSkinInstance* skin = AknsUtils::SkinInstance() |
|
32 #include <AknsUtils.h> |
|
33 // LAF |
|
34 // used in GetLayoutRectAndSetLineDelta function |
|
35 #include <aknlayoutscalable_avkon.cdl.h> // LAF |
|
36 |
|
37 #include <data_caging_path_literals.hrh> |
|
38 |
|
39 #include <s60commonutils.h> |
|
40 |
|
41 #include "CMIDTextBoxEdwinCustomDraw.h" |
|
42 |
|
43 // ========== CONSTANTS ==================================== |
|
44 |
|
45 _LIT(KAvkonMbmFileName, "avkon2.mbm"); |
|
46 |
|
47 |
|
48 // ========== MEMBER FUNCTIONS ============================= |
|
49 |
|
50 // --------------------------------------------------------- |
|
51 // CMIDTextBoxEdwinCustomDraw::NewL |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 CMIDTextBoxEdwinCustomDraw* CMIDTextBoxEdwinCustomDraw::NewL(const MLafEnv& aEnv, |
|
55 const MFormCustomDraw* aParentCustomDraw, |
|
56 const CEikEdwin* aParentControl) |
|
57 { |
|
58 CMIDTextBoxEdwinCustomDraw* self = new(ELeave) CMIDTextBoxEdwinCustomDraw(aEnv, |
|
59 aParentCustomDraw, |
|
60 aParentControl); |
|
61 |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CMIDTextBoxEdwinCustomDraw::ConstructL |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 void CMIDTextBoxEdwinCustomDraw::ConstructL() |
|
74 { |
|
75 // Get resource file name |
|
76 TFileName fileName; |
|
77 fileName.Append(KDC_APP_BITMAP_DIR); |
|
78 fileName.Append(KAvkonMbmFileName); |
|
79 fileName = java::util::S60CommonUtils::VerifiedFileNameL(fileName); |
|
80 |
|
81 iIcon = AknsUtils::CreateGulIconL(AknsUtils::SkinInstance(), |
|
82 KAknsIIDQgnGrafLinePrimaryHorizontal, |
|
83 fileName, |
|
84 EMbmAvkonQgn_graf_line_primary_horizontal, |
|
85 EMbmAvkonQgn_graf_line_primary_horizontal_mask); |
|
86 } |
|
87 |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CMIDTextBoxEdwinCustomDraw::CMIDTextBoxEdwinCustomDraw |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 CMIDTextBoxEdwinCustomDraw::CMIDTextBoxEdwinCustomDraw(const MLafEnv& aEnv, |
|
94 const MFormCustomDraw* aParentCustomDraw, |
|
95 const CEikEdwin* aParentControl) : |
|
96 CLafEdwinCustomDrawBase(aEnv,*aParentControl), |
|
97 iParentControl(aParentControl), |
|
98 iParentCustomDraw(aParentCustomDraw) |
|
99 { |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------- |
|
103 // CMIDTextBoxEdwinCustomDraw::~CMIDTextBoxEdwinCustomDraw |
|
104 // --------------------------------------------------------- |
|
105 // |
|
106 CMIDTextBoxEdwinCustomDraw::~CMIDTextBoxEdwinCustomDraw() |
|
107 { |
|
108 if (iRects) |
|
109 { |
|
110 iRects->ResetAndDestroy(); |
|
111 delete iRects; |
|
112 } |
|
113 |
|
114 delete iIcon; |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CMIDTextBoxEdwinCustomDraw::CreateRectsIfNeededL |
|
119 // --------------------------------------------------------- |
|
120 // |
|
121 void CMIDTextBoxEdwinCustomDraw::CreateRectsIfNeededL() |
|
122 { |
|
123 if ((!iRects && iNumberOfLinesInBody > 0) |
|
124 || (iRects && (iNumberOfLinesInBody >= iRects->Count()))) |
|
125 { |
|
126 if (!iRects) |
|
127 { |
|
128 iRects = new(ELeave) CArrayPtrFlat<TRect>(iNumberOfLinesInBody); |
|
129 } |
|
130 |
|
131 iRects->SetReserveL(iNumberOfLinesInBody); |
|
132 |
|
133 TRect* rect = NULL; |
|
134 for (TUint i = iRects->Count(); i < iNumberOfLinesInBody; i++) |
|
135 { |
|
136 rect = new(ELeave) TRect; |
|
137 CleanupStack::PushL(rect); |
|
138 iRects->InsertL(i, rect); |
|
139 CleanupStack::Pop(rect); |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CMIDTextBoxEdwinCustomDraw::GetLayoutRectAndSetLineDelta |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 TAknLayoutRect CMIDTextBoxEdwinCustomDraw::GetLayoutRectAndSetLineDelta( |
|
149 TRect& aRect, |
|
150 TUint8& aLineTopOffset) |
|
151 { |
|
152 iLineDelta = 0; |
|
153 aLineTopOffset = 0; |
|
154 |
|
155 TAknWindowLineLayout listSinglePaneLayout = |
|
156 AknLayoutScalable_Avkon::list_single_midp_pane(0).LayoutLine(); |
|
157 |
|
158 // get the top margin for list_single_midp_pane: |
|
159 // used for offset-ing the iLineDelta |
|
160 aLineTopOffset = listSinglePaneLayout.it; |
|
161 |
|
162 TAknLayoutRect listSinglePane; |
|
163 listSinglePane.LayoutRect(aRect, listSinglePaneLayout); |
|
164 |
|
165 TAknLayoutRect horizLinePaneLayout; |
|
166 horizLinePaneLayout.LayoutRect( |
|
167 listSinglePane.Rect(), |
|
168 AknLayoutScalable_Avkon::list_single_midp_pane_g1().LayoutLine()); |
|
169 |
|
170 iLineDelta = listSinglePane.Rect().Height(); |
|
171 ASSERT(iLineDelta > 0); |
|
172 |
|
173 return horizLinePaneLayout; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CMIDTextBoxEdwinCustomDraw::CalculateLayout |
|
178 // --------------------------------------------------------- |
|
179 // |
|
180 void CMIDTextBoxEdwinCustomDraw::CalculateLayout(TRect aParentRect) |
|
181 { |
|
182 TRect mainPane = aParentRect; |
|
183 |
|
184 TUint8 lineTopOffset; |
|
185 TAknLayoutRect lineLayout = GetLayoutRectAndSetLineDelta(mainPane, |
|
186 lineTopOffset); |
|
187 |
|
188 iNumberOfLinesInBody = (mainPane.Height() - lineTopOffset) / iLineDelta; |
|
189 |
|
190 TRAPD(err, CreateRectsIfNeededL()); |
|
191 if (err != KErrNone) |
|
192 { |
|
193 return; |
|
194 } |
|
195 |
|
196 TRect lineRect = lineLayout.Rect(); |
|
197 |
|
198 TUint i; |
|
199 for (i = 0; i < iNumberOfLinesInBody; i++) |
|
200 { |
|
201 *(iRects->At(i)) = lineRect; |
|
202 lineRect.Move(0, iLineDelta); |
|
203 } |
|
204 |
|
205 AknIconUtils::SetSize(iIcon->Bitmap(), |
|
206 lineLayout.Rect().Size(), |
|
207 EAspectRatioNotPreserved); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------- |
|
211 // CMIDTextBoxEdwinCustomDraw::DrawBackground |
|
212 // --------------------------------------------------------- |
|
213 // |
|
214 void CMIDTextBoxEdwinCustomDraw::DrawBackground(const TParam& aParam, |
|
215 const TRgb& aRgb, |
|
216 TRect& aDrawn) const |
|
217 { |
|
218 iParentCustomDraw->DrawBackground(aParam, aRgb, aDrawn); |
|
219 |
|
220 DrawEditorLines(aParam, aDrawn); |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CMIDTextBoxEdwinCustomDraw::DrawLineGraphics |
|
225 // --------------------------------------------------------- |
|
226 // |
|
227 void CMIDTextBoxEdwinCustomDraw::DrawLineGraphics(const TParam& aParam, |
|
228 const TLineInfo& aLineInfo) const |
|
229 { |
|
230 iParentCustomDraw->DrawLineGraphics(aParam, aLineInfo); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------- |
|
234 // CMIDTextBoxEdwinCustomDraw::DrawText |
|
235 // --------------------------------------------------------- |
|
236 // |
|
237 void CMIDTextBoxEdwinCustomDraw::DrawText(const TParam& aParam, |
|
238 const TLineInfo& aLineInfo, |
|
239 const TCharFormat& aFormat, |
|
240 const TDesC& aText, |
|
241 const TPoint& aTextOrigin, |
|
242 TInt aExtraPixels) const |
|
243 { |
|
244 iParentCustomDraw->DrawText(aParam, |
|
245 aLineInfo, |
|
246 aFormat, |
|
247 aText, |
|
248 aTextOrigin, |
|
249 aExtraPixels); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------- |
|
253 // CMIDTextBoxEdwinCustomDraw::SystemColor |
|
254 // --------------------------------------------------------- |
|
255 // |
|
256 TRgb CMIDTextBoxEdwinCustomDraw::SystemColor(TUint aColorIndex, TRgb aDefaultColor) const |
|
257 { |
|
258 return iParentCustomDraw->SystemColor(aColorIndex, aDefaultColor); |
|
259 } |
|
260 |
|
261 // --------------------------------------------------------- |
|
262 // CMIDTextBoxEdwinCustomDraw::DrawEditorLines |
|
263 // --------------------------------------------------------- |
|
264 // |
|
265 void CMIDTextBoxEdwinCustomDraw::DrawEditorLines(const TParam& aParam, TRect& aDrawn) const |
|
266 { |
|
267 if (!iRects) |
|
268 {// may happen only in OOM |
|
269 return; |
|
270 } |
|
271 |
|
272 for (TUint i = 0; i < iNumberOfLinesInBody; i++) |
|
273 { |
|
274 // Find out of TRect where will line drawn |
|
275 TRect currentRect = *(iRects->At(i)); |
|
276 if (aDrawn.Intersects(currentRect)) // draw only if it is inside the area to be re-drawn |
|
277 // Drawing of line |
|
278 aParam.iGc.DrawBitmapMasked(currentRect, |
|
279 iIcon->Bitmap(), |
|
280 TRect(TPoint(0 ,0), currentRect.Size()), |
|
281 iIcon->Mask(), |
|
282 ETrue); |
|
283 } |
|
284 } |
|
285 |
|
286 // --------------------------------------------------------- |
|
287 // CMIDTextBoxEdwinCustomDraw::UpdateIconL |
|
288 // --------------------------------------------------------- |
|
289 // |
|
290 void CMIDTextBoxEdwinCustomDraw::UpdateIconL() |
|
291 { |
|
292 // Find of actual skin |
|
293 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
294 // Get resource file name |
|
295 TFileName fileName; |
|
296 fileName.Append(KDC_APP_BITMAP_DIR); |
|
297 fileName.Append(KAvkonMbmFileName); |
|
298 fileName = java::util::S60CommonUtils::VerifiedFileNameL(fileName); |
|
299 |
|
300 // Update of icon. |
|
301 iIcon = AknsUtils::CreateGulIconL(skin, |
|
302 KAknsIIDQgnGrafLinePrimaryHorizontal, |
|
303 fileName, |
|
304 EMbmAvkonQgn_graf_line_primary_horizontal, |
|
305 EMbmAvkonQgn_graf_line_primary_horizontal_mask); |
|
306 } |
|
307 |
|
308 // End of File |