javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtlistbase.cpp
branchRCL_3
changeset 19 04becd199f91
child 23 98ccebc37403
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #include <eikenv.h>
       
    14 #include <aknenv.h>
       
    15 #include <eikclbd.h>
       
    16 #include <gulicon.h>
       
    17 #include <AknUtils.h>
       
    18 #include <aknappui.h>
       
    19 #include <avkon.mbg>
       
    20 #include <aknconsts.h>
       
    21 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    22 #include <aknlistloadertfx.h>
       
    23 #include <aknlistboxtfx.h>
       
    24 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
    25 #include <swtlaffacade.h>
       
    26 #include "eswtmobileextensions.h"
       
    27 #include "swtfont.h"
       
    28 #include "swtlistbase.h"
       
    29 
       
    30 
       
    31 _LIT(KTextTab, "\t");
       
    32 const TInt KCheckBoxOffIndex = 1;
       
    33 const TInt KCheckBoxOnIndex = 0;
       
    34 const TUint KIconIndexLengthMax = 1;
       
    35 const TInt KVBorderSides = 2;
       
    36 const TInt KHBorderSides = 2;
       
    37 
       
    38 
       
    39 // ======== MEMBER FUNCTIONS ========
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // CSwtListBase::CreateListBoxL
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CEikTextListBox* CSwtListBase::CreateListBoxL(TInt aStyle)
       
    47 {
       
    48     iListType = (aStyle & KSwtStyleMulti) ? ESwtLbSingleGraphic : ESwtLbSingle;
       
    49 
       
    50     CEikTextListBox* listBox = CSwtListBoxLists::NewListL(iListType);
       
    51     CSwtListBoxLists::SetListObserver(iListType, listBox, this);
       
    52 
       
    53 
       
    54     CleanupStack::PushL(listBox);
       
    55     listBox->ConstructL(this, (iStyle & KSwtStyleMulti) ?
       
    56                         EAknListBoxStylusMultiselectionList : EAknListBoxSelectionList);
       
    57 
       
    58 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    59     // Effects do not work with non window owning scrollbars.
       
    60     CWindowGc* gc = listBox->View()->ItemDrawer()->Gc();
       
    61     MAknListBoxTfx* transApi = CAknListLoader::TfxApi(gc);
       
    62     if (transApi)
       
    63     {
       
    64         transApi->EnableEffects(EFalse);
       
    65     }
       
    66 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
    67 
       
    68     listBox->SetContainerWindowL(*this);
       
    69     listBox->SetCurrentItemIndex(0);
       
    70     listBox->MakeVisible(ETrue);
       
    71     listBox->SetComponentsToInheritVisibility();
       
    72     static_cast<CEikColumnListBox*>(listBox)->ItemDrawer()->ColumnData()->SetSkinEnabledL(EFalse);
       
    73 #ifdef RD_SCALABLE_UI_V2
       
    74     listBox->SetListBoxObserver(this);
       
    75 #endif // RD_SCALABLE_UI_V2
       
    76     CleanupStack::Pop(listBox);
       
    77 
       
    78     return listBox;
       
    79 }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CSwtListBase::CreateListBoxModelL
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 void CSwtListBase::CreateListBoxModelL()
       
    86 {
       
    87     iTextItems = new(ELeave) CDesCArrayFlat(3);
       
    88 }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CSwtListBase::CreateScrollBarsL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CSwtListBase::CreateScrollBarsL(CEikTextListBox* aLb)
       
    95 {
       
    96     ASSERT(aLb);
       
    97     aLb->CreateScrollBarFrameL();
       
    98 
       
    99 #ifdef RD_SCALABLE_UI_V2
       
   100     // WARNING!!! The expanded touch area does not move correctly togehter with the scrollbars!
       
   101     aLb->ScrollBarFrame()->SetScrollBarFrameFlags(CEikScrollBarFrame::EDisableExpandedTouchArea);
       
   102 #endif // RD_SCALABLE_UI_V2
       
   103 
       
   104     // In eSWT all scrollbars must be non window owing the main reason being that
       
   105     // the scrollbars must draw at exact same time with the parent control. This
       
   106     // is especially essential in ScrolledComposite. If the scrollbars would be
       
   107     // window owing, they would draw too much ahead of the parents creating an
       
   108     // ugly visual effect when flicking the ScrolledComposite.
       
   109     // The drawback of having non window owing scrollbars is too many paint events
       
   110     // which affects on the speed of kinetic scrolling in lists.
       
   111     aLb->ScrollBarFrame()->CreateDoubleSpanScrollBarsL(EFalse, EFalse, ETrue, EFalse);
       
   112     aLb->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   113         CEikScrollBarFrame::EOff,
       
   114         iStyle & KSwtStyleVScroll ?
       
   115         CEikScrollBarFrame::EOn : CEikScrollBarFrame::EOff);
       
   116 }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // CSwtListBase::CreateIconArrayL
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CSwtListBase::CreateIconArrayL(CEikTextListBox* aLb)
       
   123 {
       
   124     ASSERT(aLb);
       
   125 
       
   126     // Create icon array
       
   127     CArrayPtr<CGulIcon>* icons = new(ELeave)CArrayPtrFlat<CGulIcon>(2);
       
   128     CleanupStack::PushL(icons);
       
   129 
       
   130     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   131 
       
   132     // Check box on
       
   133     CFbsBitmap* bmp = NULL;
       
   134     CFbsBitmap* mask = NULL;
       
   135     CGulIcon* checkBox = NULL;
       
   136     AknsUtils::CreateIconLC(AknsUtils::SkinInstance(),
       
   137                             KAknsIIDQgnPropCheckboxOn, bmp, mask,
       
   138                             AknIconUtils::AvkonIconFileName(),
       
   139                             EMbmAvkonQgn_prop_checkbox_on,
       
   140                             EMbmAvkonQgn_prop_checkbox_on_mask);
       
   141     checkBox = CGulIcon::NewL(bmp, mask);
       
   142     CleanupStack::PushL(checkBox);
       
   143     icons->AppendL(checkBox);
       
   144     CleanupStack::Pop(3);   // bmp, mask, checkbox
       
   145 
       
   146     // Check box off
       
   147     bmp = NULL;
       
   148     mask = NULL;
       
   149     checkBox = NULL;
       
   150     AknsUtils::CreateIconLC(AknsUtils::SkinInstance(),
       
   151                             KAknsIIDQgnPropCheckboxOff, bmp, mask,
       
   152                             AknIconUtils::AvkonIconFileName(),
       
   153                             EMbmAvkonQgn_prop_checkbox_off,
       
   154                             EMbmAvkonQgn_prop_checkbox_off_mask);
       
   155     checkBox = CGulIcon::NewL(bmp, mask);
       
   156     CleanupStack::PushL(checkBox);
       
   157     icons->AppendL(checkBox);
       
   158     CleanupStack::Pop(3);   // bmp, mask, checkbox
       
   159 
       
   160     CleanupStack::Pop(icons);
       
   161 
       
   162     // Set icon array
       
   163     CColumnListBoxData* listBoxData = static_cast<CEikColumnListBox*>(aLb)->ItemDrawer()->ColumnData();
       
   164     if (listBoxData->IconArray())
       
   165     {
       
   166         listBoxData->IconArray()->ResetAndDestroy();
       
   167         delete listBoxData->IconArray();
       
   168     }
       
   169     listBoxData->SetIconArray(icons);
       
   170 }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CSwtListBase::CreateItemTextLC
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 HBufC* CSwtListBase::CreateItemTextLC(
       
   177     const TDesC& aPtr,
       
   178     TBool aSelected)
       
   179 {
       
   180     // Allocate memory for the resut string.
       
   181     TInt textLength = aPtr.Length() + KTextTab().Length();
       
   182     if (iStyle & KSwtStyleMulti)
       
   183     {
       
   184         textLength += KIconIndexLengthMax;
       
   185     }
       
   186     HBufC* textBuf = HBufC::NewLC(textLength);
       
   187     TPtr itemText(textBuf->Des());
       
   188     itemText.Zero();
       
   189     if (iStyle & KSwtStyleMulti)
       
   190     {
       
   191         itemText.AppendNum(aSelected?KCheckBoxOnIndex:KCheckBoxOffIndex);
       
   192     }
       
   193     itemText.Append(KTextTab);
       
   194     itemText.Append(aPtr);
       
   195 
       
   196     return textBuf;
       
   197 }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CSwtListBase::UpdateSize
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CSwtListBase::UpdateSize()
       
   204 {
       
   205     ASSERT(iList);
       
   206     ASSERT(iList->Model());
       
   207 
       
   208     iList->SetSize(BorderInnerRect().Size());
       
   209 }
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CSwtListBase::UpdateListBoxFontL
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CSwtListBase::UpdateListBoxFontL()
       
   216 {
       
   217     ASSERT(iList);
       
   218 
       
   219     CColumnListBoxItemDrawer* itemDrawer = static_cast<CEikColumnListBox*>(iList)->ItemDrawer();
       
   220     ASSERT(itemDrawer);
       
   221     CColumnListBoxData* listBoxData = itemDrawer->ColumnData();
       
   222     ASSERT(listBoxData);
       
   223 
       
   224     // If a font has been set, apply it to the Avkon list. Its item height is also modified.
       
   225     if (iFont)
       
   226     {
       
   227         TInt newItemHeight(
       
   228             iDefaultItemHeight +
       
   229             (iFont->Font().HeightInPixels() - DefaultFont().Font().HeightInPixels()));
       
   230         newItemHeight = Max(iDefaultItemHeight, newItemHeight);
       
   231         iList->SetItemHeightL(newItemHeight);
       
   232         listBoxData->SetColumnFontL(KTextColumnIndex, &iFont->Font());
       
   233         listBoxData->SetColumnBaselinePosL(KTextColumnIndex, 0);
       
   234     }
       
   235 }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CSwtListBase::UpdateListBoxTextColorL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CSwtListBase::UpdateListBoxTextColorL()
       
   242 {
       
   243     ASSERT(iList);
       
   244 
       
   245     // If a text color has been set, apply it to the Avkon list.
       
   246     if (iTextColor)
       
   247     {
       
   248         static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->SetTextColor(
       
   249             TRgb(iTextColor->RgbValue()));
       
   250     }
       
   251     // If no color set, then the default color is retrieved
       
   252     // from the current skin and applied to the Avkon list.
       
   253     else
       
   254     {
       
   255         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   256         TRgb defaultColor;
       
   257         TInt error = AknsUtils::GetCachedColor(
       
   258                          skin,
       
   259                          defaultColor,
       
   260                          KAknsIIDQsnTextColors,
       
   261                          EAknsCIQsnTextColorsCG6);
       
   262 
       
   263         if (!error)
       
   264         {
       
   265             static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->SetTextColor(defaultColor);
       
   266         }
       
   267     }
       
   268 }
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CSwtListBase::Scrollable
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 MSwtScrollable* CSwtListBase::Scrollable()
       
   275 {
       
   276     return this;
       
   277 }
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // CSwtListBase::DeselectItems
       
   281 // ---------------------------------------------------------------------------
       
   282 //
       
   283 void CSwtListBase::DeselectItems(
       
   284     const TInt* aIndices,
       
   285     TInt aCount)
       
   286 {
       
   287     ASSERT(iList);
       
   288     ASSERT(iList->View());
       
   289 
       
   290     if (aIndices)
       
   291     {
       
   292         for (TInt i = 0; i < aCount; i++)
       
   293         {
       
   294             iList->View()->DeselectItem(aIndices[i]);
       
   295         }
       
   296     }
       
   297     TRAP_IGNORE(UpdateListMskL());
       
   298 }
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // CSwtListBase::DeselectItem
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CSwtListBase::DeselectItem(const TInt aIndex)
       
   305 {
       
   306     ASSERT(iList);
       
   307     ASSERT(iList->Model());
       
   308     ASSERT(iList->View());
       
   309 
       
   310     if (iList->Model()->NumberOfItems() == 0
       
   311             || iList->SelectionIndexes()->Count() == 0)
       
   312     {
       
   313         return;
       
   314     }
       
   315 
       
   316     iList->View()->DeselectItem(aIndex);
       
   317     TRAP_IGNORE(UpdateListMskL());
       
   318 }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CSwtListBase::DeselectRange
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 void CSwtListBase::DeselectRange(TInt aStart, TInt aEnd)
       
   325 {
       
   326     ASSERT(iList);
       
   327     ASSERT(iList->Model());
       
   328     ASSERT(iList->View());
       
   329 
       
   330     TInt count = iList->Model()->NumberOfItems();
       
   331     if (count == 0
       
   332             || aStart >= count
       
   333             || iList->SelectionIndexes()->Count() == 0)
       
   334     {
       
   335         return;
       
   336     }
       
   337 
       
   338     if (aStart < 0)
       
   339     {
       
   340         aStart = 0;
       
   341     }
       
   342 
       
   343     if (aEnd >= count)
       
   344     {
       
   345         aEnd = count - 1;
       
   346     }
       
   347 
       
   348     for (TInt i = aStart; i <= aEnd; i++)
       
   349     {
       
   350         iList->View()->DeselectItem(i);
       
   351     }
       
   352     TRAP_IGNORE(UpdateListMskL());
       
   353 }
       
   354 
       
   355 // ---------------------------------------------------------------------------
       
   356 // CSwtListBase::DeselectAll
       
   357 // ---------------------------------------------------------------------------
       
   358 //
       
   359 void CSwtListBase::DeselectAll()
       
   360 {
       
   361     ASSERT(iList);
       
   362     ASSERT(iList->Model());
       
   363 
       
   364     if (iList->Model()->NumberOfItems() == 0
       
   365             || iList->SelectionIndexes()->Count() == 0)
       
   366     {
       
   367         return;
       
   368     }
       
   369 
       
   370     iList->ClearSelection();
       
   371     TRAP_IGNORE(UpdateListMskL());
       
   372 }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // CSwtListBase::GetFocusIndex
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 TInt CSwtListBase::GetFocusIndex() const
       
   379 {
       
   380     ASSERT(iList);
       
   381     ASSERT(iList->Model());
       
   382 
       
   383     if (iList->Model()->NumberOfItems() == 0)
       
   384     {
       
   385         return -1;
       
   386     }
       
   387     return iList->CurrentItemIndex();
       
   388 }
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // CSwtListBase::GetSelectionCount
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 TInt CSwtListBase::GetSelectionCount() const
       
   395 {
       
   396     ASSERT(iList);
       
   397     return iList->SelectionIndexes()->Count();
       
   398 }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // CSwtListBase::GetSelectionIndices
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 const CArrayFix<TInt>* CSwtListBase::GetSelectionIndices() const
       
   405 {
       
   406     ASSERT(iList);
       
   407     return iList->SelectionIndexes();
       
   408 }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CSwtListBase::SelectItemL
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 void CSwtListBase::SelectItemL(TInt aIndex, TBool aScroll)
       
   415 {
       
   416     ASSERT(iList);
       
   417     ASSERT(iList->Model());
       
   418     ASSERT(iList->View());
       
   419 
       
   420     if (aIndex >= iList->Model()->NumberOfItems()
       
   421             || iList->View()->ItemIsSelected(aIndex))
       
   422     {
       
   423         return;
       
   424     }
       
   425 
       
   426     if (!(iStyle & KSwtStyleMulti))
       
   427     {
       
   428         if (aScroll && iList->View()->ViewRect().Height() >= iList->ItemHeight())
       
   429         {
       
   430             iList->View()->VerticalMoveToItemL(aIndex, CListBoxView::ESingleSelection);
       
   431         }
       
   432         else
       
   433         {
       
   434             TInt old = iList->CurrentItemIndex();
       
   435             //we do not call CEikListBox::SetCurrentItemIndex, because we do not want to scroll.
       
   436             iList->View()->SetCurrentItemIndex(aIndex);
       
   437             iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
   438             if (old != -1)
       
   439             {
       
   440                 iList->View()->DrawItem(old);
       
   441             }
       
   442         }
       
   443     }
       
   444     else
       
   445     {
       
   446         iList->View()->SelectItemL(aIndex);
       
   447         if (aScroll)
       
   448         {
       
   449             iList->ScrollToMakeItemVisible(aIndex);
       
   450         }
       
   451     }
       
   452     UpdateListMskL();
       
   453 }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // CSwtListBase::SelectRangeL
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 void CSwtListBase::SelectRangeL(TInt aStart, TInt aEnd)
       
   460 {
       
   461     ASSERT(iList);
       
   462     ASSERT(iList->Model());
       
   463     ASSERT(iList->View());
       
   464 
       
   465     TInt count = iList->Model()->NumberOfItems();
       
   466     if (count == 0 || aStart >= count)
       
   467     {
       
   468         return;
       
   469     }
       
   470 
       
   471     TInt end(aEnd);
       
   472     if (end >= count)
       
   473     {
       
   474         end = count - 1;
       
   475     }
       
   476     TInt start(aStart);
       
   477     if (start < 0)
       
   478     {
       
   479         start = 0;
       
   480     }
       
   481 
       
   482     for (TInt index = start; index <= end; ++index)
       
   483     {
       
   484         iList->View()->SelectItemL(index);
       
   485     }
       
   486     UpdateListMskL();
       
   487 }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 // CSwtListBase::SelectAllL
       
   491 // ---------------------------------------------------------------------------
       
   492 //
       
   493 void CSwtListBase::SelectAllL()
       
   494 {
       
   495     ASSERT(iList);
       
   496     ASSERT(iList->View());
       
   497 
       
   498     for (TInt index = 0; index < iList->Model()->NumberOfItems(); ++index)
       
   499     {
       
   500         iList->View()->SelectItemL(index);
       
   501     }
       
   502     UpdateListMskL();
       
   503 }
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 // CSwtListBase::ShowSelection
       
   507 // ---------------------------------------------------------------------------
       
   508 //
       
   509 void CSwtListBase::ShowSelection() const
       
   510 {
       
   511     ASSERT(iList);
       
   512 
       
   513     if (GetSelectionCount() == 0)
       
   514     {
       
   515         return;
       
   516     }
       
   517 
       
   518     iList->ScrollToMakeItemVisible((*iList->SelectionIndexes())[0]);
       
   519 }
       
   520 
       
   521 // ---------------------------------------------------------------------------
       
   522 // CSwtListBase::PostSelectionEvent
       
   523 // ---------------------------------------------------------------------------
       
   524 //
       
   525 void CSwtListBase::PostSelectionEvent() const
       
   526 {
       
   527     TRAP_IGNORE(iDisplay.PostSelectionEventL(iPeer));
       
   528 }
       
   529 
       
   530 // ---------------------------------------------------------------------------
       
   531 // CSwtListBase::CSwtListBase
       
   532 // ---------------------------------------------------------------------------
       
   533 //
       
   534 CSwtListBase::CSwtListBase(
       
   535     MSwtDisplay& aDisplay,
       
   536     TSwtPeer aPeer,
       
   537     MSwtComposite& aParent,
       
   538     TInt aStyle) :
       
   539         ASwtScrollableBase(aDisplay, aPeer, &aParent, aStyle)
       
   540 {
       
   541 }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // CSwtListBase::~CSwtListBase
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 CSwtListBase::~CSwtListBase()
       
   548 {
       
   549     delete iPrevSelItems;
       
   550     delete iList;
       
   551     delete iTextItems;
       
   552     if (iDefaultFont)
       
   553     {
       
   554         iDefaultFont->RemoveRef();
       
   555     }
       
   556 
       
   557     iRemovedItemIndices.Close();
       
   558     iDefaultFont = NULL;
       
   559     iTextColor = NULL;
       
   560     iCurrentLafFont = NULL;
       
   561 }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // CSwtListBase::ConstructL
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 void CSwtListBase::ConstructL()
       
   568 {
       
   569     CCoeControl& coeParent = iParent->Control()->CoeControl();
       
   570     SetContainerWindowL(coeParent);
       
   571     CCoeControl::MakeVisible(coeParent.IsVisible());
       
   572     CCoeControl::SetDimmed(coeParent.IsDimmed());
       
   573     SetComponentsToInheritVisibility(ETrue);
       
   574 
       
   575     iList = CreateListBoxL(iStyle);
       
   576     CreateScrollBarsL(iList);
       
   577     if (iStyle & KSwtStyleMulti)
       
   578     {
       
   579         CreateIconArrayL(iList);
       
   580     }
       
   581     iPrevSelItems = new(ELeave) CArrayFixFlat<TInt>(1);
       
   582     CreateListBoxModelL();
       
   583 
       
   584     iList->SetPosition(TPoint(GetBorderWidth(), GetBorderWidth()));
       
   585 
       
   586     // Retrieve the default font; a size must be set before retrieving the default font
       
   587     // because the font is set in SizeChanged of Avkon lists.
       
   588     SetSize(TSize(0, 0));
       
   589 
       
   590     UpdateDefaultFontL();
       
   591 
       
   592     // This is indeed necessary, otherwise the background might not be drawn!
       
   593     SetBackground(this);
       
   594 
       
   595     ActivateL();
       
   596 }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // CSwtListBase::UpdateDefaultFontL
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 void CSwtListBase::UpdateDefaultFontL()
       
   603 {
       
   604     ASSERT(iList);
       
   605 
       
   606     CColumnListBoxData* listBoxData =
       
   607         static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->ColumnData();
       
   608     ASSERT(listBoxData);
       
   609     const CFont* font = listBoxData->ColumnFont(KTextColumnIndex);
       
   610 
       
   611     if (font && iCurrentLafFont != font)
       
   612     {
       
   613         if (iDefaultFont)
       
   614         {
       
   615             iDefaultFont->RemoveRef();
       
   616             iDefaultFont = NULL;
       
   617         }
       
   618         iDefaultFont = CSwtFont::NewL(iDisplay.Device(), *font);
       
   619 
       
   620         // Current LAF font retrieved
       
   621         iCurrentLafFont = font;
       
   622 
       
   623         // Default item height retrieved
       
   624         iDefaultItemHeight = iList->ItemHeight();
       
   625     }
       
   626 }
       
   627 
       
   628 // ---------------------------------------------------------------------------
       
   629 // CSwtListBase::HandleResourceChangeL
       
   630 // ---------------------------------------------------------------------------
       
   631 //
       
   632 void CSwtListBase::HandleResourceChangeL(TInt aType)
       
   633 {
       
   634     if (aType == KAknsMessageSkinChange)
       
   635     {
       
   636         CreateIconArrayL(iList);
       
   637     }
       
   638 
       
   639     CAknControl::HandleResourceChange(aType);
       
   640 }
       
   641 
       
   642 // ---------------------------------------------------------------------------
       
   643 // CSwtListBase::GetUserSelectionL
       
   644 // ---------------------------------------------------------------------------
       
   645 //
       
   646 void CSwtListBase::GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems)
       
   647 {
       
   648     if ((iStyle & KSwtStyleMulti) && aCurrSelItems)
       
   649     {
       
   650         iList->View()->GetSelectionIndexesL(aCurrSelItems);
       
   651     }
       
   652 }
       
   653 
       
   654 // ---------------------------------------------------------------------------
       
   655 // CSwtList::CalcNewFocusIndexAndTopItemIndex
       
   656 // ---------------------------------------------------------------------------
       
   657 //
       
   658 void CSwtListBase::CalcFocusIndexAfterItemRemoval(TInt& aNewFocusIndex,
       
   659         const RArray<TInt>& aRemovedItemIndices, TInt aOldFocusIndex) const
       
   660 {
       
   661     ASSERT(iList);
       
   662     ASSERT(iList->View());
       
   663     ASSERT(iList->Model());
       
   664 
       
   665     aNewFocusIndex = aOldFocusIndex;
       
   666 
       
   667     if (aRemovedItemIndices.Count() > 0)
       
   668     {
       
   669         TInt oldItemCount(
       
   670             iList->Model()->NumberOfItems() + aRemovedItemIndices.Count());
       
   671 
       
   672         TInt counter(0);
       
   673         TInt ind = 0;
       
   674         while (ind < aRemovedItemIndices.Count()
       
   675                 && aNewFocusIndex >= aRemovedItemIndices[ind])
       
   676         {
       
   677             counter++;
       
   678             if (aNewFocusIndex == aRemovedItemIndices[ind])
       
   679             {
       
   680                 aNewFocusIndex = (aRemovedItemIndices[ind]+1) % oldItemCount;
       
   681             }
       
   682             ind++;
       
   683         }
       
   684 
       
   685         aNewFocusIndex -= counter;
       
   686         if ((aNewFocusIndex < 0)
       
   687                 || (aNewFocusIndex >= iList->Model()->NumberOfItems()))
       
   688         {
       
   689             aNewFocusIndex = 0;
       
   690         }
       
   691     }
       
   692 }
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // CSwtListBase::MinimumListItemWidth
       
   696 // ---------------------------------------------------------------------------
       
   697 //
       
   698 TInt CSwtListBase::MinimumListItemWidth() const
       
   699 {
       
   700     ASSERT(iTextItems);
       
   701 
       
   702     // Get general list Avkon layout
       
   703     TRect mainRect(TRect::EUninitialized);
       
   704     TAknLayoutRect layoutRect;
       
   705     AknLayoutUtils::LayoutMetricsRect(
       
   706         AknLayoutUtils::EMainPane,
       
   707         mainRect);
       
   708     layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListScrollGenPane, mainRect, 0);
       
   709     layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListGenPane, layoutRect.Rect(), 0);
       
   710 
       
   711     TAknLayoutText txtLayoutRect;
       
   712 
       
   713     if (iStyle & KSwtStyleMulti)
       
   714     {
       
   715         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListSingleGraphicPane, layoutRect.Rect(), 0);
       
   716         txtLayoutRect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::EListSingleGraphicPaneT1, layoutRect.Rect(), 0);
       
   717     }
       
   718     else
       
   719     {
       
   720         layoutRect = CSwtLafFacade::GetLayoutRect(CSwtLafFacade::EListSinglePane, layoutRect.Rect(), 0);
       
   721         txtLayoutRect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::EListSinglePaneT1, layoutRect.Rect(), 0);
       
   722     }
       
   723 
       
   724     if (iFont)
       
   725     {
       
   726         CColumnListBoxData* listBoxData =
       
   727             static_cast<CEikColumnListBox*>
       
   728             (iList)->ItemDrawer()->ColumnData();
       
   729         ASSERT(listBoxData);
       
   730         return (listBoxData->ColumnWidthPixel(KCheckboxColumnIndex)
       
   731                 + iTxtMaxWidth);
       
   732     }
       
   733 
       
   734     TInt diffBrX(Max(0, layoutRect.Rect().iBr.iX - txtLayoutRect.TextRect().iBr.iX));
       
   735 
       
   736     return (txtLayoutRect.TextRect().iTl.iX + diffBrX + iTxtMaxWidth);
       
   737 }
       
   738 
       
   739 // ---------------------------------------------------------------------------
       
   740 // CSwtListBase::PreferredWidth
       
   741 // ---------------------------------------------------------------------------
       
   742 //
       
   743 TInt CSwtListBase::PreferredWidth() const
       
   744 {
       
   745     TInt preferredWidth(0);
       
   746 
       
   747     // Add the border width
       
   748     preferredWidth = GetBorderWidth() * KHBorderSides;
       
   749 
       
   750     // Add the vertical scrollbar space if present
       
   751     if (SbFrame()->ScrollBarExists(CEikScrollBar::EVertical)
       
   752             && SbFrame()->ScrollBarVisibility(CEikScrollBar::EVertical)
       
   753             != CEikScrollBarFrame::EOff)
       
   754     {
       
   755         preferredWidth += iDisplay.UiUtils().ScrollBarBreadth(SbFrame()->VerticalScrollBar());
       
   756     }
       
   757 
       
   758     preferredWidth += MinimumListItemWidth();
       
   759 
       
   760     return preferredWidth;
       
   761 }
       
   762 
       
   763 // ---------------------------------------------------------------------------
       
   764 // CSwtListBase::PreferredWidth
       
   765 // ---------------------------------------------------------------------------
       
   766 //
       
   767 TInt CSwtListBase::PreferredHeight() const
       
   768 {
       
   769     TInt preferredHeight(0);
       
   770 
       
   771     // Add the border width
       
   772     preferredHeight = GetBorderWidth() * KVBorderSides;
       
   773 
       
   774     preferredHeight += iList->CalcHeightBasedOnNumOfItems(
       
   775                            Max(1, iList->Model()->NumberOfItems()));
       
   776 
       
   777     // Add horizontal scrollbar width
       
   778     if (SbFrame()->ScrollBarExists(CEikScrollBar::EHorizontal) &&
       
   779             SbFrame()->ScrollBarVisibility(CEikScrollBar::EHorizontal)
       
   780             != CEikScrollBarFrame::EOff)
       
   781     {
       
   782         preferredHeight += iDisplay.UiUtils().ScrollBarBreadth(
       
   783                                SbFrame()->GetScrollBarHandle(CEikScrollBar::EHorizontal));
       
   784     }
       
   785 
       
   786     return preferredHeight;
       
   787 }
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // CSwtListBase::ComputeTextMaxWidth
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 TInt CSwtListBase::ComputeTextMaxWidth() const
       
   794 {
       
   795     ASSERT(iTextItems);
       
   796 
       
   797     const CFont& font = GetFont()->Font();
       
   798     TInt txtMaxWidth(0);
       
   799     for (TInt ind = 0; ind < iTextItems->Count(); ind++)
       
   800     {
       
   801         txtMaxWidth = Max(txtMaxWidth,
       
   802                           font.TextWidthInPixels((*iTextItems)[ind]));
       
   803     }
       
   804 
       
   805     return txtMaxWidth;
       
   806 }
       
   807 
       
   808 // ---------------------------------------------------------------------------
       
   809 // CSwtListBase::ComputeTextMaxWidth
       
   810 // ---------------------------------------------------------------------------
       
   811 //
       
   812 void CSwtListBase::SetTextMaxWidth(TInt aMaxTxtWidth)
       
   813 {
       
   814     iTxtMaxWidth = aMaxTxtWidth;
       
   815 }
       
   816 
       
   817 // ---------------------------------------------------------------------------
       
   818 // CSwtListBase::UpdateListMSK
       
   819 // ---------------------------------------------------------------------------
       
   820 //
       
   821 void CSwtListBase::UpdateListMskL()
       
   822 {
       
   823     if (AknLayoutUtils::MSKEnabled())
       
   824     {
       
   825         MSwtCommandArranger* cmdArranger = iDisplay.CommandArranger();
       
   826         if (cmdArranger)
       
   827         {
       
   828             cmdArranger->UpdateMSKLabelL();
       
   829         }
       
   830     }
       
   831 }
       
   832 
       
   833 // ---------------------------------------------------------------------------
       
   834 // CSwtListBase::CountComponentControls
       
   835 // From CCoeControl
       
   836 // ---------------------------------------------------------------------------
       
   837 //
       
   838 TInt CSwtListBase::CountComponentControls() const
       
   839 {
       
   840     return iList ? 1 : 0;
       
   841 }
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // CSwtListBase::ComponentControl
       
   845 // From CCoeControl
       
   846 // ---------------------------------------------------------------------------
       
   847 //
       
   848 CCoeControl* CSwtListBase::ComponentControl(TInt /*aIndex*/) const
       
   849 {
       
   850     return iList;
       
   851 }
       
   852 
       
   853 // ---------------------------------------------------------------------------
       
   854 // CSwtListBase::MakeVisible
       
   855 // From CCoeControl
       
   856 // ---------------------------------------------------------------------------
       
   857 //
       
   858 void CSwtListBase::MakeVisible(TBool aVisible)
       
   859 {
       
   860     CCoeControl::MakeVisible(aVisible);
       
   861     FocusabilityChanged();
       
   862 }
       
   863 
       
   864 // ---------------------------------------------------------------------------
       
   865 // CSwtListBase::SetDimmed
       
   866 // From CCoeControl
       
   867 // ---------------------------------------------------------------------------
       
   868 //
       
   869 void CSwtListBase::SetDimmed(TBool aDimmed)
       
   870 {
       
   871     ASSERT(iList);
       
   872 
       
   873     CCoeControl::SetDimmed(aDimmed);
       
   874     iList->SetDimmed(aDimmed);
       
   875     FocusabilityChanged();
       
   876 }
       
   877 
       
   878 // ---------------------------------------------------------------------------
       
   879 // CSwtListBase::OfferKeyEventL
       
   880 // From CCoeControl
       
   881 // ---------------------------------------------------------------------------
       
   882 //
       
   883 TKeyResponse CSwtListBase::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   884         TEventCode aType)
       
   885 {
       
   886     ASSERT(iList);
       
   887     ASSERT(iList->Model());
       
   888 
       
   889     TBool traversalDoIt = ETrue;
       
   890 
       
   891     if ((iStyle & KSwtStyleMulti)
       
   892             && (aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK))
       
   893     {
       
   894         traversalDoIt = EFalse;
       
   895     }
       
   896 
       
   897     if (aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow)
       
   898     {
       
   899         traversalDoIt = EFalse;
       
   900     }
       
   901 
       
   902     if (aKeyEvent.iCode == EKeyDownArrow)
       
   903     {
       
   904         if (iList->CurrentItemIndex() == (iList->Model()->NumberOfItems()-1))
       
   905         {
       
   906             if (GetShell().FindTraversalTargetL(ESwtTraverseArrowNext, *this) != NULL)
       
   907             {
       
   908                 traversalDoIt = ETrue;
       
   909             }
       
   910         }
       
   911     }
       
   912     else if (aKeyEvent.iCode == EKeyUpArrow)
       
   913     {
       
   914         if (iList->CurrentItemIndex() == 0)
       
   915         {
       
   916             if (GetShell().FindTraversalTargetL(ESwtTraverseArrowPrevious, *this) != NULL)
       
   917             {
       
   918                 traversalDoIt = ETrue;
       
   919             }
       
   920         }
       
   921     }
       
   922 
       
   923     return HandleKeyL(aKeyEvent, aType, traversalDoIt);
       
   924 }
       
   925 
       
   926 // ---------------------------------------------------------------------------
       
   927 // CSwtListBase::HandleResourceChange
       
   928 // From CCoeControl
       
   929 // ---------------------------------------------------------------------------
       
   930 //
       
   931 void CSwtListBase::HandleResourceChange(TInt aType)
       
   932 {
       
   933     TRAP_IGNORE(HandleResourceChangeL(aType));
       
   934 }
       
   935 
       
   936 // ---------------------------------------------------------------------------
       
   937 // CSwtListBase::HandlePointerEventL
       
   938 // From CCoeControl
       
   939 // ---------------------------------------------------------------------------
       
   940 //
       
   941 #ifdef RD_SCALABLE_UI_V2
       
   942 void CSwtListBase::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   943 {
       
   944     ASSERT(iList);
       
   945 
       
   946     CEikScrollBarFrame* sbFrame = iList->ScrollBarFrame();
       
   947     CEikScrollBar* vsb = sbFrame ? sbFrame->GetScrollBarHandle(CEikScrollBar::EVertical) : NULL;
       
   948 
       
   949     // Check if we should start scrollbar grabbing
       
   950     if (aPointerEvent.iType == TPointerEvent::EButton1Down && !iVScrollBarGrabsPointerEvents)
       
   951     {
       
   952         if (vsb && vsb->Rect().Contains(aPointerEvent.iPosition))
       
   953         {
       
   954             iVScrollBarGrabsPointerEvents = ETrue;
       
   955         }
       
   956     }
       
   957 
       
   958     // Deliver event to scrollbar
       
   959     if (iVScrollBarGrabsPointerEvents && vsb)
       
   960     {
       
   961         vsb->HandlePointerEventL(aPointerEvent);
       
   962     }
       
   963 
       
   964     // Deliver event to list
       
   965     if (!iVScrollBarGrabsPointerEvents)
       
   966     {
       
   967         // Store the selection on first pointer event.
       
   968         if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   969         {
       
   970             if (iStyle & KSwtStyleMulti)
       
   971             {
       
   972                 // Multi lists
       
   973                 ASSERT(iPrevSelItems);
       
   974                 GetUserSelectionL(iPrevSelItems);
       
   975             }
       
   976             iPrevFocusIndex = iList->View()->CurrentItemIndex();
       
   977         }
       
   978 
       
   979         iList->HandlePointerEventL(aPointerEvent);
       
   980 
       
   981         if (aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   982         {
       
   983             TInt focusIndex = iList->View()->CurrentItemIndex();
       
   984 
       
   985             if (iStyle & KSwtStyleMulti)
       
   986             {
       
   987                 // Multi lists
       
   988                 if ((iList->View()->SelectionIndexes()->Count() != iPrevSelItems->Count()))
       
   989                 {
       
   990                     if (iDisplay.RevertPointerEvent())
       
   991                     {
       
   992                         // Revert newly checked item.
       
   993                         if (iList->View()->ItemIsSelected(focusIndex))
       
   994                         {
       
   995                             iList->View()->DeselectItem(focusIndex);
       
   996                         }
       
   997                         else
       
   998                         {
       
   999                             iList->View()->SelectItemL(focusIndex);
       
  1000                         }
       
  1001                     }
       
  1002                     else
       
  1003                     {
       
  1004                         iDisplay.PostSelectionEventL(iPeer);
       
  1005                     }
       
  1006                 }
       
  1007             }
       
  1008             else
       
  1009             {
       
  1010                 // Single lists
       
  1011                 // Compare the focus index after tap or drag ended
       
  1012                 if (focusIndex != iPrevFocusIndex)
       
  1013                 {
       
  1014                     // Ensure the selection and focus index are in sync.
       
  1015                     iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
  1016 
       
  1017                     // Item focus highlight moved, send selection event.
       
  1018                     // Changing the focus index is not subject to reverting.
       
  1019                     iDisplay.PostSelectionEventL(iPeer);
       
  1020                 }
       
  1021 
       
  1022                 // The default selection is sent from HandleListBoxEventL!
       
  1023             }
       
  1024         }
       
  1025     }
       
  1026 
       
  1027     // Stop scrollbar grabbing
       
  1028     if (iVScrollBarGrabsPointerEvents
       
  1029             && aPointerEvent.iType == TPointerEvent::EButton1Up)
       
  1030     {
       
  1031         iVScrollBarGrabsPointerEvents = EFalse;
       
  1032     }
       
  1033 }
       
  1034 #else //RD_SCALABLE_UI_V2
       
  1035 void CSwtListBase::HandlePointerEventL(
       
  1036     const TPointerEvent& /*aPointerEvent*/)
       
  1037 {
       
  1038 }
       
  1039 #endif //RD_SCALABLE_UI_V2
       
  1040 
       
  1041 // ---------------------------------------------------------------------------
       
  1042 // CSwtListBase::SizeChanged
       
  1043 // From CCoeControl
       
  1044 // ---------------------------------------------------------------------------
       
  1045 //
       
  1046 void CSwtListBase::SizeChanged()
       
  1047 {
       
  1048     UpdateSize();
       
  1049     HandleSizeChanged();
       
  1050 }
       
  1051 
       
  1052 // ---------------------------------------------------------------------------
       
  1053 // CSwtListBase::PositionChanged
       
  1054 // From CCoeControl
       
  1055 // ---------------------------------------------------------------------------
       
  1056 //
       
  1057 void CSwtListBase::PositionChanged()
       
  1058 {
       
  1059     HandlePositionChanged();
       
  1060 }
       
  1061 
       
  1062 // ---------------------------------------------------------------------------
       
  1063 // CSwtListBase::FocusChanged
       
  1064 // From CCoeControl
       
  1065 // ---------------------------------------------------------------------------
       
  1066 //
       
  1067 void CSwtListBase::FocusChanged(TDrawNow aDrawNow)
       
  1068 {
       
  1069     ASSERT(iList);
       
  1070 
       
  1071     TBool isFocused = IsFocusControl();
       
  1072     iList->SetFocus(isFocused, aDrawNow);
       
  1073     HandleFocusChanged(aDrawNow);
       
  1074 }
       
  1075 
       
  1076 // ---------------------------------------------------------------------------
       
  1077 // CSwtListBase::MopSupplyObject
       
  1078 // From CCoeControl
       
  1079 // ---------------------------------------------------------------------------
       
  1080 //
       
  1081 TTypeUid::Ptr CSwtListBase::MopSupplyObject(TTypeUid aId)
       
  1082 {
       
  1083     TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId);
       
  1084 
       
  1085     if (id.Pointer() == NULL)
       
  1086     {
       
  1087         return CAknControl::MopSupplyObject(aId);
       
  1088     }
       
  1089     else
       
  1090     {
       
  1091         return id;
       
  1092     }
       
  1093 }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // CSwtListBase::Draw
       
  1097 // From CCoeControl
       
  1098 // Overriding Draw just to set correct clipping rect for the item drawer of
       
  1099 // the contained list. The contained list will be drawn immediately after this.
       
  1100 // ---------------------------------------------------------------------------
       
  1101 //
       
  1102 void CSwtListBase::Draw(const TRect& /*aRect*/) const
       
  1103 {
       
  1104     // Suppress margins - they are drawn over scrollbars
       
  1105     CSwtListBoxLists::SetMargins(iListType, iList, 0, 0);
       
  1106 
       
  1107     if (GetShell().UrgentPaintControl() == this)
       
  1108         return;
       
  1109 
       
  1110     TRect clipRect(ClipToVisibleRect(iList->View()->ViewRect()));
       
  1111     if (clipRect != iLastViewVisibleRect)
       
  1112     {
       
  1113         CSwtListBoxLists::SetItemDrawerClippingRect(iListType, iList, clipRect);
       
  1114         iLastViewVisibleRect = clipRect;
       
  1115     }
       
  1116 }
       
  1117 
       
  1118 // ---------------------------------------------------------------------------
       
  1119 // CSwtListBase::SetFontL
       
  1120 // From ASwtControlbase
       
  1121 // ---------------------------------------------------------------------------
       
  1122 //
       
  1123 void CSwtListBase::SetFontL(const MSwtFont* aFont)
       
  1124 {
       
  1125     ASwtControlBase::DoSetFontL(aFont);
       
  1126 
       
  1127     SetTextMaxWidth(ComputeTextMaxWidth());
       
  1128 
       
  1129     // The font update will be performed in HandleSizeChangedL method.
       
  1130     UpdateSize();
       
  1131 
       
  1132     Redraw();
       
  1133 }
       
  1134 
       
  1135 // ---------------------------------------------------------------------------
       
  1136 // CSwtListBase::MSKLabelL
       
  1137 // From ASwtControlbase
       
  1138 // ---------------------------------------------------------------------------
       
  1139 //
       
  1140 HBufC* CSwtListBase::MSKLabelL() const
       
  1141 {
       
  1142     if (!iList || !(iList->Model()->NumberOfItems() > 0))
       
  1143     {
       
  1144         return ASwtControlBase::MSKLabelL();
       
  1145     }
       
  1146 
       
  1147     if ((iStyle & KSwtStyleSingle))
       
  1148     {
       
  1149         HBufC* label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_SELECT);
       
  1150         return label;
       
  1151     }
       
  1152     if ((iStyle & KSwtStyleMulti))
       
  1153     {
       
  1154         HBufC* label = NULL;
       
  1155         if (iList->View()->ItemIsSelected(iList->CurrentItemIndex()))
       
  1156         {
       
  1157             label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_UNMARK);
       
  1158         }
       
  1159         else
       
  1160         {
       
  1161             label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_MARK);
       
  1162         }
       
  1163         return label;
       
  1164     }
       
  1165     return ASwtControlBase::MSKLabelL();
       
  1166 }
       
  1167 
       
  1168 // ---------------------------------------------------------------------------
       
  1169 // CSwtListBase::DefaultFont
       
  1170 // From ASwtControlbase
       
  1171 // ---------------------------------------------------------------------------
       
  1172 //
       
  1173 const MSwtFont& CSwtListBase::DefaultFont() const
       
  1174 {
       
  1175     if (iDefaultFont)
       
  1176     {
       
  1177         return *iDefaultFont;
       
  1178     }
       
  1179 
       
  1180     return *(iDisplay.Device().GetSystemFont());
       
  1181 }
       
  1182 
       
  1183 // ---------------------------------------------------------------------------
       
  1184 // CSwtListBase::CoeControl
       
  1185 // From MSwtControl
       
  1186 // ---------------------------------------------------------------------------
       
  1187 //
       
  1188 CCoeControl& CSwtListBase::CoeControl()
       
  1189 {
       
  1190     return *this;
       
  1191 }
       
  1192 
       
  1193 // ---------------------------------------------------------------------------
       
  1194 // CSwtListBase::CoeControl
       
  1195 // From MSwtControl
       
  1196 // ---------------------------------------------------------------------------
       
  1197 //
       
  1198 const CCoeControl& CSwtListBase::CoeControl() const
       
  1199 {
       
  1200     return *this;
       
  1201 }
       
  1202 
       
  1203 // ---------------------------------------------------------------------------
       
  1204 // CSwtListBase::ProcessKeyEventL
       
  1205 // From MSwtControl
       
  1206 // ---------------------------------------------------------------------------
       
  1207 //
       
  1208 void CSwtListBase::ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
  1209 {
       
  1210     // No items or not a normal key event
       
  1211     if (iList->Model()->NumberOfItems() == 0 || aType != EEventKey)
       
  1212     {
       
  1213         iList->OfferKeyEventL(aKeyEvent, aType);
       
  1214         return;
       
  1215     }
       
  1216 
       
  1217     TBool scroll = aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow
       
  1218                    || aKeyEvent.iCode == EKeyNext || aKeyEvent.iCode == EKeyPrevious;
       
  1219     TBool submit = aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK;
       
  1220 
       
  1221     // For performance considerations, assuming that Enter or Select always
       
  1222     // does change the multi selection. If the assumption is wrong, we must
       
  1223     // store the multi selection before the key is handled and then compare:
       
  1224     // if ( ( iStyle & KSwtStyleMulti ) && submit ) GetUserSelectionL( iPrevSelItems );
       
  1225 
       
  1226     // Store selection before letting the list handle the key.
       
  1227     if ((iStyle & KSwtStyleSingle) && scroll)
       
  1228     {
       
  1229         iPrevFocusIndex = iList->View()->CurrentItemIndex();
       
  1230     }
       
  1231 
       
  1232     iList->OfferKeyEventL(aKeyEvent, aType);
       
  1233 
       
  1234     if (scroll || submit)
       
  1235     {
       
  1236         if (iStyle & KSwtStyleSingle)
       
  1237         {
       
  1238             // Single lists
       
  1239             if (submit)
       
  1240             {
       
  1241                 // Item submited, send default selection event.
       
  1242                 iDisplay.PostDefaultSelectionEventL(iPeer);
       
  1243             }
       
  1244             else
       
  1245             {
       
  1246                 if (iList->View()->CurrentItemIndex() != iPrevFocusIndex)
       
  1247                 {
       
  1248                     // Ensure the selection and focus index are in sync.
       
  1249                     iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
  1250 
       
  1251                     // Item focus highlight moved, send selection event.
       
  1252                     iDisplay.PostSelectionEventL(iPeer);
       
  1253                 }
       
  1254             }
       
  1255         }
       
  1256         else
       
  1257         {
       
  1258             // Multi lists
       
  1259             // Msk could have changed: Mark / Unmark
       
  1260             UpdateListMskL();
       
  1261 
       
  1262             // For performance considerations, assuming that Enter or Select always
       
  1263             // does change the multi selection. If the assumption is wrong, here's
       
  1264             // how we must check if the selection really changed:
       
  1265             // if ( submit && iPrevSelItems && ( iList->View()->SelectionIndexes()->
       
  1266             // Count() != iPrevSelItems->Count() ) )
       
  1267             if (submit)
       
  1268             {
       
  1269                 // Multi selection changed, send selection event.
       
  1270                 iDisplay.PostSelectionEventL(iPeer);
       
  1271             }
       
  1272         }
       
  1273     }
       
  1274 }
       
  1275 
       
  1276 // ---------------------------------------------------------------------------
       
  1277 // CSwtListBase::IsKeyUsed
       
  1278 // From MSwtControl
       
  1279 // ---------------------------------------------------------------------------
       
  1280 //
       
  1281 TBool CSwtListBase::IsKeyUsed(TUint aKeyCode) const
       
  1282 {
       
  1283     // A list does not use the Backspace but uses OK key
       
  1284     if (aKeyCode == EKeyBackspace)
       
  1285     {
       
  1286         return EFalse;
       
  1287     }
       
  1288     else if (aKeyCode == EKeyOK)
       
  1289     {
       
  1290         if (iStyle & KSwtStyleSingle)
       
  1291         {
       
  1292             MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
  1293             if (commandArranger)
       
  1294             {
       
  1295                 if (commandArranger->IsContextSensitiveOperationSet())
       
  1296                 {
       
  1297                     return EFalse;
       
  1298                 }
       
  1299             }
       
  1300             return ETrue;
       
  1301         }
       
  1302         else
       
  1303         {
       
  1304             return ETrue;
       
  1305         }
       
  1306     }
       
  1307     return ETrue;
       
  1308 }
       
  1309 
       
  1310 
       
  1311 TBool CSwtListBase::MSKSelCmdEnabled() const
       
  1312 {
       
  1313     return ETrue;
       
  1314 }
       
  1315 
       
  1316 // ---------------------------------------------------------------------------
       
  1317 // CSwtListBase::GetForeground
       
  1318 // From MSwtControl
       
  1319 // ---------------------------------------------------------------------------
       
  1320 //
       
  1321 TRgb CSwtListBase::GetForeground() const
       
  1322 {
       
  1323     ASSERT(iList);
       
  1324     return static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->TextColor();
       
  1325 }
       
  1326 
       
  1327 // ---------------------------------------------------------------------------
       
  1328 // CSwtListBase::SetForegroundL
       
  1329 // From MSwtControl
       
  1330 // ---------------------------------------------------------------------------
       
  1331 //
       
  1332 void CSwtListBase::SetForegroundL(const MSwtColor* aColor)
       
  1333 {
       
  1334     ASwtControlBase::DoSetForegroundL(aColor);
       
  1335     iTextColor = aColor;
       
  1336     UpdateListBoxTextColorL();
       
  1337     Redraw();
       
  1338 }
       
  1339 
       
  1340 // ---------------------------------------------------------------------------
       
  1341 // CSwtListBase::SetBackgroundL
       
  1342 // From MSwtControl
       
  1343 // ---------------------------------------------------------------------------
       
  1344 //
       
  1345 void CSwtListBase::SetBackgroundL(const MSwtColor* aColor)
       
  1346 {
       
  1347     ASSERT(iList);
       
  1348     ASwtControlBase::DoSetBackgroundL(aColor);
       
  1349     iList->HandleResourceChange(KEikMessageColorSchemeChange);
       
  1350     Redraw();
       
  1351 }
       
  1352 
       
  1353 // ---------------------------------------------------------------------------
       
  1354 // CSwtListBase::IsLongTapAnimationCandidate
       
  1355 // From MSwtControl
       
  1356 // ---------------------------------------------------------------------------
       
  1357 //
       
  1358 #ifdef RD_SCALABLE_UI_V2
       
  1359 TBool CSwtListBase::IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const
       
  1360 {
       
  1361     ASSERT(iList);
       
  1362     TInt itemIndex = KErrNotFound;
       
  1363     TBool pointerOverItem = iList->View()->XYPosToItemIndex(aPointerEvent.iPosition, itemIndex);
       
  1364     return pointerOverItem && ASwtControlBase::IsLongTapAnimationCandidate(aPointerEvent);
       
  1365 }
       
  1366 #else
       
  1367 TBool CSwtListBase::IsLongTapAnimationCandidate(const TPointerEvent& /*aPointerEvent*/) const
       
  1368 {
       
  1369     return EFalse;
       
  1370 }
       
  1371 #endif
       
  1372 
       
  1373 // ---------------------------------------------------------------------------
       
  1374 // CSwtListBase::SbFrame
       
  1375 // From ASwtScrollableBase
       
  1376 // ---------------------------------------------------------------------------
       
  1377 //
       
  1378 CEikScrollBarFrame* CSwtListBase::SbFrame() const
       
  1379 {
       
  1380     ASSERT(iList);
       
  1381     return iList->ScrollBarFrame();
       
  1382 }
       
  1383 
       
  1384 // ---------------------------------------------------------------------------
       
  1385 // CSwtListBase::HandleSizeChangedL
       
  1386 // From MSwtListObserver
       
  1387 // ---------------------------------------------------------------------------
       
  1388 //
       
  1389 void CSwtListBase::HandleSizeChangedL()
       
  1390 {
       
  1391     ASSERT(iList);
       
  1392 
       
  1393     CColumnListBoxData* listBoxData =
       
  1394         static_cast<CEikColumnListBox*>(iList)->ItemDrawer()->ColumnData();
       
  1395     ASSERT(listBoxData);
       
  1396     CColumnListBoxItemDrawer* listBoxDrawer =
       
  1397         static_cast<CEikColumnListBox*>(iList)->ItemDrawer();
       
  1398     ASSERT(listBoxDrawer);
       
  1399 
       
  1400     // Update default font if font of list box has changed
       
  1401     UpdateDefaultFontL();
       
  1402 
       
  1403     if (iFont)
       
  1404     {
       
  1405         // If a font has been set, all item layouts are removed
       
  1406         // to display all of them correctly
       
  1407         listBoxData->ResetSLSubCellArray();
       
  1408 
       
  1409         // WORKAROUND to prevent a crash in CColumnListBoxData::Draw() method.
       
  1410         // An assert ASSERT_ALWAYS is performed if column widths are not correct.
       
  1411         TRect clientRect(ClientRect());
       
  1412         for (TInt colIndex = 0;
       
  1413                 colIndex < listBoxData->LastColumn();
       
  1414                 colIndex++)
       
  1415         {
       
  1416             if (colIndex == KCheckboxColumnIndex)
       
  1417             {
       
  1418                 if (listBoxData->ColumnWidthPixel(KCheckboxColumnIndex) <= 1)
       
  1419                 {
       
  1420                     listBoxData->SetColumnWidthPixelL(KCheckboxColumnIndex, 2);
       
  1421                 }
       
  1422             }
       
  1423             else if (colIndex == KTextColumnIndex)
       
  1424             {
       
  1425                 TInt txtMaxWidth(0);
       
  1426                 if (!iTextItems->Count())
       
  1427                 {
       
  1428                     txtMaxWidth = clientRect.Width() -
       
  1429                                   listBoxData->ColumnWidthPixel(KCheckboxColumnIndex);
       
  1430                 }
       
  1431                 else
       
  1432                 {
       
  1433                     txtMaxWidth = Min(iTxtMaxWidth, clientRect.Width() -
       
  1434                                       listBoxData->ColumnWidthPixel(KCheckboxColumnIndex));
       
  1435                 }
       
  1436                 txtMaxWidth = Max(1, txtMaxWidth);
       
  1437                 listBoxData->SetColumnWidthPixelL(
       
  1438                     KTextColumnIndex, txtMaxWidth);
       
  1439             }
       
  1440             else if (listBoxData->ColumnWidthPixel(colIndex) < 0)
       
  1441             {
       
  1442                 listBoxData->SetColumnWidthPixelL(colIndex, 0);
       
  1443             }
       
  1444         }
       
  1445         // END WORKAROUND
       
  1446     }
       
  1447 
       
  1448     // ==========================================
       
  1449     // WORKAROUND to not draw the dotted lines.
       
  1450     // ==========================================
       
  1451     //
       
  1452     listBoxData->SetSeparatorLinePosition(ENoLine);
       
  1453     // END WORKAROUND
       
  1454 
       
  1455     // Update with current font
       
  1456     UpdateListBoxFontL();
       
  1457 
       
  1458     // Update with current text color
       
  1459     UpdateListBoxTextColorL();
       
  1460 
       
  1461     // Update background color
       
  1462     listBoxDrawer->SetBackColor(GetBackground());
       
  1463 }
       
  1464 
       
  1465 // ---------------------------------------------------------------------------
       
  1466 // CSwtListBase::Utils
       
  1467 // From MSwtListObserver
       
  1468 // ---------------------------------------------------------------------------
       
  1469 //
       
  1470 MSwtUiUtils& CSwtListBase::Utils() const
       
  1471 {
       
  1472     return iDisplay.UiUtils();
       
  1473 }
       
  1474 
       
  1475 // ---------------------------------------------------------------------------
       
  1476 // CSwtListBase::HandleScrollEventL
       
  1477 // From MEikScrollBarObserver
       
  1478 // ---------------------------------------------------------------------------
       
  1479 //
       
  1480 #ifdef RD_SCALABLE_UI_V2
       
  1481 void CSwtListBase::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType)
       
  1482 {
       
  1483     // On 5.0, drawing trough Java gives simply a better fps.
       
  1484 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1485     switch (aEventType)
       
  1486     {
       
  1487     case EEikScrollThumbDragVert:
       
  1488         GetShell().SetUrgentPaintControl(this);
       
  1489         break;
       
  1490     case EEikScrollThumbReleaseVert:
       
  1491         GetShell().SetUrgentPaintControl(NULL);
       
  1492         break;
       
  1493     default:
       
  1494         break;
       
  1495     }
       
  1496 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1497 
       
  1498     iList->HandleScrollEventL(aScrollBar, aEventType);
       
  1499     ASwtScrollableBase::HandleScrollEventL(aScrollBar, aEventType);
       
  1500 }
       
  1501 #else //RD_SCALABLE_UI_V2
       
  1502 void CSwtListBase::HandleScrollEventL(CEikScrollBar*, TEikScrollEvent)
       
  1503 {
       
  1504 }
       
  1505 #endif //RD_SCALABLE_UI_V2
       
  1506 
       
  1507 // ---------------------------------------------------------------------------
       
  1508 // CSwtListBase::HandleScrollEventL
       
  1509 // From MEikListBoxObserver
       
  1510 // Handles default selection for touch. Unable to handle the selection events
       
  1511 // here since EEventItemClicked is not always sent for every tap.
       
  1512 // The selection events are handled in HandlePointerEvent.
       
  1513 // ---------------------------------------------------------------------------
       
  1514 //
       
  1515 #ifdef RD_SCALABLE_UI_V2
       
  1516 void CSwtListBase::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
  1517 {
       
  1518     if (aListBox != iList)
       
  1519     {
       
  1520         return;
       
  1521     }
       
  1522 
       
  1523     switch (aEventType)
       
  1524     {
       
  1525         // On 5.0, drawing trough Java gives simply a better fps.
       
  1526 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1527     case EEventPanningStarted:
       
  1528         GetShell().SetUrgentPaintControl(this);
       
  1529         break;
       
  1530     case EEventFlickStopped:
       
  1531         GetShell().SetUrgentPaintControl(NULL);
       
  1532         break;
       
  1533 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1534 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1535     case EEventItemSingleClicked:
       
  1536 #else
       
  1537     case EEventItemDoubleClicked:
       
  1538 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1539         if (!(iStyle & KSwtStyleMulti))
       
  1540         {
       
  1541             if (!iDisplay.RevertPointerEvent())
       
  1542                 iDisplay.PostDefaultSelectionEventL(iPeer);
       
  1543         }
       
  1544         break;
       
  1545     default:
       
  1546         // Do nothing
       
  1547         break;
       
  1548     }
       
  1549 }
       
  1550 #else //RD_SCALABLE_UI_V2
       
  1551 void CSwtListBase::HandleListBoxEventL(CEikListBox*, TListBoxEvent)
       
  1552 {
       
  1553 }
       
  1554 #endif //RD_SCALABLE_UI_V2
       
  1555