imstutils/imconversationview/imcvuiapp/src/cimcvnewmsgfadecontrol.cpp
changeset 0 5e5d6b214f4f
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:  Fader control in navi pane
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "cimcvnewmsgfadecontrol.h"
       
    21 #include	"mimcvnewmsgfadecontrolobserver.h"
       
    22 
       
    23 #include	"cimcvappui.h"
       
    24 #include	"mimcvapplayoutinfo.h"
       
    25 
       
    26 #include	<eikenv.h>
       
    27 #include	<AknUtils.h>
       
    28 #include	<aknnavi.h>
       
    29 #include	<aknconsts.h>
       
    30 #include    <aknenv.h>
       
    31 #include    <applayout.cdl.h>
       
    32 #include    <AknsDrawUtils.h>
       
    33 #include    <AknsBasicBackgroundControlContext.h>
       
    34 
       
    35 
       
    36 //CONSTANTS
       
    37 const TInt KLafCount( 10 ); //Count of LAF indexes
       
    38 const TInt KDelayColorIndex( 5 ); //From LAF: Color 0 is in index 5
       
    39 const TTimeIntervalMicroSeconds32 KIndicationDelay( 4000000 ); //4 seconds waiting
       
    40 const TUint16 KAIMMessageIcon( 0xF808 ); //PUA icon code for AIMMESSAGE
       
    41 
       
    42 // ========================= MEMBER FUNCTIONS ================================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CIMCVNewMsgFadeControl::NewL
       
    46 // Two-phased constructor.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CIMCVNewMsgFadeControl* CIMCVNewMsgFadeControl::NewL( const TRect& aRect )
       
    50 	{
       
    51 	CIMCVNewMsgFadeControl* self = CIMCVNewMsgFadeControl::NewLC( aRect );
       
    52 	CleanupStack::Pop( self );
       
    53 	return self;
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CIMCVNewMsgFadeControl::NewLC
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CIMCVNewMsgFadeControl* CIMCVNewMsgFadeControl::NewLC( const TRect& aRect )
       
    62 	{
       
    63 	CIMCVNewMsgFadeControl* self = new ( ELeave ) CIMCVNewMsgFadeControl();
       
    64 	CleanupStack::PushL( self );
       
    65 	self->ConstructL( aRect );
       
    66 	return self;
       
    67 	}   
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CIMCVNewMsgFadeControl::ConstructL(const TRect& aRect)
       
    71 // Symbian OS two phased constructor
       
    72 // 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CIMCVNewMsgFadeControl::ConstructL( const TRect& aRect )
       
    76     {
       
    77 
       
    78 	iLayoutInfo = static_cast<CIMCVAppUi*>( iEikonEnv->AppUi() )->
       
    79 			LayoutInfo();
       
    80 	// Currently we have 2 observers, so granularity of 2 is logical choice.
       
    81 	iObserverArray = new ( ELeave ) CArrayPtrSeg<MIMCVNewMsgFadeControlObserver>(2);
       
    82 	iIMessage = HBufC::NewL( 512 + 1);//1 is indication character
       
    83 	iTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
    84 	
       
    85 	iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
    86 	        KAknsIIDQsnBgNavipaneSolid, aRect, EFalse );
       
    87 	iViewRect = TRect( aRect );
       
    88 	CreateWindowL();
       
    89 	MakeVisible( EFalse );
       
    90 	}
       
    91 
       
    92 // Constructor
       
    93 CIMCVNewMsgFadeControl::CIMCVNewMsgFadeControl()
       
    94 	:iTimerState( ETimerStopped )	
       
    95 	{
       
    96 	
       
    97 	}
       
    98 
       
    99 // Destructor
       
   100 CIMCVNewMsgFadeControl::~CIMCVNewMsgFadeControl()
       
   101     {
       
   102 	
       
   103 	if( iObserverArray ) 
       
   104 		{
       
   105 		iObserverArray->Reset();
       
   106 		delete iObserverArray;
       
   107 		}
       
   108 	delete iTimer;
       
   109 	delete iIMessage;
       
   110 	delete iClippedMessage;
       
   111 	delete iBgContext;
       
   112 	iTextLayouts.Close();
       
   113 	}
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CIMCVNewMsgFadeControl::SizeChanged()
       
   117 // called by framework when the view size is changed
       
   118 //  
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CIMCVNewMsgFadeControl::SizeChanged()
       
   122     {
       
   123 	TRect myNavePaneRect;
       
   124 	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, 
       
   125 	        myNavePaneRect );
       
   126 
       
   127 	
       
   128     myNavePaneRect.Move( -myNavePaneRect.iTl.iX, -myNavePaneRect.iTl.iY );
       
   129 
       
   130 	iTextLayouts.Reset();
       
   131 	for ( TInt i( 0 ); i < KLafCount; i++ )
       
   132 	    {
       
   133 		TAknLayoutText text;
       
   134 		TAknTextLineLayout textLayout;
       
   135 		textLayout= iLayoutInfo->IM_navi_pane_texts_Line_1( i, 0 );
       
   136 
       
   137 		text.LayoutText( myNavePaneRect, textLayout );
       
   138 		iTextLayouts.Append( text );
       
   139 		
       
   140 	    }	
       
   141 	TAknWindowLineLayout navipaneLayout = 
       
   142 	                        AknLayout::Status_pane_elements_Line_1();
       
   143 	iNavipaneRect.LayoutRect( myNavePaneRect, navipaneLayout );
       
   144 	
       
   145 	UpdateClippedMessage();
       
   146 	}
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CIMCVNewMsgFadeControl::CountComponentControls() const
       
   150 //
       
   151 //  
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 TInt CIMCVNewMsgFadeControl::CountComponentControls() const
       
   155     {
       
   156     return 0;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CIMCVNewMsgFadeControl::ComponentControl(TInt aIndex) const
       
   161 //
       
   162 //  
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 CCoeControl* CIMCVNewMsgFadeControl::ComponentControl(TInt /*aIndex*/) const
       
   166     {
       
   167 	return NULL;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // CIMCVNewMsgFadeControl::Draw(const TRect& aRect) const
       
   172 // 
       
   173 //  
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CIMCVNewMsgFadeControl::Draw( const TRect& /*aRect*/ ) const
       
   177 	{
       
   178 	CWindowGc& gc = SystemGc();
       
   179 	
       
   180 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   181 	MAknsControlContext* cc = iBgContext;
       
   182 	if ( !AknsDrawUtils::Background( skin, cc, gc, iViewRect ) )
       
   183 		{
       
   184 		gc.Clear( iViewRect );
       
   185 		}		
       
   186     iTextLayouts[iColorIndex].DrawText( gc, *iClippedMessage );
       
   187 	
       
   188 	}
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CIMCVNewMsgFadeControl::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
       
   192 //  
       
   193 //  
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CIMCVNewMsgFadeControl::HandleControlEventL(CCoeControl* /*aControl*/,
       
   197         TCoeEvent /*aEventType*/)
       
   198     {
       
   199     }
       
   200 
       
   201 // ---------------------------------------------------------
       
   202 // CIMCVNewMsgFadeControl::FadeText()
       
   203 // (other items were commented in a header).
       
   204 // ---------------------------------------------------------
       
   205 //
       
   206 TInt CIMCVNewMsgFadeControl::FadeText( TAny* aAnyPtr )
       
   207 	{
       
   208 	if ( !aAnyPtr ) 
       
   209 		{
       
   210 		return EFalse;
       
   211 		}
       
   212 	
       
   213 	CIMCVNewMsgFadeControl* view = reinterpret_cast< CIMCVNewMsgFadeControl* >( aAnyPtr );
       
   214 	
       
   215 	if( view->iColorIndex < KLafCount - 1 ) 
       
   216 		{
       
   217 		view->iColorIndex++;
       
   218 		view->ReportChange();
       
   219 		if ( view->iColorIndex == KDelayColorIndex )
       
   220 			{
       
   221 			//Delayed color is displayed 4 seconds
       
   222 			view->StartTicker( KIndicationDelay );
       
   223 			}	
       
   224 		return ETrue;
       
   225 		}
       
   226 	
       
   227 	view->iColorIndex = 0;
       
   228 	view->Stop();
       
   229 	TInt count( view->iObserverArray->Count() );
       
   230 	for( TInt i(0); i < count; ++i )
       
   231 		{
       
   232         MIMCVNewMsgFadeControlObserver* obs = view->iObserverArray->At( i );
       
   233 		if( obs ) 
       
   234 			{
       
   235 			obs->NotifyWhenCompleted();
       
   236 			}
       
   237 		}		
       
   238 	return EFalse;	
       
   239 	}
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CIMCVNewMsgFadeControl::Start()
       
   243 // (other items were commented in a header).
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 void CIMCVNewMsgFadeControl::Start()
       
   247 	{
       
   248 	TRect myNavePaneRect;
       
   249 	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ENaviPane, 
       
   250 	    myNavePaneRect );
       
   251 	myNavePaneRect.Move( -myNavePaneRect.iTl.iX, -myNavePaneRect.iTl.iY );
       
   252 	
       
   253 	TAknWindowLineLayout navipanelayout = AknLayout::navi_pane( 0 );
       
   254 	AknLayoutUtils::LayoutControl( this, myNavePaneRect, navipanelayout );
       
   255 	
       
   256 	iTimerTick = 10000; //KTimerInterval;
       
   257 	
       
   258 	TInt count( iObserverArray->Count() );
       
   259 	for( TInt i(0); i < count; ++i )
       
   260 		{
       
   261         MIMCVNewMsgFadeControlObserver* obs = iObserverArray->At( i );
       
   262 		if( obs ) 
       
   263 			{
       
   264 			obs->NotifyWhenStarted();
       
   265 			}
       
   266 		}
       
   267 		
       
   268 	if ( !IsActivated() ) 
       
   269 		{
       
   270 		TRAPD( err, ActivateL() );
       
   271         if( err != KErrNone )
       
   272             {
       
   273             CActiveScheduler::Current()->Error( err );
       
   274             }
       
   275 		}
       
   276 	
       
   277 	if ( !IsVisible() ) 
       
   278 		{
       
   279 		MakeVisible( ETrue );
       
   280 		}	
       
   281 	
       
   282 	StartTicker( 0 );
       
   283 	}
       
   284 
       
   285 // ---------------------------------------------------------
       
   286 // CIMCVNewMsgFadeControl::StartTicker()
       
   287 // (other items were commented in a header).
       
   288 // ---------------------------------------------------------
       
   289 //
       
   290 void CIMCVNewMsgFadeControl::StartTicker( 
       
   291             const TTimeIntervalMicroSeconds32 aDelayInternal )
       
   292 	{
       
   293 	if ( iTimerState == ETimerActivated ) 
       
   294 		{
       
   295 		iTimer->Cancel();
       
   296 		iTimerState = ETimerStopped;
       
   297 		}
       
   298 	TCallBack cb( FadeText, this );
       
   299 	iTimer->Start( aDelayInternal, iTimerTick, cb );
       
   300 	iTimerState = ETimerActivated;
       
   301 	}
       
   302 
       
   303 // ---------------------------------------------------------
       
   304 // CIMCVNewMsgFadeControl::Stop()
       
   305 // (other items were commented in a header).
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 void CIMCVNewMsgFadeControl::Stop()
       
   309 	{	
       
   310 	if ( IsVisible() ) 
       
   311 		{
       
   312 		MakeVisible( EFalse );
       
   313 		}	
       
   314 	StopTicker();
       
   315 	}
       
   316 
       
   317 // ---------------------------------------------------------
       
   318 // CIMCVNewMsgFadeControl::AddObserver()
       
   319 // (other items were commented in a header).
       
   320 // ---------------------------------------------------------
       
   321 //
       
   322 void CIMCVNewMsgFadeControl::AddObserver( MIMCVNewMsgFadeControlObserver* aObserver )
       
   323 	{	
       
   324 	TRAPD( err, iObserverArray->AppendL( aObserver ) );
       
   325 	HandleError( err );
       
   326 	}	
       
   327 
       
   328 // ---------------------------------------------------------
       
   329 // CIMCVNewMsgFadeControl::SetMessage()
       
   330 // (other items were commented in a header).
       
   331 // ---------------------------------------------------------
       
   332 //
       
   333 void CIMCVNewMsgFadeControl::SetMessage( TDesC& aMsg )
       
   334 	{
       
   335     HBufC* temp = NULL;
       
   336     TRAPD( err, temp = HBufC::NewL( aMsg.Length() + 1 ) );
       
   337 	HandleError( err );
       
   338     if( temp )
       
   339         {
       
   340         delete iIMessage;
       
   341 	    iIMessage = temp;
       
   342 	    TPtr imMsgPtr( iIMessage->Des() );
       
   343 		imMsgPtr.Append( TChar( KAIMMessageIcon ) ); 
       
   344 		imMsgPtr.Append( aMsg );
       
   345 
       
   346         UpdateClippedMessage();
       
   347         }
       
   348 	}
       
   349 
       
   350 // ---------------------------------------------------------
       
   351 // CIMCVNewMsgFadeControl::Message()
       
   352 // (other items were commented in a header).
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TPtrC CIMCVNewMsgFadeControl::Message() const
       
   356 	{
       
   357 	return *iIMessage;
       
   358 	}
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CIMCVNewMsgFadeControl::IsActive()
       
   362 // (other items were commented in a header).
       
   363 // ---------------------------------------------------------
       
   364 //
       
   365 TBool CIMCVNewMsgFadeControl::IsActive()
       
   366 	{
       
   367 	if ( iTimer ) 
       
   368 		{
       
   369 		return iTimer->IsActive();
       
   370 		}
       
   371 	return EFalse;
       
   372 	}
       
   373 
       
   374 // ---------------------------------------------------------
       
   375 // CIMCVNewMsgFadeControl::Reset()
       
   376 // (other items were commented in a header).
       
   377 // ---------------------------------------------------------
       
   378 //
       
   379 void CIMCVNewMsgFadeControl::Reset()
       
   380 	{
       
   381 	if ( iIMessage ) 
       
   382 		{
       
   383 		TPtr mesgPtr( iIMessage->Des() );
       
   384 		mesgPtr.Zero();
       
   385 		}
       
   386     
       
   387     if( iClippedMessage )
       
   388         {
       
   389         TPtr clipPtr( iClippedMessage->Des() );
       
   390         clipPtr.Zero();
       
   391 		DrawNow();
       
   392         }
       
   393 	}
       
   394 
       
   395 // ---------------------------------------------------------
       
   396 // CIMCVNewMsgFadeControl::StopTicker()
       
   397 // (other items were commented in a header).
       
   398 // ---------------------------------------------------------
       
   399 //
       
   400 void CIMCVNewMsgFadeControl::StopTicker()
       
   401 	{
       
   402 	if ( iTimerState == ETimerActivated ) 
       
   403 		{
       
   404 		iTimer->Cancel();
       
   405 		iTimerState = ETimerStopped;
       
   406 		}	
       
   407 	}
       
   408 
       
   409 // ---------------------------------------------------------
       
   410 // CIMCVNewMsgFadeControl::ReportChange()
       
   411 // (other items were commented in a header).
       
   412 // ---------------------------------------------------------
       
   413 //
       
   414 void CIMCVNewMsgFadeControl::ReportChange()
       
   415 	{
       
   416 	TRAPD( err, ReportEventL( MCoeControlObserver::EEventStateChanged ) );
       
   417 	HandleError( err );
       
   418 	}
       
   419 
       
   420 // ---------------------------------------------------------
       
   421 // CIMCVNewMsgFadeControl::HandleError
       
   422 // (other items were commented in a header).
       
   423 // ---------------------------------------------------------
       
   424 //
       
   425 void CIMCVNewMsgFadeControl::HandleError( TInt aError )
       
   426     {
       
   427     
       
   428     if( (aError < KErrNone) )
       
   429         {
       
   430         // propagate system errors to current active scheduler,
       
   431         // it should show a note
       
   432         CActiveScheduler::Current()->Error( aError );
       
   433         }
       
   434 
       
   435     // imps errors are ignored at the moment as we don't have any
       
   436     // notes specified for them
       
   437     }
       
   438 
       
   439 // ---------------------------------------------------------
       
   440 // CIMCVNewMsgFadeControl::UpdateClippedMessage
       
   441 // (other items were commented in a header).
       
   442 // ---------------------------------------------------------
       
   443 //
       
   444 void CIMCVNewMsgFadeControl::UpdateClippedMessage()
       
   445     {
       
   446     HBufC* temp = NULL;
       
   447     TRAPD( err, temp = iIMessage->AllocL() );
       
   448     if ( err )
       
   449         {
       
   450         delete temp;
       
   451         HandleError( err );
       
   452         }
       
   453     
       
   454     if ( temp )
       
   455         {
       
   456         delete iClippedMessage;
       
   457         iClippedMessage = temp;
       
   458         TPtr clipPtr( iClippedMessage->Des() );
       
   459         
       
   460         const CFont* font = iTextLayouts[iColorIndex].Font();
       
   461         AknTextUtils::ClipToFit( clipPtr, *font, Rect().Width() );
       
   462         }
       
   463     }
       
   464 
       
   465 // End of file