idlehomescreen/xmluirendering/renderingplugins/xnnewstickerfactory/src/xnnewstickeradapter.cpp
branchRCL_3
changeset 26 1b758917cafc
parent 23 7be2816dbabd
equal deleted inserted replaced
25:137ebc85284b 26:1b758917cafc
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Implementation for wrapper for a label
    14 * Description:  Marquee control
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <utf.h>
    19 #include <utf.h>
    35 
    35 
    36 #include "xnnewstickeradapter.h"
    36 #include "xnnewstickeradapter.h"
    37 #include "xnnewstickercontrol.h"
    37 #include "xnnewstickercontrol.h"
    38 #include "xncomponentnodeimpl.h"
    38 #include "xncomponentnodeimpl.h"
    39 
    39 
    40 
    40 // Constants
    41 const TInt KThousandCoef = 1000;
    41 const TInt KThousandCoef = 1000;
    42 const TInt KByteLength = 8;
    42 const TInt KByteLength = 8;
       
    43 const TInt KXnNewstickerDelay = 1000000;   // start scrolling after a delay of 1 second
       
    44 const TInt KXnNewstickerInterval = 100000; // scroll 10 times in a second
       
    45 const TInt KXnNewstickerScrollAmount = 6;  // scroll 6 pixels at time
    43 
    46 
    44 
    47 
    45 // ============================= LOCAL FUNCTIONS ===============================
    48 // ============================= LOCAL FUNCTIONS ===============================
    46 
    49 
    47 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    77 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    78 //
    81 //
    79 void CXnNewstickerAdapter::SetNewstickerPropertiesL()
    82 void CXnNewstickerAdapter::SetNewstickerPropertiesL()
    80     {
    83     {
    81     // scroll amount 
    84     // scroll amount 
    82     TInt scrollamount = GetIntPropertyL( iNode, 
    85     TInt scrollamount( GetIntPropertyL( iNode, 
    83         XnPropertyNames::newsticker::KXnScrollAmount );   // px
    86         XnPropertyNames::newsticker::KXnScrollAmount ) );   // px
    84     
    87     
    85     if( KErrNotFound == scrollamount )
    88     if ( scrollamount == KErrNotFound )
    86         {
    89         {
    87         scrollamount = KXnNewstickerScrollAmount;
    90         scrollamount = KXnNewstickerScrollAmount;
    88         }
    91         }
    89 
    92 
    90     CXnProperty* prop( iNode.GetPropertyL(
    93     CXnProperty* prop( iNode.GetPropertyL(
    91             XnPropertyNames::newsticker::KScrollBehaviour ) );
    94         XnPropertyNames::newsticker::KScrollBehaviour ) );
    92     
    95     
    93     if( prop )
    96     // Default
    94         {
    97     iScrollBehaviour = EScroll;
    95         if ( prop->StringValue() == 
    98     
    96                 XnPropertyNames::newsticker::scroll_behaviour::KAlternate )
    99     if ( prop )
       
   100         {
       
   101         const TDesC8& value( prop->StringValue() );
       
   102         
       
   103         if ( value == XnPropertyNames::newsticker::scroll_behaviour::KAlternate )                 
    97             {
   104             {
    98             scrollamount = 0;
   105             scrollamount = 0;
    99             iScrollBehaviour = EAlternate;
   106             iScrollBehaviour = EAlternate;
   100             }
   107             }
   101         else if ( prop->StringValue() == 
   108         else if ( value == XnPropertyNames::newsticker::scroll_behaviour::KScrollAlternate )                 
   102                 XnPropertyNames::newsticker::scroll_behaviour::KScrollAlternate )
       
   103             {
   109             {
   104             iScrollBehaviour = EScrollAlternate;
   110             iScrollBehaviour = EScrollAlternate;
   105             }
   111             }
   106         else
   112         }
   107             {
   113     
   108             iScrollBehaviour = EScroll;
       
   109             }
       
   110         }
       
   111     else
       
   112         {
       
   113         iScrollBehaviour = EScroll;
       
   114         }        
       
   115         
       
   116     iMarqueeControl->SetSpeedInPixels( scrollamount );
   114     iMarqueeControl->SetSpeedInPixels( scrollamount );
   117     
   115     
   118     if( iScrollBehaviour == EScroll )
   116     if ( iScrollBehaviour == EScroll || iScrollBehaviour == EScrollAlternate )
   119         {                    
   117         {                    
   120         // scroll delay
   118         // scroll delay, i.e. fps
   121         TInt scrolldelay = GetIntPropertyL( iNode, 
   119         TInt scrolldelay( GetIntPropertyL( iNode, 
   122             XnPropertyNames::newsticker::KXnScrollDelay );  // ms
   120             XnPropertyNames::newsticker::KXnScrollDelay ) );  // ms
   123         
   121         
   124         if( KErrNotFound == scrolldelay )
   122         if ( scrolldelay == KErrNotFound )
   125             {
   123             {
   126             scrolldelay = KXnNewstickerInterval;
   124             scrolldelay = KXnNewstickerInterval;
   127             }
   125             }
   128         else 
   126         else 
   129             {
   127             {
   130             scrolldelay *= KThousandCoef;    // change to microseconds
   128             // change to seconds
   131             }
   129             scrolldelay *= KThousandCoef;
   132         
   130             }
   133         iMarqueeControl->SetInterval( scrolldelay ); 
   131         
   134         iAlternateInterval = scrolldelay;
   132         iMarqueeControl->SetInterval( scrolldelay );         
   135             
   133                                     
   136         // start delay
   134         // start delay
   137         TInt startdelay = GetIntPropertyL( iNode, 
   135         TInt startdelay( GetIntPropertyL( iNode, 
   138             XnPropertyNames::newsticker::KXnStartDelay ); // ms
   136             XnPropertyNames::newsticker::KXnStartDelay ) ); // ms
   139         
   137         
   140         if( KErrNotFound == startdelay )
   138         if ( startdelay == KErrNotFound )
   141             {
   139             {
   142             startdelay = KXnNewstickerDelay;
   140             startdelay = KXnNewstickerDelay;
   143             }
   141             }
   144         else 
   142         else 
   145             {
   143             {
   146             startdelay *= KThousandCoef;    // change to microseconds
   144             // change to seconds
       
   145             startdelay *= KThousandCoef;
   147             }
   146             }
   148         
   147         
   149         iMarqueeControl->SetDelay( startdelay );
   148         iMarqueeControl->SetDelay( startdelay );
   150         iAlternateDelay = startdelay;
   149         iAlternateDelay = startdelay;
   151         }
   150         
   152     else if( iScrollBehaviour == EScrollAlternate )
   151         if ( iScrollBehaviour == EScrollAlternate )
   153 		{
   152             {
   154         // scroll delay
   153             TInt alternateTime( GetIntPropertyL( iNode,  
   155         TInt scrolldelay = GetIntPropertyL( iNode, 
   154                 XnPropertyNames::newsticker::KDisplayTime ) );
   156             XnPropertyNames::newsticker::KXnScrollDelay );  // ms
   155             
   157         
   156             if( alternateTime == KErrNotFound )
   158         if( KErrNotFound == scrolldelay )
   157                 {
   159             {
   158                 alternateTime = KXnNewstickerDelay;            
   160             scrolldelay = KXnNewstickerInterval;
   159                 }
   161             }
   160             else
   162         else 
   161                 {
   163             {
   162                 // change to seconds
   164             scrolldelay *= KThousandCoef;    // change to microseconds
   163                 alternateTime *= KThousandCoef; 
   165             }
   164                 }
   166         
   165                     
   167         iMarqueeControl->SetInterval( scrolldelay );
   166             iAlternateDelay = alternateTime;            
   168         iAlternateInterval = scrolldelay;
   167             }                    
   169 
   168         }                
   170         TInt alternateTime( GetIntPropertyL( iNode, XnPropertyNames::newsticker::KDisplayTime ) );
       
   171         
       
   172         if( alternateTime == KErrNotFound )
       
   173             {
       
   174             alternateTime = 0;
       
   175             }
       
   176 
       
   177         alternateTime *= KThousandCoef; // change to ms                        
       
   178 
       
   179         iAlternateInterval = alternateTime;
       
   180 
       
   181         // start delay
       
   182         TInt startdelay = GetIntPropertyL( iNode, 
       
   183             XnPropertyNames::newsticker::KXnStartDelay ); // ms
       
   184         
       
   185         if( KErrNotFound == startdelay )
       
   186             {
       
   187             startdelay = 0;
       
   188             }
       
   189         else 
       
   190             {
       
   191             startdelay *= KThousandCoef;    // change to microseconds
       
   192             }
       
   193         
       
   194         iMarqueeControl->SetDelay( startdelay );
       
   195         iAlternateDelay = startdelay;
       
   196         }
       
   197     else // TScrollBehaviour::EAlternate
   169     else // TScrollBehaviour::EAlternate
   198         {
   170         {
   199         TInt alternateTime( GetIntPropertyL( iNode, XnPropertyNames::newsticker::KDisplayTime ) );
   171         TInt alternateTime( GetIntPropertyL( 
   200         
   172             iNode, XnPropertyNames::newsticker::KDisplayTime ) );
   201         if( alternateTime == KErrNotFound )
   173         
   202             {
   174         if ( alternateTime == KErrNotFound )
   203             alternateTime = 0;
   175             {
   204             }
   176             alternateTime = KXnNewstickerDelay;
   205 
   177             }
   206         alternateTime *= KThousandCoef; // change to ms                        
   178         else
       
   179             {
       
   180             // change to seconds    
       
   181             alternateTime *= KThousandCoef; 
       
   182             }
   207 
   183 
   208         iMarqueeControl->SetDelay( 0 );
   184         iMarqueeControl->SetDelay( 0 );
   209         iMarqueeControl->SetInterval( alternateTime );
   185         iMarqueeControl->SetInterval( 0 );
   210         
   186         
   211         iAlternateDelay = 0;
   187         iAlternateDelay = alternateTime;        
   212         iAlternateInterval = alternateTime;
       
   213         }        
   188         }        
   214     
   189     
   215     // _s60-scroll-loop property. True by default.
   190     // _s60-scroll-loop property. True by default.
   216     CXnProperty* loopProp( iNode.GetPropertyL(
   191     CXnProperty* loopProp( iNode.GetPropertyL(
   217             XnPropertyNames::newsticker::KScrollLoop ) );
   192         XnPropertyNames::newsticker::KScrollLoop ) );
   218     
   193     
   219     if( loopProp && loopProp->StringValue() == XnPropertyNames::KFalse )
   194     TBool looping( ETrue );
   220         {
   195     
   221         iScrollLooping = EFalse;
   196     if ( loopProp && loopProp->StringValue() == XnPropertyNames::KFalse )
   222         }
   197         {
   223     else
   198         looping = EFalse;
   224         {
   199         }
   225         iScrollLooping = ETrue;
   200     
   226         }    
   201     iControl->SetScrollLooping( looping );
   227     
   202     
   228     CXnProperty* restartProperty( iNode.GetPropertyL(
   203     CXnProperty* restartProperty( iNode.GetPropertyL(
   229             XnPropertyNames::newsticker::KRestartAfterUpdate ) );
   204         XnPropertyNames::newsticker::KRestartAfterUpdate ) );
   230     
   205     
   231     if ( restartProperty && restartProperty->StringValue() == XnPropertyNames::KTrue )
   206     if ( restartProperty && restartProperty->StringValue() == XnPropertyNames::KTrue )
   232         {
   207         {
   233         iRestartAfterUpdate = ETrue;
   208         iRestartAfterUpdate = ETrue;
   234         }
   209         }
   235      }
   210     }  
   236 
   211 
   237 // ============================ MEMBER FUNCTIONS ===============================
   212 // ============================ MEMBER FUNCTIONS ===============================
   238 
   213 
   239 // -----------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
   240 // CXnNewstickerAdapter::NewL
   215 // CXnNewstickerAdapter::NewL
   267     TCallBack callback( RedrawCallback, this );
   242     TCallBack callback( RedrawCallback, this );
   268     iMarqueeControl->SetRedrawCallBack( callback );
   243     iMarqueeControl->SetRedrawCallBack( callback );
   269     iMarqueeControl->SetContainerWindowL( *aParent );
   244     iMarqueeControl->SetContainerWindowL( *aParent );
   270     iMarqueeControl->ActivateL();
   245     iMarqueeControl->ActivateL();
   271     
   246     
   272     iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   247     iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityLow );
   273     
   248     
   274     SetTextPropertiesL();
   249     SetTextPropertiesL();
   275     SetNewstickerPropertiesL();
   250     SetNewstickerPropertiesL();
   276     
   251     
   277     RPointerArray<CXnNodePluginIf> children = iNode.ChildrenL();
   252     RPointerArray<CXnNodePluginIf> children = iNode.ChildrenL();
   279     
   254     
   280     for( TInt i = 0; i < children.Count(); ++i )
   255     for( TInt i = 0; i < children.Count(); ++i )
   281         {
   256         {
   282         CXnNodePluginIf* child( children[i] );
   257         CXnNodePluginIf* child( children[i] );
   283         
   258         
   284         CXnType* xnType = child->Type();
   259         const TDesC8& type( child->Type()->Type() );
   285         
   260                 
   286         // We only care for <title> nodes
   261         // We only care for <title> nodes
   287         if ( xnType && xnType->Type() == XnPropertyNames::title::KTitle )
   262         if ( type == XnPropertyNames::title::KTitle )
   288             {
   263             {
   289             // Append  title, if one is given from the theme use that.
   264             iControl->AppendTitleL( KNullDesC );    
   290             // If no content yet available create empty title so that 
   265             }
   291             // indexing is always current
   266         }
   292             const TDesC8& pcData( child->GetPCData() );
   267     CleanupStack::PopAndDestroy( &children );          
   293     
       
   294             HBufC* pcData16 = CnvUtfConverter::ConvertToUnicodeFromUtf8L( pcData );
       
   295             CleanupStack::PushL( pcData16 );
       
   296     
       
   297             TPtr ptr( pcData16->Des() );
       
   298     
       
   299             CXnUtils::CollapseWhiteSpace( iNode, ptr );
       
   300     
       
   301             if( ptr.Length() > 0 )
       
   302                 {
       
   303                 iControl->AppendTitleL( *pcData16 );
       
   304                 }
       
   305             else
       
   306                 {
       
   307                 iControl->AppendTitleL( KNullDesC );
       
   308                 }
       
   309     
       
   310             CleanupStack::PopAndDestroy( pcData16 );
       
   311             }
       
   312         }
       
   313     CleanupStack::PopAndDestroy( &children );
       
   314     
       
   315     iControl->SetCurrentTitle( ETrue );
       
   316     
       
   317     }
   268     }
   318 
   269 
   319 // -----------------------------------------------------------------------------
   270 // -----------------------------------------------------------------------------
   320 // CXnNewstickerAdapter::CXnNewstickerAdapter
   271 // CXnNewstickerAdapter::CXnNewstickerAdapter
   321 // C++ default constructor
   272 // C++ default constructor
   322 // -----------------------------------------------------------------------------
   273 // -----------------------------------------------------------------------------
   323 //
   274 //
   324 CXnNewstickerAdapter::CXnNewstickerAdapter( CXnControlAdapter* /*aParent*/, 
   275 CXnNewstickerAdapter::CXnNewstickerAdapter( CXnControlAdapter* /*aParent*/, 
   325     CXnNodePluginIf& aNode )
   276     CXnNodePluginIf& aNode )
   326     : iNode( aNode ),
   277     : iNode( aNode ),
   327       iPowerSaveMode( ETrue ),
   278       iPowerSaveMode( EFalse ),
   328       iRestartAfterUpdate( EFalse ),
   279       iRestartAfterUpdate( EFalse ),
   329       iTextColor( KRgbBlack ),
   280       iTextColor( KRgbBlack ),
   330       iTextAlignment( ELayoutAlignLeft ),
   281       iTextAlignment( CGraphicsContext::ELeft ),
   331       iTextBaseline( 0 ),
   282       iTextBaseline( 0 ),
   332       iUnderlining( EUnderlineOff ),
   283       iUnderlining( EUnderlineOff ),
   333       iStrikethrough( EStrikethroughOff ),
   284       iStrikethrough( EStrikethroughOff ),      
   334       iScrollLooping( ETrue ),
       
   335       iRedraw( ETrue )
   285       iRedraw( ETrue )
   336     {
   286     {
   337     }
   287     }
   338 
   288 
   339 // -----------------------------------------------------------------------------
   289 // -----------------------------------------------------------------------------
   341 // C++ destructor
   291 // C++ destructor
   342 // -----------------------------------------------------------------------------
   292 // -----------------------------------------------------------------------------
   343 //
   293 //
   344 CXnNewstickerAdapter::~CXnNewstickerAdapter()
   294 CXnNewstickerAdapter::~CXnNewstickerAdapter()
   345     {           
   295     {           
   346     if( iPeriodicTimer && iPeriodicTimer->IsActive() )
       
   347         {
       
   348         iPeriodicTimer->Cancel();
       
   349         }
       
   350         
       
   351     delete iPeriodicTimer;
   296     delete iPeriodicTimer;
   352 
   297 
   353     if( iFont && ( iReleaseFont == 1 ) )
   298     if( iFont && ( iReleaseFont == 1 ) )
   354         {
   299         {
   355         CWsScreenDevice* dev = iCoeEnv->ScreenDevice();
   300         CWsScreenDevice* dev = iCoeEnv->ScreenDevice();
   356         dev->ReleaseFont( iFont ); 
   301         dev->ReleaseFont( iFont ); 
   357         }
   302         }
   358     
   303     
   359     delete iMarqueeControl;
   304     delete iMarqueeControl;
   360     delete iControl;
   305     delete iControl;
   361 
       
   362     }
   306     }
   363 
   307 
   364 // -----------------------------------------------------------------------------
   308 // -----------------------------------------------------------------------------
   365 // CXnNewstickerAdapter::SetTextPropertiesL
   309 // CXnNewstickerAdapter::SetTextPropertiesL
   366 // Sets text properties, such as color, font, etc.
   310 // Sets text properties, such as color, font, etc.
   475     TGulAlignmentValue alignment = CXnUtils::TextAlignment( iNode );
   419     TGulAlignmentValue alignment = CXnUtils::TextAlignment( iNode );
   476     
   420     
   477     switch( alignment )
   421     switch( alignment )
   478         {
   422         {
   479         case EHCenterVCenter:            
   423         case EHCenterVCenter:            
   480             iTextAlignment = ELayoutAlignCenter;                 
   424             iTextAlignment = CGraphicsContext::ECenter;                 
   481             break;
   425             break;            
   482             
       
   483         case EHRightVCenter:            
   426         case EHRightVCenter:            
   484             iTextAlignment = ELayoutAlignRight;                
   427             iTextAlignment = CGraphicsContext::ERight;                
   485             break;
   428             break;            
   486             
       
   487         default: 
   429         default: 
   488             iTextAlignment = ELayoutAlignLeft;
   430             iTextAlignment = CGraphicsContext::ELeft;
   489             break;    
   431             break;    
   490         }   
   432         }   
   491     }
   433     }
   492 
   434 
   493 // -----------------------------------------------------------------------------
   435 // -----------------------------------------------------------------------------
   518     {
   460     {
   519     iControl->UpdateTitleL( aTitle, aIndex );
   461     iControl->UpdateTitleL( aTitle, aIndex );
   520     iNode.SetDirtyL();
   462     iNode.SetDirtyL();
   521     
   463     
   522     if ( iRestartAfterUpdate )
   464     if ( iRestartAfterUpdate )
   523         {
   465         {        
   524         Stop();
   466         Restart();
   525         Start();
       
   526         }
   467         }
   527     }
   468     }
   528 
   469 
   529 // -----------------------------------------------------------------------------
   470 // -----------------------------------------------------------------------------
   530 // CXnNewstickerAdapter::DeleteTitleL
   471 // CXnNewstickerAdapter::DeleteTitleL
   563     iControl->ClearTitles();
   504     iControl->ClearTitles();
   564     TRAP_IGNORE( iNode.SetDirtyL() );
   505     TRAP_IGNORE( iNode.SetDirtyL() );
   565     }
   506     }
   566 
   507 
   567 // -----------------------------------------------------------------------------
   508 // -----------------------------------------------------------------------------
   568 // CXnNewstickerAdapter::SetCallbackInterfaceL
   509 // CXnNewstickerAdapter::Restart
   569 // -----------------------------------------------------------------------------
   510 // -----------------------------------------------------------------------------
   570 //
   511 //
   571 void CXnNewstickerAdapter::SetCallbackInterfaceL(
   512 void CXnNewstickerAdapter::Restart()
   572         XnNewstickerInterface::MXnNewstickerCallbackInterface* aCallback )
   513     {
   573     {
   514     Stop();
   574     iCallback = aCallback;
   515     Start( ETrue );                
   575     }
   516     }
   576 
   517 
   577 // -----------------------------------------------------------------------------
   518 // -----------------------------------------------------------------------------
   578 // CXnNewstickerAdapter::TitleScrolled
   519 // CXnNewstickerAdapter::Start
   579 // -----------------------------------------------------------------------------
   520 // -----------------------------------------------------------------------------
   580 //
   521 //
   581 void CXnNewstickerAdapter::TitleScrolled( TInt aTitleIndex )
   522 void CXnNewstickerAdapter::Start( TBool aSelectTitle )
   582     {
   523     {
   583     if( iCallback )
   524     if ( IsVisible() && !iPowerSaveMode && !iNode.Rect().IsEmpty() )
   584         {
   525         {
   585         iCallback->TitleScrolled( aTitleIndex );
   526         if ( aSelectTitle )
   586         }
   527             {
   587     }
   528             if ( iControl->SelectTitle() == KErrNotFound )
   588 
   529                 {
   589 // -----------------------------------------------------------------------------
   530                 return;
   590 // CXnNewstickerAdapter::StartL
   531                 }
   591 // -----------------------------------------------------------------------------
   532             }
   592 //
   533         
   593 void CXnNewstickerAdapter::Start()
   534         const TDesC& title( iControl->CurrentTitle() );
   594     {
   535                                 
   595     if( IsVisible() && !iPowerSaveMode )
   536         switch ( iScrollBehaviour )
   596         {
       
   597         if( iControl->TitleCount() < 1 )
       
   598             {
       
   599             // Nothing to show
       
   600             return;
       
   601             }
       
   602         
       
   603         switch( iScrollBehaviour )
       
   604             {
   537             {
   605             case EScroll:
   538             case EScroll:
       
   539             case EScrollAlternate:
   606                 {
   540                 {
   607                 iMarqueeControl->EnableMarquee( ETrue );
   541                 iMarqueeControl->EnableMarquee( ETrue );
   608                 iRedraw = ETrue;
   542                 iRedraw = ETrue;
   609                 }
   543 
   610                 break;
   544                 TInt textWidth( 
       
   545                     iFont->TextWidthInPixels( title ) );
   611                 
   546                 
       
   547                 TInt rectWidth( iNode.Rect().Width() );
       
   548                 
       
   549                 if ( textWidth < rectWidth )
       
   550                     {
       
   551                     StartAlternateCounter();
       
   552                     }                                
       
   553                 }
       
   554                 break;                
   612             case EAlternate:
   555             case EAlternate:
   613                 {
   556                 {
   614                 iMarqueeControl->EnableMarquee( EFalse );
   557                 iMarqueeControl->EnableMarquee( EFalse );
   615                 StartAlternateCounter();  
   558                 StartAlternateCounter();  
   616                 }
   559                 }
   617                 break;
   560                 break;                
   618                 
       
   619             case EScrollAlternate:
       
   620                 {
       
   621                 iMarqueeControl->EnableMarquee( ETrue );
       
   622                 StartAlternateCounter(); 
       
   623                 iRedraw = ETrue;
       
   624                 }
       
   625                 break;
       
   626                 
       
   627             default:
   561             default:
   628                 break;
   562                 break;
   629             }
   563             }
       
   564         
       
   565         DrawDeferred();
   630         }
   566         }
   631     }
   567     }
   632 
   568 
   633 // -----------------------------------------------------------------------------
   569 // -----------------------------------------------------------------------------
   634 // CXnNewstickerAdapter::Stop
   570 // CXnNewstickerAdapter::Stop
   644 // CXnNewstickerAdapter::StopAlternateCounter
   580 // CXnNewstickerAdapter::StopAlternateCounter
   645 // -----------------------------------------------------------------------------
   581 // -----------------------------------------------------------------------------
   646 //
   582 //
   647 void CXnNewstickerAdapter::StopAlternateCounter()
   583 void CXnNewstickerAdapter::StopAlternateCounter()
   648     {
   584     {
   649     if( iPeriodicTimer && iPeriodicTimer->IsActive() )
   585     iPeriodicTimer->Cancel();    
   650         {
       
   651         iPeriodicTimer->Cancel();
       
   652         }
       
   653     }
   586     }
   654 
   587 
   655 // -----------------------------------------------------------------------------
   588 // -----------------------------------------------------------------------------
   656 // CXnNewstickerAdapter::StopMarquee
   589 // CXnNewstickerAdapter::StopMarquee
   657 // -----------------------------------------------------------------------------
   590 // -----------------------------------------------------------------------------
   666 // CXnNewstickerAdapter::StartCounter
   599 // CXnNewstickerAdapter::StartCounter
   667 // -----------------------------------------------------------------------------
   600 // -----------------------------------------------------------------------------
   668 //
   601 //
   669 void CXnNewstickerAdapter::StartAlternateCounter()
   602 void CXnNewstickerAdapter::StartAlternateCounter()
   670     {
   603     {
   671     if( iPeriodicTimer && iPeriodicTimer->IsActive() )
   604     iPeriodicTimer->Cancel();
   672         {
   605     
   673         iPeriodicTimer->Cancel();
       
   674         }
       
   675 
       
   676     iPeriodicTimer->Start(                
   606     iPeriodicTimer->Start(                
   677         TTimeIntervalMicroSeconds32( iAlternateDelay ),
   607         TTimeIntervalMicroSeconds32( iAlternateDelay ),
   678         TTimeIntervalMicroSeconds32( iAlternateInterval ), 
   608         TTimeIntervalMicroSeconds32( 0 ), 
   679         TCallBack( CXnNewstickerAdapter::PeriodicEventL, this ) ); 
   609         TCallBack( PeriodicEventL, this ) ); 
   680     }
   610     }
   681 
   611 
   682 // -----------------------------------------------------------------------------
   612 // -----------------------------------------------------------------------------
   683 // CXnNewstickerAdapter::PeriodicEventL
   613 // CXnNewstickerAdapter::PeriodicEventL
   684 // -----------------------------------------------------------------------------
   614 // -----------------------------------------------------------------------------
   685 //
   615 //
   686 TInt CXnNewstickerAdapter::PeriodicEventL( TAny* aPtr )
   616 TInt CXnNewstickerAdapter::PeriodicEventL( TAny* aPtr )
   687     {
   617     {
   688     __PRINTS( "CXnNewstickerAdapter::PeriodicEventL, timer runs" );
   618     __PRINTS( "CXnNewstickerAdapter::PeriodicEventL, timer runs" );
       
   619     
   689     CXnNewstickerAdapter* self = static_cast< CXnNewstickerAdapter* >( aPtr );
   620     CXnNewstickerAdapter* self = static_cast< CXnNewstickerAdapter* >( aPtr );
   690     self->DoScroll();
   621     
       
   622     self->iPeriodicTimer->Cancel();
       
   623     
       
   624     TBool endOfLoop( self->iControl->SelectNextTitle() );
       
   625     
       
   626     self->DoScroll( endOfLoop );
   691   
   627   
       
   628     self->DrawNow();
       
   629     
   692     return KErrNone;
   630     return KErrNone;
   693     }
   631     }
   694 
   632 
   695 // -----------------------------------------------------------------------------
   633 // -----------------------------------------------------------------------------
   696 // CXnNewstickerAdapter::MakeVisible()
   634 // CXnNewstickerAdapter::MakeVisible()
   698 //
   636 //
   699 void CXnNewstickerAdapter::MakeVisible( TBool aVisible )
   637 void CXnNewstickerAdapter::MakeVisible( TBool aVisible )
   700     {
   638     {
   701     CCoeControl::MakeVisible( aVisible );
   639     CCoeControl::MakeVisible( aVisible );
   702 
   640 
   703     if( aVisible )
   641     if ( aVisible )
   704         {
   642         {
   705         Start();
   643         Restart();
   706         }
   644         }
   707     else
   645     else
   708         {
   646         {
   709         Stop();
   647         Stop();
   710         }
   648         }
   717 void CXnNewstickerAdapter::SizeChanged()
   655 void CXnNewstickerAdapter::SizeChanged()
   718     {
   656     {
   719     CXnControlAdapter::SizeChanged();         
   657     CXnControlAdapter::SizeChanged();         
   720     iMarqueeControl->SetExtent( iNode.Rect().iTl, iNode.Rect().Size() );
   658     iMarqueeControl->SetExtent( iNode.Rect().iTl, iNode.Rect().Size() );
   721     
   659     
   722     iTextBaseline = iNode.Rect().Height() / 2 + iFont->AscentInPixels() / 2;
   660     iTextBaseline = iNode.Rect().Height() / 2 + iFont->AscentInPixels() / 2;    
   723     }
   661     }
   724 
   662 
   725 // -----------------------------------------------------------------------------
   663 // -----------------------------------------------------------------------------
   726 // CXnNewstickerAdapter::CountComponentControls() const
   664 // CXnNewstickerAdapter::CountComponentControls() const
   727 // -----------------------------------------------------------------------------
   665 // -----------------------------------------------------------------------------
   735 // CXnNewstickerAdapter::ComponentControl(TInt aIndex) const
   673 // CXnNewstickerAdapter::ComponentControl(TInt aIndex) const
   736 // -----------------------------------------------------------------------------
   674 // -----------------------------------------------------------------------------
   737 //
   675 //
   738 CCoeControl* CXnNewstickerAdapter::ComponentControl( TInt aIndex ) const
   676 CCoeControl* CXnNewstickerAdapter::ComponentControl( TInt aIndex ) const
   739     {
   677     {
   740     switch ( aIndex )
   678     if ( aIndex == 0 )
   741         {
   679         {
   742         case 0:
   680         return iMarqueeControl;
   743             return iMarqueeControl;
   681         }
   744             
   682 
   745         default:
   683     return NULL;        
   746             return NULL;
       
   747         }
       
   748     }
   684     }
   749 
   685 
   750 // -----------------------------------------------------------------------------
   686 // -----------------------------------------------------------------------------
   751 // CXnNewstickerAdapter::DoHandlePropertyChangeL
   687 // CXnNewstickerAdapter::DoHandlePropertyChangeL
   752 // -----------------------------------------------------------------------------
   688 // -----------------------------------------------------------------------------
   769 
   705 
   770 // -----------------------------------------------------------------------------
   706 // -----------------------------------------------------------------------------
   771 // CXnNewstickerAdapter::ReportNewstickerEventL
   707 // CXnNewstickerAdapter::ReportNewstickerEventL
   772 // -----------------------------------------------------------------------------
   708 // -----------------------------------------------------------------------------
   773 // 
   709 // 
   774 void CXnNewstickerAdapter::ReportNewstickerEvent( const TDesC8& aEventName )
   710 void CXnNewstickerAdapter::ReportNewstickerEvent( const TDesC8& aEventName,
       
   711     TInt aIndex )
   775     { 
   712     { 
   776     TBuf8<KByteLength>index( KNullDesC8 );
   713     TBuf8< KByteLength >index( KNullDesC8 );
   777     index.Num( CurrentTitleIndex() );
   714     index.Num( aIndex );
   778     
   715     
   779     TRAP_IGNORE( iNode.ReportTriggerEventL( aEventName,
   716     TRAP_IGNORE( iNode.ReportTriggerEventL( aEventName,
   780             XnPropertyNames::action::trigger::name::KTitleIndex, index ); )
   717             XnPropertyNames::action::trigger::name::KTitleIndex, index ); )
   781     }
   718     }
   782 
   719 
   784 // CXnNewstickerAdapter::Draw
   721 // CXnNewstickerAdapter::Draw
   785 // Draws the text component
   722 // Draws the text component
   786 // -----------------------------------------------------------------------------
   723 // -----------------------------------------------------------------------------
   787 void CXnNewstickerAdapter::Draw( const TRect& aRect ) const
   724 void CXnNewstickerAdapter::Draw( const TRect& aRect ) const
   788     {    
   725     {    
   789     const_cast<CXnNewstickerAdapter*>(this)->DrawText( iControl->SelectTitle(), aRect );
   726     CXnControlAdapter::Draw( aRect );
       
   727     
       
   728     if ( iControl->CurrentTitleIndex() != KErrNotFound )
       
   729         {
       
   730         const TDesC& title( iControl->CurrentTitle() );
       
   731         
       
   732         const_cast< CXnNewstickerAdapter* >( this )->DrawText( title );             
       
   733         }
   790     }
   734     }
   791     
   735     
   792 // -----------------------------------------------------------------------------
   736 // -----------------------------------------------------------------------------
   793 // CXnNewstickerAdapter::DoEnterPowerSaveModeL
   737 // CXnNewstickerAdapter::DoEnterPowerSaveModeL
   794 // Enter power save mode
   738 // Enter power save mode
   795 // -----------------------------------------------------------------------------
   739 // -----------------------------------------------------------------------------
   796 void CXnNewstickerAdapter::DoEnterPowerSaveModeL( TModeEvent /*aEvent*/ )
   740 void CXnNewstickerAdapter::DoEnterPowerSaveModeL( TModeEvent /*aEvent*/ )
   797     {     
   741     {     
   798     iPowerSaveMode = ETrue;
   742     iPowerSaveMode = ETrue;
       
   743     
   799     Stop();
   744     Stop();
   800     }
   745     }
   801 
   746 
   802 // -----------------------------------------------------------------------------
   747 // -----------------------------------------------------------------------------
   803 // CXnNewstickerAdapter::DoExitPowerSaveModeL
   748 // CXnNewstickerAdapter::DoExitPowerSaveModeL
   805 // -----------------------------------------------------------------------------
   750 // -----------------------------------------------------------------------------
   806 void CXnNewstickerAdapter::DoExitPowerSaveModeL( TModeEvent /*aEvent*/ )
   751 void CXnNewstickerAdapter::DoExitPowerSaveModeL( TModeEvent /*aEvent*/ )
   807     {
   752     {
   808     iPowerSaveMode = EFalse;
   753     iPowerSaveMode = EFalse;
   809     
   754     
   810     if( IsVisible() )
   755     if ( IsVisible() )
   811         {
   756         {
   812         Start();
   757         Restart();
   813         }
   758         }
   814     }
   759     }
   815 
   760 
   816 // -----------------------------------------------------------------------------
   761 // -----------------------------------------------------------------------------
   817 // CXnNewstickerAdapter::DrawText
   762 // CXnNewstickerAdapter::DrawText
   818 // Text drawing function is selected by scrolling behaviour
   763 // Text drawing function is selected by scrolling behaviour
   819 // -----------------------------------------------------------------------------
   764 // -----------------------------------------------------------------------------
   820 void CXnNewstickerAdapter::DrawText( const TDesC& aText, const TRect& aRect )
   765 void CXnNewstickerAdapter::DrawText( const TDesC& aText )
   821     {    
   766     {    
   822     CWindowGc& gc = SystemGc();
   767     CWindowGc& gc( SystemGc() );
   823     
   768     
   824     TRect rect = iNode.Rect();
   769     TRect rect( iNode.Rect() );
   825            
   770                   
   826     CXnControlAdapter::Draw( aRect );
       
   827     
       
   828     gc.SetPenColor( iTextColor );
   771     gc.SetPenColor( iTextColor );
   829     gc.UseFont( iFont );
   772     gc.UseFont( iFont );
   830     gc.SetUnderlineStyle( iUnderlining );
   773     gc.SetUnderlineStyle( iUnderlining );
   831     gc.SetStrikethroughStyle( iStrikethrough );
   774     gc.SetStrikethroughStyle( iStrikethrough );
   832            
   775            
   833     TInt textWidth = iFont->TextWidthInPixels( aText );
   776     TInt textWidth( iFont->TextWidthInPixels( aText ) );
   834     TInt rectWidth = rect.Width();
   777     TInt rectWidth( rect.Width() );
   835     
   778     
   836     switch( iScrollBehaviour )
   779     switch ( iScrollBehaviour )
   837         {  
   780         {  
   838         case EScroll:
   781         case EScroll:
   839         case EScrollAlternate:
   782         case EScrollAlternate:
   840             {
   783             {
   841             if( !iRedraw || textWidth < rectWidth )
   784             if ( !iRedraw || textWidth < rectWidth )                 
   842                 {
   785                 {
   843                 iMarqueeControl->Stop();
   786                 iMarqueeControl->Stop();
   844                 DrawStaticText( gc, aText );
   787                 DrawStaticText( gc, aText );                
   845                 }
   788                 }
   846             else
   789             else
   847                 {
   790                 {
   848                 iMarqueeControl->Start();
   791                 iMarqueeControl->Start();
   849                 TBool isLast = DrawMarqueeText( gc, aText );
   792 
   850                 
   793                 iRedraw = !DrawMarqueeText( gc, aText );   
   851                 if( isLast )
   794                                                    
       
   795                 if ( !iRedraw )                    
   852                     {
   796                     {
   853                     if( !iScrollLooping )
   797                     // Marquee is in end
       
   798                     if ( iPeriodicTimer && !iPeriodicTimer->IsActive() )
   854                         {
   799                         {
   855                         iRedraw = EFalse;
   800                         iPeriodicTimer->Start(                
       
   801                             TTimeIntervalMicroSeconds32( 0 ),
       
   802                             TTimeIntervalMicroSeconds32( 0 ), 
       
   803                             TCallBack( PeriodicEventL, this ) );                         
   856                         }
   804                         }
   857                     
   805                     
   858                     iMarqueeControl->Reset();
   806                     TBool endOfLoop;
   859                     StartAlternateCounter();
   807                     
   860                     }
   808                     const TDesC& next( iControl->PeekNextTitle( endOfLoop ) );
   861                 }
   809                     
   862             }
   810                     DrawStaticText( gc, next, endOfLoop );                    
   863             break;
   811                     }                
   864             
   812                 }                        
       
   813             }
       
   814             break;            
   865         case EAlternate:
   815         case EAlternate:
   866             {
   816             {
   867             DrawStaticText( gc, aText );
   817             DrawStaticText( gc, aText );
   868             }
   818             }
   869             break;
   819             break;            
   870             
       
   871         default:
   820         default:
   872             break;
   821             break;
   873         }
   822         }
   874       }
   823     }
   875 
   824 
   876 // -----------------------------------------------------------------------------
   825 // -----------------------------------------------------------------------------
   877 // CXnNewstickerAdapter::RedrawCallback
   826 // CXnNewstickerAdapter::RedrawCallback
   878 // Callback function for marquee control
   827 // Callback function for marquee control
   879 // -----------------------------------------------------------------------------
   828 // -----------------------------------------------------------------------------
   880 //
   829 //
   881 TInt CXnNewstickerAdapter::RedrawCallback( TAny* aPtr )
   830 TInt CXnNewstickerAdapter::RedrawCallback( TAny* aPtr )
   882     {
   831     {
   883     CXnNewstickerAdapter* self = static_cast<CXnNewstickerAdapter*>( aPtr );
   832     CXnNewstickerAdapter* self = static_cast< CXnNewstickerAdapter* >( aPtr );
   884     self->DrawNow();
   833     
   885 
   834     if ( self->iRedraw )
   886     return self->Redraw();
   835         {
   887  
   836         self->DrawNow();        
       
   837         }
       
   838             
       
   839     return self->iRedraw; 
   888     }
   840     }
   889 
   841 
   890 // -----------------------------------------------------------------------------
   842 // -----------------------------------------------------------------------------
   891 // CXnNewstickerAdapter::DoScroll
   843 // CXnNewstickerAdapter::DoScroll
   892 // Scrolls alternative text. Function is called by periodic timer
   844 // 
   893 // -----------------------------------------------------------------------------
   845 // -----------------------------------------------------------------------------
   894 //
   846 //
   895 void CXnNewstickerAdapter::DoScroll()
   847 void CXnNewstickerAdapter::DoScroll( TBool aEndOfLoop )
   896     {
   848     {
   897     ReportNewstickerEvent( XnPropertyNames::action::trigger::name::KTitleScrolled );
   849     iMarqueeControl->Reset();
   898     
   850         
   899     if( iControl->SetCurrentTitle() )
   851     iRedraw = EFalse;
   900         {
   852     
   901         // stop alternate scrolling if current index is last
   853     if ( !aEndOfLoop )
   902         StopAlternateCounter();
   854         {        
   903         }
   855         Start();
   904     
   856         }
   905     DrawNow();
   857     else 
   906  
   858         {
   907     ReportNewstickerEvent( XnPropertyNames::action::trigger::name::KTitleToScroll );
   859         Stop();
       
   860         }
   908     }
   861     }
   909 
   862 
   910 // -----------------------------------------------------------------------------
   863 // -----------------------------------------------------------------------------
   911 // CXnNewstickerAdapter::DrawStatic
   864 // CXnNewstickerAdapter::DrawStatic
   912 // Draws text directly to screen when scrolling is not needed
   865 // Draws text directly to screen when scrolling is not needed
   913 // -----------------------------------------------------------------------------
   866 // -----------------------------------------------------------------------------
   914 //
   867 //
   915 void CXnNewstickerAdapter::DrawStaticText( CWindowGc& aGc, const TDesC& aText ) const
   868 void CXnNewstickerAdapter::DrawStaticText( CWindowGc& aGc, 
       
   869     const TDesC& aText, TBool aTruncate ) const
   916     { 
   870     { 
   917     HBufC* text = HBufC::New( aText.Length() + KAknBidiExtraSpacePerLine );
   871     HBufC* text = HBufC::New( aText.Length() + KAknBidiExtraSpacePerLine );
   918     
   872     
   919     if( text )
   873     if ( text )
   920         {
   874         {
   921         TRect rect = iNode.Rect();
   875         TRect rect = iNode.Rect();        
   922         TInt maxLength = rect.Width();
   876         TInt maxLength = rect.Width();
       
   877         
       
   878         TChar clipChar( aTruncate ? KEllipsis : 0xFFFF );
       
   879         
   923         TPtr ptr = text->Des();
   880         TPtr ptr = text->Des();
   924         AknBidiTextUtils::ConvertToVisualAndClip(
   881         AknBidiTextUtils::ConvertToVisualAndClip(
   925                 aText, ptr, *iFont, maxLength, maxLength );
   882                 aText, ptr, *iFont, maxLength, maxLength, 
       
   883                 AknBidiTextUtils::EImplicit, clipChar );
   926         
   884         
   927         aGc.DrawText( *text, rect, iTextBaseline,
   885         aGc.DrawText( *text, rect, iTextBaseline,
   928                 ( CGraphicsContext::TTextAlign )iTextAlignment );
   886                 ( CGraphicsContext::TTextAlign )iTextAlignment );
   929         
   887         
   930         delete text;
   888         delete text;
   934 // -----------------------------------------------------------------------------
   892 // -----------------------------------------------------------------------------
   935 // CXnNewstickerAdapter::DrawScrolling
   893 // CXnNewstickerAdapter::DrawScrolling
   936 // Draws scrolling text to screen via marquee control
   894 // Draws scrolling text to screen via marquee control
   937 // -----------------------------------------------------------------------------
   895 // -----------------------------------------------------------------------------
   938 //
   896 //
   939 TBool CXnNewstickerAdapter::DrawMarqueeText( CWindowGc& aGc, const TDesC& aText ) const
   897 TBool CXnNewstickerAdapter::DrawMarqueeText( CWindowGc& aGc, 
   940     {
   898     const TDesC& aText ) const
   941     TRect rect = iNode.Rect();
   899     {
       
   900     TRect rect( iNode.Rect() );
   942     
   901     
   943     // returns true when all loops have been executed
   902     // returns true when all loops have been executed
   944     return iMarqueeControl->DrawText( aGc, rect, aText, iTextBaseline,
   903     return iMarqueeControl->DrawText( aGc, rect, aText, iTextBaseline,
   945             ( CGraphicsContext::TTextAlign )iTextAlignment, *iFont );
   904             ( CGraphicsContext::TTextAlign )iTextAlignment, *iFont );
   946     }
   905     }