photosgallery/viewframework/visuallistmanager/src/glxvisuallistwindow.cpp
changeset 0 4e91876724a2
child 9 6b87b143d312
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 "glxvisuallistwindow.h" 
       
    26 
       
    27 #include <coemain.h>
       
    28 #include <alf/alfimagevisual.h>
       
    29 #include <alf/alfanchorlayout.h>
       
    30 #include <alf/alfenv.h> 
       
    31 #include <alf/alfbrush.h>
       
    32 #include <alf/alfcontrolgroup.h>
       
    33 #include <alf/alfborderbrush.h>
       
    34 #include <alf/alfdecklayout.h>
       
    35 #include <glxlog.h>
       
    36 #include <glxtracer.h>
       
    37 #include <mpxmediageneraldefs.h>
       
    38 #include <AknUtils.h>
       
    39 #include "mglxmedialistobserver.h"
       
    40 #include "glxuiutility.h"
       
    41 #include "glxitemvisual.h"
       
    42 #include <glxtexturemanager.h>
       
    43 #include "glxvisuallistcontrol.h"
       
    44 #include <mglxanimation.h>
       
    45 #include <mglxmedialist.h>
       
    46 #include <glxthumbnailutility.h>
       
    47 #include <glxuistd.h>
       
    48 #include "glxlistwindow.h"
       
    49 #include "glxitemvisual.h"
       
    50 // -----------------------------------------------------------------------------
       
    51 // Constructor
       
    52 // -----------------------------------------------------------------------------
       
    53 CGlxVisualListWindow* CGlxVisualListWindow::NewL( CGlxVisualListControl* aControl,
       
    54     MGlxMediaList* aMediaList, CGlxUiUtility* aUiUtility,
       
    55         CAlfImageVisual::TScaleMode aThumbnailScaleMode )
       
    56     {
       
    57     TRACER("CGlxVisualListWindow::NewL");
       
    58     GLX_LOG_INFO("CGlxVisualListWindow::NewL");
       
    59     CGlxVisualListWindow* self = new (ELeave) CGlxVisualListWindow();
       
    60     CleanupStack::PushL( self );
       
    61     
       
    62     self->iControl = aControl;    
       
    63     self->iMediaList = aMediaList;
       
    64     self->iUiUtility = aUiUtility;
       
    65     self->iScaleMode = aThumbnailScaleMode;
       
    66     self->ConstructL(); // Construct base class
       
    67     
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70   
       
    71     }
       
    72       
       
    73       
       
    74  CGlxVisualListWindow::CGlxVisualListWindow(): 
       
    75  	CGlxListWindow( static_cast< MGlxWindowObjectFactory& > ( *this ) )
       
    76 	 {
       
    77 	 	
       
    78 	 }
       
    79  
       
    80 CBase* CGlxVisualListWindow::CreateObjectL() const
       
    81 	{
       
    82 	TRACER("CGlxVisualListWindow::CreateObjectL");
       
    83     GLX_LOG_INFO("CGlxVisualListWindow::CreateObjectL");
       
    84 	
       
    85 	CGlxVisualObject* object = CGlxVisualObject::NewLC( *(const_cast<CGlxVisualListWindow*>(this)) ,*iMediaList  );
       
    86 	CleanupStack::Pop( object );
       
    87 	return object;
       
    88 	
       
    89 	}
       
    90 	
       
    91 	
       
    92  void CGlxVisualListWindow::SetupObject(TInt aIndex, CBase& aObject ) 
       
    93 	 {
       
    94 	 TRACER("CGlxVisualListWindow::SetupObject");
       
    95 	 GLX_LOG_INFO("CGlxVisualListWindow::SetupObject");
       
    96 	 TRAP_IGNORE(SetupObjectL( aIndex, aObject ));
       
    97 	 }
       
    98 // -----------------------------------------------------------------------------
       
    99 // SetupObjectL
       
   100 // -----------------------------------------------------------------------------
       
   101 void CGlxVisualListWindow::SetupObjectL( TInt aIndex, CBase& aObject )
       
   102     {
       
   103     TRACER("CGlxVisualListWindow::SetupObjectL 2");
       
   104     GLX_LOG_INFO("CGlxVisualListWindow::SetupObjectL 2");
       
   105     CGlxVisualObject& object = static_cast< CGlxVisualObject& >( aObject );
       
   106 	// set the index
       
   107 	object.SetIndex( aIndex );
       
   108     
       
   109     // No easy way to get rid of this trap. Would be possible to do
       
   110     // multiple objects within the same trap by modifying the CGlxListWindowBase
       
   111     // but would be surprising if this TRAP is a actually a performance problem
       
   112 
       
   113     // create texture from thumbnail 
       
   114     //TSize visSize = object.Visual()->Size().ValueNow().AsSize();
       
   115 	TSize visSize =iUiUtility->DisplaySize();
       
   116     
       
   117     CAlfTexture* texture = NULL; 
       
   118     
       
   119     // media will be null if aMedia's Properties are not available
       
   120     // so furtur operation need to be cancle
       
   121     if ( iMediaList->Item( aIndex ).Properties() == NULL)
       
   122         {
       
   123         texture = &iUiUtility->Env()->TextureManager().BlankTexture(); 
       
   124         } 
       
   125     else
       
   126         {
       
   127         TRAPD(err, texture = &iUiUtility->GlxTextureManager().CreateThumbnailTextureL(
       
   128                 iMediaList->Item( aIndex ),iMediaList->IdSpaceId( aIndex ), visSize, &object ));
       
   129         if(err != KErrNone)
       
   130             {        
       
   131             texture = &iUiUtility->Env()->TextureManager().BlankTexture();        
       
   132             }
       
   133         }   
       
   134     // add the texture and its id for the visual object
       
   135 	object.SetImage(TAlfImage( *texture  ));
       
   136 	
       
   137 	TSize imageSize ;
       
   138 	iMediaList->Item( aIndex ).GetDimensions(imageSize);	
       
   139     // Set scale mode to EScaleFitInside if the Image is bigger then screen
       
   140     // or to scale the grid size thumbnails if full thumbnail is not available while fast swipe
       
   141 	if ( imageSize.iWidth >= visSize.iWidth || imageSize.iHeight >= visSize.iHeight 
       
   142 			||(texture->Size().iHeight < imageSize.iHeight  && texture->Size().iWidth < imageSize.iWidth ))
       
   143 		{
       
   144 		object.SetScaleMode(CAlfImageVisual::EScaleFitInside);		
       
   145 		}		
       
   146 			    
       
   147     // show the object. do this before notifying control, to show
       
   148     // at the image if control leaves
       
   149     object.SetVisible( ETrue );
       
   150     
       
   151     // notify observer
       
   152     iControl->HandleVisualAddedL( object.Visual(), aIndex );
       
   153     }
       
   154 
       
   155  void CGlxVisualListWindow::CleanupObject(TInt aListIndex, CBase& aObject) 
       
   156 	{
       
   157 	TRACER("CGlxVisualListWindow::CleanupObject");
       
   158     GLX_LOG_INFO("CGlxVisualListWindow::CleanupObject");
       
   159 	CGlxVisualObject& object = static_cast< CGlxVisualObject& >( aObject );
       
   160 
       
   161     object.Reset();
       
   162     
       
   163 	iControl->HandleVisualRemoved( object.Visual() );	
       
   164 	}
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // GetObjectL
       
   168 // -----------------------------------------------------------------------------
       
   169 CGlxVisualObject* CGlxVisualListWindow::GetObjectL( TInt aListIndex )
       
   170 	{
       
   171 	TRACER("CGlxVisualListWindow::GetObjectL");
       
   172     GLX_LOG_INFO1("CGlxVisualListWindow::GetObjectL %d", aListIndex);
       
   173 	// create the object
       
   174     CGlxVisualObject* listObj = 
       
   175         CGlxVisualObject::NewLC( *this, *iMediaList );
       
   176     CleanupStack::Pop( listObj );
       
   177 	return listObj;
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CleanupObject
       
   182 // -----------------------------------------------------------------------------
       
   183 void CGlxVisualListWindow::CleanupObject( TInt aWindowIndex )
       
   184 	{
       
   185 	TRACER("CGlxVisualListWindow::CleanupObject 2");
       
   186     GLX_LOG_INFO1("CGlxVisualListWindow::CleanupObject 2 %d",aWindowIndex);
       
   187 	CGlxVisualObject* item = ObjectByIndex( aWindowIndex);
       
   188 	CAlfVisual* visual = item->Visual();
       
   189 	
       
   190 	iControl->HandleVisualRemoved( visual );
       
   191 	}
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // PostObjectsAdded
       
   195 // -----------------------------------------------------------------------------	
       
   196 void CGlxVisualListWindow::PostObjectsAdded( RArray<TInt>& aAddedAtListIndexes )	
       
   197     {
       
   198     /*
       
   199    TInt count = aAddedAtListIndexes.Count();
       
   200     // step through array and notify our observers
       
   201     // cant leave so need to just ignore the error
       
   202     TRAP_IGNORE( 
       
   203         {
       
   204         for(TInt i = 0; i < count; i++ )
       
   205             {
       
   206             TInt listIdx = aAddedAtListIndexes[i];
       
   207             //TInt idx =  ListIndexToWindowIndex( listIdx );
       
   208             //CGlxVisualObject* item = ObjectByIndex( idx);
       
   209     	    //iControl->HandleVisualAddedL( item->Visual(), listIdx );
       
   210             }
       
   211         }); 
       
   212        */
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // SetFocusIndexL
       
   217 // -----------------------------------------------------------------------------
       
   218 void CGlxVisualListWindow::SetFocusIndexL( TInt aFocusIndex )
       
   219 	{
       
   220 	TRACER("CGlxVisualListWindow::SetFocusIndexL");
       
   221     GLX_LOG_INFO1("CGlxVisualListWindow::SetFocusIndexL %d",aFocusIndex);
       
   222 	CGlxListWindow::SetFocusIndex( aFocusIndex );
       
   223 	
       
   224 	UpdatePositions();
       
   225 
       
   226 	}
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // UpdatePositions
       
   230 // -----------------------------------------------------------------------------
       
   231 void CGlxVisualListWindow::UpdatePositions()
       
   232 	{
       
   233 	TRACER("CGlxVisualListWindow::UpdatePositions");
       
   234     GLX_LOG_INFO("CGlxVisualListWindow::UpdatePositions");
       
   235 	// Set positions of items in the window to current list index.
       
   236     TGlxWindowIterator iterator = Iterator();
       
   237     TInt index = 0;
       
   238     while ( KErrNotFound != ( index = iterator++ ) )
       
   239         {
       
   240 		CGlxVisualObject* visualObj = ObjectByIndex( index );
       
   241 		// set index for the visual
       
   242 		visualObj->SetIndex( index );
       
   243 		// get screen size
       
   244 		TSize screenSize = iUiUtility->DisplaySize();
       
   245 		// update the layout data
       
   246 		visualObj->RefreshLayout(screenSize);                        
       
   247         }
       
   248 	}
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // Layout
       
   252 // -----------------------------------------------------------------------------
       
   253 CAlfLayout* CGlxVisualListWindow::Layout()
       
   254 	{
       
   255 	TRACER("CGlxVisualListWindow::Layout");
       
   256     GLX_LOG_INFO("CGlxVisualListWindow::Layout");
       
   257 	return static_cast<CAlfLayout*>(iControl->iParentLayout);
       
   258 	}
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // VisualOwner
       
   262 // -----------------------------------------------------------------------------
       
   263 CAlfControl& CGlxVisualListWindow::VisualOwner()
       
   264 	{
       
   265 	TRACER("CGlxVisualListWindow::VisualOwner");
       
   266     GLX_LOG_INFO("CGlxVisualListWindow::VisualOwner");
       
   267 	return *iControl;
       
   268 	}
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // BorderBrush
       
   272 // -----------------------------------------------------------------------------
       
   273 CAlfBrush* CGlxVisualListWindow::BorderBrush()
       
   274 	{
       
   275 	TRACER("CGlxVisualListWindow::BorderBrush");
       
   276     GLX_LOG_INFO("CGlxVisualListWindow::BorderBrush");
       
   277 	return iControl->iBorderBrush;
       
   278 	}
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // ThumbnailScaleMode
       
   282 // -----------------------------------------------------------------------------
       
   283 CAlfImageVisual::TScaleMode CGlxVisualListWindow::ThumbnailScaleMode()
       
   284     {
       
   285     TRACER("CGlxVisualListWindow::ThumbnailScaleMode");
       
   286     GLX_LOG_INFO("CGlxVisualListWindow::ThumbnailScaleMode");
       
   287     return iScaleMode;
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // Return visual object by index
       
   292 // -----------------------------------------------------------------------------
       
   293 CGlxVisualObject* CGlxVisualListWindow::ObjectByIndex( TInt aIndex ) 
       
   294     {
       
   295     TRACER("CGlxVisualListWindow::ObjectByIndex");
       
   296     GLX_LOG_INFO("CGlxVisualListWindow::ObjectByIndex");
       
   297     return static_cast< CGlxVisualObject* >( At( aIndex ) );
       
   298     }
       
   299