|
1 /* |
|
2 * Copyright (c) 2005-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: Implementation of title pane's label. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <e32def.h> |
|
21 #include <AknPictographInterface.h> |
|
22 #include <AknPictographDrawerInterface.h> |
|
23 #include <bidivisual.h> |
|
24 #include <biditext.h> |
|
25 #include <akniconconfig.h> |
|
26 #include <layoutmetadata.cdl.h> |
|
27 |
|
28 #include <AknTasHook.h> // for testability hooks |
|
29 // USER INCLUDES |
|
30 #include "AknTitlePaneLabel.h" |
|
31 #include "AknUtils.h" |
|
32 #include "AknLayoutFont.h" |
|
33 #include "aknappui.h" |
|
34 #include "AknBidiTextUtils.h" |
|
35 #include "AknStatuspaneUtils.h" |
|
36 |
|
37 // General effects-related constants |
|
38 const TInt KScrollTimerInterval = 50000; // 20 events/s |
|
39 const TInt KScrollTimerDelay = KScrollTimerInterval; |
|
40 const TInt KScrollTimerDelayBeforeDirectionReversal = 3000000; // 3s |
|
41 const TInt KStartValue = 0; |
|
42 const TInt KEndValue = 255; |
|
43 const TInt KMinInterval = 50000; |
|
44 const TInt KScaleMagicNumber = 208; |
|
45 |
|
46 // ============================ MEMBER FUNCTIONS =============================== |
|
47 |
|
48 |
|
49 CAknTitlePaneLabel::CAknTitlePaneLabel() |
|
50 { |
|
51 AKNTASHOOK_ADD( this, "CAknTitlePaneLabel" ); |
|
52 } |
|
53 |
|
54 |
|
55 CAknTitlePaneLabel::~CAknTitlePaneLabel() |
|
56 { |
|
57 AKNTASHOOK_REMOVE(); |
|
58 delete iMask; |
|
59 delete iMaskDevice; |
|
60 delete iMaskGc; |
|
61 |
|
62 delete iBitmap; |
|
63 delete iBitmapDevice; |
|
64 delete iBitmapGc; |
|
65 |
|
66 if ( iEffectTimer ) |
|
67 { |
|
68 iEffectTimer->Cancel(); |
|
69 delete iEffectTimer; |
|
70 ControlEnv()->RemoveForegroundObserver( *this ); |
|
71 } |
|
72 delete iEffectQueue; |
|
73 delete iScrollingText; |
|
74 } |
|
75 |
|
76 |
|
77 void CAknTitlePaneLabel::Draw( const TRect& aRect ) const |
|
78 { |
|
79 if ( iEffect == EEffectNone ) |
|
80 { |
|
81 CEikLabel::Draw( aRect ); |
|
82 } |
|
83 |
|
84 // Text is paused before starting to scroll, |
|
85 // drawn without truncation character. |
|
86 else if ( iEffect == EEffectPause && iPreviousEffect == EEffectNone ) |
|
87 { |
|
88 // const_cast is required to call the DrawWithoutTruncation() function. |
|
89 TRAPD( err, |
|
90 const_cast<CAknTitlePaneLabel*>( this )->DrawWithoutTruncationL( aRect ) ); |
|
91 |
|
92 if ( err != KErrNone ) |
|
93 { |
|
94 CEikLabel::Draw( aRect ); |
|
95 } |
|
96 } |
|
97 else |
|
98 { |
|
99 DrawWithEffect( aRect ); |
|
100 } |
|
101 } |
|
102 |
|
103 |
|
104 void CAknTitlePaneLabel::DrawWithoutTruncationL( const TRect& aRect ) |
|
105 { |
|
106 // Copy of the truncated text in CEikLabel is made first. |
|
107 HBufC* truncatedText = HBufC::NewL( Text()->Length() ); |
|
108 CleanupStack::PushL( truncatedText ); |
|
109 |
|
110 TPtr ptr( truncatedText->Des() ); |
|
111 ptr.Copy( *Text() ); |
|
112 |
|
113 // CEikLabel's text is set to the full text and is drawn. |
|
114 SetTextL( *iScrollingText ); |
|
115 CEikLabel::Draw( aRect ); |
|
116 |
|
117 // CEikLabel's text is set back to the truncated form. |
|
118 SetTextL( ptr ); |
|
119 |
|
120 CleanupStack::PopAndDestroy( truncatedText ); |
|
121 } |
|
122 |
|
123 |
|
124 void CAknTitlePaneLabel::DrawWithEffect( const TRect& aRect ) const |
|
125 { |
|
126 if ( iEffect && iBitmap && iMask && iBitmapGc && iMaskGc ) |
|
127 { |
|
128 // Bitblit using mask, this creates the fade effect |
|
129 CWindowGc& gc = SystemGc(); |
|
130 gc.BitBltMasked( |
|
131 iTextLayout.TextRect().iTl, |
|
132 iBitmap, |
|
133 iTextLayout.TextRect(), |
|
134 iMask, |
|
135 ETrue ); |
|
136 } |
|
137 else |
|
138 { |
|
139 CEikLabel::Draw( aRect ); |
|
140 } |
|
141 } |
|
142 |
|
143 |
|
144 void CAknTitlePaneLabel::DrawTextWithEffect() const |
|
145 { |
|
146 switch ( iEffect ) |
|
147 { |
|
148 case EEffectFadeToLeft: |
|
149 case EEffectFadeToRight: |
|
150 { |
|
151 DrawTextWithFadeEffect(); |
|
152 break; |
|
153 } |
|
154 case EEffectDefaultScroll: |
|
155 { |
|
156 DrawTextWithScrollEffect(); |
|
157 break; |
|
158 } |
|
159 case EEffectDefaultScrollWithFade: |
|
160 case EEffectLoopScrollWithFade: |
|
161 case EEffectScrollOnceWithFade: |
|
162 case EEffectFadeOut: |
|
163 case EEffectFadeIn: |
|
164 case EEffectToggleScrolledTextTruncation: |
|
165 { |
|
166 DrawTextWithScrollAndFadeEffect(); |
|
167 break; |
|
168 } |
|
169 case EEffectPause: |
|
170 case EEffectNone: |
|
171 default: |
|
172 { |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 if ( DrawableWindow() ) |
|
178 { |
|
179 DrawDeferred(); |
|
180 } |
|
181 |
|
182 if ( iObserver && iObserver->DrawableWindow() ) |
|
183 { |
|
184 iObserver->DrawDeferred(); |
|
185 } |
|
186 } |
|
187 |
|
188 |
|
189 void CAknTitlePaneLabel::DrawTextWithFadeEffect() const |
|
190 { |
|
191 if ( iEffect && |
|
192 iBitmap && |
|
193 iMask && |
|
194 iBitmapGc && |
|
195 iMaskGc && |
|
196 iTitleText && |
|
197 iScrollingText ) |
|
198 { |
|
199 InitBitmaps(); |
|
200 iMaskGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
201 iMaskGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
202 iBitmapGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
203 iBitmapGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
204 |
|
205 if ( IsStrikethrough() ) |
|
206 { |
|
207 iMaskGc->SetStrikethroughStyle( EStrikethroughOn ); |
|
208 iBitmapGc->SetStrikethroughStyle( EStrikethroughOn ); |
|
209 } |
|
210 else |
|
211 { |
|
212 iMaskGc->SetStrikethroughStyle( EStrikethroughOff ); |
|
213 iBitmapGc->SetStrikethroughStyle( EStrikethroughOff ); |
|
214 } |
|
215 |
|
216 if ( IsUnderlined() ) |
|
217 { |
|
218 iMaskGc->SetUnderlineStyle( EUnderlineOn ); |
|
219 iBitmapGc->SetUnderlineStyle( EUnderlineOn ); |
|
220 } |
|
221 else |
|
222 { |
|
223 iMaskGc->SetUnderlineStyle( EUnderlineOff ); |
|
224 iBitmapGc->SetUnderlineStyle( EUnderlineOff ); |
|
225 } |
|
226 |
|
227 const CFont* fontUsed = |
|
228 AknLayoutUtils::FontFromId( iTextLayoutLine.FontId() ); |
|
229 iBitmapGc->UseFont( fontUsed ); |
|
230 |
|
231 // First draw with white color for masking purpose |
|
232 const CAknLayoutFont* layoutFont = |
|
233 CAknLayoutFont::AsCAknLayoutFontOrNull( fontUsed ); |
|
234 TInt textPaneAscent( 0 ); |
|
235 if ( layoutFont ) |
|
236 { |
|
237 textPaneAscent = layoutFont->TextPaneTopToBaseline(); |
|
238 } |
|
239 else |
|
240 { |
|
241 textPaneAscent = fontUsed->AscentInPixels(); |
|
242 } |
|
243 |
|
244 CGraphicsContext::TTextAlign textAlign( CGraphicsContext::ELeft ); |
|
245 if( AknLayoutUtils::LayoutMirrored() ) |
|
246 { |
|
247 textAlign = CGraphicsContext::ERight; |
|
248 } |
|
249 |
|
250 iBitmapGc->SetPenColor( KRgbWhite ); |
|
251 iBitmapGc->DrawText( *iScrollingText, |
|
252 iTextLayout.TextRect(), |
|
253 textPaneAscent, |
|
254 textAlign, |
|
255 0 ); |
|
256 |
|
257 // Draw pictographs |
|
258 if ( iPictographInterface ) |
|
259 { |
|
260 iPictographInterface->Interface()->DrawPictographsInText( |
|
261 *iBitmapGc, |
|
262 *fontUsed, |
|
263 *iScrollingText, |
|
264 iTextLayout.TextRect(), |
|
265 textPaneAscent, |
|
266 textAlign, |
|
267 0 ); |
|
268 } |
|
269 |
|
270 // Draw text to mask |
|
271 iMaskGc->BitBltMasked( |
|
272 Rect().iTl, |
|
273 iBitmap, |
|
274 TRect( iBitmap->SizeInPixels() ), |
|
275 iBitmap, |
|
276 ETrue ); |
|
277 |
|
278 TRgb color( KRgbBlack ); |
|
279 if ( IsDimmed() ) |
|
280 { |
|
281 color = iEikonEnv->ControlColor( EColorLabelDimmedText, *this ); |
|
282 } |
|
283 else |
|
284 { |
|
285 color = iEikonEnv->ControlColor( EColorLabelText, *this ); |
|
286 } |
|
287 |
|
288 iBitmapGc->SetPenColor( color ); |
|
289 iBitmapGc->DrawText( *iScrollingText, |
|
290 iTextLayout.TextRect(), |
|
291 textPaneAscent, |
|
292 textAlign, |
|
293 0 ); |
|
294 |
|
295 // Draw pictographs |
|
296 if ( iPictographInterface ) |
|
297 { |
|
298 iPictographInterface->Interface()->DrawPictographsInText( |
|
299 *iBitmapGc, |
|
300 *fontUsed, |
|
301 *iScrollingText, |
|
302 iTextLayout.TextRect(), |
|
303 textPaneAscent, |
|
304 textAlign, |
|
305 0 ); |
|
306 } |
|
307 |
|
308 iBitmapGc->DiscardFont(); // Release the font cache |
|
309 } |
|
310 } |
|
311 |
|
312 void CAknTitlePaneLabel::DrawTextWithScrollEffect() const |
|
313 { |
|
314 if ( iEffect && |
|
315 iBitmap && |
|
316 iMask && |
|
317 iBitmapGc && |
|
318 iMaskGc && |
|
319 iTitleText && |
|
320 iScrollingText ) |
|
321 { |
|
322 InitBitmaps(); |
|
323 iMaskGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
324 iMaskGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
325 iBitmapGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
326 iBitmapGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
327 |
|
328 TRect rect( iScrollRect ); |
|
329 |
|
330 TRgb color( KRgbBlack ); |
|
331 if ( IsDimmed() ) |
|
332 { |
|
333 color = iEikonEnv->ControlColor( EColorLabelDimmedText, *this ); |
|
334 } |
|
335 else |
|
336 { |
|
337 color = iEikonEnv->ControlColor( EColorLabelText, *this ); |
|
338 } |
|
339 |
|
340 const CFont* fontUsed = |
|
341 AknLayoutUtils::FontFromId( iTextLayoutLine.FontId() ); |
|
342 const CAknLayoutFont* layoutFont = |
|
343 CAknLayoutFont::AsCAknLayoutFontOrNull( fontUsed ); |
|
344 TInt textPaneAscent( 0 ); |
|
345 if ( layoutFont ) |
|
346 { |
|
347 textPaneAscent = layoutFont->TextPaneTopToBaseline(); |
|
348 } |
|
349 else |
|
350 { |
|
351 textPaneAscent = fontUsed->AscentInPixels(); |
|
352 } |
|
353 |
|
354 CGraphicsContext::TTextAlign textAlign( CGraphicsContext::ELeft ); |
|
355 |
|
356 if ( iWesternText ) |
|
357 { |
|
358 rect.iTl.iX -= iScrollPosition; |
|
359 } |
|
360 else |
|
361 { |
|
362 rect.iBr.iX += iScrollPosition; |
|
363 textAlign = CGraphicsContext::ERight; |
|
364 } |
|
365 |
|
366 iBitmapGc->SetPenColor( KRgbWhite ); |
|
367 iBitmapGc->UseFont( fontUsed ); |
|
368 |
|
369 TBool truncated = Text()->Locate( KEllipsis ) != KErrNotFound; |
|
370 if ( !iScrollPosition && truncated ) |
|
371 { |
|
372 // Draw truncated text |
|
373 iBitmapGc->DrawText( *Text(), rect, textPaneAscent, textAlign, 0 ); |
|
374 // Draw pictographs |
|
375 if ( iPictographInterface ) |
|
376 { |
|
377 iPictographInterface->Interface()->DrawPictographsInText( |
|
378 *iBitmapGc, |
|
379 *fontUsed, |
|
380 *Text(), |
|
381 rect, |
|
382 textPaneAscent, |
|
383 textAlign, |
|
384 0 ); |
|
385 } |
|
386 } |
|
387 else if ( iScrollingText ) |
|
388 { |
|
389 // Draw non-truncated text |
|
390 iBitmapGc->DrawText( *iScrollingText, |
|
391 rect, |
|
392 textPaneAscent, |
|
393 textAlign, |
|
394 0 ); |
|
395 // Draw pictographs |
|
396 if ( iPictographInterface ) |
|
397 { |
|
398 iPictographInterface->Interface()->DrawPictographsInText( |
|
399 *iBitmapGc, |
|
400 *fontUsed, |
|
401 *iScrollingText, |
|
402 rect, |
|
403 textPaneAscent, |
|
404 textAlign, |
|
405 0 ); |
|
406 } |
|
407 } |
|
408 |
|
409 // Draw text to mask |
|
410 iMaskGc->BitBltMasked( |
|
411 Rect().iTl, |
|
412 iBitmap, |
|
413 TRect( iBitmap->SizeInPixels() ), |
|
414 iBitmap, |
|
415 ETrue ); |
|
416 |
|
417 iBitmapGc->SetPenColor( color ); |
|
418 |
|
419 if ( !iScrollPosition && truncated ) |
|
420 { |
|
421 // Draw truncated text |
|
422 iBitmapGc->DrawText( *Text(), rect, textPaneAscent, textAlign, 0 ); |
|
423 // Draw pictographs |
|
424 if ( iPictographInterface ) |
|
425 { |
|
426 iPictographInterface->Interface()->DrawPictographsInText( |
|
427 *iBitmapGc, |
|
428 *fontUsed, |
|
429 *Text(), |
|
430 rect, |
|
431 textPaneAscent, |
|
432 textAlign, |
|
433 0 ); |
|
434 } |
|
435 } |
|
436 else if ( iScrollingText ) |
|
437 { |
|
438 // Draw non-truncated text |
|
439 iBitmapGc->DrawText( *iScrollingText, |
|
440 rect, |
|
441 textPaneAscent, |
|
442 textAlign, |
|
443 0 ); |
|
444 // Draw pictographs |
|
445 if ( iPictographInterface ) |
|
446 { |
|
447 iPictographInterface->Interface()->DrawPictographsInText( |
|
448 *iBitmapGc, |
|
449 *fontUsed, |
|
450 *iScrollingText, |
|
451 rect, |
|
452 textPaneAscent, |
|
453 textAlign, |
|
454 0 ); |
|
455 } |
|
456 } |
|
457 |
|
458 iBitmapGc->DiscardFont(); // Release the font cache |
|
459 } |
|
460 } |
|
461 |
|
462 |
|
463 void CAknTitlePaneLabel::DrawTextWithScrollAndFadeEffect() const |
|
464 { |
|
465 DrawTextWithScrollEffect(); |
|
466 } |
|
467 |
|
468 |
|
469 void CAknTitlePaneLabel::SetTextEffect( TInt aEffect, |
|
470 TRect aEffectRect, |
|
471 TInt aEffectDuration, |
|
472 TRect aLabelRect, |
|
473 TAknLayoutText aTextLayout, |
|
474 TAknTextLineLayout aTextLayoutLine, |
|
475 HBufC* aTitleText, |
|
476 CCoeControl* aObserver) |
|
477 { |
|
478 iPreviousEffect = iEffect; |
|
479 |
|
480 iObserver = aObserver; |
|
481 iTextLayout = aTextLayout; |
|
482 iTextLayoutLine = aTextLayoutLine; |
|
483 |
|
484 if ( ( iTitleText != aTitleText && iScrollingText ) || |
|
485 ( !iScrollingText && aEffect ) ) |
|
486 { |
|
487 TRAP_IGNORE( CreateScrollingTextL( aTitleText ) ); |
|
488 } |
|
489 |
|
490 iTitleText = aTitleText; |
|
491 iEffectDuration = aEffectDuration; |
|
492 |
|
493 iWesternText = |
|
494 TBidiText::TextDirectionality( *Text() ) == TBidiText::ELeftToRight; |
|
495 |
|
496 if ( aEffect == EEffectScrollOnceWithFade || |
|
497 aEffect == EEffectLoopScrollWithFade || |
|
498 aEffect == EEffectLoopScroll || |
|
499 aEffect == EEffectDefaultScrollWithFade || |
|
500 aEffect == EEffectDefaultScroll ) |
|
501 { |
|
502 iScrollPosition = 0; |
|
503 } |
|
504 |
|
505 iScrollRect = iTextLayout.TextRect(); |
|
506 if ( iScrollRect.iTl.iX < aEffectRect.iTl.iX ) |
|
507 { |
|
508 iScrollRect.iTl.iX = aEffectRect.iTl.iX; |
|
509 } |
|
510 if ( iScrollRect.iBr.iX > aEffectRect.iBr.iX ) |
|
511 { |
|
512 iScrollRect.iBr.iX = aEffectRect.iBr.iX; |
|
513 } |
|
514 |
|
515 const CFont* fontUsed = |
|
516 AknLayoutUtils::FontFromId( aTextLayoutLine.FontId() ); |
|
517 CFont::TMeasureTextInput input; |
|
518 input.iFlags = CFont::TMeasureTextInput::EFVisualOrder; |
|
519 iTextLength = fontUsed->MeasureText( *aTitleText, &input ); |
|
520 |
|
521 iOperatorNamePhase = 0; |
|
522 |
|
523 if ( !aEffect || |
|
524 iEffect != aEffect || |
|
525 iEffectRect != aEffectRect || |
|
526 Rect() != aLabelRect ) |
|
527 { |
|
528 iEffect = aEffect; |
|
529 iEffectRect = aEffectRect; |
|
530 if ( !iEffect ) |
|
531 { |
|
532 TRgb color( iEikonEnv->ControlColor( EColorLabelText, *this ) ); |
|
533 // We cast here a bit dangerously, this might be changed someday. |
|
534 TAknMultiLineTextLayout* multilinePtr = NULL; |
|
535 multilinePtr = |
|
536 static_cast<TAknMultiLineTextLayout*> ( &aTextLayoutLine ); |
|
537 AknLayoutUtils::LayoutLabel(this, aLabelRect, *multilinePtr); |
|
538 // Layoutlabel loses the color, set it back to right one |
|
539 TRAP_IGNORE( |
|
540 AknLayoutUtils::OverrideControlColorL( |
|
541 *this, EColorLabelText, color ) ); |
|
542 } |
|
543 else |
|
544 { |
|
545 if ( aEffect != EEffectPause ) |
|
546 { |
|
547 SetRect( aLabelRect ); |
|
548 } |
|
549 } |
|
550 |
|
551 iEffectLabelSize = Size(); |
|
552 |
|
553 TInt error = KErrNone; |
|
554 TRAP( error, InitEffectL() ); |
|
555 if ( error != KErrNone ) |
|
556 { |
|
557 iEffect = EEffectNone; |
|
558 } |
|
559 } |
|
560 |
|
561 // Do effect event at least once |
|
562 DoEffectEvent(); |
|
563 |
|
564 // Setup timer for furter effect events if needed |
|
565 if ( iEffect != EEffectPause ) |
|
566 { |
|
567 TRAP_IGNORE( InitTimerL( KScrollTimerDelay, KScrollTimerInterval ) ); |
|
568 } |
|
569 } |
|
570 |
|
571 |
|
572 TInt CAknTitlePaneLabel::TextEffect() |
|
573 { |
|
574 return iEffect; |
|
575 } |
|
576 |
|
577 |
|
578 void CAknTitlePaneLabel::InitEffectL() |
|
579 { |
|
580 if ( EffectBitmapsNeeded( iEffect ) ) |
|
581 { |
|
582 delete iMask; |
|
583 iMask = NULL; |
|
584 delete iMaskDevice; |
|
585 iMaskDevice = NULL; |
|
586 delete iMaskGc; |
|
587 iMaskGc = NULL; |
|
588 |
|
589 delete iBitmap; |
|
590 iBitmap = NULL; |
|
591 delete iBitmapDevice; |
|
592 iBitmapDevice = NULL; |
|
593 delete iBitmapGc; |
|
594 iBitmapGc = NULL; |
|
595 |
|
596 iMask = new (ELeave) CFbsBitmap(); |
|
597 iMask->Create( Size(), EGray256 ); |
|
598 iMaskDevice = CFbsBitmapDevice::NewL( iMask ); |
|
599 iMaskDevice->CreateContext( iMaskGc ); |
|
600 |
|
601 AknIconConfig::TPreferredDisplayMode mode; |
|
602 AknIconConfig::PreferredDisplayMode( |
|
603 mode, |
|
604 AknIconConfig::EImageTypeOffscreen ); |
|
605 |
|
606 iBitmap = new (ELeave) CFbsBitmap(); |
|
607 iBitmap->Create( Size(), mode.iBitmapMode ); |
|
608 iBitmapDevice = CFbsBitmapDevice::NewL( iBitmap ); |
|
609 iBitmapDevice->CreateContext( iBitmapGc ); |
|
610 |
|
611 InitBitmaps(); |
|
612 } |
|
613 } |
|
614 |
|
615 |
|
616 void CAknTitlePaneLabel::InitTimerL( TInt aDelay, TInt aInterval ) |
|
617 { |
|
618 CancelTimer(); |
|
619 |
|
620 if ( EffectEventsNeeded( iEffect ) ) |
|
621 { |
|
622 if ( !iEffectTimer ) |
|
623 { |
|
624 iEffectTimer = CPeriodic::NewL( CActive::EPriorityIdle ); |
|
625 ControlEnv()->AddForegroundObserverL( *this ); |
|
626 } |
|
627 |
|
628 if ( !iEffectTimer->IsActive() ) // start timer if not already started |
|
629 { |
|
630 iEffectTimer->Start( |
|
631 TTimeIntervalMicroSeconds32( aDelay ), |
|
632 TTimeIntervalMicroSeconds32( aInterval ), |
|
633 TCallBack( CAknTitlePaneLabel::EffectEvent, this ) ); |
|
634 } |
|
635 } |
|
636 else |
|
637 { |
|
638 iScrollPosition = 0; |
|
639 } |
|
640 } |
|
641 |
|
642 |
|
643 void CAknTitlePaneLabel::CancelTimer() |
|
644 { |
|
645 if ( iEffectTimer && iEffectTimer->IsActive() ) |
|
646 { |
|
647 iEffectTimer->Cancel(); |
|
648 } |
|
649 } |
|
650 |
|
651 |
|
652 void CAknTitlePaneLabel::InitBitmaps() const |
|
653 { |
|
654 iBitmapGc->SetPenColor( KRgbBlack ); |
|
655 iBitmapGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
656 iBitmapGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
657 iBitmapGc->SetBrushColor( KRgbBlack ); |
|
658 iBitmapGc->DrawRect( TRect( Size() ) ); |
|
659 |
|
660 iMaskGc->SetPenColor( KRgbBlack ); |
|
661 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
662 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
663 iMaskGc->SetBrushColor( KRgbWhite ); |
|
664 iMaskGc->DrawRect( TRect( Size() ) ); |
|
665 |
|
666 iMaskGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
667 iMaskGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
668 |
|
669 TInt width = iEffectRect.Width(); |
|
670 |
|
671 TRect parentRect( Rect() ); |
|
672 |
|
673 TBool isLandscape( Layout_Meta_Data::IsLandscapeOrientation() ); |
|
674 TBool flatSp( AknStatuspaneUtils::FlatLayoutActive() ); |
|
675 |
|
676 switch ( iEffect ) |
|
677 { |
|
678 case EEffectFadeToLeft: |
|
679 { |
|
680 TInt KMaxFadeSteps = KEndValue - KStartValue; |
|
681 TInt usedFadeStep = 0; |
|
682 TInt usedDrawStep = 1; |
|
683 |
|
684 if ( width < KMaxFadeSteps && |
|
685 width != 0) |
|
686 { |
|
687 usedFadeStep = KMaxFadeSteps / width; |
|
688 } |
|
689 else |
|
690 { |
|
691 usedFadeStep = 1; |
|
692 usedDrawStep = width / KMaxFadeSteps; |
|
693 } |
|
694 |
|
695 TInt startValue( KStartValue ); |
|
696 |
|
697 // In portrait mode flat status pane layout |
|
698 // we fade the text fully, because the navi |
|
699 // pane content and title pane can't be displayed |
|
700 // at the same time. |
|
701 |
|
702 TRgb rgb; |
|
703 rgb.SetRed( startValue ); |
|
704 rgb.SetGreen( startValue ); |
|
705 rgb.SetBlue( startValue ); |
|
706 |
|
707 TRect rect; |
|
708 for ( TInt x = 0; x < width; x += usedDrawStep ) |
|
709 { |
|
710 iMaskGc->SetPenColor( rgb ); |
|
711 iMaskGc->SetBrushColor( rgb ); |
|
712 rect.iTl.iX = iEffectRect.iTl.iX + x; |
|
713 rect.iTl.iY = 0; |
|
714 rect.iBr.iX = rect.iTl.iX + usedDrawStep; |
|
715 rect.iBr.iY = rect.iTl.iY + parentRect.Height(); |
|
716 |
|
717 iMaskGc->DrawRect( rect ); |
|
718 rgb.SetRed( rgb.Red() + usedFadeStep ); |
|
719 rgb.SetGreen( rgb.Green() + usedFadeStep ); |
|
720 rgb.SetBlue( rgb.Blue() + usedFadeStep ); |
|
721 } |
|
722 |
|
723 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
724 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
725 iMaskGc->SetPenColor( KRgbBlack ); |
|
726 iMaskGc->SetBrushColor( KRgbBlack ); |
|
727 iMaskGc->DrawRect( TRect( parentRect.iTl.iX, |
|
728 parentRect.iTl.iY, |
|
729 iEffectRect.iTl.iX, |
|
730 parentRect.iBr.iY ) ); |
|
731 break; |
|
732 } |
|
733 case EEffectFadeToRight: |
|
734 { |
|
735 TInt KMaxFadeSteps = KEndValue - KStartValue; |
|
736 TInt usedFadeStep = 0; |
|
737 TInt usedDrawStep = 1; |
|
738 |
|
739 |
|
740 if ( width < KMaxFadeSteps && |
|
741 width != 0 ) |
|
742 { |
|
743 usedFadeStep = KMaxFadeSteps / width; |
|
744 } |
|
745 else |
|
746 { |
|
747 usedFadeStep = 1; |
|
748 usedDrawStep = width / KMaxFadeSteps; |
|
749 } |
|
750 |
|
751 TInt startValue( KStartValue ); |
|
752 |
|
753 // In portrait mode flat status pane layout |
|
754 // we fade the text fully, because the navi |
|
755 // pane content and title pane can't be displayed |
|
756 // at the same time. |
|
757 |
|
758 TRgb rgb; |
|
759 rgb.SetRed( startValue ); |
|
760 rgb.SetGreen( startValue ); |
|
761 rgb.SetBlue( startValue ); |
|
762 |
|
763 TRect rect; |
|
764 for ( TInt x = width - 1; x >= 0; x -= usedDrawStep ) |
|
765 { |
|
766 iMaskGc->SetPenColor( rgb ); |
|
767 iMaskGc->SetBrushColor( rgb ); |
|
768 rect.iTl.iX = iEffectRect.iTl.iX + x; |
|
769 rect.iTl.iY = 0; |
|
770 rect.iBr.iX = rect.iTl.iX + usedDrawStep; |
|
771 rect.iBr.iY = rect.iTl.iY + parentRect.Height(); |
|
772 iMaskGc->DrawRect( rect ); |
|
773 rgb.SetRed( rgb.Red() + usedFadeStep ); |
|
774 rgb.SetGreen( rgb.Green() + usedFadeStep ); |
|
775 rgb.SetBlue( rgb.Blue() + usedFadeStep ); |
|
776 } |
|
777 |
|
778 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
779 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
780 iMaskGc->SetPenColor( KRgbBlack ); |
|
781 iMaskGc->SetBrushColor( KRgbBlack ); |
|
782 iMaskGc->DrawRect( TRect( iEffectRect.iBr.iX, |
|
783 parentRect.iTl.iY, |
|
784 parentRect.iBr.iX, |
|
785 parentRect.iBr.iY ) ); |
|
786 break; |
|
787 } |
|
788 case EEffectDefaultScrollWithFade: |
|
789 case EEffectLoopScrollWithFade: |
|
790 case EEffectScrollOnceWithFade: |
|
791 { |
|
792 if ( !TextNeedsTruncation() || iScrollPosition == 0 ) |
|
793 { |
|
794 return; // No need to fade if not even scrolled. |
|
795 } |
|
796 |
|
797 // We fade about 5-10% of the text area end/start to make |
|
798 // scrolling text appear/disappear smoother. |
|
799 width = iEffectRect.Width() / 30; |
|
800 TRect leftFadeEffectRect( iEffectRect ); |
|
801 leftFadeEffectRect.iBr.iX = leftFadeEffectRect.iTl.iX + width; |
|
802 |
|
803 TRect rightFadeEffectRect = iEffectRect; |
|
804 rightFadeEffectRect.iTl.iX = rightFadeEffectRect.iBr.iX - width; |
|
805 |
|
806 TInt KMaxFadeSteps = KEndValue - KStartValue; |
|
807 TInt usedFadeStep = 0; |
|
808 TInt usedDrawStep = 1; |
|
809 |
|
810 if ( width < KMaxFadeSteps && |
|
811 width != 0 ) |
|
812 { |
|
813 usedFadeStep = KMaxFadeSteps / width; |
|
814 } |
|
815 else |
|
816 { |
|
817 usedFadeStep = 1; |
|
818 usedDrawStep = width / KMaxFadeSteps; |
|
819 } |
|
820 |
|
821 TRgb rgb; |
|
822 rgb.SetRed( KStartValue ); |
|
823 rgb.SetGreen( KStartValue ); |
|
824 rgb.SetBlue( KStartValue ); |
|
825 |
|
826 TRect rect; |
|
827 for ( TInt x = 0; x < width; x += usedDrawStep ) |
|
828 { |
|
829 iMaskGc->SetPenColor( rgb ); |
|
830 iMaskGc->SetBrushColor( rgb ); |
|
831 rect.iTl.iX = leftFadeEffectRect.iTl.iX + x; |
|
832 rect.iTl.iY = 0; |
|
833 rect.iBr.iX = rect.iTl.iX + usedDrawStep; |
|
834 rect.iBr.iY = rect.iTl.iY + parentRect.Height(); |
|
835 |
|
836 iMaskGc->DrawRect( rect ); |
|
837 rgb.SetRed( rgb.Red() + usedFadeStep ); |
|
838 rgb.SetGreen( rgb.Green() + usedFadeStep ); |
|
839 rgb.SetBlue( rgb.Blue() + usedFadeStep ); |
|
840 } |
|
841 |
|
842 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
843 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
844 iMaskGc->SetPenColor( KRgbBlack ); |
|
845 iMaskGc->SetBrushColor( KRgbBlack ); |
|
846 iMaskGc->DrawRect( TRect( parentRect.iTl.iX, |
|
847 parentRect.iTl.iY, |
|
848 leftFadeEffectRect.iTl.iX, |
|
849 parentRect.iBr.iY ) ); |
|
850 |
|
851 |
|
852 iMaskGc->SetPenStyle( CGraphicsContext::ESolidPen ); |
|
853 iMaskGc->SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
854 |
|
855 KMaxFadeSteps = KEndValue - KStartValue; |
|
856 usedFadeStep = 0; |
|
857 usedDrawStep = 1; |
|
858 |
|
859 if ( width < KMaxFadeSteps && |
|
860 width != 0 ) |
|
861 { |
|
862 usedFadeStep = KMaxFadeSteps / width; |
|
863 } |
|
864 else |
|
865 { |
|
866 usedFadeStep = 1; |
|
867 usedDrawStep = width / KMaxFadeSteps; |
|
868 } |
|
869 |
|
870 rgb.SetRed( KStartValue ); |
|
871 rgb.SetGreen( KStartValue ); |
|
872 rgb.SetBlue( KStartValue ); |
|
873 |
|
874 for ( TInt x = width - 1; x >= 0; x -= usedDrawStep ) |
|
875 { |
|
876 iMaskGc->SetPenColor( rgb ); |
|
877 iMaskGc->SetBrushColor( rgb ); |
|
878 rect.iTl.iX = rightFadeEffectRect.iTl.iX + x; |
|
879 rect.iTl.iY = 0; |
|
880 rect.iBr.iX = rect.iTl.iX + usedDrawStep; |
|
881 rect.iBr.iY = rect.iTl.iY + parentRect.Height(); |
|
882 |
|
883 iMaskGc->DrawRect( rect ); |
|
884 rgb.SetRed( rgb.Red() + usedFadeStep ); |
|
885 rgb.SetGreen( rgb.Green() + usedFadeStep ); |
|
886 rgb.SetBlue( rgb.Blue() + usedFadeStep ); |
|
887 } |
|
888 |
|
889 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
890 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
891 iMaskGc->SetBrushColor( KRgbBlack ); |
|
892 iMaskGc->DrawRect( TRect( rightFadeEffectRect.iBr.iX, |
|
893 parentRect.iTl.iY, |
|
894 parentRect.iBr.iX, |
|
895 parentRect.iBr.iY ) ); |
|
896 break; |
|
897 } |
|
898 case EEffectFadeOut: |
|
899 case EEffectFadeIn: |
|
900 { |
|
901 TRgb fadeRgb; |
|
902 fadeRgb.SetRed( iFadeInOutValue ); |
|
903 fadeRgb.SetGreen( iFadeInOutValue ); |
|
904 fadeRgb.SetBlue( iFadeInOutValue ); |
|
905 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
906 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
907 iMaskGc->SetPenColor( fadeRgb ); |
|
908 iMaskGc->SetBrushColor( fadeRgb ); |
|
909 iMaskGc->DrawRect( iEffectRect ); |
|
910 |
|
911 iMaskGc->SetPenStyle( CGraphicsContext::ENullPen ); |
|
912 iMaskGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
913 iMaskGc->SetPenColor( KRgbBlack ); |
|
914 iMaskGc->SetBrushColor( KRgbBlack ); |
|
915 iMaskGc->DrawRect( TRect( parentRect.iTl.iX, |
|
916 parentRect.iTl.iY, |
|
917 iEffectRect.iTl.iX, |
|
918 parentRect.iBr.iY ) ); |
|
919 break; |
|
920 } |
|
921 case EEffectPause: |
|
922 case EEffectNone: |
|
923 case EEffectToggleScrolledTextTruncation: |
|
924 case EEffectDefaultScroll: |
|
925 default: |
|
926 { |
|
927 break; |
|
928 } |
|
929 } |
|
930 } |
|
931 |
|
932 |
|
933 CFbsBitmap* CAknTitlePaneLabel::TextAsBitmap() |
|
934 { |
|
935 if ( iEffect != EEffectNone ) |
|
936 { |
|
937 return iBitmap; |
|
938 } |
|
939 else |
|
940 { |
|
941 return NULL; |
|
942 } |
|
943 } |
|
944 |
|
945 |
|
946 CFbsBitmap* CAknTitlePaneLabel::TextAsMask() |
|
947 { |
|
948 if ( iEffect != EEffectNone ) |
|
949 { |
|
950 return iMask; |
|
951 } |
|
952 else |
|
953 { |
|
954 return NULL; |
|
955 } |
|
956 } |
|
957 |
|
958 |
|
959 void CAknTitlePaneLabel::HandleGainingForeground() |
|
960 { |
|
961 TRAP_IGNORE( InitTimerL( KScrollTimerDelay, KScrollTimerInterval ) ); |
|
962 } |
|
963 |
|
964 void CAknTitlePaneLabel::HandleLosingForeground() |
|
965 { |
|
966 CancelTimer(); |
|
967 } |
|
968 |
|
969 |
|
970 TInt CAknTitlePaneLabel::EffectEvent( TAny* aPtr ) |
|
971 { |
|
972 static_cast<CAknTitlePaneLabel*> ( aPtr )->DoEffectEvent(); |
|
973 return ETrue; |
|
974 } |
|
975 |
|
976 |
|
977 TBool CAknTitlePaneLabel::DoDefaultScrollEffectEvent() |
|
978 { |
|
979 TBool done( EFalse ); |
|
980 if ( !TextNeedsTruncation() ) |
|
981 { |
|
982 iScrollStep = 0; |
|
983 done = ETrue; |
|
984 } |
|
985 |
|
986 if ( iScrollDirectionBackwards ) |
|
987 { |
|
988 iScrollStep = -ScrollStepInPixels(); |
|
989 if ( iScrollPosition == 0 ) |
|
990 { |
|
991 // If text is at the other end, switch |
|
992 // scrolling direction and continue. |
|
993 iScrollDirectionBackwards = EFalse; |
|
994 TRAP_IGNORE( |
|
995 InitTimerL( |
|
996 KScrollTimerDelayBeforeDirectionReversal, |
|
997 KScrollTimerInterval ) ); // Make a littler longer delay at the ends |
|
998 } |
|
999 } |
|
1000 else |
|
1001 { |
|
1002 iScrollStep = ScrollStepInPixels(); |
|
1003 if ( iScrollPosition + iScrollRect.Width() > iTextLength + iScrollRect.Width() / 10 ) |
|
1004 { |
|
1005 // If text is at the other end, switch scrolling direction and continue |
|
1006 iScrollDirectionBackwards = ETrue; |
|
1007 TRAP_IGNORE( |
|
1008 InitTimerL( |
|
1009 KScrollTimerDelayBeforeDirectionReversal, |
|
1010 KScrollTimerInterval ) ); // Make a littler longer delay at the ends |
|
1011 } |
|
1012 } |
|
1013 iScrollPosition += iScrollStep; |
|
1014 return done; |
|
1015 } |
|
1016 |
|
1017 |
|
1018 TBool CAknTitlePaneLabel::DoLoopScrollEffectEvent() |
|
1019 { |
|
1020 TBool done( EFalse ); |
|
1021 if ( !TextNeedsTruncation() ) |
|
1022 { |
|
1023 iScrollStep = 0; |
|
1024 done = ETrue; |
|
1025 } |
|
1026 |
|
1027 iScrollStep = ScrollStepInPixels(); |
|
1028 if ( iScrollPosition > iTextLength + iScrollRect.Width() / 10 ) |
|
1029 { |
|
1030 // If text has scrolled away from screen, start again from the other end |
|
1031 iScrollPosition = -iScrollRect.Width(); |
|
1032 } |
|
1033 iScrollPosition += iScrollStep; |
|
1034 return done; |
|
1035 } |
|
1036 |
|
1037 |
|
1038 TBool CAknTitlePaneLabel::DoScrollOnceEffectEvent() |
|
1039 { |
|
1040 TBool done( EFalse ); |
|
1041 if ( !TextNeedsTruncation() ) |
|
1042 { |
|
1043 iScrollStep = 0; |
|
1044 done = ETrue; |
|
1045 } |
|
1046 else |
|
1047 { |
|
1048 iScrollStep = ScrollStepInPixels(); |
|
1049 if ( iScrollPosition + iScrollRect.Width() > iTextLength + iScrollRect.Width() / 10 ) |
|
1050 { |
|
1051 // If text is at the other end, continue with fade after timout |
|
1052 iScrollStep = 0; |
|
1053 done = ETrue; |
|
1054 } |
|
1055 } |
|
1056 iScrollPosition += iScrollStep; |
|
1057 return done; |
|
1058 } |
|
1059 |
|
1060 |
|
1061 TBool CAknTitlePaneLabel::DoFadeInEffectEvent() |
|
1062 { |
|
1063 TBool done( EFalse ); |
|
1064 if ( iEffectDuration ) |
|
1065 { |
|
1066 TInt interval = iEffectDuration / KEndValue; |
|
1067 |
|
1068 if ( interval < KMinInterval ) |
|
1069 { |
|
1070 interval = KMinInterval; |
|
1071 iFadeInOutStep = iEffectDuration / KMinInterval; |
|
1072 } |
|
1073 else |
|
1074 { |
|
1075 iFadeInOutStep = 1; |
|
1076 } |
|
1077 |
|
1078 if ( iFadeInOutStep < 1 ) |
|
1079 { |
|
1080 iFadeInOutStep = 1; |
|
1081 } |
|
1082 if ( iFadeInOutStep > KEndValue ) |
|
1083 { |
|
1084 iFadeInOutStep = KEndValue; |
|
1085 } |
|
1086 |
|
1087 TRAP_IGNORE( InitTimerL( interval, interval ) ); |
|
1088 |
|
1089 iEffectDuration = 0; |
|
1090 iFadeInOutValue = 0; // start from fully invisible |
|
1091 } |
|
1092 |
|
1093 if ( iFadeInOutValue + iFadeInOutStep > KEndValue ) |
|
1094 { |
|
1095 iFadeInOutValue = KEndValue; |
|
1096 done = ETrue; |
|
1097 } |
|
1098 else |
|
1099 { |
|
1100 iFadeInOutValue += iFadeInOutStep; |
|
1101 } |
|
1102 |
|
1103 return done; |
|
1104 } |
|
1105 |
|
1106 TBool CAknTitlePaneLabel::DoFadeOutEffectEvent() |
|
1107 { |
|
1108 TBool done( EFalse ); |
|
1109 if ( iEffectDuration ) |
|
1110 { |
|
1111 TInt interval = iEffectDuration / KEndValue; |
|
1112 |
|
1113 if ( interval < KMinInterval ) |
|
1114 { |
|
1115 interval = KMinInterval; |
|
1116 iFadeInOutStep = iEffectDuration / KMinInterval; |
|
1117 } |
|
1118 else |
|
1119 { |
|
1120 iFadeInOutStep = 1; |
|
1121 } |
|
1122 |
|
1123 if ( iFadeInOutStep < 1 ) |
|
1124 { |
|
1125 iFadeInOutStep = 1; |
|
1126 } |
|
1127 if ( iFadeInOutStep > KEndValue ) |
|
1128 { |
|
1129 iFadeInOutStep = KEndValue; |
|
1130 } |
|
1131 |
|
1132 TRAP_IGNORE( InitTimerL( interval, interval ) ); |
|
1133 |
|
1134 iEffectDuration = 0; |
|
1135 iFadeInOutValue = KEndValue; // start from fully visible |
|
1136 } |
|
1137 |
|
1138 if ( iFadeInOutValue - iFadeInOutStep < 0 ) |
|
1139 { |
|
1140 iFadeInOutValue = 0; |
|
1141 done = ETrue; |
|
1142 } |
|
1143 else |
|
1144 { |
|
1145 iFadeInOutValue -= iFadeInOutStep; |
|
1146 } |
|
1147 |
|
1148 return done; |
|
1149 } |
|
1150 |
|
1151 |
|
1152 TBool CAknTitlePaneLabel::DoPauseEffectEvent() |
|
1153 { |
|
1154 TBool done( EFalse ); |
|
1155 if ( iEffectDuration ) |
|
1156 { |
|
1157 TRAP_IGNORE( InitTimerL( iEffectDuration, iEffectDuration ) ); |
|
1158 iEffectDuration = 0; |
|
1159 } |
|
1160 else |
|
1161 { |
|
1162 done = ETrue; |
|
1163 } |
|
1164 return done; |
|
1165 } |
|
1166 |
|
1167 |
|
1168 TBool CAknTitlePaneLabel::DoToggleScrolledTextTruncationEffectEvent() |
|
1169 { |
|
1170 iScrollPosition = 0; |
|
1171 return ETrue; |
|
1172 } |
|
1173 |
|
1174 |
|
1175 void CAknTitlePaneLabel::DoEffectEvent() |
|
1176 { |
|
1177 TBool done( EFalse ); |
|
1178 |
|
1179 switch ( iEffect ) |
|
1180 { |
|
1181 case EEffectDefaultScroll: |
|
1182 case EEffectDefaultScrollWithFade: |
|
1183 done = DoDefaultScrollEffectEvent(); |
|
1184 break; |
|
1185 case EEffectLoopScroll: |
|
1186 case EEffectLoopScrollWithFade: |
|
1187 done = DoLoopScrollEffectEvent(); |
|
1188 break; |
|
1189 case EEffectFadeIn: |
|
1190 done = DoFadeInEffectEvent(); |
|
1191 break; |
|
1192 case EEffectFadeOut: |
|
1193 done = DoFadeOutEffectEvent(); |
|
1194 break; |
|
1195 case EEffectPause: |
|
1196 done = DoPauseEffectEvent(); |
|
1197 break; |
|
1198 case EEffectScrollOnceWithFade: |
|
1199 done = DoScrollOnceEffectEvent(); |
|
1200 break; |
|
1201 case EEffectToggleScrolledTextTruncation: |
|
1202 done = DoToggleScrolledTextTruncationEffectEvent(); |
|
1203 break; |
|
1204 default: |
|
1205 iScrollStep = 0; |
|
1206 done = ETrue; |
|
1207 break; |
|
1208 } |
|
1209 |
|
1210 // Draw text |
|
1211 DrawTextWithEffect(); |
|
1212 |
|
1213 // If done then process next effect |
|
1214 if ( done ) |
|
1215 { |
|
1216 NextEffect(); |
|
1217 } |
|
1218 } |
|
1219 |
|
1220 TBool CAknTitlePaneLabel::TextNeedsTruncation() const |
|
1221 { |
|
1222 if ( iTextLength > iScrollRect.Width() ) |
|
1223 { |
|
1224 return ETrue; |
|
1225 } |
|
1226 else |
|
1227 { |
|
1228 return EFalse; |
|
1229 } |
|
1230 } |
|
1231 |
|
1232 |
|
1233 TBool CAknTitlePaneLabel::EffectEventsNeeded( TInt aEffect ) const |
|
1234 { |
|
1235 if ( aEffect == EEffectDefaultScroll || |
|
1236 aEffect == EEffectDefaultScrollWithFade || |
|
1237 aEffect == EEffectLoopScroll || |
|
1238 aEffect == EEffectLoopScrollWithFade || |
|
1239 aEffect == EEffectFadeOut || |
|
1240 aEffect == EEffectFadeIn || |
|
1241 aEffect == EEffectScrollOnceWithFade || |
|
1242 aEffect == EEffectPause ) |
|
1243 { |
|
1244 return ETrue; |
|
1245 } |
|
1246 else |
|
1247 { |
|
1248 return EFalse; |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 |
|
1253 TBool CAknTitlePaneLabel::EffectBitmapsNeeded( TInt aEffect ) const |
|
1254 { |
|
1255 if ( aEffect == EEffectDefaultScroll || |
|
1256 aEffect == EEffectDefaultScrollWithFade || |
|
1257 aEffect == EEffectLoopScroll || |
|
1258 aEffect == EEffectLoopScrollWithFade || |
|
1259 aEffect == EEffectFadeOut || |
|
1260 aEffect == EEffectFadeIn || |
|
1261 aEffect == EEffectScrollOnceWithFade || |
|
1262 aEffect == EEffectFadeToLeft || |
|
1263 aEffect == EEffectFadeToRight ) |
|
1264 { |
|
1265 return ETrue; |
|
1266 } |
|
1267 else |
|
1268 { |
|
1269 return EFalse; |
|
1270 } |
|
1271 } |
|
1272 |
|
1273 |
|
1274 TInt CAknTitlePaneLabel::ScrollStepInPixels() const |
|
1275 { |
|
1276 TInt stepInPixels = 2; |
|
1277 |
|
1278 // Adjust scrolling speed according to screen size |
|
1279 TRect screenRect( iAvkonAppUi->ApplicationRect() ); |
|
1280 |
|
1281 TInt scale = KScaleMagicNumber; |
|
1282 if ( screenRect.Height() > screenRect.Width() ) |
|
1283 { |
|
1284 scale = screenRect.Height(); |
|
1285 } |
|
1286 else |
|
1287 { |
|
1288 scale = screenRect.Width(); |
|
1289 } |
|
1290 |
|
1291 stepInPixels = ( stepInPixels * scale ) / KScaleMagicNumber; |
|
1292 |
|
1293 if ( stepInPixels < 1 ) |
|
1294 { |
|
1295 stepInPixels = 1; |
|
1296 } |
|
1297 |
|
1298 return stepInPixels; |
|
1299 } |
|
1300 |
|
1301 |
|
1302 void CAknTitlePaneLabel::InitEffectQueueL() |
|
1303 { |
|
1304 if ( !iEffectQueue ) |
|
1305 { |
|
1306 iEffectQueue = new (ELeave) CArrayFixFlat<SAknTitleLableEffect>( 2 ); |
|
1307 } |
|
1308 iEffectQueue->Reset(); |
|
1309 iNextEffectInEffectQueue = 0; |
|
1310 } |
|
1311 |
|
1312 |
|
1313 void CAknTitlePaneLabel::AddToEffectQueueL( SAknTitleLableEffect aEffect ) |
|
1314 { |
|
1315 if ( iEffectQueue ) |
|
1316 { |
|
1317 iEffectQueue->AppendL( aEffect ); |
|
1318 } |
|
1319 } |
|
1320 |
|
1321 |
|
1322 void CAknTitlePaneLabel::ActivateEffectQueue() |
|
1323 { |
|
1324 if ( iEffectQueue && iEffectQueue->Count() > iNextEffectInEffectQueue ) |
|
1325 { |
|
1326 iNextEffectInEffectQueue++; |
|
1327 SetTextEffect( |
|
1328 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iEffect, |
|
1329 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iEffectRect, |
|
1330 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iEffectDuration, |
|
1331 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iLabelRect, |
|
1332 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iTextLayout, |
|
1333 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iTextLayoutLine, |
|
1334 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iTitleText, |
|
1335 iEffectQueue->At( iNextEffectInEffectQueue - 1 ).iObserver); |
|
1336 } |
|
1337 } |
|
1338 |
|
1339 |
|
1340 void CAknTitlePaneLabel::NextEffect() |
|
1341 { |
|
1342 CancelTimer(); |
|
1343 ActivateEffectQueue(); |
|
1344 } |
|
1345 |
|
1346 |
|
1347 TInt CAknTitlePaneLabel::TextLength() |
|
1348 { |
|
1349 return iTextLength; |
|
1350 } |
|
1351 |
|
1352 |
|
1353 void CAknTitlePaneLabel::HandleResourceChange( TInt aType ) |
|
1354 { |
|
1355 CEikLabel::HandleResourceChange( aType ); |
|
1356 |
|
1357 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
1358 { |
|
1359 CancelTimer(); |
|
1360 TRAP_IGNORE( InitEffectQueueL() ); |
|
1361 iEffect = 0; |
|
1362 } |
|
1363 } |
|
1364 |
|
1365 |
|
1366 void CAknTitlePaneLabel::SetPictographInterface( |
|
1367 CAknPictographInterface& aInterface ) |
|
1368 { |
|
1369 TRAP_IGNORE( EnablePictographsL( aInterface ) ); |
|
1370 iPictographInterface = &aInterface; |
|
1371 } |
|
1372 |
|
1373 |
|
1374 void CAknTitlePaneLabel::InvalidateText() |
|
1375 { |
|
1376 iTitleText = NULL; |
|
1377 } |
|
1378 |
|
1379 |
|
1380 TBool CAknTitlePaneLabel::EffectQueueIsEmpty() |
|
1381 { |
|
1382 if ( iEffectQueue && iEffectQueue->Count() > 0 ) |
|
1383 { |
|
1384 return EFalse; |
|
1385 } |
|
1386 else |
|
1387 { |
|
1388 return ETrue; |
|
1389 } |
|
1390 } |
|
1391 |
|
1392 |
|
1393 void CAknTitlePaneLabel::CreateScrollingTextL( const HBufC* aOriginalText ) |
|
1394 { |
|
1395 delete iScrollingText; |
|
1396 iScrollingText = NULL; |
|
1397 |
|
1398 if ( aOriginalText ) |
|
1399 { |
|
1400 const CFont* fontUsed = |
|
1401 AknLayoutUtils::FontFromId( iTextLayoutLine.FontId() ); |
|
1402 CFont::TMeasureTextInput input; |
|
1403 TInt textLength = fontUsed->MeasureText( *aOriginalText, &input ); |
|
1404 // Add some safety margin ( must be at least this ) |
|
1405 textLength = textLength + textLength / 2; |
|
1406 if ( textLength < Size().iWidth ) |
|
1407 { |
|
1408 textLength = Size().iWidth; |
|
1409 } |
|
1410 |
|
1411 iScrollingText = HBufC::NewL( |
|
1412 aOriginalText->Length() + KAknBidiExtraSpacePerLine ); |
|
1413 TPtr ptr( iScrollingText->Des() ); |
|
1414 ptr.Fill(' '); |
|
1415 AknBidiTextUtils::ConvertToVisualAndClip( |
|
1416 *aOriginalText, |
|
1417 ptr, |
|
1418 *iFont, |
|
1419 textLength, |
|
1420 textLength ); |
|
1421 |
|
1422 // Linefeed chars are always removed since this |
|
1423 // text should never be used with 2-line text. |
|
1424 ReplaceControlCharacters( iScrollingText, ETrue ); |
|
1425 } |
|
1426 } |
|
1427 |
|
1428 |
|
1429 void CAknTitlePaneLabel::ReplaceControlCharacters( HBufC* aText, |
|
1430 TBool aReplaceLinefeeds ) |
|
1431 { |
|
1432 // Remove chars 0x00 to 0x1F and 0x2029 (Paragraph separator). |
|
1433 _LIT(KAknTitleLableStripListControlChars, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x2029"); |
|
1434 // 0x0A (Newline) and 0x2029 (Paragraph separator) excluded. |
|
1435 _LIT(KAknTitleLableStripListControlCharsWithoutLinefeed, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"); |
|
1436 |
|
1437 // Replace with space (0x20) |
|
1438 TChar replacementChar( 0x20 ); |
|
1439 |
|
1440 const TDesC& aChars = KAknTitleLableStripListControlChars; |
|
1441 const TDesC& aCharsWithoutLinefeed = |
|
1442 KAknTitleLableStripListControlCharsWithoutLinefeed; |
|
1443 |
|
1444 TUint16* ptr = const_cast<TUint16*> ( aText->Ptr() ); |
|
1445 |
|
1446 TInt src = 0; |
|
1447 TInt srclength = aText->Length(); |
|
1448 while( src < srclength ) |
|
1449 { |
|
1450 TChar c( ptr[src] ); |
|
1451 if ( aReplaceLinefeeds ) |
|
1452 { |
|
1453 if ( aChars.LocateF( c ) != KErrNotFound ) |
|
1454 { |
|
1455 ptr[src] = TUint16( replacementChar ); |
|
1456 } |
|
1457 } |
|
1458 else |
|
1459 { |
|
1460 if ( aCharsWithoutLinefeed.LocateF( c ) != KErrNotFound ) |
|
1461 { |
|
1462 ptr[src] = TUint16( replacementChar ); |
|
1463 } |
|
1464 } |
|
1465 ++src; |
|
1466 } |
|
1467 } |