menufw/menufwui/mmwidgets/src/mmgridview.cpp
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikfrlbd.h>
       
    20 
       
    21 #include "mmgridview.h"
       
    22 #include "mmgrid.h"
       
    23 #include "mmlistboxitemdrawer.h"
       
    24 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    25 #include <aknlistloadertfx.h>
       
    26 #include <aknlistboxtfxinternal.h>
       
    27 #endif
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CMmGridView::CMmGridView() :
       
    35     iLastCurMove( ECursorFirstItem ), iOldIndex( KErrNotFound )
       
    36     {
       
    37     // No implementation required
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMmGridView::~CMmGridView()
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CMmGridView* CMmGridView::NewLC()
       
    53     {
       
    54     CMmGridView* self = new (ELeave)CMmGridView();
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CMmGridView* CMmGridView::NewL()
       
    65     {
       
    66     CMmGridView* self = CMmGridView::NewLC();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CMmGridView::ConstructL()
       
    76     {
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 TPoint CMmGridView::ItemPos( TInt aItemIndex ) const
       
    84     {
       
    85     if ( aItemIndex < 0 )
       
    86         {
       
    87         // let avkon handle the insane cases
       
    88         return CAknGridView::ItemPos( aItemIndex );
       
    89         }
       
    90 
       
    91     if ( AknLayoutUtils::LayoutMirrored() )
       
    92         {
       
    93         const TInt colNum = NumberOfColsInView();
       
    94         TInt itemCol = aItemIndex % colNum;
       
    95         TInt mirroredItemCol = colNum - itemCol - 1;
       
    96         aItemIndex = aItemIndex - itemCol + mirroredItemCol;
       
    97         }
       
    98     
       
    99     // return CAknGridView::ItemPos( aItemIndex );
       
   100     return CorrectItemPos( aItemIndex );
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 TPoint CMmGridView::CorrectItemPos( TInt aItemIndex ) const
       
   108     {
       
   109     // it the assertion below fails, review this implementation to make sure that
       
   110     // primary vertical case is handled correctly
       
   111     ASSERT( !IsPrimaryVertical() );
       
   112     
       
   113     ASSERT( aItemIndex >= 0 );
       
   114     const TInt colNum = NumberOfColsInView();
       
   115     TInt itemRow = aItemIndex / colNum;
       
   116     TInt itemCol = aItemIndex % colNum;
       
   117     
       
   118     TInt topItemRow = TopItemIndex() / colNum;
       
   119 //    __ASSERT_DEBUG( TopItemIndex() % colNum == 0, User::Invariant() );
       
   120     
       
   121     // it is safe to assume that size between items is (0, 0) because we
       
   122     // explicitly set such value in CMmGrid::DoSetupLayoutL
       
   123     const TSize sizeBetweenItems( 0, 0 );
       
   124     
       
   125     TPoint itemPos(
       
   126         iViewRect.iTl.iX + itemCol *
       
   127             ( ColumnWidth() + sizeBetweenItems.iWidth ),
       
   128         iViewRect.iTl.iY + (itemRow - topItemRow) *
       
   129             ( iItemHeight + sizeBetweenItems.iHeight ) + iVerticalOffset );
       
   130 
       
   131     return itemPos;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TBool CMmGridView::XYPosToItemIndex( TPoint aPosition, TInt& aItemIndex ) const
       
   139     {
       
   140     if ( AknLayoutUtils::LayoutMirrored() )
       
   141         {
       
   142         aPosition.iX = iViewRect.Width() - ( aPosition.iX - iViewRect.iTl.iX );
       
   143         }
       
   144     return CAknGridView::XYPosToItemIndex( aPosition, aItemIndex );
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 CWindowGc* CMmGridView::Gc()
       
   152     {
       
   153     return iGc;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CMmGridView::MoveCursorL( TCursorMovement aCursorMovement,
       
   161         TSelectionMode aSelectionMode )
       
   162     {
       
   163 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   164     iLastCurMove = aCursorMovement;
       
   165     iOldIndex = iCurrentItemIndex;
       
   166 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   167 
       
   168     CAknGridView::MoveCursorL( aCursorMovement, aSelectionMode );
       
   169 
       
   170 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   171     iLastCurMove = ECursorFirstItem;
       
   172     iOldIndex = KErrNotFound;
       
   173 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CMmGridView::UpdateSelectionL( TSelectionMode aSelectionMode )
       
   181     {
       
   182 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
   183     if ( AknLayoutUtils::LayoutMirrored() )
       
   184         {
       
   185         MAknListBoxTfxInternal* api = CAknListLoader::TfxApiInternal( Gc() );
       
   186         TInt row( 0 );
       
   187         TInt col( 0 );
       
   188         TInt newRow( 0 );
       
   189         TInt newCol( 0 );
       
   190         LogicalPosFromListBoxIndex( iOldIndex, row, col );
       
   191         LogicalPosFromListBoxIndex( iCurrentItemIndex, newRow, newCol );
       
   192         if ( api )
       
   193             {
       
   194             if ( iLastCurMove == CAknGridView::ECursorNextColumn )
       
   195                 {
       
   196                 if ( newCol < col || newRow != row )
       
   197                     api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement );
       
   198                 }
       
   199             else if ( iLastCurMove == CAknGridView::ECursorPreviousColumn )
       
   200                 {
       
   201                 if ( newCol > col || newRow != row )
       
   202                     api->SetMoveType( MAknListBoxTfxInternal::EListNoMovement );
       
   203                 }
       
   204             }
       
   205         }
       
   206 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
   207 
       
   208     CAknGridView::UpdateSelectionL( aSelectionMode );
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CMmGridView::Draw(const TRect* aClipRect) const
       
   216     {
       
   217     const_cast<CMmGridView*>( this )->UpdateItemHeightAndWidth();
       
   218     DoDraw( aClipRect );
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CMmGridView::DoDraw(const TRect* aClipRect) const
       
   226     {
       
   227     CMmListBoxItemDrawer* itemDrawer = static_cast< CMmListBoxItemDrawer*> ( ItemDrawer() );
       
   228     TBool drawingInitiated(EFalse);
       
   229     if ( CAknEnv::Static()->TransparencyEnabled() &&
       
   230     		iWin && iWin->GetDrawRect() == TRect::EUninitialized )
       
   231     	{
       
   232     	TRect a;
       
   233     	if (!aClipRect || *aClipRect == TRect(0,0,0,0) )
       
   234     		{
       
   235     		a = ViewRect();
       
   236     		aClipRect = &a;
       
   237     		}
       
   238 
       
   239     	drawingInitiated=ETrue;
       
   240 		iWin->Invalidate( *aClipRect );
       
   241 		iWin->BeginRedraw( *aClipRect );
       
   242     	}
       
   243     CAknGridView::Draw( aClipRect );
       
   244 
       
   245 	if ( aClipRect )
       
   246 	    {
       
   247     	TRect rect(*aClipRect);
       
   248     	TInt lastItemInView = (iModel->NumberOfItems() <= BottomItemIndex() )
       
   249     	    ? iModel->NumberOfItems()-1 : BottomItemIndex();
       
   250     	rect.iTl.iY = ItemPos( lastItemInView ).iY + ItemSize( lastItemInView ).iHeight;
       
   251 //      iGc->SetClippingRect( rect );
       
   252 //		removed to prevent non-redraw drawing. Was present to prevent out of view drawing when effects are on.
       
   253 //      could be removed because effects were disabled at some point in edit mode to enhance performance.
       
   254     	itemDrawer->DrawFloatingItems( rect );
       
   255 //      iGc->CancelClippingRect();
       
   256 	    }
       
   257 
       
   258 //    if (aClipRect)
       
   259 //    	{
       
   260 //    	const_cast< CMmGridView* >(this)->Gc()->DrawRect(*aClipRect);
       
   261 //    	}
       
   262 
       
   263     if ( CAknEnv::Static()->TransparencyEnabled() &&
       
   264     		iWin && drawingInitiated )
       
   265     	{
       
   266     	drawingInitiated = EFalse;
       
   267     	iWin->EndRedraw( );
       
   268     	}
       
   269 
       
   270 	}
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TInt CMmGridView::VerticalItemOffset() const
       
   277 	{
       
   278 	return iVerticalOffset;
       
   279 	}
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 void CMmGridView::SetItemHeight(TInt aItemHeight)
       
   286 	{
       
   287 	//	we need to update the iItemHeight member in grid also (there are two different item height value holders - in grid and here in grid view)
       
   288 	CMmListBoxItemDrawer* itemDrawer =
       
   289 	        STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() );
       
   290 	static_cast<CMmGrid*>(itemDrawer->Widget())->SetItemHeight( aItemHeight );
       
   291 	
       
   292 	CAknGridView::SetItemHeight(aItemHeight);
       
   293 	}
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CMmGridView::UpdateItemHeightAndWidth()
       
   300     {
       
   301     if ( iModel && iModel->NumberOfItems() )
       
   302         {
       
   303         CMmListBoxItemDrawer* itemDrawer =
       
   304                 STATIC_CAST( CMmListBoxItemDrawer*, ItemDrawer() );
       
   305         TSize size = itemDrawer->GetItemSize( 0, EFalse );
       
   306         if ( itemDrawer->ItemCellSize() != size  )
       
   307             {
       
   308             const_cast<CMmGridView*>( this )->SetItemHeight( size.iHeight );
       
   309             const_cast<CMmGridView*>( this )->SetColumnWidth( size.iWidth );
       
   310             }
       
   311         }
       
   312     }
       
   313 
       
   314 //End of file