javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtlistbox.cpp
branchRCL_3
changeset 66 2455ef1f5bbc
child 83 26b2b12093af
equal deleted inserted replaced
65:ae942d28ec0e 66:2455ef1f5bbc
       
     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 <aknlists.h>
       
    14 #include <gulicon.h>
       
    15 #include <avkon.hrh>
       
    16 #include <aknselectionlist.h>
       
    17 #include <eikclbd.h>
       
    18 #include <avkon.mbg>
       
    19 #include <e32math.h>
       
    20 #include <aknconsts.h>
       
    21 #include <AknUtils.h>
       
    22 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
    23 #include <aknlistloadertfx.h>
       
    24 #include <aknlistboxtfx.h>
       
    25 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
    26 #include <swtlaffacade.h>
       
    27 #include "eswtgraphics.h"
       
    28 #include "swtlistboxlists.h"
       
    29 #include "swtcontrolhelper.h"
       
    30 #include "swtlistbox.h"
       
    31 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
    32 #include <touchfeedback.h>
       
    33 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
    34 
       
    35 _LIT(KTxtTab, "\t");
       
    36 _LIT(KTxtSpace, " ");
       
    37 
       
    38 const TInt KImgIdxNull = -1;
       
    39 const TInt KImgIdxOn = 0;
       
    40 const TInt KImgIdxOff = 1;
       
    41 const TInt KMaxIdxDigitCount = 4;
       
    42 const TInt KInitImgArrLength = 2;
       
    43 const TInt KInitTxtArrLength = 2;
       
    44 const TInt KInitSelArrLength = 1;
       
    45 const TInt KVBorderSides = 2;
       
    46 
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 
       
    51 //
       
    52 // CSwtLbItem
       
    53 //
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CSwtLbItem::CSwtLbItem
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CSwtLbItem::CSwtLbItem()
       
    60         : CSwtListBoxItem(NULL, NULL, NULL, NULL)
       
    61         , iHimgIdx(KImgIdxNull)
       
    62         , iDimgIdx(KImgIdxNull)
       
    63 {
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CSwtLbItem::CSwtLbItem
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 CSwtLbItem::CSwtLbItem(
       
    71     HBufC* aDtxt,
       
    72     const MSwtImage* aDimg,
       
    73     HBufC* aHtxt,
       
    74     const MSwtImage* aHimg)
       
    75         : CSwtListBoxItem(aDtxt, aDimg, aHtxt, aHimg)
       
    76         , iHimgIdx(KImgIdxNull)
       
    77         , iDimgIdx(KImgIdxNull)
       
    78 {
       
    79 }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CSwtLbItem::CSwtLbItem
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CSwtLbItem::CSwtLbItem(
       
    86     HBufC* aDtxt,
       
    87     const MSwtImage* aDimg,
       
    88     const TSize& aDimgSize,
       
    89     HBufC* aHtxt,
       
    90     const MSwtImage* aHimg,
       
    91     const TSize& aHimgSize)
       
    92         : CSwtListBoxItem(aDtxt, aDimg, aDimgSize, aHtxt, aHimg, aHimgSize)
       
    93         , iHimgIdx(KImgIdxNull)
       
    94         , iDimgIdx(KImgIdxNull)
       
    95 {
       
    96 }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CSwtLbItem::~CSwtLbItem
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 CSwtLbItem::~CSwtLbItem()
       
   103 {
       
   104 }
       
   105 
       
   106 
       
   107 //
       
   108 // CSwtListBox
       
   109 //
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CSwtListBox::NewL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 CSwtListBox* CSwtListBox::NewL(
       
   116     MSwtDisplay& aDisplay,
       
   117     TSwtPeer aPeer,
       
   118     MSwtComposite& aParent,
       
   119     TInt aStyle)
       
   120 {
       
   121     CSwtListBox* self = new(ELeave) CSwtListBox(
       
   122         aDisplay,
       
   123         aPeer,
       
   124         aParent,
       
   125         aStyle);
       
   126     CleanupStack::PushL(self);
       
   127     self->ConstructL();
       
   128     self->InitControlBaseL();
       
   129     CleanupStack::Pop(self);
       
   130     return self;
       
   131 }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CSwtListBox::CSwtListBox
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CSwtListBox::CSwtListBox(
       
   138     MSwtDisplay& aDisplay,
       
   139     TSwtPeer aPeer,
       
   140     MSwtComposite& aParent,
       
   141     TInt aStyle)
       
   142         : ASwtScrollableBase(aDisplay, aPeer, &aParent, aStyle)
       
   143         , iFlickScrollingOngoing(EFalse)
       
   144 
       
   145 {
       
   146 }
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CSwtListBox::~CSwtListBox
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 CSwtListBox::~CSwtListBox()
       
   153 {
       
   154     // Selection items, own
       
   155     delete iPrevSelItems;
       
   156     iPrevSelItems = NULL;
       
   157 
       
   158     // Contained list, own
       
   159     delete iList;
       
   160     iList = NULL;
       
   161 
       
   162     // List images, not own. The array is reset and destroyed by
       
   163     // the destructor of the contained Avkon list
       
   164     iImgs = NULL;
       
   165 
       
   166     // List texts, own.
       
   167     if (iTxts)
       
   168     {
       
   169         iTxts->Reset();
       
   170         delete iTxts;
       
   171         iTxts = NULL;
       
   172     }
       
   173 
       
   174     // Remove all items
       
   175     RemoveSubRefs();
       
   176     iItems.ResetAndDestroy();
       
   177 
       
   178     // Item cells, own.
       
   179     iCells.Close();
       
   180 
       
   181     // Current and default colors, not own
       
   182     iDefColor = NULL;
       
   183     iColor = NULL;
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CSwtListBox::ConstructL
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CSwtListBox::ConstructL()
       
   191 {
       
   192     CCoeControl& coeParent = iParent->Control()->CoeControl();
       
   193     SetContainerWindowL(coeParent);
       
   194     SetComponentsToInheritVisibility(ETrue);
       
   195     CCoeControl::MakeVisible(coeParent.IsVisible());
       
   196     CCoeControl::SetDimmed(coeParent.IsDimmed());
       
   197 
       
   198     // This is indeed necessary, otherwise the background might not be drawn!
       
   199     SetBackground(this);
       
   200 }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // CSwtListBox::CountComponentControls
       
   204 // From CCoeControl
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 TInt CSwtListBox::CountComponentControls() const
       
   208 {
       
   209     return iList ? 1 : 0;
       
   210 }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CSwtListBox::ComponentControl
       
   214 // From CCoeControl
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 CCoeControl* CSwtListBox::ComponentControl(TInt) const
       
   218 {
       
   219     return iList;
       
   220 }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CSwtListBox::MakeVisible
       
   224 // From CCoeControl
       
   225 // ---------------------------------------------------------------------------
       
   226 //
       
   227 void CSwtListBox::MakeVisible(TBool aVisible)
       
   228 {
       
   229     CCoeControl::MakeVisible(aVisible);
       
   230     FocusabilityChanged();
       
   231 }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CSwtListBox::SetDimmed
       
   235 // From CCoeControl
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CSwtListBox::SetDimmed(TBool aDimmed)
       
   239 {
       
   240     CCoeControl::SetDimmed(aDimmed);
       
   241     iList->SetDimmed(aDimmed);
       
   242     FocusabilityChanged();
       
   243 }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // CSwtListBox::OfferKeyEventL
       
   247 // From CCoeControl
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 TKeyResponse CSwtListBox::OfferKeyEventL(
       
   251     const TKeyEvent& aKeyEvent,
       
   252     TEventCode aType)
       
   253 {
       
   254     TBool traversalDoIt = ETrue;
       
   255 
       
   256     // No traverse on enter / select
       
   257     if ((iStyle & KSwtStyleMulti)
       
   258             && (aKeyEvent.iCode == EKeyEnter
       
   259                 || aKeyEvent.iCode == EKeyOK))
       
   260     {
       
   261         traversalDoIt = EFalse;
       
   262     }
       
   263 
       
   264     // No traverse on scroll by default
       
   265     if (aKeyEvent.iCode == EKeyDownArrow
       
   266             || aKeyEvent.iCode == EKeyUpArrow)
       
   267     {
       
   268         traversalDoIt = EFalse;
       
   269 
       
   270         if (aKeyEvent.iCode == EKeyDownArrow)
       
   271         {
       
   272             // Traverse if last item is focused and
       
   273             // there are other controls to traverse to
       
   274             if (iList->View()->CurrentItemIndex()
       
   275                     == (iList->Model()->NumberOfItems() - 1))
       
   276             {
       
   277                 if (GetShell().FindTraversalTargetL(
       
   278                             ESwtTraverseArrowNext,
       
   279                             *this))
       
   280                 {
       
   281                     traversalDoIt = ETrue;
       
   282                 }
       
   283             }
       
   284         }
       
   285         else
       
   286         {
       
   287             // Traverse if first item is focused and
       
   288             // there are other controls to traverse to
       
   289             if (iList->View()->CurrentItemIndex() == 0)
       
   290             {
       
   291                 if (GetShell().FindTraversalTargetL(
       
   292                             ESwtTraverseArrowPrevious,
       
   293                             *this))
       
   294                 {
       
   295                     traversalDoIt = ETrue;
       
   296                 }
       
   297             }
       
   298         }
       
   299     }
       
   300 
       
   301     return HandleKeyL(aKeyEvent, aType, traversalDoIt);
       
   302 }
       
   303 
       
   304 // ---------------------------------------------------------------------------
       
   305 // CSwtListBox::HandleResourceChange
       
   306 // From CCoeControl
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CSwtListBox::HandleResourceChange(TInt aType)
       
   310 {
       
   311     if (aType == KAknsMessageSkinChange)
       
   312     {
       
   313         if (iProps.iSelectionType == ESwtLbMultiSelection)
       
   314         {
       
   315             TRAP_IGNORE(CreateListSelImgsL(iImgs));
       
   316         }
       
   317     }
       
   318     CAknControl::HandleResourceChange(aType);
       
   319 
       
   320     SetMaximumIconSizes();
       
   321 }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // CSwtListBox::HandlePointerEventL
       
   325 // From CCoeControl
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 #ifdef RD_SCALABLE_UI_V2
       
   329 void CSwtListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   330 {
       
   331     ASSERT(iList);
       
   332 
       
   333     CEikScrollBarFrame* sbFrame = iList->ScrollBarFrame();
       
   334     CEikScrollBar* vsb = sbFrame ? sbFrame->GetScrollBarHandle(CEikScrollBar::EVertical) : NULL;
       
   335 
       
   336     // Check if we should start scrollbar grabbing
       
   337     if (aPointerEvent.iType == TPointerEvent::EButton1Down && !iVScrollBarGrabsPointerEvents)
       
   338     {
       
   339         if (vsb && vsb->Rect().Contains(aPointerEvent.iPosition))
       
   340         {
       
   341             iVScrollBarGrabsPointerEvents = ETrue;
       
   342         }
       
   343     }
       
   344 
       
   345     // Deliver event to scrollbar
       
   346     if (iVScrollBarGrabsPointerEvents && vsb)
       
   347     {
       
   348         if (!iFlickScrollingOngoing
       
   349                 && aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   350         {
       
   351             // Scrollbar was tapped after scrolling stopped
       
   352             // by itself, so no need to redirect events
       
   353             iScrollbarPointerEventToListbox = EFalse;
       
   354         }
       
   355 
       
   356         if (iScrollbarPointerEventToListbox)
       
   357         {
       
   358             // Stops kinetic scrolling when scrollbar is tapped
       
   359             iList->HandlePointerEventL(aPointerEvent);
       
   360             // Continue delivering events until button up appears to prevent
       
   361             // some unexpected behavior in both scrollbar and listbox
       
   362             switch (aPointerEvent.iType)
       
   363             {
       
   364             case TPointerEvent::EButton1Up:
       
   365                 iScrollbarPointerEventToListbox = EFalse;
       
   366                 break;
       
   367             }
       
   368         }
       
   369         else
       
   370         {
       
   371             // Handles scrollbar behavior
       
   372             vsb->HandlePointerEventL(aPointerEvent);
       
   373         }
       
   374     }
       
   375 
       
   376     // Deliver event to list
       
   377     if (!iVScrollBarGrabsPointerEvents)
       
   378     {
       
   379         // Store the selection on first pointer event.
       
   380         if (aPointerEvent.iType == TPointerEvent::EButton1Down)
       
   381         {
       
   382             if (iStyle & KSwtStyleMulti)
       
   383             {
       
   384                 // Multi lists
       
   385                 ASSERT(iPrevSelItems);
       
   386                 GetUserSelectionL(iPrevSelItems);
       
   387             }
       
   388             iPrevFocusIndex = iList->View()->CurrentItemIndex();
       
   389         }
       
   390 
       
   391         iList->HandlePointerEventL(aPointerEvent);
       
   392 
       
   393         if (aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   394         {
       
   395             TInt focusIndex = iList->View()->CurrentItemIndex();
       
   396 
       
   397             if (iStyle & KSwtStyleMulti)
       
   398             {
       
   399                 // Multi lists
       
   400                 if ((iList->View()->SelectionIndexes()->Count() != iPrevSelItems->Count()))
       
   401                 {
       
   402                     if (iDisplay.RevertPointerEvent())
       
   403                     {
       
   404                         // Revert newly checked item.
       
   405                         if (iList->View()->ItemIsSelected(focusIndex))
       
   406                         {
       
   407                             iList->View()->DeselectItem(focusIndex);
       
   408                         }
       
   409                         else
       
   410                         {
       
   411                             iList->View()->SelectItemL(focusIndex);
       
   412                         }
       
   413                     }
       
   414                     else
       
   415                     {
       
   416                         iDisplay.PostSelectionEventL(iPeer);
       
   417                     }
       
   418                 }
       
   419             }
       
   420             else
       
   421             {
       
   422                 // Single lists
       
   423                 // Compare the focus index after tap or drag ended
       
   424                 if (focusIndex != iPrevFocusIndex)
       
   425                 {
       
   426                     // Ensure the selection and focus index are in sync.
       
   427                     iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
   428 
       
   429                     // Item focus highlight moved, send selection event.
       
   430                     // Changing the focus index is not subject to reverting.
       
   431                     iDisplay.PostSelectionEventL(iPeer);
       
   432                 }
       
   433 
       
   434                 // The default selection is sent from HandleListBoxEventL!
       
   435             }
       
   436         }
       
   437     }
       
   438 
       
   439     // Stop scrollbar grabbing
       
   440     if (iVScrollBarGrabsPointerEvents
       
   441             && aPointerEvent.iType == TPointerEvent::EButton1Up)
       
   442     {
       
   443         iVScrollBarGrabsPointerEvents = EFalse;
       
   444     }
       
   445 
       
   446     PostMouseEventL(aPointerEvent);
       
   447 }
       
   448 #else //RD_SCALABLE_UI_V2
       
   449 void CSwtListBox::HandlePointerEventL(
       
   450     const TPointerEvent& /*aPointerEvent*/)
       
   451 {
       
   452 }
       
   453 #endif //RD_SCALABLE_UI_V2
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // CSwtListBox::SizeChanged
       
   457 // From CCoeControl
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 void CSwtListBox::SizeChanged()
       
   461 {
       
   462     SetMaximumIconSizes();
       
   463 
       
   464     if (iList)
       
   465     {
       
   466         TRect rect = BorderInnerRect();
       
   467         iList->SetSize(rect.Size());
       
   468 
       
   469         // This is a workaround for the list being drawn in the wrong place if
       
   470         // it is placed inside a mobile shell.
       
   471         iList->SetPosition(rect.iTl);
       
   472     }
       
   473 
       
   474     HandleSizeChanged();
       
   475 }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // CSwtListBox::PositionChanged
       
   479 // From CCoeControl
       
   480 // ---------------------------------------------------------------------------
       
   481 //
       
   482 void CSwtListBox::PositionChanged()
       
   483 {
       
   484     HandlePositionChanged();
       
   485 }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CSwtListBox::FocusChanged
       
   489 // From CCoeControl
       
   490 // ---------------------------------------------------------------------------
       
   491 //
       
   492 void CSwtListBox::FocusChanged(TDrawNow aDrawNow)
       
   493 {
       
   494     TBool isFocused = IsFocusControl();
       
   495     // This gets called before contained list is created.
       
   496     if (iList)
       
   497     {
       
   498 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   499         EnableFocusHighlight(isFocused);
       
   500 #endif //RD_JAVA_S60_RELEASE_9_2
       
   501         iList->SetFocus(isFocused, aDrawNow);
       
   502     }
       
   503     HandleFocusChanged(aDrawNow);
       
   504 }
       
   505 
       
   506 // ---------------------------------------------------------------------------
       
   507 // CSwtListBox::MopSupplyObject
       
   508 // From CCoeControl
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 TTypeUid::Ptr CSwtListBox::MopSupplyObject(TTypeUid aId)
       
   512 {
       
   513     TTypeUid::Ptr id = ASwtControlBase::SwtMopSupplyObject(aId);
       
   514 
       
   515     if (id.Pointer() == NULL)
       
   516     {
       
   517         return CAknControl::MopSupplyObject(aId);
       
   518     }
       
   519     else
       
   520     {
       
   521         return id;
       
   522     }
       
   523 }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CSwtListBox::Draw
       
   527 // From CCoeControl
       
   528 // Overriding Draw just to set correct clipping rect for the item drawer of
       
   529 // the contained list. The contained list will be drawn immediately after this.
       
   530 // ---------------------------------------------------------------------------
       
   531 //
       
   532 void CSwtListBox::Draw(const TRect& /*aRect*/) const
       
   533 {
       
   534     // Suppress margins - they are drawn over scrollbars
       
   535     CSwtListBoxLists::SetMargins(iProps.iListType, iList, 0, 0);
       
   536 
       
   537     if (GetShell().UrgentPaintControl() == this)
       
   538         return;
       
   539 
       
   540     TRect clipRect(ClipToVisibleRect(iList->View()->ViewRect()));
       
   541     if (clipRect != iLastViewVisibleRect)
       
   542     {
       
   543         CSwtListBoxLists::SetItemDrawerClippingRect(iProps.iListType, iList, clipRect);
       
   544         iLastViewVisibleRect = clipRect;
       
   545     }
       
   546 }
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CSwtListBox::MSKLabelL
       
   550 // From ASwtControlBase
       
   551 // ---------------------------------------------------------------------------
       
   552 //
       
   553 HBufC* CSwtListBox::MSKLabelL() const
       
   554 {
       
   555     // This gets called before contained list is created.
       
   556     if (iList)
       
   557     {
       
   558         if (!(iList->Model()->NumberOfItems() > 0))
       
   559         {
       
   560             return ASwtControlBase::MSKLabelL();
       
   561         }
       
   562         if ((iStyle & KSwtStyleMulti))
       
   563         {
       
   564             HBufC* label = NULL;
       
   565             if (iList->View()->ItemIsSelected(iList->CurrentItemIndex()))
       
   566             {
       
   567                 label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_UNMARK);
       
   568             }
       
   569             else
       
   570             {
       
   571                 label = iEikonEnv->AllocReadResourceL(R_QTN_MSK_MARK);
       
   572             }
       
   573             return label;
       
   574         }
       
   575         else
       
   576         {
       
   577             return iEikonEnv->AllocReadResourceL(R_QTN_MSK_SELECT);
       
   578         }
       
   579     }
       
   580     return ASwtControlBase::MSKLabelL();
       
   581 }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // CSwtListBox::SbFrame
       
   585 // From ASwtScrollableBase
       
   586 // ---------------------------------------------------------------------------
       
   587 //
       
   588 CEikScrollBarFrame* CSwtListBox::SbFrame() const
       
   589 {
       
   590     return iList ? iList->ScrollBarFrame() : NULL;
       
   591 }
       
   592 
       
   593 // ---------------------------------------------------------------------------
       
   594 // CSwtListBox::CoeControl
       
   595 // From MSwtControl
       
   596 // ---------------------------------------------------------------------------
       
   597 //
       
   598 CCoeControl& CSwtListBox::CoeControl()
       
   599 {
       
   600     return *this;
       
   601 }
       
   602 
       
   603 // ---------------------------------------------------------------------------
       
   604 // CSwtListBox::CoeControl
       
   605 // From MSwtControl
       
   606 // ---------------------------------------------------------------------------
       
   607 //
       
   608 const CCoeControl& CSwtListBox::CoeControl() const
       
   609 {
       
   610     return *this;
       
   611 }
       
   612 
       
   613 // ---------------------------------------------------------------------------
       
   614 // CSwtListBox::ComputeSizeL
       
   615 // From MSwtControl
       
   616 // ---------------------------------------------------------------------------
       
   617 //
       
   618 TSize CSwtListBox::ComputeSizeL(TInt aWhint, TInt aHhint)
       
   619 {
       
   620     if (!iList)
       
   621     {
       
   622         return TSize(0, 0);
       
   623     }
       
   624 
       
   625     TSize prefSize(aWhint, aHhint);
       
   626 
       
   627     if (aWhint == KSwtDefault)
       
   628     {
       
   629         // Add the border width
       
   630         prefSize.iWidth = GetBorderWidth() * KVBorderSides;
       
   631 
       
   632         // Add the vertical scrollbar space if present
       
   633         if (SbFrame()->ScrollBarExists(CEikScrollBar::EVertical)
       
   634                 && SbFrame()->ScrollBarVisibility(CEikScrollBar::EVertical)
       
   635                 != CEikScrollBarFrame::EOff)
       
   636         {
       
   637             prefSize.iWidth += iDisplay.UiUtils().ScrollBarBreadth(
       
   638                                    SbFrame()->VerticalScrollBar());
       
   639         }
       
   640 
       
   641         // Add minimum item width
       
   642         prefSize.iWidth += MinimumListItemWidth();
       
   643     }
       
   644     else
       
   645     {
       
   646         prefSize.iWidth = aWhint;
       
   647     }
       
   648 
       
   649 
       
   650     if (aHhint == KSwtDefault)
       
   651     {
       
   652         // Add the border width
       
   653         prefSize.iHeight = GetBorderWidth() * KVBorderSides;
       
   654 
       
   655         // Add the height of all items
       
   656         prefSize.iHeight += iList->CalcHeightBasedOnNumOfItems(
       
   657                                 iItems.Count());
       
   658     }
       
   659     else
       
   660     {
       
   661         prefSize.iHeight = aHhint;
       
   662     }
       
   663 
       
   664     return prefSize;
       
   665 }
       
   666 
       
   667 // ---------------------------------------------------------------------------
       
   668 // CSwtListBox::ProcessKeyEventL
       
   669 // From MSwtControl
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 void CSwtListBox::ProcessKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   673 {
       
   674 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   675     if (aType == EEventKeyDown)
       
   676     {
       
   677         // After panning focus highlight was disabled, so enabling again
       
   678         EnableFocusHighlight(ETrue);
       
   679     }
       
   680 #endif //RD_JAVA_S60_RELEASE_9_2
       
   681 
       
   682     // No items or not a normal key event
       
   683     if (iList->Model()->NumberOfItems() == 0 || aType != EEventKey)
       
   684     {
       
   685         iList->OfferKeyEventL(aKeyEvent, aType);
       
   686         return;
       
   687     }
       
   688 
       
   689     TBool scroll = aKeyEvent.iCode == EKeyDownArrow || aKeyEvent.iCode == EKeyUpArrow
       
   690                    || aKeyEvent.iCode == EKeyNext || aKeyEvent.iCode == EKeyPrevious;
       
   691     TBool submit = aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK;
       
   692 
       
   693     // For performance considerations, assuming that Enter or Select always
       
   694     // does change the multi selection. If the assumption is wrong, we must
       
   695     // store the multi selection before the key is handled and then compare:
       
   696     // if ( ( iStyle & KSwtStyleMulti ) && submit ) GetUserSelectionL( iPrevSelItems );
       
   697 
       
   698     // Store selection before letting the list handle the key.
       
   699     if ((iStyle & KSwtStyleSingle) && scroll)
       
   700     {
       
   701         iPrevFocusIndex = iList->View()->CurrentItemIndex();
       
   702     }
       
   703 
       
   704     iList->OfferKeyEventL(aKeyEvent, aType);
       
   705 
       
   706     if (scroll || submit)
       
   707     {
       
   708         if (iStyle & KSwtStyleSingle)
       
   709         {
       
   710             // Single lists
       
   711             if (submit)
       
   712             {
       
   713                 // Item submited, send default selection event.
       
   714                 iDisplay.PostDefaultSelectionEventL(iPeer);
       
   715             }
       
   716             else
       
   717             {
       
   718                 if (iList->View()->CurrentItemIndex() != iPrevFocusIndex)
       
   719                 {
       
   720                     // Ensure the selection and focus index are in sync.
       
   721                     iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
   722 
       
   723                     // Item focus highlight moved, send selection event.
       
   724                     iDisplay.PostSelectionEventL(iPeer);
       
   725                 }
       
   726             }
       
   727         }
       
   728         else
       
   729         {
       
   730             // Multi lists
       
   731             // Msk could have changed: Mark / Unmark
       
   732             UpdateListMskL();
       
   733 
       
   734             // For performance considerations, assuming that Enter or Select always
       
   735             // does change the multi selection. If the assumption is wrong, here's
       
   736             // how we must check if the selection really changed:
       
   737             // if ( submit && iPrevSelItems && ( iList->View()->SelectionIndexes()->
       
   738             // Count() != iPrevSelItems->Count() ) )
       
   739             if (submit)
       
   740             {
       
   741                 // Multi selection changed, send selection event.
       
   742                 iDisplay.PostSelectionEventL(iPeer);
       
   743             }
       
   744         }
       
   745     }
       
   746 }
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // CSwtListBox::IsKeyUsed
       
   750 // From MSwtControl
       
   751 // ---------------------------------------------------------------------------
       
   752 //
       
   753 TBool CSwtListBox::IsKeyUsed(TUint aKeyCode) const
       
   754 {
       
   755     if (aKeyCode == EKeyBackspace)
       
   756     {
       
   757         return EFalse;
       
   758     }
       
   759     else if (aKeyCode == EKeyOK)
       
   760     {
       
   761         if (iStyle & KSwtStyleSingle)
       
   762         {
       
   763             MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   764             if (commandArranger)
       
   765             {
       
   766                 if (commandArranger->IsContextSensitiveOperationSet())
       
   767                 {
       
   768                     return EFalse;
       
   769                 }
       
   770             }
       
   771             return ETrue;
       
   772         }
       
   773         else
       
   774         {
       
   775             return ETrue;
       
   776         }
       
   777     }
       
   778     else
       
   779     {
       
   780         return ETrue;
       
   781     }
       
   782 }
       
   783 
       
   784 
       
   785 TBool CSwtListBox::MSKSelCmdEnabled() const
       
   786 {
       
   787     return ETrue;
       
   788 }
       
   789 
       
   790 // ---------------------------------------------------------------------------
       
   791 // CSwtListBox::GetForeground
       
   792 // From MSwtControl
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 TRgb CSwtListBox::GetForeground() const
       
   796 {
       
   797     if (CSwtListBoxLists::IsListFormatted(iProps.iListType))
       
   798     {
       
   799         // Get the text color from the formatted list item drawer
       
   800         return (static_cast< CEikFormattedCellListBox* >(iList))->
       
   801                ItemDrawer()->TextColor();
       
   802     }
       
   803     else
       
   804     {
       
   805         // Get the text color from the column list item drawer
       
   806         return (static_cast< CEikColumnListBox* >(iList))->
       
   807                ItemDrawer()->TextColor();
       
   808     }
       
   809 }
       
   810 
       
   811 // ---------------------------------------------------------------------------
       
   812 // CSwtListBox::SetForegroundL
       
   813 // From MSwtControl
       
   814 // ---------------------------------------------------------------------------
       
   815 //
       
   816 void CSwtListBox::SetForegroundL(const MSwtColor* aColor)
       
   817 {
       
   818     iColor = aColor;
       
   819     UpdateListColor();
       
   820     Redraw();
       
   821 }
       
   822 
       
   823 // ---------------------------------------------------------------------------
       
   824 // CSwtListBase::SetBackgroundL
       
   825 // From MSwtControl
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 void CSwtListBox::SetBackgroundL(const MSwtColor* aColor)
       
   829 {
       
   830     ASwtControlBase::DoSetBackgroundL(aColor);
       
   831     iList->HandleResourceChange(KEikMessageColorSchemeChange);
       
   832     Redraw();
       
   833 }
       
   834 
       
   835 // ---------------------------------------------------------------------------
       
   836 // CSwtListBase::IsLongTapAnimationCandidate
       
   837 // From MSwtControl
       
   838 // ---------------------------------------------------------------------------
       
   839 //
       
   840 #ifdef RD_SCALABLE_UI_V2
       
   841 TBool CSwtListBox::IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const
       
   842 {
       
   843     ASSERT(iList);
       
   844     TInt itemIndex = KErrNotFound;
       
   845     TBool pointerOverItem = iList->View()->XYPosToItemIndex(aPointerEvent.iPosition, itemIndex);
       
   846     return pointerOverItem && ASwtControlBase::IsLongTapAnimationCandidate(aPointerEvent);
       
   847 }
       
   848 #else
       
   849 TBool CSwtListBox::IsLongTapAnimationCandidate(const TPointerEvent& /*aPointerEvent*/) const
       
   850 {
       
   851     return EFalse;
       
   852 }
       
   853 #endif
       
   854 
       
   855 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   856 // ---------------------------------------------------------------------------
       
   857 // CSwtListBox::EnableFocusHighlight
       
   858 // From MSwtControl
       
   859 // ---------------------------------------------------------------------------
       
   860 //
       
   861 void CSwtListBox::EnableFocusHighlight(TBool aEnable)
       
   862 {
       
   863     ASSERT(iList);
       
   864     ASSERT(iList->View());
       
   865 
       
   866     CSwtListBoxLists::EnableFocusHighlight(iList->View()->ItemDrawer(),
       
   867                                            aEnable);
       
   868 }
       
   869 #endif //RD_JAVA_S60_RELEASE_9_2
       
   870 
       
   871 TInt CSwtListBox::FocusBackgroundPolicy() const
       
   872 {
       
   873 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   874     return ENoFocusBackgroundInCaptionedControl;
       
   875 #else
       
   876     return EDefaultFocusBackground;
       
   877 #endif // RD_JAVA_S60_RELEASE_9_2
       
   878 }
       
   879 
       
   880 // ---------------------------------------------------------------------------
       
   881 // CSwtListBox::PrepareForTraverse
       
   882 // From MSwtControl
       
   883 // ---------------------------------------------------------------------------
       
   884 //
       
   885 void CSwtListBox::PrepareForTraverse()
       
   886 {
       
   887     ASSERT(iList);
       
   888     ASSERT(iList->View());
       
   889 
       
   890 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   891     // AvKon enables highlight only when key event is recieved.
       
   892     // When traversing, no key event is sent to AvKon, so we
       
   893     // have to enable highlight by ourselves.
       
   894     CListItemDrawer* itemDrawer = iList->View()->ItemDrawer();
       
   895     if (itemDrawer)
       
   896     {
       
   897         itemDrawer->ClearFlags(CListItemDrawer::ESingleClickDisabledHighlight);
       
   898     }
       
   899 #endif //RD_JAVA_S60_RELEASE_9_2
       
   900 }
       
   901 
       
   902 // ---------------------------------------------------------------------------
       
   903 // CSwtListBox::Scrollable
       
   904 // From MSwtListBox
       
   905 // ---------------------------------------------------------------------------
       
   906 //
       
   907 MSwtScrollable* CSwtListBox::Scrollable()
       
   908 {
       
   909     return this;
       
   910 }
       
   911 
       
   912 // ---------------------------------------------------------------------------
       
   913 // CSwtListBox::SetLayoutStyleL
       
   914 // From MSwtListBox
       
   915 // ---------------------------------------------------------------------------
       
   916 //
       
   917 void CSwtListBox::SetLayoutStyleL(TInt aLayoutStyle)
       
   918 {
       
   919     ASSERT(!iList);
       
   920 
       
   921     // Calculate first the list properties
       
   922     iProps = ListProperties(aLayoutStyle, iStyle);
       
   923 
       
   924     // Change style to SINGLE if MULTI is not supported
       
   925     if ((iProps.iSelectionType == ESwtLbSingleSelection)
       
   926             && (iStyle & KSwtStyleMulti))
       
   927     {
       
   928         iStyle &= ~KSwtStyleMulti;
       
   929         iStyle |= KSwtStyleSingle;
       
   930     }
       
   931 
       
   932     // Create a list based on properties
       
   933     iList = CreateListL(iProps.iListType);
       
   934     if (!iList)
       
   935     {
       
   936         User::Leave(ESwtErrorNullArgument);
       
   937     }
       
   938 
       
   939     // Set image array
       
   940     iImgs = CreateListImgArrL(iProps.iSelectionType == ESwtLbMultiSelection);
       
   941     if (!iImgs)
       
   942     {
       
   943         User::Leave(ESwtErrorNullArgument);
       
   944     }
       
   945     else
       
   946     {
       
   947         if (CSwtListBoxLists::IsListFormatted(iProps.iListType))
       
   948         {
       
   949             CFormattedCellListBoxData* cellData =
       
   950                 (static_cast< CEikFormattedCellListBox* >(iList))->
       
   951                 ItemDrawer()->FormattedCellData();
       
   952             cellData->SetIconArray(iImgs);
       
   953             cellData->SetSkinEnabledL(EFalse);
       
   954         }
       
   955         else
       
   956         {
       
   957             CColumnListBoxData* columnData =
       
   958                 (static_cast< CEikColumnListBox* >(iList))->
       
   959                 ItemDrawer()->ColumnData();
       
   960             columnData->SetIconArray(iImgs);
       
   961             columnData->SetSkinEnabledL(EFalse);
       
   962         }
       
   963     }
       
   964 
       
   965     // Set text array
       
   966     iTxts = new(ELeave) CDesCArrayFlat(KInitTxtArrLength);
       
   967     iList->Model()->SetItemTextArray(iTxts);
       
   968     iList->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   969 
       
   970     // Selected item array
       
   971     iPrevSelItems = new(ELeave) CArrayFixFlat<TInt>(KInitSelArrLength);
       
   972 
       
   973     // Get item cells
       
   974     CSwtListBoxLists::CellsL(iProps.iListType, iCells);
       
   975 
       
   976     // This is needed for the case where the theme has animated highlights.
       
   977     iList->SetFocus(ETrue, ENoDrawNow);
       
   978 
       
   979 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   980     // Disable stretching for two line lists
       
   981     switch (iProps.iListType)
       
   982     {
       
   983     case ESwtLbDouble:
       
   984     case ESwtLbDoubleGraphic:
       
   985     case ESwtLbDoubleLarge:
       
   986         // Disable stretching to keep items double line in landscape
       
   987         CSwtListBoxLists::EnableStretching(iProps.iListType, iList, EFalse);
       
   988         break;
       
   989     default:
       
   990         // Do nothing
       
   991         break;
       
   992     }
       
   993 #endif
       
   994 
       
   995     UpdateListMskL();
       
   996 
       
   997     ActivateL();
       
   998 
       
   999     // Because the creation of the contained list is delayed
       
  1000     // we need to ensure that it redraws with correct size.
       
  1001     // Not doing this would result in empty list in CaptionedControl for instance.
       
  1002     SizeChanged();
       
  1003 }
       
  1004 
       
  1005 // ---------------------------------------------------------------------------
       
  1006 // CSwtListBox::DeselectItemsL
       
  1007 // From MSwtListBox
       
  1008 // ---------------------------------------------------------------------------
       
  1009 //
       
  1010 void CSwtListBox::DeselectItemsL(const TInt* aIndices, TInt aCount)
       
  1011 {
       
  1012     if (aIndices)
       
  1013     {
       
  1014         for (TInt i = 0; i < aCount; i++)
       
  1015         {
       
  1016             SelectListItemL(aIndices[i], EFalse, EFalse);
       
  1017         }
       
  1018     }
       
  1019 }
       
  1020 
       
  1021 // ---------------------------------------------------------------------------
       
  1022 // CSwtListBox::DeselectItemL
       
  1023 // From MSwtListBox
       
  1024 // ---------------------------------------------------------------------------
       
  1025 //
       
  1026 void CSwtListBox::DeselectItemL(TInt aIdx)
       
  1027 {
       
  1028     SelectListItemL(aIdx, EFalse, EFalse);
       
  1029 }
       
  1030 
       
  1031 // ---------------------------------------------------------------------------
       
  1032 // CSwtListBox::DeselectRangeL
       
  1033 // From MSwtListBox
       
  1034 // ---------------------------------------------------------------------------
       
  1035 //
       
  1036 void CSwtListBox::DeselectRangeL(TInt aStart, TInt aEnd)
       
  1037 {
       
  1038     SelectListItemsL(aStart, aEnd, EFalse);
       
  1039 }
       
  1040 
       
  1041 // ---------------------------------------------------------------------------
       
  1042 // CSwtListBox::DeselectAllL
       
  1043 // From MSwtListBox
       
  1044 // ---------------------------------------------------------------------------
       
  1045 //
       
  1046 void CSwtListBox::DeselectAllL()
       
  1047 {
       
  1048     SelectListItemsL(EFalse);
       
  1049 }
       
  1050 
       
  1051 // ---------------------------------------------------------------------------
       
  1052 // CSwtListBox::GetFocusIndex
       
  1053 // From MSwtListBox
       
  1054 // ---------------------------------------------------------------------------
       
  1055 //
       
  1056 TInt CSwtListBox::GetFocusIndex() const
       
  1057 {
       
  1058     return iList->View()->CurrentItemIndex();
       
  1059 }
       
  1060 
       
  1061 // ---------------------------------------------------------------------------
       
  1062 // CSwtListBox::GetSelectionCount
       
  1063 // From MSwtListBox
       
  1064 // ---------------------------------------------------------------------------
       
  1065 //
       
  1066 TInt CSwtListBox::GetSelectionCount() const
       
  1067 {
       
  1068     return iList->View()->SelectionIndexes()->Count();
       
  1069 }
       
  1070 
       
  1071 // ---------------------------------------------------------------------------
       
  1072 // CSwtListBox::GetSelectionIndices
       
  1073 // From MSwtListBox
       
  1074 // ---------------------------------------------------------------------------
       
  1075 //
       
  1076 const CArrayFix<TInt>* CSwtListBox::GetSelectionIndices() const
       
  1077 {
       
  1078     return iList->View()->SelectionIndexes();
       
  1079 }
       
  1080 
       
  1081 // ---------------------------------------------------------------------------
       
  1082 // CSwtListBox::RefreshItemL
       
  1083 // From MSwtListBox
       
  1084 // ---------------------------------------------------------------------------
       
  1085 //
       
  1086 void CSwtListBox::RefreshItemL(TInt aIdx,
       
  1087                                const CSwtListBoxItem* aRemoteItem)
       
  1088 {
       
  1089     ASSERT(aIdx >= 0 && aIdx < iItems.Count());
       
  1090     CSwtLbItem* newItem = NULL;
       
  1091     if (aRemoteItem)
       
  1092     {
       
  1093         newItem = new(ELeave) CSwtLbItem(
       
  1094             aRemoteItem->String().AllocL(),
       
  1095             aRemoteItem->Image(),
       
  1096             aRemoteItem->ImageSize(),
       
  1097             aRemoteItem->HeadingString().AllocL(),
       
  1098             aRemoteItem->HeadingIcon(),
       
  1099             aRemoteItem->HeadingIconSize());
       
  1100     }
       
  1101     else
       
  1102     {
       
  1103         newItem = new(ELeave) CSwtLbItem();
       
  1104     }
       
  1105     DeleteListItem(aIdx);
       
  1106     newItem->iIdx = aIdx;
       
  1107     InsertListItemL(newItem);
       
  1108     iList->HandleItemAdditionL();
       
  1109 }
       
  1110 
       
  1111 // ---------------------------------------------------------------------------
       
  1112 // CSwtListBox::RefreshListL
       
  1113 // From MSwtListBox
       
  1114 // ---------------------------------------------------------------------------
       
  1115 //
       
  1116 void CSwtListBox::RefreshListL(
       
  1117     const RSwtListBoxItemsArray& aRemoteItemsArray)
       
  1118 {
       
  1119     // Guaranteed from the Java side that the remote item array
       
  1120     // is in fact the same item array received in SetDataModelL
       
  1121     TInt count = iItems.Count();
       
  1122     ASSERT(count == aRemoteItemsArray.Count());
       
  1123 
       
  1124     // Replace current items
       
  1125     CSwtListBoxItem* remoteItem = NULL;
       
  1126     CSwtLbItem* newItem = NULL;
       
  1127     for (TInt i = 0; i < count; i++)
       
  1128     {
       
  1129         remoteItem = aRemoteItemsArray[i];
       
  1130         newItem = NULL;
       
  1131         if (remoteItem)
       
  1132         {
       
  1133             newItem = new(ELeave) CSwtLbItem(
       
  1134                 remoteItem->String().AllocL(),
       
  1135                 remoteItem->Image(),
       
  1136                 remoteItem->ImageSize(),
       
  1137                 remoteItem->HeadingString().AllocL(),
       
  1138                 remoteItem->HeadingIcon(),
       
  1139                 remoteItem->HeadingIconSize());
       
  1140         }
       
  1141         else
       
  1142         {
       
  1143             newItem = new(ELeave) CSwtLbItem();
       
  1144         }
       
  1145         newItem->iIdx = i;
       
  1146         DeleteListItem(i);
       
  1147         InsertListItemL(newItem);
       
  1148     }
       
  1149 
       
  1150     // Inform list of model change
       
  1151     iList->HandleItemAdditionL();
       
  1152 }
       
  1153 
       
  1154 // --------------------------------------------------------------------------
       
  1155 // CSwtListBox::SelectItemL
       
  1156 // From MSwtListBox
       
  1157 // ---------------------------------------------------------------------------
       
  1158 //
       
  1159 void CSwtListBox::SelectItemL(TInt aIdx, TBool aScroll)
       
  1160 {
       
  1161     SelectListItemL(aIdx, ETrue, aScroll);
       
  1162 }
       
  1163 
       
  1164 // ---------------------------------------------------------------------------
       
  1165 // CSwtListBox::SelectRangeL
       
  1166 // From MSwtListBox
       
  1167 // ---------------------------------------------------------------------------
       
  1168 //
       
  1169 void CSwtListBox::SelectRangeL(TInt aStart, TInt aEnd)
       
  1170 {
       
  1171 
       
  1172     TInt count = iList->Model()->NumberOfItems();
       
  1173     if (count == 0 || aStart >= count)
       
  1174     {
       
  1175         return;
       
  1176     }
       
  1177 
       
  1178     TInt end(aEnd);
       
  1179     if (end >= count)
       
  1180     {
       
  1181         end = count - 1;
       
  1182     }
       
  1183     TInt start(aStart);
       
  1184     if (start < 0)
       
  1185     {
       
  1186         start = 0;
       
  1187     }
       
  1188 
       
  1189     for (TInt index = start; index <= end; ++index)
       
  1190     {
       
  1191         iList->View()->SelectItemL(index);
       
  1192     }
       
  1193 
       
  1194     UpdateListMskL();
       
  1195 }
       
  1196 
       
  1197 // --------------------------------------------------------------------------
       
  1198 // CSwtListBox::SelectAllL
       
  1199 // From MSwtListBox
       
  1200 // ---------------------------------------------------------------------------
       
  1201 //
       
  1202 void CSwtListBox::SelectAllL()
       
  1203 {
       
  1204     SelectListItemsL(ETrue);
       
  1205 }
       
  1206 
       
  1207 // ---------------------------------------------------------------------------
       
  1208 // CSwtListBox::SetFocusIndex
       
  1209 // ---------------------------------------------------------------------------
       
  1210 //
       
  1211 void CSwtListBox::SetFocusIndex(TInt aIndex)
       
  1212 {
       
  1213     ASSERT(iList);
       
  1214 
       
  1215     // By now, we only call this method in multiple selection.
       
  1216     // In single selection, we assume that setting the focus means selecting.
       
  1217     ASSERT(iStyle & KSwtStyleMulti);
       
  1218 
       
  1219     if (aIndex < 0 || aIndex >= iList->Model()->NumberOfItems())
       
  1220     {
       
  1221         return;
       
  1222     }
       
  1223 
       
  1224     TInt old = iList->CurrentItemIndex();
       
  1225     if (old != aIndex)
       
  1226     {
       
  1227         iList->SetCurrentItemIndex(aIndex);
       
  1228         iList->View()->DrawItem(aIndex);
       
  1229         if (old != -1)
       
  1230         {
       
  1231             iList->View()->DrawItem(old);
       
  1232         }
       
  1233     }
       
  1234     TRAP_IGNORE(UpdateListMskL());
       
  1235 }
       
  1236 
       
  1237 // ---------------------------------------------------------------------------
       
  1238 // CSwtListBox::SetDataModelL
       
  1239 // From MSwtListBox
       
  1240 // ---------------------------------------------------------------------------
       
  1241 //
       
  1242 void CSwtListBox::SetDataModelL(
       
  1243     const RSwtListBoxItemsArray& aRemoteItemsArray)
       
  1244 {
       
  1245     // Delete current items and insert copies of the received ones
       
  1246     TInt count = aRemoteItemsArray.Count();
       
  1247     CSwtListBoxItem* remoteItem = NULL;
       
  1248     CSwtLbItem* newItem = NULL;
       
  1249     DeleteAllListItems();
       
  1250     for (TInt i = 0; i < count; i++)
       
  1251     {
       
  1252         remoteItem = aRemoteItemsArray[i];
       
  1253         newItem = NULL;
       
  1254         if (remoteItem)
       
  1255         {
       
  1256             newItem = new(ELeave) CSwtLbItem(
       
  1257                 remoteItem->String().AllocL(),
       
  1258                 remoteItem->Image(),
       
  1259                 remoteItem->ImageSize(),
       
  1260                 remoteItem->HeadingString().AllocL(),
       
  1261                 remoteItem->HeadingIcon(),
       
  1262                 remoteItem->HeadingIconSize());
       
  1263         }
       
  1264         else
       
  1265         {
       
  1266             newItem = new(ELeave) CSwtLbItem();
       
  1267         }
       
  1268         newItem->iIdx = i;
       
  1269         InsertListItemL(newItem);
       
  1270     }
       
  1271 
       
  1272     // Inform list of model change and select first item
       
  1273     iList->HandleItemAdditionL();
       
  1274     if (iProps.iSelectionType != ESwtLbMultiSelection)
       
  1275     {
       
  1276         SelectListItemL(0, ETrue, EFalse);
       
  1277     }
       
  1278     UpdateListMskL();
       
  1279 }
       
  1280 
       
  1281 // ---------------------------------------------------------------------------
       
  1282 // CSwtListBox::SetHeadingFontL
       
  1283 // From MSwtListBox
       
  1284 // ---------------------------------------------------------------------------
       
  1285 //
       
  1286 void CSwtListBox::SetHeadingFontL(const MSwtFont* /*aFont*/)
       
  1287 {
       
  1288     // Not supported
       
  1289 }
       
  1290 
       
  1291 // ---------------------------------------------------------------------------
       
  1292 // CSwtListBox::ShowSelection
       
  1293 // From MSwtListBox
       
  1294 // ---------------------------------------------------------------------------
       
  1295 //
       
  1296 void CSwtListBox::ShowSelection()
       
  1297 {
       
  1298     if (GetSelectionCount() == 0)
       
  1299     {
       
  1300         return;
       
  1301     }
       
  1302 
       
  1303     TInt idx = KErrNotFound;
       
  1304     if (iProps.iSelectionType == ESwtLbSingleSelection)
       
  1305     {
       
  1306         idx = iList->View()->CurrentItemIndex();
       
  1307     }
       
  1308     else
       
  1309     {
       
  1310         idx = (*(iList->SelectionIndexes()))[0];
       
  1311         for (TInt i = 1; i < iList->SelectionIndexes()->Count(); i++)
       
  1312         {
       
  1313             idx = Min(idx, (*(iList->SelectionIndexes()))[i]);
       
  1314         }
       
  1315     }
       
  1316     iList->ScrollToMakeItemVisible(idx);
       
  1317 }
       
  1318 
       
  1319 // ---------------------------------------------------------------------------
       
  1320 // CSwtListBox::HandleSizeChangedL
       
  1321 // From MSwtListObserver
       
  1322 // ---------------------------------------------------------------------------
       
  1323 //
       
  1324 void CSwtListBox::HandleSizeChangedL()
       
  1325 {
       
  1326     if (CSwtListBoxLists::IsListFormatted(iProps.iListType))
       
  1327     {
       
  1328         CFormattedCellListBoxItemDrawer* itemDrawer = (static_cast<
       
  1329                 CEikFormattedCellListBox* >(iList))->ItemDrawer();
       
  1330         CFormattedCellListBoxData* cellData = itemDrawer->FormattedCellData();
       
  1331         cellData->SetSeparatorLinePosition(ENoLine);
       
  1332         iDefColor = itemDrawer->TextColor();
       
  1333         itemDrawer->SetBackColor(GetBackground());
       
  1334     }
       
  1335     else
       
  1336     {
       
  1337         CColumnListBoxItemDrawer* itemDrawer = (static_cast<
       
  1338                                                 CEikColumnListBox* >(iList))->ItemDrawer();
       
  1339         CColumnListBoxData* cellData = itemDrawer->ColumnData();
       
  1340         cellData->SetSeparatorLinePosition(ENoLine);
       
  1341         iDefColor = itemDrawer->TextColor();
       
  1342         itemDrawer->SetBackColor(GetBackground());
       
  1343     }
       
  1344 
       
  1345     // The listbox looses the custom color after resize, therefore reset.
       
  1346     if (iColor)
       
  1347         UpdateListColor();
       
  1348 
       
  1349     // Suppress margins - they are drawn over scrollbars
       
  1350     // We need to update margins here one more time, because previous
       
  1351     // code re-sets them
       
  1352     CSwtListBoxLists::SetMargins(iProps.iListType, iList, 0, 0);
       
  1353 }
       
  1354 
       
  1355 // ---------------------------------------------------------------------------
       
  1356 // CSwtListBox::Utils
       
  1357 // From MSwtListObserver
       
  1358 // ---------------------------------------------------------------------------
       
  1359 //
       
  1360 MSwtUiUtils& CSwtListBox::Utils() const
       
  1361 {
       
  1362     return iDisplay.UiUtils();
       
  1363 }
       
  1364 
       
  1365 // ---------------------------------------------------------------------------
       
  1366 // CSwtListBox::HandleScrollEventL
       
  1367 // From MEikScrollBarObserver
       
  1368 // ---------------------------------------------------------------------------
       
  1369 //
       
  1370 #ifdef RD_SCALABLE_UI_V2
       
  1371 void CSwtListBox::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType)
       
  1372 {
       
  1373     // On 5.0, drawing trough Java gives simply a better fps.
       
  1374 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1375     switch (aEventType)
       
  1376     {
       
  1377     case EEikScrollThumbDragVert:
       
  1378         GetShell().SetUrgentPaintControl(this);
       
  1379         break;
       
  1380     case EEikScrollThumbReleaseVert:
       
  1381         GetShell().SetUrgentPaintControl(NULL);
       
  1382         break;
       
  1383     default:
       
  1384         break;
       
  1385     }
       
  1386 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1387 
       
  1388     iList->HandleScrollEventL(aScrollBar, aEventType);
       
  1389     ASwtScrollableBase::HandleScrollEventL(aScrollBar, aEventType);
       
  1390 }
       
  1391 #else // RD_SCALABLE_UI_V2
       
  1392 void CSwtListBox::HandleScrollEventL(CEikScrollBar*, TEikScrollEvent)
       
  1393 {
       
  1394 }
       
  1395 #endif // RD_SCALABLE_UI_V2
       
  1396 
       
  1397 // ---------------------------------------------------------------------------
       
  1398 // CSwtListBase::HandleScrollEventL
       
  1399 // From MEikListBoxObserver
       
  1400 // Handles default selection for touch. Unable to handle the selection events
       
  1401 // here since EEventItemClicked is not always sent for every tap.
       
  1402 // The selection events are handled in HandlePointerEvent.
       
  1403 // ---------------------------------------------------------------------------
       
  1404 //
       
  1405 #ifdef RD_SCALABLE_UI_V2
       
  1406 void CSwtListBox::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
  1407 {
       
  1408     if (aListBox != iList)
       
  1409     {
       
  1410         return;
       
  1411     }
       
  1412 
       
  1413     UpdateFlickScrollingState(aEventType);
       
  1414 
       
  1415     switch (aEventType)
       
  1416     {
       
  1417         // On 5.0, drawing trough Java gives simply a better fps.
       
  1418 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1419     case EEventPanningStarted:
       
  1420         GetShell().SetUrgentPaintControl(this);
       
  1421         break;
       
  1422     case EEventFlickStopped:
       
  1423         GetShell().SetUrgentPaintControl(NULL);
       
  1424         break;
       
  1425 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1426 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1427     case EEventItemSingleClicked:
       
  1428 #else
       
  1429     case EEventItemDoubleClicked:
       
  1430 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1431         if (!(iStyle & KSwtStyleMulti))
       
  1432         {
       
  1433             if (!iDisplay.RevertPointerEvent())
       
  1434                 iDisplay.PostDefaultSelectionEventL(iPeer);
       
  1435         }
       
  1436         break;
       
  1437     default:
       
  1438         // Do nothing
       
  1439         break;
       
  1440     }
       
  1441 }
       
  1442 #else // RD_SCALABLE_UI_V2
       
  1443 void CSwtListBox::HandleListBoxEventL(CEikListBox*, TListBoxEvent)
       
  1444 {
       
  1445 }
       
  1446 #endif //RD_SCALABLE_UI_V2
       
  1447 
       
  1448 // ---------------------------------------------------------------------------
       
  1449 // CSwtListBox::ListProperties
       
  1450 // ---------------------------------------------------------------------------
       
  1451 //
       
  1452 CSwtListBox::TSwtLbProp CSwtListBox::ListProperties(TInt aLayoutStyle,
       
  1453         TInt aStyle) const
       
  1454 {
       
  1455     TSwtLbProp lbProp;
       
  1456     lbProp.iListType = ESwtLbSingle;
       
  1457     lbProp.iSelectionType = ESwtLbSingleSelection;
       
  1458     lbProp.iDiconVisible = aLayoutStyle & MSwtListBox::KLbModShowDetailIcons;
       
  1459 
       
  1460     // Heading 2 lines
       
  1461     if (aLayoutStyle & MSwtListBox::ELbStyle2LineItem)
       
  1462     {
       
  1463         if (aLayoutStyle & MSwtListBox::KLbModShowHeadingIcons)
       
  1464         {
       
  1465             lbProp.iListType = ESwtLbDoubleLarge;
       
  1466         }
       
  1467         else if (aStyle & KSwtStyleMulti)
       
  1468         {
       
  1469             lbProp.iSelectionType = ESwtLbMultiSelection;
       
  1470             lbProp.iListType = ESwtLbDoubleGraphic;
       
  1471         }
       
  1472         else
       
  1473         {
       
  1474             lbProp.iListType = ESwtLbDouble;
       
  1475         }
       
  1476     }
       
  1477     // Heading 1 line
       
  1478     else if (aLayoutStyle & MSwtListBox::ELbStyle1LineItem)
       
  1479     {
       
  1480         if (aLayoutStyle & MSwtListBox::KLbModShowHeadingIcons)
       
  1481         {
       
  1482             lbProp.iListType = ESwtLbSingleHeadingGraphic;
       
  1483         }
       
  1484         else if (aStyle & KSwtStyleMulti)
       
  1485         {
       
  1486             lbProp.iListType = ESwtLbSingleHeadingGraphic;
       
  1487             lbProp.iSelectionType = ESwtLbMultiSelection;
       
  1488         }
       
  1489         else
       
  1490         {
       
  1491             lbProp.iListType = ESwtLbSingleHeading;
       
  1492         }
       
  1493     }
       
  1494     // No heading
       
  1495     else
       
  1496     {
       
  1497         if (aLayoutStyle & MSwtListBox::KLbModShowHeadingIcons)
       
  1498         {
       
  1499             lbProp.iListType = ESwtLbSingleLarge;
       
  1500         }
       
  1501         else if (aStyle & KSwtStyleMulti)
       
  1502         {
       
  1503             lbProp.iListType = ESwtLbSingleGraphic;
       
  1504             lbProp.iSelectionType = ESwtLbMultiSelection;
       
  1505         }
       
  1506         else
       
  1507         {
       
  1508             lbProp.iListType = ESwtLbSingle;
       
  1509         }
       
  1510     }
       
  1511 
       
  1512     return lbProp;
       
  1513 }
       
  1514 
       
  1515 // ---------------------------------------------------------------------------
       
  1516 // CSwtListBox::CreateListL
       
  1517 // ---------------------------------------------------------------------------
       
  1518 //
       
  1519 CEikTextListBox* CSwtListBox::CreateListL(TInt aListType)
       
  1520 {
       
  1521     CEikTextListBox* list = CSwtListBoxLists::NewListL(aListType);
       
  1522 
       
  1523     if (list)
       
  1524     {
       
  1525         CleanupStack::PushL(list);
       
  1526         if (iStyle & KSwtStyleMulti)
       
  1527         {
       
  1528             list->ConstructL(this, EAknListBoxStylusMultiselectionList);
       
  1529         }
       
  1530         else
       
  1531         {
       
  1532             list->ConstructL(this, EAknListBoxSelectionList);
       
  1533         }
       
  1534 
       
  1535 #ifdef RD_UI_TRANSITION_EFFECTS_LIST
       
  1536         // Effects do not work with non window owning scrollbars.
       
  1537         CWindowGc* gc = list->View()->ItemDrawer()->Gc();
       
  1538         MAknListBoxTfx* transApi = CAknListLoader::TfxApi(gc);
       
  1539         if (transApi)
       
  1540         {
       
  1541             transApi->EnableEffects(EFalse);
       
  1542         }
       
  1543 #endif // RD_UI_TRANSITION_EFFECTS_LIST
       
  1544 
       
  1545         CSwtListBoxLists::SetListObserver(aListType, list, this);
       
  1546         list->SetContainerWindowL(*this);
       
  1547         list->SetCurrentItemIndex(0);
       
  1548         list->MakeVisible(ETrue);
       
  1549         list->SetComponentsToInheritVisibility(ETrue);
       
  1550         CreateScrollBarsL(list);
       
  1551 
       
  1552 #ifdef RD_SCALABLE_UI_V2
       
  1553         list->SetListBoxObserver(this);
       
  1554 #endif // RD_SCALABLE_UI_V2
       
  1555         CleanupStack::Pop(list);
       
  1556     }
       
  1557 
       
  1558     return list;
       
  1559 }
       
  1560 
       
  1561 // ---------------------------------------------------------------------------
       
  1562 // CSwtListBox::CreateScrollBarsL
       
  1563 // ---------------------------------------------------------------------------
       
  1564 //
       
  1565 void CSwtListBox::CreateScrollBarsL(CEikTextListBox* aList) const
       
  1566 {
       
  1567     ASSERT(aList);
       
  1568     // Horizontal scrollbars are always off, the vertical scrollbars
       
  1569     // are visible if the style contains the vertical scroll bit
       
  1570     aList->CreateScrollBarFrameL();
       
  1571 
       
  1572 #ifdef RD_SCALABLE_UI_V2
       
  1573     // WARNING!!! The expanded touch area does not move correctly togehter with the scrollbars!
       
  1574     aList->ScrollBarFrame()->SetScrollBarFrameFlags(CEikScrollBarFrame::EDisableExpandedTouchArea);
       
  1575 #endif // RD_SCALABLE_UI_V2
       
  1576 
       
  1577     // In eSWT all scrollbars must be non window owing the main reason being that
       
  1578     // the scrollbars must draw at exact same time with the parent control. This
       
  1579     // is especially essential in ScrolledComposite. If the scrollbars would be
       
  1580     // window owing, they would draw too much ahead of the parents creating an
       
  1581     // ugly visual effect when flicking the ScrolledComposite.
       
  1582     // The drawback of having non window owing scrollbars is too many paint events
       
  1583     // which affects on the speed of kinetic scrolling in lists.
       
  1584     aList->ScrollBarFrame()->CreateDoubleSpanScrollBarsL(EFalse, EFalse, ETrue, EFalse);
       
  1585     aList->ScrollBarFrame()->SetScrollBarVisibilityL(
       
  1586         CEikScrollBarFrame::EOff,
       
  1587         iStyle & KSwtStyleVScroll ?
       
  1588         CEikScrollBarFrame::EOn : CEikScrollBarFrame::EOff);
       
  1589 }
       
  1590 
       
  1591 // ---------------------------------------------------------------------------
       
  1592 // CSwtListBox::CreateListImgArrL
       
  1593 // ---------------------------------------------------------------------------
       
  1594 //
       
  1595 CArrayPtr<CGulIcon>* CSwtListBox::CreateListImgArrL(
       
  1596     TBool aMultiSelImgs) const
       
  1597 {
       
  1598     CArrayPtr<CGulIcon>* imgArray =
       
  1599         new(ELeave) CArrayPtrFlat<CGulIcon>(KInitImgArrLength);
       
  1600 
       
  1601     // Selection icons
       
  1602     CleanupStack::PushL(imgArray);
       
  1603     if (aMultiSelImgs)
       
  1604     {
       
  1605         CreateListSelImgsL(imgArray);
       
  1606     }
       
  1607     CleanupStack::Pop(imgArray);
       
  1608 
       
  1609     return imgArray;
       
  1610 }
       
  1611 
       
  1612 // ---------------------------------------------------------------------------
       
  1613 // CSwtListBox::CreateListSelImgsL
       
  1614 // ---------------------------------------------------------------------------
       
  1615 //
       
  1616 void CSwtListBox::CreateListSelImgsL(
       
  1617     CArrayPtr<CGulIcon>* aImgArr) const
       
  1618 {
       
  1619     ASSERT(aImgArr);
       
  1620 
       
  1621     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1622 
       
  1623     // Check box on
       
  1624     CFbsBitmap* bmp = NULL;
       
  1625     CFbsBitmap* mask = NULL;
       
  1626     CGulIcon* checkBox = NULL;
       
  1627 
       
  1628     AknsUtils::CreateIconLC(AknsUtils::SkinInstance(),
       
  1629                             KAknsIIDQgnPropCheckboxOn, bmp, mask,
       
  1630                             AknIconUtils::AvkonIconFileName(),
       
  1631                             EMbmAvkonQgn_prop_checkbox_on,
       
  1632                             EMbmAvkonQgn_prop_checkbox_on_mask);
       
  1633 
       
  1634     checkBox = CGulIcon::NewL(bmp, mask);
       
  1635     CleanupStack::PushL(checkBox);
       
  1636     if (aImgArr->Count() > KImgIdxOn)
       
  1637     {
       
  1638         if (aImgArr->At(KImgIdxOn))
       
  1639         {
       
  1640             delete aImgArr->At(KImgIdxOn);
       
  1641         }
       
  1642         aImgArr->At(KImgIdxOn) = checkBox;
       
  1643     }
       
  1644     else
       
  1645     {
       
  1646         aImgArr->AppendL(checkBox);
       
  1647     }
       
  1648     CleanupStack::Pop(3);   // bmp, mask, checkbox
       
  1649 
       
  1650     // Check box off
       
  1651     bmp = NULL;
       
  1652     mask = NULL;
       
  1653     checkBox = NULL;
       
  1654 
       
  1655     AknsUtils::CreateIconLC(AknsUtils::SkinInstance(),
       
  1656                             KAknsIIDQgnPropCheckboxOff, bmp, mask,
       
  1657                             AknIconUtils::AvkonIconFileName(),
       
  1658                             EMbmAvkonQgn_prop_checkbox_off,
       
  1659                             EMbmAvkonQgn_prop_checkbox_off_mask);
       
  1660 
       
  1661     checkBox = CGulIcon::NewL(bmp, mask);
       
  1662     CleanupStack::PushL(checkBox);
       
  1663     if (aImgArr->Count() > KImgIdxOff)
       
  1664     {
       
  1665         if (aImgArr->At(KImgIdxOff))
       
  1666         {
       
  1667             delete aImgArr->At(KImgIdxOff);
       
  1668         }
       
  1669         aImgArr->At(KImgIdxOff) = checkBox;
       
  1670     }
       
  1671     else
       
  1672     {
       
  1673         aImgArr->AppendL(checkBox);
       
  1674     }
       
  1675     CleanupStack::Pop(3);   // bmp, mask, checkbox
       
  1676 }
       
  1677 
       
  1678 // ---------------------------------------------------------------------------
       
  1679 // CSwtListBox::InsertListItemL
       
  1680 // ---------------------------------------------------------------------------
       
  1681 //
       
  1682 void CSwtListBox::InsertListItemL(CSwtLbItem* aItem)
       
  1683 {
       
  1684     CleanupStack::PushL(aItem);
       
  1685 
       
  1686     // Heading image
       
  1687     CGulIcon* img = NULL;
       
  1688     TInt imgIdx = KImgIdxNull;
       
  1689     TSize bitmapSize(TSize::EUninitialized);
       
  1690     if (iProps.iListType == ESwtLbSingleGraphic
       
  1691             || iProps.iListType == ESwtLbSingleLarge
       
  1692             || iProps.iListType == ESwtLbSingleHeadingGraphic
       
  1693             || iProps.iListType == ESwtLbDoubleGraphic
       
  1694             || iProps.iListType == ESwtLbDoubleLarge)
       
  1695     {
       
  1696         // Create / allocate image
       
  1697         img = CreateListImgL(aItem->HeadingIcon(), EFalse, bitmapSize);
       
  1698         if (img)
       
  1699         {
       
  1700             aItem->SetHeadingIconSize(bitmapSize);
       
  1701             // Insert image
       
  1702             CleanupStack::PushL(img);
       
  1703             imgIdx = InsertListImgL(img);
       
  1704             CleanupStack::Pop(img);
       
  1705             aItem->iHimgIdx = imgIdx;
       
  1706         }
       
  1707     }
       
  1708 
       
  1709     // Detail image
       
  1710     if (iProps.iDiconVisible)
       
  1711     {
       
  1712         // Create / allocate image
       
  1713         img = CreateListImgL(aItem->Image(), ETrue, bitmapSize);
       
  1714         if (img)
       
  1715         {
       
  1716             aItem->SetImageSize(bitmapSize);
       
  1717             // Insert image
       
  1718             CleanupStack::PushL(img);
       
  1719             imgIdx = InsertListImgL(img);
       
  1720             CleanupStack::Pop(img);
       
  1721             aItem->iDimgIdx = imgIdx;
       
  1722         }
       
  1723     }
       
  1724 
       
  1725     // Store the item
       
  1726     iItems.Insert(aItem, aItem->iIdx);
       
  1727 
       
  1728     // Insert string into the list text array
       
  1729     HBufC* buf = CreateListTxtL(aItem);
       
  1730     ASSERT(buf);
       
  1731     CleanupStack::PushL(buf);
       
  1732     InsertListTxtL(*buf, aItem->iIdx);
       
  1733     CleanupStack::PopAndDestroy(buf);
       
  1734 
       
  1735     CleanupStack::Pop(aItem);
       
  1736 }
       
  1737 
       
  1738 // ---------------------------------------------------------------------------
       
  1739 // CSwtListBox::CreateListImgL
       
  1740 // ---------------------------------------------------------------------------
       
  1741 //
       
  1742 CGulIcon* CSwtListBox::CreateListImgL(const MSwtImage* aSwtImg, const TBool aDetailIcon,
       
  1743                                       TSize& aBitmapResSize) const
       
  1744 {
       
  1745     CGulIcon* img = NULL;
       
  1746     if (aSwtImg)
       
  1747     {
       
  1748         CFbsBitmap* bmp = 0;
       
  1749         CFbsBitmap* mask = 0;
       
  1750         TSize maxIconSize = aDetailIcon ? iMaxDetailIconSize : iMaxHeadingIconSize;
       
  1751         TSize bitmapSize = aSwtImg->Bitmap().SizeInPixels();
       
  1752 
       
  1753         if (bitmapSize.iWidth > maxIconSize.iWidth ||
       
  1754                 bitmapSize.iHeight > maxIconSize.iHeight)
       
  1755         {
       
  1756             bitmapSize = SwtControlHelper::GetAspectRatioScaledBitmapSize(
       
  1757                              bitmapSize, maxIconSize);
       
  1758         }
       
  1759 
       
  1760         bmp =  const_cast<CFbsBitmap*>(&aSwtImg->SubBitmap(bitmapSize));
       
  1761         mask = const_cast<CFbsBitmap*>(aSwtImg->SubMaskBitmap(bitmapSize, ETrue));
       
  1762 
       
  1763         aSwtImg->AddSubRef(bitmapSize);
       
  1764         aBitmapResSize = bitmapSize;
       
  1765 
       
  1766         img = CGulIcon::NewL();
       
  1767         img->SetBitmapsOwnedExternally(ETrue);   // Freed by CSwtImage
       
  1768         img->SetBitmap(bmp);
       
  1769         img->SetMask(mask);
       
  1770     }
       
  1771     return img;
       
  1772 }
       
  1773 
       
  1774 // ---------------------------------------------------------------------------
       
  1775 // CSwtListBox::InsertListImgL
       
  1776 // ---------------------------------------------------------------------------
       
  1777 //
       
  1778 TInt CSwtListBox::InsertListImgL(CGulIcon* aImg)
       
  1779 {
       
  1780     ASSERT(aImg);
       
  1781 
       
  1782     TInt imgIdx = KImgIdxNull;
       
  1783     TInt nrOfImgs = iImgs->Count();
       
  1784 
       
  1785     // Search for a free position and insert if any
       
  1786     for (TInt i = 0; i < nrOfImgs; i++)
       
  1787     {
       
  1788         if (!iImgs->At(i))
       
  1789         {
       
  1790             iImgs->At(i) = aImg;
       
  1791             imgIdx = i;
       
  1792             break;
       
  1793         }
       
  1794     }
       
  1795 
       
  1796     // Append if no position was free
       
  1797     if (imgIdx == KImgIdxNull)
       
  1798     {
       
  1799         iImgs->AppendL(aImg);
       
  1800         imgIdx = nrOfImgs;
       
  1801     }
       
  1802 
       
  1803     return imgIdx;
       
  1804 }
       
  1805 
       
  1806 // ---------------------------------------------------------------------------
       
  1807 // CSwtListBox::CreateListTxtL
       
  1808 // ---------------------------------------------------------------------------
       
  1809 //
       
  1810 HBufC* CSwtListBox::CreateListTxtL(const CSwtLbItem* aItem) const
       
  1811 {
       
  1812     if (!aItem)
       
  1813     {
       
  1814         return KNullDesC().AllocL();
       
  1815     }
       
  1816 
       
  1817     // Convert heading image index to string
       
  1818     TBuf<KMaxIdxDigitCount> hImgIdxTxt;
       
  1819     if (iProps.iSelectionType == ESwtLbMultiSelection)
       
  1820     {
       
  1821         hImgIdxTxt.AppendNum(KImgIdxOff);
       
  1822     }
       
  1823     else
       
  1824     {
       
  1825         if (aItem->iHimgIdx != KImgIdxNull)
       
  1826         {
       
  1827             hImgIdxTxt.AppendNum(aItem->iHimgIdx);
       
  1828         }
       
  1829         else
       
  1830         {
       
  1831             hImgIdxTxt.Append(KNullDesC);
       
  1832         }
       
  1833     }
       
  1834 
       
  1835     // Convert detail image index to string
       
  1836     TBuf<KMaxIdxDigitCount> dImgIdxTxt;
       
  1837     if (iProps.iDiconVisible
       
  1838             && (aItem->iDimgIdx != KImgIdxNull))
       
  1839     {
       
  1840         dImgIdxTxt.AppendNum(aItem->iDimgIdx);
       
  1841     }
       
  1842     else
       
  1843     {
       
  1844         dImgIdxTxt.Append(KNullDesC);
       
  1845     }
       
  1846 
       
  1847     // Replace tabs in heading string
       
  1848     HBufC* hBuf = HBufC::NewLC(aItem->HeadingString().Length());
       
  1849     *hBuf = aItem->HeadingString();
       
  1850     TabsToSpaces(hBuf);
       
  1851 
       
  1852     // Replace tabs in detail string
       
  1853     HBufC* dBuf = HBufC::NewLC(aItem->String().Length());
       
  1854     *dBuf = aItem->String();
       
  1855     TabsToSpaces(dBuf);
       
  1856 
       
  1857     // Allocate buffer for the new formatted string
       
  1858     HBufC* buf = HBufC::NewL(dImgIdxTxt.Length()
       
  1859                              + hImgIdxTxt.Length()
       
  1860                              + hBuf->Length()
       
  1861                              + dBuf->Length()
       
  1862                              + KTxtTab().Length() * KMaxCellCount);
       
  1863     *buf = KNullDesC;
       
  1864     TPtr txt = buf->Des();
       
  1865 
       
  1866     // Go trough cells and format the new string
       
  1867     // depending on the type of each cell
       
  1868     TInt count = iCells.Count();
       
  1869     for (TInt i = 0; i < count; i++)
       
  1870     {
       
  1871         switch (iCells[i])
       
  1872         {
       
  1873         case ECellDtxt:
       
  1874             txt.Append(*dBuf);
       
  1875             break;
       
  1876         case ECellDimg:
       
  1877             txt.Append(dImgIdxTxt);
       
  1878             break;
       
  1879         case ECellHtxt:
       
  1880             txt.Append(*hBuf);
       
  1881             break;
       
  1882         case ECellHimg:
       
  1883             txt.Append(hImgIdxTxt);
       
  1884             break;
       
  1885         case ECellEmpty:
       
  1886         default:
       
  1887             // do nothing
       
  1888             break;
       
  1889         }
       
  1890         txt.Append(KTxtTab);
       
  1891     }
       
  1892 
       
  1893     CleanupStack::PopAndDestroy(dBuf);
       
  1894     CleanupStack::PopAndDestroy(hBuf);
       
  1895 
       
  1896     return buf;
       
  1897 }
       
  1898 
       
  1899 // ---------------------------------------------------------------------------
       
  1900 // CSwtListBox::InsertListTxtL
       
  1901 // ---------------------------------------------------------------------------
       
  1902 //
       
  1903 void CSwtListBox::InsertListTxtL(const TDesC& aTxt, TInt aIdx)
       
  1904 {
       
  1905     ASSERT(iTxts);
       
  1906     iTxts->InsertL(aIdx, aTxt);
       
  1907 }
       
  1908 
       
  1909 // ---------------------------------------------------------------------------
       
  1910 // CSwtListBox::DeleteListItem
       
  1911 // ---------------------------------------------------------------------------
       
  1912 //
       
  1913 void CSwtListBox::DeleteListItem(TInt aIdx)
       
  1914 {
       
  1915     // Out of range check
       
  1916     if (aIdx < 0 || aIdx >= iItems.Count())
       
  1917     {
       
  1918         return;
       
  1919     }
       
  1920 
       
  1921     // Delete images & texts, remove item
       
  1922     CSwtLbItem* item = iItems[aIdx];
       
  1923     if (!item)
       
  1924     {
       
  1925         return;
       
  1926     }
       
  1927 
       
  1928     // If we have at some point created a scaled copies for list item images,
       
  1929     // remove references to the copies here.
       
  1930     const MSwtImage* dImg = item->Image();
       
  1931     const MSwtImage* hImg = item->HeadingIcon();
       
  1932     const TSize dImgSize = item->ImageSize();
       
  1933     const TSize hImgSize = item->HeadingIconSize();
       
  1934 
       
  1935     if (dImg && dImgSize != TSize(TSize::EUninitialized))
       
  1936     {
       
  1937         dImg->RemoveSubRef(item->ImageSize());
       
  1938     }
       
  1939 
       
  1940     if (hImg && hImgSize != TSize(TSize::EUninitialized))
       
  1941     {
       
  1942         hImg->RemoveSubRef(item->HeadingIconSize());
       
  1943     }
       
  1944 
       
  1945     DeleteListImg(item->iHimgIdx);
       
  1946     DeleteListImg(item->iDimgIdx);
       
  1947     DeleteListTxt(aIdx);
       
  1948     iItems.Remove(aIdx);
       
  1949     delete item;
       
  1950 }
       
  1951 
       
  1952 // ---------------------------------------------------------------------------
       
  1953 // CSwtListBox::DeleteAllListItems
       
  1954 // ---------------------------------------------------------------------------
       
  1955 //
       
  1956 void CSwtListBox::DeleteAllListItems()
       
  1957 {
       
  1958     // Clear selection
       
  1959     iList->View()->ClearSelection();
       
  1960 
       
  1961     // Remove all texts
       
  1962     iTxts->Reset();
       
  1963 
       
  1964     RemoveSubRefs();
       
  1965 
       
  1966     // Remove all images except the selection check box images
       
  1967     if (iProps.iSelectionType != ESwtLbMultiSelection)
       
  1968     {
       
  1969         iImgs->ResetAndDestroy();
       
  1970     }
       
  1971     else
       
  1972     {
       
  1973         if (iImgs->Count() > (KImgIdxOff + 1))
       
  1974         {
       
  1975             for (TInt i = KImgIdxOff + 1; i < iImgs->Count(); i++)
       
  1976             {
       
  1977                 delete iImgs->At(i);
       
  1978             }
       
  1979             iImgs->Delete(
       
  1980                 KImgIdxOff + 1,
       
  1981                 iImgs->Count() - (KImgIdxOff + 1));
       
  1982         }
       
  1983     }
       
  1984 
       
  1985     // Remove all items
       
  1986     iItems.ResetAndDestroy();
       
  1987 }
       
  1988 
       
  1989 // ---------------------------------------------------------------------------
       
  1990 // CSwtListBox::DeleteListImg
       
  1991 // ---------------------------------------------------------------------------
       
  1992 //
       
  1993 void CSwtListBox::DeleteListImg(TInt aIdx)
       
  1994 {
       
  1995     if (aIdx >= 0 && aIdx < iImgs->Count())
       
  1996     {
       
  1997         delete iImgs->At(aIdx);
       
  1998         iImgs->At(aIdx) = NULL;
       
  1999     }
       
  2000 }
       
  2001 
       
  2002 // ---------------------------------------------------------------------------
       
  2003 // CSwtListBox::DeleteListTxt
       
  2004 // ---------------------------------------------------------------------------
       
  2005 //
       
  2006 void CSwtListBox::DeleteListTxt(TInt aIdx)
       
  2007 {
       
  2008     ASSERT(iTxts);
       
  2009     ASSERT(aIdx >= 0 && aIdx < iTxts->Count());
       
  2010     iTxts->Delete(aIdx);
       
  2011 }
       
  2012 
       
  2013 // ---------------------------------------------------------------------------
       
  2014 // CSwtListBox::SelectListItemL
       
  2015 // ---------------------------------------------------------------------------
       
  2016 //
       
  2017 void CSwtListBox::SelectListItemL(TInt aIdx, TBool aSelected, TBool aScroll)
       
  2018 {
       
  2019     // Ignore call if item is out of range
       
  2020     if (aIdx < 0 || aIdx >= iItems.Count())
       
  2021     {
       
  2022         return;
       
  2023     }
       
  2024 
       
  2025     if (iProps.iSelectionType == ESwtLbMultiSelection)
       
  2026     {
       
  2027         // Multi selection
       
  2028         if (aSelected)
       
  2029         {
       
  2030             // Select
       
  2031             iList->View()->SelectItemL(aIdx);
       
  2032             if (aScroll)
       
  2033             {
       
  2034                 iList->ScrollToMakeItemVisible(aIdx);
       
  2035             }
       
  2036         }
       
  2037         else
       
  2038         {
       
  2039             // Deselect
       
  2040             iList->View()->DeselectItem(aIdx);
       
  2041         }
       
  2042         UpdateListMskL();
       
  2043     }
       
  2044     else
       
  2045     {
       
  2046         // Single selection
       
  2047         if (aSelected)
       
  2048         {
       
  2049             // Select
       
  2050             if (aScroll && iList->View()->ViewRect().Height() >= iList->ItemHeight())
       
  2051             {
       
  2052                 iList->View()->VerticalMoveToItemL(aIdx, CListBoxView::ESingleSelection);
       
  2053             }
       
  2054             else
       
  2055             {
       
  2056                 TInt old = iList->CurrentItemIndex();
       
  2057                 iList->View()->SetCurrentItemIndex(aIdx); //we do not call CEikListBox::SetCurrentItemIndex, because we do not want to scroll.
       
  2058                 iList->View()->UpdateSelectionL(CListBoxView::ESingleSelection);
       
  2059                 if (old != -1)
       
  2060                 {
       
  2061                     iList->View()->DrawItem(old);
       
  2062                 }
       
  2063             }
       
  2064         }
       
  2065         // Calls to deselect when the style is SINGLE are ignored.
       
  2066     }
       
  2067 }
       
  2068 
       
  2069 // ---------------------------------------------------------------------------
       
  2070 // CSwtListBox::SelectListItemL
       
  2071 // ---------------------------------------------------------------------------
       
  2072 //
       
  2073 void CSwtListBox::SelectListItemsL(TInt aStart, TInt aEnd, TBool aSelected)
       
  2074 {
       
  2075     for (TInt i = aStart; i <= aEnd; i++)
       
  2076     {
       
  2077         SelectListItemL(i, aSelected, EFalse);
       
  2078     }
       
  2079 }
       
  2080 
       
  2081 // ---------------------------------------------------------------------------
       
  2082 // CSwtListBox::SelectListItemL
       
  2083 // ---------------------------------------------------------------------------
       
  2084 //
       
  2085 void CSwtListBox::SelectListItemsL(TBool aSelected)
       
  2086 {
       
  2087     SelectListItemsL(0, iItems.Count() - 1, aSelected);
       
  2088 }
       
  2089 
       
  2090 
       
  2091 // ---------------------------------------------------------------------------
       
  2092 // CSwtListBox::GetUserSelectionL
       
  2093 // ---------------------------------------------------------------------------
       
  2094 //
       
  2095 void CSwtListBox::GetUserSelectionL(CArrayFix<TInt>* aCurrSelItems)
       
  2096 {
       
  2097     // Multi selected items array
       
  2098     if ((iStyle & KSwtStyleMulti) && aCurrSelItems)
       
  2099     {
       
  2100         iList->View()->GetSelectionIndexesL(aCurrSelItems);
       
  2101     }
       
  2102 }
       
  2103 
       
  2104 // ---------------------------------------------------------------------------
       
  2105 // CSwtListBox::UpdateListColor
       
  2106 // ---------------------------------------------------------------------------
       
  2107 //
       
  2108 void CSwtListBox::UpdateListColor()
       
  2109 {
       
  2110     TRgb color;
       
  2111 
       
  2112     if (iColor)
       
  2113     {
       
  2114         // Use current color
       
  2115         color = iColor->RgbValue();
       
  2116     }
       
  2117     else
       
  2118     {
       
  2119         // Use default color
       
  2120         color = iDefColor;
       
  2121     }
       
  2122 
       
  2123     if (CSwtListBoxLists::IsListFormatted(iProps.iListType))
       
  2124     {
       
  2125         // Set text and highlighted text color to the formatted item drawer
       
  2126         static_cast< CEikFormattedCellListBox* >(iList)->
       
  2127         ItemDrawer()->SetTextColor(color);
       
  2128     }
       
  2129     else
       
  2130     {
       
  2131         // Set text and highlighted text color to the column item drawer
       
  2132         static_cast< CEikColumnListBox* >(iList)->
       
  2133         ItemDrawer()->SetTextColor(color);
       
  2134     }
       
  2135 }
       
  2136 
       
  2137 // ---------------------------------------------------------------------------
       
  2138 // CSwtListBox::UpdateListMSK
       
  2139 // ---------------------------------------------------------------------------
       
  2140 //
       
  2141 void CSwtListBox::UpdateListMskL()
       
  2142 {
       
  2143     if (AknLayoutUtils::MSKEnabled())
       
  2144     {
       
  2145         MSwtCommandArranger* cmdArranger = iDisplay.CommandArranger();
       
  2146         if (cmdArranger)
       
  2147         {
       
  2148             cmdArranger->UpdateMSKLabelL();
       
  2149         }
       
  2150     }
       
  2151 }
       
  2152 
       
  2153 // ---------------------------------------------------------------------------
       
  2154 // CSwtListBox::MinimumListItemWidth
       
  2155 // ---------------------------------------------------------------------------
       
  2156 //
       
  2157 TInt CSwtListBox::MinimumListItemWidth() const
       
  2158 {
       
  2159     // Layout id selection
       
  2160     CSwtLafFacade::TSwtLafFacadeRectId itemLayoutId =
       
  2161         CSwtLafFacade::EUndefinedRectId;
       
  2162     CSwtLafFacade::TSwtLafFacadeTextId detailTextLayoutId =
       
  2163         CSwtLafFacade::EUndefinedTextId;
       
  2164     CSwtLafFacade::TSwtLafFacadeTextId headingTextLayoutId =
       
  2165         CSwtLafFacade::EUndefinedTextId;
       
  2166     CSwtLafFacade::TSwtLafFacadeRectId detailIconLayoutId =
       
  2167         CSwtLafFacade::EUndefinedRectId;
       
  2168     switch (iProps.iListType)
       
  2169     {
       
  2170     case ESwtLbSingle:
       
  2171         itemLayoutId = CSwtLafFacade::EListSinglePane;
       
  2172         detailTextLayoutId = CSwtLafFacade::EListSinglePaneT1;
       
  2173         detailIconLayoutId = CSwtLafFacade::EListSinglePaneG1;
       
  2174         break;
       
  2175     case ESwtLbSingleGraphic:
       
  2176         itemLayoutId = CSwtLafFacade::EListSingleGraphicPane;
       
  2177         detailTextLayoutId = CSwtLafFacade::EListSingleGraphicPaneT1;
       
  2178         detailIconLayoutId = CSwtLafFacade::EListSingleGraphicPaneG2;
       
  2179         break;
       
  2180     case ESwtLbSingleLarge:
       
  2181         itemLayoutId = CSwtLafFacade::EListSingleLargeGraphicPane;
       
  2182         detailTextLayoutId = CSwtLafFacade::EListSingleLargeGraphicPaneT1;
       
  2183         detailIconLayoutId = CSwtLafFacade::EListSingleLargeGraphicPaneG2;
       
  2184         break;
       
  2185     case ESwtLbSingleHeading:
       
  2186         itemLayoutId = CSwtLafFacade::EListSingleHeadingPane;
       
  2187         detailTextLayoutId = CSwtLafFacade::EListSingleHeadingPaneT1;
       
  2188         detailIconLayoutId = CSwtLafFacade::EListSingleHeadingPaneG1;
       
  2189         break;
       
  2190     case ESwtLbSingleHeadingGraphic:
       
  2191         itemLayoutId = CSwtLafFacade::EListSingleGraphicHeadingPane;
       
  2192         detailTextLayoutId = CSwtLafFacade::EListSingleGraphicHeadingPaneT1;
       
  2193         detailIconLayoutId = CSwtLafFacade::EListSingleGraphicHeadingPaneG4;
       
  2194         break;
       
  2195     case ESwtLbDouble:
       
  2196         itemLayoutId = CSwtLafFacade::EListDoublePane;
       
  2197         headingTextLayoutId = CSwtLafFacade::EListDoublePaneT1;
       
  2198         detailTextLayoutId = CSwtLafFacade::EListDoublePaneT2;
       
  2199         detailIconLayoutId = CSwtLafFacade::EListDoublePaneG1;
       
  2200         break;
       
  2201     case ESwtLbDoubleGraphic:
       
  2202         itemLayoutId = CSwtLafFacade::EListDoubleGraphicPane;
       
  2203         headingTextLayoutId = CSwtLafFacade::EListDoubleGraphicPaneT1;
       
  2204         detailTextLayoutId = CSwtLafFacade::EListDoubleGraphicPaneT2;
       
  2205         detailIconLayoutId = CSwtLafFacade::EListDoubleGraphicPaneG2;
       
  2206         break;
       
  2207     case ESwtLbDoubleLarge:
       
  2208         itemLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPane;
       
  2209         headingTextLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneT1;
       
  2210         detailTextLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneT2;
       
  2211         detailIconLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneG2;
       
  2212         break;
       
  2213     default:
       
  2214         ASSERT(EFalse);
       
  2215         break;
       
  2216     }
       
  2217 
       
  2218     TBool isListDouble = (iProps.iListType >= ESwtLbDouble);
       
  2219 
       
  2220     // List item pane
       
  2221     TAknLayoutRect itemLayout;
       
  2222     TRect mainRect;
       
  2223     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainRect);
       
  2224     itemLayout = CSwtLafFacade::GetLayoutRect(
       
  2225                      CSwtLafFacade::EListScrollGenPane, mainRect, 0);
       
  2226     itemLayout = CSwtLafFacade::GetLayoutRect(
       
  2227                      CSwtLafFacade::EListGenPane, itemLayout.Rect(), 0);
       
  2228     itemLayout = CSwtLafFacade::GetLayoutRect(
       
  2229                      itemLayoutId, itemLayout.Rect(), 0);
       
  2230 
       
  2231     // Text layouts
       
  2232     TAknLayoutText detailTextLayout = CSwtLafFacade::GetLayoutText(
       
  2233                                           detailTextLayoutId, itemLayout.Rect(), 0);
       
  2234     TAknLayoutText headingTextLayout;
       
  2235     if (headingTextLayoutId != CSwtLafFacade::EUndefinedRectId)
       
  2236     {
       
  2237         headingTextLayout = CSwtLafFacade::GetLayoutText(
       
  2238                                 headingTextLayoutId, itemLayout.Rect(), 0);
       
  2239     }
       
  2240 
       
  2241     // Text fonts
       
  2242     const CFont* detailFont = detailTextLayout.Font();
       
  2243     const CFont* headingFont = NULL;
       
  2244     if (isListDouble)
       
  2245     {
       
  2246         headingFont = headingTextLayout.Font();
       
  2247     }
       
  2248 
       
  2249     TInt width(0);
       
  2250     TInt detailX(0);
       
  2251     TInt headingX(0);
       
  2252     TInt detailIconX(0);
       
  2253 
       
  2254     // Text max width
       
  2255     if (detailFont || headingFont)
       
  2256     {
       
  2257         TInt count = iItems.Count();
       
  2258         for (TInt i = 0; i < count; i++)
       
  2259         {
       
  2260             if (headingFont)
       
  2261             {
       
  2262                 headingX = Max(headingX, headingFont->TextWidthInPixels(
       
  2263                                    iItems[i]->HeadingString()));
       
  2264             }
       
  2265             if (detailFont)
       
  2266             {
       
  2267                 detailX = Max(detailX, detailFont->TextWidthInPixels(
       
  2268                                   iItems[i]->String()));
       
  2269             }
       
  2270         }
       
  2271     }
       
  2272 
       
  2273     // Detail text fixed left margin & fixed right margin
       
  2274     if (AknLayoutUtils::LayoutMirrored())
       
  2275     {
       
  2276         detailX += mainRect.iBr.iX - detailTextLayout.TextRect().iBr.iX;
       
  2277         detailX += CSwtLafFacade::TextLineLayout(detailTextLayoutId).il;
       
  2278     }
       
  2279     else
       
  2280     {
       
  2281         detailX += detailTextLayout.TextRect().iTl.iX;
       
  2282         detailX += CSwtLafFacade::TextLineLayout(detailTextLayoutId).ir;
       
  2283     }
       
  2284 
       
  2285     // Heading text fixed left margin & fixed right margin
       
  2286     if (isListDouble)
       
  2287     {
       
  2288         if (AknLayoutUtils::LayoutMirrored())
       
  2289         {
       
  2290             headingX += mainRect.iBr.iX - headingTextLayout.TextRect().iBr.iX;
       
  2291             headingX += CSwtLafFacade::TextLineLayout(headingTextLayoutId).il;
       
  2292         }
       
  2293         else
       
  2294         {
       
  2295             headingX += headingTextLayout.TextRect().iTl.iX;
       
  2296             headingX += CSwtLafFacade::TextLineLayout(headingTextLayoutId).ir;
       
  2297         }
       
  2298     }
       
  2299 
       
  2300     // Icon fixed width & fixed right margin
       
  2301     if (iProps.iDiconVisible)
       
  2302     {
       
  2303         TAknLayoutRect detailIconLayout = CSwtLafFacade::GetLayoutRect(
       
  2304                                               detailIconLayoutId, itemLayout.Rect(), 0);
       
  2305         detailIconX += detailIconLayout.Rect().Width();
       
  2306         if (AknLayoutUtils::LayoutMirrored())
       
  2307         {
       
  2308             detailIconX += CSwtLafFacade::WindowLineLayout(
       
  2309                                detailIconLayoutId).il;
       
  2310         }
       
  2311         else
       
  2312         {
       
  2313             detailIconX += CSwtLafFacade::WindowLineLayout(
       
  2314                                detailIconLayoutId).ir;
       
  2315         }
       
  2316         if (isListDouble)
       
  2317         {
       
  2318             headingX += detailIconX;
       
  2319         }
       
  2320         else
       
  2321         {
       
  2322             detailX += detailIconX;
       
  2323         }
       
  2324     }
       
  2325 
       
  2326     width += Max(headingX, detailX);
       
  2327 
       
  2328     return width;
       
  2329 }
       
  2330 
       
  2331 // ---------------------------------------------------------------------------
       
  2332 // CSwtListBox::TabsToSpace
       
  2333 // ---------------------------------------------------------------------------
       
  2334 //
       
  2335 void CSwtListBox::TabsToSpaces(HBufC* aBuf) const
       
  2336 {
       
  2337     ASSERT(aBuf);
       
  2338 
       
  2339     TPtr ptr = aBuf->Des();
       
  2340     TInt pos = KErrNotFound;
       
  2341 
       
  2342     // Locate tab, replace with space and start from there new search
       
  2343     do
       
  2344     {
       
  2345         pos = ptr.Find(KTxtTab);
       
  2346         if (pos != KErrNotFound)
       
  2347         {
       
  2348             ptr.Replace(pos, KTxtTab().Length(), KTxtSpace);
       
  2349             ptr = ptr.MidTPtr(pos + KTxtTab().Length() + 1);
       
  2350         }
       
  2351     }
       
  2352     while (pos != KErrNotFound);
       
  2353 }
       
  2354 
       
  2355 
       
  2356 // ---------------------------------------------------------------------------
       
  2357 // CSwtListBox::SetMaximumIconSizes
       
  2358 // ---------------------------------------------------------------------------
       
  2359 //
       
  2360 void CSwtListBox::SetMaximumIconSizes()
       
  2361 {
       
  2362     CSwtLafFacade::TSwtLafFacadeRectId detailIconLayoutId =
       
  2363         CSwtLafFacade::EUndefinedRectId;
       
  2364     CSwtLafFacade::TSwtLafFacadeRectId headingIconLayoutId =
       
  2365         CSwtLafFacade::EUndefinedRectId;
       
  2366 
       
  2367     // Heading icon is not supported for all styles.
       
  2368     switch (iProps.iListType)
       
  2369     {
       
  2370     case ESwtLbSingle:
       
  2371         detailIconLayoutId = CSwtLafFacade::EListSinglePaneG1;
       
  2372         break;
       
  2373     case ESwtLbSingleGraphic:
       
  2374         detailIconLayoutId = CSwtLafFacade::EListSingleGraphicPaneG2;
       
  2375         headingIconLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneG1;
       
  2376         break;
       
  2377     case ESwtLbSingleLarge:
       
  2378         detailIconLayoutId = CSwtLafFacade::EListSingleLargeGraphicPaneG2;
       
  2379         headingIconLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneG1;
       
  2380         break;
       
  2381     case ESwtLbSingleHeading:
       
  2382         detailIconLayoutId = CSwtLafFacade::EListSingleHeadingPaneG1;
       
  2383         break;
       
  2384     case ESwtLbSingleHeadingGraphic:
       
  2385         detailIconLayoutId = CSwtLafFacade::EListSingleGraphicHeadingPaneG4;
       
  2386         headingIconLayoutId = CSwtLafFacade::EListSingleGraphicHeadingPaneG1;
       
  2387         break;
       
  2388     case ESwtLbDouble:
       
  2389         detailIconLayoutId = CSwtLafFacade::EListDoublePaneG1;
       
  2390         break;
       
  2391     case ESwtLbDoubleGraphic:
       
  2392         detailIconLayoutId = CSwtLafFacade::EListDoubleGraphicPaneG2;
       
  2393         headingIconLayoutId = CSwtLafFacade::EListDoubleGraphicPaneG1;
       
  2394         break;
       
  2395     case ESwtLbDoubleLarge:
       
  2396         detailIconLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneG2;
       
  2397         headingIconLayoutId = CSwtLafFacade::EListDoubleLargeGraphicPaneG1;
       
  2398         break;
       
  2399     default:
       
  2400         ASSERT(EFalse);
       
  2401         break;
       
  2402     }
       
  2403 
       
  2404     TAknLayoutRect detailIconLayout = CSwtLafFacade::GetLayoutRect(
       
  2405                                           detailIconLayoutId, TRect(), 0);
       
  2406     TSize maxDetailIconSize = detailIconLayout.Rect().Size();
       
  2407     TSize maxHeadingIconSize;
       
  2408 
       
  2409     if (headingIconLayoutId != CSwtLafFacade::EUndefinedRectId)
       
  2410     {
       
  2411         TAknLayoutRect headingIconLayout = CSwtLafFacade::GetLayoutRect(
       
  2412                                                headingIconLayoutId, TRect(), 0);
       
  2413         maxHeadingIconSize = headingIconLayout.Rect().Size();
       
  2414     }
       
  2415 
       
  2416     if (maxDetailIconSize != iMaxDetailIconSize ||
       
  2417             maxHeadingIconSize != iMaxHeadingIconSize)
       
  2418     {
       
  2419         UpdateImageSizes(maxDetailIconSize, maxHeadingIconSize);
       
  2420         iMaxDetailIconSize = maxDetailIconSize;
       
  2421         iMaxHeadingIconSize = maxHeadingIconSize;
       
  2422     }
       
  2423 }
       
  2424 
       
  2425 // ---------------------------------------------------------------------------
       
  2426 // CSwtListBox::SetMaximumIconSizes
       
  2427 // ---------------------------------------------------------------------------
       
  2428 //
       
  2429 void CSwtListBox::UpdateImageSizes(const TSize& aNewMaxDetailSize,
       
  2430                                    const TSize& aNewMaxHeadingSize)
       
  2431 {
       
  2432     TInt count = iItems.Count();
       
  2433 
       
  2434     for (TInt i = 0; i < count; i++)
       
  2435     {
       
  2436         CSwtLbItem* item = iItems[ i ];
       
  2437 
       
  2438         CGulIcon* detailIcon = 0;
       
  2439         CGulIcon* headingIcon = 0;
       
  2440         const MSwtImage* headingImage = item->HeadingIcon();
       
  2441         const MSwtImage* detailImage = item->Image();
       
  2442 
       
  2443         if (item->iDimgIdx != KImgIdxNull)
       
  2444         {
       
  2445             detailIcon = iImgs->At(item->iDimgIdx);
       
  2446         }
       
  2447 
       
  2448         if (item->iHimgIdx != KImgIdxNull)
       
  2449         {
       
  2450             headingIcon = iImgs->At(item->iHimgIdx);
       
  2451         }
       
  2452 
       
  2453         if (detailIcon && detailImage)
       
  2454         {
       
  2455             item->SetImageSize(
       
  2456                 ScaleImage(detailImage, detailIcon, iMaxDetailIconSize, aNewMaxDetailSize));
       
  2457 
       
  2458         }
       
  2459 
       
  2460         if (headingIcon && headingImage)
       
  2461         {
       
  2462             item->SetHeadingIconSize(
       
  2463                 ScaleImage(headingImage, headingIcon, iMaxHeadingIconSize, aNewMaxHeadingSize));
       
  2464         }
       
  2465     }
       
  2466 }
       
  2467 
       
  2468 // ---------------------------------------------------------------------------
       
  2469 // CSwtListBox::ScaleImage
       
  2470 // ---------------------------------------------------------------------------
       
  2471 //
       
  2472 TSize CSwtListBox::ScaleImage(const MSwtImage* aImage, CGulIcon* aIcon,
       
  2473                               const TSize& aOldMaxSize, const TSize& aNewMaxSize)
       
  2474 {
       
  2475     TSize imageSize = aImage->Bitmap().SizeInPixels();
       
  2476     TSize oldSize;
       
  2477     TBool doScaling = ETrue;
       
  2478 
       
  2479     if (imageSize.iHeight > aOldMaxSize.iHeight ||
       
  2480             imageSize.iWidth > aOldMaxSize.iWidth)
       
  2481     {
       
  2482         // If image size is bigger than the old maximum size, then
       
  2483         // the image has been also previously scaled.
       
  2484         oldSize = SwtControlHelper::GetAspectRatioScaledBitmapSize(
       
  2485                       imageSize, aOldMaxSize);
       
  2486     }
       
  2487     else if (imageSize.iHeight > aNewMaxSize.iHeight ||
       
  2488              imageSize.iWidth > aNewMaxSize.iWidth)
       
  2489     {
       
  2490         // Image is bigger than the new boundaries, but it did fit
       
  2491         // inside the old boundaries, so the image is default size.
       
  2492         oldSize = imageSize;
       
  2493     }
       
  2494     else
       
  2495     {
       
  2496         doScaling = EFalse;
       
  2497     }
       
  2498 
       
  2499     if (doScaling)
       
  2500     {
       
  2501         imageSize = SwtControlHelper::GetAspectRatioScaledBitmapSize(
       
  2502                         imageSize, aNewMaxSize);
       
  2503         CFbsBitmap* bmp = const_cast<CFbsBitmap*>(&aImage->SubBitmap(imageSize));
       
  2504         CFbsBitmap* mask = const_cast<CFbsBitmap*>(aImage->SubMaskBitmap(imageSize, ETrue));
       
  2505 
       
  2506         aImage->AddSubRef(imageSize);
       
  2507 
       
  2508         // Remove the old reference
       
  2509         aImage->RemoveSubRef(oldSize);
       
  2510 
       
  2511         aIcon->SetBitmap(bmp);
       
  2512         aIcon->SetMask(mask);
       
  2513     }
       
  2514 
       
  2515     return imageSize;
       
  2516 }
       
  2517 
       
  2518 // ---------------------------------------------------------------------------
       
  2519 // CSwtListBox::RemoveSubRefs
       
  2520 // ---------------------------------------------------------------------------
       
  2521 //
       
  2522 void CSwtListBox::RemoveSubRefs()
       
  2523 {
       
  2524     TInt count = iItems.Count();
       
  2525     for (TInt i = 0; i < count; i++)
       
  2526     {
       
  2527         CSwtLbItem* item = iItems[ i ];
       
  2528         const MSwtImage* dImg = item->Image();
       
  2529         const MSwtImage* hImg = item->HeadingIcon();
       
  2530         const TSize dImgSize = item->ImageSize();
       
  2531         const TSize hImgSize = item->HeadingIconSize();
       
  2532 
       
  2533         if (dImg && dImgSize != TSize(TSize::EUninitialized))
       
  2534         {
       
  2535             dImg->RemoveSubRef(item->ImageSize());
       
  2536         }
       
  2537 
       
  2538         if (hImg && hImgSize != TSize(TSize::EUninitialized))
       
  2539         {
       
  2540             hImg->RemoveSubRef(item->HeadingIconSize());
       
  2541         }
       
  2542     }
       
  2543 }
       
  2544 
       
  2545 #ifdef RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
  2546 void CSwtListBox::DoControlSpecificFeedback(
       
  2547     const TBool& aFirstTap,
       
  2548     const TBool& aTappedToChildRect,
       
  2549     const TPointerEvent& aPointerEvent) const
       
  2550 {
       
  2551     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  2552     if (feedback && !aTappedToChildRect)
       
  2553     {
       
  2554         switch (aPointerEvent.iType)
       
  2555         {
       
  2556         case TPointerEvent::EButton1Down:
       
  2557             if (aFirstTap)
       
  2558             {
       
  2559                 feedback->InstantFeedback(ETouchFeedbackSensitiveList);
       
  2560             }
       
  2561             break;
       
  2562         }
       
  2563     }
       
  2564 }
       
  2565 #endif //RD_JAVA_ADVANCED_TACTILE_FEEDBACK
       
  2566 
       
  2567 // ---------------------------------------------------------------------------
       
  2568 // CSwtTableListBox::UpdateFlickScrollingState
       
  2569 // Updates flick scrolling status based on received listbox event.
       
  2570 // ---------------------------------------------------------------------------
       
  2571 //
       
  2572 void CSwtListBox::UpdateFlickScrollingState(TListBoxEvent aEventType)
       
  2573 {
       
  2574     switch (aEventType)
       
  2575     {
       
  2576     case EEventFlickStarted:
       
  2577         iFlickScrollingOngoing = ETrue;
       
  2578         iScrollbarPointerEventToListbox = ETrue;
       
  2579         break;
       
  2580     case EEventFlickStopped:
       
  2581         iFlickScrollingOngoing = EFalse;
       
  2582         break;
       
  2583     }
       
  2584 }