|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : NaviScrollTimer.cpp 00004 * Part of : Listbox example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2007 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 #include <aknnavi.h> 00017 #include <aknnavide.h> 00018 #include <eikspane.h> 00019 #include <aknutils.h> 00020 #include "NaviScrollTimer.h" 00021 00022 // This is the maximum length for visible text in navigation pane 00023 const TInt KMaxVisibleStringLenth = 19; 00024 // Following timeout is used on scrolling starts from the beginning (after text 00025 // is scrolled totally to left). Timeout is in microseconds. 00026 const TInt KScrollStartTimeout = 1000000; 00027 // Timeout for scrolling (in microseconds). 00028 const TInt KScrollTimeout = 90000; 00029 00030 // ============================ MEMBER FUNCTIONS =============================== 00031 00032 // ----------------------------------------------------------------------------- 00033 // CNaviScrollTimer::CNaviScrollTimer() 00034 // C++ Default constructor. 00035 // ----------------------------------------------------------------------------- 00036 // 00037 CNaviScrollTimer::CNaviScrollTimer() 00038 : CTimer( CActive::EPriorityStandard ) 00039 { 00040 } 00041 00042 // ----------------------------------------------------------------------------- 00043 // CNaviScrollTimer::~CNaviScrollTimer() 00044 // Destructor 00045 // ----------------------------------------------------------------------------- 00046 // 00047 CNaviScrollTimer::~CNaviScrollTimer() 00048 { 00049 Cancel(); 00050 delete iNaviText; 00051 00052 if( iDecorator ) 00053 { 00054 if( iNaviPane ) iNaviPane->Pop( iDecorator ); 00055 delete iDecorator; 00056 } 00057 } 00058 00059 // ----------------------------------------------------------------------------- 00060 // CNaviScrollTimer::ConstructL() 00061 // 2nd phase constructor. 00062 // ----------------------------------------------------------------------------- 00063 // 00064 void CNaviScrollTimer::ConstructL( const TDesC& aNavitext ) 00065 { 00066 CActiveScheduler::Add( this ); 00067 CTimer::ConstructL(); 00068 00069 iNaviText = aNavitext.AllocL(); 00070 iCount = iNaviText->Des().Length(); 00071 00072 // Get the navigation pane 00073 CEikStatusPane* sp = CEikonEnv::Static()->AppUiFactory()->StatusPane(); 00074 iNaviPane = static_cast<CAknNavigationControlContainer*>( 00075 sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ); 00076 } 00077 00078 // ----------------------------------------------------------------------------- 00079 // CNaviScrollTimer::NewL() 00080 // Two-phased constructor. 00081 // ----------------------------------------------------------------------------- 00082 // 00083 CNaviScrollTimer* CNaviScrollTimer::NewL( const TDesC& aNavitext ) 00084 { 00085 CNaviScrollTimer* self = new ( ELeave ) CNaviScrollTimer(); 00086 CleanupStack::PushL( self ); 00087 self->ConstructL( aNavitext ); 00088 CleanupStack::Pop( self ); 00089 return self; 00090 } 00091 00092 // ----------------------------------------------------------------------------- 00093 // CNaviScrollTimer::RunL() 00094 // After completed timer period, execution comes to RunL. 00095 // ----------------------------------------------------------------------------- 00096 // 00097 void CNaviScrollTimer::RunL() 00098 { 00099 TInt timeout; 00100 00101 if( UpdateNaviPaneL() ) 00102 timeout = KScrollStartTimeout; 00103 else 00104 timeout = KScrollTimeout; 00105 00106 After( timeout ); 00107 } 00108 00109 // ----------------------------------------------------------------------------- 00110 // CNaviScrollTimer::StartScroll() 00111 // Starts to scroll the navigation pane text. 00112 // ----------------------------------------------------------------------------- 00113 // 00114 void CNaviScrollTimer::StartScroll() 00115 { 00116 // Start scrolling only if text do not fit to navi pane 00117 if( iNaviText->Des().Length() > KMaxVisibleStringLenth ) 00118 After( 1 ); 00119 else 00120 UpdateNaviPaneL(); 00121 } 00122 00123 // ----------------------------------------------------------------------------- 00124 // CNaviScrollTimer::UpdateNaviPaneL() 00125 // Updates the Navigation pane. Every time when this function is called 00126 // it moves the text to the left by one character. 00127 // ----------------------------------------------------------------------------- 00128 // 00129 TBool CNaviScrollTimer::UpdateNaviPaneL() 00130 { 00131 TBool returnVal( EFalse ); 00132 // Return ETrue if text is scrolled totally to left 00133 if( iCount == iNaviText->Des().Length() ) 00134 returnVal = ETrue; 00135 00136 // NaviLabel can only be updated by creating a new navidecorator. 00137 if( iDecorator ) 00138 { 00139 iNaviPane->Pop( iDecorator ); 00140 delete iDecorator; 00141 iDecorator = NULL; 00142 } 00143 // Create new decorator 00144 iDecorator = iNaviPane->CreateNavigationLabelL(); 00145 // Push decorator object to the navigation pane's object stack. 00146 iNaviPane->PushL( *iDecorator ); 00147 // Get the control inside of decorator object as CAknNaviLabel. 00148 CAknNaviLabel* naviLabel = 00149 static_cast<CAknNaviLabel*>( iDecorator->DecoratedControl() ); 00150 // Finally set label text 00151 naviLabel->SetTextL( iNaviText->Des().Right(iCount) ); 00152 00153 iCount--; 00154 if(iCount == 0) 00155 iCount = iNaviText->Des().Length(); 00156 00157 return returnVal; 00158 }
|
© Nokia 2009 |