175 |
182 |
176 // ----------------------------------------------------------------------------- |
183 // ----------------------------------------------------------------------------- |
177 // CXnNewstickerControl::LastIndexWithContent |
184 // CXnNewstickerControl::LastIndexWithContent |
178 // ----------------------------------------------------------------------------- |
185 // ----------------------------------------------------------------------------- |
179 // |
186 // |
180 TInt CXnNewstickerControl::LastIndexWithContent() |
187 TInt CXnNewstickerControl::LastIndexWithContent() const |
181 { |
188 { |
182 for( TInt i(iTitleTexts.Count()-1); i>=0; --i ) |
189 for( TInt i(iTitleTexts.Count()-1); i>=0; --i ) |
183 { |
190 { |
184 if ( iTitleTexts[ i ]->Des().Length() > 0 ) |
191 const TDesC& title( *iTitleTexts[i] ); |
|
192 |
|
193 if( title != KNullDesC() ) |
185 { |
194 { |
186 return i; |
195 return i; |
187 } |
196 } |
188 } |
197 } |
|
198 |
189 return KErrNotFound; |
199 return KErrNotFound; |
190 } |
200 } |
191 |
201 |
192 // ----------------------------------------------------------------------------- |
202 // ----------------------------------------------------------------------------- |
193 // CXnNewstickerControl::ClearTitles |
203 // CXnNewstickerControl::ClearTitles |
194 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
195 // |
205 // |
196 void CXnNewstickerControl::ClearTitles() |
206 void CXnNewstickerControl::ClearTitles() |
197 { |
207 { |
198 iAdapter->Stop(); |
208 iAdapter->Stop(); |
199 iCurrentTitleIndex = -1; |
209 iCurrentTitleIndex = KErrNotFound; |
200 // Don't delete just clear the contents |
210 // Don't delete just clear the contents |
201 for( TInt i=0; i < iTitleTexts.Count(); i++ ) |
211 for( TInt i=0; i < iTitleTexts.Count(); i++ ) |
202 { |
212 { |
203 TRAP_IGNORE( UpdateTitleL( KNullDesC, i ) ); |
213 TRAP_IGNORE( UpdateTitleL( KNullDesC, i ) ); |
204 } |
214 } |
212 { |
222 { |
213 return iTitleTexts.Count(); |
223 return iTitleTexts.Count(); |
214 } |
224 } |
215 |
225 |
216 // ----------------------------------------------------------------------------- |
226 // ----------------------------------------------------------------------------- |
217 // CXnNewstickerControl::SelectTitle |
227 // CXnNewstickerControl::CurrentTitle |
218 // (other items were commented in a header). |
228 // (other items were commented in a header). |
219 // ----------------------------------------------------------------------------- |
229 // ----------------------------------------------------------------------------- |
220 // |
230 // |
221 const TDesC& CXnNewstickerControl::SelectTitle() |
231 const TDesC& CXnNewstickerControl::CurrentTitle() const |
222 { |
232 { |
223 if( IsVisibleTitles() ) |
233 return Title( iCurrentTitleIndex ); |
224 { |
|
225 if( iCurrentTitleIndex < 0 || iCurrentTitleIndex >= iTitleTexts.Count() ) |
|
226 { |
|
227 // Get the last title |
|
228 TInt index = |
|
229 GetNextTitleWithContent( iTitleTexts.Count() - 1, ETrue ); |
|
230 iCurrentTitleIndex = index; |
|
231 } |
|
232 |
|
233 return Title( iCurrentTitleIndex ); |
|
234 } |
|
235 |
|
236 return KNullDesC; |
|
237 } |
234 } |
238 |
235 |
239 // ----------------------------------------------------------------------------- |
236 // ----------------------------------------------------------------------------- |
240 // CXnNewstickerControl::GetNextTitleWithContent |
237 // CXnNewstickerControl::GetNextTitleWithContent |
241 // ----------------------------------------------------------------------------- |
238 // ----------------------------------------------------------------------------- |
242 // |
239 // |
243 TInt CXnNewstickerControl::GetNextTitleWithContent( TInt aStartSearch, |
240 TInt CXnNewstickerControl::GetNextTitleWithContent( TInt aStartSearch, |
244 TBool aBackwards ) const |
241 TBool aBackwards ) const |
245 { |
242 { |
246 TInt dir = 1; |
243 TInt dir = 1; |
247 if( aBackwards ) |
244 if( aBackwards ) |
248 { |
245 { |
249 dir = -1; |
246 dir = -1; |
250 } |
247 } |
251 |
248 |
252 for( TInt i = aStartSearch; i < iTitleTexts.Count() && i >= 0; i += dir ) |
249 for( TInt i = aStartSearch; i < iTitleTexts.Count() && i >= 0; i += dir ) |
253 { |
250 { |
254 if( iTitleTexts[i]->Compare( KNullDesC ) != KErrNone ) |
251 const TDesC& title( *iTitleTexts[i] ); |
|
252 |
|
253 if( title != KNullDesC() ) |
255 { |
254 { |
256 return i; |
255 return i; |
257 } |
256 } |
258 } |
257 } |
259 |
258 |
260 return aStartSearch; |
259 return KErrNotFound; |
261 } |
260 } |
262 |
261 |
263 // ----------------------------------------------------------------------------- |
262 // ----------------------------------------------------------------------------- |
264 // CXnNewstickerControl::SetCurrentTitle |
263 // CXnNewstickerControl::SelectTitle |
265 // ----------------------------------------------------------------------------- |
264 // ----------------------------------------------------------------------------- |
266 // |
265 // |
267 TBool CXnNewstickerControl::SetCurrentTitle( TBool aSetDefault ) |
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 |
268 { |
366 { |
269 TBool ret( EFalse ); |
367 TBool ret( EFalse ); |
270 TInt lastIndex( iTitleTexts.Count() - 1 ); |
368 TInt lastIndex( iTitleTexts.Count() - 1 ); |
271 TInt lastIndexWithContent = LastIndexWithContent(); |
369 TInt lastIndexWithContent = LastIndexWithContent(); |
272 |
370 |
273 if( aSetDefault ) |
371 TPtrC retval( KNullDesC() ); |
274 { |
372 |
275 // set last index as default |
373 if ( lastIndexWithContent == KErrNotFound ) |
276 iCurrentTitleIndex = GetNextTitleWithContent( lastIndex, ETrue ); |
374 { |
277 } |
375 // Loop done |
278 else if( iCurrentTitleIndex >= lastIndex ) |
376 ret = ETrue; |
279 { |
377 } |
280 // if iCurrentTitleIndex is in last position start from beginning |
378 else if ( !iScrollLooping && iCurrentTitleIndex == lastIndexWithContent ) |
281 iCurrentTitleIndex = GetNextTitleWithContent( 0 ); |
379 { |
282 } |
380 // Loop done |
|
381 ret = ETrue; |
|
382 |
|
383 retval.Set( CurrentTitle() ); |
|
384 } |
283 else |
385 else |
284 { |
386 { |
285 if ( iCurrentTitleIndex + 1 > lastIndexWithContent ) |
387 if ( iCurrentTitleIndex + 1 > lastIndexWithContent ) |
286 { |
388 { |
287 // if lastIndexWithContent is creater than next item |
389 // At the end, get first |
288 // it means all next items are empty strings |
390 retval.Set( Title( GetNextTitleWithContent( 0 ) ) ); |
289 iCurrentTitleIndex = lastIndexWithContent; |
|
290 } |
391 } |
291 else |
392 else |
292 { |
393 { |
293 // find next index with content |
394 // find next index with content |
294 iCurrentTitleIndex |
395 retval.Set( Title( GetNextTitleWithContent( iCurrentTitleIndex + 1 ) ) ); |
295 = GetNextTitleWithContent( iCurrentTitleIndex + 1 ); |
396 } |
296 } |
397 } |
297 } |
398 |
298 |
399 aEndOfLoop = ret; |
299 if( iCurrentTitleIndex == lastIndexWithContent || |
400 |
300 lastIndexWithContent == KErrNotFound ) |
401 return retval; |
301 { |
|
302 // loop done stop periodic timer. |
|
303 ret = ETrue; |
|
304 } |
|
305 |
|
306 return ret; |
|
307 } |
402 } |
308 |
403 |
309 // ----------------------------------------------------------------------------- |
404 // ----------------------------------------------------------------------------- |
310 // CXnNewstickerControl::IsVisibleTitles |
405 // CXnNewstickerControl::IsVisibleTitles |
311 // ----------------------------------------------------------------------------- |
406 // ----------------------------------------------------------------------------- |
312 // |
407 // |
313 TBool CXnNewstickerControl::IsVisibleTitles() const |
408 TBool CXnNewstickerControl::IsVisibleTitles() const |
314 { |
409 { |
315 for( TInt i=0; i < iTitleTexts.Count(); i++ ) |
410 for( TInt i = 0; i < iTitleTexts.Count(); i++ ) |
316 { |
411 { |
317 if( iTitleTexts[i]->Compare( KNullDesC ) != KErrNone ) |
412 const TDesC& title( *iTitleTexts[i] ); |
|
413 |
|
414 if( title != KNullDesC() ) |
318 { |
415 { |
319 return ETrue; |
416 return ETrue; |
320 } |
417 } |
321 } |
418 } |
322 |
419 |