|
1 /* |
|
2 * Copyright (c) 2002-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: Text scrolling functionality. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef XNNEWSTICKERCONTROL_H |
|
20 #define XNNEWSTICKERCONTROL_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class CXnNewstickerAdapter; |
|
27 class CFont; |
|
28 |
|
29 // CLASS DECLARATION |
|
30 |
|
31 /** |
|
32 * @ingroup group_xnnewstickerfactory |
|
33 * |
|
34 * Newsticker control for XUIKON text scrolling functionality. |
|
35 * |
|
36 * @lib xn3newstickerfactory.dll |
|
37 * @since Series 60 3.2 |
|
38 */ |
|
39 class CXnNewstickerControl : public CBase |
|
40 { |
|
41 public: |
|
42 |
|
43 /** |
|
44 * Two-phased constructor. |
|
45 * @param aAdapter Parent control |
|
46 * @param aLoops Max number of loops to be executed |
|
47 * @param aScrollAmount The amount of pixels scrolled per iteration |
|
48 * @param aScrollDelay The interval between iterations |
|
49 * @param aStartDelay The delay before the animation starts |
|
50 * @return Pointer to this. |
|
51 */ |
|
52 static CXnNewstickerControl* NewL(CXnNewstickerAdapter* aAdapter); |
|
53 |
|
54 /** |
|
55 * Sets newsticker scroll amount. |
|
56 * @param aScrollAmount A scroll amount. |
|
57 * @return void |
|
58 */ |
|
59 void SetScrollAmount(TInt aScrollAmount); |
|
60 |
|
61 /** |
|
62 * Sets the rect of the visible area. |
|
63 * @param aContentRect The visible rect. |
|
64 * @return void |
|
65 */ |
|
66 void SetNewstickerRect(TRect& aContentRect); |
|
67 |
|
68 /** |
|
69 * Checks whether a western layout is used. |
|
70 * @return Returns true if wesern layout is in use. |
|
71 */ |
|
72 TBool IsWestern(); |
|
73 |
|
74 // Routed from MXnNewstickerInterface. |
|
75 |
|
76 /** |
|
77 * Append new title to the end of the title list. |
|
78 * @param aTitle The new title to add. |
|
79 */ |
|
80 void AppendTitleL(const TDesC& aTitle); |
|
81 |
|
82 /** |
|
83 * Insert new title to the end of the title list. |
|
84 * @param aTitle The new title to add. |
|
85 * @param aIndex The place to add the title. |
|
86 */ |
|
87 void InsertTitleL(const TDesC& aTitle, TInt aIndex); |
|
88 |
|
89 /** |
|
90 * Update title in the title list. |
|
91 * @param aTitle The new title to add. |
|
92 * @param aIndex The place to add the title. |
|
93 */ |
|
94 void UpdateTitleL(const TDesC& aTitle, TInt aIndex); |
|
95 |
|
96 /** |
|
97 * Delete the title. |
|
98 * @param aIndex The title index to delete. |
|
99 */ |
|
100 void DeleteTitleL(TInt aIndex); |
|
101 |
|
102 /** |
|
103 * Returns index of the currently selected title. |
|
104 * @return The index of the current title. |
|
105 */ |
|
106 TInt CurrentTitleIndex(); |
|
107 |
|
108 /** |
|
109 * Return the title of the given index. |
|
110 * @param aIndex The index to return the title. |
|
111 * @return The title of the given index. |
|
112 */ |
|
113 const TDesC& Title(TInt aIndex); |
|
114 |
|
115 /** |
|
116 * Set the separator image for all titles. |
|
117 * @param aIcon The separator image. This must be mif icon. |
|
118 * @return KErrNone if successful, KErrArgument if the icon is not mif. |
|
119 */ |
|
120 TInt SetSeparatorImageL(CGulIcon* aIcon); |
|
121 |
|
122 /** |
|
123 * Delete all titles. |
|
124 */ |
|
125 void ClearTitles(); |
|
126 |
|
127 /** |
|
128 * Append the SVG title to be shown. |
|
129 * @param aByteData The SVG data. |
|
130 */ |
|
131 void AppendSvgTitleL(const TDesC8& aByteData); |
|
132 |
|
133 /** |
|
134 * Insert the SVG title to be shown. |
|
135 * @param aByteData The SVG data. |
|
136 */ |
|
137 void InsertSvgTitleL(const TDesC8& aByteData, TInt aIndex); |
|
138 |
|
139 /** |
|
140 * Return the current svg title. |
|
141 * @return The current svg title. |
|
142 */ |
|
143 const TDesC8& CurrentSvgTitle(); |
|
144 |
|
145 /** |
|
146 * Return the number of titles in the list. |
|
147 * @return The number of titles in the list. |
|
148 */ |
|
149 TInt TitleCount() const; |
|
150 |
|
151 /** |
|
152 * Move to the next title. |
|
153 */ |
|
154 void MoveToNextL(); |
|
155 |
|
156 /** |
|
157 * Move to the previous title. |
|
158 */ |
|
159 void MoveToPrevL(); |
|
160 |
|
161 /** |
|
162 * Move to first title |
|
163 */ |
|
164 void MoveToFirstL(); |
|
165 |
|
166 /** |
|
167 * Move to last title |
|
168 */ |
|
169 void MoveToLastL(); |
|
170 |
|
171 /** |
|
172 * Move to the previous title. |
|
173 */ |
|
174 void MoveToCurrent(); |
|
175 |
|
176 /** |
|
177 * Sets font for bitmap graphic context. |
|
178 * @param aFont Font family. |
|
179 */ |
|
180 void SetFont(CFont* aFont); |
|
181 |
|
182 /** |
|
183 * Sets text color for bitmap graphic context. |
|
184 * @param aColor Color in RGB format. |
|
185 */ |
|
186 void SetTextColor(TRgb aColor); |
|
187 |
|
188 /** |
|
189 * Sets the underline style for all subsequently drawn text. |
|
190 * @param aStyle Underline style, which can be either on of off. |
|
191 */ |
|
192 void SetTextUnderlineStyle(TFontUnderline aStyle); |
|
193 |
|
194 /** |
|
195 * Sets the strikethrough style for all subsequently drawn text. |
|
196 * @param aStyle Strikethrough style, which can be either on of off. |
|
197 */ |
|
198 void SetTextStrikethroughStyle(TFontStrikethrough aStyle); |
|
199 |
|
200 /** |
|
201 * Destructor |
|
202 */ |
|
203 virtual ~CXnNewstickerControl(); |
|
204 |
|
205 /** |
|
206 * Creates background bitmap |
|
207 */ |
|
208 void CreateBufferBitmapL(); |
|
209 |
|
210 /** |
|
211 * Advance text and issue a callback to parent |
|
212 */ |
|
213 void DoScrollL(); |
|
214 |
|
215 /** |
|
216 * Blit visible stuff to d-buffer. Drawing direction is left-to-right. |
|
217 */ |
|
218 void PrepareToDrawLtrL(); |
|
219 |
|
220 /** |
|
221 * Blit visible stuff to d-buffer. Drawing direction is right-to-left. |
|
222 */ |
|
223 void PrepareToDrawRtlL(); |
|
224 |
|
225 /** |
|
226 * Blit double buffer to gc. |
|
227 */ |
|
228 void Draw(); |
|
229 |
|
230 /** |
|
231 * Blit double buffer to gc. Draws only the last title truncated. |
|
232 */ |
|
233 void DrawStatic(); |
|
234 |
|
235 /** |
|
236 * Sets iFirstdrawingOffset as a start position. |
|
237 */ |
|
238 void SetBeginningState(); |
|
239 |
|
240 /** |
|
241 * Return the font |
|
242 * @return font |
|
243 */ |
|
244 inline const CFont* Font() { return iFont; }; |
|
245 |
|
246 /** |
|
247 * Return the text color. |
|
248 * @return Text color. |
|
249 */ |
|
250 inline const TRgb TextColor() { return iTextColor; }; |
|
251 |
|
252 /** |
|
253 * Return font underline flag. |
|
254 * @return Font underline flag. |
|
255 */ |
|
256 inline const TFontUnderline TextUnderlineStyle() { return iUnderlining; }; |
|
257 |
|
258 /** |
|
259 * Return the font strikethrough flag. |
|
260 * @return Font strikethrough flag. |
|
261 */ |
|
262 inline const TFontStrikethrough TextStrikethroughStyle() { return iStrikethrough; }; |
|
263 |
|
264 /** |
|
265 * Set scroll looping property |
|
266 */ |
|
267 void SetScrollLooping( TBool aLoop ); |
|
268 |
|
269 /** |
|
270 * Return scroll looping property |
|
271 * @return TBool |
|
272 */ |
|
273 TBool ScrollLooping(); |
|
274 |
|
275 /** |
|
276 * @return ETrue if all the text fits on the drawing rect. In that case no scrolling and |
|
277 * text alignment should be used |
|
278 */ |
|
279 TBool TextFitInNewstickerRect(); |
|
280 |
|
281 /** |
|
282 * @param aAlignment ( ELayoutAlignCenter, ELayoutAlignLeft or ELayoutAlignRight ) |
|
283 * ELayoutAlignLeft default in western, ELayoutAlignRight in AH. |
|
284 */ |
|
285 void SetTextAlignment(TInt aAlignment); |
|
286 |
|
287 /** |
|
288 * @return ETrue if the current text fits on |
|
289 * the drawing rect (when scrolling behaviour is scroll-alternate) |
|
290 * EFalse otherwise. |
|
291 * If this is ETrue then no scrolling and text alignment should be used |
|
292 */ |
|
293 TBool CalculateCurrentTextFitInNewstickerRect(); |
|
294 |
|
295 private: |
|
296 |
|
297 CXnNewstickerControl(CXnNewstickerAdapter* aAdapter); |
|
298 |
|
299 void ConstructL(); |
|
300 |
|
301 /** |
|
302 * Calculate the indexes and offset after new title has been inserted. |
|
303 * @param aIndex The inserted index. |
|
304 */ |
|
305 void CountIndexAfterInsertL(TInt aIndex); |
|
306 |
|
307 /** |
|
308 * @return ETrue if all the text fits on the drawing rect (when scrolling behaviour is slide) |
|
309 * EFalse otherwise. |
|
310 * If this is ETrue then no scrolling and text alignment should be used |
|
311 */ |
|
312 TBool CalculateTextFitInNewstickerRect(); |
|
313 |
|
314 /** |
|
315 * @return text alignment from properties if text fits to the rect or scroll behaviour is alternate. |
|
316 * otherwise returns default alignment value (left in western, right in AH). |
|
317 */ |
|
318 CGraphicsContext::TTextAlign TextAlignment(); |
|
319 /** |
|
320 * Get the index of the next title that has content |
|
321 * |
|
322 * @param aStartSearch The index where to start search |
|
323 * @param aBackwards Search backwards |
|
324 * |
|
325 * @return The next index that has content or -1 if nothing was found |
|
326 */ |
|
327 TInt GetNextTitleWithContent( TInt aStartSearch, TBool aBackwards = EFalse ); |
|
328 |
|
329 TBool IsVisibleTitles(); |
|
330 |
|
331 private: // Data |
|
332 |
|
333 /** |
|
334 * Helper class containing the title text and its length in pixels. |
|
335 * |
|
336 * @lib xnnewstickerfactory.dll |
|
337 * @since Series 60 3.2 |
|
338 */ |
|
339 class CTitleData : public CBase |
|
340 { |
|
341 public: |
|
342 |
|
343 /** |
|
344 * Destructor |
|
345 */ |
|
346 virtual ~CTitleData(); |
|
347 |
|
348 /** |
|
349 * Two-phased constructor. |
|
350 * @param aTitle The title text. |
|
351 * @param aLenghtInPixels The lenght of title text in pixels. |
|
352 * @return Pointer to this. |
|
353 */ |
|
354 static CTitleData* NewL(const TDesC& aTitle, TInt aLenghtInPixels); |
|
355 |
|
356 /** |
|
357 * Two-phased constructor. |
|
358 * @param aTitle The title text. |
|
359 * @param aLenghtInPixels The lenght of title text in pixels. |
|
360 * @return Pointer to this. |
|
361 */ |
|
362 static CTitleData* NewLC(const TDesC& aTitle, TInt aLenghtInPixels); |
|
363 |
|
364 /** |
|
365 * Two-phased constructor. |
|
366 * @param aByteData The SVG title. |
|
367 * @param aLenghtInPixels The lenght of title text in pixels. |
|
368 * @return Pointer to this. |
|
369 */ |
|
370 static CTitleData* NewL(const TDesC8& aByteData); |
|
371 |
|
372 /** |
|
373 * Two-phased constructor. |
|
374 * @param aByteData The SVG title. |
|
375 * @param aLenghtInPixels The lenght of title text in pixels. |
|
376 * @return Pointer to this. |
|
377 */ |
|
378 static CTitleData* NewLC(const TDesC8& aByteData); |
|
379 |
|
380 /** |
|
381 * Return the title text. |
|
382 * @return The title text. |
|
383 */ |
|
384 const TDesC& TitleText(); |
|
385 |
|
386 /** |
|
387 * Set new title text |
|
388 */ |
|
389 void SetTitleTextL(const TDesC& aTitle); |
|
390 |
|
391 /** |
|
392 * Return the title text lenght in pixels. |
|
393 * @return The title text lenght in pixels. |
|
394 */ |
|
395 TInt TitleTextLengthInPixels(); |
|
396 |
|
397 /** |
|
398 * Return the title text lenght in pixels. |
|
399 * @param aLenghtInPixels The lenght of title text in pixels. |
|
400 */ |
|
401 void SetTitleTextLengthInPixels(TInt aLenghtInPixels); |
|
402 |
|
403 /** |
|
404 * ETrue if the title is svg, EFalse if it is text. |
|
405 * @return ETrue if the title is svg, EFalse if it is text. |
|
406 */ |
|
407 TBool IsSvgTitle(); |
|
408 |
|
409 /** |
|
410 * Return the svg title data. |
|
411 * @return The svg title data. |
|
412 */ |
|
413 const TDesC8& SvgTitleData(); |
|
414 |
|
415 private: |
|
416 |
|
417 CTitleData(TInt aLenghtInPixels = 0); |
|
418 |
|
419 void ConstructL(const TDesC& aTitle); |
|
420 |
|
421 void ConstructL(const TDesC8& aByteData); |
|
422 |
|
423 private: // Data |
|
424 |
|
425 /** |
|
426 * ETrue if the title is SVG, EFalse if it is text. |
|
427 */ |
|
428 TBool iTitleIsSvg; |
|
429 |
|
430 /** |
|
431 * The title text. Owned. |
|
432 */ |
|
433 HBufC* iText; |
|
434 |
|
435 /** |
|
436 * The svg title. Owned. |
|
437 */ |
|
438 HBufC8* iData; |
|
439 |
|
440 /** |
|
441 * The title text length in pixels. |
|
442 */ |
|
443 TInt iTextLenghtInPixels; |
|
444 }; |
|
445 |
|
446 /** |
|
447 * List of titles to show. |
|
448 */ |
|
449 RPointerArray<CTitleData> iTitles; |
|
450 |
|
451 /** |
|
452 * The index of the title which is drawn first. |
|
453 */ |
|
454 TInt iFirstDrawingTitleIndex; |
|
455 |
|
456 /** |
|
457 * The number of pixels of the first title and separator image which |
|
458 * have already been shown. In other words, the number of the pixels |
|
459 * that are not visible in the screen. The iFirstDrawingTitleIndex |
|
460 * is updated when: |
|
461 * iFirstDrawingOffset > iTextLenghtInPixels + iSeparatorImageWidth |
|
462 */ |
|
463 TInt iFirstDrawingOffset; |
|
464 |
|
465 /** |
|
466 * The width of the.separator image. |
|
467 */ |
|
468 TInt iImageWidthInPixels; |
|
469 |
|
470 /** |
|
471 * The index of the title which is selected if user activates the |
|
472 * control. |
|
473 */ |
|
474 TInt iCurrentTitleIndex; |
|
475 |
|
476 /** |
|
477 * The separator image. |
|
478 * Owned. |
|
479 */ |
|
480 CGulIcon* iSeparatorimage; |
|
481 |
|
482 /** |
|
483 * The separator image including the gap between image and text. |
|
484 * Owned. |
|
485 */ |
|
486 TInt iSeparatorImageWidth; |
|
487 |
|
488 /** |
|
489 * Font |
|
490 * Not own. |
|
491 */ |
|
492 CFont* iFont; |
|
493 |
|
494 /** |
|
495 * Baseline for the text. |
|
496 */ |
|
497 TInt iTextBaseline; |
|
498 |
|
499 /** |
|
500 * Color for the text |
|
501 */ |
|
502 TRgb iTextColor; |
|
503 |
|
504 /** |
|
505 * Whether to use underlining for the text |
|
506 */ |
|
507 TFontUnderline iUnderlining; |
|
508 |
|
509 /** |
|
510 * Whether to use strikethrough for the text |
|
511 */ |
|
512 TFontStrikethrough iStrikethrough; |
|
513 |
|
514 /** |
|
515 * A rect in which the scrolling text is shown. |
|
516 */ |
|
517 TRect iContentRect; |
|
518 |
|
519 /** |
|
520 * Amount of pixels the text moves in a tick. |
|
521 */ |
|
522 TInt iSpeed; |
|
523 |
|
524 /** |
|
525 * Whether the scrolling texts will loop or not. |
|
526 * If false, the scrolling will end at the last index. |
|
527 */ |
|
528 TBool iScrollLooping; |
|
529 |
|
530 /** |
|
531 * Whether the text direction is LTR or RTL. |
|
532 */ |
|
533 TBool iIsWestern; |
|
534 |
|
535 /** |
|
536 * Parent control adapter |
|
537 * Not own. |
|
538 */ |
|
539 CXnNewstickerAdapter* iAdapter; |
|
540 |
|
541 /** |
|
542 * ETrue if there is only one title, it fits in the rect and |
|
543 * scroll behaviour is slide |
|
544 */ |
|
545 TBool iTextFitInNewstickerRect; |
|
546 /** |
|
547 * Text alignment from the properties |
|
548 */ |
|
549 TInt iTextAlignment; |
|
550 }; |
|
551 |
|
552 #endif // XNNEWSTICKERCONTROL_H |
|
553 |
|
554 // End of File |