|
1 /* |
|
2 * Copyright (c) 2004 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: Text scrolling functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "AknMarqueeControl.h" |
|
22 #include <biditext.h> |
|
23 #include <AknBidiTextUtils.h> |
|
24 #include <AknUtils.h> |
|
25 #include <AknLayout2ScalableDef.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KAknMarqueeDelay = 1000000; // start scrolling after a delay of 1 second |
|
29 const TInt KAknMarqueeInterval = 100000; // scroll 10 times in a second |
|
30 const TInt KAknMarqueeSpeed = 7; // scroll 3 pixels at time |
|
31 const TInt KAknMarqueeLoops = 1; |
|
32 const TInt KAknSensibleLength = 80; |
|
33 // it does not make any sense to marquee texts longer than this |
|
34 // since it will take hours and drain battery. |
|
35 const TInt KAknMaxMarqueeLength = 512; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CAknMarqueeControl::CAknMarqueeControl |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CAknMarqueeControl::CAknMarqueeControl(const TInt aLoops, const TInt aScrollAmount, |
|
46 const TInt aScrollDelay) : |
|
47 iDelta(0), |
|
48 iDelay(aScrollDelay), |
|
49 iSpeed(aScrollAmount), |
|
50 iInterval(KAknMarqueeInterval), |
|
51 iLoops(0), |
|
52 iMaxLoops(aLoops), |
|
53 iLastCharacter(EFalse) |
|
54 { |
|
55 iFlags.Set( EFlagIsBeginningOfLoop ); |
|
56 iFlags.Set( EFlagUseVisualToLogicalConversion ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAknMarqueeControl::ConstructL |
|
61 // Symbian 2nd phase constructor can leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CAknMarqueeControl::ConstructL() |
|
65 { |
|
66 iPeriodicTimer = CPeriodic::NewL(CActive::EPriorityIdle); |
|
67 ControlEnv()->AddForegroundObserverL(*this); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CAknMarqueeControl::NewLC |
|
72 // Two-phased constructor. |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C CAknMarqueeControl* CAknMarqueeControl::NewLC(const TInt aLoops, |
|
76 const TInt aScrollAmount, |
|
77 const TInt aScrollDelay) |
|
78 { |
|
79 CAknMarqueeControl* self = new( ELeave )CAknMarqueeControl(aLoops, aScrollAmount, aScrollDelay); |
|
80 |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 |
|
84 return self; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CAknMarqueeControl::NewL |
|
89 // Two-phased constructor. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 EXPORT_C CAknMarqueeControl* CAknMarqueeControl::NewL(const TInt aLoops, |
|
93 const TInt aScrollAmount, |
|
94 const TInt aScrollDelay) |
|
95 { |
|
96 CAknMarqueeControl* self = CAknMarqueeControl::NewLC(aLoops, aScrollAmount, aScrollDelay); |
|
97 CleanupStack::Pop(); |
|
98 |
|
99 return self; |
|
100 } |
|
101 |
|
102 // Destructor |
|
103 CAknMarqueeControl::~CAknMarqueeControl() |
|
104 { |
|
105 if (iPeriodicTimer) |
|
106 { |
|
107 iPeriodicTimer->Cancel(); |
|
108 delete iPeriodicTimer; |
|
109 } |
|
110 ControlEnv()->RemoveForegroundObserver(*this); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CAknMarqueeControl::SetRedrawCallBack |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 EXPORT_C void CAknMarqueeControl::SetRedrawCallBack(TCallBack& aCallBack) |
|
119 { |
|
120 iCallBack = aCallBack; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CAknMarqueeControl::DrawText |
|
125 // |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 EXPORT_C TBool CAknMarqueeControl::DrawText( |
|
129 CWindowGc& aGc, |
|
130 const TRect& aMarqueeRect, |
|
131 const TDesC& aText, |
|
132 const TInt aBaselineOffset, |
|
133 const CGraphicsContext::TTextAlign aAlign, |
|
134 const CFont& aFont ) |
|
135 { |
|
136 if (iLoops < iMaxLoops || // Has every loop been executed? |
|
137 iFlags.IsSet(EFlagIsWaitingForCallBack)) |
|
138 { |
|
139 TInt textWidth = aFont.TextWidthInPixels(aText); |
|
140 |
|
141 if (TBidiText::TextDirectionality(aText) == TBidiText::ELeftToRight) |
|
142 iFlags.Set(EFlagIsWestern); |
|
143 else |
|
144 iFlags.Clear(EFlagIsWestern); |
|
145 |
|
146 // Does the text fit in the rect or is it wider |
|
147 if ( textWidth > aMarqueeRect.Width() ) |
|
148 { |
|
149 // Logical-to-visual conversion. |
|
150 |
|
151 TInt maxTextLength = KAknSensibleLength; |
|
152 |
|
153 // Stack buffer is used with normal size texts or in OOM. |
|
154 TBuf<KAknSensibleLength + KAknBidiExtraSpacePerLine> visualText; |
|
155 |
|
156 HBufC* buffer = NULL; |
|
157 const TDesC* textToBeDrawn = &aText; |
|
158 |
|
159 if ( iFlags.IsSet(EFlagUseVisualToLogicalConversion) ) |
|
160 { |
|
161 // If given text is too large for the stack buffer, |
|
162 // try to allocate a heap buffer. |
|
163 if ( aText.Length() > maxTextLength) |
|
164 { |
|
165 TInt len( aText.Length() < KAknMaxMarqueeLength ? aText.Length() : KAknMaxMarqueeLength ); |
|
166 buffer = HBufC::New( len + KAknBidiExtraSpacePerLine ); |
|
167 if ( buffer ) |
|
168 { |
|
169 maxTextLength = len; |
|
170 } |
|
171 } |
|
172 |
|
173 if ( buffer ) |
|
174 { |
|
175 TPtr p( buffer->Des() ); |
|
176 AknBidiTextUtils::ConvertToVisualAndClip( |
|
177 aText.Left( maxTextLength ), |
|
178 p, |
|
179 aFont, |
|
180 KMaxTInt, |
|
181 KMaxTInt ); |
|
182 textToBeDrawn = buffer; |
|
183 } |
|
184 else |
|
185 { |
|
186 AknBidiTextUtils::ConvertToVisualAndClip( |
|
187 aText.Left( maxTextLength ), |
|
188 visualText, |
|
189 aFont, |
|
190 KMaxTInt, |
|
191 KMaxTInt ); |
|
192 textToBeDrawn = &visualText; |
|
193 } |
|
194 } |
|
195 |
|
196 aGc.SetClippingRect(aMarqueeRect); |
|
197 |
|
198 if ( iFlags.IsSet(EFlagIsWestern) ) // Scrolls from right to left. |
|
199 { |
|
200 TRect rect = aMarqueeRect; |
|
201 rect.SetWidth(textWidth); |
|
202 if ( iFlags.IsSet(EFlagIsBeginningOfLoop) ) |
|
203 { |
|
204 if (iFlags.IsSet(EFlagIsWaitingForCallBack)) |
|
205 { |
|
206 rect.Move(-iDelta, 0); |
|
207 } |
|
208 Stop(); // Just in case |
|
209 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign, 0); |
|
210 rect.Move(iDelta, 0); |
|
211 iFlags.Clear(EFlagIsBeginningOfLoop); |
|
212 Start(); |
|
213 aGc.CancelClippingRect(); |
|
214 if ( buffer ) |
|
215 { |
|
216 delete buffer; |
|
217 } |
|
218 return EFalse; // all drawn for first loop |
|
219 } |
|
220 rect.Move(-iDelta, 0); |
|
221 |
|
222 // Sliding behaviour: When the last character is visible, scrolling stops |
|
223 // and starts from the beginning after a short delay. |
|
224 if (rect.iBr.iX >= aMarqueeRect.iBr.iX || iFlags.IsSet(EFlagIsWaitingForCallBack)) |
|
225 { |
|
226 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign, 0); |
|
227 iFlags.Clear(EFlagIsBeginningOfLoop); |
|
228 if ( !iPeriodicTimer->IsActive() ) |
|
229 Start(); |
|
230 } |
|
231 else // Last character has appeared, so let's make it reappear from the other |
|
232 { // side after a delay |
|
233 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign, 0); |
|
234 //Stop(); // Cancel all outstanding requests. |
|
235 iPeriodicTimer->Cancel(); |
|
236 iFlags.Set(EFlagIsBeginningOfLoop); |
|
237 iFlags.Set(EFlagIsWaitingForCallBack); |
|
238 iLastCharacter = ETrue; |
|
239 iLoops++; |
|
240 Start(); |
|
241 } |
|
242 } |
|
243 else // Non-western, scrolls from left to right. |
|
244 { |
|
245 TRect rect = aMarqueeRect; |
|
246 // Prepare rect to be scrolled from l -> r |
|
247 rect.iTl.iX = rect.iTl.iX - (textWidth - rect.Width()); |
|
248 |
|
249 if ( iFlags.IsSet(EFlagIsBeginningOfLoop) ) |
|
250 { |
|
251 if (iFlags.IsSet(EFlagIsWaitingForCallBack)) |
|
252 { |
|
253 rect.Move(iDelta, 0); |
|
254 } |
|
255 Stop(); // Just in case |
|
256 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign, 0); |
|
257 rect.Move(-iDelta, 0); |
|
258 iFlags.Clear(EFlagIsBeginningOfLoop); |
|
259 Start(); |
|
260 aGc.CancelClippingRect(); |
|
261 if ( buffer ) |
|
262 { |
|
263 delete buffer; |
|
264 } |
|
265 return EFalse; // all drawn for first loop |
|
266 } |
|
267 rect.Move(iDelta, 0); |
|
268 |
|
269 if (rect.iTl.iX < aMarqueeRect.iTl.iX || iFlags.IsSet(EFlagIsWaitingForCallBack)) |
|
270 { |
|
271 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign, 0); |
|
272 iFlags.Clear(EFlagIsBeginningOfLoop); |
|
273 if ( !iPeriodicTimer->IsActive() ) |
|
274 Start(); |
|
275 } |
|
276 else // Last character has appeared |
|
277 { |
|
278 aGc.DrawText(*textToBeDrawn, rect, aBaselineOffset, aAlign); |
|
279 //Stop(); // Cancel all outstanding requests. |
|
280 iPeriodicTimer->Cancel(); |
|
281 iFlags.Set(EFlagIsBeginningOfLoop); |
|
282 iFlags.Set(EFlagIsWaitingForCallBack); |
|
283 iLastCharacter = ETrue; |
|
284 iLoops++; |
|
285 Start(); |
|
286 } |
|
287 } |
|
288 |
|
289 delete buffer; |
|
290 aGc.CancelClippingRect(); |
|
291 } |
|
292 |
|
293 // Time to let the parent know all loops aren't executed yet. |
|
294 return EFalse; |
|
295 } |
|
296 else // No more loops to be executed -> draw text in the default position. |
|
297 { |
|
298 //aGc.DrawText(aText, aMarqueeRect, aBaselineOffset, aAlign, 0); |
|
299 Stop(); // No need to generate events any longer. |
|
300 return ETrue; // Indicate the parent that marquee has stopped, |
|
301 // parent is then able to for example truncate the text. |
|
302 } |
|
303 } |
|
304 |
|
305 EXPORT_C TBool CAknMarqueeControl::DrawText( |
|
306 CWindowGc& aGc, |
|
307 const TRect& aRect, |
|
308 const TAknTextComponentLayout& aTextLayout, |
|
309 const TDesC& aText, |
|
310 const CFont* aFont) |
|
311 { |
|
312 RDebug::Print(_L("Warning: Deprecated method CAknMarqueeControl::DrawText( CWindowGc&, TRect&, TAknTextComponentLayout&, TDesC&, CFont* called" ) ); |
|
313 RDebug::Print(_L("Call CAknMarqueeControl::DrawText(CWindowGc&,,,,, TRgb aColor ) instead") ); |
|
314 return DrawText( aGc, aRect, aTextLayout, aText, aFont, KRgbBlack ); |
|
315 } |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CAknMarqueeControl::DrawText |
|
318 // |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C TBool CAknMarqueeControl::DrawText( |
|
322 CWindowGc& aGc, |
|
323 const TRect& aRect, |
|
324 const TAknTextComponentLayout& aTextLayout, |
|
325 const TDesC& aText, |
|
326 const CFont* aFont, |
|
327 TRgb aColor ) |
|
328 { |
|
329 // In this function, TAknLayoutText::DrawText performs logical-to-visual |
|
330 // conversion for the given text. |
|
331 if ( iLoops < iMaxLoops ) // Has every loop been executed? |
|
332 { |
|
333 TAknLayoutText textLayout; |
|
334 |
|
335 if ( aFont ) |
|
336 { |
|
337 textLayout.LayoutText( aRect, aTextLayout, aFont ); |
|
338 } |
|
339 else |
|
340 { |
|
341 textLayout.LayoutText( aRect, aTextLayout ); |
|
342 } |
|
343 |
|
344 TRect marqueeRect( textLayout.TextRect() ); |
|
345 TInt textWidth = textLayout.Font()->TextWidthInPixels( aText ); |
|
346 |
|
347 if ( TBidiText::TextDirectionality( aText ) == TBidiText::ELeftToRight ) |
|
348 iFlags.Set( EFlagIsWestern ); |
|
349 else |
|
350 iFlags.Clear( EFlagIsWestern ); |
|
351 |
|
352 aGc.SetClippingRect( marqueeRect ); |
|
353 |
|
354 if ( iFlags.IsSet( EFlagIsWestern ) ) // Scrolls from right to left. |
|
355 { |
|
356 // Does the text fit in the rect or is it wider |
|
357 if ( textWidth > marqueeRect.Width() ) |
|
358 { |
|
359 TRect rect = aRect; |
|
360 rect.SetWidth( aRect.Width() + ( textWidth - marqueeRect.Width() ) ); |
|
361 if ( iFlags.IsSet( EFlagIsBeginningOfLoop ) && |
|
362 !iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
363 { |
|
364 Stop(); // Just in case |
|
365 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
366 iFlags.Clear( EFlagIsBeginningOfLoop ); |
|
367 Start(); |
|
368 aGc.CancelClippingRect(); |
|
369 return EFalse; // all drawn for first loop |
|
370 } |
|
371 |
|
372 if ( iDelta == 0 ) // we are still drawing non-scrolling text (2 line lists need this) |
|
373 { |
|
374 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
375 aGc.CancelClippingRect(); |
|
376 return EFalse; |
|
377 } |
|
378 |
|
379 rect.Move(-iDelta, 0); |
|
380 |
|
381 // ESRY-7M5A33 |
|
382 // Due to text rolling region is not actual parent region, |
|
383 // textLayout.TextRect() is incorrect. Introduce a temparory layout to recalculate. |
|
384 TAknTextLineLayout tmpTextLineLayout = aTextLayout; |
|
385 tmpTextLineLayout.iW = textWidth; |
|
386 // ESLM-7SE7HE |
|
387 // If left margin isn't given reasonable value, calculate it from other values in advance |
|
388 if (IsParentRelative(tmpTextLineLayout.il)) |
|
389 { |
|
390 tmpTextLineLayout.il = rect.Width() - tmpTextLineLayout.ir - tmpTextLineLayout.iW; |
|
391 } |
|
392 if ( aFont ) |
|
393 { |
|
394 textLayout.LayoutText( rect, tmpTextLineLayout, aFont ); |
|
395 } |
|
396 else |
|
397 { |
|
398 textLayout.LayoutText( rect, tmpTextLineLayout ); |
|
399 } |
|
400 |
|
401 if ( iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
402 { |
|
403 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
404 aGc.CancelClippingRect(); |
|
405 return EFalse; // all drawn for end delay |
|
406 } |
|
407 |
|
408 // Sliding behaviour: When the last character is visible, scrolling stops |
|
409 // and starts from the beginning after a short delay. |
|
410 if ( textLayout.TextRect().iBr.iX >= marqueeRect.iBr.iX ) |
|
411 { |
|
412 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
413 iFlags.Clear( EFlagIsBeginningOfLoop ); |
|
414 if ( !iPeriodicTimer->IsActive() ) |
|
415 Start(); |
|
416 } |
|
417 else // Last character has appeared, so let's make it reappear from the other |
|
418 { // side after a delay |
|
419 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
420 iFlags.Set( EFlagIsBeginningOfLoop ); |
|
421 iFlags.Set( EFlagIsWaitingForCallBack ); |
|
422 iLastCharacter = ETrue; |
|
423 Stop(); // Cancel all outstanding requests. |
|
424 ++iLoops; |
|
425 Start(); |
|
426 } |
|
427 } |
|
428 } |
|
429 else // Non-western, scrolls from left to right. |
|
430 { |
|
431 if ( textWidth > marqueeRect.Width() ) |
|
432 { |
|
433 TRect rect = aRect; |
|
434 // Prepare rect to be scrolled from l -> r |
|
435 rect.iTl.iX = rect.iTl.iX - ( textWidth - marqueeRect.Width() ); |
|
436 |
|
437 if ( iFlags.IsSet( EFlagIsBeginningOfLoop ) && |
|
438 !iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
439 { |
|
440 Stop(); // Just in case |
|
441 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
442 iFlags.Clear( EFlagIsBeginningOfLoop ); |
|
443 Start(); |
|
444 aGc.CancelClippingRect(); |
|
445 return EFalse; // all drawn for first loop |
|
446 } |
|
447 |
|
448 if ( iDelta == 0 ) // we are still drawing non-scrolling text (2 line lists need this) |
|
449 { |
|
450 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
451 aGc.CancelClippingRect(); |
|
452 return EFalse; |
|
453 } |
|
454 |
|
455 rect.Move(iDelta, 0); |
|
456 |
|
457 // note refer to case western |
|
458 TAknTextLineLayout tmpTextLineLayout = aTextLayout; |
|
459 tmpTextLineLayout.iW = textWidth; |
|
460 // ESLM-7SE7HE |
|
461 // If right margin isn't given reasonable value, calculate it from other values in advance |
|
462 if (IsParentRelative(tmpTextLineLayout.ir)) |
|
463 { |
|
464 tmpTextLineLayout.ir = rect.Width() - tmpTextLineLayout.il - tmpTextLineLayout.iW; |
|
465 } |
|
466 if ( aFont ) |
|
467 { |
|
468 textLayout.LayoutText( rect, tmpTextLineLayout, aFont ); |
|
469 } |
|
470 else |
|
471 { |
|
472 textLayout.LayoutText( rect, tmpTextLineLayout ); |
|
473 } |
|
474 |
|
475 if ( iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
476 { |
|
477 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
478 aGc.CancelClippingRect(); |
|
479 return EFalse; // all drawn for end delay |
|
480 } |
|
481 |
|
482 if ( textLayout.TextRect().iTl.iX < marqueeRect.iTl.iX ) |
|
483 { |
|
484 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
485 iFlags.Clear( EFlagIsBeginningOfLoop ); |
|
486 if ( !iPeriodicTimer->IsActive() ) |
|
487 Start(); |
|
488 } |
|
489 else // Last character has appeared |
|
490 { |
|
491 textLayout.DrawText( aGc, aText, iFlags.IsSet( EFlagUseVisualToLogicalConversion ), aColor ); |
|
492 iFlags.Set( EFlagIsBeginningOfLoop ); |
|
493 iFlags.Set( EFlagIsWaitingForCallBack ); |
|
494 iLastCharacter = ETrue; |
|
495 Stop(); // Cancel all outstanding requests. |
|
496 ++iLoops; |
|
497 Start(); |
|
498 } |
|
499 } |
|
500 } |
|
501 |
|
502 aGc.CancelClippingRect(); |
|
503 // Time to let the parent know all loops aren't executed yet. |
|
504 return EFalse; |
|
505 } |
|
506 else // No more loops to be executed -> draw text in the default position. |
|
507 { |
|
508 //aGc.DrawText(aText, aMarqueeRect, aBaselineOffset, aAlign, 0); |
|
509 Stop(); // No need to generate events any longer. |
|
510 return ETrue; // Indicate the parent that marquee has stopped, |
|
511 } // parent is then able to for example truncate the text. |
|
512 } |
|
513 |
|
514 // ----------------------------------------------------------------------------- |
|
515 // CAknMarqueeControl::Draw |
|
516 // Draws the text to the proper position. |
|
517 // ----------------------------------------------------------------------------- |
|
518 // |
|
519 void CAknMarqueeControl::Draw(const TRect& /*aRect*/) const |
|
520 { |
|
521 /* nothing to do here really */ |
|
522 } |
|
523 |
|
524 // ----------------------------------------------------------------------------- |
|
525 // CAknMarqueeControl::Start |
|
526 // Starts scrolling the text. |
|
527 // ----------------------------------------------------------------------------- |
|
528 // |
|
529 EXPORT_C void CAknMarqueeControl::Start() |
|
530 { |
|
531 if ( iFlags.IsSet( EFlagIsOn ) ) |
|
532 { |
|
533 if ( !iPeriodicTimer->IsActive() ) // start timer if not already started |
|
534 { |
|
535 iPeriodicTimer->Start( TTimeIntervalMicroSeconds32( iDelay ), |
|
536 TTimeIntervalMicroSeconds32( iInterval ), |
|
537 TCallBack( CAknMarqueeControl::ScrollEvent, this ) ); |
|
538 } |
|
539 } |
|
540 } |
|
541 |
|
542 // ----------------------------------------------------------------------------- |
|
543 // CAknMarqueeControl::Stop |
|
544 // Stops scrolling the text. |
|
545 // ----------------------------------------------------------------------------- |
|
546 // |
|
547 EXPORT_C void CAknMarqueeControl::Stop() |
|
548 { |
|
549 //Stop the timer if it is active |
|
550 if ( iPeriodicTimer->IsActive() ) |
|
551 { |
|
552 iPeriodicTimer->Cancel(); |
|
553 } |
|
554 if ( !iFlags.IsSet(EFlagIsWaitingForCallBack) ) |
|
555 { |
|
556 iDelta = 0; // reset scroll position |
|
557 } |
|
558 } |
|
559 |
|
560 // ----------------------------------------------------------------------------- |
|
561 // CAknMarqueeControl::Reset |
|
562 // Resets the animation data. |
|
563 // ----------------------------------------------------------------------------- |
|
564 // |
|
565 EXPORT_C void CAknMarqueeControl::Reset() |
|
566 { |
|
567 iDelta = 0; // reset scroll position |
|
568 iLoops = 0; |
|
569 iLastCharacter = EFalse; |
|
570 Stop(); |
|
571 iFlags.Set( EFlagIsBeginningOfLoop ); |
|
572 iFlags.Clear( EFlagIsWaitingForCallBack ); |
|
573 } |
|
574 |
|
575 // ----------------------------------------------------------------------------- |
|
576 // CAknMarqueeControl::IsMarqueeOn |
|
577 // Returns marquee status |
|
578 // Two versions to discard compiler warnings |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 #ifdef __WINS__ |
|
582 EXPORT_C const TBool CAknMarqueeControl::IsMarqueeOn() |
|
583 { |
|
584 return iFlags.IsSet( EFlagIsOn ); |
|
585 } |
|
586 #else |
|
587 EXPORT_C TBool CAknMarqueeControl::IsMarqueeOn() |
|
588 { |
|
589 return iFlags.IsSet( EFlagIsOn ); |
|
590 } |
|
591 #endif // __WINS__ |
|
592 |
|
593 // ----------------------------------------------------------------------------- |
|
594 // CAknMarqueeControl::SetSpeedInPixels |
|
595 // sets scrolling speed in pixels |
|
596 // ----------------------------------------------------------------------------- |
|
597 // |
|
598 EXPORT_C void CAknMarqueeControl::SetSpeedInPixels(TInt aSpeed) |
|
599 { |
|
600 if ( aSpeed <= 0 ) |
|
601 aSpeed = KAknMarqueeSpeed; |
|
602 iSpeed = aSpeed; |
|
603 } |
|
604 |
|
605 // ----------------------------------------------------------------------------- |
|
606 // CAknMarqueeControl::SetDelay |
|
607 // Sets delay between loops |
|
608 // ----------------------------------------------------------------------------- |
|
609 // |
|
610 EXPORT_C void CAknMarqueeControl::SetDelay(TInt aDelay) |
|
611 { |
|
612 if ( aDelay < 0 ) |
|
613 aDelay = KAknMarqueeDelay; |
|
614 iDelay = aDelay; |
|
615 } |
|
616 |
|
617 // ----------------------------------------------------------------------------- |
|
618 // CAknMarqueeControl::SetInterval |
|
619 // Sets scrolling interval |
|
620 // ----------------------------------------------------------------------------- |
|
621 // |
|
622 EXPORT_C void CAknMarqueeControl::SetInterval(TInt aInterval) |
|
623 { |
|
624 iInterval = aInterval; |
|
625 } |
|
626 |
|
627 // ----------------------------------------------------------------------------- |
|
628 // CAknMarqueeControl::SetLoops |
|
629 // Sets the amount of maximum loops to be executed. |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 EXPORT_C void CAknMarqueeControl::SetLoops(TInt aLoops) |
|
633 { |
|
634 if ( aLoops < 0 ) |
|
635 aLoops = KAknMarqueeLoops; |
|
636 iMaxLoops = aLoops; |
|
637 } |
|
638 |
|
639 // ----------------------------------------------------------------------------- |
|
640 // CAknMarqueeControl::DoScroll |
|
641 // advances text position and instructs parent control to do a redraw |
|
642 // ----------------------------------------------------------------------------- |
|
643 // |
|
644 void CAknMarqueeControl::DoScroll() |
|
645 { |
|
646 if ( !iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
647 { |
|
648 iDelta += iSpeed; // advance text |
|
649 } |
|
650 |
|
651 iFlags.Clear( EFlagIsWaitingForCallBack ); |
|
652 |
|
653 if ( !iCallBack.CallBack() ) // stop timer if callback returns false |
|
654 { |
|
655 iPeriodicTimer->Cancel(); |
|
656 } |
|
657 } |
|
658 |
|
659 // ----------------------------------------------------------------------------- |
|
660 // CAknMarqueeControl::ScrollEvent |
|
661 // This static function is called by the periodic timer |
|
662 // ----------------------------------------------------------------------------- |
|
663 // |
|
664 TInt CAknMarqueeControl::ScrollEvent(TAny * aPtr) |
|
665 { |
|
666 ( ( CAknMarqueeControl* ) aPtr )->DoScroll(); |
|
667 return TRUE; // run again |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CAknMarqueeControl::EnableMarquee |
|
672 // Enables/disables marquee feature. |
|
673 // ----------------------------------------------------------------------------- |
|
674 // |
|
675 EXPORT_C void CAknMarqueeControl::EnableMarquee(TBool aEnable) |
|
676 { |
|
677 if ( aEnable ) |
|
678 { |
|
679 iFlags.Set( EFlagIsOn ); |
|
680 } |
|
681 else |
|
682 { |
|
683 iFlags.Clear( EFlagIsOn ); |
|
684 } |
|
685 } |
|
686 |
|
687 // ----------------------------------------------------------------------------- |
|
688 // CAknMarqueeControl::HandleResourceChange |
|
689 // Handle fade and unfade message for starts and stops scrolling the text. |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 void CAknMarqueeControl::HandleResourceChange(TInt aType) |
|
693 { |
|
694 if( aType == KEikMessageUnfadeWindows ) |
|
695 { |
|
696 if ( ( !iFlags.IsSet( EFlagIsBeginningOfLoop ) |
|
697 && !iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
698 || iLastCharacter ) |
|
699 { |
|
700 iLastCharacter = EFalse; |
|
701 Start(); |
|
702 } |
|
703 } |
|
704 else if ( aType == KEikMessageFadeAllWindows ) |
|
705 { |
|
706 Stop(); |
|
707 } |
|
708 CCoeControl::HandleResourceChange( aType ); |
|
709 } |
|
710 |
|
711 // ----------------------------------------------------------------------------- |
|
712 // CAknMarqueeControl::HandleGainingForeground |
|
713 // ----------------------------------------------------------------------------- |
|
714 // |
|
715 void CAknMarqueeControl::HandleGainingForeground() |
|
716 { |
|
717 // AJUA-7JCDRR, set marquee text to beginning. |
|
718 if ( ( !iFlags.IsSet( EFlagIsBeginningOfLoop ) |
|
719 && !iFlags.IsSet( EFlagIsWaitingForCallBack ) ) |
|
720 || iLastCharacter ) |
|
721 { |
|
722 iLastCharacter = EFalse; |
|
723 Start(); |
|
724 } |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // CAknMarqueeControl::HandleLosingForeground |
|
729 // ----------------------------------------------------------------------------- |
|
730 // |
|
731 void CAknMarqueeControl::HandleLosingForeground() |
|
732 { |
|
733 // AJUA-7JCDRR, do not reset it, just then marquee can be resumed |
|
734 Stop(); |
|
735 } |
|
736 |
|
737 // ----------------------------------------------------------------------------- |
|
738 // CAknMarqueeControl::UseLogicalToVisualConversion |
|
739 // ----------------------------------------------------------------------------- |
|
740 // |
|
741 |
|
742 EXPORT_C void CAknMarqueeControl::UseLogicalToVisualConversion( |
|
743 TBool aUseConversion ) |
|
744 { |
|
745 if ( aUseConversion ) |
|
746 { |
|
747 iFlags.Set( EFlagUseVisualToLogicalConversion ); |
|
748 } |
|
749 else |
|
750 { |
|
751 iFlags.Clear( EFlagUseVisualToLogicalConversion ); |
|
752 } |
|
753 } |
|
754 |
|
755 // End of File |