|
1 /* |
|
2 * Copyright (c) 2003 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: CScreensaverIndicatorNumberAndIcon implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <barsread.h> |
|
21 #include <AknsUtils.h> |
|
22 #include <AknLayoutFont.h> |
|
23 |
|
24 #include "screensaverindicatornumberandicon.h" |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CScreensaverNumberAndIconIndicator::~CScreensaverNumberAndIconIndicator |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CScreensaverIndicatorNumberAndIcon::~CScreensaverIndicatorNumberAndIcon() |
|
32 { |
|
33 delete iIcon; |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CScreensaverNumberAndIconIndicator::Draw |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void CScreensaverIndicatorNumberAndIcon::Draw( CWindowGc& aGc ) const |
|
41 { |
|
42 TBuf<10> nStr; |
|
43 nStr.AppendNum( iValue ); |
|
44 |
|
45 aGc.SetPenColor( iTextColor ); |
|
46 aGc.SetBrushColor( iBgColor ); |
|
47 |
|
48 if ( iFont ) |
|
49 { |
|
50 aGc.UseFont( iFont ); |
|
51 } |
|
52 else |
|
53 { |
|
54 ASSERT( iFont != NULL ); |
|
55 aGc.UseFont( CEikonEnv::Static()->AnnotationFont() ); |
|
56 } |
|
57 |
|
58 if ( Visible() && iIcon ) |
|
59 { |
|
60 // Convert number according to language |
|
61 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( nStr ); |
|
62 |
|
63 DrawIcon( aGc ); |
|
64 |
|
65 // Draw number beside icon |
|
66 if ( ( iTextRect.IsEmpty() ) || ( !iFont ) ) |
|
67 { |
|
68 // Draw using text position (old layout) |
|
69 aGc.DrawText( nStr, iTextPos ); |
|
70 } |
|
71 else |
|
72 { |
|
73 // Use text rect |
|
74 ASSERT( iTextOffset> 0 ); |
|
75 aGc.DrawText( nStr, iTextRect, iTextOffset ); |
|
76 } |
|
77 } |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CScreensaverNumberAndIconIndicator::ConstructL |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CScreensaverIndicatorNumberAndIcon::ConstructL( TResourceReader &aReader, |
|
85 TUint32 aBgColor, TUint aTextColor ) |
|
86 { |
|
87 CScreensaverIndicator::ConstructL( aReader, aBgColor, aTextColor ); |
|
88 |
|
89 iIconAlign = ( TScreensaverAlignment )aReader.ReadInt32(); |
|
90 iFont = AknLayoutUtils::FontFromId( aReader.ReadInt32() ); |
|
91 if ( !iFont ) |
|
92 { |
|
93 iFont = LatinPlain12(); |
|
94 } |
|
95 |
|
96 // create icon |
|
97 InitializeIconL( aReader ); |
|
98 |
|
99 // Set desired size for SVG graphics (height from LAF, width 3 x height) |
|
100 InitializeLayout(); |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CScreensaverNumberAndIconIndicator::SetupDrawingParameters |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 void CScreensaverIndicatorNumberAndIcon::SetupDrawingParameters( |
|
108 const TPoint& aCorner, const TRect& aParentRect ) |
|
109 { |
|
110 iVisible = EFalse; |
|
111 |
|
112 TBuf<10> nStr; |
|
113 |
|
114 if ( !iIcon ) |
|
115 { |
|
116 return; |
|
117 } |
|
118 |
|
119 nStr.AppendNum( iValue ); |
|
120 |
|
121 TSize bmsize = iIcon->Bitmap()->SizeInPixels(); |
|
122 TInt textWidth = iFont ? iFont->TextWidthInPixels( nStr ) + 1 : nStr.Length() |
|
123 * 11; // Should be enough for APAC too |
|
124 |
|
125 iTopLeft.iX = aCorner.iX; |
|
126 if ( iAlignment == ESsAlignRight ) |
|
127 { |
|
128 // Change topright to topleft. |
|
129 iTopLeft.iX -= bmsize.iWidth + textWidth; |
|
130 } |
|
131 // Center bitmap in y direction. |
|
132 iTopLeft.iY = aCorner.iY + ( aParentRect.Size().iHeight / 2 ) - ( bmsize.iHeight / 2 ) - 2; |
|
133 |
|
134 // Calculate text corner |
|
135 if ( iIconAlign == ESsAlignLeft ) |
|
136 { |
|
137 iTextPos.iX = iTopLeft.iX + bmsize.iWidth + 1; |
|
138 } |
|
139 else |
|
140 { |
|
141 iTextPos.iX = iTopLeft.iX; |
|
142 } |
|
143 |
|
144 iTextPos.iY = aCorner.iY + iRect.Size().iHeight / 2 + 4; |
|
145 |
|
146 iRect = TRect( 0, 0, bmsize.iWidth + textWidth, aParentRect.Size().iHeight ); |
|
147 |
|
148 // Make sure text rect is not used |
|
149 iTextRect.SetRect( 0, 0, 0, 0 ); |
|
150 |
|
151 iVisible = ETrue; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CScreensaverNumberAndIconIndicator::CheckVisibilityConditions |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 TBool CScreensaverIndicatorNumberAndIcon::CheckVisibilityConditions() const |
|
159 { |
|
160 if ( ( iIcon ) && ( iValue > 0 ) ) |
|
161 { |
|
162 return ETrue; |
|
163 } |
|
164 |
|
165 return EFalse; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CScreensaverNumberAndIconIndicator::Payload |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CScreensaverIndicatorNumberAndIcon::Payload( TIndicatorPayload& aPayload ) const |
|
173 { |
|
174 aPayload.iType = EPayloadTypeInteger; |
|
175 aPayload.iInteger = iValue; |
|
176 aPayload.iText = KNullDesC; |
|
177 aPayload.iIsDisplayed = Visible(); |
|
178 aPayload.iIcon = iIcon; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CScreensaverNumberAndIconIndicator::SetPayload |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CScreensaverIndicatorNumberAndIcon::SetPayload( |
|
186 const TIndicatorPayload& aPayload ) |
|
187 { |
|
188 if ( aPayload.iType != EPayloadTypeInteger ) |
|
189 { |
|
190 return; |
|
191 } |
|
192 |
|
193 iValue = aPayload.iInteger; |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CScreensaverNumberAndIconIndicator::SetIconLayout |
|
198 // Sets icon position and size |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 void CScreensaverIndicatorNumberAndIcon::SetIconLayout( TAknLayoutRect& aLayout, |
|
202 TInt aX ) |
|
203 { |
|
204 if ( !iIcon ) |
|
205 { |
|
206 ASSERT( iIcon ); |
|
207 return; |
|
208 } |
|
209 |
|
210 // Resize icon according to layout |
|
211 TInt height = aLayout.Rect().Height(); |
|
212 TSize iconSize(KMaxTInt, height); |
|
213 AknIconUtils::SetSize( iIcon->Bitmap(), iconSize, |
|
214 EAspectRatioPreservedAndUnusedSpaceRemoved ); |
|
215 |
|
216 // Overrides vertical icon position set earlier |
|
217 iTopLeft.iY = aLayout.Rect().iTl.iY; |
|
218 |
|
219 // Set initial rect |
|
220 iRect = TRect( 0, 0, PreferredWidth(), height ); |
|
221 |
|
222 // Set X-position |
|
223 SetXPos( aX ); |
|
224 |
|
225 #ifdef SS_LAYOUTTRACE |
|
226 SCRLOGGER_WRITEF( _L("SCR: NumberAndIcon indicator (%d):"), iId ); |
|
227 SCRLOGGER_WRITEF( _L("SCR: Icon rect: (%d,%d,%d,%d)"), |
|
228 iRect.iTl.iX, |
|
229 iRect.iTl.iY, |
|
230 iRect.iBr.iX, |
|
231 iRect.iBr.iY ); |
|
232 TSize size = iIcon->Bitmap()->SizeInPixels(); |
|
233 SCRLOGGER_WRITEF( _L("SCR: Icon size: (%d,%d)"), size.iWidth, size.iHeight ); |
|
234 SCRLOGGER_WRITEF( _L("SCR: Icon pos: (%d,%d)"), iTopLeft.iX, iTopLeft.iY ); |
|
235 #endif |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CScreensaverNumberAndIconIndicator::SetTextLayout |
|
240 // Sets text position and font |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CScreensaverIndicatorNumberAndIcon::SetTextLayout( TAknLayoutText& aLayout, |
|
244 TInt /* aX */ ) |
|
245 { |
|
246 // Font from layout |
|
247 iFont = aLayout.Font(); |
|
248 // Layout MUST have a font |
|
249 ASSERT( iFont != NULL ); |
|
250 |
|
251 // Vertical dimension of text rect from layout |
|
252 // (x-dims will be set separately) |
|
253 iTextRect = aLayout.TextRect(); |
|
254 |
|
255 // Calculate text offset from rect top |
|
256 const CAknLayoutFont* layoutFont = |
|
257 CAknLayoutFont::AsCAknLayoutFontOrNull( iFont ); |
|
258 |
|
259 if ( layoutFont ) |
|
260 { |
|
261 iTextOffset = layoutFont->TextPaneTopToBaseline(); |
|
262 } |
|
263 else |
|
264 { |
|
265 iTextOffset = iFont->AscentInPixels(); |
|
266 } |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CScreensaverNumberAndIconIndicator::PreferredWidth |
|
271 // Return width where the whole indicator can be drawn |
|
272 // ----------------------------------------------------------------------------- |
|
273 // |
|
274 TInt CScreensaverIndicatorNumberAndIcon::PreferredWidth() |
|
275 { |
|
276 // Preferred width = icon width + text width + a little gap in between |
|
277 TBuf<10> nStr; |
|
278 nStr.AppendNum( iValue ); |
|
279 |
|
280 TInt width = iFont ? iFont->TextWidthInPixels( nStr ) : nStr.Length() * 11; // Should be enough for APAC too |
|
281 |
|
282 // Add icon width |
|
283 width += MinimumWidth(); |
|
284 |
|
285 // Add a little gap between text and icon |
|
286 return width + 1; |
|
287 } |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CScreensaverNumberAndIconIndicator::MinimumWidth |
|
291 // Get minimum width |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 TInt CScreensaverIndicatorNumberAndIcon::MinimumWidth() |
|
295 { |
|
296 // Minimum width is icon width |
|
297 return ( iIcon ? ( iIcon->Bitmap()->SizeInPixels()).iWidth : 0 ); |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // CScreensaverNumberAndIconIndicator::SetXPos |
|
302 // Sets the x-position for the indicator |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CScreensaverIndicatorNumberAndIcon::SetXPos( TInt aX ) |
|
306 { |
|
307 iVisible = EFalse; |
|
308 |
|
309 if ( !iIcon ) |
|
310 { |
|
311 return; |
|
312 } |
|
313 |
|
314 TBuf<10> nStr; |
|
315 nStr.AppendNum( iValue ); |
|
316 |
|
317 TSize bmsize = iIcon->Bitmap()->SizeInPixels(); |
|
318 TInt textWidth = iFont ? iFont->TextWidthInPixels( nStr ) + 1 : nStr.Length() |
|
319 * 11; // Should be enough for APAC too |
|
320 |
|
321 iTopLeft.iX = aX; |
|
322 if ( iAlignment == ESsAlignRight ) |
|
323 { |
|
324 // Change topright to topleft. |
|
325 iTopLeft.iX -= bmsize.iWidth + textWidth; |
|
326 } |
|
327 |
|
328 // Calculate text corner |
|
329 if ( iIconAlign == ESsAlignLeft ) |
|
330 { |
|
331 iTextRect.iTl.iX = iTopLeft.iX + bmsize.iWidth; |
|
332 } |
|
333 else |
|
334 { |
|
335 iTextRect.iTl.iX = iTopLeft.iX; |
|
336 } |
|
337 |
|
338 iTextRect.SetWidth( textWidth ); |
|
339 |
|
340 iVisible = ETrue; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CScreensaverNumberAndIconIndicator::InitializeLayout |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CScreensaverIndicatorNumberAndIcon::InitializeLayout() |
|
348 { |
|
349 // Set desired size for SVG graphics (height from LAF, width 3 x height) |
|
350 TAknLayoutRect screenLayout; |
|
351 screenLayout.LayoutRect( TRect(0, 0, 0, 0), AknLayout::screen() ); |
|
352 TRect screenRect = screenLayout.Rect(); |
|
353 TAknLayoutRect powerSavePaneLayout; |
|
354 powerSavePaneLayout.LayoutRect( screenRect, |
|
355 AknLayout::Power_save_pane_descendants_Line_1() ); |
|
356 TRect powerSavePaneRect = powerSavePaneLayout.Rect(); |
|
357 TAknLayoutRect rect; |
|
358 rect.LayoutRect( powerSavePaneRect, |
|
359 AknLayout::Power_save_pane_descendants_Line_3() ); |
|
360 TInt height = rect.Rect().Height(); |
|
361 TSize iconSize( 2 * height, height ); |
|
362 AknIconUtils::SetSize( iIcon->Bitmap(), iconSize ); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // CScreensaverNumberAndIconIndicator::InitializeIconL |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 void CScreensaverIndicatorNumberAndIcon::InitializeIconL( TResourceReader &aReader ) |
|
370 { |
|
371 // Icon & mask ids |
|
372 TInt id = aReader.ReadInt32(); |
|
373 TInt maskid = aReader.ReadInt32(); |
|
374 |
|
375 // Icon & mask skin identifiers |
|
376 TInt skinid = aReader.ReadInt32(); |
|
377 TInt skinmask = aReader.ReadInt32(); |
|
378 |
|
379 iIcon = CGulIcon::NewL(); |
|
380 |
|
381 CFbsBitmap* bmp= NULL; |
|
382 CFbsBitmap* mask= NULL; |
|
383 |
|
384 // Load skinned bitmap |
|
385 AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(), |
|
386 MakeSkinItemId( skinid ), |
|
387 KAknsIIDNone, // Lie so that we get default color, not skin color |
|
388 0, // No color group |
|
389 bmp, mask, AknIconUtils::AvkonIconFileName(), id, maskid, |
|
390 iTextColor ); |
|
391 |
|
392 CleanupStack::Pop( 2 ); |
|
393 |
|
394 // Save the icon |
|
395 iIcon->SetBitmap( bmp ); |
|
396 iIcon->SetMask( mask ); |
|
397 } |
|
398 |
|
399 // ----------------------------------------------------------------------------- |
|
400 // CScreensaverNumberAndIconIndicator::DrawIcon |
|
401 // ----------------------------------------------------------------------------- |
|
402 // |
|
403 void CScreensaverIndicatorNumberAndIcon::DrawIcon( CWindowGc& aGc ) const |
|
404 { |
|
405 if ( iIconAlign == ESsAlignLeft ) |
|
406 { |
|
407 if ( !iIcon->Mask() ) |
|
408 { |
|
409 aGc.BitBlt( iTopLeft, iIcon->Bitmap(), iRect ); |
|
410 } |
|
411 else |
|
412 { |
|
413 aGc.BitBltMasked( iTopLeft, iIcon->Bitmap(), iRect, |
|
414 iIcon->Mask(), ETrue ); |
|
415 } |
|
416 } |
|
417 else |
|
418 { |
|
419 // Calculate icon left point (right edge - icon width) |
|
420 TPoint pTmp = TPoint( iTopLeft.iX + iRect.Size().iWidth - iIcon->Bitmap()->SizeInPixels().iWidth, iTopLeft.iY ); |
|
421 |
|
422 if ( !iIcon->Mask() ) |
|
423 { |
|
424 aGc.BitBlt( pTmp, iIcon->Bitmap(), iRect ); |
|
425 } |
|
426 else |
|
427 { |
|
428 aGc.BitBltMasked( pTmp, iIcon->Bitmap(), iRect, iIcon->Mask(), |
|
429 ETrue ); |
|
430 } |
|
431 } |
|
432 } |
|
433 |
|
434 // End of file |