author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:58:58 +0300 | |
branch | RCL_3 |
changeset 88 | 3321d3e205b6 |
parent 83 | 5456b4e8b3a8 |
child 102 | ba63c83f4716 |
permissions | -rw-r--r-- |
83 | 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 |
// INCLUDE FILES |
|
20 |
#include "xnnewstickercontrol.h" |
|
21 |
#include "xnnewstickeradapter.h" |
|
22 |
#include "xnproperty.h" |
|
23 |
||
24 |
// CONSTANTS |
|
25 |
||
26 |
// ============================ MEMBER FUNCTIONS =============================== |
|
27 |
||
28 |
// ----------------------------------------------------------------------------- |
|
29 |
// CXnNewstickerControl::CXnNewstickerControl |
|
30 |
// C++ default constructor can NOT contain any code, that |
|
31 |
// might leave. |
|
32 |
// ----------------------------------------------------------------------------- |
|
33 |
// |
|
34 |
CXnNewstickerControl::CXnNewstickerControl( CXnNewstickerAdapter* aAdapter ) : |
|
35 |
iCurrentTitleIndex( KErrNotFound ), |
|
36 |
iAdapter( aAdapter ), |
|
37 |
iScrollLooping( ETrue ) |
|
38 |
{ |
|
39 |
} |
|
40 |
||
41 |
// ----------------------------------------------------------------------------- |
|
42 |
// CXnNewstickerControl::ConstructL |
|
43 |
// Symbian 2nd phase constructor can leave. |
|
44 |
// ----------------------------------------------------------------------------- |
|
45 |
// |
|
46 |
void CXnNewstickerControl::ConstructL() |
|
47 |
{ |
|
48 |
||
49 |
} |
|
50 |
||
51 |
// ----------------------------------------------------------------------------- |
|
52 |
// CXnNewstickerControl::NewL |
|
53 |
// Two-phased constructor. |
|
54 |
// ----------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
CXnNewstickerControl* CXnNewstickerControl::NewL( CXnNewstickerAdapter* aAdapter ) |
|
57 |
{ |
|
58 |
CXnNewstickerControl* self = new(ELeave)CXnNewstickerControl( aAdapter ); |
|
59 |
CleanupStack::PushL( self ); |
|
60 |
self->ConstructL(); |
|
61 |
CleanupStack::Pop(); // self |
|
62 |
return self; |
|
63 |
} |
|
64 |
||
65 |
// ----------------------------------------------------------------------------- |
|
66 |
// CXnNewstickerControl::~CXnNewstickerControl() |
|
67 |
// Destructor. |
|
68 |
// ----------------------------------------------------------------------------- |
|
69 |
// |
|
70 |
CXnNewstickerControl::~CXnNewstickerControl() |
|
71 |
{ |
|
72 |
iTitleTexts.ResetAndDestroy(); |
|
73 |
} |
|
74 |
||
75 |
// ----------------------------------------------------------------------------- |
|
76 |
// CXnNewstickerControl::SetScrollLooping() |
|
77 |
// |
|
78 |
// ----------------------------------------------------------------------------- |
|
79 |
// |
|
80 |
void CXnNewstickerControl::SetScrollLooping( TBool aLooping ) |
|
81 |
{ |
|
82 |
iScrollLooping = aLooping; |
|
83 |
} |
|
84 |
||
85 |
// ----------------------------------------------------------------------------- |
|
86 |
// CXnNewstickerControl::AppendTitleL |
|
87 |
// (other items were commented in a header). |
|
88 |
// ----------------------------------------------------------------------------- |
|
89 |
// |
|
90 |
void CXnNewstickerControl::AppendTitleL( const TDesC& aTitle ) |
|
91 |
{ |
|
92 |
HBufC* title = aTitle.AllocLC(); |
|
93 |
iTitleTexts.AppendL( title ); |
|
94 |
CleanupStack::Pop( title ); |
|
95 |
} |
|
96 |
||
97 |
// ----------------------------------------------------------------------------- |
|
98 |
// CXnNewstickerControl::InsertTitleL |
|
99 |
// ----------------------------------------------------------------------------- |
|
100 |
// |
|
101 |
void CXnNewstickerControl::InsertTitleL( const TDesC& aTitle, TInt aIndex ) |
|
102 |
{ |
|
103 |
if( aIndex >= 0 && aIndex < iTitleTexts.Count() ) |
|
104 |
{ |
|
105 |
HBufC* title = aTitle.AllocLC(); |
|
106 |
iTitleTexts.InsertL( title, aIndex ); |
|
107 |
CleanupStack::Pop( title ); |
|
108 |
} |
|
109 |
else |
|
110 |
{ |
|
111 |
AppendTitleL( aTitle ); |
|
112 |
} |
|
113 |
} |
|
114 |
||
115 |
// ----------------------------------------------------------------------------- |
|
116 |
// CXnNewstickerControl::UpdateTitleL |
|
117 |
// ----------------------------------------------------------------------------- |
|
118 |
// |
|
119 |
void CXnNewstickerControl::UpdateTitleL( const TDesC& aTitle, TInt aIndex ) |
|
120 |
{ |
|
121 |
if( aIndex >= 0 && aIndex < iTitleTexts.Count() ) |
|
122 |
{ |
|
123 |
HBufC* oldTitle = iTitleTexts[ aIndex ]; |
|
124 |
iTitleTexts.Remove( aIndex ); |
|
125 |
||
126 |
delete oldTitle; |
|
127 |
oldTitle = NULL; |
|
128 |
||
129 |
HBufC* title = aTitle.AllocLC(); |
|
130 |
iTitleTexts.InsertL( title, aIndex ); |
|
131 |
CleanupStack::Pop( title ); |
|
132 |
} |
|
133 |
else |
|
134 |
{ |
|
135 |
AppendTitleL( aTitle ); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
// ----------------------------------------------------------------------------- |
|
140 |
// CXnNewstickerControl::DeleteTitle |
|
141 |
// ----------------------------------------------------------------------------- |
|
142 |
// |
|
143 |
void CXnNewstickerControl::DeleteTitleL( TInt aIndex ) |
|
144 |
{ |
|
145 |
TInt count = iTitleTexts.Count(); |
|
146 |
||
147 |
if( aIndex >= 0 && aIndex < count ) |
|
148 |
{ |
|
149 |
// If the last item will be deleted |
|
150 |
if(count == 1) |
|
151 |
{ |
|
152 |
iAdapter->Stop(); |
|
153 |
iCurrentTitleIndex = KErrNotFound; |
|
154 |
} |
|
155 |
||
156 |
UpdateTitleL( KNullDesC, aIndex ); |
|
88
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
83
diff
changeset
|
157 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
83
diff
changeset
|
158 |
if( aIndex == iCurrentTitleIndex ) |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
83
diff
changeset
|
159 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
83
diff
changeset
|
160 |
iCurrentTitleIndex = GetNextTitleWithContent( aIndex ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
83
diff
changeset
|
161 |
} |
83 | 162 |
} |
163 |
} |
|
164 |
||
165 |
// ----------------------------------------------------------------------------- |
|
166 |
// CXnNewstickerControl::CurrentTitleIndex |
|
167 |
// ----------------------------------------------------------------------------- |
|
168 |
// |
|
169 |
TInt CXnNewstickerControl::CurrentTitleIndex() const |
|
170 |
{ |
|
171 |
return iCurrentTitleIndex; |
|
172 |
} |
|
173 |
||
174 |
// ----------------------------------------------------------------------------- |
|
175 |
// CXnNewstickerControl::Title |
|
176 |
// ----------------------------------------------------------------------------- |
|
177 |
// |
|
178 |
const TDesC& CXnNewstickerControl::Title( TInt aIndex ) const |
|
179 |
{ |
|
180 |
if( aIndex >= 0 && aIndex < iTitleTexts.Count() ) |
|
181 |
{ |
|
182 |
return *iTitleTexts[ aIndex ]; |
|
183 |
} |
|
184 |
||
185 |
return KNullDesC; |
|
186 |
} |
|
187 |
||
188 |
// ----------------------------------------------------------------------------- |
|
189 |
// CXnNewstickerControl::LastIndexWithContent |
|
190 |
// ----------------------------------------------------------------------------- |
|
191 |
// |
|
192 |
TInt CXnNewstickerControl::LastIndexWithContent() const |
|
193 |
{ |
|
194 |
for( TInt i(iTitleTexts.Count()-1); i>=0; --i ) |
|
195 |
{ |
|
196 |
const TDesC& title( *iTitleTexts[i] ); |
|
197 |
||
198 |
if( title != KNullDesC() ) |
|
199 |
{ |
|
200 |
return i; |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
return KErrNotFound; |
|
205 |
} |
|
206 |
||
207 |
// ----------------------------------------------------------------------------- |
|
208 |
// CXnNewstickerControl::ClearTitles |
|
209 |
// ----------------------------------------------------------------------------- |
|
210 |
// |
|
211 |
void CXnNewstickerControl::ClearTitles() |
|
212 |
{ |
|
213 |
iAdapter->Stop(); |
|
214 |
iCurrentTitleIndex = KErrNotFound; |
|
215 |
// Don't delete just clear the contents |
|
216 |
for( TInt i=0; i < iTitleTexts.Count(); i++ ) |
|
217 |
{ |
|
218 |
TRAP_IGNORE( UpdateTitleL( KNullDesC, i ) ); |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
// ----------------------------------------------------------------------------- |
|
223 |
// CXnNewstickerControl::TitleCount |
|
224 |
// ----------------------------------------------------------------------------- |
|
225 |
// |
|
226 |
TInt CXnNewstickerControl::TitleCount() const |
|
227 |
{ |
|
228 |
return iTitleTexts.Count(); |
|
229 |
} |
|
230 |
||
231 |
// ----------------------------------------------------------------------------- |
|
232 |
// CXnNewstickerControl::CurrentTitle |
|
233 |
// (other items were commented in a header). |
|
234 |
// ----------------------------------------------------------------------------- |
|
235 |
// |
|
236 |
const TDesC& CXnNewstickerControl::CurrentTitle() const |
|
237 |
{ |
|
238 |
return Title( iCurrentTitleIndex ); |
|
239 |
} |
|
240 |
||
241 |
// ----------------------------------------------------------------------------- |
|
242 |
// CXnNewstickerControl::GetNextTitleWithContent |
|
243 |
// ----------------------------------------------------------------------------- |
|
244 |
// |
|
245 |
TInt CXnNewstickerControl::GetNextTitleWithContent( TInt aStartSearch, |
|
246 |
TBool aBackwards ) const |
|
247 |
{ |
|
248 |
TInt dir = 1; |
|
249 |
if( aBackwards ) |
|
250 |
{ |
|
251 |
dir = -1; |
|
252 |
} |
|
253 |
||
254 |
for( TInt i = aStartSearch; i < iTitleTexts.Count() && i >= 0; i += dir ) |
|
255 |
{ |
|
256 |
const TDesC& title( *iTitleTexts[i] ); |
|
257 |
||
258 |
if( title != KNullDesC() ) |
|
259 |
{ |
|
260 |
return i; |
|
261 |
} |
|
262 |
} |
|
263 |
||
264 |
return KErrNotFound; |
|
265 |
} |
|
266 |
||
267 |
// ----------------------------------------------------------------------------- |
|
268 |
// CXnNewstickerControl::SelectTitle |
|
269 |
// ----------------------------------------------------------------------------- |
|
270 |
// |
|
271 |
TInt CXnNewstickerControl::SelectTitle() |
|
272 |
{ |
|
273 |
TInt index( GetNextTitleWithContent( 0 ) ); |
|
274 |
||
275 |
TInt currentIndex( iCurrentTitleIndex ); |
|
276 |
||
277 |
iCurrentTitleIndex = index; |
|
278 |
||
279 |
if ( currentIndex != iCurrentTitleIndex ) |
|
280 |
{ |
|
281 |
if ( currentIndex != KErrNotFound ) |
|
282 |
{ |
|
283 |
iAdapter->ReportNewstickerEvent( |
|
284 |
XnPropertyNames::action::trigger::name::KTitleScrolled, |
|
285 |
currentIndex ); |
|
286 |
} |
|
287 |
||
288 |
if ( iCurrentTitleIndex != KErrNotFound ) |
|
289 |
{ |
|
290 |
iAdapter->ReportNewstickerEvent( |
|
291 |
XnPropertyNames::action::trigger::name::KTitleToScroll, |
|
292 |
iCurrentTitleIndex ); |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
return iCurrentTitleIndex; |
|
297 |
} |
|
298 |
||
299 |
// ----------------------------------------------------------------------------- |
|
300 |
// CXnNewstickerControl::SelectNextTitle |
|
301 |
// ----------------------------------------------------------------------------- |
|
302 |
// |
|
303 |
TBool CXnNewstickerControl::SelectNextTitle() |
|
304 |
{ |
|
305 |
TBool ret( EFalse ); |
|
306 |
TInt lastIndex( iTitleTexts.Count() - 1 ); |
|
307 |
TInt lastIndexWithContent( LastIndexWithContent() ); |
|
308 |
||
309 |
TInt currentIndex( iCurrentTitleIndex ); |
|
310 |
||
311 |
if ( lastIndexWithContent == KErrNotFound ) |
|
312 |
{ |
|
313 |
// Loop done |
|
314 |
ret = ETrue; |
|
315 |
} |
|
316 |
else if ( !iScrollLooping && iCurrentTitleIndex == lastIndexWithContent ) |
|
317 |
{ |
|
318 |
// Loop done |
|
319 |
ret = ETrue; |
|
320 |
} |
|
321 |
else |
|
322 |
{ |
|
323 |
if ( iCurrentTitleIndex + 1 > lastIndexWithContent ) |
|
324 |
{ |
|
325 |
// At the end, get first |
|
326 |
iCurrentTitleIndex = |
|
327 |
GetNextTitleWithContent( 0 ); |
|
328 |
} |
|
329 |
else |
|
330 |
{ |
|
331 |
// find next index with content |
|
332 |
iCurrentTitleIndex = |
|
333 |
GetNextTitleWithContent( iCurrentTitleIndex + 1 ); |
|
334 |
} |
|
335 |
} |
|
336 |
||
337 |
if ( ret ) |
|
338 |
{ |
|
339 |
if ( iCurrentTitleIndex != KErrNotFound ) |
|
340 |
{ |
|
341 |
iAdapter->ReportNewstickerEvent( |
|
342 |
XnPropertyNames::action::trigger::name::KTitleScrolled, |
|
343 |
iCurrentTitleIndex ); |
|
344 |
} |
|
345 |
} |
|
346 |
else |
|
347 |
{ |
|
348 |
if ( currentIndex != iCurrentTitleIndex && currentIndex != KErrNotFound ) |
|
349 |
{ |
|
350 |
iAdapter->ReportNewstickerEvent( |
|
351 |
XnPropertyNames::action::trigger::name::KTitleScrolled, |
|
352 |
currentIndex ); |
|
353 |
} |
|
354 |
||
355 |
if ( currentIndex != iCurrentTitleIndex && iCurrentTitleIndex != KErrNotFound ) |
|
356 |
{ |
|
357 |
iAdapter->ReportNewstickerEvent( |
|
358 |
XnPropertyNames::action::trigger::name::KTitleToScroll, |
|
359 |
iCurrentTitleIndex ); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
return ret; |
|
364 |
} |
|
365 |
||
366 |
// ----------------------------------------------------------------------------- |
|
367 |
// CXnNewstickerControl::PeekNextTitle |
|
368 |
// ----------------------------------------------------------------------------- |
|
369 |
// |
|
370 |
TPtrC CXnNewstickerControl::PeekNextTitle( TBool& aEndOfLoop ) const |
|
371 |
{ |
|
372 |
TBool ret( EFalse ); |
|
373 |
TInt lastIndex( iTitleTexts.Count() - 1 ); |
|
374 |
TInt lastIndexWithContent = LastIndexWithContent(); |
|
375 |
||
376 |
TPtrC retval( KNullDesC() ); |
|
377 |
||
378 |
if ( lastIndexWithContent == KErrNotFound ) |
|
379 |
{ |
|
380 |
// Loop done |
|
381 |
ret = ETrue; |
|
382 |
} |
|
383 |
else if ( !iScrollLooping && iCurrentTitleIndex == lastIndexWithContent ) |
|
384 |
{ |
|
385 |
// Loop done |
|
386 |
ret = ETrue; |
|
387 |
||
388 |
retval.Set( CurrentTitle() ); |
|
389 |
} |
|
390 |
else |
|
391 |
{ |
|
392 |
if ( iCurrentTitleIndex + 1 > lastIndexWithContent ) |
|
393 |
{ |
|
394 |
// At the end, get first |
|
395 |
retval.Set( Title( GetNextTitleWithContent( 0 ) ) ); |
|
396 |
} |
|
397 |
else |
|
398 |
{ |
|
399 |
// find next index with content |
|
400 |
retval.Set( Title( GetNextTitleWithContent( iCurrentTitleIndex + 1 ) ) ); |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
aEndOfLoop = ret; |
|
405 |
||
406 |
return retval; |
|
407 |
} |
|
408 |
||
409 |
// ----------------------------------------------------------------------------- |
|
410 |
// CXnNewstickerControl::IsVisibleTitles |
|
411 |
// ----------------------------------------------------------------------------- |
|
412 |
// |
|
413 |
TBool CXnNewstickerControl::IsVisibleTitles() const |
|
414 |
{ |
|
415 |
for( TInt i = 0; i < iTitleTexts.Count(); i++ ) |
|
416 |
{ |
|
417 |
const TDesC& title( *iTitleTexts[i] ); |
|
418 |
||
419 |
if( title != KNullDesC() ) |
|
420 |
{ |
|
421 |
return ETrue; |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
return EFalse; |
|
426 |
} |
|
427 |
||
428 |
||
429 |
// End of File |