uifw/ganes/src/HgList.cpp
changeset 47 2f0c06423c72
parent 46 0e1e0022bd03
child 53 3c67ea82fafc
equal deleted inserted replaced
46:0e1e0022bd03 47:2f0c06423c72
     1 /*
       
     2 * Copyright (c) 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:     
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <ganes/HgList.h>
       
    21 #include <ganes/HgItem.h>
       
    22 
       
    23 #include "HgLayoutData.h"
       
    24 #include "HgDrawUtils.h"
       
    25 
       
    26 #include <aknphysics.h>
       
    27 
       
    28 #include "HgConstants.h"
       
    29 #include "HgMarquee.h"
       
    30 
       
    31 #include <AknIconUtils.h>
       
    32 #include <avkon.mbg>
       
    33 #include <AknUtils.h> //AknLayoutUtils
       
    34 #include <gdi.h> // CFont
       
    35 #include <AknsUtils.h>
       
    36 #include <AknsDrawUtils.h>
       
    37 #include <AknsConstants.h>
       
    38 #include <AknsFrameBackgroundControlContext.h>
       
    39 #include <gulicon.h>
       
    40 
       
    41 #include <layoutmetadata.cdl.h>
       
    42 #include <aknlayoutscalable_avkon.cdl.h>
       
    43 
       
    44 // UI Constants
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CHgList::ConstructL()
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CHgList::ConstructL (const TRect& aRect, RWsSession* aSession )
       
    54     {
       
    55     // Inherited classes might use some custom layout data, so lets use the
       
    56     // default one only if not yet initialized.
       
    57     if( !iLayoutData )
       
    58         iLayoutData = CHgListLayoutData::NewL();
       
    59     
       
    60     CHgScroller::ConstructL( aRect, aSession );
       
    61     
       
    62     // Activate the window, which makes it ready to be drawn
       
    63     ActivateL ( );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CHgList::CHgList()
       
    68 // C++ default constructor can NOT contain any code, that might leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CHgList::CHgList( TInt aItemCount, 
       
    72         CGulIcon* aDefaultIcon )
       
    73 : CHgScroller( aItemCount, aDefaultIcon ),
       
    74     iColor( KRgbBlack ),
       
    75     iColorBack( AKN_LAF_COLOR( 0 ) ),
       
    76     iHighlightedColor( KRgbBlack ),
       
    77     iHighlightedColorBack( AKN_LAF_COLOR( 0 ) )    
       
    78     {
       
    79     SetFlags(EHgScrollerSearchWithQWERTY); // Set QWERTY search on
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CHgList::~CHgList()
       
    84 // Destructor.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 EXPORT_C CHgList::~CHgList ( )
       
    88     {
       
    89     delete iLayoutData;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CHgList::InitItemsL()
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CHgList::InitItemsL()
       
    97     {
       
    98     for(TInt i = 0; i < iItemCount; ++i)
       
    99         {
       
   100         iItems.Append(CHgItem::NewL());
       
   101         }
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CHgList::DrawHighlight()
       
   106 // Called by Draw function to draw the higlighted item effect.
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CHgList::DrawHighlight( const TRect& aRect, TRgb& aTextColor ) const
       
   110     {
       
   111     // Init drawing options
       
   112     TRect outerRect( aRect );
       
   113     TRect innerRect( aRect );
       
   114     innerRect.Shrink(KListHighlightInnerRectShrink,KListHighlightInnerRectShrink);
       
   115     
       
   116     CWindowGc& gc = SystemGc();
       
   117     
       
   118     // Draw "selected item" rect for the row. Bitmaps to draw the rect are feched from 
       
   119     // current skin instance.
       
   120     if( HasHighlight() )
       
   121         {
       
   122         if( iPointerDown && !iPanning && iFocusedIndex != KErrNotFound && iSelectionToFocusedItem )
       
   123             {
       
   124             AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(),
       
   125                                         gc,
       
   126                                         outerRect,
       
   127                                         innerRect,
       
   128                                         KAknsIIDQsnFrListPressed,
       
   129                                         KAknsIIDQsnFrListCenterPressed );
       
   130             }
       
   131         else
       
   132             {
       
   133             AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(),
       
   134                                         gc,
       
   135                                         outerRect,
       
   136                                         innerRect,
       
   137                                         KAknsIIDQsnFrList,
       
   138                                         KAknsIIDQsnFrListCenter );
       
   139             }
       
   140         aTextColor = iHighlightedColor;
       
   141         }
       
   142     else if( iPointerDown && !iPanning )
       
   143         {
       
   144         AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(),
       
   145                                     gc,
       
   146                                     outerRect,
       
   147                                     innerRect,
       
   148                                     KAknsIIDQsnFrList,
       
   149                                     KAknsIIDQsnFrListCenter );
       
   150         }
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CHgList::HandleSizeChanged()
       
   155 // Called by framework when the view size is changed.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CHgList::HandleSizeChanged ( )
       
   159     {
       
   160     iLandscapeScrolling = EFalse; // list always scrolls in portrait mode
       
   161     iRows = iItemCount;
       
   162     
       
   163     // Resolve colors for normal and higlighted items            
       
   164     if ( AknsUtils::AvkonSkinEnabled() )
       
   165         {
       
   166         // this does not modify color unless it gets a correct one
       
   167         // no real need to check errors
       
   168         AknsUtils::GetCachedColor( 
       
   169                 AknsUtils::SkinInstance(),
       
   170                 iColor,
       
   171                 KAknsIIDQsnTextColors,
       
   172                 EAknsCIQsnTextColorsCG6 );                
       
   173         
       
   174         AknsUtils::GetCachedColor( 
       
   175                 AknsUtils::SkinInstance(),
       
   176                 iHighlightedColor,
       
   177                 KAknsIIDQsnTextColors,
       
   178                 EAknsCIQsnTextColorsCG10 );
       
   179         }
       
   180     iLayoutData->SetBaseLayout(AknLayoutScalable_Avkon::list_gen_pane(0));
       
   181 
       
   182     if( iFlags & CHgScroller::EHgScrollerFlatStatusPane )
       
   183         {
       
   184         iListOffset = TPoint(0,0);
       
   185         }
       
   186     else
       
   187         {
       
   188         TAknLayoutRect foobar;
       
   189         foobar.LayoutRect(Rect(), AknLayoutScalable_Avkon::listscroll_gen_pane(0));
       
   190         
       
   191         iWidth = foobar.Rect().Width();
       
   192         iHeight = foobar.Rect().Height();
       
   193         iListOffset = foobar.Rect().iTl;
       
   194         }
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CHgList::DoDraw()
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CHgList::DoDraw(const TRect& /*aRect*/ ) const
       
   202     {
       
   203     // Calculate the displacement. How much of the first row is showing.
       
   204     TInt ydiff = (iViewPosition.iY-(iHeight/2))%(iRowHeight);
       
   205     
       
   206     CWindowGc& gc = SystemGc();
       
   207     
       
   208     if( iItemCount == 0 )
       
   209         {
       
   210         if( iEmptyText )
       
   211             iDrawUtils->DrawEmptyText(gc, Rect(), *iEmptyText, iColor);
       
   212         }
       
   213     else
       
   214         {
       
   215         // Get the row rect
       
   216         TAknLayoutRect layout;
       
   217         layout.LayoutRect(ListRect(), iLayoutData->ItemLayout());
       
   218         
       
   219         ResetClippingRect(gc);
       
   220         
       
   221         // Draw rows
       
   222         for(TInt i = iCurrentRow; i < iRows && i < iItems.Count(); ++i)
       
   223             {
       
   224             // Topleft position of the row.
       
   225             TPoint point(
       
   226                     0, 
       
   227                     ((i-iCurrentRow)*iRowHeight) - ydiff);
       
   228 
       
   229             if( i < 0 || point.iY < iListOffset.iY - layout.Rect().Height() )
       
   230                 continue; // Not a real row
       
   231             else if( point.iY + iListOffset.iY > iHeight )
       
   232                 break; // Row is now showing on the screen, we can stop. 
       
   233             
       
   234             
       
   235             TRect rect(layout.Rect());
       
   236             // Move to correct y-position
       
   237             rect.Move(point);
       
   238             DrawItem( i, rect );
       
   239             }
       
   240         gc.CancelClippingRect();
       
   241         }
       
   242     }
       
   243 
       
   244 
       
   245 void CHgList::ResetClippingRect( CWindowGc& aGc ) const
       
   246     {
       
   247     if( !(iFlags & CHgScroller::EHgScrollerFlatStatusPane) )
       
   248         aGc.SetClippingRect( TRect(iListOffset, TSize(iWidth, iHeight+2)) );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CHgList::TotalSize()
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TSize CHgList::TotalSize() const 
       
   256     {
       
   257     return TSize( iWidth, iRows*iRowHeight );
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CHgList::GetSelected()
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 TInt CHgList::GetSelected( TPoint aPosition ) const
       
   265     {
       
   266     // Real position is current screen pos + world pos
       
   267     TInt y = aPosition.iY + (iViewPosition.iY - (iHeight/2)) - iListOffset.iY;
       
   268     y /= iRowHeight;
       
   269     return y >= iItems.Count() || y < 0 ? KErrNotFound : y;
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CHgList::DoHandleKeyEvent()
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 TBool CHgList::DoHandleKeyEvent(const TKeyEvent& aKeyEvent)
       
   277     {        
       
   278     TBool ret = ETrue;
       
   279     switch( aKeyEvent.iCode )
       
   280         {
       
   281         case EKeyUpArrow:
       
   282             HandleUpArrow();
       
   283             break;
       
   284         case EKeyDownArrow:
       
   285             HandleDownArrow();
       
   286             break;
       
   287         case EKeyLeftArrow:
       
   288         case EKeyRightArrow:
       
   289         default:
       
   290             ret = EFalse;
       
   291             break;
       
   292         }
       
   293     
       
   294     return ret;
       
   295     }
       
   296 
       
   297 // -----------------------------------------------------------------------------
       
   298 // CHgList::HandleDownArrow()
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 void CHgList::HandleDownArrow()
       
   302     {
       
   303     if( iSelectedIndex == KErrNotFound )
       
   304         {
       
   305         SelectDefaultItem();
       
   306         }
       
   307     else
       
   308         {
       
   309         if( iSelectedIndex <= iRows - 1 )
       
   310             {
       
   311             const TInt nextIndex = iSelectedIndex == (iRows - 1) ? 
       
   312                 0 : iSelectedIndex + 1;
       
   313 
       
   314             if( iSelectionMode == ESelectionMark )
       
   315                 {
       
   316                 Mark( iSelectedIndex );
       
   317                 Mark( nextIndex );
       
   318                 }
       
   319             else if( iSelectionMode == ESelectionUnMark )
       
   320                 {
       
   321                 UnMark( iSelectedIndex );
       
   322                 UnMark( nextIndex );
       
   323                 }
       
   324             iSelectedIndex = nextIndex;
       
   325             FitSelectionToView();
       
   326             SelectionChanged();
       
   327             DrawDeferred();
       
   328             }
       
   329         }
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CHgList::HandleUpArrow()
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CHgList::HandleUpArrow()
       
   337     {    
       
   338     if( iSelectedIndex == KErrNotFound )
       
   339         {
       
   340         SelectDefaultItem();
       
   341         }
       
   342     else
       
   343         {
       
   344         if( iSelectedIndex >= 0 )
       
   345             {
       
   346             const TInt nextIndex = iSelectedIndex == 0 ? 
       
   347                 iRows - 1 : iSelectedIndex - 1;
       
   348             
       
   349             if( iSelectionMode == ESelectionMark )
       
   350                 {
       
   351                 Mark( iSelectedIndex );
       
   352                 Mark( nextIndex );
       
   353                 }
       
   354             else if( iSelectionMode == ESelectionUnMark )
       
   355                 {
       
   356                 UnMark( iSelectedIndex );
       
   357                 UnMark( nextIndex );
       
   358                 }
       
   359             iSelectedIndex = nextIndex;
       
   360             FitSelectionToView();
       
   361             SelectionChanged();
       
   362             DrawDeferred();
       
   363             }
       
   364         }
       
   365     }
       
   366 
       
   367 // -----------------------------------------------------------------------------
       
   368 // CHgList::FitSelectionToView()
       
   369 // -----------------------------------------------------------------------------
       
   370 //
       
   371 void CHgList::FitSelectionToView()
       
   372     {
       
   373     FitRowToView( iSelectedIndex );
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CHgList::ListRect()
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 TRect CHgList::ListRect() const
       
   381     {
       
   382     TRect rect(iListOffset, TSize(iWidth,iHeight));
       
   383     TAknLayoutRect areaaftersb;
       
   384     areaaftersb.LayoutRect(rect, iLayoutData->BaseLayout());
       
   385     return areaaftersb.Rect();
       
   386     }
       
   387 
       
   388 // -----------------------------------------------------------------------------
       
   389 // CHgList::SelectDefaultItem()
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void CHgList::SelectDefaultItem()
       
   393     {
       
   394     iSelectedIndex = iCurrentRow;
       
   395     FitSelectionToView();
       
   396     SelectionChanged();
       
   397 
       
   398     DrawDeferred();
       
   399     }
       
   400 
       
   401 TInt CHgList::CurrentIndex()
       
   402     {
       
   403     return iCurrentRow;
       
   404     }
       
   405 
       
   406 TBool CHgList::IsDisplayed( TInt aIndex )
       
   407     {
       
   408     TInt start = CurrentIndex();
       
   409     TInt rowsPerView = ItemsOnScreen();
       
   410     if( (iViewPosition.iY-(iHeight/2))%(iRowHeight) )
       
   411         ++rowsPerView;
       
   412     TInt end = start + rowsPerView;
       
   413     return aIndex >= start && aIndex <= end;
       
   414     }
       
   415 
       
   416 // -----------------------------------------------------------------------------
       
   417 // CHgList::FitTopItemToView()
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 void CHgList::FitTopItemToView( TInt aIndex )
       
   421     {
       
   422     // Higlighted item is set to top of the list
       
   423     TInt newPos = aIndex*iRowHeight + iHeight/2;
       
   424     
       
   425     if( ItemsOnScreen() >= iItems.Count() )
       
   426         {
       
   427         newPos = iHeight/2;
       
   428         }
       
   429     else
       
   430         {
       
   431         const TInt endMid = TotalSize().iHeight - iHeight/2;
       
   432         if( newPos > endMid )
       
   433             {
       
   434             // We are presenting last items in the list
       
   435             newPos = endMid;
       
   436             }
       
   437         }
       
   438     
       
   439     iViewPosition.iY = newPos;
       
   440     HandleViewPositionChanged();    
       
   441     }
       
   442 
       
   443 // End of File