|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <aknlayoutscalable_avkon.cdl.h> |
|
20 #include <AknUtils.h> |
|
21 #include <eikfrlb.h> |
|
22 #include <AknBidiTextUtils.h> |
|
23 #include <gdi.h> |
|
24 #include <AknLayoutFont.h> |
|
25 |
|
26 #include "mmlistbox.h" |
|
27 #include "mmmarqueeadapter.h" |
|
28 #include "mmwidgetsconstants.h" |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CMmMarqueeAdapter::CMmMarqueeAdapter () |
|
35 { |
|
36 // No implementation required |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CMmMarqueeAdapter::~CMmMarqueeAdapter () |
|
44 { |
|
45 iMarqueeElements.ResetAndDestroy(); |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CMmMarqueeAdapter* CMmMarqueeAdapter::NewLC () |
|
53 { |
|
54 CMmMarqueeAdapter* self = new (ELeave)CMmMarqueeAdapter(); |
|
55 CleanupStack::PushL (self); |
|
56 self->ConstructL (); |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CMmMarqueeAdapter* CMmMarqueeAdapter::NewL () |
|
65 { |
|
66 CMmMarqueeAdapter* self = CMmMarqueeAdapter::NewLC (); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CMmMarqueeAdapter::ConstructL () |
|
76 { |
|
77 iMarqueeEnabled = ETrue; |
|
78 iCurrentMarqueeItemIndex = -1; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CMmMarqueeAdapter::AddMarqueeElementL( |
|
86 const TRect& aRect, |
|
87 const TDesC& aText, |
|
88 TAknLogicalFontId aFont, |
|
89 TRgb aColor, |
|
90 CGraphicsContext::TTextAlign aAlign, |
|
91 TInt aIndex, |
|
92 TInt aBaselineOffset, |
|
93 TInt aCurrentlyDrawnItemIndex |
|
94 ) |
|
95 { |
|
96 if( !iMarqueeEnabled ) |
|
97 { |
|
98 return; |
|
99 } |
|
100 |
|
101 if ( aCurrentlyDrawnItemIndex != iCurrentMarqueeItemIndex ) |
|
102 { |
|
103 StopMarqueeDrawing(); |
|
104 iCurrentMarqueeItemIndex = aCurrentlyDrawnItemIndex; |
|
105 } |
|
106 |
|
107 CMmMarqueeElement* element = NULL; |
|
108 TInt elementIndex(0); |
|
109 for (TInt i = 0; i < iMarqueeElements.Count() ; i++) |
|
110 { |
|
111 if (iMarqueeElements[i]->iSubcellIndex == aIndex) |
|
112 { |
|
113 element = iMarqueeElements[i]; |
|
114 elementIndex = i; |
|
115 break; |
|
116 } |
|
117 } |
|
118 |
|
119 if ( element ) |
|
120 { |
|
121 const TDesC& previousText = *(element->iText); |
|
122 TBool textChanged = previousText.Compare( aText ); |
|
123 |
|
124 if ( textChanged ) |
|
125 { |
|
126 CAknMarqueeControl * control = element->iMarqueeControl; |
|
127 control->Stop(); |
|
128 control->Reset(); |
|
129 iMarqueeElements.Remove(elementIndex ); |
|
130 delete element; |
|
131 } |
|
132 } |
|
133 |
|
134 if( SubcellMarqueeElementExists( aIndex ) ) |
|
135 { |
|
136 return; |
|
137 } |
|
138 |
|
139 CMmMarqueeElement* newElement = |
|
140 CMmMarqueeElement::NewL( aRect, aAlign, aText, aFont, aColor, aIndex, aBaselineOffset ); |
|
141 CleanupStack::PushL( newElement ); |
|
142 newElement->SetupMarqueeControlL( MmMarqueeConstants::KLoops, |
|
143 MmMarqueeConstants::KScrollAmount, MmMarqueeConstants::KScrollDelay); |
|
144 TCallBack callBack(CMmMarqueeAdapter::RedrawEvent, iListbox); |
|
145 if ( newElement->iMarqueeControl ) |
|
146 { |
|
147 newElement->iMarqueeControl->SetRedrawCallBack(callBack); |
|
148 } |
|
149 iMarqueeElements.AppendL( newElement ); |
|
150 CleanupStack::Pop( newElement ); |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CMmMarqueeAdapter::StopMarqueeDrawing(TInt aIndex) |
|
158 { |
|
159 for (TInt elementIndex = iMarqueeElements.Count() - 1; |
|
160 elementIndex >= 0; elementIndex--) |
|
161 { |
|
162 if ((aIndex < 0) || |
|
163 (iMarqueeElements[elementIndex]->iSubcellIndex == aIndex)) |
|
164 { |
|
165 CMmMarqueeElement* element = iMarqueeElements[elementIndex]; |
|
166 CAknMarqueeControl * control = element->iMarqueeControl; |
|
167 control->Stop(); |
|
168 control->Reset(); |
|
169 iMarqueeElements.Remove(elementIndex); |
|
170 delete element; |
|
171 if (iMarqueeElements.Count() == 0 || (aIndex >= 0)) |
|
172 { |
|
173 iCurrentMarqueeItemIndex = -1; |
|
174 break; |
|
175 } |
|
176 } |
|
177 } |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 // ----------------------------------------------------------------------------- |
|
183 // |
|
184 void CMmMarqueeAdapter::EnableMarquee( TBool aEnable ) |
|
185 { |
|
186 iMarqueeEnabled = aEnable; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 // ----------------------------------------------------------------------------- |
|
192 // |
|
193 void CMmMarqueeAdapter::DrawMarqueeL(CWindowGc & aGc ) |
|
194 { |
|
195 if ( iCurrentMarqueeItemIndex != iListbox->View()->CurrentItemIndex() ) |
|
196 { |
|
197 StopMarqueeDrawing(); |
|
198 return; |
|
199 } |
|
200 else if ( iMarqueeEnabled ) |
|
201 { |
|
202 for (TInt i = 0; i < iMarqueeElements.Count() ; i++) |
|
203 { |
|
204 CMmMarqueeElement* element = iMarqueeElements[i]; |
|
205 CAknMarqueeControl* control = element->iMarqueeControl; |
|
206 control->EnableMarquee( ETrue ); |
|
207 |
|
208 // Setup graphical context ( font, colors ) for marquee |
|
209 const CFont* font = AknLayoutUtils::FontFromId( element->iFont ); |
|
210 TInt baseLineOffset = CAknLayoutFont::AsCAknLayoutFontOrNull( font )->TextPaneTopToBaseline(); |
|
211 aGc.UseFont(font); |
|
212 aGc.SetPenColor( element->iColor ); |
|
213 aGc.SetBrushStyle( CGraphicsContext::ENullBrush ); |
|
214 |
|
215 // Let marquee know if it needs to do bidi conversion |
|
216 control->UseLogicalToVisualConversion( ETrue ); |
|
217 |
|
218 TRect subcellRectOnScreen = element->iElementRect; |
|
219 TPoint currentItemPositionOnScreen |
|
220 = iListbox->View()->ItemPos( iListbox->View()->CurrentItemIndex() ); |
|
221 subcellRectOnScreen.Move( currentItemPositionOnScreen.iX , currentItemPositionOnScreen.iY ); |
|
222 if ( control->DrawText(aGc, subcellRectOnScreen, *(element->iText), |
|
223 baseLineOffset, element->iAlign, *font) ) |
|
224 |
|
225 { |
|
226 // All the loops have been executed, the text needs to be truncated. |
|
227 TBuf< MmMarqueeConstants::KClippingBufLength > clipbuf |
|
228 = (element->iText)->Left( MmMarqueeConstants::KTextTrimmingThreshold ); |
|
229 // Get the clipping buffer and draw it |
|
230 TInt maxClipWidth = element->iElementRect.Width(); |
|
231 AknBidiTextUtils::ConvertToVisualAndClipL( clipbuf, *font, |
|
232 element->iElementRect.Width(), maxClipWidth ); |
|
233 aGc.DrawText(clipbuf, subcellRectOnScreen, baseLineOffset , element->iAlign, 0); |
|
234 } |
|
235 // Clean the font cache in graphical context after marquee drawing |
|
236 aGc.DiscardFont(); |
|
237 } |
|
238 } |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TInt CMmMarqueeAdapter::RedrawEvent(TAny* aControl ) |
|
246 { |
|
247 if ( !((CCoeControl*)aControl)->IsVisible() ) |
|
248 { |
|
249 return EFalse; |
|
250 } |
|
251 |
|
252 CMmListBox* listBox = |
|
253 (CMmListBox*)aControl; |
|
254 if (listBox->CurrentItemIndex() >= 0 |
|
255 && listBox->CurrentItemIndex() <= listBox->View()->BottomItemIndex() |
|
256 && listBox->CurrentItemIndex() >= listBox->View()->TopItemIndex() |
|
257 ) |
|
258 { |
|
259 listBox->SetMarqueeDrawing( ETrue ); //redraw the item without using marquee in the last loop |
|
260 listBox->View()->DrawItem( listBox->CurrentItemIndex() ); |
|
261 listBox->SetMarqueeDrawing(EFalse); |
|
262 } |
|
263 |
|
264 return ETrue; |
|
265 } |
|
266 |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void CMmMarqueeAdapter::SetControl( CEikListBox * aControl ) |
|
272 { |
|
273 iListbox = aControl; |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 // ----------------------------------------------------------------------------- |
|
279 // |
|
280 TBool CMmMarqueeAdapter::SubcellMarqueeElementExists( TInt aIndex ) |
|
281 { |
|
282 TBool ret = EFalse; |
|
283 for (TInt i = 0; i < iMarqueeElements.Count() ; i++) |
|
284 { |
|
285 if (iMarqueeElements[i]->iSubcellIndex == aIndex) |
|
286 { |
|
287 ret = ETrue; |
|
288 } |
|
289 } |
|
290 return ret; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CMmMarqueeAdapter::RemoveSubcellMarqueeElement(TInt aSubcellIndex) |
|
298 { |
|
299 for (TInt i = 0; i < iMarqueeElements.Count() ; i++) |
|
300 { |
|
301 if (iMarqueeElements[i]->iSubcellIndex == aSubcellIndex) |
|
302 { |
|
303 iMarqueeElements.Remove(i); |
|
304 break; |
|
305 } |
|
306 } |
|
307 } |
|
308 |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 // ----------------------------------------------------------------------------- |
|
312 // |
|
313 TBool CMmMarqueeAdapter::IsMarqueeEnabled() const |
|
314 { |
|
315 return iMarqueeEnabled; |
|
316 } |
|
317 |
|
318 //class CMmMarqueeElement |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 CMmMarqueeAdapter::CMmMarqueeElement::CMmMarqueeElement ( |
|
325 TRect aElementRect, |
|
326 CGraphicsContext::TTextAlign aAlign, |
|
327 TAknLogicalFontId aFont, |
|
328 TRgb aColor, TInt aIndex, |
|
329 TInt aBaselineOffset ):iElementRect(aElementRect), |
|
330 iAlign(aAlign), |
|
331 iFont(aFont),iColor(aColor), |
|
332 iSubcellIndex(aIndex), |
|
333 iBaselineOffset(aBaselineOffset) |
|
334 { |
|
335 |
|
336 } |
|
337 |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 CMmMarqueeAdapter::CMmMarqueeElement::~CMmMarqueeElement () |
|
344 { |
|
345 delete iMarqueeControl; |
|
346 delete iText; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 CMmMarqueeAdapter::CMmMarqueeElement* CMmMarqueeAdapter::CMmMarqueeElement::NewL ( |
|
354 TRect aElementRect, CGraphicsContext::TTextAlign aAlign, |
|
355 const TDesC& aText, TAknLogicalFontId aFont, TRgb aColor,TInt aIndex, |
|
356 TInt aBaselineOffset ) |
|
357 { |
|
358 CMmMarqueeAdapter::CMmMarqueeElement* self |
|
359 = new (ELeave)CMmMarqueeAdapter::CMmMarqueeElement( aElementRect, aAlign, |
|
360 aFont, aColor, aIndex, aBaselineOffset ); |
|
361 CleanupStack::PushL( self ); |
|
362 self->ConstructL( aText ); |
|
363 CleanupStack::Pop( self ); |
|
364 return self; |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 // ----------------------------------------------------------------------------- |
|
370 // |
|
371 void CMmMarqueeAdapter::CMmMarqueeElement::ConstructL ( const TDesC& aText ) |
|
372 { |
|
373 iText = aText.AllocL(); |
|
374 } |
|
375 |
|
376 // ----------------------------------------------------------------------------- |
|
377 // |
|
378 // ----------------------------------------------------------------------------- |
|
379 // |
|
380 void CMmMarqueeAdapter::CMmMarqueeElement::SetupMarqueeControlL( |
|
381 TInt aLoops, |
|
382 TInt aScrollAmount, |
|
383 TInt aScrollDelay ) |
|
384 { |
|
385 iMarqueeControl = CAknMarqueeControl::NewL( aLoops, aScrollAmount, aScrollDelay ); |
|
386 iMarqueeControl->SetLoops(aLoops); |
|
387 iLoops = aLoops; |
|
388 iScrollAmount = aScrollAmount; |
|
389 iScrollDelay = aScrollDelay; |
|
390 } |
|
391 // End of file |
|
392 |
|
393 |
|
394 |
|
395 |