mulwidgets/mulcoverflowwidget/src/mulcoverflowcontrol.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Widget Control Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //  Include Files
       
    20 
       
    21 // Class Headers
       
    22 #include "mulcoverflowcontrol.h"
       
    23 
       
    24 #include <AknUtils.h>
       
    25 // Alf Headers
       
    26 #include <alf/alfenv.h>
       
    27 // for dosetimage func
       
    28 #include <alf/alfimageloaderutil.h>
       
    29 #include <alf/alfbitmapprovider.h>
       
    30 #include <alf/alfdisplay.h>
       
    31 #include <alf/alfresourcepool.h> //for resource pooling
       
    32 #include <alf/alfwidgetenvextension.h> //for resource pooling
       
    33 #include <alf/alfutil.h>
       
    34 #include <alf/alfimagevisual.h>
       
    35 
       
    36 // Mul Headers
       
    37 #include <mul/mulevent.h>
       
    38 #include <mul/imulsliderwidget.h>
       
    39 
       
    40 
       
    41 // Gesture Helper 
       
    42 #include <gesturehelper.h>
       
    43 
       
    44 // Local Headers
       
    45 #include "mulbaseelement.h"
       
    46 #include "mulcoverflowao.h"
       
    47 #include "mulcoverflowtemplate.h" 
       
    48 #include "mulcoverflowwidget.h"
       
    49 #include "mulleave.h" //for leaving function
       
    50 #include "mullog.h" //for logs
       
    51 #include "mulassert.h"
       
    52 #include "imulmodelaccessor.h"
       
    53 
       
    54 //Gesture Helper
       
    55 using namespace GestureHelper;
       
    56 
       
    57 namespace Alf
       
    58 	{
       
    59 		
       
    60 struct TMulCoverFlowControlImpl
       
    61 	{
       
    62 	TMulCoverFlowControlImpl()
       
    63 		{
       
    64 		mHighlightIndex = -1;
       
    65 		mScreenWidth = 0;
       
    66 		mScreenHeight = 0;
       
    67 		mGestureSpeed  = 0;
       
    68 		mCoverFlow2DTemplate = NULL;
       
    69 		mIsWidgetVisible = true; //by default widget is visible .
       
    70 		mBaseElement = NULL;
       
    71 		mFastScroll = false;
       
    72 		mNumVisibleItem = 0;
       
    73 		mDefaultTextureId = -1;	
       
    74 		mBounceInProgress = false;
       
    75 		mDirectionChanged = false;
       
    76 		mDontBounce = false;
       
    77 		mNumberOfRepeatEvents = 0;
       
    78 		mIsMirrored = false;
       
    79 		}
       
    80 			
       
    81     /// @bug critical:avanhata:4/7/2008 you should never cache a property that is a property of
       
    82     /// another class. The model exists to own this type of information. I gave this review comment
       
    83     /// as "critical", since it is exactly these cached member variables that will 
       
    84     /// yield most of bugs and complexity. Refactor it away.
       
    85 	int mHighlightIndex;
       
    86     
       
    87 	int mScreenWidth;
       
    88     int	mScreenHeight;
       
    89 	bool mIsWidgetVisible;
       
    90 	MulBaseElement* mBaseElement;	
       
    91 	auto_ptr<MulCoverFlowTemplate> mCoverFlow2DTemplate;  // 2D cover flow template //owns 
       
    92 	TReal32 mGestureSpeed;
       
    93 	bool mFastScroll; 		// Flag to indicate wheher in fast scroll mode or not
       
    94 	int mNumVisibleItem;
       
    95 	int mDefaultTextureId;
       
    96 	bool mBounceInProgress;
       
    97 	int mReferencePoint;
       
    98 	bool mDirectionChanged;
       
    99 	int mCurrGestureDir; 
       
   100 	bool mDontBounce;
       
   101 	int mNumberOfRepeatEvents;
       
   102 	bool mIsLandscape;
       
   103 	bool mIsMirrored;
       
   104 	};
       
   105 	
       
   106 // ---------------------------------------------------------------------------
       
   107 // MulCoverFlowControl
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 MulCoverFlowControl::MulCoverFlowControl(CAlfEnv& aEnv	)
       
   111 	{
       
   112 	//Call the base class method
       
   113 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::MulCoverFlowControl");
       
   114 	CAlfWidgetControl::construct ( aEnv);
       
   115 
       
   116 	mData.reset( new (EMM)TMulCoverFlowControlImpl );
       
   117     
       
   118 	mFeedback = MTouchFeedback::Instance(); 
       
   119 	
       
   120     if (AknLayoutUtils::LayoutMirrored())
       
   121     	{
       
   122     	mData->mIsMirrored = true;
       
   123     	}
       
   124     else
       
   125 		{
       
   126 		mData->mIsMirrored = false;
       
   127 		}
       
   128 		
       
   129 	mData->mIsLandscape = IsLandscape();
       
   130 
       
   131     THROW_IF_LEAVES
       
   132 		(
       
   133         /// @bug critical:avanhata:30/9/2008 this is a symbian code section. don't call throwing osn code here. 
       
   134         /// Throwing within a TRAP is at best undefined
       
   135 		mCoverFlowAo.reset( new(EMM) MulCoverFlowAo( *this ) );
       
   136 
       
   137 		mHelper.reset(GestureHelper::CGestureHelper::NewL( *this ));
       
   138 		mHelper->InitAlfredPointerCaptureL( aEnv, aEnv.PrimaryDisplay(), KGroupId ); 
       
   139 		mHelper->SetHoldingEnabled( EFalse );
       
   140 		)
       
   141 	}
       
   142 		
       
   143 // ---------------------------------------------------------------------------
       
   144 // ~MulCoverFlowControl
       
   145 // ---------------------------------------------------------------------------
       
   146 //	
       
   147 MulCoverFlowControl::~MulCoverFlowControl()
       
   148 	{
       
   149 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::~MulCoverFlowControl");
       
   150 
       
   151     if( ModelAccessor() != NULL )
       
   152         {
       
   153         ModelAccessor()->RemoveModelObserver(this);
       
   154         }
       
   155 
       
   156 	DestroySlider();      
       
   157 
       
   158 	}
       
   159     
       
   160 // ---------------------------------------------------------------------------
       
   161 // makeInterface
       
   162 // ---------------------------------------------------------------------------
       
   163 //          
       
   164 IAlfInterfaceBase* MulCoverFlowControl::makeInterface( const IfId& aType )
       
   165     {
       
   166     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::makeInterface");
       
   167     UString param(aType.mImplementationId);
       
   168     return CAlfWidgetControl::makeInterface( aType );
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // ResetShowWidgetFlag
       
   173 // ---------------------------------------------------------------------------
       
   174 //  
       
   175 void MulCoverFlowControl::ResetShowWidgetFlag( bool aNewResetValue )
       
   176     {
       
   177     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ResetShowWidgetFlag");
       
   178     mData->mIsWidgetVisible = aNewResetValue;
       
   179     if( aNewResetValue)
       
   180         {
       
   181     	mHelper->AddObserver(this);
       
   182         } 
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // Template2D
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 MulCoverFlowTemplate*  MulCoverFlowControl::Template2D()
       
   190 	{
       
   191 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::Template2D");
       
   192 	return mData->mCoverFlow2DTemplate.get();
       
   193 	}
       
   194 		
       
   195 // ---------------------------------------------------------------------------
       
   196 // IsFastScrollMode
       
   197 // ---------------------------------------------------------------------------
       
   198 //	
       
   199 bool MulCoverFlowControl::IsFastScrollMode()
       
   200 	{
       
   201 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::IsFastScrollMode");
       
   202 	return mData->mFastScroll;
       
   203 	}	
       
   204 	
       
   205 
       
   206 //-----------------------Event Handling API's -------------------------------
       
   207 // ---------------------------------------------------------------------------
       
   208 // handleEvent
       
   209 // ---------------------------------------------------------------------------
       
   210 //	
       
   211 AlfEventStatus MulCoverFlowControl::handleEvent(const TAlfEvent& aEvent)
       
   212 	{
       
   213     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::handleEvent");
       
   214     if( aEvent.IsCustomEvent() )
       
   215         {
       
   216         return HandleCustomEvent( aEvent );
       
   217         } 
       
   218     else if( aEvent.IsKeyEvent() && mData->mIsWidgetVisible )
       
   219         {
       
   220         if(TotalModelCount() <= KMinNumItemForFastScroll || 
       
   221         	aEvent.KeyEvent().iRepeats == 0 )
       
   222 	        {
       
   223 	        return HandleKeyEvent( aEvent );	
       
   224 	        }
       
   225 	    else
       
   226 	    	{	        
       
   227 		    return HandleRepeatKeyEvent( aEvent );	
       
   228 	    	}
       
   229         }      
       
   230  	else if( aEvent.IsPointerEvent() && mData->mIsWidgetVisible )
       
   231         {                 
       
   232 		MUL_LOG_INFO("MUL::MulCoverFlowControl: handleEvent ::pointer event");
       
   233 		//commented as gives warning in armv5 
       
   234 		//THROW_IF_LEAVES
       
   235 		     //(
       
   236 		     TBool result = mHelper->OfferEventL(aEvent);
       
   237 		     MUL_LOG_INFO1("MUL::MulCoverFlowControl: handleEvent::result %d ",result);
       
   238 		     return result ? EEventConsumed :EEventNotHandled ;            
       
   239 		    // )            
       
   240         }    
       
   241    	return EEventNotHandled;
       
   242     }
       
   243 // ---------------------------------------------------------------------------
       
   244 // HandleCustomEvent
       
   245 // ---------------------------------------------------------------------------
       
   246 //  
       
   247 AlfEventStatus MulCoverFlowControl::HandleCustomEvent( const TAlfEvent& aEvent )
       
   248     {
       
   249     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleCustomEvent");
       
   250     AlfEventStatus eventConsumed = EEventNotHandled;
       
   251     switch( aEvent.CustomParameter() )
       
   252         {
       
   253         case ECustomEventBounceBack:
       
   254             {
       
   255             MUL_LOG_INFO("MUL::MulCF:Handle custom event Compensate Bounce");
       
   256             mFeedback->InstantFeedback(ETouchFeedbackBasic); 
       
   257             mData->mBaseElement->StopDoodling(/*3*KBounceTime*/500);
       
   258             if ((TotalModelCount() > 1 && mData->mNumVisibleItem == 1) || 
       
   259             	(TotalModelCount() > 2))
       
   260 	            {
       
   261 	            Env().Send(TAlfCustomEventCommand(ECustomEventScroll, this),500/*3*KBounceTime*/ + 30); 	
       
   262 	            }
       
   263 	        else
       
   264 	        	{
       
   265 	        	//start marquee in case of text is visible.
       
   266 	        	if(mData->mBaseElement->IsTextVisibile())
       
   267 	        	    {
       
   268 	        	    //start marquee after 1 sec (after doodle completed)
       
   269 	        	    Env().Send(TAlfCustomEventCommand(
       
   270 	        	            ECustomEventMarqueeStart, this),500/*3*KBounceTime*/ + KMarqueeTime1000);
       
   271 	        	    }
       
   272 	        	// if only one item is there then no need to scroll.
       
   273 	        	mData->mBounceInProgress = false;	
       
   274 	        	}
       
   275             eventConsumed = EEventConsumed;
       
   276             break;
       
   277             } 
       
   278         case ECustomEventScroll:
       
   279             {
       
   280             MUL_LOG_INFO("MUL::MulCF:Handle custom event Compensate Bounce");
       
   281             Env().Send(TAlfCustomEventCommand(ECustomEventBounceCompleted,this),600); 
       
   282             
       
   283             if (mData->mHighlightIndex == 0)
       
   284 	            {
       
   285 	            DoSetFocusIndex(TotalModelCount() -1,/*4*KBounceTime*/800);	
       
   286 	            }
       
   287 	        else
       
   288 	        	{
       
   289 	        	DoSetFocusIndex(0,800);	
       
   290 	        	}
       
   291 	        SetSliderTickPosition();
       
   292             eventConsumed = EEventConsumed;
       
   293             break;
       
   294             } 
       
   295         case ECustomEventBounceCompleted:
       
   296         	{
       
   297         	mData->mBounceInProgress = false;
       
   298 			eventConsumed = EEventConsumed;
       
   299             break;        		
       
   300         	}
       
   301         case ECustomEventMarqueeStart:
       
   302         	{
       
   303         	mData->mBaseElement->StartMarquee(mulvisualitem::KMulTitle);
       
   304 			eventConsumed = EEventConsumed;
       
   305 			break;
       
   306         	}
       
   307         case ECustomEventTitleMarqueeFinished:
       
   308             {
       
   309             mData->mBaseElement->StopMarquee(mulvisualitem::KMulTitle);
       
   310             eventConsumed = EEventConsumed;
       
   311             break;
       
   312             }
       
   313         case ECustomEventDetailMarqueeStart:
       
   314             {
       
   315             mData->mBaseElement->StartMarquee(mulvisualitem::KMulDetail);
       
   316             eventConsumed = EEventConsumed;
       
   317             break;
       
   318             }
       
   319         case ECustomEventMarqueeFinished:
       
   320            {
       
   321            mData->mBaseElement->StopMarquee(mulvisualitem::KMulDetail);
       
   322     	   eventConsumed = EEventConsumed;
       
   323     	   break;
       
   324            }
       
   325         default: break;
       
   326         }  
       
   327     return eventConsumed;
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // HandleKeyEvent
       
   332 // ---------------------------------------------------------------------------
       
   333 //  
       
   334 AlfEventStatus MulCoverFlowControl::HandleKeyEvent( const TAlfEvent& aEvent )
       
   335     {
       
   336     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleKeyEvent");
       
   337     AlfEventStatus eventConsumed = EEventNotHandled;
       
   338    	if( aEvent.Code() == EEventKey)
       
   339      	{
       
   340      	switch ( aEvent.KeyEvent().iCode )
       
   341 	        {
       
   342 	        case EKeyEnter:
       
   343             // Event when selection key is pressed .( key event )
       
   344 	        case EKeyDeviceA:
       
   345 	        case EKeyDevice3: 
       
   346 	            {
       
   347 	            if(aEvent.KeyEvent().iRepeats == 0)
       
   348 		            {
       
   349 		            if(TotalModelCount() <= 0 && mData->mBaseElement->IsEmptyText() )           
       
   350 			            {
       
   351 			            SetSelection(mData->mHighlightIndex);
       
   352 			            eventConsumed = EEventConsumed;
       
   353 			            }
       
   354 			        else if( TotalModelCount() > 0 )
       
   355 			        	{
       
   356 			        	SetSelection(mData->mHighlightIndex);
       
   357 			            eventConsumed = EEventConsumed;	
       
   358 			        	}
       
   359 			        break;	
       
   360 		            }
       
   361 	            }
       
   362 	        case EKeyRightArrow:
       
   363 	            {
       
   364 	            // Send event to inform that the Right Key is pressed
       
   365 				if (mData->mIsMirrored)
       
   366 					{
       
   367 					HandleNavigationEvent ( EEventScrollLeft );
       
   368 					}
       
   369 				else
       
   370 					{
       
   371 					HandleNavigationEvent ( EEventScrollRight );
       
   372 					}
       
   373 	            eventConsumed = EEventConsumed;
       
   374 	            break;
       
   375 	            }
       
   376 	        
       
   377 	        case EKeyLeftArrow:
       
   378 	            {
       
   379 	            // Send event to inform that the Left Key is pressed
       
   380 				if (mData->mIsMirrored)
       
   381 					{
       
   382 					HandleNavigationEvent ( EEventScrollRight );
       
   383 					}
       
   384 				else
       
   385 					{
       
   386 					HandleNavigationEvent ( EEventScrollLeft );
       
   387 					}
       
   388 	            eventConsumed = EEventConsumed;
       
   389 	            break;
       
   390 	            }
       
   391 	        case EKeyBackspace:
       
   392 	        //case EKeyDelete:
       
   393 	            {
       
   394 	            CAlfWidgetControl::processEvent( TAlfEvent( ETypeRemove,mData->mHighlightIndex));
       
   395 	            eventConsumed = EEventConsumed;
       
   396 	            break;
       
   397 	            }
       
   398 	        default:
       
   399 	            {
       
   400 	            break;
       
   401 	            }
       
   402 	     	}
       
   403     	}
       
   404         
       
   405    else if(aEvent.Code() == EEventKeyUp) 
       
   406 	   {
       
   407 	   mData->mNumberOfRepeatEvents = 0;
       
   408 	   switch ( aEvent.KeyEvent().iScanCode )
       
   409 	        {
       
   410 			case EStdKeyRightArrow:
       
   411 			case EStdKeyLeftArrow:
       
   412 				{
       
   413 				if(mData->mFastScroll)
       
   414 					{
       
   415 					HandleEnhancedStop();
       
   416 			   		eventConsumed = EEventConsumed;	
       
   417 					}				
       
   418 		   		break;
       
   419 				}
       
   420 			default:
       
   421 				{
       
   422 				break;	
       
   423 				}
       
   424 	        }
       
   425 	   }         
       
   426      
       
   427     return eventConsumed;
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------------------------	
       
   431 // HandleRepeatKeyEvent
       
   432 // ---------------------------------------------------------------------------
       
   433 //
       
   434 AlfEventStatus MulCoverFlowControl::HandleRepeatKeyEvent( const TAlfEvent& aEvent )
       
   435     {
       
   436     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleHoldGestureEvents");
       
   437 
       
   438 	AlfEventStatus eventConsumed = EEventNotHandled;
       
   439    	if( aEvent.Code() == EEventKey)
       
   440      	{
       
   441      	switch ( aEvent.KeyEvent().iCode )
       
   442 	        {
       
   443 	        case EKeyRightArrow:
       
   444 	            {
       
   445 				if (mData->mIsMirrored)
       
   446 					{
       
   447 					HandleFastScrollWithKeyEvents(1);
       
   448 					}
       
   449 				else
       
   450 					{
       
   451 					HandleFastScrollWithKeyEvents(-1);
       
   452 					}
       
   453 	            eventConsumed = EEventConsumed;
       
   454 	            break;
       
   455 	            }
       
   456 	        
       
   457 	        case EKeyLeftArrow:
       
   458 	            {
       
   459 				if (mData->mIsMirrored)
       
   460 					{
       
   461 					HandleFastScrollWithKeyEvents(-1);
       
   462 					}
       
   463 				else
       
   464 					{
       
   465 					HandleFastScrollWithKeyEvents(1);
       
   466 					}
       
   467 	            eventConsumed = EEventConsumed;
       
   468 	            break;
       
   469 	            }
       
   470 	        default:
       
   471 	            {
       
   472 	            break;
       
   473 	            }
       
   474 	     	}
       
   475     	}
       
   476 	return eventConsumed;
       
   477     }
       
   478 
       
   479 // ---------------------------------------------------------------------------	
       
   480 // HandleFastScrollWithKeyEvents
       
   481 // ---------------------------------------------------------------------------
       
   482 //
       
   483 void MulCoverFlowControl::HandleFastScrollWithKeyEvents(int aDirection)
       
   484     {
       
   485     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleFastScrollWithKeyEvents");
       
   486     mData->mNumberOfRepeatEvents++;
       
   487     if(mData->mNumberOfRepeatEvents == 1 )
       
   488         {
       
   489         CAlfWidgetControl::processEvent( TAlfEvent( ETypeFastScroll,EScrollStart ));
       
   490 		mData->mFastScroll = true;
       
   491 		mCoverFlowAo->StartMoving(1, aDirection,true,200);	
       
   492         }
       
   493     else if(mData->mNumberOfRepeatEvents == KNumberOfRepeatsForMediumSpeed && mData->mFastScroll )
       
   494         {
       
   495         mCoverFlowAo->StartMoving(1, aDirection,true,150);	
       
   496         }
       
   497     else if(mData->mNumberOfRepeatEvents == KNumberOfRepeatsForFastSpeed && mData->mFastScroll )
       
   498         {
       
   499         mCoverFlowAo->StartMoving(1, aDirection,true,100);	
       
   500         }
       
   501     }      
       
   502     
       
   503 // ---------------------------------------------------------------------------
       
   504 // HandleNavigationEvent
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void MulCoverFlowControl::HandleNavigationEvent( int aEvent )
       
   508 	{
       
   509 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleNavigationEvent");
       
   510 	
       
   511 	// During bounce ignore all the events
       
   512 	if (mData->mBounceInProgress)
       
   513 		{
       
   514 		return;	
       
   515 		}
       
   516 		
       
   517 	int highlightIndex = mData->mHighlightIndex;
       
   518 	int totalcount = TotalModelCount();
       
   519 	if(totalcount <= 0 && highlightIndex == -1 )
       
   520 		{
       
   521 		return;
       
   522 		}
       
   523 	//stop marquee if the navigation is happening.
       
   524 	if(mData->mBaseElement->IsTextVisibile())
       
   525 	    {
       
   526 	    mData->mBaseElement->StopMarquee(mulvisualitem::KMulTitle);
       
   527 	    mData->mBaseElement->StopMarquee(mulvisualitem::KMulDetail);
       
   528 	    }
       
   529 	Env().CancelCustomCommands(this);
       
   530 	
       
   531 	//Update the highlight index
       
   532 	switch( aEvent )
       
   533 		{
       
   534 		case EEventScrollRight: 
       
   535 			{
       
   536 			// boundary check
       
   537 			if( highlightIndex == totalcount - 1 )
       
   538 				{
       
   539 				if( !mData->mBounceInProgress && !mData->mDontBounce)
       
   540 					{
       
   541 					mData->mBounceInProgress = true;
       
   542 					mData->mBaseElement->StartBounce(KBounceRight);
       
   543 					}
       
   544 				else
       
   545 					{
       
   546 					mData->mBounceInProgress = false;
       
   547 					mData->mDontBounce = false;
       
   548 					highlightIndex = 0;	
       
   549 					}
       
   550 				}
       
   551 			else 
       
   552 				{
       
   553 				highlightIndex++;
       
   554 				}
       
   555 				
       
   556 			mData->mBaseElement->SetScrollDir(EItemScrollRight);	
       
   557 			}
       
   558 		break;
       
   559 		
       
   560 		case EEventScrollLeft:
       
   561 			{
       
   562 			//boundary check
       
   563 			if( highlightIndex == 0 )
       
   564 				{
       
   565 				if( !mData->mBounceInProgress && !mData->mDontBounce)
       
   566 					{
       
   567 					mData->mBounceInProgress = true;
       
   568 				    mData->mBaseElement->StartBounce(KBounceLeft);
       
   569 					}
       
   570 				else
       
   571 					{
       
   572 					mData->mBounceInProgress = false;
       
   573 					mData->mDontBounce = false;
       
   574 					highlightIndex = totalcount - 1;	
       
   575 					}
       
   576 				}
       
   577 			else
       
   578 				{
       
   579 				highlightIndex--;
       
   580 				}	
       
   581 			}
       
   582 		mData->mBaseElement->SetScrollDir(EItemScrollLeft);	
       
   583 		break;
       
   584 		}
       
   585 		
       
   586 	// to handle bounce checks
       
   587 	if( !mData->mBounceInProgress )	
       
   588 		{ 
       
   589 		DoSetFocusIndex( highlightIndex ); 	
       
   590 		SetSliderTickPosition();
       
   591 		}	   
       
   592 	}
       
   593 // ---------------------------------------------------------------------------
       
   594 // SendEventToBaseElement
       
   595 // ---------------------------------------------------------------------------
       
   596 //
       
   597 void MulCoverFlowControl::SendEventToBaseElement( const TAlfEvent& aEvent )
       
   598     {
       
   599     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SendEventToBaseElement");
       
   600     mData->mBaseElement->offerEvent(  *this, aEvent);
       
   601     }
       
   602 
       
   603 //----------------------------Highlight and Selection API's -----------------
       
   604 
       
   605 // ---------------------------------------------------------------------------
       
   606 // SetHighlightIndex
       
   607 // ---------------------------------------------------------------------------
       
   608 //          
       
   609 void MulCoverFlowControl::SetHighlightIndex( int aIndex, bool aUpdateSlider)
       
   610     {
       
   611     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetHighlightIndex");
       
   612     // Throw Out of Bound Exception if index is negative
       
   613    __MUL_ASSERT (aIndex > -1 && aIndex < TotalModelCount(), KOutOfBound); 
       
   614     //set the highlight in model
       
   615     if(aIndex > mData->mHighlightIndex)
       
   616         {
       
   617         mData->mBaseElement->SetScrollDir(EItemScrollRight);	    
       
   618         }
       
   619     else
       
   620         {
       
   621         mData->mBaseElement->SetScrollDir(EItemScrollLeft);    
       
   622         }    
       
   623     DoSetFocusIndex( aIndex );  
       
   624     if (aUpdateSlider)
       
   625         {
       
   626         SetSliderTickPosition();	
       
   627         }
       
   628     }   
       
   629 // ---------------------------------------------------------------------------
       
   630 // DoSetFocusIndex
       
   631 // ---------------------------------------------------------------------------
       
   632 //  
       
   633 void MulCoverFlowControl::DoSetFocusIndex( int aNewIndex, int aAnimationTime )
       
   634     {
       
   635     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::DoSetFocusIndex");
       
   636     
       
   637     if(aNewIndex < 0 )
       
   638 	    {
       
   639 	    return;	
       
   640 	    }
       
   641 
       
   642     int oldindex = mData->mHighlightIndex;
       
   643     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
   644     if(accessor)
       
   645 	    {
       
   646 	    if( oldindex == aNewIndex )
       
   647 	        {
       
   648             accessor->SetHighlight( aNewIndex ); 
       
   649             
       
   650             // When one item case to cancel the drag effect
       
   651             mData->mBaseElement->StopDoodling(200);            
       
   652 	        return;
       
   653 	        }
       
   654 	    // handling of cancelling bounce in 2 items case
       
   655 	    if(TotalModelCount() == 2)
       
   656 		    {
       
   657 		    if((mData->mBaseElement->ScrollDir() == EItemScrollRight && aNewIndex == 1 && oldindex == 2)||
       
   658 		    	(mData->mBaseElement->ScrollDir() == EItemScrollLeft && aNewIndex == 2 && oldindex == 1))
       
   659 			    {
       
   660 			    mData->mBaseElement->StopDoodling(200); 
       
   661 			    return;	
       
   662 			    }
       
   663 		    }
       
   664 	 
       
   665 	    accessor->SetHighlight( aNewIndex ); 
       
   666 	    accessor->ScrollWindow( WindowTop(aNewIndex) );  
       
   667 
       
   668 	    // Set the new focused item 
       
   669 	    mData->mHighlightIndex = aNewIndex; 
       
   670 	     
       
   671 	   // Throw Out of Bound Exception if index is negative
       
   672 	   __MUL_ASSERT( mData->mHighlightIndex > -1 , KOutOfBound ); 
       
   673 	   mData->mBaseElement->offerEvent(*this,TAlfEvent(ETypeHighlight,aAnimationTime));
       
   674 	    
       
   675 	    if( mData->mIsWidgetVisible )
       
   676 	        {
       
   677 	        // If the widget is in hidden mode no event will be sent to the application/client
       
   678 	        CAlfWidgetControl::processEvent( TAlfEvent( ETypeHighlight,mData->mHighlightIndex));
       
   679 	        }
       
   680 	    }
       
   681     }
       
   682 
       
   683 // ----------------------------------------------------------------------------
       
   684 // SetSelection
       
   685 // ----------------------------------------------------------------------------
       
   686 //
       
   687 void MulCoverFlowControl::SetSelection(int aHighlight)    
       
   688     {
       
   689     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetSelection");
       
   690     CAlfWidgetControl::processEvent ( TAlfEvent ( ETypeSelect, aHighlight));
       
   691     }
       
   692 
       
   693 // ---------------------------------------------------------------------------
       
   694 // HighlightIndex
       
   695 // ---------------------------------------------------------------------------
       
   696 //  
       
   697 int MulCoverFlowControl::HighlightIndex()
       
   698     {
       
   699     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HighlightIndex");
       
   700     return mData->mHighlightIndex; 
       
   701     }  
       
   702       
       
   703 // ---------------------------------------------------------------------------
       
   704 // SetSliderTickPosition
       
   705 // ---------------------------------------------------------------------------
       
   706 //
       
   707 void MulCoverFlowControl::SetSliderTickPosition( )
       
   708     {
       
   709     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetSliderTickPosition");
       
   710     if (mData->mCoverFlow2DTemplate->IsSliderVisible())
       
   711 	    {
       
   712 	    IMulSliderModel* mulSliderModel = GetSliderModel();	
       
   713 	    if( mulSliderModel && mData->mHighlightIndex >= KInitialvalueZero )
       
   714 	        {
       
   715 	        mulSliderModel->SetPrimaryValue( mData->mHighlightIndex );   
       
   716 	        }
       
   717 	    }
       
   718     }
       
   719   
       
   720 //----------------------Model Change Related API's----------------------------
       
   721 // ----------------------------------------------------------------------------
       
   722 // ModelStateChanged
       
   723 // ----------------------------------------------------------------------------
       
   724 //
       
   725 void MulCoverFlowControl::ModelStateChanged( TMulChangedState aState, IMulVariantType& aData  )
       
   726     {  
       
   727     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ModelStateChanged");
       
   728     switch( aState )
       
   729         {
       
   730         case EItemUpdated:
       
   731         	{
       
   732         	int index = aData.integer();
       
   733         	if(TotalModelCount() < 2*mData->mNumVisibleItem+1)
       
   734 	        	{
       
   735 	        	HandleLessItemsUpdate(index);	
       
   736 	        	}
       
   737         	else
       
   738 	        	{
       
   739 	        	int relativeIndex = 0;
       
   740 	        	if (IsIndexInVisibleWindow(index, relativeIndex))
       
   741 		        	{
       
   742 		        	UpdateCoverflowItem(index,relativeIndex);
       
   743 		        	mData->mBaseElement->CancelRotationOnUpdate(relativeIndex);
       
   744 		        	}	
       
   745 	        	}
       
   746         	break;	
       
   747         	} 
       
   748        case EHighlightChanged:
       
   749             {
       
   750             if (mData->mHighlightIndex != aData.integer())
       
   751 	            {
       
   752 	            mData->mHighlightIndex = aData.integer();
       
   753 	            IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
   754                 if( mData->mHighlightIndex == 0 )
       
   755                 	{
       
   756                 	mData->mBaseElement->ShowEmptyText(false);
       
   757 				    }
       
   758                 if( mData->mHighlightIndex >= 0)
       
   759                     {
       
   760                     // the same things have to be done for highlight>0 and highlight = 0
       
   761                     // the only diff is at highlight 0 dont show empty text 
       
   762                     accessor->ScrollWindow(WindowTop(mData->mHighlightIndex));
       
   763 	           		mData->mBaseElement->UpdateVisuals();
       
   764 	           		mData->mBaseElement->SetCounterText();	
       
   765 	           		SetSliderTickPosition();
       
   766 				    }           		
       
   767                 else
       
   768                     {
       
   769                     // remove the visualisation and hide counter. 
       
   770                     mData->mBaseElement->RecycleIconVisuals();  
       
   771 	                mData->mBaseElement->ShowEmptyText( true );
       
   772                     }				
       
   773 	            }
       
   774             break;
       
   775             }
       
   776         case EItemsInserted:
       
   777         case EItemsRemoved:
       
   778         	{
       
   779         	HandleModelCountChange();
       
   780         	break;
       
   781         	}
       
   782         
       
   783 		}                                  
       
   784     }
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // HandleLessItemsUpdate 
       
   788 // ---------------------------------------------------------------------------
       
   789 //    
       
   790 void MulCoverFlowControl::HandleLessItemsUpdate(int aIndex)
       
   791 	{
       
   792 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleLessItemsUpdate");
       
   793 	if(aIndex == mData->mHighlightIndex)
       
   794 		{
       
   795 		UpdateCoverflowItem(aIndex,mData->mNumVisibleItem);
       
   796 		if(mData->mNumVisibleItem != 1 && TotalModelCount() == 3)	
       
   797 			{
       
   798 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem + 3);
       
   799 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem - 3);	
       
   800 			}
       
   801 		}
       
   802 	else 
       
   803 		{
       
   804 		// fulscreen tempalte and 2d in portrait
       
   805 		if(mData->mNumVisibleItem == 1)	
       
   806 			{
       
   807 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem+1);
       
   808 			UpdateCoverflowItem(aIndex,mData->mNumVisibleItem-1);				
       
   809 			}
       
   810 		else
       
   811 			{
       
   812 			// 2d template landscape mode
       
   813 			if(TotalModelCount() == 2)
       
   814 				{
       
   815 				UpdateCoverflowItem(aIndex,mData->mNumVisibleItem+(aIndex - mData->mHighlightIndex));	
       
   816 				}
       
   817 			else
       
   818 				{
       
   819 				int relativeIndex = (aIndex - mData->mHighlightIndex) + mData->mNumVisibleItem;
       
   820 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
       
   821 					{
       
   822 					UpdateCoverflowItem(aIndex,relativeIndex);						
       
   823 					}
       
   824 				relativeIndex = relativeIndex + TotalModelCount();
       
   825 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
       
   826 					{
       
   827 					UpdateCoverflowItem(aIndex,relativeIndex);	
       
   828 					}
       
   829 								
       
   830 				relativeIndex = mData->mNumVisibleItem - (TotalModelCount() - aIndex + mData->mHighlightIndex);
       
   831 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
       
   832 					{
       
   833 					UpdateCoverflowItem(aIndex,relativeIndex);					
       
   834 					}
       
   835 				relativeIndex = relativeIndex - TotalModelCount();
       
   836 				if(relativeIndex >= 0 && relativeIndex < 2*mData->mNumVisibleItem+1)
       
   837 					{
       
   838 					UpdateCoverflowItem(aIndex,relativeIndex);	
       
   839 					}					
       
   840 				}
       
   841 			}
       
   842 		}
       
   843 	}
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // IsIndexInVisibleWindow 
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 bool MulCoverFlowControl::IsIndexInVisibleWindow(const int aIndex, int& aRelativeIndex)
       
   850     {
       
   851     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::IsIndexInVisibleWindow");
       
   852 
       
   853 	int totalVisual = TotalModelCount();
       
   854     int noOfVisuals = mData->mNumVisibleItem; 
       
   855     int highlightRelativeIndex = mData->mNumVisibleItem;
       
   856     	
       
   857 	int leftIndex = mData->mHighlightIndex - noOfVisuals;
       
   858 	int rightIndex = mData->mHighlightIndex + noOfVisuals;
       
   859     
       
   860  	if (leftIndex >= 0)
       
   861 	 	{
       
   862 	 	if ((aIndex <= mData->mHighlightIndex) && (aIndex >= leftIndex))
       
   863 		 	{
       
   864 		 	aRelativeIndex = highlightRelativeIndex - (mData->mHighlightIndex - aIndex);
       
   865 		 	return true;	
       
   866 		 	}
       
   867 	 	}
       
   868 	else
       
   869 		{
       
   870 		if (aIndex <= mData->mHighlightIndex)
       
   871 			{
       
   872 			aRelativeIndex = highlightRelativeIndex - (mData->mHighlightIndex - aIndex);
       
   873 			return true;	
       
   874 			}
       
   875 		else
       
   876 			{
       
   877 			leftIndex = totalVisual + leftIndex ;
       
   878 			if (aIndex >= leftIndex)
       
   879 				{
       
   880 				aRelativeIndex = highlightRelativeIndex - noOfVisuals +	(aIndex - leftIndex);
       
   881 				return true;
       
   882 				}
       
   883 			}	
       
   884 		}
       
   885  
       
   886  	if (rightIndex < totalVisual)
       
   887 	 	{
       
   888 	 	if ((aIndex >= mData->mHighlightIndex) && (aIndex <= rightIndex))
       
   889 		 	{
       
   890 		 	aRelativeIndex = highlightRelativeIndex + (aIndex - mData->mHighlightIndex);
       
   891 		 	return true;	
       
   892 		 	}
       
   893 	 	}
       
   894 	else
       
   895 		{
       
   896 		if (aIndex >= mData->mHighlightIndex)
       
   897 			{
       
   898 			aRelativeIndex = highlightRelativeIndex + (aIndex - mData->mHighlightIndex);
       
   899 			return true;	
       
   900 			}
       
   901 		rightIndex = rightIndex - totalVisual;
       
   902 		if (aIndex <= rightIndex)
       
   903 			{
       
   904 			aRelativeIndex = highlightRelativeIndex + noOfVisuals - (rightIndex - aIndex);
       
   905 			return true;	
       
   906 			}
       
   907 		}
       
   908  
       
   909 	return false;
       
   910     }
       
   911         
       
   912         
       
   913 // ---------------------------------------------------------------------------
       
   914 // RelativeToAbsolute
       
   915 // ---------------------------------------------------------------------------
       
   916 //
       
   917 int MulCoverFlowControl::RelativeToAbsolute(const int aRelativeIndex)
       
   918     {
       
   919     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::RelativeToAbsolute");
       
   920     int highlightRelativeIndex = mData->mNumVisibleItem;
       
   921     int absolute = -1;
       
   922     int totalVisuals = TotalModelCount();
       
   923     if(totalVisuals <= 0)
       
   924 	    {
       
   925 	    // absolute index is always -1, so no need of any calculations
       
   926 	    }
       
   927     else if(totalVisuals < 2*mData->mNumVisibleItem + 1)
       
   928 	    {
       
   929 	    if(aRelativeIndex == highlightRelativeIndex)
       
   930 			{
       
   931 			absolute = 	mData->mHighlightIndex;
       
   932 			}
       
   933 		else
       
   934 			{
       
   935 			if(mData->mNumVisibleItem == 1)
       
   936 				{
       
   937 				if (totalVisuals == 1)
       
   938 				    {
       
   939 				    absolute = -1;
       
   940 				    }
       
   941 				else if(totalVisuals == 2)
       
   942 					{
       
   943 					absolute = mData->mHighlightIndex + 1;
       
   944 					absolute = absolute >= totalVisuals ? 0 : absolute;
       
   945 					}
       
   946 				}
       
   947 			else
       
   948 				{
       
   949 				if (totalVisuals == 1)
       
   950 				    {
       
   951 				    absolute = -1;
       
   952 				    }
       
   953 				else if(totalVisuals == 2)
       
   954 					{
       
   955 					absolute = mData->mHighlightIndex + (aRelativeIndex - highlightRelativeIndex);
       
   956 					absolute = absolute >= totalVisuals ? -1 : absolute;
       
   957 					}
       
   958 				else // totalvisuals > 3
       
   959 					{
       
   960 					if(aRelativeIndex - highlightRelativeIndex > 0)
       
   961 						{
       
   962 						absolute = mData->mHighlightIndex + aRelativeIndex - highlightRelativeIndex;	
       
   963 						}
       
   964 					else
       
   965 						{
       
   966 						absolute = mData->mHighlightIndex + aRelativeIndex - highlightRelativeIndex
       
   967 							+ TotalModelCount();	
       
   968 						}					
       
   969 					absolute = absolute >= totalVisuals ? absolute - totalVisuals : absolute;
       
   970 					}
       
   971 				}
       
   972 			}
       
   973 	    }
       
   974 	else
       
   975 		{
       
   976 		if(aRelativeIndex == highlightRelativeIndex)
       
   977 			{
       
   978 			absolute = 	mData->mHighlightIndex;
       
   979 			}
       
   980 		else if (aRelativeIndex > highlightRelativeIndex)
       
   981 		    {
       
   982 		    absolute = mData->mHighlightIndex + (aRelativeIndex - highlightRelativeIndex);
       
   983 		    absolute = absolute >= totalVisuals ? (absolute - totalVisuals) : absolute;	
       
   984 		    }
       
   985 		else
       
   986 			{
       
   987 		    absolute = mData->mHighlightIndex - (highlightRelativeIndex - aRelativeIndex);
       
   988 		    absolute = absolute <0 ? (totalVisuals + absolute) : absolute;
       
   989 		    absolute = absolute > totalVisuals - 1 ? -1 : absolute;	    
       
   990 			}	
       
   991 		}    
       
   992     return absolute;
       
   993     }
       
   994 
       
   995         
       
   996 // ---------------------------------------------------------------------------
       
   997 // TotalModelCount
       
   998 // ---------------------------------------------------------------------------
       
   999 //  
       
  1000 int MulCoverFlowControl::TotalModelCount()
       
  1001     {
       
  1002     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::TotalModelCount");
       
  1003     
       
  1004     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
  1005     if(accessor)
       
  1006         {
       
  1007         return accessor->CurrentItemCount();
       
  1008         }
       
  1009 	return -1;    
       
  1010     }
       
  1011 
       
  1012 // ---------------------------------------------------------------------------
       
  1013 // HandleModelCountChange
       
  1014 // ---------------------------------------------------------------------------
       
  1015 //
       
  1016 void MulCoverFlowControl::HandleModelCountChange()
       
  1017 	{
       
  1018 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleModelCountChange");
       
  1019     IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
  1020     if(accessor)
       
  1021 	    {
       
  1022 	    if(TotalModelCount() < (2*mData->mNumVisibleItem + 1))
       
  1023 	    	{
       
  1024 	    	mData->mBaseElement->UpdateVisuals();
       
  1025 	    	}
       
  1026 		mData->mBaseElement->UpdateSliderTick( TotalModelCount() );
       
  1027 		mData->mBaseElement->SetCounterText();
       
  1028 	    }
       
  1029 	}
       
  1030 
       
  1031 // ---------------------------------------------------------------------------
       
  1032 // modelAccessor
       
  1033 // ---------------------------------------------------------------------------
       
  1034 //  
       
  1035 IMulModelAccessor* MulCoverFlowControl::ModelAccessor()
       
  1036     {
       
  1037     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ModelAccessor");
       
  1038     if(widget())
       
  1039     	{
       
  1040     	return static_cast<IMulModelAccessor*>(widget()->model());
       
  1041     	}    
       
  1042     return NULL;    
       
  1043     }
       
  1044 
       
  1045 // ---------------------------------------------------------------------------
       
  1046 // ModelChanged
       
  1047 // ---------------------------------------------------------------------------
       
  1048 //
       
  1049 void MulCoverFlowControl::ModelChanged( IMulModelAccessor* aAccessor )
       
  1050 	{
       
  1051 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ModelChanged");
       
  1052 	Env().CancelCustomCommands(this);
       
  1053 	// update the highlight index as well as the no of item.
       
  1054 	mData->mHighlightIndex = aAccessor->Highlight();
       
  1055 
       
  1056 	CAlfLayout* main = (CAlfLayout*) mData->mBaseElement->findVisual( KMainLayoutIndex );
       
  1057 	int width = main->Size().Target().AsSize().iWidth;
       
  1058 	int height = main->Size().Target().AsSize().iHeight;
       
  1059 
       
  1060 	if( width == 0 && height == 0 )
       
  1061 		{
       
  1062 		return;
       
  1063 		}
       
  1064 	else
       
  1065 		{
       
  1066 		// @todo check if we are setting a new model with the same old template, 
       
  1067 		// then should we call CreateTemplateElement
       
  1068 		mData->mScreenWidth = width;
       
  1069     	mData->mScreenHeight = height;
       
  1070 		CreateTemplateElement(aAccessor->Template());
       
  1071 		mData->mBaseElement->CreateAndInitializeVisuals(); 
       
  1072 		aAccessor->SetVisibleWindow( 2 * mData->mCoverFlow2DTemplate->MaxVisibleCount() + 1
       
  1073 		            ,WindowTop(mData->mHighlightIndex));
       
  1074 		// For setting or clearing empty text if depending on the new modle count
       
  1075 		SendEventToBaseElement( TAlfEvent( EEventWidgetInitialized ) );
       
  1076 		}
       
  1077 	}
       
  1078 		
       
  1079 
       
  1080 
       
  1081 //-----------------Template Element Creation API's --------------------------
       
  1082 
       
  1083 // ---------------------------------------------------------------------------
       
  1084 // CreateTemplateElement
       
  1085 // ---------------------------------------------------------------------------
       
  1086 //
       
  1087 void MulCoverFlowControl::CreateTemplateElement( mulwidget::TLogicalTemplate aTemplateName)
       
  1088 	{
       
  1089 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::CreateTemplateElement");
       
  1090 	if (aTemplateName == mulwidget::KTemplate1)
       
  1091 		{
       
  1092 		mData->mCoverFlow2DTemplate.reset( new(EMM) MulCoverFlowTemplate1(*this, *mData->mBaseElement));
       
  1093 		}
       
  1094 	else if(aTemplateName == mulwidget::KTemplate4)
       
  1095 		{
       
  1096 		mData->mCoverFlow2DTemplate.reset( new(EMM) MulCoverFlowTemplate4(*this, *mData->mBaseElement));
       
  1097 		}
       
  1098 	else
       
  1099 		{
       
  1100 		// Invalid template
       
  1101 		return;
       
  1102 		}
       
  1103     mData->mCoverFlow2DTemplate->CreateVisualisation(IsLandscape());
       
  1104 	// set holding mode to gesture helper.
       
  1105 	SetHoldingEnabled(); 
       
  1106 	}
       
  1107 
       
  1108 
       
  1109     
       
  1110 //--------------Orientation Change Related API's----------------------------- 
       
  1111 // ---------------------------------------------------------------------------
       
  1112 // VisualLayoutUpdated
       
  1113 // ---------------------------------------------------------------------------
       
  1114 //		
       
  1115 void MulCoverFlowControl::VisualLayoutUpdated (CAlfVisual& aVisual)
       
  1116     {
       
  1117     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::VisualLayoutUpdated");
       
  1118         
       
  1119     TSize topLayoutSize = aVisual.Size().Target().AsSize(); ;
       
  1120     int height = topLayoutSize.iHeight;
       
  1121     int width  = topLayoutSize.iWidth;
       
  1122     
       
  1123  	// to avoid unnecessary visual layout updated calls .
       
  1124  	// in order to check if the orientation has changed really or not this is done .
       
  1125     if( mData->mScreenWidth == width && height == mData->mScreenHeight  )
       
  1126         {
       
  1127         return;
       
  1128         }
       
  1129     
       
  1130     mData->mScreenWidth = width;
       
  1131     mData->mScreenHeight = height;
       
  1132         
       
  1133 	
       
  1134 	IMulModelAccessor* accessor = ModelAccessor();
       
  1135     if(IsLandscape() == mData->mIsLandscape)
       
  1136         {  
       
  1137         if(accessor)
       
  1138             {
       
  1139             CreateTemplateElement(accessor->Template());
       
  1140             mData->mBaseElement->CreateAndInitializeVisuals(); 
       
  1141             accessor->SetVisibleWindow( 2 * mData->mCoverFlow2DTemplate->MaxVisibleCount() + 1
       
  1142                         ,WindowTop(mData->mHighlightIndex));
       
  1143             // For setting or clearing empty text if depending on the new modle count
       
  1144             SendEventToBaseElement( TAlfEvent( EEventWidgetInitialized ) );
       
  1145             }
       
  1146         else
       
  1147         	{
       
  1148         	// For null model
       
  1149 		    // reset the coverflow 2d template to NULL
       
  1150 		    mData->mCoverFlow2DTemplate.reset(NULL);
       
  1151         	}
       
  1152         }
       
  1153     else
       
  1154         { 
       
  1155         mData->mIsLandscape = IsLandscape();
       
  1156     	
       
  1157     	if(!accessor)
       
  1158     		{
       
  1159     		mData->mBaseElement->SetDefaultSize(TSize(mData->mScreenWidth,mData->mScreenHeight));
       
  1160     		return; 
       
  1161     		}
       
  1162           
       
  1163         mData->mBaseElement->OrientationChange();
       
  1164     	// enable or disable hold events depending on whether ECF enabled
       
  1165     	SetHoldingEnabled();
       
  1166         }
       
  1167         
       
  1168     }
       
  1169 	    
       
  1170 // ---------------------------------------------------------------------------
       
  1171 // RecycleVisuals
       
  1172 // ---------------------------------------------------------------------------
       
  1173 //   
       
  1174 void MulCoverFlowControl::RecycleVisuals()
       
  1175     {
       
  1176     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::RecycleVisuals");
       
  1177     // reset the coverflow 2d template to NULL
       
  1178     mData->mCoverFlow2DTemplate.reset(NULL);
       
  1179     
       
  1180     if(mData->mBaseElement)
       
  1181         {
       
  1182         mData->mBaseElement->RecycleIconVisuals();
       
  1183         mData->mHighlightIndex = -1;
       
  1184         }
       
  1185     }  
       
  1186 
       
  1187 //--------------------------- Gesture ----------------------------------------
       
  1188 
       
  1189 // ---------------------------------------------------------------------------
       
  1190 // SetHoldingEnabled
       
  1191 // ---------------------------------------------------------------------------
       
  1192 // 
       
  1193 void MulCoverFlowControl::SetHoldingEnabled()
       
  1194 	{
       
  1195 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetHoldingEnabled");
       
  1196 
       
  1197 	mHelper->SetHoldingEnabled(EnhancedModeCondition());	
       
  1198 	}
       
  1199 
       
  1200 // ---------------------------------------------------------------------------
       
  1201 // SetDoubleTapEnabled
       
  1202 // ---------------------------------------------------------------------------
       
  1203 // 
       
  1204 void MulCoverFlowControl::SetDoubleTapEnabled( bool aValue)
       
  1205 	{
       
  1206 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetDoubleTapEnabled");
       
  1207 
       
  1208 	mHelper->SetDoubleTapEnabled( aValue );	
       
  1209 	}
       
  1210 	
       
  1211 // ---------------------------------------------------------------------------
       
  1212 // HandleGestureL
       
  1213 // ---------------------------------------------------------------------------
       
  1214 //    
       
  1215 void MulCoverFlowControl::HandleGestureL( const MGestureEvent& aEvent )
       
  1216     {
       
  1217     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleGestureL");
       
  1218 	if(aEvent.IsHolding())
       
  1219 		{
       
  1220 	    HandleHoldGestureEvents(aEvent);	
       
  1221 		}
       
  1222 	else
       
  1223 		{
       
  1224 		HandleNormalGestureEvents(aEvent);
       
  1225 		}
       
  1226     }
       
  1227 
       
  1228 // ---------------------------------------------------------------------------
       
  1229 // HandleNormalGestureEvents
       
  1230 // ---------------------------------------------------------------------------
       
  1231 //
       
  1232 void MulCoverFlowControl::HandleNormalGestureEvents( const MGestureEvent& aEvent )
       
  1233     {
       
  1234     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleNormalGestureEvents");
       
  1235     
       
  1236     switch ( aEvent.Code(MGestureEvent::EAxisHorizontal) )
       
  1237         {
       
  1238         case EGestureStart:
       
  1239             {
       
  1240             SendFeedbackOnTouchDown(aEvent);
       
  1241             }
       
  1242             break;
       
  1243 		case EGestureDrag: // fall through
       
  1244 			{		
       
  1245 			MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureDrag");
       
  1246 			if(	aEvent.CurrentPos().iX > mData->mScreenWidth )
       
  1247 				{
       
  1248 				return;
       
  1249 				}
       
  1250 
       
  1251 			if(TotalModelCount() > 0 )
       
  1252 				{
       
  1253 				// if ui is on send event to applications	
       
  1254 				if( mData->mCoverFlow2DTemplate->IsUiOnOffFlagEnabled() && 
       
  1255 	    			(mData->mBaseElement->IsUiOnMode()) )
       
  1256 					{
       
  1257 					CAlfWidgetControl::processEvent( TAlfEvent( ETypeSwitchUiStateOnDrag ));	
       
  1258 					}
       
  1259 					
       
  1260 				if (mData->mBounceInProgress && TotalModelCount() > 2)
       
  1261 					{
       
  1262 					mData->mBounceInProgress = false;
       
  1263 					Env().CancelCustomCommands(this);
       
  1264 					// bounce canceled once .dont bounce again for the next swipe.
       
  1265 					mData->mDontBounce = true;	
       
  1266 					}
       
  1267 
       
  1268 				int distance =  aEvent.Distance().iX ;
       
  1269 				mData->mCurrGestureDir = distance;//CovertDistAnceToDirection(distance);				
       
  1270 				if (mData->mIsMirrored)
       
  1271 					{
       
  1272 					distance = -distance;
       
  1273 					}
       
  1274 				mData->mReferencePoint = aEvent.CurrentPos().iX - 10; //pointerDownPos + distanceTravelled/2;	
       
  1275 
       
  1276 				mData->mBaseElement->StartDoodling(distance);
       
  1277 				}
       
  1278 			break;
       
  1279 			}
       
  1280         
       
  1281         case EGestureTap:
       
  1282         	{
       
  1283         	MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureTap ");
       
  1284             HandleSingleTap(aEvent); 
       
  1285             break;   
       
  1286         	}
       
  1287         
       
  1288         case EGestureDoubleTap:
       
  1289            {
       
  1290            MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureDoubleTap ");
       
  1291            if(TotalModelCount() <= 0 )
       
  1292 	    		{
       
  1293 	    		//find out whether event should be sent on double tap or not 
       
  1294 	    		// in case of empty model and the feedback too.
       
  1295 	    		break; 
       
  1296 	    		}
       
  1297             MulDoubleTapData doubleTapData;
       
  1298             // Finding the visual which has been hit .
       
  1299             CAlfVisual* hitVisual = aEvent.Visual();           
       
  1300             if(hitVisual && (hitVisual->Tag() == KCoverflowIndicator) ) 
       
  1301                 {
       
  1302                 doubleTapData.mTapVisualIndex = mData->mHighlightIndex ;
       
  1303                 }
       
  1304             else
       
  1305                 {
       
  1306                 int hitVisualIndex = GetHitVisualIndex( hitVisual );           
       
  1307                 if( hitVisualIndex == -1 )
       
  1308                     {
       
  1309                     break; 
       
  1310                     }
       
  1311                 doubleTapData.mTapVisualIndex = hitVisualIndex;
       
  1312                 }
       
  1313             doubleTapData.mDoubleTapPoint = aEvent.CurrentPos();
       
  1314             
       
  1315             mFeedback->InstantFeedback(ETouchFeedbackBasic); 
       
  1316             CAlfWidgetControl::processEvent ( TAlfEvent ( ETypeDoubleTap,
       
  1317                     uint(&doubleTapData)));
       
  1318             break;  
       
  1319             }
       
  1320                            	
       
  1321         case EGestureUnknown :
       
  1322         	{
       
  1323         	MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureUnknown");
       
  1324         	if(TotalModelCount() > 0 )
       
  1325 	    		{
       
  1326 		    	// this will revert to the original position if gesture get cancelled
       
  1327 	        	// with some animation time.
       
  1328 	        	// @TODO animation time should be same as set by application.
       
  1329 	        	mData->mBaseElement->StopDoodling(200);
       
  1330 	    		}
       
  1331             break;
       
  1332         	}
       
  1333                     
       
  1334         case EGestureSwipeLeft:
       
  1335         	{
       
  1336         	MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureSwipeLeft");
       
  1337         	if(TotalModelCount() > 0 )
       
  1338 	    		{
       
  1339 	    		// do the calculations for changing teh higlight left or right depnding on last direction
       
  1340 			    // and the total direction moved.
       
  1341 			    int finalSwipeDirection = mData->mBaseElement->FinalSwipeDirection(
       
  1342 			    	TotalSwipeDistance(aEvent),EEventScrollRight);
       
  1343 
       
  1344 	    		HandleSwipe(finalSwipeDirection);
       
  1345 	    		}
       
  1346             break;
       
  1347         	}
       
  1348               
       
  1349         case EGestureSwipeRight:
       
  1350             {
       
  1351             MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureSwipeRight");
       
  1352             if(TotalModelCount() > 0 )
       
  1353 	    		{
       
  1354 			    int finalSwipeDirection = mData->mBaseElement->FinalSwipeDirection(
       
  1355 			    	TotalSwipeDistance(aEvent),EEventScrollLeft);
       
  1356 	    		
       
  1357 	    		HandleSwipe(finalSwipeDirection);
       
  1358 	    		}
       
  1359             break;
       
  1360             }
       
  1361         case EGestureMultiTouchStart:
       
  1362            {
       
  1363             MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureMultiTouchStart");
       
  1364             mData->mBaseElement->StopDoodling(0);
       
  1365             break;
       
  1366           }
       
  1367         case EGestureMultiTouchReleased:
       
  1368             MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureMultiTouchReleased");
       
  1369             break;
       
  1370         case EGesturePinch:
       
  1371             MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGesturePinch");
       
  1372             CAlfWidgetControl::processEvent ( TAlfEvent ( ETypePinch,aEvent.PinchPercent()));
       
  1373             break;
       
  1374         case EGestureReleased:
       
  1375         	{
       
  1376         	 MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleNormalGestureEvents EGestureReleased");
       
  1377         	 mFeedback->InstantFeedback(ETouchFeedbackBasic);
       
  1378          	 break;
       
  1379 			}
       
  1380         default:
       
  1381             break;
       
  1382         } // end of switch
       
  1383     }
       
  1384 
       
  1385 // ---------------------------------------------------------------------------
       
  1386 // TotalSwipeDistance
       
  1387 // ---------------------------------------------------------------------------
       
  1388 //
       
  1389 int MulCoverFlowControl::TotalSwipeDistance( const GestureHelper::MGestureEvent& aEvent )
       
  1390 	{
       
  1391 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::TotalSwipeDistance");
       
  1392 	if(	aEvent.CurrentPos().iX > mData->mScreenWidth )
       
  1393 		{
       
  1394 		return aEvent.Distance().iX - (aEvent.CurrentPos().iX - mData->mScreenWidth);
       
  1395 		}
       
  1396 	return 	aEvent.Distance().iX;
       
  1397 	}
       
  1398 
       
  1399 // ---------------------------------------------------------------------------
       
  1400 // GetHitVisualIndex
       
  1401 // ---------------------------------------------------------------------------
       
  1402 //
       
  1403 int MulCoverFlowControl::GetHitVisualIndex( CAlfVisual* aHitVisual )
       
  1404     {
       
  1405     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::GetHitVisualIndex");
       
  1406     int visualIndex  = -1;
       
  1407         
       
  1408     if(!aHitVisual)
       
  1409 	    {
       
  1410 	    // no visual found
       
  1411 	    return -1;
       
  1412 	    }
       
  1413      #ifdef _DEBUG
       
  1414         const TDesC8& buffer = aHitVisual->Tag();
       
  1415     #endif
       
  1416 
       
  1417     if ((aHitVisual->Tag() != KCoverflowIcon))
       
  1418         {
       
  1419         visualIndex = -1;
       
  1420         }
       
  1421     else
       
  1422         {
       
  1423         if(mData->mNumVisibleItem > 1)
       
  1424 	        {
       
  1425     		CAlfLayout& iconFlow =mData->mBaseElement->FlowLayout( KIconFlowLayoutIndex );
       
  1426     		CAlfVisual* imgVisual = NULL;
       
  1427 	        for(int i=2; i<=4;i++)	
       
  1428 		        {
       
  1429 		        imgVisual = iconFlow.Visual(i).FindTag(KCoverflowIcon);
       
  1430 		        if (imgVisual == aHitVisual)
       
  1431 			        {
       
  1432 			        visualIndex = RelativeToAbsolute(i);	
       
  1433 			        break;
       
  1434 			        }
       
  1435 		        }
       
  1436 	        }
       
  1437 	    else
       
  1438 	    	{
       
  1439 	    	visualIndex = mData->mHighlightIndex;
       
  1440 	    	}
       
  1441         }
       
  1442     return visualIndex;
       
  1443     }
       
  1444 
       
  1445 
       
  1446 // ---------------------------------------------------------------------------
       
  1447 // HandleSingleTap
       
  1448 // ---------------------------------------------------------------------------
       
  1449 //  
       
  1450 void MulCoverFlowControl::HandleSingleTap(const MGestureEvent& aEvent) 
       
  1451     {
       
  1452     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleSingleTap");
       
  1453 
       
  1454     if(TotalModelCount() <= 0 )
       
  1455         {
       
  1456         // in case of empty model and null model only when the empty text is set 
       
  1457         // then only the selection event should be sent to the applications.
       
  1458         if( mData->mBaseElement->IsEmptyText() )
       
  1459             {
       
  1460             SetSelection(-1);	
       
  1461             }
       
  1462         // In case of null model and empty model if the empty text is not set then no need to calculate
       
  1463         //the hit visual index . Doest serve any purpose.
       
  1464         }
       
  1465     else
       
  1466         {
       
  1467         // Finding the visual which has been hit .
       
  1468         CAlfVisual* hitVisual = aEvent.Visual();        	
       
  1469         if(hitVisual && (hitVisual->Tag() == KCoverflowIndicator) ) 
       
  1470             {
       
  1471             CAlfWidgetControl::processEvent( TAlfEvent( EVideoIconSelect ));
       
  1472             return;
       
  1473             }
       
  1474         int hitVisualIndex = GetHitVisualIndex( hitVisual );
       
  1475         if( hitVisualIndex > -1 )
       
  1476             {
       
  1477             if( hitVisualIndex == mData->mHighlightIndex )
       
  1478                 {
       
  1479                 SetSelection(mData->mHighlightIndex );
       
  1480                 }
       
  1481             else
       
  1482                 {
       
  1483                 //set the highlight in model
       
  1484 			    if(TotalModelCount() > 2 && hitVisualIndex == TotalModelCount()-1 
       
  1485 			    	&& mData->mHighlightIndex == 0)
       
  1486 				    {
       
  1487 				    HandleNavigationEvent ( EEventScrollLeft );	
       
  1488 				    }
       
  1489 				else if(TotalModelCount() > 2 && mData->mHighlightIndex == TotalModelCount()-1 
       
  1490 					&& hitVisualIndex == 0)
       
  1491 					{
       
  1492 					HandleNavigationEvent ( EEventScrollRight );	
       
  1493 					}
       
  1494 			    else if(hitVisualIndex > mData->mHighlightIndex)
       
  1495 			        {
       
  1496 			        HandleNavigationEvent ( EEventScrollRight );	    
       
  1497 			        }
       
  1498 			    else
       
  1499 			        {
       
  1500 			        HandleNavigationEvent ( EEventScrollLeft );   
       
  1501 			        }
       
  1502                 }
       
  1503             }	
       
  1504         }   
       
  1505     }
       
  1506      
       
  1507 // ---------------------------------------------------------------------------
       
  1508 // SendFeedbackOnTouchDown
       
  1509 // ---------------------------------------------------------------------------
       
  1510 //  
       
  1511 void MulCoverFlowControl::SendFeedbackOnTouchDown(const MGestureEvent& aEvent)
       
  1512     {
       
  1513     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SendFeedbackOnTouchDown");
       
  1514 
       
  1515     IMulModelAccessor* modelaccessor = ModelAccessor();
       
  1516     if(!modelaccessor ||  modelaccessor->CurrentItemCount() == 0)
       
  1517         {
       
  1518         return;   
       
  1519         }
       
  1520     CAlfVisual* hitVisual = aEvent.Visual();
       
  1521     if((hitVisual && hitVisual->Tag() == KCoverflowIcon) || (mData->mCoverFlow2DTemplate->IsUiOnOffFlagEnabled() )) 
       
  1522         {
       
  1523         mFeedback->InstantFeedback(ETouchFeedbackBasic);  
       
  1524         }    
       
  1525     }
       
  1526 // ---------------------------------------------------------------------------
       
  1527 // HandleSwipe
       
  1528 // Handle the swipe events (swipe left and swipe right) provided by the gesture helper.
       
  1529 // Also handles the extreme doodling case (it may happen that in doodling you can move two
       
  1530 // or three highlight before doing a pointer up) but gesture only gives us a swipe left and 
       
  1531 // swipe right event. so we have to decide the no of highlight movement to do while getting 
       
  1532 // left or right event. 
       
  1533 // Also for 2 or 3 highlight movement if the 1st or 2nd highlight movement is the cycling case
       
  1534 // then we have to cancel the bounce as its already happend because of swipe. But the bounce
       
  1535 // will happen if the final highlight change is a cyclic case.
       
  1536 // ---------------------------------------------------------------------------
       
  1537 //  
       
  1538 void MulCoverFlowControl::HandleSwipe(int aEvent)
       
  1539     {
       
  1540     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleSwipe");
       
  1541     int event;
       
  1542     if(aEvent == EItemScrollLeft)
       
  1543 	    {
       
  1544 		if (mData->mIsMirrored)
       
  1545 			{
       
  1546 		    event = EEventScrollRight;
       
  1547 			}
       
  1548 		else
       
  1549 			{
       
  1550 			event = EEventScrollLeft;
       
  1551 			}
       
  1552 	    }
       
  1553 	else if(aEvent == EItemScrollRight)
       
  1554 		{
       
  1555 		if (mData->mIsMirrored)
       
  1556 			{
       
  1557 		    event = EEventScrollLeft;
       
  1558 			}
       
  1559 		else
       
  1560 			{
       
  1561 			event = EEventScrollRight;
       
  1562 			}
       
  1563 		}
       
  1564 	else
       
  1565 		{
       
  1566 		mData->mBaseElement->StopDoodling(200);	
       
  1567 		return;
       
  1568 		}
       
  1569 		
       
  1570 	if(mData->mBaseElement->NumberOfSwipes() == EDoubleSwipe || mData->mBaseElement->NumberOfSwipes() == ETripleSwipe)
       
  1571 		{
       
  1572 		// done to avoid undesirable ui behaviour when we move the pointer little back.
       
  1573 		// check if it can be done in another way.
       
  1574 		CAlfEnv& env = Env();
       
  1575 		TAlfRefreshMode oldRefreshMode = env.RefreshMode();
       
  1576 		env.SetRefreshMode(EAlfRefreshModeManual);
       
  1577 		if(mData->mBaseElement->NumberOfSwipes() == ETripleSwipe)
       
  1578 			{
       
  1579 			HandleNavigationEvent( event );	
       
  1580 			}
       
  1581 		HandleNavigationEvent( event );
       
  1582 		env.SetRefreshMode(oldRefreshMode);			
       
  1583 		}
       
  1584 	// Commented feedback for swipe event
       
  1585 	//mFeedback->InstantFeedback(ETouchFeedbackBasic);
       
  1586 	HandleNavigationEvent( event );
       
  1587     }
       
  1588 
       
  1589 // ---------------------------------------------------------------------------	
       
  1590 // HandleHoldGestureEvents
       
  1591 // ---------------------------------------------------------------------------
       
  1592 //
       
  1593 void MulCoverFlowControl::HandleHoldGestureEvents( const MGestureEvent& aEvent )
       
  1594     {
       
  1595     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleHoldGestureEvents");
       
  1596 
       
  1597     switch ( aEvent.Code(MGestureEvent::EAxisHorizontal) )
       
  1598         {
       
  1599         case EGestureDrag: 
       
  1600             {		
       
  1601             MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleHoldGestureEvents EGestureDrag");
       
  1602             
       
  1603             ReverseDirectionInFastScroll(aEvent);
       
  1604             
       
  1605             /// @todo The strip direction intially should start with the current gesture direction.
       
  1606             // But if u keep dragging without releasing the pointer tehn the directioon should chnage whenever
       
  1607             // the pointer crosses the centre of the screen.
       
  1608             
       
  1609             // if the pointer has crossed the centre position after holding started then the
       
  1610             // direction should depend on which half of teh screen
       
  1611             // else
       
  1612             // the direction should depend on the swipe direction
       
  1613 			StartMoving(aEvent);		
       
  1614 	        break;
       
  1615             }
       
  1616 
       
  1617         case EGestureReleased:
       
  1618         case EGestureTap:
       
  1619         	{
       
  1620         	MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleHoldGestureEvents EGestureReleased");
       
  1621  	        HandleEnhancedStop();
       
  1622 	        break;
       
  1623         	}	    	
       
  1624 	            
       
  1625         case EGestureHoldLeft:
       
  1626         case EGestureHoldRight:
       
  1627         	{
       
  1628         	MUL_LOG_INFO("MUL::MulCoverFlowControl:HandleHoldGestureEvents EGestureHoldLeft");
       
  1629 			if( EnhancedModeCondition() ) 
       
  1630             	{
       
  1631             	EnhancedStarted( aEvent );
       
  1632                 }
       
  1633             break;
       
  1634         	}
       
  1635         	
       
  1636         default:
       
  1637             break;
       
  1638         } // end of switch
       
  1639     
       
  1640     }
       
  1641   
       
  1642 // ---------------------------------------------------------------------------
       
  1643 // ReverseDirectionInFastSrroll
       
  1644 // ---------------------------------------------------------------------------
       
  1645 //    
       
  1646 void MulCoverFlowControl::ReverseDirectionInFastScroll(const MGestureEvent& aEvent)
       
  1647     {
       
  1648     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ReverseDirectionInFastScroll");
       
  1649 
       
  1650     int distTravelled = aEvent.Distance().iX;
       
  1651     int pointerDownPos = aEvent.StartPos().iX;
       
  1652     int currPosition = aEvent.CurrentPos().iX;
       
  1653     int prevGestureDir = ConvertDistanceToDirection(mData->mCurrGestureDir);
       
  1654 
       
  1655     // if the distance travelled is negative i.e from right to left and the start position is on
       
  1656     // the right half of the screen and the direction has not changed yet , then special case to handle reference point. and vice versa
       
  1657     // case for left half of the screen.
       
  1658     if( ((distTravelled < 0 && pointerDownPos > mData->mScreenWidth/2 ) || (distTravelled > 0 && 
       
  1659     	pointerDownPos < mData->mScreenWidth/2 )) && mData->mReferencePoint != mData->mScreenWidth/2) 
       
  1660         {
       
  1661         if( mData->mDirectionChanged )
       
  1662             {
       
  1663             return;
       
  1664             }
       
  1665             
       
  1666         ChangeDirReferencePoint(currPosition,distTravelled);
       
  1667         }
       
  1668     else
       
  1669         {
       
  1670         // else the reference point will be the middle of the screen.
       
  1671         
       
  1672         // if the direction is not equal .. just check whether it has crossed the reference point.
       
  1673         // how to check whether it has crossed the reference point.
       
  1674         if(( prevGestureDir < 0 &&  currPosition > mData->mReferencePoint )||(prevGestureDir > 0 && currPosition < mData->mReferencePoint))
       
  1675             {
       
  1676             mData->mCurrGestureDir *= -1;
       
  1677             }
       
  1678           
       
  1679         mData->mReferencePoint = mData->mScreenWidth/2;	
       
  1680         }    
       
  1681     }
       
  1682     
       
  1683 // ---------------------------------------------------------------------------
       
  1684 // ChangeDirReferencePoint
       
  1685 // ---------------------------------------------------------------------------
       
  1686 //    
       
  1687 void MulCoverFlowControl::ChangeDirReferencePoint(int aCurrPosition, int aDistanceTravelled )
       
  1688     {
       
  1689     MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ChangeDirReferencePoint");
       
  1690    
       
  1691     int prevGestureDir = ConvertDistanceToDirection(mData->mCurrGestureDir);
       
  1692     int currGestureDir =  ConvertDistanceToDirection(aDistanceTravelled);
       
  1693     
       
  1694     if( prevGestureDir != currGestureDir ) 
       
  1695         {
       
  1696         // if the direction is not equal .. just check whether it has crossed the reference point.
       
  1697         // how to check whether it has crossed the reference point.
       
  1698         if(( prevGestureDir < 0 &&  aCurrPosition > mData->mReferencePoint )||(prevGestureDir > 0 && aCurrPosition < mData->mReferencePoint))
       
  1699             {
       
  1700             //crossed the reference point first time .now no need to maintain the reference point .its always half of the screen
       
  1701             mData->mReferencePoint = mData->mScreenWidth/2;
       
  1702             mData->mDirectionChanged = true;
       
  1703             mData->mCurrGestureDir = aDistanceTravelled;
       
  1704             }
       
  1705         else
       
  1706             {
       
  1707             // not crossed the reference point yet
       
  1708             // still going in the same direction .
       
  1709             mData->mReferencePoint = aCurrPosition - 10;	
       
  1710             }
       
  1711         }
       
  1712     else
       
  1713         {
       
  1714         // still going in the same direction .
       
  1715         if(( prevGestureDir < 0 &&  aCurrPosition < mData->mScreenWidth/2 )||(prevGestureDir > 0 
       
  1716         	&& aCurrPosition > mData->mScreenWidth/2))
       
  1717             {
       
  1718             mData->mReferencePoint = mData->mScreenWidth/2;			
       
  1719             }
       
  1720         else if(Abs(mData->mCurrGestureDir) < Abs(aDistanceTravelled)  )
       
  1721             {
       
  1722             // moving in the same direction in the increasing side towards the middle of the screen but hasnt 
       
  1723             // crossed the reference point yet.
       
  1724             mData->mReferencePoint = aCurrPosition - 10;		
       
  1725             }
       
  1726         }
       
  1727     }
       
  1728     
       
  1729 // ---------------------------------------------------------------------------
       
  1730 // ConvertDistanceToDirection
       
  1731 // ---------------------------------------------------------------------------
       
  1732 //
       
  1733 int MulCoverFlowControl::ConvertDistanceToDirection( int aDistance )
       
  1734 	{
       
  1735 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::ConvertDistanceToDirection");
       
  1736 	return aDistance>0?1:-1;
       
  1737 	}      
       
  1738 
       
  1739 // ---------------------------------------------------------------------------
       
  1740 // HandleEnhancedStop
       
  1741 // ---------------------------------------------------------------------------
       
  1742 //
       
  1743 void MulCoverFlowControl::HandleEnhancedStop()
       
  1744 	{
       
  1745 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::HandleEnhancedStop");
       
  1746         					
       
  1747 	CAlfWidgetControl::processEvent( TAlfEvent( ETypeFastScroll,EScrollStop ));
       
  1748 	mCoverFlowAo->StopMoving();
       
  1749 	mData->mFastScroll = false;
       
  1750 	mData->mGestureSpeed = 0;	
       
  1751     // @TODO animation time should be same as set by the application.
       
  1752     mData->mBaseElement->MoveVisuals(0,200);
       
  1753 	}
       
  1754 	
       
  1755 // ---------------------------------------------------------------------------
       
  1756 // FastScrollTransitionTime
       
  1757 // ---------------------------------------------------------------------------
       
  1758 // 	
       
  1759 int MulCoverFlowControl::FastScrollTransitionTime()
       
  1760 	{
       
  1761 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::FastScrollTransitionTime");
       
  1762 	if (mData->mBounceInProgress)	
       
  1763 		{
       
  1764 		return 800;	
       
  1765 		}
       
  1766 	else
       
  1767 		{
       
  1768 		return mCoverFlowAo->FastScrollTransitionTime();
       
  1769 		}
       
  1770 	}	
       
  1771 	
       
  1772 
       
  1773 // ---------------------------------------------------------------------------
       
  1774 // EnhancedModeCondition
       
  1775 // ---------------------------------------------------------------------------
       
  1776 //
       
  1777 bool MulCoverFlowControl::EnhancedModeCondition()
       
  1778 	{
       
  1779 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::EnhancedMode");
       
  1780 	if( !mData->mCoverFlow2DTemplate.get() )
       
  1781 		{
       
  1782 		return false;
       
  1783 		}
       
  1784 	UString orientation  = IsLandscape() ? UString(KLandscape)  :  UString(KPortrait);
       
  1785 
       
  1786 	// If EMulWidgetFlagFastScroll is not set, 
       
  1787 	// or the current orientation is not landscape
       
  1788 	// or in teh current template enhanced mode is not supported
       
  1789 	if( !(((MulCoverFlowWidget*)widget())->IsFlagSet(IMulMultiItemWidget::EMulWidgetFlagFastScroll) 
       
  1790 		&& !orientation.compare(KLandscape) 
       
  1791 		&& mData->mCoverFlow2DTemplate->EnhancedTagParsed()) )
       
  1792 		{		
       
  1793 		return false;
       
  1794 		}
       
  1795 	// If template4(i.e. ui on off mode is anabled) then if ui on mode then ecf canot be launched,so return false		
       
  1796 	else if( mData->mCoverFlow2DTemplate->IsUiOnOffFlagEnabled() && 
       
  1797     		(mData->mBaseElement->IsUiOnMode()) )
       
  1798 		{
       
  1799 		return false;	
       
  1800 		}
       
  1801     else
       
  1802 	    {
       
  1803 	    return true; // enhanced mode enabled
       
  1804 	    }
       
  1805 	}
       
  1806 
       
  1807 // ---------------------------------------------------------------------------
       
  1808 // EnhancedStarted
       
  1809 // ---------------------------------------------------------------------------
       
  1810 // 	
       
  1811 void MulCoverFlowControl::EnhancedStarted(const GestureHelper::MGestureEvent& aEvent )
       
  1812 	{
       
  1813 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::EnhancedStarted");
       
  1814 	CAlfWidgetControl::processEvent( TAlfEvent( ETypeFastScroll,EScrollStart ));
       
  1815 	mData->mFastScroll = true;
       
  1816 	StartMoving(aEvent);			
       
  1817 	}
       
  1818 
       
  1819 // ---------------------------------------------------------------------------
       
  1820 // StartMoving
       
  1821 // ---------------------------------------------------------------------------
       
  1822 // 
       
  1823 void MulCoverFlowControl::StartMoving( const GestureHelper::MGestureEvent& aEvent )
       
  1824 	{
       
  1825 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::StartMoving");
       
  1826 
       
  1827 	TRealPoint speedPoint = GestureSpeed( aEvent );
       
  1828 	int distance =  mData->mCurrGestureDir;
       
  1829 	if (mData->mIsMirrored)
       
  1830 		{
       
  1831 		distance = -distance;
       
  1832 		}
       
  1833 	mCoverFlowAo->StartMoving(speedPoint.iX, ConvertDistanceToDirection(distance) );
       
  1834 	mData->mGestureSpeed = speedPoint.iX;
       
  1835    	}
       
  1836 
       
  1837 // ---------------------------------------------------------------------------
       
  1838 // GestureSpeed
       
  1839 // ---------------------------------------------------------------------------
       
  1840 //
       
  1841 TRealPoint MulCoverFlowControl::GestureSpeed( const MGestureEvent& aEvent )
       
  1842     {
       
  1843 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::GestureSpeed");    
       
  1844     
       
  1845     TRect area(this->DisplayArea());
       
  1846     TRect rect(TPoint(0,0),TPoint(area.Width(),area.Height())); 
       
  1847     return aEvent.SpeedPercent( rect );
       
  1848     }	
       
  1849 
       
  1850 //--------------------Slider related functions----------------------------
       
  1851 
       
  1852 // ---------------------------------------------------------------------------
       
  1853 // CreateSliderWidget
       
  1854 // ---------------------------------------------------------------------------
       
  1855 //
       
  1856 IAlfWidget* MulCoverFlowControl::CreateSliderWidget()
       
  1857 	{
       
  1858 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::CreateSliderWidget");
       
  1859 	
       
  1860 	IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(Env());
       
  1861 	IAlfWidget* sliderWidget = widgetFactory.findWidget( KNameSliderWidget );
       
  1862 	
       
  1863 	if( sliderWidget )
       
  1864 		{
       
  1865 		mSliderWidget = static_cast<IMulSliderWidget*>(sliderWidget);
       
  1866 		mData->mBaseElement->UpdateSliderTick( 1 );
       
  1867 		}
       
  1868 	else
       
  1869 		{
       
  1870 		// Get the template Id in Integer from your template data 
       
  1871 		//NOTE: Set template takes int as parameter not UString
       
  1872 		
       
  1873 		// Slider Widget creation
       
  1874 		mSliderWidget = widgetFactory.createWidget<IMulSliderWidget> ( KNameSliderWidget, KNameSliderWidget, *widget()->parent(), NULL);
       
  1875 		IMulSliderModel* mSliderModel = widgetFactory.createModel<IMulSliderModel> ("mulslidermodel");
       
  1876 		mSliderWidget->setModel(mSliderModel, true);	
       
  1877 		mSliderModel->SetTemplate(ESliderTemplate1);
       
  1878 		mSliderWidget->SetHandleKeyEvent(false);	
       
  1879 		mSliderWidget->control()->disableState(IAlfWidgetControl::Focusable); 
       
  1880 		}
       
  1881 	
       
  1882 	IAlfWidgetEventHandler* coverFlowEventHandler = static_cast<IAlfWidgetEventHandler*> (
       
  1883 	        mData->mBaseElement->makeInterface( IAlfWidgetEventHandler::type() ) );
       
  1884 	
       
  1885 	//Register the slidereventhandler and coverfloweventhandler with one another
       
  1886 	mSliderWidget->control()->addEventHandler((coverFlowEventHandler));
       
  1887 			
       
  1888 	return mSliderWidget;	
       
  1889 	}
       
  1890 	
       
  1891 // ---------------------------------------------------------------------------
       
  1892 // GetSliderWidget
       
  1893 // ---------------------------------------------------------------------------
       
  1894 //	
       
  1895 IAlfWidget* MulCoverFlowControl::GetSliderWidget()
       
  1896 	{
       
  1897 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::GetSliderWidget");
       
  1898 
       
  1899 	IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*(CAlfEnv::Static()));
       
  1900 	return widgetFactory.findWidget( KNameSliderWidget );
       
  1901 	}		    		    		
       
  1902 
       
  1903 // ---------------------------------------------------------------------------
       
  1904 // GetSliderModel
       
  1905 // ---------------------------------------------------------------------------
       
  1906 //	
       
  1907 IMulSliderModel* MulCoverFlowControl::GetSliderModel()
       
  1908 	{
       
  1909 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::GetSliderModel");
       
  1910 	if( mSliderWidget )
       
  1911 		{
       
  1912 		IMulSliderWidget* mulSliderWidget = static_cast<IMulSliderWidget*>(mSliderWidget);
       
  1913 		IMulSliderModel* mulSliderModel = static_cast<IMulSliderModel*>(mulSliderWidget->model());
       
  1914 		return mulSliderModel;
       
  1915 		}
       
  1916 	return NULL;
       
  1917 	}
       
  1918 	
       
  1919 // ---------------------------------------------------------------------------
       
  1920 // DestroySlider
       
  1921 // ---------------------------------------------------------------------------
       
  1922 //  
       
  1923 void MulCoverFlowControl::DestroySlider()
       
  1924 	{
       
  1925 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::DestroySlider");
       
  1926 
       
  1927     MulBaseElement* baseelement = static_cast<MulBaseElement*>(findElement(KBase));
       
  1928     if(baseelement)
       
  1929     	{
       
  1930     	baseelement->RemoveSliderFromLayout();
       
  1931     	}
       
  1932         
       
  1933 	IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(Env());
       
  1934 	IAlfWidget* sliderWidget = widgetFactory.findWidget( KNameSliderWidget );
       
  1935 	if( sliderWidget )
       
  1936 		{  
       
  1937 		IAlfElement* baseelement = findElement(KBase);
       
  1938 		if(baseelement)
       
  1939 			{
       
  1940 		
       
  1941 			IAlfWidgetEventHandler* coverFlowEventHandler = static_cast<IAlfWidgetEventHandler*> (
       
  1942 		          baseelement->makeInterface( IAlfWidgetEventHandler::type() ) );
       
  1943 		         
       
  1944 		    if( sliderWidget->control() )
       
  1945 				{
       
  1946 				sliderWidget->control()->removeEventHandler(*(coverFlowEventHandler));	
       
  1947 				}	
       
  1948 			
       
  1949 			}
       
  1950 		}		
       
  1951 	}
       
  1952 
       
  1953 // ---------------------------------------------------------------------------
       
  1954 // UpdateItemAtIndex
       
  1955 // ---------------------------------------------------------------------------
       
  1956 //
       
  1957 void MulCoverFlowControl::UpdateItemAtIndex(const int aRelativeIndex, int aAnimationTime)	
       
  1958 	{
       
  1959 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::UpdateItemAtIndex");
       
  1960 	int absoluteIndex = RelativeToAbsolute(aRelativeIndex);
       
  1961 	if(absoluteIndex >= 0)
       
  1962 		{
       
  1963 		UpdateCoverflowItem( absoluteIndex,aRelativeIndex, aAnimationTime );	
       
  1964 		}
       
  1965 	else
       
  1966 		{
       
  1967 		SetBlankTexture(aRelativeIndex);	
       
  1968 		}	
       
  1969 	}
       
  1970 
       
  1971 // ---------------------------------------------------------------------------
       
  1972 // SetBlankTexture
       
  1973 // ---------------------------------------------------------------------------
       
  1974 //
       
  1975 void MulCoverFlowControl::SetBlankTexture(int aRelativeIndex)
       
  1976 	{
       
  1977 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetBlankTexture");
       
  1978     CAlfFlowLayout& iconFlow = static_cast<CAlfFlowLayout&>(mData->mBaseElement->FlowLayout( KIconFlowLayoutIndex ));
       
  1979 	
       
  1980 	CAlfDeckLayout& layout = static_cast<CAlfDeckLayout&>(iconFlow.Visual(aRelativeIndex));
       
  1981 	CAlfImageVisual* visual =static_cast<CAlfImageVisual*>(layout.FindTag(KCoverflowIcon));
       
  1982 	
       
  1983     CAlfTextureManager& textureMgr = Env().TextureManager();
       
  1984     TAlfImage blankTexture = textureMgr.BlankTexture();
       
  1985     visual->SetImage(blankTexture);
       
  1986     
       
  1987     // remove the icon brush if any.
       
  1988     mData->mBaseElement->RemoveBrushOnIcon(*visual);        
       
  1989     
       
  1990     CAlfImageVisual* indicatorVisual =static_cast<CAlfImageVisual*>(layout.FindTag(KCoverflowIndicator));    
       
  1991     if(indicatorVisual)
       
  1992         {
       
  1993         indicatorVisual->SetImage(blankTexture);   
       
  1994         }
       
  1995 	}
       
  1996 
       
  1997 // ---------------------------------------------------------------------------
       
  1998 // UpdateCoverflowItem
       
  1999 // ---------------------------------------------------------------------------
       
  2000 //
       
  2001 void MulCoverFlowControl::UpdateCoverflowItem( int aItemIndex,int aVisualIndex, int aAnimationTime )
       
  2002 	{
       
  2003 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::UpdateCoverflowItem");
       
  2004     
       
  2005     CAlfFlowLayout& iconFlow = static_cast<CAlfFlowLayout&>(mData->mBaseElement->FlowLayout( KIconFlowLayoutIndex ));
       
  2006 	IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model()); 
       
  2007 		
       
  2008 	try
       
  2009 		{
       
  2010 		const MulVisualItem& item = accessor->Item(aItemIndex);
       
  2011 
       
  2012 		CAlfDeckLayout& layout = static_cast<CAlfDeckLayout&>(iconFlow.Visual(aVisualIndex));
       
  2013 		CAlfImageVisual* visual =static_cast<CAlfImageVisual*>(layout.FindTag(KCoverflowIcon));
       
  2014 		IMulVariantType* varData = item.Attribute(mulvisualitem::KMulIcon1);
       
  2015 		if(varData && visual)
       
  2016 			{
       
  2017 			DoSetImage(varData,visual);
       
  2018 			mData->mBaseElement->ApplyScaleMode(*visual);
       
  2019 			}
       
  2020 		else
       
  2021 			{
       
  2022 			if (mData->mDefaultTextureId >= 0)
       
  2023 				{
       
  2024 				const CAlfTexture* texture = Env().TextureManager().Texture (mData->mDefaultTextureId);
       
  2025 				if(visual)
       
  2026 				    {
       
  2027 				    visual->SetImage (TAlfImage (*texture));
       
  2028 				    }
       
  2029 				mData->mBaseElement->ApplyScaleMode(*visual);	
       
  2030 				}
       
  2031 			else
       
  2032 				{
       
  2033 				if(visual)
       
  2034 				    {        
       
  2035 				    visual->SetImage(Env().TextureManager().BlankTexture());
       
  2036 				    }
       
  2037 				}
       
  2038 			}
       
  2039 		if(mData->mCoverFlow2DTemplate->IsUiOnOffFlagEnabled() )
       
  2040     		{
       
  2041     		mData->mBaseElement->DisplayIndicatorIcon(item,aVisualIndex);			
       
  2042     		}
       
  2043 		}
       
  2044 	catch(...)
       
  2045 		{
       
  2046 		CAlfDeckLayout& layout = static_cast<CAlfDeckLayout&>(iconFlow.Visual(aVisualIndex));		
       
  2047 		CAlfImageVisual* visual =static_cast<CAlfImageVisual*>(layout.FindTag(KCoverflowIcon));
       
  2048 		if (mData->mDefaultTextureId >= 0)
       
  2049 			{
       
  2050 			const CAlfTexture* texture = Env().TextureManager().Texture (mData->mDefaultTextureId);
       
  2051 			visual->SetImage (TAlfImage (*texture));
       
  2052 			mData->mBaseElement->ApplyScaleMode(*visual);	
       
  2053 			}
       
  2054 		else
       
  2055 			{
       
  2056 		    visual->SetImage(Env().TextureManager().BlankTexture());	
       
  2057 			}			
       
  2058 		
       
  2059 		}//catch ends
       
  2060 	// if the item is the highlight item then update the text if required.	
       
  2061 	if (aVisualIndex == mData->mNumVisibleItem)		
       
  2062 		{
       
  2063 		mData->mBaseElement->UpdateTextValue(aAnimationTime);
       
  2064 		}
       
  2065 	}
       
  2066 	
       
  2067 
       
  2068 // ---------------------------------------------------------------------------
       
  2069 // DoSetImage
       
  2070 // ---------------------------------------------------------------------------
       
  2071 //			
       
  2072 void MulCoverFlowControl::DoSetImage(IMulVariantType* aData,CAlfImageVisual* aImgVisual)
       
  2073 	{
       
  2074 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::DoSetImage");
       
  2075 
       
  2076 	if ( aData && aData->Type() == IMulVariantType::EDes)
       
  2077 		{
       
  2078 		TAlfImage image = AlfWidgetEnvExtension::resourcePool(
       
  2079 			aImgVisual->Env()).getImageResource((char*)(aData->DesC().Ptr()));
       
  2080 		if(image.HasTexture())
       
  2081 			{
       
  2082 			aImgVisual->SetImage(image);
       
  2083 			}
       
  2084 		else if(IsSVGImage(aData->DesC()))
       
  2085 			{
       
  2086 			LoadImageFromSvg(aData->DesC(),*aImgVisual);
       
  2087 			}
       
  2088 		else
       
  2089 			{
       
  2090 			// check if the texture is already loaded
       
  2091 			CAlfTextureManager& textureMgr = aImgVisual->Env().TextureManager();
       
  2092 			const TInt existingTextureId = textureMgr.TextureId( aData->DesC() );
       
  2093 			const CAlfTexture* texture = NULL;  
       
  2094 
       
  2095 			if ( existingTextureId != KErrNotFound )
       
  2096 				{
       
  2097 				texture = textureMgr.Texture( existingTextureId );
       
  2098 				}
       
  2099 			else
       
  2100 				{
       
  2101 				TRAPD( err, texture = &( textureMgr.LoadTextureL(aData->DesC(),
       
  2102 				EAlfTextureFlagLoadAnimAsImage, KAlfAutoGeneratedTextureId ) ) );               
       
  2103 				if( err != KErrNone )
       
  2104 					{
       
  2105 					// means the texture is invalid.
       
  2106 					//draw a blank texture here.
       
  2107 					texture = &( textureMgr.BlankTexture() );
       
  2108 					}                           
       
  2109 				}                                   
       
  2110 			aImgVisual->SetImage( TAlfImage( *texture ) ); 
       
  2111 			}
       
  2112 		}
       
  2113 	else if ( aData && aData->Type ()== IMulVariantType::EInt)
       
  2114 		{
       
  2115 		const CAlfTexture* texture = Env().TextureManager().Texture (aData->integer());
       
  2116 		aImgVisual->SetImage (TAlfImage (*texture));	
       
  2117 		}
       
  2118 	}
       
  2119 	
       
  2120 // ---------------------------------------------------------------------------
       
  2121 // IsSVGImage	
       
  2122 // ---------------------------------------------------------------------------
       
  2123 //
       
  2124 bool MulCoverFlowControl::IsSVGImage(const TDesC& aImagePath)
       
  2125 	{
       
  2126 	MUL_LOG_INFO("MUL:MulCoverFlowControl::IsSVGImage");
       
  2127     _LIT(KSvgFile,".svg");
       
  2128 
       
  2129 	return  (KErrNotFound != aImagePath.FindC(KSvgFile));
       
  2130 	}
       
  2131 	
       
  2132 // ---------------------------------------------------------------------------
       
  2133 // LoadImageFromSvg	
       
  2134 // ---------------------------------------------------------------------------
       
  2135 //
       
  2136 void MulCoverFlowControl::LoadImageFromSvg(const TDesC& aImagePath,
       
  2137 											CAlfImageVisual& aImageVisual )
       
  2138 	{
       
  2139 	MUL_LOG_INFO("MUL:MulCoverFlowControl::LoadImageFromSvg");
       
  2140 	
       
  2141 	CAlfImageLoaderUtil imgLoaderUtil;
       
  2142 	imgLoaderUtil.SetSize (TSize (50, 50));
       
  2143 
       
  2144 	MAlfBitmapProvider* iSvgBitMapProv= imgLoaderUtil.CreateSVGImageLoaderL (aImagePath);
       
  2145 	CAlfTexture &texture = aImageVisual.Env().TextureManager().CreateTextureL (
       
  2146 							KAlfAutoGeneratedTextureId,
       
  2147 							iSvgBitMapProv,
       
  2148 							EAlfTextureFlagLoadAnimAsImage);
       
  2149 	aImageVisual.SetImage (TAlfImage (texture));
       
  2150 	
       
  2151 	}
       
  2152 
       
  2153 // ---------------------------------------------------------------------------
       
  2154 // StoreVisibleItemCount	
       
  2155 // ---------------------------------------------------------------------------
       
  2156 //		
       
  2157 void MulCoverFlowControl::StoreVisibleItemCount(int aVisibleItemCount)
       
  2158 	{
       
  2159 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::StoreVisibleItemCount");
       
  2160 	mData->mNumVisibleItem = aVisibleItemCount;
       
  2161 	}
       
  2162 
       
  2163 // ---------------------------------------------------------------------------
       
  2164 // SetDefaultImage	
       
  2165 // ---------------------------------------------------------------------------
       
  2166 //
       
  2167 void MulCoverFlowControl::SetDefaultImage(int aTextureId)
       
  2168 	{
       
  2169 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::SetDefaultImage");
       
  2170 	mData->mDefaultTextureId = aTextureId;
       
  2171 	}
       
  2172 
       
  2173 // ---------------------------------------------------------------------------
       
  2174 // WindowTop	
       
  2175 // ---------------------------------------------------------------------------
       
  2176 //
       
  2177 int MulCoverFlowControl::WindowTop(int aHighlightIndex)
       
  2178 	{
       
  2179 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::WindowTop");
       
  2180 	int visibleItems = 2 * mData->mNumVisibleItem + 1;
       
  2181 	int windowTop = aHighlightIndex - (visibleItems / 2);
       
  2182 	IMulModelAccessor* accessor = static_cast<IMulModelAccessor*>(widget()->model());
       
  2183     if(accessor)
       
  2184         {
       
  2185     	windowTop = (windowTop + visibleItems - 1) >= TotalModelCount() ? 
       
  2186     		TotalModelCount() - visibleItems : windowTop;
       
  2187     	windowTop = windowTop > 0 ? windowTop : 0;
       
  2188         }
       
  2189 
       
  2190 	return windowTop;
       
  2191 	}
       
  2192 
       
  2193 // ---------------------------------------------------------------------------
       
  2194 // UpdateBaseElement	
       
  2195 // ---------------------------------------------------------------------------
       
  2196 //
       
  2197 void MulCoverFlowControl::UpdateBaseElement(MulBaseElement* aBaseElement)
       
  2198 	{
       
  2199 	MUL_LOG_ENTRY_EXIT("MUL:MulCoverFlowControl::UpdateBaseElement");
       
  2200 	mData->mBaseElement = aBaseElement;
       
  2201 	}
       
  2202 
       
  2203 // ---------------------------------------------------------------------------
       
  2204 // IsLandscape	
       
  2205 // ---------------------------------------------------------------------------
       
  2206 //
       
  2207 bool MulCoverFlowControl::IsLandscape()
       
  2208 	{
       
  2209 	bool ret;
       
  2210 	TSize ScreenSz = AlfUtil::ScreenSize();
       
  2211 	if (ScreenSz.iWidth > ScreenSz.iHeight)
       
  2212 		{
       
  2213 		ret = true;
       
  2214 		}
       
  2215 	else
       
  2216 		{
       
  2217 		ret = false;
       
  2218 		}
       
  2219 	return ret;
       
  2220 	}
       
  2221 
       
  2222 // ---------------------------------------------------------------------------
       
  2223 // Gesturehelper  
       
  2224 // ---------------------------------------------------------------------------
       
  2225 //
       
  2226 GestureHelper::CGestureHelper* MulCoverFlowControl::Gesturehelper()
       
  2227     {
       
  2228     return mHelper.get(); 
       
  2229     }
       
  2230 
       
  2231 	} // namespace Alf
       
  2232 
       
  2233 //End of file