photosgallery/viewframework/visuallistmanager/src/glxvisuallistcontrol.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Visual list manager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  * @internal reviewed 04/07/2007 by M Byrne
       
    23  */
       
    24 
       
    25 #include <coemain.h>
       
    26 #include <eikappui.h>
       
    27 #include <eikenv.h>
       
    28 #include <alf/alfborderbrush.h>
       
    29 #include <alf/alfimagevisual.h>
       
    30 #include <alf/alfanchorlayout.h>
       
    31 #include <alf/alfenv.h> 
       
    32 #include <alf/alftexturemanager.h>
       
    33 #include <alf/alfbrush.h>
       
    34 #include <alf/alfcontrolgroup.h>
       
    35 #include <alf/alfdisplay.h>
       
    36 #include <alf/alfroster.h>
       
    37 #include <alf/alftexture.h>
       
    38 #include <alf/alfdecklayout.h>
       
    39 #include <mpxmediageneraldefs.h>
       
    40 #include <glxuiutility.h>
       
    41 #include <glxtexturemanager.h>
       
    42 #include <glxmediageneraldefs.h>
       
    43 #include <glxattributecontext.h>
       
    44 #include <glxuistd.h>
       
    45 #include <alf/alflayout.h>
       
    46 #include <mglxmedialist.h>
       
    47 #include <glxlog.h>
       
    48 #include <glxtracer.h>
       
    49 
       
    50 #include "glxvisuallistcontrol.h"
       
    51 #include "mglxvisuallistobserver.h" 
       
    52 #include "glxvisuallistwindow.h" 
       
    53 #include "glxitemvisual.h"
       
    54 #include "glxvisualiconmanager.h" // for iVisualIconManager
       
    55 #include "mglxlayoutobserver.h"
       
    56 
       
    57 const TInt KMaxTimeBetweenNavigationsForSpeedConsideration = 2000;
       
    58 const TInt KGlxVisualFetchOffset = 2;
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CGlxVisualListControl* CGlxVisualListControl::NewLC(
       
    65         MGlxMediaList& aMediaList, 
       
    66         CAlfEnv& aEnv, 
       
    67         CAlfDisplay& aDisplay,
       
    68         CAlfImageVisual::TScaleMode aThumbnailScaleMode )
       
    69     {
       
    70     TRACER("CGlxVisualListControl::NewLC");
       
    71     GLX_LOG_INFO("CGlxVisualListControl::NewLC");
       
    72     CGlxVisualListControl* self =
       
    73         new (ELeave) CGlxVisualListControl( 
       
    74             aMediaList, aEnv, aThumbnailScaleMode );
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL( aEnv, aDisplay );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // Constructor
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CGlxVisualListControl::CGlxVisualListControl(
       
    85         MGlxMediaList& aMediaList,
       
    86         CAlfEnv& aEnv, 
       
    87 		CAlfImageVisual::TScaleMode aThumbnailScaleMode )
       
    88     : iMediaList(aMediaList ),
       
    89       iEnv( aEnv ),
       
    90       iScaleMode( aThumbnailScaleMode )
       
    91 	{
       
    92 	TRACER("CGlxVisualListControl::CGlxVisualListControl");
       
    93 	GLX_LOG_INFO("CGlxVisualListControl::CGlxVisualListControl");
       
    94 	// set current time
       
    95 	TTime time;
       
    96 	time.HomeTime();
       
    97     iLastTime = time;
       
    98 	}
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // ConstructL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CGlxVisualListControl::ConstructL( CAlfEnv& aEnv, 
       
   105 		CAlfDisplay& aDisplay ) 
       
   106 	{
       
   107 	TRACER("CGlxVisualListControl::ConstructL");
       
   108 	GLX_LOG_INFO("CGlxVisualListControl::ConstructL");
       
   109 	// call base class ConstructL
       
   110     CAlfControl::ConstructL( aEnv );
       
   111 	BindDisplay( aDisplay );    
       
   112 	iParentLayout = CAlfAnchorLayout::AddNewL(*this);
       
   113 	iParentLayout->SetFlags(EAlfVisualFlagLayoutUpdateNotification);
       
   114 	iParentLayout->EnableTransformationL();
       
   115 
       
   116 	iBorderBrush = CAlfBorderBrush::NewL( iEnv, 1, 1, 0, 0 );
       
   117 	iBorderBrush->SetColor(KRgbBlack);
       
   118 
       
   119 	iMediaList.AddMediaListObserverL( this );
       
   120 
       
   121     iUiUtility = CGlxUiUtility::UtilityL();
       
   122     // create the visual list window
       
   123     iVisualWindow = CGlxVisualListWindow::NewL(this,&iMediaList, iUiUtility, iScaleMode);
       
   124     
       
   125     //@todo below method not found    
       
   126     //iVisualWindow->SetOwnsObjects( ETrue );   
       
   127 	iControlGroupId = reinterpret_cast<int>((void*)this);   // @todo: Temp, have better logic for control group ids
       
   128 	iControlGroup = &Env().NewControlGroupL(iControlGroupId);
       
   129 	iControlGroup->AppendL(this);
       
   130 	
       
   131 	// The media list might not be empty, so add items if there are any
       
   132 	TInt count = iMediaList.Count();
       
   133 	if (count > 0) 
       
   134 		{
       
   135 		// add the items to the visual list first
       
   136 		HandleItemAddedL( 0, count - 1, &iMediaList );
       
   137 		// then set the focus as media list may have been navigated before
       
   138 		iVisualWindow->SetFocusIndexL( iMediaList.FocusIndex() );
       
   139 		}
       
   140     iAttributeContext = CGlxDefaultAttributeContext::NewL();
       
   141     iAttributeContext->AddAttributeL(KMPXMediaGeneralUri);
       
   142     iAttributeContext->AddAttributeL(KGlxMediaGeneralFramecount);
       
   143     iAttributeContext->SetRangeOffsets(KGlxVisualFetchOffset,
       
   144                                         KGlxVisualFetchOffset);
       
   145     iMediaList.AddContextL( iAttributeContext, KGlxFetchContextPriorityLow );
       
   146     
       
   147     
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // Destructor
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 CGlxVisualListControl::~CGlxVisualListControl()
       
   155 	{
       
   156 	TRACER("CGlxVisualListControl::~CGlxVisualListControl");
       
   157 	GLX_LOG_INFO("CGlxVisualListControl::~CGlxVisualListControl");
       
   158 	// delete visual icon manager just in case
       
   159 	delete iVisualIconManager;
       
   160 	iVisualIconManager = NULL;
       
   161 	
       
   162 	// This control has to be removed from the control group, since deleting 
       
   163 	// the control group also deletes the control (this object), and would
       
   164 	// delete the control twice.
       
   165 	if ( iControlGroup )
       
   166 		{
       
   167 		iControlGroup->Remove(this); // Gives ownership to caller, but I'm being deleted anyway
       
   168 		Env().DeleteControlGroup(iControlGroupId);
       
   169 		iControlGroup = NULL;
       
   170 		}
       
   171 
       
   172     if ( iAttributeContext )
       
   173         {
       
   174         iMediaList.RemoveContext( iAttributeContext );
       
   175         }
       
   176     delete iAttributeContext;
       
   177     iAttributeContext = NULL;
       
   178 
       
   179 	// and media list observer
       
   180 	iMediaList.RemoveMediaListObserver( this );
       
   181 	delete iVisualWindow;
       
   182 	iVisualWindow = NULL;
       
   183 	iContexts.Close();
       
   184 	iObservers.Close();
       
   185 	delete iBorderBrush;
       
   186 	iBorderBrush = NULL;
       
   187     if ( iUiUtility )
       
   188         {
       
   189         iUiUtility->Close();
       
   190         iUiUtility = NULL;
       
   191         }
       
   192 	}
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // AddReference
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 TInt CGlxVisualListControl::AddReference()
       
   199 	{
       
   200 	TRACER("CGlxVisualListControl::AddReference");
       
   201 	GLX_LOG_INFO("CGlxVisualListControl::AddReference");
       
   202 	iReferenceCount++;
       
   203 	return iReferenceCount;
       
   204 	}
       
   205     
       
   206 // -----------------------------------------------------------------------------
       
   207 // RemoveReference
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 TInt CGlxVisualListControl::RemoveReference()
       
   211 	{
       
   212 	TRACER("CGlxVisualListControl::RemoveReference");
       
   213 	GLX_LOG_INFO("CGlxVisualListControl::RemoveReference");
       
   214 	__ASSERT_ALWAYS(iReferenceCount > 0, Panic(EGlxPanicLogicError));
       
   215 	iReferenceCount--;
       
   216 	return iReferenceCount;
       
   217 	}
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // MediaList
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 const MGlxMediaList& CGlxVisualListControl::MediaList() const
       
   224     {
       
   225     TRACER("CGlxVisualListControl::MediaList");
       
   226     GLX_LOG_INFO("CGlxVisualListControl::MediaList");
       
   227     return iMediaList;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // Id
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TGlxVisualListId CGlxVisualListControl::Id() const 
       
   235 	{
       
   236 	TRACER("CGlxVisualListControl::Id");
       
   237 	GLX_LOG_INFO("CGlxVisualListControl::Id");
       
   238 	return TGlxVisualListId(reinterpret_cast<unsigned int>((void*)this));
       
   239 	}
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // Returns visual by index
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 CAlfVisual* CGlxVisualListControl::Visual( TInt aListIndex )
       
   246 	{
       
   247 	TRACER("CGlxVisualListControl::Visual");
       
   248 	GLX_LOG_INFO("CGlxVisualListControl::Visual");
       
   249     CGlxVisualObject* visualObject = Item( aListIndex );
       
   250     if ( visualObject )
       
   251         {
       
   252         return visualObject->Visual();
       
   253         }
       
   254     return NULL;
       
   255 	}
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // Returns visual by index
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 CGlxVisualObject* CGlxVisualListControl::Item( TInt aListIndex )
       
   262     {
       
   263     TRACER("CGlxVisualListControl::Item");
       
   264     GLX_LOG_INFO("CGlxVisualListControl::Item");
       
   265     return iVisualWindow->ObjectByIndex( aListIndex );
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // Returns item count
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 TInt CGlxVisualListControl::ItemCount(NGlxListDefs::TCountType aType) const
       
   273 	{
       
   274 	TRACER("CGlxVisualListControl::ItemCount");
       
   275 	GLX_LOG_INFO("CGlxVisualListControl::ItemCount");
       
   276 	return iMediaList.Count(aType);
       
   277 	}
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // Returns focus index
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TInt CGlxVisualListControl::FocusIndex() const
       
   284 	{
       
   285 	TRACER("CGlxVisualListControl::FocusIndex");
       
   286 	GLX_LOG_INFO("CGlxVisualListControl::FocusIndex");
       
   287 	return iMediaList.FocusIndex();
       
   288 	}
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // ControlGroup
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 CAlfControlGroup* CGlxVisualListControl::ControlGroup() const 
       
   295 	{
       
   296 	TRACER("CGlxVisualListControl::ControlGroup");
       
   297 	GLX_LOG_INFO("CGlxVisualListControl::ControlGroup");
       
   298 	return iControlGroup;
       
   299 	}
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // AddContextL
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CGlxVisualListControl::AddObserverL(MGlxVisualListObserver* aObserver) 
       
   306 	{
       
   307 	TRACER("CGlxVisualListControl::AddObserverL");
       
   308 	GLX_LOG_INFO("CGlxVisualListControl::AddObserverL");
       
   309 	__ASSERT_DEBUG(iObservers.Find(aObserver) == KErrNotFound, 
       
   310 	                    Panic(EGlxPanicIllegalArgument)); // Already exists
       
   311 	iObservers.Append(aObserver);
       
   312 	}
       
   313 
       
   314 // -----------------------------------------------------------------------------
       
   315 // AddContextL
       
   316 // -----------------------------------------------------------------------------
       
   317 //
       
   318 void CGlxVisualListControl::RemoveObserver(MGlxVisualListObserver* aObserver)
       
   319 	{
       
   320 	TRACER("CGlxVisualListControl::RemoveObserver");
       
   321 	GLX_LOG_INFO("CGlxVisualListControl::RemoveObserver");
       
   322 	TInt i = iObservers.Find(aObserver);
       
   323 	if (i != KErrNotFound)
       
   324 		{
       
   325 		iObservers.Remove(i);
       
   326 		}
       
   327 	}
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // AddContextL
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 TGlxViewContextId CGlxVisualListControl::AddContextL(
       
   334                 TInt aFrontVisibleRangeOffset, TInt aRearVisibleRangeOffset )
       
   335 	{
       
   336 	TRACER("CGlxVisualListControl::AddContextL");
       
   337 	GLX_LOG_INFO("CGlxVisualListControl::AddContextL");
       
   338 	iContexts.ReserveL( iContexts.Count() + 1 );
       
   339 	TGlxViewContextId nextId;
       
   340 	iContextIdProvider.NextId(nextId);
       
   341 	
       
   342 	// Add the context to define which visuals should be created
       
   343 	TContext context;
       
   344 	context.iId = nextId;
       
   345 	context.iFrontVisibleRangeOffset = aFrontVisibleRangeOffset;
       
   346 	context.aRearVisibleRangeOffset = aRearVisibleRangeOffset;
       
   347 	iContexts.Append(context); // Cannot fail thanks to reservation
       
   348 	
       
   349 	// Combine the contexts, and update the window
       
   350 	TInt frontOffset = 0;
       
   351 	TInt rearOffset = 0;
       
   352 	RangeOffsets(frontOffset, rearOffset);
       
   353 	iVisualWindow->SetRangeOffsetsL(frontOffset, rearOffset);
       
   354 
       
   355 	iVisualWindow->UpdatePositions();
       
   356 
       
   357 	return nextId;
       
   358 	}
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // RemoveContext
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CGlxVisualListControl::RemoveContext(const TGlxViewContextId& aContextId) 
       
   365 	{
       
   366 	TRACER("CGlxVisualListControl::RemoveContext");
       
   367 	GLX_LOG_INFO("CGlxVisualListControl::RemoveContext");
       
   368 	// Remove context
       
   369 	TInt count = iContexts.Count();
       
   370 	TInt i;
       
   371 	for (i = 0; i < count; i++)
       
   372 		{
       
   373 		if (iContexts[i].iId == aContextId)
       
   374 			{
       
   375 			iContexts.Remove(i);
       
   376 			break;
       
   377 			}
       
   378 		}
       
   379 	__ASSERT_DEBUG(i != count, Panic(EGlxPanicIllegalArgument)); // No such context
       
   380 	
       
   381 	// Combine the contexts, and update the window
       
   382 	TInt frontOffset = 0;
       
   383 	TInt rearOffset = 0;
       
   384 	RangeOffsets(frontOffset, rearOffset); 
       
   385 	// This can actually never fail (read CVieListWindow header). Trapped in case maintenance
       
   386 	// changes change the behavior of window base class
       
   387 	TRAP_IGNORE(iVisualWindow->SetRangeOffsetsL(frontOffset, rearOffset));
       
   388 	}
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // RangeOffsets
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 void CGlxVisualListControl::RangeOffsets(TInt& aFrontOffset, TInt& aRearOffsets)
       
   395 	{
       
   396 	TRACER("CGlxVisualListControl::RangeOffsets");
       
   397 	GLX_LOG_INFO("CGlxVisualListControl::RangeOffsets");
       
   398 	// Combine the contexts, and update the window
       
   399 	aFrontOffset = 0;
       
   400 	aRearOffsets = 0;
       
   401 	
       
   402 	TInt count = iContexts.Count();
       
   403 	for (TInt i = 0; i < count; i++)
       
   404 		{
       
   405 		TContext& context = iContexts[i];
       
   406 		// Pick smallest start offset
       
   407 		aFrontOffset = Min(aFrontOffset, context.iFrontVisibleRangeOffset);
       
   408 		// Pick largest end offset
       
   409 		aRearOffsets = Max(aRearOffsets, context.aRearVisibleRangeOffset);
       
   410 		}
       
   411 	}
       
   412 	
       
   413 // -----------------------------------------------------------------------------
       
   414 // AddLayoutL
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CGlxVisualListControl::AddLayoutL(MGlxLayout* /*aLayout*/)
       
   418 	{
       
   419 	// add the layout to the blender
       
   420 	//iLayoutBlender.AddLayoutL( aLayout );
       
   421 	}
       
   422 	
       
   423 // -----------------------------------------------------------------------------
       
   424 // RemoveLayout
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 void CGlxVisualListControl::RemoveLayout(const MGlxLayout* /*aLayout*/)
       
   428 	{
       
   429 	// remove layout
       
   430 	//iLayoutBlender.RemoveLayout( aLayout );
       
   431 	}
       
   432 
       
   433 // BringVisualsToFront
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 void CGlxVisualListControl::BringVisualsToFront()
       
   437     {
       
   438     TRACER("CGlxVisualListControl::BringVisualsToFront");
       
   439     GLX_LOG_INFO("CGlxVisualListControl::BringVisualsToFront");
       
   440     iUiUtility->Display()->Roster().MoveVisualToFront( *iParentLayout );
       
   441     }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 // HandleItemAddedL
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void CGlxVisualListControl::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex,
       
   448 		MGlxMediaList* /*aList*/)
       
   449 	{
       
   450 	TRACER("CGlxVisualListControl::HandleItemAddedL");
       
   451 	GLX_LOG_INFO("CGlxVisualListControl::HandleItemAddedL");
       
   452 	iVisualWindow->AddObjects( aStartIndex, aEndIndex );
       
   453 	iVisualWindow->UpdatePositions();
       
   454 	}
       
   455 	
       
   456 // -----------------------------------------------------------------------------
       
   457 // HandleMediaL
       
   458 // -----------------------------------------------------------------------------
       
   459 //
       
   460 void CGlxVisualListControl::HandleMediaL(TInt /*aIndex*/, MGlxMediaList* aList)
       
   461 	{
       
   462 	TRACER("CGlxVisualListControl::HandleMediaL");
       
   463 	GLX_LOG_INFO("CGlxVisualListControl::HandleMediaL");
       
   464 	__ASSERT_DEBUG(aList == &iMediaList, Panic(EGlxPanicIllegalArgument));
       
   465 	}
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // HandleItemRemovedL
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void CGlxVisualListControl::HandleItemRemovedL(TInt aStartIndex, TInt aEndIndex,
       
   472 		MGlxMediaList* /*aList*/)
       
   473 	{
       
   474 	TRACER("CGlxVisualListControl::HandleItemRemovedL");
       
   475 	GLX_LOG_INFO("CGlxVisualListControl::HandleItemRemovedL");
       
   476 	iVisualWindow->RemoveObjects( aStartIndex, aEndIndex );
       
   477 	iVisualWindow->UpdatePositions();
       
   478 	}
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // HandleItemModifiedL
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CGlxVisualListControl::HandleItemModifiedL(
       
   485             const RArray<TInt>& /*aItemIndexes*/, MGlxMediaList* /*aList*/ )
       
   486     {
       
   487     // No implementation
       
   488     }
       
   489 
       
   490 // -----------------------------------------------------------------------------
       
   491 // HandleAttributesAvailableL
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 void CGlxVisualListControl::HandleAttributesAvailableL( TInt aItemIndex, 	
       
   495 		const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* aList ) 
       
   496 	{
       
   497 	TRACER("CGlxVisualListControl::HandleAttributesAvailableL");
       
   498 	GLX_LOG_INFO("CGlxVisualListControl::HandleAttributesAvailableL");
       
   499 	__ASSERT_DEBUG( aList == &iMediaList, Panic( EGlxPanicIllegalArgument ) );
       
   500 
       
   501     // forward the attribute availability info to the matching visual object,
       
   502     // if it exists in the window
       
   503     CGlxVisualObject* visualObject = iVisualWindow->ObjectByIndex( aItemIndex );
       
   504 	if( visualObject )
       
   505 		{
       
   506 		visualObject->HandleAttributesAvailableL( aList->IdSpaceId( aItemIndex ), 
       
   507             aList->Item( aItemIndex ), aAttributes );
       
   508 		}
       
   509 	}
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // HandleFocusChangedL
       
   513 // -----------------------------------------------------------------------------
       
   514 //
       
   515 void CGlxVisualListControl::HandleFocusChangedL( 
       
   516                 NGlxListDefs::TFocusChangeType aType, 
       
   517                 TInt aNewIndex, TInt aOldIndex, MGlxMediaList* aList )
       
   518     {
       
   519     TRACER("CGlxVisualListControl::HandleFocusChangedL");
       
   520     GLX_LOG_INFO("CGlxVisualListControl::HandleFocusChangedL");
       
   521     __ASSERT_DEBUG( aList == &iMediaList, Panic( EGlxPanicIllegalArgument ) );
       
   522 
       
   523     iVisualWindow->SetFocusIndexL( aNewIndex );
       
   524 
       
   525     // Move the focused visual to front to make sure focused visual is above
       
   526     // other visuals
       
   527     if ( aNewIndex >= 0 )
       
   528         {
       
   529          iVisualWindow->ObjectByIndex( aNewIndex )->Visual()->MoveToFront();
       
   530         }
       
   531 
       
   532     // get the current time
       
   533     TTime time_now;
       
   534     time_now.HomeTime();
       
   535     // get the delta
       
   536     TTimeIntervalMicroSeconds elapsed = time_now.MicroSecondsFrom( iLastTime );
       
   537     // set last time to be time now
       
   538     iLastTime = time_now;
       
   539 
       
   540     TReal32 speed = 0;
       
   541     // Only consider the focus change if there was a focus before
       
   542     if ( aOldIndex != KErrNotFound
       
   543         && elapsed < KMaxTimeBetweenNavigationsForSpeedConsideration )
       
   544         {
       
   545         TInt indexesMoved = 0;
       
   546 
       
   547         if ( aType == NGlxListDefs::EForward ) 
       
   548             {
       
   549             indexesMoved = aNewIndex - aOldIndex;
       
   550             }
       
   551         else if ( aType == NGlxListDefs::EBackward ) 
       
   552             {
       
   553             indexesMoved = aOldIndex - aNewIndex;
       
   554             }
       
   555         else 
       
   556             {
       
   557             // Client did not use NavigateL for setting the focus index =>
       
   558             // don't guess, instead provide no speed.
       
   559             }
       
   560 
       
   561         if ( indexesMoved < 0 )
       
   562             {
       
   563             indexesMoved += ItemCount();
       
   564             }
       
   565         //speed = indexesMoved / elapsed;		
       
   566         }
       
   567 
       
   568 	TInt count = iObservers.Count();
       
   569 	for (TInt i = 0; i < count; i++)
       
   570 		{
       
   571 		iObservers[i]->HandleFocusChangedL( aNewIndex, speed, this, aType );
       
   572 		}
       
   573 	} 
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // Handles item selection/deselection
       
   577 // -----------------------------------------------------------------------------
       
   578 void CGlxVisualListControl::HandleItemSelectedL( TInt /*aIndex*/,
       
   579                                 TBool /*aSelected*/, MGlxMediaList* /*aList*/ )
       
   580 	{
       
   581 	// No implementation
       
   582 	}
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // Handles collection notification
       
   586 // -----------------------------------------------------------------------------
       
   587 void CGlxVisualListControl::HandleMessageL( const CMPXMessage& /*aMessage*/,
       
   588                                             MGlxMediaList* /*aList*/ )
       
   589 	{
       
   590 	// No implementation
       
   591 	}
       
   592 
       
   593 // -----------------------------------------------------------------------------
       
   594 // NavigateL
       
   595 // From MViuVisualOwner
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 void CGlxVisualListControl::NavigateL(TInt aIndexCount)
       
   599 	{
       
   600 	TRACER("CGlxVisualListControl::NavigateL");
       
   601 	GLX_LOG_INFO("CGlxVisualListControl::NavigateL");
       
   602 	if (aIndexCount == 0)
       
   603 		{
       
   604  		__ASSERT_DEBUG(EFalse, Panic(EGlxPanicIllegalArgument)); // no navigation to either direction
       
   605 		return;
       
   606 		}
       
   607 	iMediaList.SetFocusL(NGlxListDefs::ERelative, aIndexCount);
       
   608 	}
       
   609 	
       
   610 // -----------------------------------------------------------------------------
       
   611 // NavigateL
       
   612 // From MViuVisualOwner
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615  TSize CGlxVisualListControl::Size() const 
       
   616  	{
       
   617  	TRACER("CGlxVisualListControl::Size");
       
   618  	GLX_LOG_INFO("CGlxVisualListControl::Size");
       
   619 	return iParentLayout->Size().Target().AsSize();
       
   620  	}
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // NavigateL
       
   624 // From CHuiControl
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 void CGlxVisualListControl::VisualLayoutUpdated( CAlfVisual& aVisual )
       
   628 	{
       
   629 	TRACER("CGlxVisualListControl::VisualLayoutUpdated");
       
   630 	GLX_LOG_INFO("CGlxVisualListControl::VisualLayoutUpdated");
       
   631 	if (&aVisual == iParentLayout) 
       
   632 		{
       
   633 		TSize size = iParentLayout->Size().Target().AsSize();
       
   634 		if(size != iCurrentLayoutSize)
       
   635 		    {
       
   636             iCurrentLayoutSize = size;		    
       
   637     		TInt count = iObservers.Count();
       
   638     		for (TInt i = 0; i < count; i++)
       
   639     			{
       
   640     			iObservers[i]->HandleSizeChanged(size, this);
       
   641     			}
       
   642 		    }
       
   643 		}
       
   644 	}
       
   645 
       
   646 // -----------------------------------------------------------------------------
       
   647 // HandleVisualRemoved
       
   648 // -----------------------------------------------------------------------------
       
   649 //
       
   650 void CGlxVisualListControl::HandleVisualRemoved(const CAlfVisual* aVisual)
       
   651 	{
       
   652 	TRACER("CGlxVisualListControl::HandleVisualRemoved");
       
   653 	GLX_LOG_INFO("CGlxVisualListControl::HandleVisualRemoved");
       
   654 	TInt count = iObservers.Count();
       
   655 	for (TInt i = 0; i < count; i++)
       
   656 		{
       
   657 		iObservers[i]->HandleVisualRemoved(aVisual, this);
       
   658 		}
       
   659 	}
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // HandleVisualRemoved
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CGlxVisualListControl::HandleVisualAddedL(CAlfVisual* aVisual, TInt aIndex)
       
   666 	{
       
   667 	TRACER("CGlxVisualListControl::HandleVisualAddedL");
       
   668 	GLX_LOG_INFO("CGlxVisualListControl::HandleVisualAddedL");
       
   669 	//iVisualWindow->ObjectByIndex(aIndex)->AddObserver(this);
       
   670 	TInt count = iObservers.Count();
       
   671 	for (TInt i = 0; i < count; i++)
       
   672 		{
       
   673 		iObservers[i]->HandleVisualAddedL(aVisual, aIndex, this);
       
   674 		}
       
   675 	}
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // EnableAnimationL
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 void CGlxVisualListControl::EnableAnimationL(TBool aAnimate, TInt aIndex)
       
   682     {
       
   683     TRACER("CGlxVisualListControl::EnableAnimationL");
       
   684     GLX_LOG_INFO("CGlxVisualListControl::EnableAnimationL");
       
   685     CGlxVisualObject* visualObject = iVisualWindow->ObjectByIndex( aIndex );
       
   686     if ( visualObject )
       
   687         {
       
   688         //iVisualWindow->ObjectByIndex(aIndex)->RemoveObserver(this);
       
   689         if( aAnimate )
       
   690             {
       
   691             visualObject->TryAnimateL( iMediaList.Item( aIndex ) );
       
   692     		}
       
   693         else
       
   694             {
       
   695             // Stop animation
       
   696     		visualObject->StopAnimation();
       
   697             visualObject->SetAnimateWhenAttributesAvailable( EFalse );
       
   698             }
       
   699         }
       
   700     }
       
   701 
       
   702 // -----------------------------------------------------------------------------
       
   703 // SetDefaultIconBehaviourL
       
   704 // -----------------------------------------------------------------------------
       
   705 void CGlxVisualListControl::SetDefaultIconBehaviourL( TBool aEnable )
       
   706     {
       
   707     TRACER("CGlxVisualListControl::SetDefaultIconBehaviourL");
       
   708     GLX_LOG_INFO("CGlxVisualListControl::SetDefaultIconBehaviourL");
       
   709     // do we want to disable
       
   710     if( !aEnable )
       
   711     	{
       
   712     	// disable by deleting it
       
   713     	delete iVisualIconManager;
       
   714     	// prevent double delete
       
   715     	iVisualIconManager = NULL;
       
   716     	}
       
   717     // do we want to enable and we dont yet have icon manager
       
   718     else if( !iVisualIconManager )
       
   719     	{
       
   720 	    iVisualIconManager = CGlxVisualIconManager::NewL( iMediaList, *this );
       
   721     	}
       
   722     else
       
   723         {
       
   724         }
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // ThumbnailScaleMode
       
   729 // -----------------------------------------------------------------------------
       
   730 //
       
   731 CAlfImageVisual::TScaleMode CGlxVisualListControl::ThumbnailScaleMode()
       
   732     {
       
   733     TRACER("CGlxVisualListControl::ThumbnailScaleMode");
       
   734     GLX_LOG_INFO("CGlxVisualListControl::ThumbnailScaleMode");
       
   735     return iScaleMode;
       
   736     }
       
   737 
       
   738 // -----------------------------------------------------------------------------
       
   739 // AddIconL
       
   740 // -----------------------------------------------------------------------------
       
   741 //    
       
   742 void CGlxVisualListControl::AddIconL( TInt aListIndex, const CAlfTexture& aTexture, 
       
   743             NGlxIconMgrDefs::TGlxIconPosition aIconPos,
       
   744             TBool aForeground, TBool aStretch, TInt aBorderMargin,
       
   745             TReal32 aWidth, TReal32 aHeight )
       
   746     {
       
   747     TRACER("CGlxVisualListControl::AddIconL");
       
   748     GLX_LOG_INFO("CGlxVisualListControl::AddIconL");
       
   749     CGlxVisualObject* visItem = Item( aListIndex );
       
   750     if( visItem )
       
   751         {
       
   752         visItem->AddIconL( aTexture, aIconPos, 
       
   753                        aForeground, aStretch, aBorderMargin, aWidth, aHeight );
       
   754         }
       
   755     }
       
   756 
       
   757 // -----------------------------------------------------------------------------
       
   758 // RemoveIconL
       
   759 // -----------------------------------------------------------------------------
       
   760 //   
       
   761 TBool CGlxVisualListControl::RemoveIcon( TInt aListIndex, const CAlfTexture& aTexture )
       
   762     {
       
   763     TRACER("CGlxVisualListControl::RemoveIcon");
       
   764     GLX_LOG_INFO("CGlxVisualListControl::RemoveIcon");
       
   765     TBool iconRemoved = EFalse;
       
   766     
       
   767     CGlxVisualObject* visItem = Item( aListIndex );
       
   768     if( visItem )
       
   769         {
       
   770         iconRemoved = visItem->RemoveIcon( aTexture );
       
   771         }
       
   772     
       
   773     return iconRemoved;
       
   774     }    
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // SetIconVisibility
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 void CGlxVisualListControl::SetIconVisibility( TInt aListIndex, 
       
   781                                 const CAlfTexture& aTexture, TBool aVisible )
       
   782     {
       
   783     TRACER("CGlxVisualListControl::SetIconVisibility");
       
   784     GLX_LOG_INFO("CGlxVisualListControl::SetIconVisibility");
       
   785     CGlxVisualObject* visItem = Item( aListIndex );
       
   786     if( visItem )
       
   787         {
       
   788         visItem->SetIconVisibility( aTexture, aVisible );
       
   789         }
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // VisualObjectLayoutRefreshed
       
   794 // -----------------------------------------------------------------------------
       
   795 //
       
   796 void CGlxVisualListControl::VisualObjectLayoutRefreshed(TInt aListIndex ,TSize /*aScreensize*/)
       
   797     {
       
   798     TRACER("CGlxVisualListControl::VisualObjectLayoutRefreshed");
       
   799     GLX_LOG_INFO("CGlxVisualListControl::VisualObjectLayoutRefreshed");
       
   800      iLayoutObserver->UpdateLayout( * ( Visual ( aListIndex ) ) );
       
   801     }
       
   802