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 );
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
// CXnNewstickerControl::CurrentTitleIndex
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
TInt CXnNewstickerControl::CurrentTitleIndex() const
|
|
165 |
{
|
|
166 |
return iCurrentTitleIndex;
|
|
167 |
}
|
|
168 |
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
// CXnNewstickerControl::Title
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
const TDesC& CXnNewstickerControl::Title( TInt aIndex ) const
|
|
174 |
{
|
|
175 |
if( aIndex >= 0 && aIndex < iTitleTexts.Count() )
|
|
176 |
{
|
|
177 |
return *iTitleTexts[ aIndex ];
|
|
178 |
}
|
|
179 |
|
|
180 |
return KNullDesC;
|
|
181 |
}
|
|
182 |
|
|
183 |
// -----------------------------------------------------------------------------
|
|
184 |
// CXnNewstickerControl::LastIndexWithContent
|
|
185 |
// -----------------------------------------------------------------------------
|
|
186 |
//
|
|
187 |
TInt CXnNewstickerControl::LastIndexWithContent() const
|
|
188 |
{
|
|
189 |
for( TInt i(iTitleTexts.Count()-1); i>=0; --i )
|
|
190 |
{
|
|
191 |
const TDesC& title( *iTitleTexts[i] );
|
|
192 |
|
|
193 |
if( title != KNullDesC() )
|
|
194 |
{
|
|
195 |
return i;
|
|
196 |
}
|
|
197 |
}
|
|
198 |
|
|
199 |
return KErrNotFound;
|
|
200 |
}
|
|
201 |
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
// CXnNewstickerControl::ClearTitles
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
void CXnNewstickerControl::ClearTitles()
|
|
207 |
{
|
|
208 |
iAdapter->Stop();
|
|
209 |
iCurrentTitleIndex = KErrNotFound;
|
|
210 |
// Don't delete just clear the contents
|
|
211 |
for( TInt i=0; i < iTitleTexts.Count(); i++ )
|
|
212 |
{
|
|
213 |
TRAP_IGNORE( UpdateTitleL( KNullDesC, i ) );
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
// -----------------------------------------------------------------------------
|
|
218 |
// CXnNewstickerControl::TitleCount
|
|
219 |
// -----------------------------------------------------------------------------
|
|
220 |
//
|
|
221 |
TInt CXnNewstickerControl::TitleCount() const
|
|
222 |
{
|
|
223 |
return iTitleTexts.Count();
|
|
224 |
}
|
|
225 |
|
|
226 |
// -----------------------------------------------------------------------------
|
|
227 |
// CXnNewstickerControl::CurrentTitle
|
|
228 |
// (other items were commented in a header).
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
//
|
|
231 |
const TDesC& CXnNewstickerControl::CurrentTitle() const
|
|
232 |
{
|
|
233 |
return Title( iCurrentTitleIndex );
|
|
234 |
}
|
|
235 |
|
|
236 |
// -----------------------------------------------------------------------------
|
|
237 |
// CXnNewstickerControl::GetNextTitleWithContent
|
|
238 |
// -----------------------------------------------------------------------------
|
|
239 |
//
|
|
240 |
TInt CXnNewstickerControl::GetNextTitleWithContent( TInt aStartSearch,
|
|
241 |
TBool aBackwards ) const
|
|
242 |
{
|
|
243 |
TInt dir = 1;
|
|
244 |
if( aBackwards )
|
|
245 |
{
|
|
246 |
dir = -1;
|
|
247 |
}
|
|
248 |
|
|
249 |
for( TInt i = aStartSearch; i < iTitleTexts.Count() && i >= 0; i += dir )
|
|
250 |
{
|
|
251 |
const TDesC& title( *iTitleTexts[i] );
|
|
252 |
|
|
253 |
if( title != KNullDesC() )
|
|
254 |
{
|
|
255 |
return i;
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
return KErrNotFound;
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// CXnNewstickerControl::SelectTitle
|
|
264 |
// -----------------------------------------------------------------------------
|
|
265 |
//
|
|
266 |
TInt CXnNewstickerControl::SelectTitle()
|
|
267 |
{
|
|
268 |
TInt index( GetNextTitleWithContent( 0 ) );
|
|
269 |
|
|
270 |
TInt currentIndex( iCurrentTitleIndex );
|
|
271 |
|
|
272 |
iCurrentTitleIndex = index;
|
|
273 |
|
|
274 |
if ( currentIndex != iCurrentTitleIndex )
|
|
275 |
{
|
|
276 |
if ( currentIndex != KErrNotFound )
|
|
277 |
{
|
|
278 |
iAdapter->ReportNewstickerEvent(
|
|
279 |
XnPropertyNames::action::trigger::name::KTitleScrolled,
|
|
280 |
currentIndex );
|
|
281 |
}
|
|
282 |
|
|
283 |
if ( iCurrentTitleIndex != KErrNotFound )
|
|
284 |
{
|
|
285 |
iAdapter->ReportNewstickerEvent(
|
|
286 |
XnPropertyNames::action::trigger::name::KTitleToScroll,
|
|
287 |
iCurrentTitleIndex );
|
|
288 |
}
|
|
289 |
}
|
|
290 |
|
|
291 |
return iCurrentTitleIndex;
|
|
292 |
}
|
|
293 |
|
|
294 |
// -----------------------------------------------------------------------------
|
|
295 |
// CXnNewstickerControl::SelectNextTitle
|
|
296 |
// -----------------------------------------------------------------------------
|
|
297 |
//
|
|
298 |
TBool CXnNewstickerControl::SelectNextTitle()
|
|
299 |
{
|
|
300 |
TBool ret( EFalse );
|
|
301 |
TInt lastIndex( iTitleTexts.Count() - 1 );
|
|
302 |
TInt lastIndexWithContent( LastIndexWithContent() );
|
|
303 |
|
|
304 |
TInt currentIndex( iCurrentTitleIndex );
|
|
305 |
|
|
306 |
if ( lastIndexWithContent == KErrNotFound )
|
|
307 |
{
|
|
308 |
// Loop done
|
|
309 |
ret = ETrue;
|
|
310 |
}
|
|
311 |
else if ( !iScrollLooping && iCurrentTitleIndex == lastIndexWithContent )
|
|
312 |
{
|
|
313 |
// Loop done
|
|
314 |
ret = ETrue;
|
|
315 |
}
|
|
316 |
else
|
|
317 |
{
|
|
318 |
if ( iCurrentTitleIndex + 1 > lastIndexWithContent )
|
|
319 |
{
|
|
320 |
// At the end, get first
|
|
321 |
iCurrentTitleIndex =
|
|
322 |
GetNextTitleWithContent( 0 );
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
// find next index with content
|
|
327 |
iCurrentTitleIndex =
|
|
328 |
GetNextTitleWithContent( iCurrentTitleIndex + 1 );
|
|
329 |
}
|
|
330 |
}
|
|
331 |
|
|
332 |
if ( ret )
|
|
333 |
{
|
|
334 |
if ( iCurrentTitleIndex != KErrNotFound )
|
|
335 |
{
|
|
336 |
iAdapter->ReportNewstickerEvent(
|
|
337 |
XnPropertyNames::action::trigger::name::KTitleScrolled,
|
|
338 |
iCurrentTitleIndex );
|
|
339 |
}
|
|
340 |
}
|
|
341 |
else
|
|
342 |
{
|
|
343 |
if ( currentIndex != iCurrentTitleIndex && currentIndex != KErrNotFound )
|
|
344 |
{
|
|
345 |
iAdapter->ReportNewstickerEvent(
|
|
346 |
XnPropertyNames::action::trigger::name::KTitleScrolled,
|
|
347 |
currentIndex );
|
|
348 |
}
|
|
349 |
|
|
350 |
if ( currentIndex != iCurrentTitleIndex && iCurrentTitleIndex != KErrNotFound )
|
|
351 |
{
|
|
352 |
iAdapter->ReportNewstickerEvent(
|
|
353 |
XnPropertyNames::action::trigger::name::KTitleToScroll,
|
|
354 |
iCurrentTitleIndex );
|
|
355 |
}
|
|
356 |
}
|
|
357 |
|
|
358 |
return ret;
|
|
359 |
}
|
|
360 |
|
|
361 |
// -----------------------------------------------------------------------------
|
|
362 |
// CXnNewstickerControl::PeekNextTitle
|
|
363 |
// -----------------------------------------------------------------------------
|
|
364 |
//
|
|
365 |
TPtrC CXnNewstickerControl::PeekNextTitle( TBool& aEndOfLoop ) const
|
|
366 |
{
|
|
367 |
TBool ret( EFalse );
|
|
368 |
TInt lastIndex( iTitleTexts.Count() - 1 );
|
|
369 |
TInt lastIndexWithContent = LastIndexWithContent();
|
|
370 |
|
|
371 |
TPtrC retval( KNullDesC() );
|
|
372 |
|
|
373 |
if ( lastIndexWithContent == KErrNotFound )
|
|
374 |
{
|
|
375 |
// Loop done
|
|
376 |
ret = ETrue;
|
|
377 |
}
|
|
378 |
else if ( !iScrollLooping && iCurrentTitleIndex == lastIndexWithContent )
|
|
379 |
{
|
|
380 |
// Loop done
|
|
381 |
ret = ETrue;
|
|
382 |
|
|
383 |
retval.Set( CurrentTitle() );
|
|
384 |
}
|
|
385 |
else
|
|
386 |
{
|
|
387 |
if ( iCurrentTitleIndex + 1 > lastIndexWithContent )
|
|
388 |
{
|
|
389 |
// At the end, get first
|
|
390 |
retval.Set( Title( GetNextTitleWithContent( 0 ) ) );
|
|
391 |
}
|
|
392 |
else
|
|
393 |
{
|
|
394 |
// find next index with content
|
|
395 |
retval.Set( Title( GetNextTitleWithContent( iCurrentTitleIndex + 1 ) ) );
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
aEndOfLoop = ret;
|
|
400 |
|
|
401 |
return retval;
|
|
402 |
}
|
|
403 |
|
|
404 |
// -----------------------------------------------------------------------------
|
|
405 |
// CXnNewstickerControl::IsVisibleTitles
|
|
406 |
// -----------------------------------------------------------------------------
|
|
407 |
//
|
|
408 |
TBool CXnNewstickerControl::IsVisibleTitles() const
|
|
409 |
{
|
|
410 |
for( TInt i = 0; i < iTitleTexts.Count(); i++ )
|
|
411 |
{
|
|
412 |
const TDesC& title( *iTitleTexts[i] );
|
|
413 |
|
|
414 |
if( title != KNullDesC() )
|
|
415 |
{
|
|
416 |
return ETrue;
|
|
417 |
}
|
|
418 |
}
|
|
419 |
|
|
420 |
return EFalse;
|
|
421 |
}
|
|
422 |
|
|
423 |
|
|
424 |
// End of File
|