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